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

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