1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
/*
* Copyright (C) 2013 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
FILE_LICENCE ( GPL2_OR_LATER );
#include <string.h>
#include <errno.h>
#include <ipxe/linux_api.h>
#include <ipxe/linux_sysfs.h>
#include <ipxe/linux.h>
#include <ipxe/umalloc.h>
#include <ipxe/init.h>
#include <ipxe/smbios.h>
/** SMBIOS entry point filename */
static const char smbios_entry_filename[] =
"/sys/firmware/dmi/tables/smbios_entry_point";
/** SMBIOS filename */
static const char smbios_filename[] = "/sys/firmware/dmi/tables/DMI";
/** Cache SMBIOS data */
static void *smbios_data;
/**
* Find SMBIOS
*
* @v smbios SMBIOS entry point descriptor structure to fill in
* @ret rc Return status code
*/
static int linux_find_smbios ( struct smbios *smbios ) {
struct smbios3_entry *smbios3_entry;
struct smbios_entry *smbios_entry;
void *entry;
void *data;
int len;
int rc;
/* Read entry point file */
len = linux_sysfs_read ( smbios_entry_filename, &entry );
if ( len < 0 ) {
rc = len;
DBGC ( smbios, "SMBIOS could not read %s: %s\n",
smbios_entry_filename, strerror ( rc ) );
goto err_entry;
}
data = entry;
smbios3_entry = data;
smbios_entry = data;
if ( ( len >= ( ( int ) sizeof ( *smbios3_entry ) ) ) &&
( smbios3_entry->signature == SMBIOS3_SIGNATURE ) ) {
smbios->version = SMBIOS_VERSION ( smbios3_entry->major,
smbios3_entry->minor );
} else if ( ( len >= ( ( int ) sizeof ( *smbios_entry ) ) ) &&
( smbios_entry->signature == SMBIOS_SIGNATURE ) ) {
smbios->version = SMBIOS_VERSION ( smbios_entry->major,
smbios_entry->minor );
} else {
DBGC ( smbios, "SMBIOS invalid entry point %s:\n",
smbios_entry_filename );
DBGC_HDA ( smbios, 0, data, len );
rc = -EINVAL;
goto err_version;
}
/* Read SMBIOS file */
len = linux_sysfs_read ( smbios_filename, &smbios_data );
if ( len < 0 ) {
rc = len;
DBGC ( smbios, "SMBIOS could not read %s: %s\n",
smbios_filename, strerror ( rc ) );
goto err_read;
}
/* Populate SMBIOS descriptor */
smbios->address = smbios_data;
smbios->len = len;
smbios->count = 0;
/* Free entry point */
ufree ( entry );
return 0;
ufree ( smbios_data );
smbios_data = NULL;
err_read:
err_version:
ufree ( entry );
err_entry:
return rc;
}
/**
* Free cached SMBIOS data
*
*/
static void linux_smbios_shutdown ( int booting __unused ) {
/* Clear SMBIOS data pointer */
smbios_clear();
/* Free SMBIOS data */
ufree ( smbios_data );
smbios_data = NULL;
}
/** SMBIOS shutdown function */
struct startup_fn linux_smbios_startup_fn __startup_fn ( STARTUP_NORMAL ) = {
.name = "linux_smbios",
.shutdown = linux_smbios_shutdown,
};
PROVIDE_SMBIOS ( linux, find_smbios, linux_find_smbios );
|