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>
16 static char * __init dmi_string(struct dmi_header *dm, u8 s)
18 u8 *bp = ((u8 *) dm) + dm->length;
23 while (s > 0 && *bp) {
29 str = alloc_bootmem(strlen(bp) + 1);
33 printk(KERN_ERR "dmi_string: out of memory.\n");
41 * We have to be cautious here. We have seen BIOSes with DMI pointers
42 * pointing to completely the wrong place for example
44 static int __init dmi_table(u32 base, int len, int num,
45 void (*decode)(struct dmi_header *))
50 buf = bt_ioremap(base, len);
57 * Stop when we see all the items the table claimed to have
58 * OR we run off the end of the table (also happens)
60 while ((i < num) && (data - buf + sizeof(struct dmi_header)) <= len) {
61 struct dmi_header *dm = (struct dmi_header *)data;
63 * We want to know the total length (formated area and strings)
64 * before decoding to make sure we won't run off the table in
65 * dmi_decode or dmi_string
68 while ((data - buf < len - 1) && (data[0] || data[1]))
70 if (data - buf < len - 1)
79 static int __init dmi_checksum(u8 *buf)
84 for (a = 0; a < 15; a++)
90 static char *dmi_ident[DMI_STRING_MAX];
95 static void __init dmi_save_ident(struct dmi_header *dm, int slot, int string)
97 char *p, *d = (char*) dm;
102 p = dmi_string(dm, d[string]);
110 * Process a DMI table entry. Right now all we care about are the BIOS
111 * and machine entries. For 2.5 we should pull the smbus controller info
114 static void __init dmi_decode(struct dmi_header *dm)
116 u8 *data __attribute__((__unused__)) = (u8 *)dm;
120 dmi_save_ident(dm, DMI_BIOS_VENDOR, 4);
121 dmi_save_ident(dm, DMI_BIOS_VERSION, 5);
122 dmi_save_ident(dm, DMI_BIOS_DATE, 8);
125 dmi_save_ident(dm, DMI_SYS_VENDOR, 4);
126 dmi_save_ident(dm, DMI_PRODUCT_NAME, 5);
127 dmi_save_ident(dm, DMI_PRODUCT_VERSION, 6);
128 dmi_save_ident(dm, DMI_PRODUCT_SERIAL, 7);
131 dmi_save_ident(dm, DMI_BOARD_VENDOR, 4);
132 dmi_save_ident(dm, DMI_BOARD_NAME, 5);
133 dmi_save_ident(dm, DMI_BOARD_VERSION, 6);
138 void __init dmi_scan_machine(void)
144 * no iounmap() for that ioremap(); it would be a no-op, but it's
145 * so early in setup that sucker gets confused into doing what
146 * it shouldn't if we actually call it.
148 p = ioremap(0xF0000, 0x10000);
152 for (q = p; q < p + 0x10000; q += 16) {
153 memcpy_fromio(buf, q, 15);
154 if ((memcmp(buf, "_DMI_", 5) == 0) && dmi_checksum(buf)) {
155 u16 num = (buf[13] << 8) | buf[12];
156 u16 len = (buf[7] << 8) | buf[6];
157 u32 base = (buf[11] << 24) | (buf[10] << 16) |
158 (buf[9] << 8) | buf[8];
161 * DMI version 0.0 means that the real version is taken from
162 * the SMBIOS version, which we don't know at this point.
165 printk(KERN_INFO "DMI %d.%d present.\n",
166 buf[14] >> 4, buf[14] & 0xF);
168 printk(KERN_INFO "DMI present.\n");
170 if (dmi_table(base,len, num, dmi_decode) == 0)
175 out: printk(KERN_INFO "DMI not present.\n");
180 * dmi_check_system - check system DMI data
181 * @list: array of dmi_system_id structures to match against
183 * Walk the blacklist table running matching functions until someone
184 * returns non zero or we hit the end. Callback function is called for
185 * each successfull match. Returns the number of matches.
187 int dmi_check_system(struct dmi_system_id *list)
190 struct dmi_system_id *d = list;
193 for (i = 0; i < ARRAY_SIZE(d->matches); i++) {
194 int s = d->matches[i].slot;
197 if (dmi_ident[s] && strstr(dmi_ident[s], d->matches[i].substr))
202 if (d->callback && d->callback(d))
210 EXPORT_SYMBOL(dmi_check_system);
213 * dmi_get_system_info - return DMI data value
214 * @field: data index (see enum dmi_filed)
216 * Returns one DMI data value, can be used to perform
217 * complex DMI data checks.
219 char *dmi_get_system_info(int field)
221 return dmi_ident[field];
223 EXPORT_SYMBOL(dmi_get_system_info);