1 #include <linux/types.h>
2 #include <linux/string.h>
3 #include <linux/init.h>
4 #include <linux/module.h>
6 #include <linux/bootmem.h>
7 #include <linux/slab.h>
10 static char * __init dmi_string(struct dmi_header *dm, u8 s)
12 u8 *bp = ((u8 *) dm) + dm->length;
17 while (s > 0 && *bp) {
23 str = dmi_alloc(strlen(bp) + 1);
27 printk(KERN_ERR "dmi_string: out of memory.\n");
35 * We have to be cautious here. We have seen BIOSes with DMI pointers
36 * pointing to completely the wrong place for example
38 static int __init dmi_table(u32 base, int len, int num,
39 void (*decode)(struct dmi_header *))
44 buf = dmi_ioremap(base, len);
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)
54 while ((i < num) && (data - buf + sizeof(struct dmi_header)) <= len) {
55 struct dmi_header *dm = (struct dmi_header *)data;
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
62 while ((data - buf < len - 1) && (data[0] || data[1]))
64 if (data - buf < len - 1)
69 dmi_iounmap(buf, len);
73 static int __init dmi_checksum(u8 *buf)
78 for (a = 0; a < 15; a++)
84 static char *dmi_ident[DMI_STRING_MAX];
85 static LIST_HEAD(dmi_devices);
90 static void __init dmi_save_ident(struct dmi_header *dm, int slot, int string)
92 char *p, *d = (char*) dm;
97 p = dmi_string(dm, d[string]);
104 static void __init dmi_save_devices(struct dmi_header *dm)
106 int i, count = (dm->length - sizeof(struct dmi_header)) / 2;
107 struct dmi_device *dev;
109 for (i = 0; i < count; i++) {
110 char *d = (char *)(dm + 1) + (i * 2);
112 /* Skip disabled device */
113 if ((*d & 0x80) == 0)
116 dev = dmi_alloc(sizeof(*dev));
118 printk(KERN_ERR "dmi_save_devices: out of memory.\n");
122 dev->type = *d++ & 0x7f;
123 dev->name = dmi_string(dm, *d);
124 dev->device_data = NULL;
126 list_add(&dev->list, &dmi_devices);
130 static void __init dmi_save_ipmi_device(struct dmi_header *dm)
132 struct dmi_device *dev;
135 data = dmi_alloc(dm->length);
137 printk(KERN_ERR "dmi_save_ipmi_device: out of memory.\n");
141 memcpy(data, dm, dm->length);
143 dev = dmi_alloc(sizeof(*dev));
145 printk(KERN_ERR "dmi_save_ipmi_device: out of memory.\n");
149 dev->type = DMI_DEV_TYPE_IPMI;
150 dev->name = "IPMI controller";
151 dev->device_data = data;
153 list_add(&dev->list, &dmi_devices);
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
161 static void __init dmi_decode(struct dmi_header *dm)
164 case 0: /* BIOS Information */
165 dmi_save_ident(dm, DMI_BIOS_VENDOR, 4);
166 dmi_save_ident(dm, DMI_BIOS_VERSION, 5);
167 dmi_save_ident(dm, DMI_BIOS_DATE, 8);
169 case 1: /* System Information */
170 dmi_save_ident(dm, DMI_SYS_VENDOR, 4);
171 dmi_save_ident(dm, DMI_PRODUCT_NAME, 5);
172 dmi_save_ident(dm, DMI_PRODUCT_VERSION, 6);
173 dmi_save_ident(dm, DMI_PRODUCT_SERIAL, 7);
175 case 2: /* Base Board Information */
176 dmi_save_ident(dm, DMI_BOARD_VENDOR, 4);
177 dmi_save_ident(dm, DMI_BOARD_NAME, 5);
178 dmi_save_ident(dm, DMI_BOARD_VERSION, 6);
180 case 10: /* Onboard Devices Information */
181 dmi_save_devices(dm);
183 case 38: /* IPMI Device Information */
184 dmi_save_ipmi_device(dm);
188 void __init dmi_scan_machine(void)
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.
198 p = ioremap(0xF0000, 0x10000);
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];
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.
215 printk(KERN_INFO "DMI %d.%d present.\n",
216 buf[14] >> 4, buf[14] & 0xF);
218 printk(KERN_INFO "DMI present.\n");
220 if (dmi_table(base,len, num, dmi_decode) == 0)
225 out: printk(KERN_INFO "DMI not present or invalid.\n");
230 * dmi_check_system - check system DMI data
231 * @list: array of dmi_system_id structures to match against
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.
237 int dmi_check_system(struct dmi_system_id *list)
240 struct dmi_system_id *d = list;
243 for (i = 0; i < ARRAY_SIZE(d->matches); i++) {
244 int s = d->matches[i].slot;
247 if (dmi_ident[s] && strstr(dmi_ident[s], d->matches[i].substr))
253 if (d->callback && d->callback(d))
260 EXPORT_SYMBOL(dmi_check_system);
263 * dmi_get_system_info - return DMI data value
264 * @field: data index (see enum dmi_filed)
266 * Returns one DMI data value, can be used to perform
267 * complex DMI data checks.
269 char *dmi_get_system_info(int field)
271 return dmi_ident[field];
273 EXPORT_SYMBOL(dmi_get_system_info);
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.
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.
287 struct dmi_device * dmi_find_device(int type, const char *name,
288 struct dmi_device *from)
290 struct list_head *d, *head = from ? &from->list : &dmi_devices;
292 for(d = head->next; d != &dmi_devices; d = d->next) {
293 struct dmi_device *dev = list_entry(d, struct dmi_device, list);
295 if (((type == DMI_DEV_TYPE_ANY) || (dev->type == type)) &&
296 ((name == NULL) || (strcmp(dev->name, name) == 0)))
302 EXPORT_SYMBOL(dmi_find_device);
305 * dmi_get_year - Return year of a DMI date
306 * @field: data index (like dmi_get_system_info)
308 * Returns -1 when the field doesn't exist. 0 when it is broken.
310 int dmi_get_year(int field)
313 char *s = dmi_get_system_info(field);
324 year = simple_strtoul(s, NULL, 0);
325 if (year && year < 100) { /* 2-digit year */
327 if (year < 1996) /* no dates < spec 1.0 */