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