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.

bios_smbios.c 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (C) 2007 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. FILE_LICENCE ( GPL2_OR_LATER );
  20. #include <stdint.h>
  21. #include <string.h>
  22. #include <errno.h>
  23. #include <assert.h>
  24. #include <ipxe/uaccess.h>
  25. #include <ipxe/smbios.h>
  26. #include <realmode.h>
  27. #include <pnpbios.h>
  28. /** @file
  29. *
  30. * System Management BIOS
  31. *
  32. */
  33. /**
  34. * Find SMBIOS
  35. *
  36. * @v smbios SMBIOS entry point descriptor structure to fill in
  37. * @ret rc Return status code
  38. */
  39. static int bios_find_smbios ( struct smbios *smbios ) {
  40. union {
  41. struct smbios_entry entry;
  42. uint8_t bytes[256]; /* 256 is maximum length possible */
  43. } u;
  44. static unsigned int offset = 0;
  45. size_t len;
  46. unsigned int i;
  47. uint8_t sum;
  48. /* Try to find SMBIOS */
  49. for ( ; offset < 0x10000 ; offset += 0x10 ) {
  50. /* Read start of header and verify signature */
  51. copy_from_real ( &u.entry, BIOS_SEG, offset,
  52. sizeof ( u.entry ));
  53. if ( u.entry.signature != SMBIOS_SIGNATURE )
  54. continue;
  55. /* Read whole header and verify checksum */
  56. len = u.entry.len;
  57. copy_from_real ( &u.bytes, BIOS_SEG, offset, len );
  58. for ( i = 0 , sum = 0 ; i < len ; i++ ) {
  59. sum += u.bytes[i];
  60. }
  61. if ( sum != 0 ) {
  62. DBG ( "SMBIOS at %04x:%04x has bad checksum %02x\n",
  63. BIOS_SEG, offset, sum );
  64. continue;
  65. }
  66. /* Fill result structure */
  67. DBG ( "Found SMBIOS v%d.%d entry point at %04x:%04x\n",
  68. u.entry.major, u.entry.minor, BIOS_SEG, offset );
  69. smbios->address = phys_to_user ( u.entry.smbios_address );
  70. smbios->len = u.entry.smbios_len;
  71. smbios->count = u.entry.smbios_count;
  72. return 0;
  73. }
  74. DBG ( "No SMBIOS found\n" );
  75. return -ENODEV;
  76. }
  77. PROVIDE_SMBIOS ( pcbios, find_smbios, bios_find_smbios );