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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
/*-
* Copyright (c) 1997 Michael Smith
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: bios.c,v 1.9 1998/01/01 13:26:55 msmith Exp $
*/
/*
* Code for dealing with the BIOS in x86 PC systems.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <vm/vm.h>
#include <vm/pmap.h>
#include <machine/md_var.h>
#include <machine/pc/bios.h>
#define BIOS_START 0xe0000
#define BIOS_SIZE 0x20000
/* exported lookup results */
struct bios32_SDentry PCIbios = {entry : 0};
static struct SMBIOS_table *SMBIOStable = 0;
static struct DMI_table *DMItable = 0;
static caddr_t bios32_SDCI = NULL;
static void bios32_init(void *junk);
/* start fairly early */
SYSINIT(bios32, SI_SUB_CPU, SI_ORDER_ANY, bios32_init, NULL);
/*
* bios32_init
*
* Locate various bios32 entities.
*/
static void
bios32_init(void *junk)
{
u_long sigaddr;
struct bios32_SDheader *sdh;
struct SMBIOS_table *sbt;
struct DMI_table *dmit;
u_int8_t ck, *cv;
int i;
/*
* BIOS32 Service Directory
*/
/* look for the signature */
if ((sigaddr = bios_sigsearch(0, "_32_", 4, 16, 0)) != 0) {
/* get a virtual pointer to the structure */
sdh = (struct bios32_SDheader *)BIOS_PADDRTOVADDR(sigaddr);
for (cv = (u_int8_t *)sdh, ck = 0, i = 0; i < (sdh->len * 16); i++) {
ck += cv[i];
}
/* If checksum is OK, enable use of the entrypoint */
if ((ck == 0) && (sdh->entry < (BIOS_START + BIOS_SIZE))) {
bios32_SDCI = (caddr_t)BIOS_PADDRTOVADDR(sdh->entry);
if (bootverbose) {
printf("Found BIOS32 Service Directory header at %p\n", sdh);
printf("Entry = 0x%x (%p) Rev = %d Len = %d\n",
sdh->entry, bios32_SDCI, sdh->revision, sdh->len);
}
/* See if there's a PCI BIOS entrypoint here */
PCIbios.ident.id = 0x49435024; /* PCI systems should have this */
if (!bios32_SDlookup(&PCIbios) && bootverbose)
printf("PCI BIOS entry at 0x%x\n", PCIbios.entry);
} else {
printf("Bad BIOS32 Service Directory!\n");
}
}
/*
* System Management BIOS
*/
/* look for the SMBIOS signature */
if ((sigaddr = bios_sigsearch(0, "_SM_", 4, 16, 0)) != 0) {
/* get a virtual pointer to the structure */
sbt = (struct SMBIOS_table *)BIOS_PADDRTOVADDR(sigaddr);
for (cv = (u_int8_t *)sbt, ck = 0, i = 0; i < sbt->len; i++) {
ck += cv[i];
}
/* if checksum is OK, we have action */
if (ck == 0) {
SMBIOStable = sbt; /* save reference */
DMItable = &sbt->dmi; /* contained within */
if (bootverbose) {
printf("SMIBIOS header at %p\n", sbt);
printf("Version %d.%d\n", sbt->major, sbt->minor);
printf("Table at 0x%x, %d entries, %d bytes, largest entry %d bytes\n",
sbt->dmi.st_base, (int)sbt->dmi.st_entries, (int)sbt->dmi.st_size,
(int)sbt->st_maxsize);
}
} else {
printf("Bad SMBIOS table checksum!\n");
}
}
/* look for the DMI signature */
if ((sigaddr = bios_sigsearch(0, "_DMI_", 5, 16, 0)) != 0) {
/* get a virtual pointer to the structure */
dmit = (struct DMI_table *)BIOS_PADDRTOVADDR(sigaddr);
for (cv = (u_int8_t *)dmit, ck = 0, i = 0; i < 15; i++) {
ck += cv[i];
}
/* if checksum is OK, we have action */
if (ck == 0) {
DMItable = dmit; /* save reference */
if (bootverbose) {
printf("DMI header at %p\n", dmit);
printf("Version %d.%d\n", (dmit->bcd_revision >> 4),
(dmit->bcd_revision & 0x0f));
printf("Table at 0x%x, %d entries, %d bytes\n",
dmit->st_base, (int)dmit->st_entries,
(int)dmit->st_size);
}
} else {
printf("Bad DMI table checksum!\n");
}
}
if (bootverbose) {
/* look for other know signatures */
printf("Other BIOS signatures found:\n");
printf("ACPI: %08x\n", bios_sigsearch(0, "FACP", 4, 1, 0));
printf("$PnP: %08x\n", bios_sigsearch(0, "$PnP", 4, 16, 0));
}
}
/*
* bios32_SDlookup
*
* Query the BIOS32 Service Directory for the service named in (ent),
* returns nonzero if the lookup fails. The caller must fill in
* (ent->ident), the remainder are populated on a successful lookup.
*/
int
bios32_SDlookup(struct bios32_SDentry *ent)
{
struct bios32_args args;
if (bios32_SDCI != NULL) {
args.eax = ent->ident.id; /* set up arguments */
args.ebx = args.ecx = args.edx = 0;
bios32(bios32_SDCI, &args); /* make the BIOS call */
if ((args.eax & 0xff) == 0) { /* success? */
ent->base = args.ebx;
ent->len = args.ecx;
ent->entry = args.edx;
return(0); /* all OK */
}
}
return(1); /* failed */
}
/*
* bios_sigsearch
*
* Search some or all of the BIOS region for a signature string.
*
* (start) Optional offset returned from this function
* (for searching for multiple matches), or NULL
* to start the search from the base of the BIOS.
* Note that this will be a _physical_ address in
* the range 0xe0000 - 0xfffff.
* (sig) is a pointer to the byte(s) of the signature.
* (siglen) number of bytes in the signature.
* (paralen) signature paragraph (alignment) size.
* (sigofs) offset of the signature within the paragraph.
*
* Returns the _physical_ address of the found signature, 0 if the
* signature was not found.
*/
u_int32_t
bios_sigsearch(u_int32_t start, u_char *sig, int siglen, int paralen, int sigofs)
{
u_char *sp, *end;
/* compute the starting address */
if ((start >= BIOS_START) && (start <= (BIOS_START + BIOS_SIZE))) {
sp = (char *)BIOS_PADDRTOVADDR(start);
} else if (start == 0) {
sp = (char *)BIOS_PADDRTOVADDR(BIOS_START);
} else {
return 0; /* bogus start address */
}
/* compute the end address */
end = (u_char *)BIOS_PADDRTOVADDR(BIOS_START + BIOS_SIZE);
/* loop searching */
while ((sp + sigofs + siglen) < end) {
/* compare here */
if (!bcmp(sp + sigofs, sig, siglen)) {
/* convert back to physical address */
return((u_int32_t)BIOS_VADDRTOPADDR(sp));
}
sp += paralen;
}
return(0);
}
|