blob: c8f9e9d3bf9163c8b76fd846d5093a8501cb1957 [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>
Luck, Tony0841c042013-11-01 13:59:52 -070011#include <asm/unaligned.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
Paul Jacksoncb5dd7c2008-05-14 08:15:16 -070013/*
14 * DMI stands for "Desktop Management Interface". It is part
15 * of and an antecedent to, SMBIOS, which stands for System
16 * Management BIOS. See further: http://www.dmtf.org/standards
17 */
Jean Delvareffbbb962013-09-11 14:24:09 -070018static const char dmi_empty_string[] = " ";
Parag Warudkar79da4722008-01-30 13:31:59 +010019
Ivan Khoronzhuk95be58d2015-02-18 13:33:20 +020020static u32 dmi_ver __initdata;
Ingo Molnar9a22b6e2008-09-18 12:50:18 +020021/*
22 * Catch too early calls to dmi_check_system():
23 */
24static int dmi_initialized;
25
Tejun Heoc90fe6b2013-04-30 15:27:14 -070026/* DMI system identification string used during boot */
27static char dmi_ids_string[128] __initdata;
28
Chen, Gongdd6dad42013-10-18 14:29:25 -070029static struct dmi_memdev_info {
30 const char *device;
31 const char *bank;
32 u16 handle;
33} *dmi_memdev;
34static int dmi_memdev_nr;
35
Jean Delvaref3069ae2008-02-23 15:23:46 -080036static const char * __init dmi_string_nosave(const struct dmi_header *dm, u8 s)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037{
Jeff Garzik18552562007-10-03 15:15:40 -040038 const u8 *bp = ((u8 *) dm) + dm->length;
Andrey Panin1249c512005-06-25 14:54:47 -070039
Andrey Paninc3c71202005-09-06 15:18:28 -070040 if (s) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 s--;
Andrey Paninc3c71202005-09-06 15:18:28 -070042 while (s > 0 && *bp) {
43 bp += strlen(bp) + 1;
44 s--;
45 }
46
47 if (*bp != 0) {
Parag Warudkar79da4722008-01-30 13:31:59 +010048 size_t len = strlen(bp)+1;
49 size_t cmp_len = len > 8 ? 8 : len;
50
51 if (!memcmp(bp, dmi_empty_string, cmp_len))
52 return dmi_empty_string;
Jean Delvaref3069ae2008-02-23 15:23:46 -080053 return bp;
Andrey Paninc3c71202005-09-06 15:18:28 -070054 }
Bjorn Helgaas4f705ae2006-04-03 17:09:22 -070055 }
Andrey Paninc3c71202005-09-06 15:18:28 -070056
Jean Delvaref3069ae2008-02-23 15:23:46 -080057 return "";
58}
59
Jean Delvareffbbb962013-09-11 14:24:09 -070060static const char * __init dmi_string(const struct dmi_header *dm, u8 s)
Jean Delvaref3069ae2008-02-23 15:23:46 -080061{
62 const char *bp = dmi_string_nosave(dm, s);
63 char *str;
64 size_t len;
65
66 if (bp == dmi_empty_string)
67 return dmi_empty_string;
68
69 len = strlen(bp) + 1;
70 str = dmi_alloc(len);
71 if (str != NULL)
72 strcpy(str, bp);
Jean Delvaref3069ae2008-02-23 15:23:46 -080073
Andrey Paninc3c71202005-09-06 15:18:28 -070074 return str;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075}
76
77/*
78 * We have to be cautious here. We have seen BIOSes with DMI pointers
79 * pointing to completely the wrong place for example
80 */
Ivan Khoronzhuk6d9ff472015-02-18 13:33:19 +020081static void dmi_table(u8 *buf, u32 len, int num,
Jean Delvaree7a19c562009-03-30 21:46:44 +020082 void (*decode)(const struct dmi_header *, void *),
83 void *private_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
Jean Delvare7fce0842007-11-03 17:29:20 +010085 u8 *data = buf;
Andrey Panin1249c512005-06-25 14:54:47 -070086 int i = 0;
Bjorn Helgaas4f705ae2006-04-03 17:09:22 -070087
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 /*
Bjorn Helgaas4f705ae2006-04-03 17:09:22 -070089 * Stop when we see all the items the table claimed to have
90 * OR we run off the end of the table (also happens)
91 */
Andrey Panin1249c512005-06-25 14:54:47 -070092 while ((i < num) && (data - buf + sizeof(struct dmi_header)) <= len) {
Jeff Garzik18552562007-10-03 15:15:40 -040093 const struct dmi_header *dm = (const struct dmi_header *)data;
94
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 /*
Alan Cox86385452008-11-07 16:03:46 +000096 * We want to know the total length (formatted area and
97 * strings) before decoding to make sure we won't run off the
98 * table in dmi_decode or dmi_string
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 */
Andrey Panin1249c512005-06-25 14:54:47 -0700100 data += dm->length;
101 while ((data - buf < len - 1) && (data[0] || data[1]))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 data++;
Andrey Panin1249c512005-06-25 14:54:47 -0700103 if (data - buf < len - 1)
Jean Delvaree7a19c562009-03-30 21:46:44 +0200104 decode(dm, private_data);
Ivan Khoronzhukce204e92015-02-18 15:51:41 +0200105
106 /*
107 * 7.45 End-of-Table (Type 127) [SMBIOS reference spec v3.0.0]
108 */
109 if (dm->type == DMI_ENTRY_END_OF_TABLE)
110 break;
111
Andrey Panin1249c512005-06-25 14:54:47 -0700112 data += 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 i++;
114 }
Jean Delvare7fce0842007-11-03 17:29:20 +0100115}
116
Ard Biesheuvelfc430262014-10-14 16:41:27 +0200117static phys_addr_t dmi_base;
Ivan Khoronzhuk6d9ff472015-02-18 13:33:19 +0200118static u32 dmi_len;
Jean Delvare7fce0842007-11-03 17:29:20 +0100119static u16 dmi_num;
120
Jean Delvaree7a19c562009-03-30 21:46:44 +0200121static int __init dmi_walk_early(void (*decode)(const struct dmi_header *,
122 void *))
Jean Delvare7fce0842007-11-03 17:29:20 +0100123{
124 u8 *buf;
125
Ard Biesheuvelcf074402014-01-23 15:54:39 -0800126 buf = dmi_early_remap(dmi_base, dmi_len);
Jean Delvare7fce0842007-11-03 17:29:20 +0100127 if (buf == NULL)
128 return -1;
129
Jean Delvaree7a19c562009-03-30 21:46:44 +0200130 dmi_table(buf, dmi_len, dmi_num, decode, NULL);
Jean Delvare7fce0842007-11-03 17:29:20 +0100131
Tony Luckd114a332012-07-20 13:15:20 -0700132 add_device_randomness(buf, dmi_len);
133
Ard Biesheuvelcf074402014-01-23 15:54:39 -0800134 dmi_early_unmap(buf, dmi_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 return 0;
136}
137
Zhenzhong Duan9f9c9cbb2012-12-20 15:05:14 -0800138static int __init dmi_checksum(const u8 *buf, u8 len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139{
Andrey Panin1249c512005-06-25 14:54:47 -0700140 u8 sum = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 int a;
Bjorn Helgaas4f705ae2006-04-03 17:09:22 -0700142
Zhenzhong Duan9f9c9cbb2012-12-20 15:05:14 -0800143 for (a = 0; a < len; a++)
Andrey Panin1249c512005-06-25 14:54:47 -0700144 sum += buf[a];
145
146 return sum == 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147}
148
Jean Delvareffbbb962013-09-11 14:24:09 -0700149static const char *dmi_ident[DMI_STRING_MAX];
Andrey Paninebad6a42005-09-06 15:18:29 -0700150static LIST_HEAD(dmi_devices);
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200151int dmi_available;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153/*
154 * Save a DMI string
155 */
Jean Delvare02d9c472013-09-11 14:24:08 -0700156static void __init dmi_save_ident(const struct dmi_header *dm, int slot,
157 int string)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
Jean Delvare02d9c472013-09-11 14:24:08 -0700159 const char *d = (const char *) dm;
Jean Delvareffbbb962013-09-11 14:24:09 -0700160 const char *p;
Andrey Panin1249c512005-06-25 14:54:47 -0700161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 if (dmi_ident[slot])
163 return;
Andrey Panin1249c512005-06-25 14:54:47 -0700164
Andrey Paninc3c71202005-09-06 15:18:28 -0700165 p = dmi_string(dm, d[string]);
166 if (p == NULL)
167 return;
168
169 dmi_ident[slot] = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170}
171
Jean Delvare02d9c472013-09-11 14:24:08 -0700172static void __init dmi_save_uuid(const struct dmi_header *dm, int slot,
173 int index)
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200174{
Jean Delvare02d9c472013-09-11 14:24:08 -0700175 const u8 *d = (u8 *) dm + index;
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200176 char *s;
177 int is_ff = 1, is_00 = 1, i;
178
179 if (dmi_ident[slot])
180 return;
181
182 for (i = 0; i < 16 && (is_ff || is_00); i++) {
Zhenzhong Duanf1d8e612012-12-20 15:05:13 -0800183 if (d[i] != 0x00)
184 is_00 = 0;
185 if (d[i] != 0xFF)
186 is_ff = 0;
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200187 }
188
189 if (is_ff || is_00)
190 return;
191
192 s = dmi_alloc(16*2+4+1);
193 if (!s)
194 return;
195
Zhenzhong Duanf1d8e612012-12-20 15:05:13 -0800196 /*
197 * As of version 2.6 of the SMBIOS specification, the first 3 fields of
198 * the UUID are supposed to be little-endian encoded. The specification
199 * says that this is the defacto standard.
200 */
Ivan Khoronzhuk95be58d2015-02-18 13:33:20 +0200201 if (dmi_ver >= 0x020600)
Zhenzhong Duanf1d8e612012-12-20 15:05:13 -0800202 sprintf(s, "%pUL", d);
203 else
204 sprintf(s, "%pUB", d);
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200205
Jean Delvare02d9c472013-09-11 14:24:08 -0700206 dmi_ident[slot] = s;
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200207}
208
Jean Delvare02d9c472013-09-11 14:24:08 -0700209static void __init dmi_save_type(const struct dmi_header *dm, int slot,
210 int index)
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200211{
Jean Delvare02d9c472013-09-11 14:24:08 -0700212 const u8 *d = (u8 *) dm + index;
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200213 char *s;
214
215 if (dmi_ident[slot])
216 return;
217
218 s = dmi_alloc(4);
219 if (!s)
220 return;
221
222 sprintf(s, "%u", *d & 0x7F);
223 dmi_ident[slot] = s;
224}
225
Jean Delvaref3069ae2008-02-23 15:23:46 -0800226static void __init dmi_save_one_device(int type, const char *name)
227{
228 struct dmi_device *dev;
229
230 /* No duplicate device */
231 if (dmi_find_device(type, name, NULL))
232 return;
233
234 dev = dmi_alloc(sizeof(*dev) + strlen(name) + 1);
Jean Delvareae797442013-09-11 14:24:10 -0700235 if (!dev)
Jean Delvaref3069ae2008-02-23 15:23:46 -0800236 return;
Jean Delvaref3069ae2008-02-23 15:23:46 -0800237
238 dev->type = type;
239 strcpy((char *)(dev + 1), name);
240 dev->name = (char *)(dev + 1);
241 dev->device_data = NULL;
242 list_add(&dev->list, &dmi_devices);
243}
244
Jeff Garzik18552562007-10-03 15:15:40 -0400245static void __init dmi_save_devices(const struct dmi_header *dm)
Andrey Paninebad6a42005-09-06 15:18:29 -0700246{
247 int i, count = (dm->length - sizeof(struct dmi_header)) / 2;
Andrey Paninebad6a42005-09-06 15:18:29 -0700248
249 for (i = 0; i < count; i++) {
Jeff Garzik18552562007-10-03 15:15:40 -0400250 const char *d = (char *)(dm + 1) + (i * 2);
Andrey Paninebad6a42005-09-06 15:18:29 -0700251
252 /* Skip disabled device */
253 if ((*d & 0x80) == 0)
254 continue;
255
Jean Delvaref3069ae2008-02-23 15:23:46 -0800256 dmi_save_one_device(*d & 0x7f, dmi_string_nosave(dm, *(d + 1)));
Shem Multinymous2e0c1f62006-09-29 01:59:37 -0700257 }
258}
259
Jeff Garzik18552562007-10-03 15:15:40 -0400260static void __init dmi_save_oem_strings_devices(const struct dmi_header *dm)
Shem Multinymous2e0c1f62006-09-29 01:59:37 -0700261{
262 int i, count = *(u8 *)(dm + 1);
263 struct dmi_device *dev;
264
265 for (i = 1; i <= count; i++) {
Jean Delvareffbbb962013-09-11 14:24:09 -0700266 const char *devname = dmi_string(dm, i);
Parag Warudkar79da4722008-01-30 13:31:59 +0100267
Jean Delvare43fe1052008-02-23 15:23:55 -0800268 if (devname == dmi_empty_string)
Parag Warudkar79da4722008-01-30 13:31:59 +0100269 continue;
Parag Warudkar79da4722008-01-30 13:31:59 +0100270
Shem Multinymous2e0c1f62006-09-29 01:59:37 -0700271 dev = dmi_alloc(sizeof(*dev));
Jean Delvareae797442013-09-11 14:24:10 -0700272 if (!dev)
Shem Multinymous2e0c1f62006-09-29 01:59:37 -0700273 break;
Shem Multinymous2e0c1f62006-09-29 01:59:37 -0700274
275 dev->type = DMI_DEV_TYPE_OEM_STRING;
Parag Warudkar79da4722008-01-30 13:31:59 +0100276 dev->name = devname;
Shem Multinymous2e0c1f62006-09-29 01:59:37 -0700277 dev->device_data = NULL;
Andrey Paninebad6a42005-09-06 15:18:29 -0700278
279 list_add(&dev->list, &dmi_devices);
280 }
281}
282
Jeff Garzik18552562007-10-03 15:15:40 -0400283static void __init dmi_save_ipmi_device(const struct dmi_header *dm)
Andrey Paninebad6a42005-09-06 15:18:29 -0700284{
285 struct dmi_device *dev;
Jean Delvare02d9c472013-09-11 14:24:08 -0700286 void *data;
Andrey Paninebad6a42005-09-06 15:18:29 -0700287
Andi Kleene9928672006-01-11 22:43:33 +0100288 data = dmi_alloc(dm->length);
Jean Delvareae797442013-09-11 14:24:10 -0700289 if (data == NULL)
Andrey Paninebad6a42005-09-06 15:18:29 -0700290 return;
Andrey Paninebad6a42005-09-06 15:18:29 -0700291
292 memcpy(data, dm, dm->length);
293
Andi Kleene9928672006-01-11 22:43:33 +0100294 dev = dmi_alloc(sizeof(*dev));
Jean Delvareae797442013-09-11 14:24:10 -0700295 if (!dev)
Andrey Paninebad6a42005-09-06 15:18:29 -0700296 return;
Andrey Paninebad6a42005-09-06 15:18:29 -0700297
298 dev->type = DMI_DEV_TYPE_IPMI;
299 dev->name = "IPMI controller";
300 dev->device_data = data;
301
Carol Hebertabd24df2008-04-04 14:30:03 -0700302 list_add_tail(&dev->list, &dmi_devices);
Andrey Paninebad6a42005-09-06 15:18:29 -0700303}
304
Narendra K911e1c92010-07-26 05:56:50 -0500305static void __init dmi_save_dev_onboard(int instance, int segment, int bus,
306 int devfn, const char *name)
307{
308 struct dmi_dev_onboard *onboard_dev;
309
310 onboard_dev = dmi_alloc(sizeof(*onboard_dev) + strlen(name) + 1);
Jean Delvareae797442013-09-11 14:24:10 -0700311 if (!onboard_dev)
Narendra K911e1c92010-07-26 05:56:50 -0500312 return;
Jean Delvareae797442013-09-11 14:24:10 -0700313
Narendra K911e1c92010-07-26 05:56:50 -0500314 onboard_dev->instance = instance;
315 onboard_dev->segment = segment;
316 onboard_dev->bus = bus;
317 onboard_dev->devfn = devfn;
318
319 strcpy((char *)&onboard_dev[1], name);
320 onboard_dev->dev.type = DMI_DEV_TYPE_DEV_ONBOARD;
321 onboard_dev->dev.name = (char *)&onboard_dev[1];
322 onboard_dev->dev.device_data = onboard_dev;
323
324 list_add(&onboard_dev->dev.list, &dmi_devices);
325}
326
Wim Van Sebroeckb4bd7d52008-02-08 04:20:58 -0800327static void __init dmi_save_extended_devices(const struct dmi_header *dm)
328{
Jean Delvare02d9c472013-09-11 14:24:08 -0700329 const u8 *d = (u8 *) dm + 5;
Wim Van Sebroeckb4bd7d52008-02-08 04:20:58 -0800330
331 /* Skip disabled device */
332 if ((*d & 0x80) == 0)
333 return;
334
Narendra K911e1c92010-07-26 05:56:50 -0500335 dmi_save_dev_onboard(*(d+1), *(u16 *)(d+2), *(d+4), *(d+5),
336 dmi_string_nosave(dm, *(d-1)));
Jean Delvaref3069ae2008-02-23 15:23:46 -0800337 dmi_save_one_device(*d & 0x7f, dmi_string_nosave(dm, *(d - 1)));
Wim Van Sebroeckb4bd7d52008-02-08 04:20:58 -0800338}
339
Chen, Gongdd6dad42013-10-18 14:29:25 -0700340static void __init count_mem_devices(const struct dmi_header *dm, void *v)
341{
342 if (dm->type != DMI_ENTRY_MEM_DEVICE)
343 return;
344 dmi_memdev_nr++;
345}
346
347static void __init save_mem_devices(const struct dmi_header *dm, void *v)
348{
349 const char *d = (const char *)dm;
350 static int nr;
351
352 if (dm->type != DMI_ENTRY_MEM_DEVICE)
353 return;
354 if (nr >= dmi_memdev_nr) {
355 pr_warn(FW_BUG "Too many DIMM entries in SMBIOS table\n");
356 return;
357 }
Luck, Tony0841c042013-11-01 13:59:52 -0700358 dmi_memdev[nr].handle = get_unaligned(&dm->handle);
Chen, Gongdd6dad42013-10-18 14:29:25 -0700359 dmi_memdev[nr].device = dmi_string(dm, d[0x10]);
360 dmi_memdev[nr].bank = dmi_string(dm, d[0x11]);
361 nr++;
362}
363
364void __init dmi_memdev_walk(void)
365{
366 if (!dmi_available)
367 return;
368
369 if (dmi_walk_early(count_mem_devices) == 0 && dmi_memdev_nr) {
370 dmi_memdev = dmi_alloc(sizeof(*dmi_memdev) * dmi_memdev_nr);
371 if (dmi_memdev)
372 dmi_walk_early(save_mem_devices);
373 }
374}
375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 * Process a DMI table entry. Right now all we care about are the BIOS
378 * and machine entries. For 2.5 we should pull the smbus controller info
379 * out of here.
380 */
Jean Delvaree7a19c562009-03-30 21:46:44 +0200381static void __init dmi_decode(const struct dmi_header *dm, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382{
Jean Delvare02d9c472013-09-11 14:24:08 -0700383 switch (dm->type) {
Andrey Paninebad6a42005-09-06 15:18:29 -0700384 case 0: /* BIOS Information */
Andrey Panin1249c512005-06-25 14:54:47 -0700385 dmi_save_ident(dm, DMI_BIOS_VENDOR, 4);
Andrey Panin1249c512005-06-25 14:54:47 -0700386 dmi_save_ident(dm, DMI_BIOS_VERSION, 5);
Andrey Panin1249c512005-06-25 14:54:47 -0700387 dmi_save_ident(dm, DMI_BIOS_DATE, 8);
388 break;
Andrey Paninebad6a42005-09-06 15:18:29 -0700389 case 1: /* System Information */
Andrey Panin1249c512005-06-25 14:54:47 -0700390 dmi_save_ident(dm, DMI_SYS_VENDOR, 4);
Andrey Panin1249c512005-06-25 14:54:47 -0700391 dmi_save_ident(dm, DMI_PRODUCT_NAME, 5);
Andrey Panin1249c512005-06-25 14:54:47 -0700392 dmi_save_ident(dm, DMI_PRODUCT_VERSION, 6);
Andrey Panin1249c512005-06-25 14:54:47 -0700393 dmi_save_ident(dm, DMI_PRODUCT_SERIAL, 7);
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200394 dmi_save_uuid(dm, DMI_PRODUCT_UUID, 8);
Andrey Panin1249c512005-06-25 14:54:47 -0700395 break;
Andrey Paninebad6a42005-09-06 15:18:29 -0700396 case 2: /* Base Board Information */
Andrey Panin1249c512005-06-25 14:54:47 -0700397 dmi_save_ident(dm, DMI_BOARD_VENDOR, 4);
Andrey Panin1249c512005-06-25 14:54:47 -0700398 dmi_save_ident(dm, DMI_BOARD_NAME, 5);
Andrey Panin1249c512005-06-25 14:54:47 -0700399 dmi_save_ident(dm, DMI_BOARD_VERSION, 6);
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200400 dmi_save_ident(dm, DMI_BOARD_SERIAL, 7);
401 dmi_save_ident(dm, DMI_BOARD_ASSET_TAG, 8);
402 break;
403 case 3: /* Chassis Information */
404 dmi_save_ident(dm, DMI_CHASSIS_VENDOR, 4);
405 dmi_save_type(dm, DMI_CHASSIS_TYPE, 5);
406 dmi_save_ident(dm, DMI_CHASSIS_VERSION, 6);
407 dmi_save_ident(dm, DMI_CHASSIS_SERIAL, 7);
408 dmi_save_ident(dm, DMI_CHASSIS_ASSET_TAG, 8);
Andrey Panin1249c512005-06-25 14:54:47 -0700409 break;
Andrey Paninebad6a42005-09-06 15:18:29 -0700410 case 10: /* Onboard Devices Information */
411 dmi_save_devices(dm);
412 break;
Shem Multinymous2e0c1f62006-09-29 01:59:37 -0700413 case 11: /* OEM Strings */
414 dmi_save_oem_strings_devices(dm);
415 break;
Andrey Paninebad6a42005-09-06 15:18:29 -0700416 case 38: /* IPMI Device Information */
417 dmi_save_ipmi_device(dm);
Wim Van Sebroeckb4bd7d52008-02-08 04:20:58 -0800418 break;
419 case 41: /* Onboard Devices Extended Information */
420 dmi_save_extended_devices(dm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 }
422}
423
Tejun Heoc90fe6b2013-04-30 15:27:14 -0700424static int __init print_filtered(char *buf, size_t len, const char *info)
Bjorn Helgaas8881cdc2010-10-27 15:32:59 -0700425{
Tejun Heoc90fe6b2013-04-30 15:27:14 -0700426 int c = 0;
Bjorn Helgaas8881cdc2010-10-27 15:32:59 -0700427 const char *p;
428
429 if (!info)
Tejun Heoc90fe6b2013-04-30 15:27:14 -0700430 return c;
Bjorn Helgaas8881cdc2010-10-27 15:32:59 -0700431
432 for (p = info; *p; p++)
433 if (isprint(*p))
Tejun Heoc90fe6b2013-04-30 15:27:14 -0700434 c += scnprintf(buf + c, len - c, "%c", *p);
Bjorn Helgaas8881cdc2010-10-27 15:32:59 -0700435 else
Tejun Heoc90fe6b2013-04-30 15:27:14 -0700436 c += scnprintf(buf + c, len - c, "\\x%02x", *p & 0xff);
437 return c;
Bjorn Helgaas8881cdc2010-10-27 15:32:59 -0700438}
439
Tejun Heoc90fe6b2013-04-30 15:27:14 -0700440static void __init dmi_format_ids(char *buf, size_t len)
Bjorn Helgaas8881cdc2010-10-27 15:32:59 -0700441{
Tejun Heoc90fe6b2013-04-30 15:27:14 -0700442 int c = 0;
Naga Chumbalkar84e383b2011-02-14 22:47:17 +0000443 const char *board; /* Board Name is optional */
444
Tejun Heoc90fe6b2013-04-30 15:27:14 -0700445 c += print_filtered(buf + c, len - c,
446 dmi_get_system_info(DMI_SYS_VENDOR));
447 c += scnprintf(buf + c, len - c, " ");
448 c += print_filtered(buf + c, len - c,
449 dmi_get_system_info(DMI_PRODUCT_NAME));
450
Naga Chumbalkar84e383b2011-02-14 22:47:17 +0000451 board = dmi_get_system_info(DMI_BOARD_NAME);
452 if (board) {
Tejun Heoc90fe6b2013-04-30 15:27:14 -0700453 c += scnprintf(buf + c, len - c, "/");
454 c += print_filtered(buf + c, len - c, board);
Naga Chumbalkar84e383b2011-02-14 22:47:17 +0000455 }
Tejun Heoc90fe6b2013-04-30 15:27:14 -0700456 c += scnprintf(buf + c, len - c, ", BIOS ");
457 c += print_filtered(buf + c, len - c,
458 dmi_get_system_info(DMI_BIOS_VERSION));
459 c += scnprintf(buf + c, len - c, " ");
460 c += print_filtered(buf + c, len - c,
461 dmi_get_system_info(DMI_BIOS_DATE));
Bjorn Helgaas8881cdc2010-10-27 15:32:59 -0700462}
463
Ben Hutchingsd39de282013-07-31 13:53:30 -0700464/*
465 * Check for DMI/SMBIOS headers in the system firmware image. Any
466 * SMBIOS header must start 16 bytes before the DMI header, so take a
467 * 32 byte buffer and check for DMI at offset 16 and SMBIOS at offset
468 * 0. If the DMI header is present, set dmi_ver accordingly (SMBIOS
469 * takes precedence) and return 0. Otherwise return 1.
470 */
Ben Hutchings79bae422013-04-30 15:27:46 -0700471static int __init dmi_present(const u8 *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472{
Ivan Khoronzhuk95be58d2015-02-18 13:33:20 +0200473 u32 smbios_ver;
Jeff Garzik18552562007-10-03 15:15:40 -0400474
Ben Hutchings79bae422013-04-30 15:27:46 -0700475 if (memcmp(buf, "_SM_", 4) == 0 &&
476 buf[5] < 32 && dmi_checksum(buf, buf[5])) {
Ard Biesheuvelfc430262014-10-14 16:41:27 +0200477 smbios_ver = get_unaligned_be16(buf + 6);
Ben Hutchings79bae422013-04-30 15:27:46 -0700478
479 /* Some BIOS report weird SMBIOS version, fix that up */
480 switch (smbios_ver) {
481 case 0x021F:
482 case 0x0221:
483 pr_debug("SMBIOS version fixup(2.%d->2.%d)\n",
484 smbios_ver & 0xFF, 3);
485 smbios_ver = 0x0203;
486 break;
487 case 0x0233:
488 pr_debug("SMBIOS version fixup(2.%d->2.%d)\n", 51, 6);
489 smbios_ver = 0x0206;
490 break;
491 }
492 } else {
493 smbios_ver = 0;
494 }
495
496 buf += 16;
497
498 if (memcmp(buf, "_DMI_", 5) == 0 && dmi_checksum(buf, 15)) {
Ard Biesheuvelfc430262014-10-14 16:41:27 +0200499 dmi_num = get_unaligned_le16(buf + 12);
500 dmi_len = get_unaligned_le16(buf + 6);
501 dmi_base = get_unaligned_le32(buf + 8);
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800502
Bjorn Helgaas8881cdc2010-10-27 15:32:59 -0700503 if (dmi_walk_early(dmi_decode) == 0) {
Ben Hutchings79bae422013-04-30 15:27:46 -0700504 if (smbios_ver) {
505 dmi_ver = smbios_ver;
Ivan Khoronzhuk95be58d2015-02-18 13:33:20 +0200506 pr_info("SMBIOS %d.%d%s present.\n",
507 dmi_ver >> 8, dmi_ver & 0xFF,
508 (dmi_ver < 0x0300) ? "" : ".x");
Ben Hutchings79bae422013-04-30 15:27:46 -0700509 } else {
Zhenzhong Duan9f9c9cbb2012-12-20 15:05:14 -0800510 dmi_ver = (buf[14] & 0xF0) << 4 |
511 (buf[14] & 0x0F);
512 pr_info("Legacy DMI %d.%d present.\n",
513 dmi_ver >> 8, dmi_ver & 0xFF);
514 }
Ivan Khoronzhuk95be58d2015-02-18 13:33:20 +0200515 dmi_ver <<= 8;
Tejun Heoc90fe6b2013-04-30 15:27:14 -0700516 dmi_format_ids(dmi_ids_string, sizeof(dmi_ids_string));
517 printk(KERN_DEBUG "DMI: %s\n", dmi_ids_string);
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800518 return 0;
Bjorn Helgaas8881cdc2010-10-27 15:32:59 -0700519 }
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800520 }
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800521
Ben Hutchingsa40e7cf2013-03-08 12:43:32 -0800522 return 1;
Zhenzhong Duan9f9c9cbb2012-12-20 15:05:14 -0800523}
524
Ard Biesheuvelfc430262014-10-14 16:41:27 +0200525/*
526 * Check for the SMBIOS 3.0 64-bit entry point signature. Unlike the legacy
527 * 32-bit entry point, there is no embedded DMI header (_DMI_) in here.
528 */
529static int __init dmi_smbios3_present(const u8 *buf)
530{
531 if (memcmp(buf, "_SM3_", 5) == 0 &&
532 buf[6] < 32 && dmi_checksum(buf, buf[6])) {
Ivan Khoronzhuk95be58d2015-02-18 13:33:20 +0200533 dmi_ver = get_unaligned_be32(buf + 6);
534 dmi_ver &= 0xFFFFFF;
Ard Biesheuvelfc430262014-10-14 16:41:27 +0200535 dmi_len = get_unaligned_le32(buf + 12);
536 dmi_base = get_unaligned_le64(buf + 16);
537
538 /*
539 * The 64-bit SMBIOS 3.0 entry point no longer has a field
540 * containing the number of structures present in the table.
541 * Instead, it defines the table size as a maximum size, and
542 * relies on the end-of-table structure type (#127) to be used
543 * to signal the end of the table.
544 * So let's define dmi_num as an upper bound as well: each
545 * structure has a 4 byte header, so dmi_len / 4 is an upper
546 * bound for the number of structures in the table.
547 */
548 dmi_num = dmi_len / 4;
549
550 if (dmi_walk_early(dmi_decode) == 0) {
Ivan Khoronzhuk95be58d2015-02-18 13:33:20 +0200551 pr_info("SMBIOS %d.%d.%d present.\n",
552 dmi_ver >> 16, (dmi_ver >> 8) & 0xFF,
553 dmi_ver & 0xFF);
Ard Biesheuvelfc430262014-10-14 16:41:27 +0200554 dmi_format_ids(dmi_ids_string, sizeof(dmi_ids_string));
555 pr_debug("DMI: %s\n", dmi_ids_string);
556 return 0;
557 }
558 }
559 return 1;
560}
561
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800562void __init dmi_scan_machine(void)
563{
Andrey Panin61e032fa2005-09-06 15:18:26 -0700564 char __iomem *p, *q;
Ben Hutchings79bae422013-04-30 15:27:46 -0700565 char buf[32];
Andrey Panin61e032fa2005-09-06 15:18:26 -0700566
Matt Fleming83e68182012-11-14 09:42:35 +0000567 if (efi_enabled(EFI_CONFIG_TABLES)) {
Ard Biesheuvelfc430262014-10-14 16:41:27 +0200568 /*
569 * According to the DMTF SMBIOS reference spec v3.0.0, it is
570 * allowed to define both the 64-bit entry point (smbios3) and
571 * the 32-bit entry point (smbios), in which case they should
572 * either both point to the same SMBIOS structure table, or the
573 * table pointed to by the 64-bit entry point should contain a
574 * superset of the table contents pointed to by the 32-bit entry
575 * point (section 5.2)
576 * This implies that the 64-bit entry point should have
577 * precedence if it is defined and supported by the OS. If we
578 * have the 64-bit entry point, but fail to decode it, fall
579 * back to the legacy one (if available)
580 */
581 if (efi.smbios3 != EFI_INVALID_TABLE_ADDR) {
582 p = dmi_early_remap(efi.smbios3, 32);
583 if (p == NULL)
584 goto error;
585 memcpy_fromio(buf, p, 32);
586 dmi_early_unmap(p, 32);
587
588 if (!dmi_smbios3_present(buf)) {
589 dmi_available = 1;
590 goto out;
591 }
592 }
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800593 if (efi.smbios == EFI_INVALID_TABLE_ADDR)
Ingo Molnar9a22b6e2008-09-18 12:50:18 +0200594 goto error;
Andrey Panin61e032fa2005-09-06 15:18:26 -0700595
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200596 /* This is called as a core_initcall() because it isn't
597 * needed during early boot. This also means we can
598 * iounmap the space when we're done with it.
599 */
Ard Biesheuvelcf074402014-01-23 15:54:39 -0800600 p = dmi_early_remap(efi.smbios, 32);
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800601 if (p == NULL)
Ingo Molnar9a22b6e2008-09-18 12:50:18 +0200602 goto error;
Ben Hutchings79bae422013-04-30 15:27:46 -0700603 memcpy_fromio(buf, p, 32);
Ard Biesheuvelcf074402014-01-23 15:54:39 -0800604 dmi_early_unmap(p, 32);
Ben Hutchings79bae422013-04-30 15:27:46 -0700605
606 if (!dmi_present(buf)) {
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200607 dmi_available = 1;
Ingo Molnar9a22b6e2008-09-18 12:50:18 +0200608 goto out;
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200609 }
Ard Biesheuvelcf074402014-01-23 15:54:39 -0800610 } else if (IS_ENABLED(CONFIG_DMI_SCAN_MACHINE_NON_EFI_FALLBACK)) {
611 p = dmi_early_remap(0xF0000, 0x10000);
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800612 if (p == NULL)
Ingo Molnar9a22b6e2008-09-18 12:50:18 +0200613 goto error;
Andrey Panin61e032fa2005-09-06 15:18:26 -0700614
Ben Hutchingsd39de282013-07-31 13:53:30 -0700615 /*
616 * Iterate over all possible DMI header addresses q.
617 * Maintain the 32 bytes around q in buf. On the
618 * first iteration, substitute zero for the
619 * out-of-range bytes so there is no chance of falsely
620 * detecting an SMBIOS header.
621 */
Ben Hutchings79bae422013-04-30 15:27:46 -0700622 memset(buf, 0, 16);
Matt Domsch3ed3bce2006-03-26 01:37:03 -0800623 for (q = p; q < p + 0x10000; q += 16) {
Ben Hutchings79bae422013-04-30 15:27:46 -0700624 memcpy_fromio(buf + 16, q, 16);
Ard Biesheuvelfc430262014-10-14 16:41:27 +0200625 if (!dmi_smbios3_present(buf) || !dmi_present(buf)) {
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200626 dmi_available = 1;
Ard Biesheuvelcf074402014-01-23 15:54:39 -0800627 dmi_early_unmap(p, 0x10000);
Ingo Molnar9a22b6e2008-09-18 12:50:18 +0200628 goto out;
Lennart Poettering4f5c7912007-05-08 22:07:02 +0200629 }
Ben Hutchings79bae422013-04-30 15:27:46 -0700630 memcpy(buf, buf + 16, 16);
Andrey Panin61e032fa2005-09-06 15:18:26 -0700631 }
Ard Biesheuvelcf074402014-01-23 15:54:39 -0800632 dmi_early_unmap(p, 0x10000);
Andrey Panin61e032fa2005-09-06 15:18:26 -0700633 }
Ingo Molnar9a22b6e2008-09-18 12:50:18 +0200634 error:
Jean Delvare02d9c472013-09-11 14:24:08 -0700635 pr_info("DMI not present or invalid.\n");
Ingo Molnar9a22b6e2008-09-18 12:50:18 +0200636 out:
637 dmi_initialized = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638}
639
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640/**
Tejun Heo98e5e1b2013-04-30 15:27:15 -0700641 * dmi_set_dump_stack_arch_desc - set arch description for dump_stack()
642 *
643 * Invoke dump_stack_set_arch_desc() with DMI system information so that
644 * DMI identifiers are printed out on task dumps. Arch boot code should
645 * call this function after dmi_scan_machine() if it wants to print out DMI
646 * identifiers on task dumps.
647 */
648void __init dmi_set_dump_stack_arch_desc(void)
649{
650 dump_stack_set_arch_desc("%s", dmi_ids_string);
651}
652
653/**
Rafael J. Wysockid7b19562009-01-19 20:55:50 +0100654 * dmi_matches - check if dmi_system_id structure matches system DMI data
655 * @dmi: pointer to the dmi_system_id structure to check
656 */
657static bool dmi_matches(const struct dmi_system_id *dmi)
658{
659 int i;
660
661 WARN(!dmi_initialized, KERN_ERR "dmi check: not initialized yet.\n");
662
663 for (i = 0; i < ARRAY_SIZE(dmi->matches); i++) {
664 int s = dmi->matches[i].slot;
665 if (s == DMI_NONE)
Dmitry Torokhov75757502009-12-04 10:24:19 -0800666 break;
Jani Nikula5017b282013-07-03 15:05:02 -0700667 if (dmi_ident[s]) {
668 if (!dmi->matches[i].exact_match &&
669 strstr(dmi_ident[s], dmi->matches[i].substr))
670 continue;
671 else if (dmi->matches[i].exact_match &&
672 !strcmp(dmi_ident[s], dmi->matches[i].substr))
673 continue;
674 }
675
Rafael J. Wysockid7b19562009-01-19 20:55:50 +0100676 /* No match */
677 return false;
678 }
679 return true;
680}
681
682/**
Dmitry Torokhov75757502009-12-04 10:24:19 -0800683 * dmi_is_end_of_table - check for end-of-table marker
684 * @dmi: pointer to the dmi_system_id structure to check
685 */
686static bool dmi_is_end_of_table(const struct dmi_system_id *dmi)
687{
688 return dmi->matches[0].slot == DMI_NONE;
689}
690
691/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 * dmi_check_system - check system DMI data
693 * @list: array of dmi_system_id structures to match against
Randy Dunlapb0ef3712006-06-25 05:49:18 -0700694 * All non-null elements of the list must match
695 * their slot's (field index's) data (i.e., each
696 * list string must be a substring of the specified
697 * DMI slot's string data) to be considered a
698 * successful match.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 *
700 * Walk the blacklist table running matching functions until someone
701 * returns non zero or we hit the end. Callback function is called for
Randy Dunlapb0ef3712006-06-25 05:49:18 -0700702 * each successful match. Returns the number of matches.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 */
Jeff Garzik18552562007-10-03 15:15:40 -0400704int dmi_check_system(const struct dmi_system_id *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705{
Rafael J. Wysockid7b19562009-01-19 20:55:50 +0100706 int count = 0;
707 const struct dmi_system_id *d;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
Dmitry Torokhov75757502009-12-04 10:24:19 -0800709 for (d = list; !dmi_is_end_of_table(d); d++)
Rafael J. Wysockid7b19562009-01-19 20:55:50 +0100710 if (dmi_matches(d)) {
711 count++;
712 if (d->callback && d->callback(d))
713 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
716 return count;
717}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718EXPORT_SYMBOL(dmi_check_system);
719
720/**
Rafael J. Wysockid7b19562009-01-19 20:55:50 +0100721 * dmi_first_match - find dmi_system_id structure matching system DMI data
722 * @list: array of dmi_system_id structures to match against
723 * All non-null elements of the list must match
724 * their slot's (field index's) data (i.e., each
725 * list string must be a substring of the specified
726 * DMI slot's string data) to be considered a
727 * successful match.
728 *
729 * Walk the blacklist table until the first match is found. Return the
730 * pointer to the matching entry or NULL if there's no match.
731 */
732const struct dmi_system_id *dmi_first_match(const struct dmi_system_id *list)
733{
734 const struct dmi_system_id *d;
735
Dmitry Torokhov75757502009-12-04 10:24:19 -0800736 for (d = list; !dmi_is_end_of_table(d); d++)
Rafael J. Wysockid7b19562009-01-19 20:55:50 +0100737 if (dmi_matches(d))
738 return d;
739
740 return NULL;
741}
742EXPORT_SYMBOL(dmi_first_match);
743
744/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 * dmi_get_system_info - return DMI data value
Randy Dunlapb0ef3712006-06-25 05:49:18 -0700746 * @field: data index (see enum dmi_field)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 *
748 * Returns one DMI data value, can be used to perform
749 * complex DMI data checks.
750 */
Jeff Garzik18552562007-10-03 15:15:40 -0400751const char *dmi_get_system_info(int field)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752{
753 return dmi_ident[field];
754}
Dmitry Torokhove70c9d52005-06-25 14:54:25 -0700755EXPORT_SYMBOL(dmi_get_system_info);
Andrey Paninebad6a42005-09-06 15:18:29 -0700756
Alok Katariafd8cd7e2008-11-03 15:50:38 -0800757/**
Randy Dunlapc2bacfc2009-01-06 14:41:40 -0800758 * dmi_name_in_serial - Check if string is in the DMI product serial information
759 * @str: string to check for
Alok Katariafd8cd7e2008-11-03 15:50:38 -0800760 */
761int dmi_name_in_serial(const char *str)
762{
763 int f = DMI_PRODUCT_SERIAL;
764 if (dmi_ident[f] && strstr(dmi_ident[f], str))
765 return 1;
766 return 0;
767}
Andi Kleena1bae672006-10-21 18:37:02 +0200768
769/**
Jean Delvare66e13e62011-11-15 14:36:09 -0800770 * dmi_name_in_vendors - Check if string is in the DMI system or board vendor name
Jean Delvare02d9c472013-09-11 14:24:08 -0700771 * @str: Case sensitive Name
Andi Kleena1bae672006-10-21 18:37:02 +0200772 */
Jeff Garzik18552562007-10-03 15:15:40 -0400773int dmi_name_in_vendors(const char *str)
Andi Kleena1bae672006-10-21 18:37:02 +0200774{
Jean Delvare66e13e62011-11-15 14:36:09 -0800775 static int fields[] = { DMI_SYS_VENDOR, DMI_BOARD_VENDOR, DMI_NONE };
Andi Kleena1bae672006-10-21 18:37:02 +0200776 int i;
777 for (i = 0; fields[i] != DMI_NONE; i++) {
778 int f = fields[i];
779 if (dmi_ident[f] && strstr(dmi_ident[f], str))
780 return 1;
781 }
782 return 0;
783}
784EXPORT_SYMBOL(dmi_name_in_vendors);
785
Andrey Paninebad6a42005-09-06 15:18:29 -0700786/**
787 * dmi_find_device - find onboard device by type/name
788 * @type: device type or %DMI_DEV_TYPE_ANY to match all device types
Randy Dunlapb0ef3712006-06-25 05:49:18 -0700789 * @name: device name string or %NULL to match all
Andrey Paninebad6a42005-09-06 15:18:29 -0700790 * @from: previous device found in search, or %NULL for new search.
791 *
792 * Iterates through the list of known onboard devices. If a device is
793 * found with a matching @vendor and @device, a pointer to its device
794 * structure is returned. Otherwise, %NULL is returned.
Randy Dunlapb0ef3712006-06-25 05:49:18 -0700795 * A new search is initiated by passing %NULL as the @from argument.
Andrey Paninebad6a42005-09-06 15:18:29 -0700796 * If @from is not %NULL, searches continue from next device.
797 */
Jean Delvare02d9c472013-09-11 14:24:08 -0700798const struct dmi_device *dmi_find_device(int type, const char *name,
Jeff Garzik18552562007-10-03 15:15:40 -0400799 const struct dmi_device *from)
Andrey Paninebad6a42005-09-06 15:18:29 -0700800{
Jeff Garzik18552562007-10-03 15:15:40 -0400801 const struct list_head *head = from ? &from->list : &dmi_devices;
802 struct list_head *d;
Andrey Paninebad6a42005-09-06 15:18:29 -0700803
Jean Delvare02d9c472013-09-11 14:24:08 -0700804 for (d = head->next; d != &dmi_devices; d = d->next) {
Jeff Garzik18552562007-10-03 15:15:40 -0400805 const struct dmi_device *dev =
806 list_entry(d, struct dmi_device, list);
Andrey Paninebad6a42005-09-06 15:18:29 -0700807
808 if (((type == DMI_DEV_TYPE_ANY) || (dev->type == type)) &&
809 ((name == NULL) || (strcmp(dev->name, name) == 0)))
810 return dev;
811 }
812
813 return NULL;
814}
815EXPORT_SYMBOL(dmi_find_device);
Andi Kleenf083a322006-03-25 16:30:19 +0100816
817/**
Tejun Heo3e5cd1f2009-08-16 21:02:36 +0900818 * dmi_get_date - parse a DMI date
819 * @field: data index (see enum dmi_field)
820 * @yearp: optional out parameter for the year
821 * @monthp: optional out parameter for the month
822 * @dayp: optional out parameter for the day
Andi Kleenf083a322006-03-25 16:30:19 +0100823 *
Tejun Heo3e5cd1f2009-08-16 21:02:36 +0900824 * The date field is assumed to be in the form resembling
825 * [mm[/dd]]/yy[yy] and the result is stored in the out
826 * parameters any or all of which can be omitted.
827 *
828 * If the field doesn't exist, all out parameters are set to zero
829 * and false is returned. Otherwise, true is returned with any
830 * invalid part of date set to zero.
831 *
832 * On return, year, month and day are guaranteed to be in the
833 * range of [0,9999], [0,12] and [0,31] respectively.
Andi Kleenf083a322006-03-25 16:30:19 +0100834 */
Tejun Heo3e5cd1f2009-08-16 21:02:36 +0900835bool dmi_get_date(int field, int *yearp, int *monthp, int *dayp)
Andi Kleenf083a322006-03-25 16:30:19 +0100836{
Tejun Heo3e5cd1f2009-08-16 21:02:36 +0900837 int year = 0, month = 0, day = 0;
838 bool exists;
839 const char *s, *y;
Tejun Heo02c24fa2009-08-16 21:01:22 +0900840 char *e;
Andi Kleenf083a322006-03-25 16:30:19 +0100841
Tejun Heo3e5cd1f2009-08-16 21:02:36 +0900842 s = dmi_get_system_info(field);
843 exists = s;
844 if (!exists)
845 goto out;
Andi Kleenf083a322006-03-25 16:30:19 +0100846
Tejun Heo3e5cd1f2009-08-16 21:02:36 +0900847 /*
848 * Determine year first. We assume the date string resembles
849 * mm/dd/yy[yy] but the original code extracted only the year
850 * from the end. Keep the behavior in the spirit of no
851 * surprises.
852 */
853 y = strrchr(s, '/');
854 if (!y)
855 goto out;
856
857 y++;
858 year = simple_strtoul(y, &e, 10);
859 if (y != e && year < 100) { /* 2-digit year */
Andi Kleenf083a322006-03-25 16:30:19 +0100860 year += 1900;
861 if (year < 1996) /* no dates < spec 1.0 */
862 year += 100;
863 }
Tejun Heo3e5cd1f2009-08-16 21:02:36 +0900864 if (year > 9999) /* year should fit in %04d */
865 year = 0;
Andi Kleenf083a322006-03-25 16:30:19 +0100866
Tejun Heo3e5cd1f2009-08-16 21:02:36 +0900867 /* parse the mm and dd */
868 month = simple_strtoul(s, &e, 10);
869 if (s == e || *e != '/' || !month || month > 12) {
870 month = 0;
871 goto out;
872 }
873
874 s = e + 1;
875 day = simple_strtoul(s, &e, 10);
876 if (s == y || s == e || *e != '/' || day > 31)
877 day = 0;
878out:
879 if (yearp)
880 *yearp = year;
881 if (monthp)
882 *monthp = month;
883 if (dayp)
884 *dayp = day;
885 return exists;
Andi Kleenf083a322006-03-25 16:30:19 +0100886}
Tejun Heo3e5cd1f2009-08-16 21:02:36 +0900887EXPORT_SYMBOL(dmi_get_date);
Jean Delvare7fce0842007-11-03 17:29:20 +0100888
889/**
890 * dmi_walk - Walk the DMI table and get called back for every record
891 * @decode: Callback function
Jean Delvaree7a19c562009-03-30 21:46:44 +0200892 * @private_data: Private data to be passed to the callback function
Jean Delvare7fce0842007-11-03 17:29:20 +0100893 *
894 * Returns -1 when the DMI table can't be reached, 0 on success.
895 */
Jean Delvaree7a19c562009-03-30 21:46:44 +0200896int dmi_walk(void (*decode)(const struct dmi_header *, void *),
897 void *private_data)
Jean Delvare7fce0842007-11-03 17:29:20 +0100898{
899 u8 *buf;
900
901 if (!dmi_available)
902 return -1;
903
Ard Biesheuvelcf074402014-01-23 15:54:39 -0800904 buf = dmi_remap(dmi_base, dmi_len);
Jean Delvare7fce0842007-11-03 17:29:20 +0100905 if (buf == NULL)
906 return -1;
907
Jean Delvaree7a19c562009-03-30 21:46:44 +0200908 dmi_table(buf, dmi_len, dmi_num, decode, private_data);
Jean Delvare7fce0842007-11-03 17:29:20 +0100909
Ard Biesheuvelcf074402014-01-23 15:54:39 -0800910 dmi_unmap(buf);
Jean Delvare7fce0842007-11-03 17:29:20 +0100911 return 0;
912}
913EXPORT_SYMBOL_GPL(dmi_walk);
Jiri Slabyd61c72e2008-12-10 14:07:21 +0100914
915/**
916 * dmi_match - compare a string to the dmi field (if exists)
Randy Dunlapc2bacfc2009-01-06 14:41:40 -0800917 * @f: DMI field identifier
918 * @str: string to compare the DMI field to
Jiri Slabyd61c72e2008-12-10 14:07:21 +0100919 *
920 * Returns true if the requested field equals to the str (including NULL).
921 */
922bool dmi_match(enum dmi_field f, const char *str)
923{
924 const char *info = dmi_get_system_info(f);
925
926 if (info == NULL || str == NULL)
927 return info == str;
928
929 return !strcmp(info, str);
930}
931EXPORT_SYMBOL_GPL(dmi_match);
Chen, Gongdd6dad42013-10-18 14:29:25 -0700932
933void dmi_memdev_name(u16 handle, const char **bank, const char **device)
934{
935 int n;
936
937 if (dmi_memdev == NULL)
938 return;
939
940 for (n = 0; n < dmi_memdev_nr; n++) {
941 if (handle == dmi_memdev[n].handle) {
942 *bank = dmi_memdev[n].bank;
943 *device = dmi_memdev[n].device;
944 break;
945 }
946 }
947}
948EXPORT_SYMBOL_GPL(dmi_memdev_name);