iPXE
bios_smbios.c
Go to the documentation of this file.
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 * 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
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
26#include <stdint.h>
27#include <string.h>
28#include <errno.h>
29#include <assert.h>
30#include <ipxe/uaccess.h>
31#include <ipxe/smbios.h>
32#include <realmode.h>
33#include <pnpbios.h>
34
35/** @file
36 *
37 * System Management BIOS
38 *
39 */
40
41/**
42 * Find SMBIOS
43 *
44 * @v smbios SMBIOS entry point descriptor structure to fill in
45 * @ret rc Return status code
46 */
47static int bios_find_smbios2 ( struct smbios *smbios ) {
48 const struct smbios_entry *entry;
49
50 /* Scan through BIOS segment to find SMBIOS 32-bit entry point */
51 entry = find_smbios_entry ( real_to_virt ( BIOS_SEG, 0 ), 0x10000 );
52 if ( ! entry )
53 return -ENOENT;
54
55 /* Fill in entry point descriptor structure */
56 smbios->address = phys_to_virt ( entry->smbios_address );
57 smbios->len = entry->smbios_len;
58 smbios->count = entry->smbios_count;
59 smbios->version = SMBIOS_VERSION ( entry->major, entry->minor );
60
61 return 0;
62}
63
64/**
65 * Find SMBIOS
66 *
67 * @v smbios SMBIOS entry point descriptor structure to fill in
68 * @ret rc Return status code
69 */
70static int bios_find_smbios3 ( struct smbios *smbios ) {
71 const struct smbios3_entry *entry;
72
73 /* Scan through BIOS segment to find SMBIOS 64-bit entry point */
74 entry = find_smbios3_entry ( real_to_virt ( BIOS_SEG, 0 ), 0x10000 );
75 if ( ! entry )
76 return -ENOENT;
77
78 /* Check that address is accessible */
79 if ( entry->smbios_address > ~( ( physaddr_t ) 0 ) ) {
80 DBG ( "SMBIOS3 at %08llx is inaccessible\n",
81 ( ( unsigned long long ) entry->smbios_address ) );
82 return -ENOTSUP;
83 }
84
85 /* Fill in entry point descriptor structure */
86 smbios->address = phys_to_virt ( entry->smbios_address );
87 smbios->len = entry->smbios_len;
88 smbios->count = 0;
89 smbios->version = SMBIOS_VERSION ( entry->major, entry->minor );
90
91 return 0;
92}
93
94/**
95 * Find SMBIOS
96 *
97 * @v smbios SMBIOS entry point descriptor structure to fill in
98 * @ret rc Return status code
99 */
100static int bios_find_smbios ( struct smbios *smbios ) {
101 int rc;
102
103 /* Use 32-bit table if present */
104 if ( ( rc = bios_find_smbios2 ( smbios ) ) == 0 )
105 return 0;
106
107 /* Otherwise, use 64-bit table if present and accessible */
108 if ( ( rc = bios_find_smbios3 ( smbios ) ) == 0 )
109 return 0;
110
111 return rc;
112}
113
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
unsigned long physaddr_t
Definition stdint.h:20
Assertions.
static int bios_find_smbios(struct smbios *smbios)
Find SMBIOS.
static int bios_find_smbios2(struct smbios *smbios)
Find SMBIOS.
Definition bios_smbios.c:47
static int bios_find_smbios3(struct smbios *smbios)
Find SMBIOS.
Definition bios_smbios.c:70
Error codes.
#define DBG(...)
Print a debugging message.
Definition compiler.h:498
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define ENOENT
No such file or directory.
Definition errno.h:515
#define ENOTSUP
Operation not supported.
Definition errno.h:590
System Management BIOS.
int find_smbios(struct smbios *smbios)
#define PROVIDE_SMBIOS(_subsys, _api_func, _func)
Provide an SMBIOS API implementation.
Definition smbios.h:24
#define SMBIOS_VERSION(major, minor)
Calculate SMBIOS version.
Definition smbios.h:216
String functions.
Access to external ("user") memory.
PnP BIOS.
#define BIOS_SEG
Definition pnpbios.h:13
static __always_inline void * real_to_virt(unsigned int segment, unsigned int offset)
Convert segment:offset address to virtual address.
Definition realmode.h:77
const struct smbios_entry * find_smbios_entry(const void *start, size_t len)
Scan for SMBIOS 32-bit entry point structure.
Definition smbios.c:70
const struct smbios3_entry * find_smbios3_entry(const void *start, size_t len)
Scan for SMBIOS 64-bit entry point structure.
Definition smbios.c:116
SMBIOS 64-bit entry point.
Definition smbios.h:91
uint8_t major
Major version.
Definition smbios.h:104
uint64_t smbios_address
Structure table address.
Definition smbios.h:116
uint8_t minor
Minor version.
Definition smbios.h:106
uint32_t smbios_len
Structure table length.
Definition smbios.h:114
SMBIOS 32-bit entry point.
Definition smbios.h:50
uint32_t smbios_address
Structure table address.
Definition smbios.h:77
uint8_t minor
Minor version.
Definition smbios.h:63
uint16_t smbios_count
Number of SMBIOS structures.
Definition smbios.h:79
uint16_t smbios_len
Structure table length.
Definition smbios.h:75
uint8_t major
Major version.
Definition smbios.h:61
SMBIOS entry point descriptor.
Definition smbios.h:198
size_t len
Length of SMBIOS structures.
Definition smbios.h:202
unsigned int count
Number of SMBIOS structures.
Definition smbios.h:204
uint16_t version
SMBIOS version.
Definition smbios.h:206
const void * address
Start of SMBIOS structures.
Definition smbios.h:200