acpi.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "libcflat.h"
  2. #include "acpi.h"
  3. void* find_acpi_table_addr(u32 sig)
  4. {
  5. unsigned long addr;
  6. struct rsdp_descriptor *rsdp;
  7. struct rsdt_descriptor_rev1 *rsdt;
  8. void *end;
  9. int i;
  10. /* FACS is special... */
  11. if (sig == FACS_SIGNATURE) {
  12. struct fadt_descriptor_rev1 *fadt;
  13. fadt = find_acpi_table_addr(FACP_SIGNATURE);
  14. if (!fadt) {
  15. return NULL;
  16. }
  17. return (void*)(ulong)fadt->firmware_ctrl;
  18. }
  19. for(addr = 0xf0000; addr < 0x100000; addr += 16) {
  20. rsdp = (void*)addr;
  21. if (rsdp->signature == 0x2052545020445352LL)
  22. break;
  23. }
  24. if (addr == 0x100000) {
  25. printf("Can't find RSDP\n");
  26. return 0;
  27. }
  28. if (sig == RSDP_SIGNATURE) {
  29. return rsdp;
  30. }
  31. rsdt = (void*)(ulong)rsdp->rsdt_physical_address;
  32. if (!rsdt || rsdt->signature != RSDT_SIGNATURE)
  33. return 0;
  34. if (sig == RSDT_SIGNATURE) {
  35. return rsdt;
  36. }
  37. end = (void*)rsdt + rsdt->length;
  38. for (i=0; (void*)&rsdt->table_offset_entry[i] < end; i++) {
  39. struct acpi_table *t = (void*)(ulong)rsdt->table_offset_entry[i];
  40. if (t && t->signature == sig) {
  41. return t;
  42. }
  43. }
  44. return NULL;
  45. }