diff --git a/source/tool/tests/software/mock_helper.py b/source/tool/tests/software/mock_helper.py index c39efea1..c8d07ec5 100644 --- a/source/tool/tests/software/mock_helper.py +++ b/source/tool/tests/software/mock_helper.py @@ -59,9 +59,6 @@ class ACPIHelper(TestHelper): XSDT_ADDRESS = 0x100 RSDT_ADDRESS = 0x200 - RSDT_ENTRIES = [] - XSDT_ENTRIES = [] - def _create_rsdp(self): rsdp = None if self.USE_RSDP_REV_0: @@ -96,40 +93,97 @@ class ACPIHelper(TestHelper): "CRRV") # Creator Revision def _create_rsdt(self): - rsdt_length = 36 + 4 * len(self.RSDT_ENTRIES) # 36 : ACPI table header size + rsdt_length = 36 + 4 * len(self.rsdt_entries) # 36 : ACPI table header size rsdt = self._create_generic_acpi_table_header("RSDT", rsdt_length) - for rsdt_entry in self.RSDT_ENTRIES: + for rsdt_entry in self.rsdt_entries: rsdt += struct.pack("> 4) elif pa_lo >= self.EBDA_ADDRESS and \ - pa_lo < self.RSDP_ADDRESS + len(self.RSDP_DESCRIPTOR): - mem = "\x00" * self.EBDA_PADDING + self.RSDP_DESCRIPTOR + pa_lo < self.RSDP_ADDRESS + len(self.rsdp_descriptor): + mem = "\x00" * self.EBDA_PADDING + self.rsdp_descriptor offset = pa_lo - self.EBDA_ADDRESS return mem[offset:offset+length] elif pa_lo == self.RSDT_ADDRESS: - return self.RSDT_DESCRIPTOR[:length] + return self.rsdt_descriptor[:length] elif pa_lo == self.XSDT_ADDRESS: - return self.XSDT_DESCRIPTOR[:length] + return self.xsdt_descriptor[:length] else: return "\xFF" * length +class DSDTParsingHelper(ACPIHelper): + """Test helper containing generic descriptor for RSDP, RSDT, and FADT to parse DSDT + + Default entry for DSDT and X_DSDT inside FADT is 0x0 + + One additional region is defined: + * FADT table [0x400, 0x514] + """ + USE_FADT_WITH_X_DSDT = True + + FADT_ADDRESS = 0x400 + DSDT_ADDRESS = 0x0 + X_DSDT_ADDRESS = 0x0 + + def _add_fadt_to_sdt_entries(self): + if self.USE_RSDP_REV_0: + self._add_entry_to_rsdt(self.FADT_ADDRESS) + else: + self._add_entry_to_xsdt(self.FADT_ADDRESS) + + def _create_fadt(self): + fadt = "" + if self.USE_FADT_WITH_X_DSDT: + fadt = self._create_generic_acpi_table_header("FACP", 0x10C) + fadt += struct.pack("= self.EBDA_ADDRESS and \ - pa_lo < self.RSDP_ADDRESS + len(self.RSDP_DESCRIPTOR): + pa_lo < self.RSDP_ADDRESS + len(self.rsdp_descriptor): # Simulate a condition where there is no RSDP in EBDA return "\xFF" * length elif pa_lo == 0xE0000: - return self.RSDP_DESCRIPTOR[:length] + return self.rsdp_descriptor[:length] elif pa_lo == 0x300: return "ABCD" else: @@ -92,10 +96,88 @@ class TestChipsecUtil(unittest.TestCase): self._chipsec_util("acpi list", ACPIHelper) self.assertIn("ABCD: 0x0000000000000300", self.log) + def test_acpi_facp_list(self): + self._chipsec_util("acpi table FACP", mock_helper.DSDTParsingHelper) + self.assertIn("DSDT: 0x00000000", self.log) + self.assertIn("X_DSDT: 0x0000000000000000", self.log) + + def test_mismatch_dsdt_x_dsdt_error(self): + + class DSDTParsingHelper(mock_helper.DSDTParsingHelper): + + DSDT_ADDRESS = 0x400 + X_DSDT_ADDRESS = 0x312 + + self._chipsec_util("acpi table FACP", DSDTParsingHelper) + self.assertIn("DSDT: 0x00000400", self.log) + self.assertIn("X_DSDT: 0x0000000000000312", self.log) + self.assertIn("Unable to determine the correct DSDT address", self.log) + + def test_mismatch_dsdt_x_dsdt_ok_dsdt_zero(self): + + class DSDTParsingHelper(mock_helper.DSDTParsingHelper): + + DSDT_ADDRESS = 0x0 + X_DSDT_ADDRESS = 0x400 + + self._chipsec_util("acpi table FACP", DSDTParsingHelper) + self.assertIn("DSDT: 0x00000000", self.log) + self.assertIn("X_DSDT: 0x0000000000000400", self.log) + self.assertNotIn("Unable to determine the correct DSDT address", self.log) + + def test_mismatch_dsdt_x_dsdt_ok_x_dsdt_zero(self): + + class DSDTParsingHelper(mock_helper.DSDTParsingHelper): + + DSDT_ADDRESS = 0x400 + X_DSDT_ADDRESS = 0x0 + + self._chipsec_util("acpi table FACP", DSDTParsingHelper) + self.assertIn("DSDT: 0x00000400", self.log) + self.assertIn("X_DSDT: 0x0000000000000000", self.log) + self.assertNotIn("Unable to determine the correct DSDT address", self.log) + + def test_no_x_dsdt(self): + + class DSDTParsingHelper(mock_helper.DSDTParsingHelper): + + USE_FADT_WITH_X_DSDT = False + DSDT_ADDRESS = 0x400 + + self._chipsec_util("acpi table FACP", DSDTParsingHelper) + self.assertIn("DSDT: 0x00000400", self.log) + self.assertIn("X_DSDT: Not found", self.log) + self.assertIn("Cannot find X_DSDT entry in FADT.", self.log) + + def test_show_dsdt(self): + + class DSDTParsingHelper(mock_helper.DSDTParsingHelper): + + DSDT_ADDRESS = 0x600 + + DSDT_DESCRIPTOR = ("DSDT" + # Signature + struct.pack("