void acpi_EnterDebugger(void) { ACPI_PARSE_OBJECT obj; static int initted = 0; if (!initted) { printf("Initialising ACPICA debugger...\n"); AcpiInitializeDebugger(); initted = 1; } printf("Entering ACPICA debugger...\n"); AcpiDbUserCommands('A', &obj); }
void main(int argc, char *argv[]) { int set = -1, enable = -1; int seg = 0, bus = 0, dev = 2, fn = 0, pin = 0; ACPI_STATUS status; int verbose = 0; AcpiDbgLevel = 0; ARGBEGIN{ case 'v': AcpiDbgLevel = ACPI_LV_VERBOSITY1; verbose++; break; case 's': set = open("#P/irqmap", OWRITE); if (set < 0) sysfatal("%r"); break; default: sysfatal("usage: acpi/irq [-v] [-s]"); break; }ARGEND; status = AcpiInitializeSubsystem(); if (ACPI_FAILURE(status)) { sysfatal("Error %d\n", status); } status = AcpiInitializeTables(NULL, 0, FALSE); if (ACPI_FAILURE(status)) sysfatal("can't set up acpi tables: %d", status); if (verbose) print("init dables\n"); status = AcpiLoadTables(); if (ACPI_FAILURE(status)) sysfatal("Can't load ACPI tables: %d", status); /* from acpi: */ /* If the Hardware Reduced flag is set, machine is always in acpi mode */ AcpiGbl_ReducedHardware = 1; if (verbose) print("LOADED TABLES.\n"); status = AcpiEnableSubsystem(0); if (ACPI_FAILURE(status)) print("Probably does not matter: Can't enable ACPI subsystem"); if (verbose) print("enabled subsystem.\n"); status = AcpiInitializeObjects(0); if (ACPI_FAILURE(status)) sysfatal("Can't Initialize ACPI objects"); int picmode; status = FindIOAPICs(&picmode); if (picmode == 0) sysfatal("PANIC: Can't handle picmode 0!"); ACPI_STATUS ExecuteOSI(int pic_mode); if (verbose) print("FindIOAPICs returns status %d picmode %d\n", status, picmode); status = ExecuteOSI(picmode); CHECK_STATUS("ExecuteOSI"); failed: if (verbose) print("inited objects.\n"); if (verbose) AcpiDbgLevel |= ACPI_LV_VERBOSITY1 | ACPI_LV_FUNCTIONS; status = AcpiInitializeDebugger(); if (ACPI_FAILURE(status)) { sysfatal("Error %d\n", status); } int GetPRT(); status = GetPRT(); if (ACPI_FAILURE(status)) { sysfatal("Error %d\n", status); } while (1) { if (scanf("%x %x", &bus, &dev) < 0) break; ACPI_STATUS RouteIRQ(ACPI_PCI_ID* device, int pin, int* irq); AcpiDbgLevel = 0; ACPI_PCI_ID id = (ACPI_PCI_ID){seg, bus, dev, fn}; status = AcpiOsReadPciConfiguration (&id, 0x3d, &pin, 8); if (!ACPI_SUCCESS(status)){ printf("Can't read pin for bus %d dev %d\n", bus, dev); continue; } print("ROUTE {%d, %d, %d, %d}, pin %d\n", seg, bus, dev, fn, pin); int irq; status = RouteIRQ(&id, pin, &irq); print("status %d, irq %d\n", status, irq); AcpiDbgLevel = 0; print("echo %d %d %d %d 0x%x > /dev/irqmap", seg, bus, dev, fn, irq); //ACPI_STATUS PrintDevices(void); //status = PrintDevices(); if (set > -1) fprint(set, "%d %d %d %d 0x%x", seg, bus, dev, fn, irq); } /* we're done. Enable the IRQs we might have set up. */ enable = open("/dev/irqenable", OWRITE); if (enable < 0) sysfatal("/dev/irqenable: %r"); if (write(enable, "", 1) < 1) sysfatal("Write irqenable: %r"); exits(0); }
int ACPI_SYSTEM_XFACE main ( int argc, char **argv) { ACPI_NEW_TABLE_DESC *ListHead = NULL; ACPI_STATUS Status; UINT32 InitFlags; int ExitCode = 0; ACPI_DEBUG_INITIALIZE (); /* For debug version only */ signal (SIGINT, AeCtrlCHandler); /* Init debug globals */ AcpiDbgLevel = ACPI_NORMAL_DEFAULT; AcpiDbgLayer = 0xFFFFFFFF; /* * Initialize ACPICA and start debugger thread. * * NOTE: After ACPICA initialization, AcpiTerminate MUST be called * before this procedure exits -- otherwise, the console may be * left in an incorrect state. */ Status = AcpiInitializeSubsystem (); ACPI_CHECK_OK (AcpiInitializeSubsystem, Status); if (ACPI_FAILURE (Status)) { goto ErrorExit; } /* ACPICA runtime configuration */ AcpiGbl_MaxLoopIterations = 400; /* Initialize the AML debugger */ Status = AcpiInitializeDebugger (); ACPI_CHECK_OK (AcpiInitializeDebugger, Status); if (ACPI_FAILURE (Status)) { goto ErrorExit; } printf (ACPI_COMMON_SIGNON (ACPIEXEC_NAME)); if (argc < 2) { usage (); goto NormalExit; } /* Get the command line options */ ExitCode = AeDoOptions (argc, argv); if (ExitCode) { if (ExitCode > 0) { ExitCode = 0; } goto ErrorExit; } /* The remaining arguments are filenames for ACPI tables */ if (!argv[AcpiGbl_Optind]) { goto EnterDebugger; } AcpiGbl_CstyleDisassembly = FALSE; /* Not supported for AcpiExec */ /* Get each of the ACPI table files on the command line */ while (argv[AcpiGbl_Optind]) { /* Get all ACPI AML tables in this file */ Status = AcGetAllTablesFromFile (argv[AcpiGbl_Optind], ACPI_GET_ALL_TABLES, &ListHead); if (ACPI_FAILURE (Status)) { ExitCode = -1; goto ErrorExit; } AcpiGbl_Optind++; } printf ("\n"); /* Build a local RSDT with all tables and let ACPICA process the RSDT */ Status = AeBuildLocalTables (ListHead); if (ACPI_FAILURE (Status)) { goto ErrorExit; } /* Install all of the ACPI tables */ Status = AeInstallTables (); if (ACPI_FAILURE (Status)) { printf ("**** Could not install ACPI tables, %s\n", AcpiFormatException (Status)); goto EnterDebugger; } /* * Install most of the handlers (Regions, Notify, Table, etc.) * Override the default region handlers, especially SystemMemory, * which is simulated in this utility. */ Status = AeInstallEarlyHandlers (); if (ACPI_FAILURE (Status)) { goto EnterDebugger; } /* Setup initialization flags for ACPICA */ InitFlags = (ACPI_NO_HANDLER_INIT | ACPI_NO_ACPI_ENABLE); if (AcpiGbl_DbOpt_NoIniMethods) { InitFlags |= (ACPI_NO_DEVICE_INIT | ACPI_NO_OBJECT_INIT); } /* * Main initialization for ACPICA subsystem * TBD: Need a way to call this after the ACPI table "LOAD" command? * * NOTE: This initialization does not match the _Lxx and _Exx methods * to individual GPEs, as there are no real GPEs when the hardware * is simulated - because there is no namespace until AeLoadTables is * executed. This may have to change if AcpiExec is ever run natively * on actual hardware (such as under UEFI). */ Status = AcpiEnableSubsystem (InitFlags); if (ACPI_FAILURE (Status)) { printf ("**** Could not EnableSubsystem, %s\n", AcpiFormatException (Status)); goto EnterDebugger; } Status = AeLoadTables (); /* * Exit namespace initialization for the "load namespace only" option. * No control methods will be executed. However, still enter the * the debugger. */ if (AcpiGbl_AeLoadOnly) { goto EnterDebugger; } if (ACPI_FAILURE (Status)) { printf ("**** Could not load ACPI tables, %s\n", AcpiFormatException (Status)); goto EnterDebugger; } /* * Install handlers for "device driver" space IDs (EC,SMBus, etc.) * and fixed event handlers */ AeInstallLateHandlers (); /* Finish the ACPICA initialization */ Status = AcpiInitializeObjects (InitFlags); if (ACPI_FAILURE (Status)) { printf ("**** Could not InitializeObjects, %s\n", AcpiFormatException (Status)); goto EnterDebugger; } AeMiscellaneousTests (); EnterDebugger: /* Exit if error above and we are in one of the batch modes */ if (ACPI_FAILURE (Status) && (AcpiGbl_ExecutionMode > 0)) { goto ErrorExit; } /* Run a batch command or enter the command loop */ switch (AcpiGbl_ExecutionMode) { default: case AE_MODE_COMMAND_LOOP: AcpiRunDebugger (NULL); break; case AE_MODE_BATCH_MULTIPLE: AcpiRunDebugger (BatchBuffer); break; case AE_MODE_BATCH_SINGLE: AcpiDbExecute (BatchBuffer, NULL, NULL, EX_NO_SINGLE_STEP); break; } /* Shut down the debugger and ACPICA */ AcpiTerminateDebugger (); NormalExit: ExitCode = 0; ErrorExit: (void) AcpiOsTerminate (); return (ExitCode); }