You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright (C) 2017 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. *
  19. * You can also choose to distribute this program under the terms of
  20. * the Unmodified Binary Distribution Licence (as given in the file
  21. * COPYING.UBDL), provided that you have satisfied its requirements.
  22. */
  23. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. /**
  25. * @file
  26. *
  27. * ACPI Root System Description Pointer
  28. *
  29. */
  30. #include <stdint.h>
  31. #include <realmode.h>
  32. #include <bios.h>
  33. #include <ipxe/acpi.h>
  34. #include <ipxe/rsdp.h>
  35. /** EBDA RSDP maximum segment */
  36. #define RSDP_EBDA_END_SEG 0xa000
  37. /** Fixed BIOS area RSDP start address */
  38. #define RSDP_BIOS_START 0xe0000
  39. /** Fixed BIOS area RSDP length */
  40. #define RSDP_BIOS_LEN 0x20000
  41. /** Stride at which to search for RSDP */
  42. #define RSDP_STRIDE 16
  43. /**
  44. * Locate ACPI root system description table within a memory range
  45. *
  46. * @v start Start address to search
  47. * @v len Length to search
  48. * @ret rsdt ACPI root system description table, or UNULL
  49. */
  50. static userptr_t rsdp_find_rsdt_range ( userptr_t start, size_t len ) {
  51. static const char signature[8] = RSDP_SIGNATURE;
  52. struct acpi_rsdp rsdp;
  53. userptr_t rsdt;
  54. size_t offset;
  55. uint8_t sum;
  56. unsigned int i;
  57. /* Search for RSDP */
  58. for ( offset = 0 ; ( ( offset + sizeof ( rsdp ) ) < len ) ;
  59. offset += RSDP_STRIDE ) {
  60. /* Check signature and checksum */
  61. copy_from_user ( &rsdp, start, offset, sizeof ( rsdp ) );
  62. if ( memcmp ( rsdp.signature, signature,
  63. sizeof ( signature ) ) != 0 )
  64. continue;
  65. for ( sum = 0, i = 0 ; i < sizeof ( rsdp ) ; i++ )
  66. sum += *( ( ( uint8_t * ) &rsdp ) + i );
  67. if ( sum != 0 )
  68. continue;
  69. /* Extract RSDT */
  70. rsdt = phys_to_user ( le32_to_cpu ( rsdp.rsdt ) );
  71. DBGC ( rsdt, "RSDT %#08lx found via RSDP %#08lx\n",
  72. user_to_phys ( rsdt, 0 ),
  73. user_to_phys ( start, offset ) );
  74. return rsdt;
  75. }
  76. return UNULL;
  77. }
  78. /**
  79. * Locate ACPI root system description table
  80. *
  81. * @ret rsdt ACPI root system description table, or UNULL
  82. */
  83. static userptr_t rsdp_find_rsdt ( void ) {
  84. static userptr_t rsdt;
  85. uint16_t ebda_seg;
  86. userptr_t ebda;
  87. size_t ebda_len;
  88. /* Return existing RSDT if already found */
  89. if ( rsdt )
  90. return rsdt;
  91. /* Search EBDA */
  92. get_real ( ebda_seg, BDA_SEG, BDA_EBDA );
  93. if ( ebda_seg < RSDP_EBDA_END_SEG ) {
  94. ebda = real_to_user ( ebda_seg, 0 );
  95. ebda_len = ( ( RSDP_EBDA_END_SEG - ebda_seg ) * 16 );
  96. rsdt = rsdp_find_rsdt_range ( ebda, ebda_len );
  97. if ( rsdt )
  98. return rsdt;
  99. }
  100. /* Search fixed BIOS area */
  101. rsdt = rsdp_find_rsdt_range ( phys_to_user ( RSDP_BIOS_START ),
  102. RSDP_BIOS_LEN );
  103. if ( rsdt )
  104. return rsdt;
  105. return UNULL;
  106. }
  107. PROVIDE_ACPI ( rsdp, acpi_find_rsdt, rsdp_find_rsdt );