def Run(self, args): self.logs = [] self.chipsec_log = StringIO.StringIO() if args.logging: self.logs.append("Dumping %s" % args.table_signature) logger.logger().logfile = self.chipsec_log logger.logger().LOG_TO_FILE = True # Wrap most of Chipsec code to gather its logs in case of failure. try: # Initialise Chipsec (die early if unknown chipset) c = chipset.cs() # Platform = None, Start Driver = False c.init(None, False) a = acpi.ACPI(c) acpi_tables_raw = a.get_ACPI_table(args.table_signature) acpi_tables = [] for i, table_address in enumerate( a.tableList[args.table_signature]): table_header, table_content = acpi_tables_raw[i] table_blob = table_header + table_content acpi_tables.append( rdf_chipsec_types.ACPITableData( table_address=table_address, table_blob=table_blob)) except (chipset.UnknownChipsetError, OSError) as err: # Expected errors that might happen on the client # If the chipset is unknown or we encountered an error due to reading # an area we do not have access to using /dev/mem, simply return an # error message. if args.logging: self.LogError(err) self.SendReply( rdf_chipsec_types.DumpACPITableResponse(logs=["%s" % err], )) return except Exception as err: # pylint: disable=broad-except # In case an exception is raised, if the verbose mode # is enabled, return the raw logs from Chipsec. if args.logging: self.LogError(err) raise if not acpi_tables: self.logs.append("No ACPI table with signature %s." % args.table_signature) else: self.logs.append( "ACPI table with signature %s has been successfully dumped." % args.table_signature) if args.logging: self.logs.extend(self.chipsec_log.getvalue().splitlines()) self.SendReply( rdf_chipsec_types.DumpACPITableResponse(acpi_tables=acpi_tables, logs=self.logs))
def run(self): if len(self.argv) < 3: print(IOMMUCommand.__doc__) return op = self.argv[2] t = time.time() try: _iommu = iommu.IOMMU(self.cs) except iommu.IOMMUError as msg: print(msg) return if ('list' == op): self.logger.log("[CHIPSEC] Enumerating supported IOMMU engines..") self.logger.log(iommu.IOMMU_ENGINES.keys()) elif ('config' == op or 'status' == op or 'enable' == op or 'disable' == op or 'pt' == op): if len(self.argv) > 3: if self.argv[3] in iommu.IOMMU_ENGINES.keys(): _iommu_engines = [self.argv[3]] else: self.logger.error( "IOMMU name {} not recognized. Run 'iommu list' command for supported IOMMU names" .format(self.argv[3])) return else: _iommu_engines = iommu.IOMMU_ENGINES.keys() if 'config' == op: try: _acpi = acpi.ACPI(self.cs) except acpi.AcpiRuntimeError as msg: print(msg) return if _acpi.is_ACPI_table_present(acpi.ACPI_TABLE_SIG_DMAR): self.logger.log( "[CHIPSEC] Dumping contents of DMAR ACPI table..\n") _acpi.dump_ACPI_table(acpi.ACPI_TABLE_SIG_DMAR) else: self.logger.log( "[CHIPSEC] Couldn't find DMAR ACPI table\n") for e in _iommu_engines: if 'config' == op: _iommu.dump_IOMMU_configuration(e) elif 'pt' == op: _iommu.dump_IOMMU_page_tables(e) elif 'status' == op: _iommu.dump_IOMMU_status(e) elif 'enable' == op: _iommu.set_IOMMU_Translation(e, 1) elif 'disable' == op: _iommu.set_IOMMU_Translation(e, 0) else: print(IOMMUCommand.__doc__) return self.logger.log( "[CHIPSEC] (iommu) time elapsed {:.3f}".format(time.time() - t))
def get_number_threads_from_APIC_table(self): _acpi = acpi.ACPI( self.cs ) dACPIID = {} (table_header,APIC_object,table_header_blob,table_blob) = _acpi.get_parse_ACPI_table( chipsec.hal.acpi.ACPI_TABLE_SIG_APIC ) for structure in APIC_object.apic_structs: if 0x00 == structure.Type: if dACPIID.has_key( structure.APICID ) == False: if 1 == structure.Flags: dACPIID[ structure.APICID ] = structure.ACPIProcID return len( dACPIID )
def get_number_threads_from_APIC_table(self): _acpi = acpi.ACPI( self.cs ) dACPIID = {} for apic in _acpi.get_parse_ACPI_table( acpi.ACPI_TABLE_SIG_APIC ): table_header,APIC_object,table_header_blob,table_blob = apic for structure in APIC_object.apic_structs: if 0x00 == structure.Type: if not structure.ACICID in dACPIID: if 1 == structure.Flags: dACPIID[ structure.APICID ] = structure.ACPIProcID return len( dACPIID )
def iommu_engine(self, cmd): try: _iommu = iommu.IOMMU(self.cs) except iommu.IOMMUError as msg: print(msg) return if self.engine: if self.engine in iommu.IOMMU_ENGINES.keys(): _iommu_engines = [self.engine] else: self.logger.error( "IOMMU name {} not recognized. Run 'iommu list' command for supported IOMMU names" .format(self.engine)) return else: _iommu_engines = iommu.IOMMU_ENGINES.keys() if 'config' == cmd: try: _acpi = acpi.ACPI(self.cs) except acpi.AcpiRuntimeError as msg: print(msg) return if _acpi.is_ACPI_table_present(acpi.ACPI_TABLE_SIG_DMAR): self.logger.log( "[CHIPSEC] Dumping contents of DMAR ACPI table..\n") _acpi.dump_ACPI_table(acpi.ACPI_TABLE_SIG_DMAR) else: self.logger.log("[CHIPSEC] Couldn't find DMAR ACPI table\n") for e in _iommu_engines: if (cmd == 'config'): _iommu.dump_IOMMU_configuration(e) elif (cmd == 'pt'): _iommu.dump_IOMMU_page_tables(e) elif (cmd == 'status'): _iommu.dump_IOMMU_status(e) elif (cmd == 'enable'): _iommu.set_IOMMU_Translation(e, 1) elif (cmd == 'disable'): _iommu.set_IOMMU_Translation(e, 0)
class IOMMUCommand(BaseCommand): """ >>> chipsec_util iommu list >>> chipsec_util iommu config [iommu_engine] >>> chipsec_util iommu status [iommu_engine] >>> chipsec_util iommu enable|disable <iommu_engine> >>> chipsec_util iommu pt Examples: >>> chipsec_util iommu list >>> chipsec_util iommu config VTD >>> chipsec_util iommu status GFXVTD >>> chipsec_util iommu enable VTD >>> chipsec_util iommu pt """ def requires_driver(self): # No driver required when printing the util documentation if len(self.argv) < 3: return False return True def run(self): if len(self.argv) < 3: print IOMMUCommand.__doc__ return op = self.argv[2] t = time.time() try: _iommu = iommu.IOMMU(self.cs) except IOMMUError, msg: print msg return if ('list' == op): self.logger.log("[CHIPSEC] Enumerating supported IOMMU engines..") self.logger.log(iommu.IOMMU_ENGINES.keys()) elif ('config' == op or 'status' == op or 'enable' == op or 'disable' == op or 'pt' == op): if len(self.argv) > 3: if self.argv[3] in iommu.IOMMU_ENGINES.keys(): _iommu_engines = [self.argv[3]] else: self.logger.error( "IOMMU name %s not recognized. Run 'iommu list' command for supported IOMMU names" % self.argv[3]) return else: _iommu_engines = iommu.IOMMU_ENGINES.keys() if 'config' == op: try: _acpi = acpi.ACPI(self.cs) except acpi.AcpiRuntimeError, msg: print msg return if _acpi.is_ACPI_table_present(acpi.ACPI_TABLE_SIG_DMAR): self.logger.log( "[CHIPSEC] Dumping contents of DMAR ACPI table..\n") _acpi.dump_ACPI_table(acpi.ACPI_TABLE_SIG_DMAR) else: self.logger.log( "[CHIPSEC] Couldn't find DMAR ACPI table\n") for e in _iommu_engines: if 'config' == op: _iommu.dump_IOMMU_configuration(e) elif 'pt' == op: _iommu.dump_IOMMU_page_tables(e) elif 'status' == op: _iommu.dump_IOMMU_status(e) elif 'enable' == op: _iommu.set_IOMMU_Translation(e, 1) elif 'disable' == op: _iommu.set_IOMMU_Translation(e, 0)