]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/firmware/dmi_scan.c
drivers/firmware/dmi_scan.c: fetch dmi version from SMBIOS if it exists
[karo-tx-linux.git] / drivers / firmware / dmi_scan.c
1 #include <linux/types.h>
2 #include <linux/string.h>
3 #include <linux/init.h>
4 #include <linux/module.h>
5 #include <linux/ctype.h>
6 #include <linux/dmi.h>
7 #include <linux/efi.h>
8 #include <linux/bootmem.h>
9 #include <linux/random.h>
10 #include <asm/dmi.h>
11
12 /*
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  */
17 static char dmi_empty_string[] = "        ";
18
19 static u16 __initdata dmi_ver;
20 /*
21  * Catch too early calls to dmi_check_system():
22  */
23 static int dmi_initialized;
24
25 static const char * __init dmi_string_nosave(const struct dmi_header *dm, u8 s)
26 {
27         const u8 *bp = ((u8 *) dm) + dm->length;
28
29         if (s) {
30                 s--;
31                 while (s > 0 && *bp) {
32                         bp += strlen(bp) + 1;
33                         s--;
34                 }
35
36                 if (*bp != 0) {
37                         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;
42                         return bp;
43                 }
44         }
45
46         return "";
47 }
48
49 static 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
65         return str;
66 }
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  */
72 static void dmi_table(u8 *buf, int len, int num,
73                       void (*decode)(const struct dmi_header *, void *),
74                       void *private_data)
75 {
76         u8 *data = buf;
77         int i = 0;
78
79         /*
80          *      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          */
83         while ((i < num) && (data - buf + sizeof(struct dmi_header)) <= len) {
84                 const struct dmi_header *dm = (const struct dmi_header *)data;
85
86                 /*
87                  *  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
90                  */
91                 data += dm->length;
92                 while ((data - buf < len - 1) && (data[0] || data[1]))
93                         data++;
94                 if (data - buf < len - 1)
95                         decode(dm, private_data);
96                 data += 2;
97                 i++;
98         }
99 }
100
101 static u32 dmi_base;
102 static u16 dmi_len;
103 static u16 dmi_num;
104
105 static int __init dmi_walk_early(void (*decode)(const struct dmi_header *,
106                 void *))
107 {
108         u8 *buf;
109
110         buf = dmi_ioremap(dmi_base, dmi_len);
111         if (buf == NULL)
112                 return -1;
113
114         dmi_table(buf, dmi_len, dmi_num, decode, NULL);
115
116         add_device_randomness(buf, dmi_len);
117
118         dmi_iounmap(buf, dmi_len);
119         return 0;
120 }
121
122 static int __init dmi_checksum(const u8 *buf, u8 len)
123 {
124         u8 sum = 0;
125         int a;
126
127         for (a = 0; a < len; a++)
128                 sum += buf[a];
129
130         return sum == 0;
131 }
132
133 static char *dmi_ident[DMI_STRING_MAX];
134 static LIST_HEAD(dmi_devices);
135 int dmi_available;
136
137 /*
138  *      Save a DMI string
139  */
140 static void __init dmi_save_ident(const struct dmi_header *dm, int slot, int string)
141 {
142         const char *d = (const char*) dm;
143         char *p;
144
145         if (dmi_ident[slot])
146                 return;
147
148         p = dmi_string(dm, d[string]);
149         if (p == NULL)
150                 return;
151
152         dmi_ident[slot] = p;
153 }
154
155 static void __init dmi_save_uuid(const struct dmi_header *dm, int slot, int index)
156 {
157         const u8 *d = (u8*) dm + index;
158         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++) {
165                 if (d[i] != 0x00)
166                         is_00 = 0;
167                 if (d[i] != 0xFF)
168                         is_ff = 0;
169         }
170
171         if (is_ff || is_00)
172                 return;
173
174         s = dmi_alloc(16*2+4+1);
175         if (!s)
176                 return;
177
178         /*
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);
187
188         dmi_ident[slot] = s;
189 }
190
191 static void __init dmi_save_type(const struct dmi_header *dm, int slot, int index)
192 {
193         const u8 *d = (u8*) dm + index;
194         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
207 static 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
228 static void __init dmi_save_devices(const struct dmi_header *dm)
229 {
230         int i, count = (dm->length - sizeof(struct dmi_header)) / 2;
231
232         for (i = 0; i < count; i++) {
233                 const char *d = (char *)(dm + 1) + (i * 2);
234
235                 /* Skip disabled device */
236                 if ((*d & 0x80) == 0)
237                         continue;
238
239                 dmi_save_one_device(*d & 0x7f, dmi_string_nosave(dm, *(d + 1)));
240         }
241 }
242
243 static void __init dmi_save_oem_strings_devices(const struct dmi_header *dm)
244 {
245         int i, count = *(u8 *)(dm + 1);
246         struct dmi_device *dev;
247
248         for (i = 1; i <= count; i++) {
249                 char *devname = dmi_string(dm, i);
250
251                 if (devname == dmi_empty_string)
252                         continue;
253
254                 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;
262                 dev->name = devname;
263                 dev->device_data = NULL;
264
265                 list_add(&dev->list, &dmi_devices);
266         }
267 }
268
269 static void __init dmi_save_ipmi_device(const struct dmi_header *dm)
270 {
271         struct dmi_device *dev;
272         void * data;
273
274         data = dmi_alloc(dm->length);
275         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
282         dev = dmi_alloc(sizeof(*dev));
283         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
292         list_add_tail(&dev->list, &dmi_devices);
293 }
294
295 static 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
318 static void __init dmi_save_extended_devices(const struct dmi_header *dm)
319 {
320         const u8 *d = (u8*) dm + 5;
321
322         /* Skip disabled device */
323         if ((*d & 0x80) == 0)
324                 return;
325
326         dmi_save_dev_onboard(*(d+1), *(u16 *)(d+2), *(d+4), *(d+5),
327                              dmi_string_nosave(dm, *(d-1)));
328         dmi_save_one_device(*d & 0x7f, dmi_string_nosave(dm, *(d - 1)));
329 }
330
331 /*
332  *      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  */
336 static void __init dmi_decode(const struct dmi_header *dm, void *dummy)
337 {
338         switch(dm->type) {
339         case 0:         /* BIOS Information */
340                 dmi_save_ident(dm, DMI_BIOS_VENDOR, 4);
341                 dmi_save_ident(dm, DMI_BIOS_VERSION, 5);
342                 dmi_save_ident(dm, DMI_BIOS_DATE, 8);
343                 break;
344         case 1:         /* System Information */
345                 dmi_save_ident(dm, DMI_SYS_VENDOR, 4);
346                 dmi_save_ident(dm, DMI_PRODUCT_NAME, 5);
347                 dmi_save_ident(dm, DMI_PRODUCT_VERSION, 6);
348                 dmi_save_ident(dm, DMI_PRODUCT_SERIAL, 7);
349                 dmi_save_uuid(dm, DMI_PRODUCT_UUID, 8);
350                 break;
351         case 2:         /* Base Board Information */
352                 dmi_save_ident(dm, DMI_BOARD_VENDOR, 4);
353                 dmi_save_ident(dm, DMI_BOARD_NAME, 5);
354                 dmi_save_ident(dm, DMI_BOARD_VERSION, 6);
355                 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);
364                 break;
365         case 10:        /* Onboard Devices Information */
366                 dmi_save_devices(dm);
367                 break;
368         case 11:        /* OEM Strings */
369                 dmi_save_oem_strings_devices(dm);
370                 break;
371         case 38:        /* IPMI Device Information */
372                 dmi_save_ipmi_device(dm);
373                 break;
374         case 41:        /* Onboard Devices Extended Information */
375                 dmi_save_extended_devices(dm);
376         }
377 }
378
379 static 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
393 static void __init dmi_dump_ids(void)
394 {
395         const char *board;      /* Board Name is optional */
396
397         printk(KERN_DEBUG "DMI: ");
398         print_filtered(dmi_get_system_info(DMI_SYS_VENDOR));
399         printk(KERN_CONT " ");
400         print_filtered(dmi_get_system_info(DMI_PRODUCT_NAME));
401         board = dmi_get_system_info(DMI_BOARD_NAME);
402         if (board) {
403                 printk(KERN_CONT "/");
404                 print_filtered(board);
405         }
406         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
413 static int __init dmi_present(const char __iomem *p)
414 {
415         u8 buf[15];
416
417         memcpy_fromio(buf, p, 15);
418         if (dmi_checksum(buf, 15)) {
419                 dmi_num = (buf[13] << 8) | buf[12];
420                 dmi_len = (buf[7] << 8) | buf[6];
421                 dmi_base = (buf[11] << 24) | (buf[10] << 16) |
422                         (buf[9] << 8) | buf[8];
423
424                 if (dmi_walk_early(dmi_decode) == 0) {
425                         if (dmi_ver)
426                                 printk(KERN_INFO "SMBIOS %d.%d present.\n",
427                                        dmi_ver >> 8, dmi_ver & 0xFF);
428                         else {
429                                 dmi_ver = (buf[14] & 0xF0) << 4 |
430                                            (buf[14] & 0x0F);
431                                 printk(KERN_INFO "Legacy DMI %d.%d present.\n",
432                                        dmi_ver >> 8, dmi_ver & 0xFF);
433                         }
434                         dmi_dump_ids();
435                         return 0;
436                 }
437         }
438         dmi_ver = 0;
439         return 1;
440 }
441
442 static int __init smbios_present(const char __iomem *p)
443 {
444         u8 buf[32];
445         int offset = 0;
446
447         memcpy_fromio(buf, p, 32);
448         if ((buf[5] < 32) && dmi_checksum(buf, buf[5])) {
449                 dmi_ver = (buf[6] << 8) + buf[7];
450
451                 /* Some BIOS report weird SMBIOS version, fix that up */
452                 switch (dmi_ver) {
453                 case 0x021F:
454                 case 0x0221:
455                         printk(KERN_DEBUG "SMBIOS version fixup(2.%d->2.%d)\n",
456                                dmi_ver & 0xFF, 3);
457                         dmi_ver = 0x0203;
458                         break;
459                 case 0x0233:
460                         printk(KERN_DEBUG "SMBIOS version fixup(2.%d->2.%d)\n",
461                                51, 6);
462                         dmi_ver = 0x0206;
463                         break;
464                 }
465                 offset = 16;
466         }
467         return dmi_present(buf + offset);
468 }
469
470 void __init dmi_scan_machine(void)
471 {
472         char __iomem *p, *q;
473         int rc;
474
475         if (efi_enabled) {
476                 if (efi.smbios == EFI_INVALID_TABLE_ADDR)
477                         goto error;
478
479                 /* This is called as a core_initcall() because it isn't
480                  * needed during early boot.  This also means we can
481                  * iounmap the space when we're done with it.
482                  */
483                 p = dmi_ioremap(efi.smbios, 32);
484                 if (p == NULL)
485                         goto error;
486
487                 rc = smbios_present(p);
488                 dmi_iounmap(p, 32);
489                 if (!rc) {
490                         dmi_available = 1;
491                         goto out;
492                 }
493         }
494         else {
495                 /*
496                  * no iounmap() for that ioremap(); it would be a no-op, but
497                  * it's so early in setup that sucker gets confused into doing
498                  * what it shouldn't if we actually call it.
499                  */
500                 p = dmi_ioremap(0xF0000, 0x10000);
501                 if (p == NULL)
502                         goto error;
503
504                 for (q = p; q < p + 0x10000; q += 16) {
505                         if (memcmp(q, "_SM_", 4) == 0 && q - p <= 0xFFE0)
506                                 rc = smbios_present(q);
507                         else if (memcmp(q, "_DMI_", 5) == 0)
508                                 rc = dmi_present(q);
509                         else
510                                 continue;
511                         if (!rc) {
512                                 dmi_available = 1;
513                                 dmi_iounmap(p, 0x10000);
514                                 goto out;
515                         }
516                 }
517                 dmi_iounmap(p, 0x10000);
518         }
519  error:
520         printk(KERN_INFO "DMI not present or invalid.\n");
521  out:
522         dmi_initialized = 1;
523 }
524
525 /**
526  *      dmi_matches - check if dmi_system_id structure matches system DMI data
527  *      @dmi: pointer to the dmi_system_id structure to check
528  */
529 static bool dmi_matches(const struct dmi_system_id *dmi)
530 {
531         int i;
532
533         WARN(!dmi_initialized, KERN_ERR "dmi check: not initialized yet.\n");
534
535         for (i = 0; i < ARRAY_SIZE(dmi->matches); i++) {
536                 int s = dmi->matches[i].slot;
537                 if (s == DMI_NONE)
538                         break;
539                 if (dmi_ident[s]
540                     && strstr(dmi_ident[s], dmi->matches[i].substr))
541                         continue;
542                 /* No match */
543                 return false;
544         }
545         return true;
546 }
547
548 /**
549  *      dmi_is_end_of_table - check for end-of-table marker
550  *      @dmi: pointer to the dmi_system_id structure to check
551  */
552 static bool dmi_is_end_of_table(const struct dmi_system_id *dmi)
553 {
554         return dmi->matches[0].slot == DMI_NONE;
555 }
556
557 /**
558  *      dmi_check_system - check system DMI data
559  *      @list: array of dmi_system_id structures to match against
560  *              All non-null elements of the list must match
561  *              their slot's (field index's) data (i.e., each
562  *              list string must be a substring of the specified
563  *              DMI slot's string data) to be considered a
564  *              successful match.
565  *
566  *      Walk the blacklist table running matching functions until someone
567  *      returns non zero or we hit the end. Callback function is called for
568  *      each successful match. Returns the number of matches.
569  */
570 int dmi_check_system(const struct dmi_system_id *list)
571 {
572         int count = 0;
573         const struct dmi_system_id *d;
574
575         for (d = list; !dmi_is_end_of_table(d); d++)
576                 if (dmi_matches(d)) {
577                         count++;
578                         if (d->callback && d->callback(d))
579                                 break;
580                 }
581
582         return count;
583 }
584 EXPORT_SYMBOL(dmi_check_system);
585
586 /**
587  *      dmi_first_match - find dmi_system_id structure matching system DMI data
588  *      @list: array of dmi_system_id structures to match against
589  *              All non-null elements of the list must match
590  *              their slot's (field index's) data (i.e., each
591  *              list string must be a substring of the specified
592  *              DMI slot's string data) to be considered a
593  *              successful match.
594  *
595  *      Walk the blacklist table until the first match is found.  Return the
596  *      pointer to the matching entry or NULL if there's no match.
597  */
598 const struct dmi_system_id *dmi_first_match(const struct dmi_system_id *list)
599 {
600         const struct dmi_system_id *d;
601
602         for (d = list; !dmi_is_end_of_table(d); d++)
603                 if (dmi_matches(d))
604                         return d;
605
606         return NULL;
607 }
608 EXPORT_SYMBOL(dmi_first_match);
609
610 /**
611  *      dmi_get_system_info - return DMI data value
612  *      @field: data index (see enum dmi_field)
613  *
614  *      Returns one DMI data value, can be used to perform
615  *      complex DMI data checks.
616  */
617 const char *dmi_get_system_info(int field)
618 {
619         return dmi_ident[field];
620 }
621 EXPORT_SYMBOL(dmi_get_system_info);
622
623 /**
624  * dmi_name_in_serial - Check if string is in the DMI product serial information
625  * @str: string to check for
626  */
627 int dmi_name_in_serial(const char *str)
628 {
629         int f = DMI_PRODUCT_SERIAL;
630         if (dmi_ident[f] && strstr(dmi_ident[f], str))
631                 return 1;
632         return 0;
633 }
634
635 /**
636  *      dmi_name_in_vendors - Check if string is in the DMI system or board vendor name
637  *      @str:   Case sensitive Name
638  */
639 int dmi_name_in_vendors(const char *str)
640 {
641         static int fields[] = { DMI_SYS_VENDOR, DMI_BOARD_VENDOR, DMI_NONE };
642         int i;
643         for (i = 0; fields[i] != DMI_NONE; i++) {
644                 int f = fields[i];
645                 if (dmi_ident[f] && strstr(dmi_ident[f], str))
646                         return 1;
647         }
648         return 0;
649 }
650 EXPORT_SYMBOL(dmi_name_in_vendors);
651
652 /**
653  *      dmi_find_device - find onboard device by type/name
654  *      @type: device type or %DMI_DEV_TYPE_ANY to match all device types
655  *      @name: device name string or %NULL to match all
656  *      @from: previous device found in search, or %NULL for new search.
657  *
658  *      Iterates through the list of known onboard devices. If a device is
659  *      found with a matching @vendor and @device, a pointer to its device
660  *      structure is returned.  Otherwise, %NULL is returned.
661  *      A new search is initiated by passing %NULL as the @from argument.
662  *      If @from is not %NULL, searches continue from next device.
663  */
664 const struct dmi_device * dmi_find_device(int type, const char *name,
665                                     const struct dmi_device *from)
666 {
667         const struct list_head *head = from ? &from->list : &dmi_devices;
668         struct list_head *d;
669
670         for(d = head->next; d != &dmi_devices; d = d->next) {
671                 const struct dmi_device *dev =
672                         list_entry(d, struct dmi_device, list);
673
674                 if (((type == DMI_DEV_TYPE_ANY) || (dev->type == type)) &&
675                     ((name == NULL) || (strcmp(dev->name, name) == 0)))
676                         return dev;
677         }
678
679         return NULL;
680 }
681 EXPORT_SYMBOL(dmi_find_device);
682
683 /**
684  *      dmi_get_date - parse a DMI date
685  *      @field: data index (see enum dmi_field)
686  *      @yearp: optional out parameter for the year
687  *      @monthp: optional out parameter for the month
688  *      @dayp: optional out parameter for the day
689  *
690  *      The date field is assumed to be in the form resembling
691  *      [mm[/dd]]/yy[yy] and the result is stored in the out
692  *      parameters any or all of which can be omitted.
693  *
694  *      If the field doesn't exist, all out parameters are set to zero
695  *      and false is returned.  Otherwise, true is returned with any
696  *      invalid part of date set to zero.
697  *
698  *      On return, year, month and day are guaranteed to be in the
699  *      range of [0,9999], [0,12] and [0,31] respectively.
700  */
701 bool dmi_get_date(int field, int *yearp, int *monthp, int *dayp)
702 {
703         int year = 0, month = 0, day = 0;
704         bool exists;
705         const char *s, *y;
706         char *e;
707
708         s = dmi_get_system_info(field);
709         exists = s;
710         if (!exists)
711                 goto out;
712
713         /*
714          * Determine year first.  We assume the date string resembles
715          * mm/dd/yy[yy] but the original code extracted only the year
716          * from the end.  Keep the behavior in the spirit of no
717          * surprises.
718          */
719         y = strrchr(s, '/');
720         if (!y)
721                 goto out;
722
723         y++;
724         year = simple_strtoul(y, &e, 10);
725         if (y != e && year < 100) {     /* 2-digit year */
726                 year += 1900;
727                 if (year < 1996)        /* no dates < spec 1.0 */
728                         year += 100;
729         }
730         if (year > 9999)                /* year should fit in %04d */
731                 year = 0;
732
733         /* parse the mm and dd */
734         month = simple_strtoul(s, &e, 10);
735         if (s == e || *e != '/' || !month || month > 12) {
736                 month = 0;
737                 goto out;
738         }
739
740         s = e + 1;
741         day = simple_strtoul(s, &e, 10);
742         if (s == y || s == e || *e != '/' || day > 31)
743                 day = 0;
744 out:
745         if (yearp)
746                 *yearp = year;
747         if (monthp)
748                 *monthp = month;
749         if (dayp)
750                 *dayp = day;
751         return exists;
752 }
753 EXPORT_SYMBOL(dmi_get_date);
754
755 /**
756  *      dmi_walk - Walk the DMI table and get called back for every record
757  *      @decode: Callback function
758  *      @private_data: Private data to be passed to the callback function
759  *
760  *      Returns -1 when the DMI table can't be reached, 0 on success.
761  */
762 int dmi_walk(void (*decode)(const struct dmi_header *, void *),
763              void *private_data)
764 {
765         u8 *buf;
766
767         if (!dmi_available)
768                 return -1;
769
770         buf = ioremap(dmi_base, dmi_len);
771         if (buf == NULL)
772                 return -1;
773
774         dmi_table(buf, dmi_len, dmi_num, decode, private_data);
775
776         iounmap(buf);
777         return 0;
778 }
779 EXPORT_SYMBOL_GPL(dmi_walk);
780
781 /**
782  * dmi_match - compare a string to the dmi field (if exists)
783  * @f: DMI field identifier
784  * @str: string to compare the DMI field to
785  *
786  * Returns true if the requested field equals to the str (including NULL).
787  */
788 bool dmi_match(enum dmi_field f, const char *str)
789 {
790         const char *info = dmi_get_system_info(f);
791
792         if (info == NULL || str == NULL)
793                 return info == str;
794
795         return !strcmp(info, str);
796 }
797 EXPORT_SYMBOL_GPL(dmi_match);