[PATCH] i386: export: memory more than 4G through /proc/iomem
[linux-2.6-block.git] / arch / i386 / kernel / dmi_scan.c
CommitLineData
1da177e4 1#include <linux/types.h>
1da177e4
LT
2#include <linux/string.h>
3#include <linux/init.h>
4#include <linux/module.h>
1da177e4
LT
5#include <linux/dmi.h>
6#include <linux/bootmem.h>
e9928674 7#include <linux/slab.h>
f2d3efed 8#include <asm/dmi.h>
1da177e4 9
1da177e4
LT
10static char * __init dmi_string(struct dmi_header *dm, u8 s)
11{
1249c513 12 u8 *bp = ((u8 *) dm) + dm->length;
c3c7120d 13 char *str = "";
1249c513 14
c3c7120d 15 if (s) {
1da177e4 16 s--;
c3c7120d
AP
17 while (s > 0 && *bp) {
18 bp += strlen(bp) + 1;
19 s--;
20 }
21
22 if (*bp != 0) {
e9928674 23 str = dmi_alloc(strlen(bp) + 1);
c3c7120d
AP
24 if (str != NULL)
25 strcpy(str, bp);
26 else
27 printk(KERN_ERR "dmi_string: out of memory.\n");
28 }
29 }
30
31 return str;
1da177e4
LT
32}
33
34/*
35 * We have to be cautious here. We have seen BIOSes with DMI pointers
36 * pointing to completely the wrong place for example
37 */
1249c513
AP
38static int __init dmi_table(u32 base, int len, int num,
39 void (*decode)(struct dmi_header *))
1da177e4 40{
1249c513
AP
41 u8 *buf, *data;
42 int i = 0;
1da177e4 43
e9928674 44 buf = dmi_ioremap(base, len);
1249c513 45 if (buf == NULL)
1da177e4
LT
46 return -1;
47
48 data = buf;
49
50 /*
51 * Stop when we see all the items the table claimed to have
52 * OR we run off the end of the table (also happens)
53 */
1249c513
AP
54 while ((i < num) && (data - buf + sizeof(struct dmi_header)) <= len) {
55 struct dmi_header *dm = (struct dmi_header *)data;
1da177e4
LT
56 /*
57 * We want to know the total length (formated area and strings)
58 * before decoding to make sure we won't run off the table in
59 * dmi_decode or dmi_string
60 */
1249c513
AP
61 data += dm->length;
62 while ((data - buf < len - 1) && (data[0] || data[1]))
1da177e4 63 data++;
1249c513 64 if (data - buf < len - 1)
1da177e4 65 decode(dm);
1249c513 66 data += 2;
1da177e4
LT
67 i++;
68 }
e9928674 69 dmi_iounmap(buf, len);
1da177e4
LT
70 return 0;
71}
72
1249c513 73static int __init dmi_checksum(u8 *buf)
1da177e4 74{
1249c513 75 u8 sum = 0;
1da177e4
LT
76 int a;
77
1249c513
AP
78 for (a = 0; a < 15; a++)
79 sum += buf[a];
80
81 return sum == 0;
1da177e4
LT
82}
83
1da177e4 84static char *dmi_ident[DMI_STRING_MAX];
ebad6a42 85static LIST_HEAD(dmi_devices);
1da177e4
LT
86
87/*
88 * Save a DMI string
89 */
1da177e4
LT
90static void __init dmi_save_ident(struct dmi_header *dm, int slot, int string)
91{
c3c7120d 92 char *p, *d = (char*) dm;
1249c513 93
1da177e4
LT
94 if (dmi_ident[slot])
95 return;
1249c513 96
c3c7120d
AP
97 p = dmi_string(dm, d[string]);
98 if (p == NULL)
99 return;
100
101 dmi_ident[slot] = p;
1da177e4
LT
102}
103
ebad6a42
AP
104static void __init dmi_save_devices(struct dmi_header *dm)
105{
106 int i, count = (dm->length - sizeof(struct dmi_header)) / 2;
107 struct dmi_device *dev;
108
109 for (i = 0; i < count; i++) {
bc83455b 110 char *d = (char *)(dm + 1) + (i * 2);
ebad6a42
AP
111
112 /* Skip disabled device */
113 if ((*d & 0x80) == 0)
114 continue;
115
e9928674 116 dev = dmi_alloc(sizeof(*dev));
ebad6a42
AP
117 if (!dev) {
118 printk(KERN_ERR "dmi_save_devices: out of memory.\n");
119 break;
120 }
121
122 dev->type = *d++ & 0x7f;
123 dev->name = dmi_string(dm, *d);
124 dev->device_data = NULL;
125
126 list_add(&dev->list, &dmi_devices);
127 }
128}
129
130static void __init dmi_save_ipmi_device(struct dmi_header *dm)
131{
132 struct dmi_device *dev;
133 void * data;
134
e9928674 135 data = dmi_alloc(dm->length);
ebad6a42
AP
136 if (data == NULL) {
137 printk(KERN_ERR "dmi_save_ipmi_device: out of memory.\n");
138 return;
139 }
140
141 memcpy(data, dm, dm->length);
142
e9928674 143 dev = dmi_alloc(sizeof(*dev));
ebad6a42
AP
144 if (!dev) {
145 printk(KERN_ERR "dmi_save_ipmi_device: out of memory.\n");
146 return;
147 }
148
149 dev->type = DMI_DEV_TYPE_IPMI;
150 dev->name = "IPMI controller";
151 dev->device_data = data;
152
153 list_add(&dev->list, &dmi_devices);
154}
155
1da177e4
LT
156/*
157 * Process a DMI table entry. Right now all we care about are the BIOS
158 * and machine entries. For 2.5 we should pull the smbus controller info
159 * out of here.
160 */
1da177e4
LT
161static void __init dmi_decode(struct dmi_header *dm)
162{
1249c513 163 switch(dm->type) {
ebad6a42 164 case 0: /* BIOS Information */
1249c513 165 dmi_save_ident(dm, DMI_BIOS_VENDOR, 4);
1249c513 166 dmi_save_ident(dm, DMI_BIOS_VERSION, 5);
1249c513
AP
167 dmi_save_ident(dm, DMI_BIOS_DATE, 8);
168 break;
ebad6a42 169 case 1: /* System Information */
1249c513 170 dmi_save_ident(dm, DMI_SYS_VENDOR, 4);
1249c513 171 dmi_save_ident(dm, DMI_PRODUCT_NAME, 5);
1249c513 172 dmi_save_ident(dm, DMI_PRODUCT_VERSION, 6);
1249c513
AP
173 dmi_save_ident(dm, DMI_PRODUCT_SERIAL, 7);
174 break;
ebad6a42 175 case 2: /* Base Board Information */
1249c513 176 dmi_save_ident(dm, DMI_BOARD_VENDOR, 4);
1249c513 177 dmi_save_ident(dm, DMI_BOARD_NAME, 5);
1249c513
AP
178 dmi_save_ident(dm, DMI_BOARD_VERSION, 6);
179 break;
ebad6a42
AP
180 case 10: /* Onboard Devices Information */
181 dmi_save_devices(dm);
182 break;
183 case 38: /* IPMI Device Information */
184 dmi_save_ipmi_device(dm);
1da177e4
LT
185 }
186}
187
188void __init dmi_scan_machine(void)
189{
61e032fa
AP
190 u8 buf[15];
191 char __iomem *p, *q;
192
193 /*
194 * no iounmap() for that ioremap(); it would be a no-op, but it's
195 * so early in setup that sucker gets confused into doing what
196 * it shouldn't if we actually call it.
197 */
198 p = ioremap(0xF0000, 0x10000);
199 if (p == NULL)
200 goto out;
201
202 for (q = p; q < p + 0x10000; q += 16) {
203 memcpy_fromio(buf, q, 15);
204 if ((memcmp(buf, "_DMI_", 5) == 0) && dmi_checksum(buf)) {
205 u16 num = (buf[13] << 8) | buf[12];
206 u16 len = (buf[7] << 8) | buf[6];
207 u32 base = (buf[11] << 24) | (buf[10] << 16) |
208 (buf[9] << 8) | buf[8];
209
210 /*
211 * DMI version 0.0 means that the real version is taken from
212 * the SMBIOS version, which we don't know at this point.
213 */
214 if (buf[14] != 0)
215 printk(KERN_INFO "DMI %d.%d present.\n",
216 buf[14] >> 4, buf[14] & 0xF);
217 else
218 printk(KERN_INFO "DMI present.\n");
219
61e032fa
AP
220 if (dmi_table(base,len, num, dmi_decode) == 0)
221 return;
222 }
223 }
224
e9928674 225out: printk(KERN_INFO "DMI not present or invalid.\n");
1da177e4
LT
226}
227
228
229/**
230 * dmi_check_system - check system DMI data
231 * @list: array of dmi_system_id structures to match against
232 *
233 * Walk the blacklist table running matching functions until someone
234 * returns non zero or we hit the end. Callback function is called for
235 * each successfull match. Returns the number of matches.
236 */
237int dmi_check_system(struct dmi_system_id *list)
238{
239 int i, count = 0;
240 struct dmi_system_id *d = list;
241
242 while (d->ident) {
243 for (i = 0; i < ARRAY_SIZE(d->matches); i++) {
244 int s = d->matches[i].slot;
245 if (s == DMI_NONE)
246 continue;
247 if (dmi_ident[s] && strstr(dmi_ident[s], d->matches[i].substr))
248 continue;
249 /* No match */
250 goto fail;
251 }
640e8033 252 count++;
1da177e4
LT
253 if (d->callback && d->callback(d))
254 break;
1da177e4
LT
255fail: d++;
256 }
257
258 return count;
259}
1da177e4
LT
260EXPORT_SYMBOL(dmi_check_system);
261
262/**
263 * dmi_get_system_info - return DMI data value
264 * @field: data index (see enum dmi_filed)
265 *
266 * Returns one DMI data value, can be used to perform
267 * complex DMI data checks.
268 */
e70c9d5e 269char *dmi_get_system_info(int field)
1da177e4
LT
270{
271 return dmi_ident[field];
272}
e70c9d5e 273EXPORT_SYMBOL(dmi_get_system_info);
ebad6a42
AP
274
275/**
276 * dmi_find_device - find onboard device by type/name
277 * @type: device type or %DMI_DEV_TYPE_ANY to match all device types
278 * @desc: device name string or %NULL to match all
279 * @from: previous device found in search, or %NULL for new search.
280 *
281 * Iterates through the list of known onboard devices. If a device is
282 * found with a matching @vendor and @device, a pointer to its device
283 * structure is returned. Otherwise, %NULL is returned.
284 * A new search is initiated by passing %NULL to the @from argument.
285 * If @from is not %NULL, searches continue from next device.
286 */
287struct dmi_device * dmi_find_device(int type, const char *name,
288 struct dmi_device *from)
289{
290 struct list_head *d, *head = from ? &from->list : &dmi_devices;
291
292 for(d = head->next; d != &dmi_devices; d = d->next) {
293 struct dmi_device *dev = list_entry(d, struct dmi_device, list);
294
295 if (((type == DMI_DEV_TYPE_ANY) || (dev->type == type)) &&
296 ((name == NULL) || (strcmp(dev->name, name) == 0)))
297 return dev;
298 }
299
300 return NULL;
301}
302EXPORT_SYMBOL(dmi_find_device);
f083a329
AK
303
304/**
305 * dmi_get_year - Return year of a DMI date
306 * @field: data index (like dmi_get_system_info)
307 *
308 * Returns -1 when the field doesn't exist. 0 when it is broken.
309 */
310int dmi_get_year(int field)
311{
312 int year;
313 char *s = dmi_get_system_info(field);
314
315 if (!s)
316 return -1;
317 if (*s == '\0')
318 return 0;
319 s = strrchr(s, '/');
320 if (!s)
321 return 0;
322
323 s += 1;
324 year = simple_strtoul(s, NULL, 0);
325 if (year && year < 100) { /* 2-digit year */
326 year += 1900;
327 if (year < 1996) /* no dates < spec 1.0 */
328 year += 100;
329 }
330
331 return year;
332}