blob: 3714e3c03df6ba50ff9c9c1df1128972a481bb4b [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>
Bjorn Helgaas8881cdc2010-10-27 15:32:59 -07005#include <linux/ctype.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include <linux/dmi.h>
Matt Domsch3ed3bce2006-03-26 01:37:03 -08007#include <linux/efi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/bootmem.h>
Tony Luckd114a332012-07-20 13:15:20 -07009#include <linux/random.h>
Andi Kleenf2d3efe2006-03-25 16:30:22 +010010#include <asm/dmi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Paul Jacksoncb5dd7c2008-05-14 08:15:16 -070012/*
13 * DMI stands for "Desktop Management Interface". It is part
14 * of and an antecedent to, SMBIOS, which stands for System
15 * Management BIOS. See further: http://www.dmtf.org/standards
16 */
Parag Warudkar79da4722008-01-30 13:31:59 +010017static char dmi_empty_string[] = " ";
18
Zhenzhong Duanf1d8e612012-12-20 15:05:13 -080019static u16 __initdata dmi_ver;
Ingo Molnar9a22b6e2008-09-18 12:50:18 +020020/*
21 * Catch too early calls to dmi_check_system():
22 */
23static int dmi_initialized;
24
Jean Delvaref3069ae2008-02-23 15:23:46 -080025static const char * __init dmi_string_nosave(const struct dmi_header *dm, u8 s)
Linus Torvalds1da177e2005-04-16 15:20:36 -070026{
Jeff Garzik18552562007-10-03 15:15:40 -040027 const u8 *bp = ((u8 *) dm) + dm->length;
Andrey Panin1249c512005-06-25 14:54:47 -070028
Andrey Paninc3c71202005-09-06 15:18:28 -070029 if (s) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 s--;
Andrey Paninc3c71202005-09-06 15:18:28 -070031 while (s > 0 && *bp) {
32 bp += strlen(bp) + 1;
33 s--;
34 }
35
36 if (*bp != 0) {
Parag Warudkar79da4722008-01-30 13:31:59 +010037 size_t len = strlen(bp)+1;
38 size_t cmp_len = len > 8 ? 8 : len;
39
40 if (!memcmp(bp, dmi_empty_string, cmp_len))
41 return dmi_empty_string;
Jean Delvaref3069ae2008-02-23 15:23:46 -080042 return bp;
Andrey Paninc3c71202005-09-06 15:18:28 -070043 }
Bjorn Helgaas4f705ae2006-04-03 17:09:22 -070044 }
Andrey Paninc3c71202005-09-06 15:18:28 -070045
Jean Delvaref3069ae2008-02-23 15:23:46 -080046 return "";
47}
48
49static char * __init dmi_string(const struct dmi_header *dm, u8 s)
50{
51 const char *bp = dmi_string_nosave(dm, s);
52 char *str;
53 size_t len;
54
55 if (bp == dmi_empty_string)
56 return dmi_empty_string;
57
58 len = strlen(bp) + 1;
59 str = dmi_alloc(len);
60 if (str != NULL)
61 strcpy(str, bp);
62 else
63 printk(KERN_ERR "dmi_string: cannot allocate %Zu bytes.\n", len);
64
Andrey Paninc3c71202005-09-06 15:18:28 -070065 return str;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066}
67
68/*
69 * We have to be cautious here. We have seen BIOSes with DMI pointers
70 * pointing to completely the wrong place for example
71 */
Jean Delvare7fce0842007-11-03 17:29:20 +010072static void dmi_table(u8 *buf, int len, int num,
Jean Delvaree7a19c562009-03-30 21:46:44 +020073 void (*decode)(const struct dmi_header *, void *),
74 void *private_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
Jean Delvare7fce0842007-11-03 17:29:20 +010076 u8 *data = buf;
Andrey Panin1249c512005-06-25 14:54:47 -070077 int i = 0;
Bjorn Helgaas4f705ae2006-04-03 17:09:22 -070078
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 /*
Bjorn Helgaas4f705ae2006-04-03 17:09:22 -070080 * Stop when we see all the items the table claimed to have
81 * OR we run off the end of the table (also happens)
82 */
Andrey Panin1249c512005-06-25 14:54:47 -070083 while ((i < num) && (data - buf + sizeof(struct dmi_header)) <= len) {
Jeff Garzik18552562007-10-03 15:15:40 -040084 const struct dmi_header *dm = (const struct dmi_header *)data;
85
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 /*
Alan Cox86385452008-11-07 16:03:46 +000087 * We want to know the total length (formatted area and
88 * strings) before decoding to make sure we won't run off the
89 * table in dmi_decode or dmi_string
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 */
Andrey Panin1249c512005-06-25 14:54:47 -070091 data += dm->length;
92 while ((data - buf < len - 1) && (data[0] || data[1]))
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 data++;
Andrey Panin1249c512005-06-25 14:54:47 -070094 if (data - buf < len - 1)
Jean Delvaree7a19c562009-03-30 21:46:44 +020095 decode(dm, private_data);
Andrey Panin1249c512005-06-25 14:54:47 -070096 data += 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 i++;
98 }
Jean Delvare7fce0842007-11-03 17:29:20 +010099}
100
101static u32 dmi_base;
102static u16 dmi_len;
103static u16 dmi_num;
104
Jean Delvaree7a19c562009-03-30 21:46:44 +0200105static int __init dmi_walk_early(void (*decode)(const struct dmi_header *,
106 void *))
Jean Delvare7fce0842007-11-03 17:29:20 +0100107{
108 u8 *buf;
109
110 buf = dmi_ioremap(dmi_base, dmi_len);
111 if (buf == NULL)
112 return -1;
113
Jean Delvaree7a19c562009-03-30 21:46:44 +0200114 dmi_table(buf, dmi_len, dmi_num, decode, NULL);
Jean Delvare7fce0842007-11-03 17:29:20 +0100115
Tony Luckd114a332012-07-20 13:15:20 -0700116 add_device_randomness(buf, dmi_len);
117
Jean Delvare7fce0842007-11-03 17:29:20 +0100118 dmi_iounmap(buf, dmi_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 return 0;
120}
121
Jeff Garzik18552562007-10-03 15:15:40 -0400122static int __init dmi_checksum(const u8 *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
Andrey Panin1249c512005-06-25 14:54:47 -0700124 u8 sum = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 int a;
Bjorn Helgaas4f705ae2006-04-03 17:09:22 -0700126
Andrey Panin1249c512005-06-25 14:54:47 -0700127 for (a = 0; a < 15; a++)
128 sum += buf[a];
129
130 return sum == 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131}
132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133static char *dmi_ident[DMI_STRING_MAX];
Andrey Paninebad6a42005-09-06 15:18:29 -0700134static LIST_HEAD(dmi_devices);
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200135int dmi_available;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137/*
138 * Save a DMI string
139 */
Jeff Garzik18552562007-10-03 15:15:40 -0400140static void __init dmi_save_ident(const struct dmi_header *dm, int slot, int string)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141{
Jeff Garzik18552562007-10-03 15:15:40 -0400142 const char *d = (const char*) dm;
143 char *p;
Andrey Panin1249c512005-06-25 14:54:47 -0700144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 if (dmi_ident[slot])
146 return;
Andrey Panin1249c512005-06-25 14:54:47 -0700147
Andrey Paninc3c71202005-09-06 15:18:28 -0700148 p = dmi_string(dm, d[string]);
149 if (p == NULL)
150 return;
151
152 dmi_ident[slot] = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153}
154
Jeff Garzik18552562007-10-03 15:15:40 -0400155static void __init dmi_save_uuid(const struct dmi_header *dm, int slot, int index)
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200156{
Jeff Garzik18552562007-10-03 15:15:40 -0400157 const u8 *d = (u8*) dm + index;
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200158 char *s;
159 int is_ff = 1, is_00 = 1, i;
160
161 if (dmi_ident[slot])
162 return;
163
164 for (i = 0; i < 16 && (is_ff || is_00); i++) {
Zhenzhong Duanf1d8e612012-12-20 15:05:13 -0800165 if (d[i] != 0x00)
166 is_00 = 0;
167 if (d[i] != 0xFF)
168 is_ff = 0;
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200169 }
170
171 if (is_ff || is_00)
172 return;
173
174 s = dmi_alloc(16*2+4+1);
175 if (!s)
176 return;
177
Zhenzhong Duanf1d8e612012-12-20 15:05:13 -0800178 /*
179 * As of version 2.6 of the SMBIOS specification, the first 3 fields of
180 * the UUID are supposed to be little-endian encoded. The specification
181 * says that this is the defacto standard.
182 */
183 if (dmi_ver >= 0x0206)
184 sprintf(s, "%pUL", d);
185 else
186 sprintf(s, "%pUB", d);
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200187
188 dmi_ident[slot] = s;
189}
190
Jeff Garzik18552562007-10-03 15:15:40 -0400191static void __init dmi_save_type(const struct dmi_header *dm, int slot, int index)
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200192{
Jeff Garzik18552562007-10-03 15:15:40 -0400193 const u8 *d = (u8*) dm + index;
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200194 char *s;
195
196 if (dmi_ident[slot])
197 return;
198
199 s = dmi_alloc(4);
200 if (!s)
201 return;
202
203 sprintf(s, "%u", *d & 0x7F);
204 dmi_ident[slot] = s;
205}
206
Jean Delvaref3069ae2008-02-23 15:23:46 -0800207static void __init dmi_save_one_device(int type, const char *name)
208{
209 struct dmi_device *dev;
210
211 /* No duplicate device */
212 if (dmi_find_device(type, name, NULL))
213 return;
214
215 dev = dmi_alloc(sizeof(*dev) + strlen(name) + 1);
216 if (!dev) {
217 printk(KERN_ERR "dmi_save_one_device: out of memory.\n");
218 return;
219 }
220
221 dev->type = type;
222 strcpy((char *)(dev + 1), name);
223 dev->name = (char *)(dev + 1);
224 dev->device_data = NULL;
225 list_add(&dev->list, &dmi_devices);
226}
227
Jeff Garzik18552562007-10-03 15:15:40 -0400228static void __init dmi_save_devices(const struct dmi_header *dm)
Andrey Paninebad6a42005-09-06 15:18:29 -0700229{
230 int i, count = (dm->length - sizeof(struct dmi_header)) / 2;
Andrey Paninebad6a42005-09-06 15:18:29 -0700231
232 for (i = 0; i < count; i++) {
Jeff Garzik18552562007-10-03 15:15:40 -0400233 const char *d = (char *)(dm + 1) + (i * 2);
Andrey Paninebad6a42005-09-06 15:18:29 -0700234
235 /* Skip disabled device */
236 if ((*d & 0x80) == 0)
237 continue;
238
Jean Delvaref3069ae2008-02-23 15:23:46 -0800239 dmi_save_one_device(*d & 0x7f, dmi_string_nosave(dm, *(d + 1)));
Shem Multinymous2e0c1f62006-09-29 01:59:37 -0700240 }
241}
242
Jeff Garzik18552562007-10-03 15:15:40 -0400243static void __init dmi_save_oem_strings_devices(const struct dmi_header *dm)
Shem Multinymous2e0c1f62006-09-29 01:59:37 -0700244{
245 int i, count = *(u8 *)(dm + 1);
246 struct dmi_device *dev;
247
248 for (i = 1; i <= count; i++) {
Parag Warudkar79da4722008-01-30 13:31:59 +0100249 char *devname = dmi_string(dm, i);
250
Jean Delvare43fe1052008-02-23 15:23:55 -0800251 if (devname == dmi_empty_string)
Parag Warudkar79da4722008-01-30 13:31:59 +0100252 continue;
Parag Warudkar79da4722008-01-30 13:31:59 +0100253
Shem Multinymous2e0c1f62006-09-29 01:59:37 -0700254 dev = dmi_alloc(sizeof(*dev));
255 if (!dev) {
256 printk(KERN_ERR
257 "dmi_save_oem_strings_devices: out of memory.\n");
258 break;
259 }
260
261 dev->type = DMI_DEV_TYPE_OEM_STRING;
Parag Warudkar79da4722008-01-30 13:31:59 +0100262 dev->name = devname;
Shem Multinymous2e0c1f62006-09-29 01:59:37 -0700263 dev->device_data = NULL;
Andrey Paninebad6a42005-09-06 15:18:29 -0700264
265 list_add(&dev->list, &dmi_devices);
266 }
267}
268
Jeff Garzik18552562007-10-03 15:15:40 -0400269static void __init dmi_save_ipmi_device(const struct dmi_header *dm)
Andrey Paninebad6a42005-09-06 15:18:29 -0700270{
271 struct dmi_device *dev;
272 void * data;
273
Andi Kleene9928672006-01-11 22:43:33 +0100274 data = dmi_alloc(dm->length);
Andrey Paninebad6a42005-09-06 15:18:29 -0700275 if (data == NULL) {
276 printk(KERN_ERR "dmi_save_ipmi_device: out of memory.\n");
277 return;
278 }
279
280 memcpy(data, dm, dm->length);
281
Andi Kleene9928672006-01-11 22:43:33 +0100282 dev = dmi_alloc(sizeof(*dev));
Andrey Paninebad6a42005-09-06 15:18:29 -0700283 if (!dev) {
284 printk(KERN_ERR "dmi_save_ipmi_device: out of memory.\n");
285 return;
286 }
287
288 dev->type = DMI_DEV_TYPE_IPMI;
289 dev->name = "IPMI controller";
290 dev->device_data = data;
291
Carol Hebertabd24df2008-04-04 14:30:03 -0700292 list_add_tail(&dev->list, &dmi_devices);
Andrey Paninebad6a42005-09-06 15:18:29 -0700293}
294
Narendra K911e1c92010-07-26 05:56:50 -0500295static void __init dmi_save_dev_onboard(int instance, int segment, int bus,
296 int devfn, const char *name)
297{
298 struct dmi_dev_onboard *onboard_dev;
299
300 onboard_dev = dmi_alloc(sizeof(*onboard_dev) + strlen(name) + 1);
301 if (!onboard_dev) {
302 printk(KERN_ERR "dmi_save_dev_onboard: out of memory.\n");
303 return;
304 }
305 onboard_dev->instance = instance;
306 onboard_dev->segment = segment;
307 onboard_dev->bus = bus;
308 onboard_dev->devfn = devfn;
309
310 strcpy((char *)&onboard_dev[1], name);
311 onboard_dev->dev.type = DMI_DEV_TYPE_DEV_ONBOARD;
312 onboard_dev->dev.name = (char *)&onboard_dev[1];
313 onboard_dev->dev.device_data = onboard_dev;
314
315 list_add(&onboard_dev->dev.list, &dmi_devices);
316}
317
Wim Van Sebroeckb4bd7d52008-02-08 04:20:58 -0800318static void __init dmi_save_extended_devices(const struct dmi_header *dm)
319{
320 const u8 *d = (u8*) dm + 5;
Wim Van Sebroeckb4bd7d52008-02-08 04:20:58 -0800321
322 /* Skip disabled device */
323 if ((*d & 0x80) == 0)
324 return;
325
Narendra K911e1c92010-07-26 05:56:50 -0500326 dmi_save_dev_onboard(*(d+1), *(u16 *)(d+2), *(d+4), *(d+5),
327 dmi_string_nosave(dm, *(d-1)));
Jean Delvaref3069ae2008-02-23 15:23:46 -0800328 dmi_save_one_device(*d & 0x7f, dmi_string_nosave(dm, *(d - 1)));
Wim Van Sebroeckb4bd7d52008-02-08 04:20:58 -0800329}
330
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 * Process a DMI table entry. Right now all we care about are the BIOS
333 * and machine entries. For 2.5 we should pull the smbus controller info
334 * out of here.
335 */
Jean Delvaree7a19c562009-03-30 21:46:44 +0200336static void __init dmi_decode(const struct dmi_header *dm, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337{
Andrey Panin1249c512005-06-25 14:54:47 -0700338 switch(dm->type) {
Andrey Paninebad6a42005-09-06 15:18:29 -0700339 case 0: /* BIOS Information */
Andrey Panin1249c512005-06-25 14:54:47 -0700340 dmi_save_ident(dm, DMI_BIOS_VENDOR, 4);
Andrey Panin1249c512005-06-25 14:54:47 -0700341 dmi_save_ident(dm, DMI_BIOS_VERSION, 5);
Andrey Panin1249c512005-06-25 14:54:47 -0700342 dmi_save_ident(dm, DMI_BIOS_DATE, 8);
343 break;
Andrey Paninebad6a42005-09-06 15:18:29 -0700344 case 1: /* System Information */
Andrey Panin1249c512005-06-25 14:54:47 -0700345 dmi_save_ident(dm, DMI_SYS_VENDOR, 4);
Andrey Panin1249c512005-06-25 14:54:47 -0700346 dmi_save_ident(dm, DMI_PRODUCT_NAME, 5);
Andrey Panin1249c512005-06-25 14:54:47 -0700347 dmi_save_ident(dm, DMI_PRODUCT_VERSION, 6);
Andrey Panin1249c512005-06-25 14:54:47 -0700348 dmi_save_ident(dm, DMI_PRODUCT_SERIAL, 7);
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200349 dmi_save_uuid(dm, DMI_PRODUCT_UUID, 8);
Andrey Panin1249c512005-06-25 14:54:47 -0700350 break;
Andrey Paninebad6a42005-09-06 15:18:29 -0700351 case 2: /* Base Board Information */
Andrey Panin1249c512005-06-25 14:54:47 -0700352 dmi_save_ident(dm, DMI_BOARD_VENDOR, 4);
Andrey Panin1249c512005-06-25 14:54:47 -0700353 dmi_save_ident(dm, DMI_BOARD_NAME, 5);
Andrey Panin1249c512005-06-25 14:54:47 -0700354 dmi_save_ident(dm, DMI_BOARD_VERSION, 6);
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200355 dmi_save_ident(dm, DMI_BOARD_SERIAL, 7);
356 dmi_save_ident(dm, DMI_BOARD_ASSET_TAG, 8);
357 break;
358 case 3: /* Chassis Information */
359 dmi_save_ident(dm, DMI_CHASSIS_VENDOR, 4);
360 dmi_save_type(dm, DMI_CHASSIS_TYPE, 5);
361 dmi_save_ident(dm, DMI_CHASSIS_VERSION, 6);
362 dmi_save_ident(dm, DMI_CHASSIS_SERIAL, 7);
363 dmi_save_ident(dm, DMI_CHASSIS_ASSET_TAG, 8);
Andrey Panin1249c512005-06-25 14:54:47 -0700364 break;
Andrey Paninebad6a42005-09-06 15:18:29 -0700365 case 10: /* Onboard Devices Information */
366 dmi_save_devices(dm);
367 break;
Shem Multinymous2e0c1f62006-09-29 01:59:37 -0700368 case 11: /* OEM Strings */
369 dmi_save_oem_strings_devices(dm);
370 break;
Andrey Paninebad6a42005-09-06 15:18:29 -0700371 case 38: /* IPMI Device Information */
372 dmi_save_ipmi_device(dm);
Wim Van Sebroeckb4bd7d52008-02-08 04:20:58 -0800373 break;
374 case 41: /* Onboard Devices Extended Information */
375 dmi_save_extended_devices(dm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 }
377}
378
Bjorn Helgaas8881cdc2010-10-27 15:32:59 -0700379static void __init print_filtered(const char *info)
380{
381 const char *p;
382
383 if (!info)
384 return;
385
386 for (p = info; *p; p++)
387 if (isprint(*p))
388 printk(KERN_CONT "%c", *p);
389 else
390 printk(KERN_CONT "\\x%02x", *p & 0xff);
391}
392
393static void __init dmi_dump_ids(void)
394{
Naga Chumbalkar84e383b2011-02-14 22:47:17 +0000395 const char *board; /* Board Name is optional */
396
Bjorn Helgaas8881cdc2010-10-27 15:32:59 -0700397 printk(KERN_DEBUG "DMI: ");
Naga Chumbalkar84e383b2011-02-14 22:47:17 +0000398 print_filtered(dmi_get_system_info(DMI_SYS_VENDOR));
399 printk(KERN_CONT " ");
Bjorn Helgaas8881cdc2010-10-27 15:32:59 -0700400 print_filtered(dmi_get_system_info(DMI_PRODUCT_NAME));
Naga Chumbalkar84e383b2011-02-14 22:47:17 +0000401 board = dmi_get_system_info(DMI_BOARD_NAME);
402 if (board) {
403 printk(KERN_CONT "/");
404 print_filtered(board);
405 }
Bjorn Helgaas8881cdc2010-10-27 15:32:59 -0700406 printk(KERN_CONT ", BIOS ");
407 print_filtered(dmi_get_system_info(DMI_BIOS_VERSION));
408 printk(KERN_CONT " ");
409 print_filtered(dmi_get_system_info(DMI_BIOS_DATE));
410 printk(KERN_CONT "\n");
411}
412
Jeff Garzik18552562007-10-03 15:15:40 -0400413static int __init dmi_present(const char __iomem *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414{
Andrey Panin61e032fa2005-09-06 15:18:26 -0700415 u8 buf[15];
Jeff Garzik18552562007-10-03 15:15:40 -0400416
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800417 memcpy_fromio(buf, p, 15);
418 if ((memcmp(buf, "_DMI_", 5) == 0) && dmi_checksum(buf)) {
Jean Delvare7fce0842007-11-03 17:29:20 +0100419 dmi_num = (buf[13] << 8) | buf[12];
420 dmi_len = (buf[7] << 8) | buf[6];
421 dmi_base = (buf[11] << 24) | (buf[10] << 16) |
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800422 (buf[9] << 8) | buf[8];
423
424 /*
425 * DMI version 0.0 means that the real version is taken from
426 * the SMBIOS version, which we don't know at this point.
427 */
Zhenzhong Duanf1d8e612012-12-20 15:05:13 -0800428 dmi_ver = (buf[14] & 0xf0) << 4 | (buf[14] & 0x0f);
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800429 if (buf[14] != 0)
430 printk(KERN_INFO "DMI %d.%d present.\n",
431 buf[14] >> 4, buf[14] & 0xF);
432 else
433 printk(KERN_INFO "DMI present.\n");
Bjorn Helgaas8881cdc2010-10-27 15:32:59 -0700434 if (dmi_walk_early(dmi_decode) == 0) {
435 dmi_dump_ids();
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800436 return 0;
Bjorn Helgaas8881cdc2010-10-27 15:32:59 -0700437 }
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800438 }
439 return 1;
440}
441
442void __init dmi_scan_machine(void)
443{
Andrey Panin61e032fa2005-09-06 15:18:26 -0700444 char __iomem *p, *q;
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800445 int rc;
Andrey Panin61e032fa2005-09-06 15:18:26 -0700446
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800447 if (efi_enabled) {
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800448 if (efi.smbios == EFI_INVALID_TABLE_ADDR)
Ingo Molnar9a22b6e2008-09-18 12:50:18 +0200449 goto error;
Andrey Panin61e032fa2005-09-06 15:18:26 -0700450
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200451 /* This is called as a core_initcall() because it isn't
452 * needed during early boot. This also means we can
453 * iounmap the space when we're done with it.
454 */
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800455 p = dmi_ioremap(efi.smbios, 32);
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800456 if (p == NULL)
Ingo Molnar9a22b6e2008-09-18 12:50:18 +0200457 goto error;
Andrey Panin61e032fa2005-09-06 15:18:26 -0700458
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800459 rc = dmi_present(p + 0x10); /* offset of _DMI_ string */
Tolentino, Matthew E23dd8422006-03-26 01:37:09 -0800460 dmi_iounmap(p, 32);
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200461 if (!rc) {
462 dmi_available = 1;
Ingo Molnar9a22b6e2008-09-18 12:50:18 +0200463 goto out;
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200464 }
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800465 }
466 else {
467 /*
468 * no iounmap() for that ioremap(); it would be a no-op, but
469 * it's so early in setup that sucker gets confused into doing
470 * what it shouldn't if we actually call it.
471 */
472 p = dmi_ioremap(0xF0000, 0x10000);
473 if (p == NULL)
Ingo Molnar9a22b6e2008-09-18 12:50:18 +0200474 goto error;
Andrey Panin61e032fa2005-09-06 15:18:26 -0700475
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800476 for (q = p; q < p + 0x10000; q += 16) {
477 rc = dmi_present(q);
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200478 if (!rc) {
479 dmi_available = 1;
Ingo Molnar0d644842008-01-30 13:33:09 +0100480 dmi_iounmap(p, 0x10000);
Ingo Molnar9a22b6e2008-09-18 12:50:18 +0200481 goto out;
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200482 }
Andrey Panin61e032fa2005-09-06 15:18:26 -0700483 }
Yinghai Lu3212bff2008-01-30 13:33:32 +0100484 dmi_iounmap(p, 0x10000);
Andrey Panin61e032fa2005-09-06 15:18:26 -0700485 }
Ingo Molnar9a22b6e2008-09-18 12:50:18 +0200486 error:
487 printk(KERN_INFO "DMI not present or invalid.\n");
488 out:
489 dmi_initialized = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490}
491
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492/**
Rafael J. Wysockid7b19562009-01-19 20:55:50 +0100493 * dmi_matches - check if dmi_system_id structure matches system DMI data
494 * @dmi: pointer to the dmi_system_id structure to check
495 */
496static bool dmi_matches(const struct dmi_system_id *dmi)
497{
498 int i;
499
500 WARN(!dmi_initialized, KERN_ERR "dmi check: not initialized yet.\n");
501
502 for (i = 0; i < ARRAY_SIZE(dmi->matches); i++) {
503 int s = dmi->matches[i].slot;
504 if (s == DMI_NONE)
Dmitry Torokhov75757502009-12-04 10:24:19 -0800505 break;
Rafael J. Wysockid7b19562009-01-19 20:55:50 +0100506 if (dmi_ident[s]
507 && strstr(dmi_ident[s], dmi->matches[i].substr))
508 continue;
509 /* No match */
510 return false;
511 }
512 return true;
513}
514
515/**
Dmitry Torokhov75757502009-12-04 10:24:19 -0800516 * dmi_is_end_of_table - check for end-of-table marker
517 * @dmi: pointer to the dmi_system_id structure to check
518 */
519static bool dmi_is_end_of_table(const struct dmi_system_id *dmi)
520{
521 return dmi->matches[0].slot == DMI_NONE;
522}
523
524/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 * dmi_check_system - check system DMI data
526 * @list: array of dmi_system_id structures to match against
Randy Dunlapb0ef3712006-06-25 05:49:18 -0700527 * All non-null elements of the list must match
528 * their slot's (field index's) data (i.e., each
529 * list string must be a substring of the specified
530 * DMI slot's string data) to be considered a
531 * successful match.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 *
533 * Walk the blacklist table running matching functions until someone
534 * returns non zero or we hit the end. Callback function is called for
Randy Dunlapb0ef3712006-06-25 05:49:18 -0700535 * each successful match. Returns the number of matches.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 */
Jeff Garzik18552562007-10-03 15:15:40 -0400537int dmi_check_system(const struct dmi_system_id *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538{
Rafael J. Wysockid7b19562009-01-19 20:55:50 +0100539 int count = 0;
540 const struct dmi_system_id *d;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
Dmitry Torokhov75757502009-12-04 10:24:19 -0800542 for (d = list; !dmi_is_end_of_table(d); d++)
Rafael J. Wysockid7b19562009-01-19 20:55:50 +0100543 if (dmi_matches(d)) {
544 count++;
545 if (d->callback && d->callback(d))
546 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
549 return count;
550}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551EXPORT_SYMBOL(dmi_check_system);
552
553/**
Rafael J. Wysockid7b19562009-01-19 20:55:50 +0100554 * dmi_first_match - find dmi_system_id structure matching system DMI data
555 * @list: array of dmi_system_id structures to match against
556 * All non-null elements of the list must match
557 * their slot's (field index's) data (i.e., each
558 * list string must be a substring of the specified
559 * DMI slot's string data) to be considered a
560 * successful match.
561 *
562 * Walk the blacklist table until the first match is found. Return the
563 * pointer to the matching entry or NULL if there's no match.
564 */
565const struct dmi_system_id *dmi_first_match(const struct dmi_system_id *list)
566{
567 const struct dmi_system_id *d;
568
Dmitry Torokhov75757502009-12-04 10:24:19 -0800569 for (d = list; !dmi_is_end_of_table(d); d++)
Rafael J. Wysockid7b19562009-01-19 20:55:50 +0100570 if (dmi_matches(d))
571 return d;
572
573 return NULL;
574}
575EXPORT_SYMBOL(dmi_first_match);
576
577/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 * dmi_get_system_info - return DMI data value
Randy Dunlapb0ef3712006-06-25 05:49:18 -0700579 * @field: data index (see enum dmi_field)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 *
581 * Returns one DMI data value, can be used to perform
582 * complex DMI data checks.
583 */
Jeff Garzik18552562007-10-03 15:15:40 -0400584const char *dmi_get_system_info(int field)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585{
586 return dmi_ident[field];
587}
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700588EXPORT_SYMBOL(dmi_get_system_info);
Andrey Paninebad6a42005-09-06 15:18:29 -0700589
Alok Katariafd8cd7e2008-11-03 15:50:38 -0800590/**
Randy Dunlapc2bacfc2009-01-06 14:41:40 -0800591 * dmi_name_in_serial - Check if string is in the DMI product serial information
592 * @str: string to check for
Alok Katariafd8cd7e2008-11-03 15:50:38 -0800593 */
594int dmi_name_in_serial(const char *str)
595{
596 int f = DMI_PRODUCT_SERIAL;
597 if (dmi_ident[f] && strstr(dmi_ident[f], str))
598 return 1;
599 return 0;
600}
Andi Kleena1bae672006-10-21 18:37:02 +0200601
602/**
Jean Delvare66e13e62011-11-15 14:36:09 -0800603 * dmi_name_in_vendors - Check if string is in the DMI system or board vendor name
Andi Kleena1bae672006-10-21 18:37:02 +0200604 * @str: Case sensitive Name
605 */
Jeff Garzik18552562007-10-03 15:15:40 -0400606int dmi_name_in_vendors(const char *str)
Andi Kleena1bae672006-10-21 18:37:02 +0200607{
Jean Delvare66e13e62011-11-15 14:36:09 -0800608 static int fields[] = { DMI_SYS_VENDOR, DMI_BOARD_VENDOR, DMI_NONE };
Andi Kleena1bae672006-10-21 18:37:02 +0200609 int i;
610 for (i = 0; fields[i] != DMI_NONE; i++) {
611 int f = fields[i];
612 if (dmi_ident[f] && strstr(dmi_ident[f], str))
613 return 1;
614 }
615 return 0;
616}
617EXPORT_SYMBOL(dmi_name_in_vendors);
618
Andrey Paninebad6a42005-09-06 15:18:29 -0700619/**
620 * dmi_find_device - find onboard device by type/name
621 * @type: device type or %DMI_DEV_TYPE_ANY to match all device types
Randy Dunlapb0ef3712006-06-25 05:49:18 -0700622 * @name: device name string or %NULL to match all
Andrey Paninebad6a42005-09-06 15:18:29 -0700623 * @from: previous device found in search, or %NULL for new search.
624 *
625 * Iterates through the list of known onboard devices. If a device is
626 * found with a matching @vendor and @device, a pointer to its device
627 * structure is returned. Otherwise, %NULL is returned.
Randy Dunlapb0ef3712006-06-25 05:49:18 -0700628 * A new search is initiated by passing %NULL as the @from argument.
Andrey Paninebad6a42005-09-06 15:18:29 -0700629 * If @from is not %NULL, searches continue from next device.
630 */
Jeff Garzik18552562007-10-03 15:15:40 -0400631const struct dmi_device * dmi_find_device(int type, const char *name,
632 const struct dmi_device *from)
Andrey Paninebad6a42005-09-06 15:18:29 -0700633{
Jeff Garzik18552562007-10-03 15:15:40 -0400634 const struct list_head *head = from ? &from->list : &dmi_devices;
635 struct list_head *d;
Andrey Paninebad6a42005-09-06 15:18:29 -0700636
637 for(d = head->next; d != &dmi_devices; d = d->next) {
Jeff Garzik18552562007-10-03 15:15:40 -0400638 const struct dmi_device *dev =
639 list_entry(d, struct dmi_device, list);
Andrey Paninebad6a42005-09-06 15:18:29 -0700640
641 if (((type == DMI_DEV_TYPE_ANY) || (dev->type == type)) &&
642 ((name == NULL) || (strcmp(dev->name, name) == 0)))
643 return dev;
644 }
645
646 return NULL;
647}
648EXPORT_SYMBOL(dmi_find_device);
Andi Kleenf083a322006-03-25 16:30:19 +0100649
650/**
Tejun Heo3e5cd1f2009-08-16 21:02:36 +0900651 * dmi_get_date - parse a DMI date
652 * @field: data index (see enum dmi_field)
653 * @yearp: optional out parameter for the year
654 * @monthp: optional out parameter for the month
655 * @dayp: optional out parameter for the day
Andi Kleenf083a322006-03-25 16:30:19 +0100656 *
Tejun Heo3e5cd1f2009-08-16 21:02:36 +0900657 * The date field is assumed to be in the form resembling
658 * [mm[/dd]]/yy[yy] and the result is stored in the out
659 * parameters any or all of which can be omitted.
660 *
661 * If the field doesn't exist, all out parameters are set to zero
662 * and false is returned. Otherwise, true is returned with any
663 * invalid part of date set to zero.
664 *
665 * On return, year, month and day are guaranteed to be in the
666 * range of [0,9999], [0,12] and [0,31] respectively.
Andi Kleenf083a322006-03-25 16:30:19 +0100667 */
Tejun Heo3e5cd1f2009-08-16 21:02:36 +0900668bool dmi_get_date(int field, int *yearp, int *monthp, int *dayp)
Andi Kleenf083a322006-03-25 16:30:19 +0100669{
Tejun Heo3e5cd1f2009-08-16 21:02:36 +0900670 int year = 0, month = 0, day = 0;
671 bool exists;
672 const char *s, *y;
Tejun Heo02c24fa2009-08-16 21:01:22 +0900673 char *e;
Andi Kleenf083a322006-03-25 16:30:19 +0100674
Tejun Heo3e5cd1f2009-08-16 21:02:36 +0900675 s = dmi_get_system_info(field);
676 exists = s;
677 if (!exists)
678 goto out;
Andi Kleenf083a322006-03-25 16:30:19 +0100679
Tejun Heo3e5cd1f2009-08-16 21:02:36 +0900680 /*
681 * Determine year first. We assume the date string resembles
682 * mm/dd/yy[yy] but the original code extracted only the year
683 * from the end. Keep the behavior in the spirit of no
684 * surprises.
685 */
686 y = strrchr(s, '/');
687 if (!y)
688 goto out;
689
690 y++;
691 year = simple_strtoul(y, &e, 10);
692 if (y != e && year < 100) { /* 2-digit year */
Andi Kleenf083a322006-03-25 16:30:19 +0100693 year += 1900;
694 if (year < 1996) /* no dates < spec 1.0 */
695 year += 100;
696 }
Tejun Heo3e5cd1f2009-08-16 21:02:36 +0900697 if (year > 9999) /* year should fit in %04d */
698 year = 0;
Andi Kleenf083a322006-03-25 16:30:19 +0100699
Tejun Heo3e5cd1f2009-08-16 21:02:36 +0900700 /* parse the mm and dd */
701 month = simple_strtoul(s, &e, 10);
702 if (s == e || *e != '/' || !month || month > 12) {
703 month = 0;
704 goto out;
705 }
706
707 s = e + 1;
708 day = simple_strtoul(s, &e, 10);
709 if (s == y || s == e || *e != '/' || day > 31)
710 day = 0;
711out:
712 if (yearp)
713 *yearp = year;
714 if (monthp)
715 *monthp = month;
716 if (dayp)
717 *dayp = day;
718 return exists;
Andi Kleenf083a322006-03-25 16:30:19 +0100719}
Tejun Heo3e5cd1f2009-08-16 21:02:36 +0900720EXPORT_SYMBOL(dmi_get_date);
Jean Delvare7fce0842007-11-03 17:29:20 +0100721
722/**
723 * dmi_walk - Walk the DMI table and get called back for every record
724 * @decode: Callback function
Jean Delvaree7a19c562009-03-30 21:46:44 +0200725 * @private_data: Private data to be passed to the callback function
Jean Delvare7fce0842007-11-03 17:29:20 +0100726 *
727 * Returns -1 when the DMI table can't be reached, 0 on success.
728 */
Jean Delvaree7a19c562009-03-30 21:46:44 +0200729int dmi_walk(void (*decode)(const struct dmi_header *, void *),
730 void *private_data)
Jean Delvare7fce0842007-11-03 17:29:20 +0100731{
732 u8 *buf;
733
734 if (!dmi_available)
735 return -1;
736
737 buf = ioremap(dmi_base, dmi_len);
738 if (buf == NULL)
739 return -1;
740
Jean Delvaree7a19c562009-03-30 21:46:44 +0200741 dmi_table(buf, dmi_len, dmi_num, decode, private_data);
Jean Delvare7fce0842007-11-03 17:29:20 +0100742
743 iounmap(buf);
744 return 0;
745}
746EXPORT_SYMBOL_GPL(dmi_walk);
Jiri Slabyd61c72e2008-12-10 14:07:21 +0100747
748/**
749 * dmi_match - compare a string to the dmi field (if exists)
Randy Dunlapc2bacfc2009-01-06 14:41:40 -0800750 * @f: DMI field identifier
751 * @str: string to compare the DMI field to
Jiri Slabyd61c72e2008-12-10 14:07:21 +0100752 *
753 * Returns true if the requested field equals to the str (including NULL).
754 */
755bool dmi_match(enum dmi_field f, const char *str)
756{
757 const char *info = dmi_get_system_info(f);
758
759 if (info == NULL || str == NULL)
760 return info == str;
761
762 return !strcmp(info, str);
763}
764EXPORT_SYMBOL_GPL(dmi_match);