blob: 1412d7bcdbd195f7cfb0d0c46f63ddd772a1c5f1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#include <linux/string.h>
3#include <linux/init.h>
4#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#include <linux/dmi.h>
Matt Domsch3ed3bce2006-03-26 01:37:03 -08006#include <linux/efi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/bootmem.h>
Andi Kleene9928672006-01-11 22:43:33 +01008#include <linux/slab.h>
Andi Kleenf2d3efe2006-03-25 16:30:22 +01009#include <asm/dmi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
Parag Warudkar79da4722008-01-30 13:31:59 +010011static char dmi_empty_string[] = " ";
12
Jeff Garzik18552562007-10-03 15:15:40 -040013static char * __init dmi_string(const struct dmi_header *dm, u8 s)
Linus Torvalds1da177e2005-04-16 15:20:36 -070014{
Jeff Garzik18552562007-10-03 15:15:40 -040015 const u8 *bp = ((u8 *) dm) + dm->length;
Andrey Paninc3c71202005-09-06 15:18:28 -070016 char *str = "";
Andrey Panin1249c512005-06-25 14:54:47 -070017
Andrey Paninc3c71202005-09-06 15:18:28 -070018 if (s) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 s--;
Andrey Paninc3c71202005-09-06 15:18:28 -070020 while (s > 0 && *bp) {
21 bp += strlen(bp) + 1;
22 s--;
23 }
24
25 if (*bp != 0) {
Parag Warudkar79da4722008-01-30 13:31:59 +010026 size_t len = strlen(bp)+1;
27 size_t cmp_len = len > 8 ? 8 : len;
28
29 if (!memcmp(bp, dmi_empty_string, cmp_len))
30 return dmi_empty_string;
31 str = dmi_alloc(len);
Andrey Paninc3c71202005-09-06 15:18:28 -070032 if (str != NULL)
33 strcpy(str, bp);
34 else
Parag Warudkar79da4722008-01-30 13:31:59 +010035 printk(KERN_ERR "dmi_string: cannot allocate %Zu bytes.\n", len);
Andrey Paninc3c71202005-09-06 15:18:28 -070036 }
Bjorn Helgaas4f705ae2006-04-03 17:09:22 -070037 }
Andrey Paninc3c71202005-09-06 15:18:28 -070038
39 return str;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040}
41
42/*
43 * We have to be cautious here. We have seen BIOSes with DMI pointers
44 * pointing to completely the wrong place for example
45 */
Jean Delvare7fce0842007-11-03 17:29:20 +010046static void dmi_table(u8 *buf, int len, int num,
47 void (*decode)(const struct dmi_header *))
Linus Torvalds1da177e2005-04-16 15:20:36 -070048{
Jean Delvare7fce0842007-11-03 17:29:20 +010049 u8 *data = buf;
Andrey Panin1249c512005-06-25 14:54:47 -070050 int i = 0;
Bjorn Helgaas4f705ae2006-04-03 17:09:22 -070051
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 /*
Bjorn Helgaas4f705ae2006-04-03 17:09:22 -070053 * Stop when we see all the items the table claimed to have
54 * OR we run off the end of the table (also happens)
55 */
Andrey Panin1249c512005-06-25 14:54:47 -070056 while ((i < num) && (data - buf + sizeof(struct dmi_header)) <= len) {
Jeff Garzik18552562007-10-03 15:15:40 -040057 const struct dmi_header *dm = (const struct dmi_header *)data;
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 /*
60 * We want to know the total length (formated area and strings)
61 * before decoding to make sure we won't run off the table in
62 * dmi_decode or dmi_string
63 */
Andrey Panin1249c512005-06-25 14:54:47 -070064 data += dm->length;
65 while ((data - buf < len - 1) && (data[0] || data[1]))
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 data++;
Andrey Panin1249c512005-06-25 14:54:47 -070067 if (data - buf < len - 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 decode(dm);
Andrey Panin1249c512005-06-25 14:54:47 -070069 data += 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 i++;
71 }
Jean Delvare7fce0842007-11-03 17:29:20 +010072}
73
74static u32 dmi_base;
75static u16 dmi_len;
76static u16 dmi_num;
77
78static int __init dmi_walk_early(void (*decode)(const struct dmi_header *))
79{
80 u8 *buf;
81
82 buf = dmi_ioremap(dmi_base, dmi_len);
83 if (buf == NULL)
84 return -1;
85
86 dmi_table(buf, dmi_len, dmi_num, decode);
87
88 dmi_iounmap(buf, dmi_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 return 0;
90}
91
Jeff Garzik18552562007-10-03 15:15:40 -040092static int __init dmi_checksum(const u8 *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093{
Andrey Panin1249c512005-06-25 14:54:47 -070094 u8 sum = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 int a;
Bjorn Helgaas4f705ae2006-04-03 17:09:22 -070096
Andrey Panin1249c512005-06-25 14:54:47 -070097 for (a = 0; a < 15; a++)
98 sum += buf[a];
99
100 return sum == 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101}
102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103static char *dmi_ident[DMI_STRING_MAX];
Andrey Paninebad6a42005-09-06 15:18:29 -0700104static LIST_HEAD(dmi_devices);
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200105int dmi_available;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107/*
108 * Save a DMI string
109 */
Jeff Garzik18552562007-10-03 15:15:40 -0400110static void __init dmi_save_ident(const struct dmi_header *dm, int slot, int string)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
Jeff Garzik18552562007-10-03 15:15:40 -0400112 const char *d = (const char*) dm;
113 char *p;
Andrey Panin1249c512005-06-25 14:54:47 -0700114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 if (dmi_ident[slot])
116 return;
Andrey Panin1249c512005-06-25 14:54:47 -0700117
Andrey Paninc3c71202005-09-06 15:18:28 -0700118 p = dmi_string(dm, d[string]);
119 if (p == NULL)
120 return;
121
122 dmi_ident[slot] = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123}
124
Jeff Garzik18552562007-10-03 15:15:40 -0400125static void __init dmi_save_uuid(const struct dmi_header *dm, int slot, int index)
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200126{
Jeff Garzik18552562007-10-03 15:15:40 -0400127 const u8 *d = (u8*) dm + index;
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200128 char *s;
129 int is_ff = 1, is_00 = 1, i;
130
131 if (dmi_ident[slot])
132 return;
133
134 for (i = 0; i < 16 && (is_ff || is_00); i++) {
135 if(d[i] != 0x00) is_ff = 0;
136 if(d[i] != 0xFF) is_00 = 0;
137 }
138
139 if (is_ff || is_00)
140 return;
141
142 s = dmi_alloc(16*2+4+1);
143 if (!s)
144 return;
145
146 sprintf(s,
147 "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
148 d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],
149 d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15]);
150
151 dmi_ident[slot] = s;
152}
153
Jeff Garzik18552562007-10-03 15:15:40 -0400154static void __init dmi_save_type(const struct dmi_header *dm, int slot, int index)
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200155{
Jeff Garzik18552562007-10-03 15:15:40 -0400156 const u8 *d = (u8*) dm + index;
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200157 char *s;
158
159 if (dmi_ident[slot])
160 return;
161
162 s = dmi_alloc(4);
163 if (!s)
164 return;
165
166 sprintf(s, "%u", *d & 0x7F);
167 dmi_ident[slot] = s;
168}
169
Jeff Garzik18552562007-10-03 15:15:40 -0400170static void __init dmi_save_devices(const struct dmi_header *dm)
Andrey Paninebad6a42005-09-06 15:18:29 -0700171{
172 int i, count = (dm->length - sizeof(struct dmi_header)) / 2;
173 struct dmi_device *dev;
174
175 for (i = 0; i < count; i++) {
Jeff Garzik18552562007-10-03 15:15:40 -0400176 const char *d = (char *)(dm + 1) + (i * 2);
Andrey Paninebad6a42005-09-06 15:18:29 -0700177
178 /* Skip disabled device */
179 if ((*d & 0x80) == 0)
180 continue;
181
Andi Kleene9928672006-01-11 22:43:33 +0100182 dev = dmi_alloc(sizeof(*dev));
Andrey Paninebad6a42005-09-06 15:18:29 -0700183 if (!dev) {
184 printk(KERN_ERR "dmi_save_devices: out of memory.\n");
185 break;
186 }
187
188 dev->type = *d++ & 0x7f;
189 dev->name = dmi_string(dm, *d);
190 dev->device_data = NULL;
Shem Multinymous2e0c1f62006-09-29 01:59:37 -0700191 list_add(&dev->list, &dmi_devices);
192 }
193}
194
Parag Warudkar79da4722008-01-30 13:31:59 +0100195static struct dmi_device empty_oem_string_dev = {
196 .name = dmi_empty_string,
197};
198
Jeff Garzik18552562007-10-03 15:15:40 -0400199static void __init dmi_save_oem_strings_devices(const struct dmi_header *dm)
Shem Multinymous2e0c1f62006-09-29 01:59:37 -0700200{
201 int i, count = *(u8 *)(dm + 1);
202 struct dmi_device *dev;
203
204 for (i = 1; i <= count; i++) {
Parag Warudkar79da4722008-01-30 13:31:59 +0100205 char *devname = dmi_string(dm, i);
206
207 if (!strcmp(devname, dmi_empty_string)) {
208 list_add(&empty_oem_string_dev.list, &dmi_devices);
209 continue;
210 }
211
Shem Multinymous2e0c1f62006-09-29 01:59:37 -0700212 dev = dmi_alloc(sizeof(*dev));
213 if (!dev) {
214 printk(KERN_ERR
215 "dmi_save_oem_strings_devices: out of memory.\n");
216 break;
217 }
218
219 dev->type = DMI_DEV_TYPE_OEM_STRING;
Parag Warudkar79da4722008-01-30 13:31:59 +0100220 dev->name = devname;
Shem Multinymous2e0c1f62006-09-29 01:59:37 -0700221 dev->device_data = NULL;
Andrey Paninebad6a42005-09-06 15:18:29 -0700222
223 list_add(&dev->list, &dmi_devices);
224 }
225}
226
Jeff Garzik18552562007-10-03 15:15:40 -0400227static void __init dmi_save_ipmi_device(const struct dmi_header *dm)
Andrey Paninebad6a42005-09-06 15:18:29 -0700228{
229 struct dmi_device *dev;
230 void * data;
231
Andi Kleene9928672006-01-11 22:43:33 +0100232 data = dmi_alloc(dm->length);
Andrey Paninebad6a42005-09-06 15:18:29 -0700233 if (data == NULL) {
234 printk(KERN_ERR "dmi_save_ipmi_device: out of memory.\n");
235 return;
236 }
237
238 memcpy(data, dm, dm->length);
239
Andi Kleene9928672006-01-11 22:43:33 +0100240 dev = dmi_alloc(sizeof(*dev));
Andrey Paninebad6a42005-09-06 15:18:29 -0700241 if (!dev) {
242 printk(KERN_ERR "dmi_save_ipmi_device: out of memory.\n");
243 return;
244 }
245
246 dev->type = DMI_DEV_TYPE_IPMI;
247 dev->name = "IPMI controller";
248 dev->device_data = data;
249
250 list_add(&dev->list, &dmi_devices);
251}
252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 * Process a DMI table entry. Right now all we care about are the BIOS
255 * and machine entries. For 2.5 we should pull the smbus controller info
256 * out of here.
257 */
Jeff Garzik18552562007-10-03 15:15:40 -0400258static void __init dmi_decode(const struct dmi_header *dm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259{
Andrey Panin1249c512005-06-25 14:54:47 -0700260 switch(dm->type) {
Andrey Paninebad6a42005-09-06 15:18:29 -0700261 case 0: /* BIOS Information */
Andrey Panin1249c512005-06-25 14:54:47 -0700262 dmi_save_ident(dm, DMI_BIOS_VENDOR, 4);
Andrey Panin1249c512005-06-25 14:54:47 -0700263 dmi_save_ident(dm, DMI_BIOS_VERSION, 5);
Andrey Panin1249c512005-06-25 14:54:47 -0700264 dmi_save_ident(dm, DMI_BIOS_DATE, 8);
265 break;
Andrey Paninebad6a42005-09-06 15:18:29 -0700266 case 1: /* System Information */
Andrey Panin1249c512005-06-25 14:54:47 -0700267 dmi_save_ident(dm, DMI_SYS_VENDOR, 4);
Andrey Panin1249c512005-06-25 14:54:47 -0700268 dmi_save_ident(dm, DMI_PRODUCT_NAME, 5);
Andrey Panin1249c512005-06-25 14:54:47 -0700269 dmi_save_ident(dm, DMI_PRODUCT_VERSION, 6);
Andrey Panin1249c512005-06-25 14:54:47 -0700270 dmi_save_ident(dm, DMI_PRODUCT_SERIAL, 7);
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200271 dmi_save_uuid(dm, DMI_PRODUCT_UUID, 8);
Andrey Panin1249c512005-06-25 14:54:47 -0700272 break;
Andrey Paninebad6a42005-09-06 15:18:29 -0700273 case 2: /* Base Board Information */
Andrey Panin1249c512005-06-25 14:54:47 -0700274 dmi_save_ident(dm, DMI_BOARD_VENDOR, 4);
Andrey Panin1249c512005-06-25 14:54:47 -0700275 dmi_save_ident(dm, DMI_BOARD_NAME, 5);
Andrey Panin1249c512005-06-25 14:54:47 -0700276 dmi_save_ident(dm, DMI_BOARD_VERSION, 6);
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200277 dmi_save_ident(dm, DMI_BOARD_SERIAL, 7);
278 dmi_save_ident(dm, DMI_BOARD_ASSET_TAG, 8);
279 break;
280 case 3: /* Chassis Information */
281 dmi_save_ident(dm, DMI_CHASSIS_VENDOR, 4);
282 dmi_save_type(dm, DMI_CHASSIS_TYPE, 5);
283 dmi_save_ident(dm, DMI_CHASSIS_VERSION, 6);
284 dmi_save_ident(dm, DMI_CHASSIS_SERIAL, 7);
285 dmi_save_ident(dm, DMI_CHASSIS_ASSET_TAG, 8);
Andrey Panin1249c512005-06-25 14:54:47 -0700286 break;
Andrey Paninebad6a42005-09-06 15:18:29 -0700287 case 10: /* Onboard Devices Information */
288 dmi_save_devices(dm);
289 break;
Shem Multinymous2e0c1f62006-09-29 01:59:37 -0700290 case 11: /* OEM Strings */
291 dmi_save_oem_strings_devices(dm);
292 break;
Andrey Paninebad6a42005-09-06 15:18:29 -0700293 case 38: /* IPMI Device Information */
294 dmi_save_ipmi_device(dm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 }
296}
297
Jeff Garzik18552562007-10-03 15:15:40 -0400298static int __init dmi_present(const char __iomem *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299{
Andrey Panin61e032f2005-09-06 15:18:26 -0700300 u8 buf[15];
Jeff Garzik18552562007-10-03 15:15:40 -0400301
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800302 memcpy_fromio(buf, p, 15);
303 if ((memcmp(buf, "_DMI_", 5) == 0) && dmi_checksum(buf)) {
Jean Delvare7fce0842007-11-03 17:29:20 +0100304 dmi_num = (buf[13] << 8) | buf[12];
305 dmi_len = (buf[7] << 8) | buf[6];
306 dmi_base = (buf[11] << 24) | (buf[10] << 16) |
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800307 (buf[9] << 8) | buf[8];
308
309 /*
310 * DMI version 0.0 means that the real version is taken from
311 * the SMBIOS version, which we don't know at this point.
312 */
313 if (buf[14] != 0)
314 printk(KERN_INFO "DMI %d.%d present.\n",
315 buf[14] >> 4, buf[14] & 0xF);
316 else
317 printk(KERN_INFO "DMI present.\n");
Jean Delvare7fce0842007-11-03 17:29:20 +0100318 if (dmi_walk_early(dmi_decode) == 0)
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800319 return 0;
320 }
321 return 1;
322}
323
324void __init dmi_scan_machine(void)
325{
Andrey Panin61e032f2005-09-06 15:18:26 -0700326 char __iomem *p, *q;
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800327 int rc;
Andrey Panin61e032f2005-09-06 15:18:26 -0700328
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800329 if (efi_enabled) {
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800330 if (efi.smbios == EFI_INVALID_TABLE_ADDR)
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800331 goto out;
Andrey Panin61e032f2005-09-06 15:18:26 -0700332
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200333 /* This is called as a core_initcall() because it isn't
334 * needed during early boot. This also means we can
335 * iounmap the space when we're done with it.
336 */
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800337 p = dmi_ioremap(efi.smbios, 32);
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800338 if (p == NULL)
339 goto out;
Andrey Panin61e032f2005-09-06 15:18:26 -0700340
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800341 rc = dmi_present(p + 0x10); /* offset of _DMI_ string */
Tolentino, Matthew E23dd8422006-03-26 01:37:09 -0800342 dmi_iounmap(p, 32);
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200343 if (!rc) {
344 dmi_available = 1;
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800345 return;
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200346 }
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800347 }
348 else {
349 /*
350 * no iounmap() for that ioremap(); it would be a no-op, but
351 * it's so early in setup that sucker gets confused into doing
352 * what it shouldn't if we actually call it.
353 */
354 p = dmi_ioremap(0xF0000, 0x10000);
355 if (p == NULL)
356 goto out;
Andrey Panin61e032f2005-09-06 15:18:26 -0700357
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800358 for (q = p; q < p + 0x10000; q += 16) {
359 rc = dmi_present(q);
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200360 if (!rc) {
361 dmi_available = 1;
Ingo Molnar0d644842008-01-30 13:33:09 +0100362 dmi_iounmap(p, 0x10000);
Andrey Panin61e032f2005-09-06 15:18:26 -0700363 return;
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200364 }
Andrey Panin61e032f2005-09-06 15:18:26 -0700365 }
Yinghai Lu3212bff2008-01-30 13:33:32 +0100366 dmi_iounmap(p, 0x10000);
Andrey Panin61e032f2005-09-06 15:18:26 -0700367 }
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800368 out: printk(KERN_INFO "DMI not present or invalid.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369}
370
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371/**
372 * dmi_check_system - check system DMI data
373 * @list: array of dmi_system_id structures to match against
Randy Dunlapb0ef3712006-06-25 05:49:18 -0700374 * All non-null elements of the list must match
375 * their slot's (field index's) data (i.e., each
376 * list string must be a substring of the specified
377 * DMI slot's string data) to be considered a
378 * successful match.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 *
380 * Walk the blacklist table running matching functions until someone
381 * returns non zero or we hit the end. Callback function is called for
Randy Dunlapb0ef3712006-06-25 05:49:18 -0700382 * each successful match. Returns the number of matches.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 */
Jeff Garzik18552562007-10-03 15:15:40 -0400384int dmi_check_system(const struct dmi_system_id *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385{
386 int i, count = 0;
Jeff Garzik18552562007-10-03 15:15:40 -0400387 const struct dmi_system_id *d = list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
389 while (d->ident) {
390 for (i = 0; i < ARRAY_SIZE(d->matches); i++) {
391 int s = d->matches[i].slot;
392 if (s == DMI_NONE)
393 continue;
394 if (dmi_ident[s] && strstr(dmi_ident[s], d->matches[i].substr))
395 continue;
396 /* No match */
397 goto fail;
398 }
Robert Love640e8032005-09-06 15:18:30 -0700399 count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 if (d->callback && d->callback(d))
401 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402fail: d++;
403 }
404
405 return count;
406}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407EXPORT_SYMBOL(dmi_check_system);
408
409/**
410 * dmi_get_system_info - return DMI data value
Randy Dunlapb0ef3712006-06-25 05:49:18 -0700411 * @field: data index (see enum dmi_field)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 *
413 * Returns one DMI data value, can be used to perform
414 * complex DMI data checks.
415 */
Jeff Garzik18552562007-10-03 15:15:40 -0400416const char *dmi_get_system_info(int field)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417{
418 return dmi_ident[field];
419}
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700420EXPORT_SYMBOL(dmi_get_system_info);
Andrey Paninebad6a42005-09-06 15:18:29 -0700421
Andi Kleena1bae672006-10-21 18:37:02 +0200422
423/**
424 * dmi_name_in_vendors - Check if string is anywhere in the DMI vendor information.
425 * @str: Case sensitive Name
426 */
Jeff Garzik18552562007-10-03 15:15:40 -0400427int dmi_name_in_vendors(const char *str)
Andi Kleena1bae672006-10-21 18:37:02 +0200428{
429 static int fields[] = { DMI_BIOS_VENDOR, DMI_BIOS_VERSION, DMI_SYS_VENDOR,
430 DMI_PRODUCT_NAME, DMI_PRODUCT_VERSION, DMI_BOARD_VENDOR,
431 DMI_BOARD_NAME, DMI_BOARD_VERSION, DMI_NONE };
432 int i;
433 for (i = 0; fields[i] != DMI_NONE; i++) {
434 int f = fields[i];
435 if (dmi_ident[f] && strstr(dmi_ident[f], str))
436 return 1;
437 }
438 return 0;
439}
440EXPORT_SYMBOL(dmi_name_in_vendors);
441
Andrey Paninebad6a42005-09-06 15:18:29 -0700442/**
443 * dmi_find_device - find onboard device by type/name
444 * @type: device type or %DMI_DEV_TYPE_ANY to match all device types
Randy Dunlapb0ef3712006-06-25 05:49:18 -0700445 * @name: device name string or %NULL to match all
Andrey Paninebad6a42005-09-06 15:18:29 -0700446 * @from: previous device found in search, or %NULL for new search.
447 *
448 * Iterates through the list of known onboard devices. If a device is
449 * found with a matching @vendor and @device, a pointer to its device
450 * structure is returned. Otherwise, %NULL is returned.
Randy Dunlapb0ef3712006-06-25 05:49:18 -0700451 * A new search is initiated by passing %NULL as the @from argument.
Andrey Paninebad6a42005-09-06 15:18:29 -0700452 * If @from is not %NULL, searches continue from next device.
453 */
Jeff Garzik18552562007-10-03 15:15:40 -0400454const struct dmi_device * dmi_find_device(int type, const char *name,
455 const struct dmi_device *from)
Andrey Paninebad6a42005-09-06 15:18:29 -0700456{
Jeff Garzik18552562007-10-03 15:15:40 -0400457 const struct list_head *head = from ? &from->list : &dmi_devices;
458 struct list_head *d;
Andrey Paninebad6a42005-09-06 15:18:29 -0700459
460 for(d = head->next; d != &dmi_devices; d = d->next) {
Jeff Garzik18552562007-10-03 15:15:40 -0400461 const struct dmi_device *dev =
462 list_entry(d, struct dmi_device, list);
Andrey Paninebad6a42005-09-06 15:18:29 -0700463
464 if (((type == DMI_DEV_TYPE_ANY) || (dev->type == type)) &&
465 ((name == NULL) || (strcmp(dev->name, name) == 0)))
466 return dev;
467 }
468
469 return NULL;
470}
471EXPORT_SYMBOL(dmi_find_device);
Andi Kleenf083a322006-03-25 16:30:19 +0100472
473/**
474 * dmi_get_year - Return year of a DMI date
475 * @field: data index (like dmi_get_system_info)
476 *
477 * Returns -1 when the field doesn't exist. 0 when it is broken.
478 */
479int dmi_get_year(int field)
480{
481 int year;
Jeff Garzik18552562007-10-03 15:15:40 -0400482 const char *s = dmi_get_system_info(field);
Andi Kleenf083a322006-03-25 16:30:19 +0100483
484 if (!s)
485 return -1;
486 if (*s == '\0')
487 return 0;
488 s = strrchr(s, '/');
489 if (!s)
490 return 0;
491
492 s += 1;
493 year = simple_strtoul(s, NULL, 0);
494 if (year && year < 100) { /* 2-digit year */
495 year += 1900;
496 if (year < 1996) /* no dates < spec 1.0 */
497 year += 100;
498 }
499
500 return year;
501}
Jean Delvare7fce0842007-11-03 17:29:20 +0100502
503/**
504 * dmi_walk - Walk the DMI table and get called back for every record
505 * @decode: Callback function
506 *
507 * Returns -1 when the DMI table can't be reached, 0 on success.
508 */
509int dmi_walk(void (*decode)(const struct dmi_header *))
510{
511 u8 *buf;
512
513 if (!dmi_available)
514 return -1;
515
516 buf = ioremap(dmi_base, dmi_len);
517 if (buf == NULL)
518 return -1;
519
520 dmi_table(buf, dmi_len, dmi_num, decode);
521
522 iounmap(buf);
523 return 0;
524}
525EXPORT_SYMBOL_GPL(dmi_walk);