acpi.c 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* acpi.c - get acpi tables. */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2009 Free Software Foundation, Inc.
  5. *
  6. * GRUB is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * GRUB is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <grub/acpi.h>
  20. #include <grub/misc.h>
  21. struct grub_acpi_rsdp_v10 *
  22. grub_machine_acpi_get_rsdpv1 (void)
  23. {
  24. int ebda_len;
  25. grub_uint8_t *ebda, *ptr;
  26. grub_dprintf ("acpi", "Looking for RSDP. Scanning EBDA\n");
  27. ebda = (grub_uint8_t *) ((* ((grub_uint16_t *) 0x40e)) << 4);
  28. ebda_len = * (grub_uint16_t *) ebda;
  29. if (! ebda_len)
  30. return 0;
  31. for (ptr = ebda; ptr < ebda + 0x400; ptr += 16)
  32. if (grub_memcmp (ptr, "RSD PTR ", 8) == 0
  33. && grub_byte_checksum (ptr, sizeof (struct grub_acpi_rsdp_v10)) == 0
  34. && ((struct grub_acpi_rsdp_v10 *) ptr)->revision == 0)
  35. return (struct grub_acpi_rsdp_v10 *) ptr;
  36. grub_dprintf ("acpi", "Looking for RSDP. Scanning BIOS\n");
  37. for (ptr = (grub_uint8_t *) 0xe0000; ptr < (grub_uint8_t *) 0x100000;
  38. ptr += 16)
  39. if (grub_memcmp (ptr, "RSD PTR ", 8) == 0
  40. && grub_byte_checksum (ptr, sizeof (struct grub_acpi_rsdp_v10)) == 0
  41. && ((struct grub_acpi_rsdp_v10 *) ptr)->revision == 0)
  42. return (struct grub_acpi_rsdp_v10 *) ptr;
  43. return 0;
  44. }
  45. struct grub_acpi_rsdp_v20 *
  46. grub_machine_acpi_get_rsdpv2 (void)
  47. {
  48. int ebda_len;
  49. grub_uint8_t *ebda, *ptr;
  50. grub_dprintf ("acpi", "Looking for RSDP. Scanning EBDA\n");
  51. ebda = (grub_uint8_t *) ((* ((grub_uint16_t *) 0x40e)) << 4);
  52. ebda_len = * (grub_uint16_t *) ebda;
  53. if (! ebda_len)
  54. return 0;
  55. for (ptr = ebda; ptr < ebda + 0x400; ptr += 16)
  56. if (grub_memcmp (ptr, "RSD PTR ", 8) == 0
  57. && grub_byte_checksum (ptr, sizeof (struct grub_acpi_rsdp_v10)) == 0
  58. && ((struct grub_acpi_rsdp_v10 *) ptr)->revision != 0
  59. && ((struct grub_acpi_rsdp_v20 *) ptr)->length < 1024
  60. && grub_byte_checksum (ptr, ((struct grub_acpi_rsdp_v20 *) ptr)->length)
  61. == 0)
  62. return (struct grub_acpi_rsdp_v20 *) ptr;
  63. grub_dprintf ("acpi", "Looking for RSDP. Scanning BIOS\n");
  64. for (ptr = (grub_uint8_t *) 0xe0000; ptr < (grub_uint8_t *) 0x100000;
  65. ptr += 16)
  66. if (grub_memcmp (ptr, "RSD PTR ", 8) == 0
  67. && grub_byte_checksum (ptr, sizeof (struct grub_acpi_rsdp_v10)) == 0
  68. && ((struct grub_acpi_rsdp_v10 *) ptr)->revision != 0
  69. && ((struct grub_acpi_rsdp_v20 *) ptr)->length < 1024
  70. && grub_byte_checksum (ptr, ((struct grub_acpi_rsdp_v20 *) ptr)->length)
  71. == 0)
  72. return (struct grub_acpi_rsdp_v20 *) ptr;
  73. return 0;
  74. }