bios_smbios.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00018 
00019 FILE_LICENCE ( GPL2_OR_LATER );
00020 
00021 #include <stdint.h>
00022 #include <string.h>
00023 #include <errno.h>
00024 #include <assert.h>
00025 #include <gpxe/uaccess.h>
00026 #include <gpxe/smbios.h>
00027 #include <realmode.h>
00028 #include <pnpbios.h>
00029 
00030 /** @file
00031  *
00032  * System Management BIOS
00033  *
00034  */
00035 
00036 /**
00037  * Find SMBIOS
00038  *
00039  * @v smbios            SMBIOS entry point descriptor structure to fill in
00040  * @ret rc              Return status code
00041  */
00042 static int bios_find_smbios ( struct smbios *smbios ) {
00043         union {
00044                 struct smbios_entry entry;
00045                 uint8_t bytes[256]; /* 256 is maximum length possible */
00046         } u;
00047         static unsigned int offset = 0;
00048         size_t len;
00049         unsigned int i;
00050         uint8_t sum;
00051 
00052         /* Try to find SMBIOS */
00053         for ( ; offset < 0x10000 ; offset += 0x10 ) {
00054 
00055                 /* Read start of header and verify signature */
00056                 copy_from_real ( &u.entry, BIOS_SEG, offset,
00057                                  sizeof ( u.entry ));
00058                 if ( u.entry.signature != SMBIOS_SIGNATURE )
00059                         continue;
00060 
00061                 /* Read whole header and verify checksum */
00062                 len = u.entry.len;
00063                 copy_from_real ( &u.bytes, BIOS_SEG, offset, len );
00064                 for ( i = 0 , sum = 0 ; i < len ; i++ ) {
00065                         sum += u.bytes[i];
00066                 }
00067                 if ( sum != 0 ) {
00068                         DBG ( "SMBIOS at %04x:%04x has bad checksum %02x\n",
00069                               BIOS_SEG, offset, sum );
00070                         continue;
00071                 }
00072 
00073                 /* Fill result structure */
00074                 DBG ( "Found SMBIOS v%d.%d entry point at %04x:%04x\n",
00075                       u.entry.major, u.entry.minor, BIOS_SEG, offset );
00076                 smbios->address = phys_to_user ( u.entry.smbios_address );
00077                 smbios->len = u.entry.smbios_len;
00078                 smbios->count = u.entry.smbios_count;
00079                 return 0;
00080         }
00081 
00082         DBG ( "No SMBIOS found\n" );
00083         return -ENODEV;
00084 }
00085 
00086 PROVIDE_SMBIOS ( pcbios, find_smbios, bios_find_smbios );

Generated on Tue Apr 6 20:00:50 2010 for gPXE by  doxygen 1.5.7.1