blob: 59579a744d58ce31a6521825dc0df1dc9b971db4 [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 */
Jean Delvareffbbb962013-09-11 14:24:09 -070017static const char dmi_empty_string[] = " ";
Parag Warudkar79da4722008-01-30 13:31:59 +010018
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
Tejun Heoc90fe6b2013-04-30 15:27:14 -070025/* DMI system identification string used during boot */
26static char dmi_ids_string[128] __initdata;
27
Chen, Gongdd6dad42013-10-18 14:29:25 -070028static struct dmi_memdev_info {
29 const char *device;
30 const char *bank;
31 u16 handle;
32} *dmi_memdev;
33static int dmi_memdev_nr;
34
Jean Delvaref3069ae2008-02-23 15:23:46 -080035static const char * __init dmi_string_nosave(const struct dmi_header *dm, u8 s)
Linus Torvalds1da177e2005-04-16 15:20:36 -070036{
Jeff Garzik18552562007-10-03 15:15:40 -040037 const u8 *bp = ((u8 *) dm) + dm->length;
Andrey Panin1249c512005-06-25 14:54:47 -070038
Andrey Paninc3c71202005-09-06 15:18:28 -070039 if (s) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 s--;
Andrey Paninc3c71202005-09-06 15:18:28 -070041 while (s > 0 && *bp) {
42 bp += strlen(bp) + 1;
43 s--;
44 }
45
46 if (*bp != 0) {
Parag Warudkar79da4722008-01-30 13:31:59 +010047 size_t len = strlen(bp)+1;
48 size_t cmp_len = len > 8 ? 8 : len;
49
50 if (!memcmp(bp, dmi_empty_string, cmp_len))
51 return dmi_empty_string;
Jean Delvaref3069ae2008-02-23 15:23:46 -080052 return bp;
Andrey Paninc3c71202005-09-06 15:18:28 -070053 }
Bjorn Helgaas4f705ae2006-04-03 17:09:22 -070054 }
Andrey Paninc3c71202005-09-06 15:18:28 -070055
Jean Delvaref3069ae2008-02-23 15:23:46 -080056 return "";
57}
58
Jean Delvareffbbb962013-09-11 14:24:09 -070059static const char * __init dmi_string(const struct dmi_header *dm, u8 s)
Jean Delvaref3069ae2008-02-23 15:23:46 -080060{
61 const char *bp = dmi_string_nosave(dm, s);
62 char *str;
63 size_t len;
64
65 if (bp == dmi_empty_string)
66 return dmi_empty_string;
67
68 len = strlen(bp) + 1;
69 str = dmi_alloc(len);
70 if (str != NULL)
71 strcpy(str, bp);
Jean Delvaref3069ae2008-02-23 15:23:46 -080072
Andrey Paninc3c71202005-09-06 15:18:28 -070073 return str;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074}
75
76/*
77 * We have to be cautious here. We have seen BIOSes with DMI pointers
78 * pointing to completely the wrong place for example
79 */
Jean Delvare7fce0842007-11-03 17:29:20 +010080static void dmi_table(u8 *buf, int len, int num,
Jean Delvaree7a19c562009-03-30 21:46:44 +020081 void (*decode)(const struct dmi_header *, void *),
82 void *private_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
Jean Delvare7fce0842007-11-03 17:29:20 +010084 u8 *data = buf;
Andrey Panin1249c512005-06-25 14:54:47 -070085 int i = 0;
Bjorn Helgaas4f705ae2006-04-03 17:09:22 -070086
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 /*
Bjorn Helgaas4f705ae2006-04-03 17:09:22 -070088 * Stop when we see all the items the table claimed to have
89 * OR we run off the end of the table (also happens)
90 */
Andrey Panin1249c512005-06-25 14:54:47 -070091 while ((i < num) && (data - buf + sizeof(struct dmi_header)) <= len) {
Jeff Garzik18552562007-10-03 15:15:40 -040092 const struct dmi_header *dm = (const struct dmi_header *)data;
93
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 /*
Alan Cox86385452008-11-07 16:03:46 +000095 * We want to know the total length (formatted area and
96 * strings) before decoding to make sure we won't run off the
97 * table in dmi_decode or dmi_string
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 */
Andrey Panin1249c512005-06-25 14:54:47 -070099 data += dm->length;
100 while ((data - buf < len - 1) && (data[0] || data[1]))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 data++;
Andrey Panin1249c512005-06-25 14:54:47 -0700102 if (data - buf < len - 1)
Jean Delvaree7a19c562009-03-30 21:46:44 +0200103 decode(dm, private_data);
Andrey Panin1249c512005-06-25 14:54:47 -0700104 data += 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 i++;
106 }
Jean Delvare7fce0842007-11-03 17:29:20 +0100107}
108
109static u32 dmi_base;
110static u16 dmi_len;
111static u16 dmi_num;
112
Jean Delvaree7a19c562009-03-30 21:46:44 +0200113static int __init dmi_walk_early(void (*decode)(const struct dmi_header *,
114 void *))
Jean Delvare7fce0842007-11-03 17:29:20 +0100115{
116 u8 *buf;
117
118 buf = dmi_ioremap(dmi_base, dmi_len);
119 if (buf == NULL)
120 return -1;
121
Jean Delvaree7a19c562009-03-30 21:46:44 +0200122 dmi_table(buf, dmi_len, dmi_num, decode, NULL);
Jean Delvare7fce0842007-11-03 17:29:20 +0100123
Tony Luckd114a332012-07-20 13:15:20 -0700124 add_device_randomness(buf, dmi_len);
125
Jean Delvare7fce0842007-11-03 17:29:20 +0100126 dmi_iounmap(buf, dmi_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 return 0;
128}
129
Zhenzhong Duan9f9c9cbb2012-12-20 15:05:14 -0800130static int __init dmi_checksum(const u8 *buf, u8 len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
Andrey Panin1249c512005-06-25 14:54:47 -0700132 u8 sum = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 int a;
Bjorn Helgaas4f705ae2006-04-03 17:09:22 -0700134
Zhenzhong Duan9f9c9cbb2012-12-20 15:05:14 -0800135 for (a = 0; a < len; a++)
Andrey Panin1249c512005-06-25 14:54:47 -0700136 sum += buf[a];
137
138 return sum == 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139}
140
Jean Delvareffbbb962013-09-11 14:24:09 -0700141static const char *dmi_ident[DMI_STRING_MAX];
Andrey Paninebad6a42005-09-06 15:18:29 -0700142static LIST_HEAD(dmi_devices);
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200143int dmi_available;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145/*
146 * Save a DMI string
147 */
Jean Delvare02d9c472013-09-11 14:24:08 -0700148static void __init dmi_save_ident(const struct dmi_header *dm, int slot,
149 int string)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150{
Jean Delvare02d9c472013-09-11 14:24:08 -0700151 const char *d = (const char *) dm;
Jean Delvareffbbb962013-09-11 14:24:09 -0700152 const char *p;
Andrey Panin1249c512005-06-25 14:54:47 -0700153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 if (dmi_ident[slot])
155 return;
Andrey Panin1249c512005-06-25 14:54:47 -0700156
Andrey Paninc3c71202005-09-06 15:18:28 -0700157 p = dmi_string(dm, d[string]);
158 if (p == NULL)
159 return;
160
161 dmi_ident[slot] = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162}
163
Jean Delvare02d9c472013-09-11 14:24:08 -0700164static void __init dmi_save_uuid(const struct dmi_header *dm, int slot,
165 int index)
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200166{
Jean Delvare02d9c472013-09-11 14:24:08 -0700167 const u8 *d = (u8 *) dm + index;
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200168 char *s;
169 int is_ff = 1, is_00 = 1, i;
170
171 if (dmi_ident[slot])
172 return;
173
174 for (i = 0; i < 16 && (is_ff || is_00); i++) {
Zhenzhong Duanf1d8e612012-12-20 15:05:13 -0800175 if (d[i] != 0x00)
176 is_00 = 0;
177 if (d[i] != 0xFF)
178 is_ff = 0;
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200179 }
180
181 if (is_ff || is_00)
182 return;
183
184 s = dmi_alloc(16*2+4+1);
185 if (!s)
186 return;
187
Zhenzhong Duanf1d8e612012-12-20 15:05:13 -0800188 /*
189 * As of version 2.6 of the SMBIOS specification, the first 3 fields of
190 * the UUID are supposed to be little-endian encoded. The specification
191 * says that this is the defacto standard.
192 */
193 if (dmi_ver >= 0x0206)
194 sprintf(s, "%pUL", d);
195 else
196 sprintf(s, "%pUB", d);
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200197
Jean Delvare02d9c472013-09-11 14:24:08 -0700198 dmi_ident[slot] = s;
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200199}
200
Jean Delvare02d9c472013-09-11 14:24:08 -0700201static void __init dmi_save_type(const struct dmi_header *dm, int slot,
202 int index)
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200203{
Jean Delvare02d9c472013-09-11 14:24:08 -0700204 const u8 *d = (u8 *) dm + index;
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200205 char *s;
206
207 if (dmi_ident[slot])
208 return;
209
210 s = dmi_alloc(4);
211 if (!s)
212 return;
213
214 sprintf(s, "%u", *d & 0x7F);
215 dmi_ident[slot] = s;
216}
217
Jean Delvaref3069ae2008-02-23 15:23:46 -0800218static void __init dmi_save_one_device(int type, const char *name)
219{
220 struct dmi_device *dev;
221
222 /* No duplicate device */
223 if (dmi_find_device(type, name, NULL))
224 return;
225
226 dev = dmi_alloc(sizeof(*dev) + strlen(name) + 1);
Jean Delvareae797442013-09-11 14:24:10 -0700227 if (!dev)
Jean Delvaref3069ae2008-02-23 15:23:46 -0800228 return;
Jean Delvaref3069ae2008-02-23 15:23:46 -0800229
230 dev->type = type;
231 strcpy((char *)(dev + 1), name);
232 dev->name = (char *)(dev + 1);
233 dev->device_data = NULL;
234 list_add(&dev->list, &dmi_devices);
235}
236
Jeff Garzik18552562007-10-03 15:15:40 -0400237static void __init dmi_save_devices(const struct dmi_header *dm)
Andrey Paninebad6a42005-09-06 15:18:29 -0700238{
239 int i, count = (dm->length - sizeof(struct dmi_header)) / 2;
Andrey Paninebad6a42005-09-06 15:18:29 -0700240
241 for (i = 0; i < count; i++) {
Jeff Garzik18552562007-10-03 15:15:40 -0400242 const char *d = (char *)(dm + 1) + (i * 2);
Andrey Paninebad6a42005-09-06 15:18:29 -0700243
244 /* Skip disabled device */
245 if ((*d & 0x80) == 0)
246 continue;
247
Jean Delvaref3069ae2008-02-23 15:23:46 -0800248 dmi_save_one_device(*d & 0x7f, dmi_string_nosave(dm, *(d + 1)));
Shem Multinymous2e0c1f62006-09-29 01:59:37 -0700249 }
250}
251
Jeff Garzik18552562007-10-03 15:15:40 -0400252static void __init dmi_save_oem_strings_devices(const struct dmi_header *dm)
Shem Multinymous2e0c1f62006-09-29 01:59:37 -0700253{
254 int i, count = *(u8 *)(dm + 1);
255 struct dmi_device *dev;
256
257 for (i = 1; i <= count; i++) {
Jean Delvareffbbb962013-09-11 14:24:09 -0700258 const char *devname = dmi_string(dm, i);
Parag Warudkar79da4722008-01-30 13:31:59 +0100259
Jean Delvare43fe1052008-02-23 15:23:55 -0800260 if (devname == dmi_empty_string)
Parag Warudkar79da4722008-01-30 13:31:59 +0100261 continue;
Parag Warudkar79da4722008-01-30 13:31:59 +0100262
Shem Multinymous2e0c1f62006-09-29 01:59:37 -0700263 dev = dmi_alloc(sizeof(*dev));
Jean Delvareae797442013-09-11 14:24:10 -0700264 if (!dev)
Shem Multinymous2e0c1f62006-09-29 01:59:37 -0700265 break;
Shem Multinymous2e0c1f62006-09-29 01:59:37 -0700266
267 dev->type = DMI_DEV_TYPE_OEM_STRING;
Parag Warudkar79da4722008-01-30 13:31:59 +0100268 dev->name = devname;
Shem Multinymous2e0c1f62006-09-29 01:59:37 -0700269 dev->device_data = NULL;
Andrey Paninebad6a42005-09-06 15:18:29 -0700270
271 list_add(&dev->list, &dmi_devices);
272 }
273}
274
Jeff Garzik18552562007-10-03 15:15:40 -0400275static void __init dmi_save_ipmi_device(const struct dmi_header *dm)
Andrey Paninebad6a42005-09-06 15:18:29 -0700276{
277 struct dmi_device *dev;
Jean Delvare02d9c472013-09-11 14:24:08 -0700278 void *data;
Andrey Paninebad6a42005-09-06 15:18:29 -0700279
Andi Kleene9928672006-01-11 22:43:33 +0100280 data = dmi_alloc(dm->length);
Jean Delvareae797442013-09-11 14:24:10 -0700281 if (data == NULL)
Andrey Paninebad6a42005-09-06 15:18:29 -0700282 return;
Andrey Paninebad6a42005-09-06 15:18:29 -0700283
284 memcpy(data, dm, dm->length);
285
Andi Kleene9928672006-01-11 22:43:33 +0100286 dev = dmi_alloc(sizeof(*dev));
Jean Delvareae797442013-09-11 14:24:10 -0700287 if (!dev)
Andrey Paninebad6a42005-09-06 15:18:29 -0700288 return;
Andrey Paninebad6a42005-09-06 15:18:29 -0700289
290 dev->type = DMI_DEV_TYPE_IPMI;
291 dev->name = "IPMI controller";
292 dev->device_data = data;
293
Carol Hebertabd24df2008-04-04 14:30:03 -0700294 list_add_tail(&dev->list, &dmi_devices);
Andrey Paninebad6a42005-09-06 15:18:29 -0700295}
296
Narendra K911e1c92010-07-26 05:56:50 -0500297static void __init dmi_save_dev_onboard(int instance, int segment, int bus,
298 int devfn, const char *name)
299{
300 struct dmi_dev_onboard *onboard_dev;
301
302 onboard_dev = dmi_alloc(sizeof(*onboard_dev) + strlen(name) + 1);
Jean Delvareae797442013-09-11 14:24:10 -0700303 if (!onboard_dev)
Narendra K911e1c92010-07-26 05:56:50 -0500304 return;
Jean Delvareae797442013-09-11 14:24:10 -0700305
Narendra K911e1c92010-07-26 05:56:50 -0500306 onboard_dev->instance = instance;
307 onboard_dev->segment = segment;
308 onboard_dev->bus = bus;
309 onboard_dev->devfn = devfn;
310
311 strcpy((char *)&onboard_dev[1], name);
312 onboard_dev->dev.type = DMI_DEV_TYPE_DEV_ONBOARD;
313 onboard_dev->dev.name = (char *)&onboard_dev[1];
314 onboard_dev->dev.device_data = onboard_dev;
315
316 list_add(&onboard_dev->dev.list, &dmi_devices);
317}
318
Wim Van Sebroeckb4bd7d52008-02-08 04:20:58 -0800319static void __init dmi_save_extended_devices(const struct dmi_header *dm)
320{
Jean Delvare02d9c472013-09-11 14:24:08 -0700321 const u8 *d = (u8 *) dm + 5;
Wim Van Sebroeckb4bd7d52008-02-08 04:20:58 -0800322
323 /* Skip disabled device */
324 if ((*d & 0x80) == 0)
325 return;
326
Narendra K911e1c92010-07-26 05:56:50 -0500327 dmi_save_dev_onboard(*(d+1), *(u16 *)(d+2), *(d+4), *(d+5),
328 dmi_string_nosave(dm, *(d-1)));
Jean Delvaref3069ae2008-02-23 15:23:46 -0800329 dmi_save_one_device(*d & 0x7f, dmi_string_nosave(dm, *(d - 1)));
Wim Van Sebroeckb4bd7d52008-02-08 04:20:58 -0800330}
331
Chen, Gongdd6dad42013-10-18 14:29:25 -0700332static void __init count_mem_devices(const struct dmi_header *dm, void *v)
333{
334 if (dm->type != DMI_ENTRY_MEM_DEVICE)
335 return;
336 dmi_memdev_nr++;
337}
338
339static void __init save_mem_devices(const struct dmi_header *dm, void *v)
340{
341 const char *d = (const char *)dm;
342 static int nr;
343
344 if (dm->type != DMI_ENTRY_MEM_DEVICE)
345 return;
346 if (nr >= dmi_memdev_nr) {
347 pr_warn(FW_BUG "Too many DIMM entries in SMBIOS table\n");
348 return;
349 }
350 dmi_memdev[nr].handle = dm->handle;
351 dmi_memdev[nr].device = dmi_string(dm, d[0x10]);
352 dmi_memdev[nr].bank = dmi_string(dm, d[0x11]);
353 nr++;
354}
355
356void __init dmi_memdev_walk(void)
357{
358 if (!dmi_available)
359 return;
360
361 if (dmi_walk_early(count_mem_devices) == 0 && dmi_memdev_nr) {
362 dmi_memdev = dmi_alloc(sizeof(*dmi_memdev) * dmi_memdev_nr);
363 if (dmi_memdev)
364 dmi_walk_early(save_mem_devices);
365 }
366}
367
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 * Process a DMI table entry. Right now all we care about are the BIOS
370 * and machine entries. For 2.5 we should pull the smbus controller info
371 * out of here.
372 */
Jean Delvaree7a19c562009-03-30 21:46:44 +0200373static void __init dmi_decode(const struct dmi_header *dm, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374{
Jean Delvare02d9c472013-09-11 14:24:08 -0700375 switch (dm->type) {
Andrey Paninebad6a42005-09-06 15:18:29 -0700376 case 0: /* BIOS Information */
Andrey Panin1249c512005-06-25 14:54:47 -0700377 dmi_save_ident(dm, DMI_BIOS_VENDOR, 4);
Andrey Panin1249c512005-06-25 14:54:47 -0700378 dmi_save_ident(dm, DMI_BIOS_VERSION, 5);
Andrey Panin1249c512005-06-25 14:54:47 -0700379 dmi_save_ident(dm, DMI_BIOS_DATE, 8);
380 break;
Andrey Paninebad6a42005-09-06 15:18:29 -0700381 case 1: /* System Information */
Andrey Panin1249c512005-06-25 14:54:47 -0700382 dmi_save_ident(dm, DMI_SYS_VENDOR, 4);
Andrey Panin1249c512005-06-25 14:54:47 -0700383 dmi_save_ident(dm, DMI_PRODUCT_NAME, 5);
Andrey Panin1249c512005-06-25 14:54:47 -0700384 dmi_save_ident(dm, DMI_PRODUCT_VERSION, 6);
Andrey Panin1249c512005-06-25 14:54:47 -0700385 dmi_save_ident(dm, DMI_PRODUCT_SERIAL, 7);
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200386 dmi_save_uuid(dm, DMI_PRODUCT_UUID, 8);
Andrey Panin1249c512005-06-25 14:54:47 -0700387 break;
Andrey Paninebad6a42005-09-06 15:18:29 -0700388 case 2: /* Base Board Information */
Andrey Panin1249c512005-06-25 14:54:47 -0700389 dmi_save_ident(dm, DMI_BOARD_VENDOR, 4);
Andrey Panin1249c512005-06-25 14:54:47 -0700390 dmi_save_ident(dm, DMI_BOARD_NAME, 5);
Andrey Panin1249c512005-06-25 14:54:47 -0700391 dmi_save_ident(dm, DMI_BOARD_VERSION, 6);
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200392 dmi_save_ident(dm, DMI_BOARD_SERIAL, 7);
393 dmi_save_ident(dm, DMI_BOARD_ASSET_TAG, 8);
394 break;
395 case 3: /* Chassis Information */
396 dmi_save_ident(dm, DMI_CHASSIS_VENDOR, 4);
397 dmi_save_type(dm, DMI_CHASSIS_TYPE, 5);
398 dmi_save_ident(dm, DMI_CHASSIS_VERSION, 6);
399 dmi_save_ident(dm, DMI_CHASSIS_SERIAL, 7);
400 dmi_save_ident(dm, DMI_CHASSIS_ASSET_TAG, 8);
Andrey Panin1249c512005-06-25 14:54:47 -0700401 break;
Andrey Paninebad6a42005-09-06 15:18:29 -0700402 case 10: /* Onboard Devices Information */
403 dmi_save_devices(dm);
404 break;
Shem Multinymous2e0c1f62006-09-29 01:59:37 -0700405 case 11: /* OEM Strings */
406 dmi_save_oem_strings_devices(dm);
407 break;
Andrey Paninebad6a42005-09-06 15:18:29 -0700408 case 38: /* IPMI Device Information */
409 dmi_save_ipmi_device(dm);
Wim Van Sebroeckb4bd7d52008-02-08 04:20:58 -0800410 break;
411 case 41: /* Onboard Devices Extended Information */
412 dmi_save_extended_devices(dm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 }
414}
415
Tejun Heoc90fe6b2013-04-30 15:27:14 -0700416static int __init print_filtered(char *buf, size_t len, const char *info)
Bjorn Helgaas8881cdc2010-10-27 15:32:59 -0700417{
Tejun Heoc90fe6b2013-04-30 15:27:14 -0700418 int c = 0;
Bjorn Helgaas8881cdc2010-10-27 15:32:59 -0700419 const char *p;
420
421 if (!info)
Tejun Heoc90fe6b2013-04-30 15:27:14 -0700422 return c;
Bjorn Helgaas8881cdc2010-10-27 15:32:59 -0700423
424 for (p = info; *p; p++)
425 if (isprint(*p))
Tejun Heoc90fe6b2013-04-30 15:27:14 -0700426 c += scnprintf(buf + c, len - c, "%c", *p);
Bjorn Helgaas8881cdc2010-10-27 15:32:59 -0700427 else
Tejun Heoc90fe6b2013-04-30 15:27:14 -0700428 c += scnprintf(buf + c, len - c, "\\x%02x", *p & 0xff);
429 return c;
Bjorn Helgaas8881cdc2010-10-27 15:32:59 -0700430}
431
Tejun Heoc90fe6b2013-04-30 15:27:14 -0700432static void __init dmi_format_ids(char *buf, size_t len)
Bjorn Helgaas8881cdc2010-10-27 15:32:59 -0700433{
Tejun Heoc90fe6b2013-04-30 15:27:14 -0700434 int c = 0;
Naga Chumbalkar84e383b2011-02-14 22:47:17 +0000435 const char *board; /* Board Name is optional */
436
Tejun Heoc90fe6b2013-04-30 15:27:14 -0700437 c += print_filtered(buf + c, len - c,
438 dmi_get_system_info(DMI_SYS_VENDOR));
439 c += scnprintf(buf + c, len - c, " ");
440 c += print_filtered(buf + c, len - c,
441 dmi_get_system_info(DMI_PRODUCT_NAME));
442
Naga Chumbalkar84e383b2011-02-14 22:47:17 +0000443 board = dmi_get_system_info(DMI_BOARD_NAME);
444 if (board) {
Tejun Heoc90fe6b2013-04-30 15:27:14 -0700445 c += scnprintf(buf + c, len - c, "/");
446 c += print_filtered(buf + c, len - c, board);
Naga Chumbalkar84e383b2011-02-14 22:47:17 +0000447 }
Tejun Heoc90fe6b2013-04-30 15:27:14 -0700448 c += scnprintf(buf + c, len - c, ", BIOS ");
449 c += print_filtered(buf + c, len - c,
450 dmi_get_system_info(DMI_BIOS_VERSION));
451 c += scnprintf(buf + c, len - c, " ");
452 c += print_filtered(buf + c, len - c,
453 dmi_get_system_info(DMI_BIOS_DATE));
Bjorn Helgaas8881cdc2010-10-27 15:32:59 -0700454}
455
Ben Hutchingsd39de282013-07-31 13:53:30 -0700456/*
457 * Check for DMI/SMBIOS headers in the system firmware image. Any
458 * SMBIOS header must start 16 bytes before the DMI header, so take a
459 * 32 byte buffer and check for DMI at offset 16 and SMBIOS at offset
460 * 0. If the DMI header is present, set dmi_ver accordingly (SMBIOS
461 * takes precedence) and return 0. Otherwise return 1.
462 */
Ben Hutchings79bae422013-04-30 15:27:46 -0700463static int __init dmi_present(const u8 *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464{
Ben Hutchings79bae422013-04-30 15:27:46 -0700465 int smbios_ver;
Jeff Garzik18552562007-10-03 15:15:40 -0400466
Ben Hutchings79bae422013-04-30 15:27:46 -0700467 if (memcmp(buf, "_SM_", 4) == 0 &&
468 buf[5] < 32 && dmi_checksum(buf, buf[5])) {
469 smbios_ver = (buf[6] << 8) + buf[7];
470
471 /* Some BIOS report weird SMBIOS version, fix that up */
472 switch (smbios_ver) {
473 case 0x021F:
474 case 0x0221:
475 pr_debug("SMBIOS version fixup(2.%d->2.%d)\n",
476 smbios_ver & 0xFF, 3);
477 smbios_ver = 0x0203;
478 break;
479 case 0x0233:
480 pr_debug("SMBIOS version fixup(2.%d->2.%d)\n", 51, 6);
481 smbios_ver = 0x0206;
482 break;
483 }
484 } else {
485 smbios_ver = 0;
486 }
487
488 buf += 16;
489
490 if (memcmp(buf, "_DMI_", 5) == 0 && dmi_checksum(buf, 15)) {
Jean Delvare7fce0842007-11-03 17:29:20 +0100491 dmi_num = (buf[13] << 8) | buf[12];
492 dmi_len = (buf[7] << 8) | buf[6];
493 dmi_base = (buf[11] << 24) | (buf[10] << 16) |
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800494 (buf[9] << 8) | buf[8];
495
Bjorn Helgaas8881cdc2010-10-27 15:32:59 -0700496 if (dmi_walk_early(dmi_decode) == 0) {
Ben Hutchings79bae422013-04-30 15:27:46 -0700497 if (smbios_ver) {
498 dmi_ver = smbios_ver;
Zhenzhong Duan9f9c9cbb2012-12-20 15:05:14 -0800499 pr_info("SMBIOS %d.%d present.\n",
500 dmi_ver >> 8, dmi_ver & 0xFF);
Ben Hutchings79bae422013-04-30 15:27:46 -0700501 } else {
Zhenzhong Duan9f9c9cbb2012-12-20 15:05:14 -0800502 dmi_ver = (buf[14] & 0xF0) << 4 |
503 (buf[14] & 0x0F);
504 pr_info("Legacy DMI %d.%d present.\n",
505 dmi_ver >> 8, dmi_ver & 0xFF);
506 }
Tejun Heoc90fe6b2013-04-30 15:27:14 -0700507 dmi_format_ids(dmi_ids_string, sizeof(dmi_ids_string));
508 printk(KERN_DEBUG "DMI: %s\n", dmi_ids_string);
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800509 return 0;
Bjorn Helgaas8881cdc2010-10-27 15:32:59 -0700510 }
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800511 }
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800512
Ben Hutchingsa40e7cf2013-03-08 12:43:32 -0800513 return 1;
Zhenzhong Duan9f9c9cbb2012-12-20 15:05:14 -0800514}
515
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800516void __init dmi_scan_machine(void)
517{
Andrey Panin61e032f2005-09-06 15:18:26 -0700518 char __iomem *p, *q;
Ben Hutchings79bae422013-04-30 15:27:46 -0700519 char buf[32];
Andrey Panin61e032f2005-09-06 15:18:26 -0700520
Matt Fleming83e68182012-11-14 09:42:35 +0000521 if (efi_enabled(EFI_CONFIG_TABLES)) {
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800522 if (efi.smbios == EFI_INVALID_TABLE_ADDR)
Ingo Molnar9a22b6e2008-09-18 12:50:18 +0200523 goto error;
Andrey Panin61e032f2005-09-06 15:18:26 -0700524
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200525 /* This is called as a core_initcall() because it isn't
526 * needed during early boot. This also means we can
527 * iounmap the space when we're done with it.
528 */
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800529 p = dmi_ioremap(efi.smbios, 32);
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800530 if (p == NULL)
Ingo Molnar9a22b6e2008-09-18 12:50:18 +0200531 goto error;
Ben Hutchings79bae422013-04-30 15:27:46 -0700532 memcpy_fromio(buf, p, 32);
Tolentino, Matthew E23dd8422006-03-26 01:37:09 -0800533 dmi_iounmap(p, 32);
Ben Hutchings79bae422013-04-30 15:27:46 -0700534
535 if (!dmi_present(buf)) {
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200536 dmi_available = 1;
Ingo Molnar9a22b6e2008-09-18 12:50:18 +0200537 goto out;
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200538 }
Jean Delvare02d9c472013-09-11 14:24:08 -0700539 } else {
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800540 p = dmi_ioremap(0xF0000, 0x10000);
541 if (p == NULL)
Ingo Molnar9a22b6e2008-09-18 12:50:18 +0200542 goto error;
Andrey Panin61e032f2005-09-06 15:18:26 -0700543
Ben Hutchingsd39de282013-07-31 13:53:30 -0700544 /*
545 * Iterate over all possible DMI header addresses q.
546 * Maintain the 32 bytes around q in buf. On the
547 * first iteration, substitute zero for the
548 * out-of-range bytes so there is no chance of falsely
549 * detecting an SMBIOS header.
550 */
Ben Hutchings79bae422013-04-30 15:27:46 -0700551 memset(buf, 0, 16);
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800552 for (q = p; q < p + 0x10000; q += 16) {
Ben Hutchings79bae422013-04-30 15:27:46 -0700553 memcpy_fromio(buf + 16, q, 16);
554 if (!dmi_present(buf)) {
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200555 dmi_available = 1;
Ingo Molnar0d644842008-01-30 13:33:09 +0100556 dmi_iounmap(p, 0x10000);
Ingo Molnar9a22b6e2008-09-18 12:50:18 +0200557 goto out;
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200558 }
Ben Hutchings79bae422013-04-30 15:27:46 -0700559 memcpy(buf, buf + 16, 16);
Andrey Panin61e032f2005-09-06 15:18:26 -0700560 }
Yinghai Lu3212bff2008-01-30 13:33:32 +0100561 dmi_iounmap(p, 0x10000);
Andrey Panin61e032f2005-09-06 15:18:26 -0700562 }
Ingo Molnar9a22b6e2008-09-18 12:50:18 +0200563 error:
Jean Delvare02d9c472013-09-11 14:24:08 -0700564 pr_info("DMI not present or invalid.\n");
Ingo Molnar9a22b6e2008-09-18 12:50:18 +0200565 out:
566 dmi_initialized = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567}
568
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569/**
Tejun Heo98e5e1b2013-04-30 15:27:15 -0700570 * dmi_set_dump_stack_arch_desc - set arch description for dump_stack()
571 *
572 * Invoke dump_stack_set_arch_desc() with DMI system information so that
573 * DMI identifiers are printed out on task dumps. Arch boot code should
574 * call this function after dmi_scan_machine() if it wants to print out DMI
575 * identifiers on task dumps.
576 */
577void __init dmi_set_dump_stack_arch_desc(void)
578{
579 dump_stack_set_arch_desc("%s", dmi_ids_string);
580}
581
582/**
Rafael J. Wysockid7b19562009-01-19 20:55:50 +0100583 * dmi_matches - check if dmi_system_id structure matches system DMI data
584 * @dmi: pointer to the dmi_system_id structure to check
585 */
586static bool dmi_matches(const struct dmi_system_id *dmi)
587{
588 int i;
589
590 WARN(!dmi_initialized, KERN_ERR "dmi check: not initialized yet.\n");
591
592 for (i = 0; i < ARRAY_SIZE(dmi->matches); i++) {
593 int s = dmi->matches[i].slot;
594 if (s == DMI_NONE)
Dmitry Torokhov75757502009-12-04 10:24:19 -0800595 break;
Jani Nikula5017b282013-07-03 15:05:02 -0700596 if (dmi_ident[s]) {
597 if (!dmi->matches[i].exact_match &&
598 strstr(dmi_ident[s], dmi->matches[i].substr))
599 continue;
600 else if (dmi->matches[i].exact_match &&
601 !strcmp(dmi_ident[s], dmi->matches[i].substr))
602 continue;
603 }
604
Rafael J. Wysockid7b19562009-01-19 20:55:50 +0100605 /* No match */
606 return false;
607 }
608 return true;
609}
610
611/**
Dmitry Torokhov75757502009-12-04 10:24:19 -0800612 * dmi_is_end_of_table - check for end-of-table marker
613 * @dmi: pointer to the dmi_system_id structure to check
614 */
615static bool dmi_is_end_of_table(const struct dmi_system_id *dmi)
616{
617 return dmi->matches[0].slot == DMI_NONE;
618}
619
620/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 * dmi_check_system - check system DMI data
622 * @list: array of dmi_system_id structures to match against
Randy Dunlapb0ef3712006-06-25 05:49:18 -0700623 * All non-null elements of the list must match
624 * their slot's (field index's) data (i.e., each
625 * list string must be a substring of the specified
626 * DMI slot's string data) to be considered a
627 * successful match.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 *
629 * Walk the blacklist table running matching functions until someone
630 * returns non zero or we hit the end. Callback function is called for
Randy Dunlapb0ef3712006-06-25 05:49:18 -0700631 * each successful match. Returns the number of matches.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 */
Jeff Garzik18552562007-10-03 15:15:40 -0400633int dmi_check_system(const struct dmi_system_id *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634{
Rafael J. Wysockid7b19562009-01-19 20:55:50 +0100635 int count = 0;
636 const struct dmi_system_id *d;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637
Dmitry Torokhov75757502009-12-04 10:24:19 -0800638 for (d = list; !dmi_is_end_of_table(d); d++)
Rafael J. Wysockid7b19562009-01-19 20:55:50 +0100639 if (dmi_matches(d)) {
640 count++;
641 if (d->callback && d->callback(d))
642 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
645 return count;
646}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647EXPORT_SYMBOL(dmi_check_system);
648
649/**
Rafael J. Wysockid7b19562009-01-19 20:55:50 +0100650 * dmi_first_match - find dmi_system_id structure matching system DMI data
651 * @list: array of dmi_system_id structures to match against
652 * All non-null elements of the list must match
653 * their slot's (field index's) data (i.e., each
654 * list string must be a substring of the specified
655 * DMI slot's string data) to be considered a
656 * successful match.
657 *
658 * Walk the blacklist table until the first match is found. Return the
659 * pointer to the matching entry or NULL if there's no match.
660 */
661const struct dmi_system_id *dmi_first_match(const struct dmi_system_id *list)
662{
663 const struct dmi_system_id *d;
664
Dmitry Torokhov75757502009-12-04 10:24:19 -0800665 for (d = list; !dmi_is_end_of_table(d); d++)
Rafael J. Wysockid7b19562009-01-19 20:55:50 +0100666 if (dmi_matches(d))
667 return d;
668
669 return NULL;
670}
671EXPORT_SYMBOL(dmi_first_match);
672
673/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 * dmi_get_system_info - return DMI data value
Randy Dunlapb0ef3712006-06-25 05:49:18 -0700675 * @field: data index (see enum dmi_field)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 *
677 * Returns one DMI data value, can be used to perform
678 * complex DMI data checks.
679 */
Jeff Garzik18552562007-10-03 15:15:40 -0400680const char *dmi_get_system_info(int field)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681{
682 return dmi_ident[field];
683}
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700684EXPORT_SYMBOL(dmi_get_system_info);
Andrey Paninebad6a42005-09-06 15:18:29 -0700685
Alok Katariafd8cd7e2008-11-03 15:50:38 -0800686/**
Randy Dunlapc2bacfc2009-01-06 14:41:40 -0800687 * dmi_name_in_serial - Check if string is in the DMI product serial information
688 * @str: string to check for
Alok Katariafd8cd7e2008-11-03 15:50:38 -0800689 */
690int dmi_name_in_serial(const char *str)
691{
692 int f = DMI_PRODUCT_SERIAL;
693 if (dmi_ident[f] && strstr(dmi_ident[f], str))
694 return 1;
695 return 0;
696}
Andi Kleena1bae672006-10-21 18:37:02 +0200697
698/**
Jean Delvare66e13e62011-11-15 14:36:09 -0800699 * dmi_name_in_vendors - Check if string is in the DMI system or board vendor name
Jean Delvare02d9c472013-09-11 14:24:08 -0700700 * @str: Case sensitive Name
Andi Kleena1bae672006-10-21 18:37:02 +0200701 */
Jeff Garzik18552562007-10-03 15:15:40 -0400702int dmi_name_in_vendors(const char *str)
Andi Kleena1bae672006-10-21 18:37:02 +0200703{
Jean Delvare66e13e62011-11-15 14:36:09 -0800704 static int fields[] = { DMI_SYS_VENDOR, DMI_BOARD_VENDOR, DMI_NONE };
Andi Kleena1bae672006-10-21 18:37:02 +0200705 int i;
706 for (i = 0; fields[i] != DMI_NONE; i++) {
707 int f = fields[i];
708 if (dmi_ident[f] && strstr(dmi_ident[f], str))
709 return 1;
710 }
711 return 0;
712}
713EXPORT_SYMBOL(dmi_name_in_vendors);
714
Andrey Paninebad6a42005-09-06 15:18:29 -0700715/**
716 * dmi_find_device - find onboard device by type/name
717 * @type: device type or %DMI_DEV_TYPE_ANY to match all device types
Randy Dunlapb0ef3712006-06-25 05:49:18 -0700718 * @name: device name string or %NULL to match all
Andrey Paninebad6a42005-09-06 15:18:29 -0700719 * @from: previous device found in search, or %NULL for new search.
720 *
721 * Iterates through the list of known onboard devices. If a device is
722 * found with a matching @vendor and @device, a pointer to its device
723 * structure is returned. Otherwise, %NULL is returned.
Randy Dunlapb0ef3712006-06-25 05:49:18 -0700724 * A new search is initiated by passing %NULL as the @from argument.
Andrey Paninebad6a42005-09-06 15:18:29 -0700725 * If @from is not %NULL, searches continue from next device.
726 */
Jean Delvare02d9c472013-09-11 14:24:08 -0700727const struct dmi_device *dmi_find_device(int type, const char *name,
Jeff Garzik18552562007-10-03 15:15:40 -0400728 const struct dmi_device *from)
Andrey Paninebad6a42005-09-06 15:18:29 -0700729{
Jeff Garzik18552562007-10-03 15:15:40 -0400730 const struct list_head *head = from ? &from->list : &dmi_devices;
731 struct list_head *d;
Andrey Paninebad6a42005-09-06 15:18:29 -0700732
Jean Delvare02d9c472013-09-11 14:24:08 -0700733 for (d = head->next; d != &dmi_devices; d = d->next) {
Jeff Garzik18552562007-10-03 15:15:40 -0400734 const struct dmi_device *dev =
735 list_entry(d, struct dmi_device, list);
Andrey Paninebad6a42005-09-06 15:18:29 -0700736
737 if (((type == DMI_DEV_TYPE_ANY) || (dev->type == type)) &&
738 ((name == NULL) || (strcmp(dev->name, name) == 0)))
739 return dev;
740 }
741
742 return NULL;
743}
744EXPORT_SYMBOL(dmi_find_device);
Andi Kleenf083a322006-03-25 16:30:19 +0100745
746/**
Tejun Heo3e5cd1f2009-08-16 21:02:36 +0900747 * dmi_get_date - parse a DMI date
748 * @field: data index (see enum dmi_field)
749 * @yearp: optional out parameter for the year
750 * @monthp: optional out parameter for the month
751 * @dayp: optional out parameter for the day
Andi Kleenf083a322006-03-25 16:30:19 +0100752 *
Tejun Heo3e5cd1f2009-08-16 21:02:36 +0900753 * The date field is assumed to be in the form resembling
754 * [mm[/dd]]/yy[yy] and the result is stored in the out
755 * parameters any or all of which can be omitted.
756 *
757 * If the field doesn't exist, all out parameters are set to zero
758 * and false is returned. Otherwise, true is returned with any
759 * invalid part of date set to zero.
760 *
761 * On return, year, month and day are guaranteed to be in the
762 * range of [0,9999], [0,12] and [0,31] respectively.
Andi Kleenf083a322006-03-25 16:30:19 +0100763 */
Tejun Heo3e5cd1f2009-08-16 21:02:36 +0900764bool dmi_get_date(int field, int *yearp, int *monthp, int *dayp)
Andi Kleenf083a322006-03-25 16:30:19 +0100765{
Tejun Heo3e5cd1f2009-08-16 21:02:36 +0900766 int year = 0, month = 0, day = 0;
767 bool exists;
768 const char *s, *y;
Tejun Heo02c24fa2009-08-16 21:01:22 +0900769 char *e;
Andi Kleenf083a322006-03-25 16:30:19 +0100770
Tejun Heo3e5cd1f2009-08-16 21:02:36 +0900771 s = dmi_get_system_info(field);
772 exists = s;
773 if (!exists)
774 goto out;
Andi Kleenf083a322006-03-25 16:30:19 +0100775
Tejun Heo3e5cd1f2009-08-16 21:02:36 +0900776 /*
777 * Determine year first. We assume the date string resembles
778 * mm/dd/yy[yy] but the original code extracted only the year
779 * from the end. Keep the behavior in the spirit of no
780 * surprises.
781 */
782 y = strrchr(s, '/');
783 if (!y)
784 goto out;
785
786 y++;
787 year = simple_strtoul(y, &e, 10);
788 if (y != e && year < 100) { /* 2-digit year */
Andi Kleenf083a322006-03-25 16:30:19 +0100789 year += 1900;
790 if (year < 1996) /* no dates < spec 1.0 */
791 year += 100;
792 }
Tejun Heo3e5cd1f2009-08-16 21:02:36 +0900793 if (year > 9999) /* year should fit in %04d */
794 year = 0;
Andi Kleenf083a322006-03-25 16:30:19 +0100795
Tejun Heo3e5cd1f2009-08-16 21:02:36 +0900796 /* parse the mm and dd */
797 month = simple_strtoul(s, &e, 10);
798 if (s == e || *e != '/' || !month || month > 12) {
799 month = 0;
800 goto out;
801 }
802
803 s = e + 1;
804 day = simple_strtoul(s, &e, 10);
805 if (s == y || s == e || *e != '/' || day > 31)
806 day = 0;
807out:
808 if (yearp)
809 *yearp = year;
810 if (monthp)
811 *monthp = month;
812 if (dayp)
813 *dayp = day;
814 return exists;
Andi Kleenf083a322006-03-25 16:30:19 +0100815}
Tejun Heo3e5cd1f2009-08-16 21:02:36 +0900816EXPORT_SYMBOL(dmi_get_date);
Jean Delvare7fce0842007-11-03 17:29:20 +0100817
818/**
819 * dmi_walk - Walk the DMI table and get called back for every record
820 * @decode: Callback function
Jean Delvaree7a19c562009-03-30 21:46:44 +0200821 * @private_data: Private data to be passed to the callback function
Jean Delvare7fce0842007-11-03 17:29:20 +0100822 *
823 * Returns -1 when the DMI table can't be reached, 0 on success.
824 */
Jean Delvaree7a19c562009-03-30 21:46:44 +0200825int dmi_walk(void (*decode)(const struct dmi_header *, void *),
826 void *private_data)
Jean Delvare7fce0842007-11-03 17:29:20 +0100827{
828 u8 *buf;
829
830 if (!dmi_available)
831 return -1;
832
833 buf = ioremap(dmi_base, dmi_len);
834 if (buf == NULL)
835 return -1;
836
Jean Delvaree7a19c562009-03-30 21:46:44 +0200837 dmi_table(buf, dmi_len, dmi_num, decode, private_data);
Jean Delvare7fce0842007-11-03 17:29:20 +0100838
839 iounmap(buf);
840 return 0;
841}
842EXPORT_SYMBOL_GPL(dmi_walk);
Jiri Slabyd61c72e2008-12-10 14:07:21 +0100843
844/**
845 * dmi_match - compare a string to the dmi field (if exists)
Randy Dunlapc2bacfc2009-01-06 14:41:40 -0800846 * @f: DMI field identifier
847 * @str: string to compare the DMI field to
Jiri Slabyd61c72e2008-12-10 14:07:21 +0100848 *
849 * Returns true if the requested field equals to the str (including NULL).
850 */
851bool dmi_match(enum dmi_field f, const char *str)
852{
853 const char *info = dmi_get_system_info(f);
854
855 if (info == NULL || str == NULL)
856 return info == str;
857
858 return !strcmp(info, str);
859}
860EXPORT_SYMBOL_GPL(dmi_match);
Chen, Gongdd6dad42013-10-18 14:29:25 -0700861
862void dmi_memdev_name(u16 handle, const char **bank, const char **device)
863{
864 int n;
865
866 if (dmi_memdev == NULL)
867 return;
868
869 for (n = 0; n < dmi_memdev_nr; n++) {
870 if (handle == dmi_memdev[n].handle) {
871 *bank = dmi_memdev[n].bank;
872 *device = dmi_memdev[n].device;
873 break;
874 }
875 }
876}
877EXPORT_SYMBOL_GPL(dmi_memdev_name);