dmi_scan.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  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 <asm/dmi.h>
  10. /*
  11. * DMI stands for "Desktop Management Interface". It is part
  12. * of and an antecedent to, SMBIOS, which stands for System
  13. * Management BIOS. See further: http://www.dmtf.org/standards
  14. */
  15. static char dmi_empty_string[] = " ";
  16. /*
  17. * Catch too early calls to dmi_check_system():
  18. */
  19. static int dmi_initialized;
  20. static const char * __init dmi_string_nosave(const struct dmi_header *dm, u8 s)
  21. {
  22. const u8 *bp = ((u8 *) dm) + dm->length;
  23. if (s) {
  24. s--;
  25. while (s > 0 && *bp) {
  26. bp += strlen(bp) + 1;
  27. s--;
  28. }
  29. if (*bp != 0) {
  30. size_t len = strlen(bp)+1;
  31. size_t cmp_len = len > 8 ? 8 : len;
  32. if (!memcmp(bp, dmi_empty_string, cmp_len))
  33. return dmi_empty_string;
  34. return bp;
  35. }
  36. }
  37. return "";
  38. }
  39. static char * __init dmi_string(const struct dmi_header *dm, u8 s)
  40. {
  41. const char *bp = dmi_string_nosave(dm, s);
  42. char *str;
  43. size_t len;
  44. if (bp == dmi_empty_string)
  45. return dmi_empty_string;
  46. len = strlen(bp) + 1;
  47. str = dmi_alloc(len);
  48. if (str != NULL)
  49. strcpy(str, bp);
  50. else
  51. printk(KERN_ERR "dmi_string: cannot allocate %Zu bytes.\n", len);
  52. return str;
  53. }
  54. /*
  55. * We have to be cautious here. We have seen BIOSes with DMI pointers
  56. * pointing to completely the wrong place for example
  57. */
  58. static void dmi_table(u8 *buf, int len, int num,
  59. void (*decode)(const struct dmi_header *, void *),
  60. void *private_data)
  61. {
  62. u8 *data = buf;
  63. int i = 0;
  64. /*
  65. * Stop when we see all the items the table claimed to have
  66. * OR we run off the end of the table (also happens)
  67. */
  68. while ((i < num) && (data - buf + sizeof(struct dmi_header)) <= len) {
  69. const struct dmi_header *dm = (const struct dmi_header *)data;
  70. /*
  71. * We want to know the total length (formatted area and
  72. * strings) before decoding to make sure we won't run off the
  73. * table in dmi_decode or dmi_string
  74. */
  75. data += dm->length;
  76. while ((data - buf < len - 1) && (data[0] || data[1]))
  77. data++;
  78. if (data - buf < len - 1)
  79. decode(dm, private_data);
  80. data += 2;
  81. i++;
  82. }
  83. }
  84. static u32 dmi_base;
  85. static u16 dmi_len;
  86. static u16 dmi_num;
  87. static int __init dmi_walk_early(void (*decode)(const struct dmi_header *,
  88. void *))
  89. {
  90. u8 *buf;
  91. buf = dmi_ioremap(dmi_base, dmi_len);
  92. if (buf == NULL)
  93. return -1;
  94. dmi_table(buf, dmi_len, dmi_num, decode, NULL);
  95. dmi_iounmap(buf, dmi_len);
  96. return 0;
  97. }
  98. static int __init dmi_checksum(const u8 *buf)
  99. {
  100. u8 sum = 0;
  101. int a;
  102. for (a = 0; a < 15; a++)
  103. sum += buf[a];
  104. return sum == 0;
  105. }
  106. static char *dmi_ident[DMI_STRING_MAX];
  107. static LIST_HEAD(dmi_devices);
  108. int dmi_available;
  109. /*
  110. * Save a DMI string
  111. */
  112. static void __init dmi_save_ident(const struct dmi_header *dm, int slot, int string)
  113. {
  114. const char *d = (const char*) dm;
  115. char *p;
  116. if (dmi_ident[slot])
  117. return;
  118. p = dmi_string(dm, d[string]);
  119. if (p == NULL)
  120. return;
  121. dmi_ident[slot] = p;
  122. }
  123. static void __init dmi_save_uuid(const struct dmi_header *dm, int slot, int index)
  124. {
  125. const u8 *d = (u8*) dm + index;
  126. char *s;
  127. int is_ff = 1, is_00 = 1, i;
  128. if (dmi_ident[slot])
  129. return;
  130. for (i = 0; i < 16 && (is_ff || is_00); i++) {
  131. if(d[i] != 0x00) is_ff = 0;
  132. if(d[i] != 0xFF) is_00 = 0;
  133. }
  134. if (is_ff || is_00)
  135. return;
  136. s = dmi_alloc(16*2+4+1);
  137. if (!s)
  138. return;
  139. sprintf(s, "%pUB", d);
  140. dmi_ident[slot] = s;
  141. }
  142. static void __init dmi_save_type(const struct dmi_header *dm, int slot, int index)
  143. {
  144. const u8 *d = (u8*) dm + index;
  145. char *s;
  146. if (dmi_ident[slot])
  147. return;
  148. s = dmi_alloc(4);
  149. if (!s)
  150. return;
  151. sprintf(s, "%u", *d & 0x7F);
  152. dmi_ident[slot] = s;
  153. }
  154. static void __init dmi_save_one_device(int type, const char *name)
  155. {
  156. struct dmi_device *dev;
  157. /* No duplicate device */
  158. if (dmi_find_device(type, name, NULL))
  159. return;
  160. dev = dmi_alloc(sizeof(*dev) + strlen(name) + 1);
  161. if (!dev) {
  162. printk(KERN_ERR "dmi_save_one_device: out of memory.\n");
  163. return;
  164. }
  165. dev->type = type;
  166. strcpy((char *)(dev + 1), name);
  167. dev->name = (char *)(dev + 1);
  168. dev->device_data = NULL;
  169. list_add(&dev->list, &dmi_devices);
  170. }
  171. static void __init dmi_save_devices(const struct dmi_header *dm)
  172. {
  173. int i, count = (dm->length - sizeof(struct dmi_header)) / 2;
  174. for (i = 0; i < count; i++) {
  175. const char *d = (char *)(dm + 1) + (i * 2);
  176. /* Skip disabled device */
  177. if ((*d & 0x80) == 0)
  178. continue;
  179. dmi_save_one_device(*d & 0x7f, dmi_string_nosave(dm, *(d + 1)));
  180. }
  181. }
  182. static void __init dmi_save_oem_strings_devices(const struct dmi_header *dm)
  183. {
  184. int i, count = *(u8 *)(dm + 1);
  185. struct dmi_device *dev;
  186. for (i = 1; i <= count; i++) {
  187. char *devname = dmi_string(dm, i);
  188. if (devname == dmi_empty_string)
  189. continue;
  190. dev = dmi_alloc(sizeof(*dev));
  191. if (!dev) {
  192. printk(KERN_ERR
  193. "dmi_save_oem_strings_devices: out of memory.\n");
  194. break;
  195. }
  196. dev->type = DMI_DEV_TYPE_OEM_STRING;
  197. dev->name = devname;
  198. dev->device_data = NULL;
  199. list_add(&dev->list, &dmi_devices);
  200. }
  201. }
  202. static void __init dmi_save_ipmi_device(const struct dmi_header *dm)
  203. {
  204. struct dmi_device *dev;
  205. void * data;
  206. data = dmi_alloc(dm->length);
  207. if (data == NULL) {
  208. printk(KERN_ERR "dmi_save_ipmi_device: out of memory.\n");
  209. return;
  210. }
  211. memcpy(data, dm, dm->length);
  212. dev = dmi_alloc(sizeof(*dev));
  213. if (!dev) {
  214. printk(KERN_ERR "dmi_save_ipmi_device: out of memory.\n");
  215. return;
  216. }
  217. dev->type = DMI_DEV_TYPE_IPMI;
  218. dev->name = "IPMI controller";
  219. dev->device_data = data;
  220. list_add_tail(&dev->list, &dmi_devices);
  221. }
  222. static void __init dmi_save_dev_onboard(int instance, int segment, int bus,
  223. int devfn, const char *name)
  224. {
  225. struct dmi_dev_onboard *onboard_dev;
  226. onboard_dev = dmi_alloc(sizeof(*onboard_dev) + strlen(name) + 1);
  227. if (!onboard_dev) {
  228. printk(KERN_ERR "dmi_save_dev_onboard: out of memory.\n");
  229. return;
  230. }
  231. onboard_dev->instance = instance;
  232. onboard_dev->segment = segment;
  233. onboard_dev->bus = bus;
  234. onboard_dev->devfn = devfn;
  235. strcpy((char *)&onboard_dev[1], name);
  236. onboard_dev->dev.type = DMI_DEV_TYPE_DEV_ONBOARD;
  237. onboard_dev->dev.name = (char *)&onboard_dev[1];
  238. onboard_dev->dev.device_data = onboard_dev;
  239. list_add(&onboard_dev->dev.list, &dmi_devices);
  240. }
  241. static void __init dmi_save_extended_devices(const struct dmi_header *dm)
  242. {
  243. const u8 *d = (u8*) dm + 5;
  244. /* Skip disabled device */
  245. if ((*d & 0x80) == 0)
  246. return;
  247. dmi_save_dev_onboard(*(d+1), *(u16 *)(d+2), *(d+4), *(d+5),
  248. dmi_string_nosave(dm, *(d-1)));
  249. dmi_save_one_device(*d & 0x7f, dmi_string_nosave(dm, *(d - 1)));
  250. }
  251. /*
  252. * Process a DMI table entry. Right now all we care about are the BIOS
  253. * and machine entries. For 2.5 we should pull the smbus controller info
  254. * out of here.
  255. */
  256. static void __init dmi_decode(const struct dmi_header *dm, void *dummy)
  257. {
  258. switch(dm->type) {
  259. case 0: /* BIOS Information */
  260. dmi_save_ident(dm, DMI_BIOS_VENDOR, 4);
  261. dmi_save_ident(dm, DMI_BIOS_VERSION, 5);
  262. dmi_save_ident(dm, DMI_BIOS_DATE, 8);
  263. break;
  264. case 1: /* System Information */
  265. dmi_save_ident(dm, DMI_SYS_VENDOR, 4);
  266. dmi_save_ident(dm, DMI_PRODUCT_NAME, 5);
  267. dmi_save_ident(dm, DMI_PRODUCT_VERSION, 6);
  268. dmi_save_ident(dm, DMI_PRODUCT_SERIAL, 7);
  269. dmi_save_uuid(dm, DMI_PRODUCT_UUID, 8);
  270. break;
  271. case 2: /* Base Board Information */
  272. dmi_save_ident(dm, DMI_BOARD_VENDOR, 4);
  273. dmi_save_ident(dm, DMI_BOARD_NAME, 5);
  274. dmi_save_ident(dm, DMI_BOARD_VERSION, 6);
  275. dmi_save_ident(dm, DMI_BOARD_SERIAL, 7);
  276. dmi_save_ident(dm, DMI_BOARD_ASSET_TAG, 8);
  277. break;
  278. case 3: /* Chassis Information */
  279. dmi_save_ident(dm, DMI_CHASSIS_VENDOR, 4);
  280. dmi_save_type(dm, DMI_CHASSIS_TYPE, 5);
  281. dmi_save_ident(dm, DMI_CHASSIS_VERSION, 6);
  282. dmi_save_ident(dm, DMI_CHASSIS_SERIAL, 7);
  283. dmi_save_ident(dm, DMI_CHASSIS_ASSET_TAG, 8);
  284. break;
  285. case 10: /* Onboard Devices Information */
  286. dmi_save_devices(dm);
  287. break;
  288. case 11: /* OEM Strings */
  289. dmi_save_oem_strings_devices(dm);
  290. break;
  291. case 38: /* IPMI Device Information */
  292. dmi_save_ipmi_device(dm);
  293. break;
  294. case 41: /* Onboard Devices Extended Information */
  295. dmi_save_extended_devices(dm);
  296. }
  297. }
  298. static void __init print_filtered(const char *info)
  299. {
  300. const char *p;
  301. if (!info)
  302. return;
  303. for (p = info; *p; p++)
  304. if (isprint(*p))
  305. printk(KERN_CONT "%c", *p);
  306. else
  307. printk(KERN_CONT "\\x%02x", *p & 0xff);
  308. }
  309. static void __init dmi_dump_ids(void)
  310. {
  311. printk(KERN_DEBUG "DMI: ");
  312. print_filtered(dmi_get_system_info(DMI_BOARD_NAME));
  313. printk(KERN_CONT "/");
  314. print_filtered(dmi_get_system_info(DMI_PRODUCT_NAME));
  315. printk(KERN_CONT ", BIOS ");
  316. print_filtered(dmi_get_system_info(DMI_BIOS_VERSION));
  317. printk(KERN_CONT " ");
  318. print_filtered(dmi_get_system_info(DMI_BIOS_DATE));
  319. printk(KERN_CONT "\n");
  320. }
  321. static int __init dmi_present(const char __iomem *p)
  322. {
  323. u8 buf[15];
  324. memcpy_fromio(buf, p, 15);
  325. if ((memcmp(buf, "_DMI_", 5) == 0) && dmi_checksum(buf)) {
  326. dmi_num = (buf[13] << 8) | buf[12];
  327. dmi_len = (buf[7] << 8) | buf[6];
  328. dmi_base = (buf[11] << 24) | (buf[10] << 16) |
  329. (buf[9] << 8) | buf[8];
  330. /*
  331. * DMI version 0.0 means that the real version is taken from
  332. * the SMBIOS version, which we don't know at this point.
  333. */
  334. if (buf[14] != 0)
  335. printk(KERN_INFO "DMI %d.%d present.\n",
  336. buf[14] >> 4, buf[14] & 0xF);
  337. else
  338. printk(KERN_INFO "DMI present.\n");
  339. if (dmi_walk_early(dmi_decode) == 0) {
  340. dmi_dump_ids();
  341. return 0;
  342. }
  343. }
  344. return 1;
  345. }
  346. void __init dmi_scan_machine(void)
  347. {
  348. char __iomem *p, *q;
  349. int rc;
  350. if (efi_enabled) {
  351. if (efi.smbios == EFI_INVALID_TABLE_ADDR)
  352. goto error;
  353. /* This is called as a core_initcall() because it isn't
  354. * needed during early boot. This also means we can
  355. * iounmap the space when we're done with it.
  356. */
  357. p = dmi_ioremap(efi.smbios, 32);
  358. if (p == NULL)
  359. goto error;
  360. rc = dmi_present(p + 0x10); /* offset of _DMI_ string */
  361. dmi_iounmap(p, 32);
  362. if (!rc) {
  363. dmi_available = 1;
  364. goto out;
  365. }
  366. }
  367. else {
  368. /*
  369. * no iounmap() for that ioremap(); it would be a no-op, but
  370. * it's so early in setup that sucker gets confused into doing
  371. * what it shouldn't if we actually call it.
  372. */
  373. p = dmi_ioremap(0xF0000, 0x10000);
  374. if (p == NULL)
  375. goto error;
  376. for (q = p; q < p + 0x10000; q += 16) {
  377. rc = dmi_present(q);
  378. if (!rc) {
  379. dmi_available = 1;
  380. dmi_iounmap(p, 0x10000);
  381. goto out;
  382. }
  383. }
  384. dmi_iounmap(p, 0x10000);
  385. }
  386. error:
  387. printk(KERN_INFO "DMI not present or invalid.\n");
  388. out:
  389. dmi_initialized = 1;
  390. }
  391. /**
  392. * dmi_matches - check if dmi_system_id structure matches system DMI data
  393. * @dmi: pointer to the dmi_system_id structure to check
  394. */
  395. static bool dmi_matches(const struct dmi_system_id *dmi)
  396. {
  397. int i;
  398. WARN(!dmi_initialized, KERN_ERR "dmi check: not initialized yet.\n");
  399. for (i = 0; i < ARRAY_SIZE(dmi->matches); i++) {
  400. int s = dmi->matches[i].slot;
  401. if (s == DMI_NONE)
  402. break;
  403. if (dmi_ident[s]
  404. && strstr(dmi_ident[s], dmi->matches[i].substr))
  405. continue;
  406. /* No match */
  407. return false;
  408. }
  409. return true;
  410. }
  411. /**
  412. * dmi_is_end_of_table - check for end-of-table marker
  413. * @dmi: pointer to the dmi_system_id structure to check
  414. */
  415. static bool dmi_is_end_of_table(const struct dmi_system_id *dmi)
  416. {
  417. return dmi->matches[0].slot == DMI_NONE;
  418. }
  419. /**
  420. * dmi_check_system - check system DMI data
  421. * @list: array of dmi_system_id structures to match against
  422. * All non-null elements of the list must match
  423. * their slot's (field index's) data (i.e., each
  424. * list string must be a substring of the specified
  425. * DMI slot's string data) to be considered a
  426. * successful match.
  427. *
  428. * Walk the blacklist table running matching functions until someone
  429. * returns non zero or we hit the end. Callback function is called for
  430. * each successful match. Returns the number of matches.
  431. */
  432. int dmi_check_system(const struct dmi_system_id *list)
  433. {
  434. int count = 0;
  435. const struct dmi_system_id *d;
  436. for (d = list; !dmi_is_end_of_table(d); d++)
  437. if (dmi_matches(d)) {
  438. count++;
  439. if (d->callback && d->callback(d))
  440. break;
  441. }
  442. return count;
  443. }
  444. EXPORT_SYMBOL(dmi_check_system);
  445. /**
  446. * dmi_first_match - find dmi_system_id structure matching system DMI data
  447. * @list: array of dmi_system_id structures to match against
  448. * All non-null elements of the list must match
  449. * their slot's (field index's) data (i.e., each
  450. * list string must be a substring of the specified
  451. * DMI slot's string data) to be considered a
  452. * successful match.
  453. *
  454. * Walk the blacklist table until the first match is found. Return the
  455. * pointer to the matching entry or NULL if there's no match.
  456. */
  457. const struct dmi_system_id *dmi_first_match(const struct dmi_system_id *list)
  458. {
  459. const struct dmi_system_id *d;
  460. for (d = list; !dmi_is_end_of_table(d); d++)
  461. if (dmi_matches(d))
  462. return d;
  463. return NULL;
  464. }
  465. EXPORT_SYMBOL(dmi_first_match);
  466. /**
  467. * dmi_get_system_info - return DMI data value
  468. * @field: data index (see enum dmi_field)
  469. *
  470. * Returns one DMI data value, can be used to perform
  471. * complex DMI data checks.
  472. */
  473. const char *dmi_get_system_info(int field)
  474. {
  475. return dmi_ident[field];
  476. }
  477. EXPORT_SYMBOL(dmi_get_system_info);
  478. /**
  479. * dmi_name_in_serial - Check if string is in the DMI product serial information
  480. * @str: string to check for
  481. */
  482. int dmi_name_in_serial(const char *str)
  483. {
  484. int f = DMI_PRODUCT_SERIAL;
  485. if (dmi_ident[f] && strstr(dmi_ident[f], str))
  486. return 1;
  487. return 0;
  488. }
  489. /**
  490. * dmi_name_in_vendors - Check if string is anywhere in the DMI vendor information.
  491. * @str: Case sensitive Name
  492. */
  493. int dmi_name_in_vendors(const char *str)
  494. {
  495. static int fields[] = { DMI_BIOS_VENDOR, DMI_BIOS_VERSION, DMI_SYS_VENDOR,
  496. DMI_PRODUCT_NAME, DMI_PRODUCT_VERSION, DMI_BOARD_VENDOR,
  497. DMI_BOARD_NAME, DMI_BOARD_VERSION, DMI_NONE };
  498. int i;
  499. for (i = 0; fields[i] != DMI_NONE; i++) {
  500. int f = fields[i];
  501. if (dmi_ident[f] && strstr(dmi_ident[f], str))
  502. return 1;
  503. }
  504. return 0;
  505. }
  506. EXPORT_SYMBOL(dmi_name_in_vendors);
  507. /**
  508. * dmi_find_device - find onboard device by type/name
  509. * @type: device type or %DMI_DEV_TYPE_ANY to match all device types
  510. * @name: device name string or %NULL to match all
  511. * @from: previous device found in search, or %NULL for new search.
  512. *
  513. * Iterates through the list of known onboard devices. If a device is
  514. * found with a matching @vendor and @device, a pointer to its device
  515. * structure is returned. Otherwise, %NULL is returned.
  516. * A new search is initiated by passing %NULL as the @from argument.
  517. * If @from is not %NULL, searches continue from next device.
  518. */
  519. const struct dmi_device * dmi_find_device(int type, const char *name,
  520. const struct dmi_device *from)
  521. {
  522. const struct list_head *head = from ? &from->list : &dmi_devices;
  523. struct list_head *d;
  524. for(d = head->next; d != &dmi_devices; d = d->next) {
  525. const struct dmi_device *dev =
  526. list_entry(d, struct dmi_device, list);
  527. if (((type == DMI_DEV_TYPE_ANY) || (dev->type == type)) &&
  528. ((name == NULL) || (strcmp(dev->name, name) == 0)))
  529. return dev;
  530. }
  531. return NULL;
  532. }
  533. EXPORT_SYMBOL(dmi_find_device);
  534. /**
  535. * dmi_get_date - parse a DMI date
  536. * @field: data index (see enum dmi_field)
  537. * @yearp: optional out parameter for the year
  538. * @monthp: optional out parameter for the month
  539. * @dayp: optional out parameter for the day
  540. *
  541. * The date field is assumed to be in the form resembling
  542. * [mm[/dd]]/yy[yy] and the result is stored in the out
  543. * parameters any or all of which can be omitted.
  544. *
  545. * If the field doesn't exist, all out parameters are set to zero
  546. * and false is returned. Otherwise, true is returned with any
  547. * invalid part of date set to zero.
  548. *
  549. * On return, year, month and day are guaranteed to be in the
  550. * range of [0,9999], [0,12] and [0,31] respectively.
  551. */
  552. bool dmi_get_date(int field, int *yearp, int *monthp, int *dayp)
  553. {
  554. int year = 0, month = 0, day = 0;
  555. bool exists;
  556. const char *s, *y;
  557. char *e;
  558. s = dmi_get_system_info(field);
  559. exists = s;
  560. if (!exists)
  561. goto out;
  562. /*
  563. * Determine year first. We assume the date string resembles
  564. * mm/dd/yy[yy] but the original code extracted only the year
  565. * from the end. Keep the behavior in the spirit of no
  566. * surprises.
  567. */
  568. y = strrchr(s, '/');
  569. if (!y)
  570. goto out;
  571. y++;
  572. year = simple_strtoul(y, &e, 10);
  573. if (y != e && year < 100) { /* 2-digit year */
  574. year += 1900;
  575. if (year < 1996) /* no dates < spec 1.0 */
  576. year += 100;
  577. }
  578. if (year > 9999) /* year should fit in %04d */
  579. year = 0;
  580. /* parse the mm and dd */
  581. month = simple_strtoul(s, &e, 10);
  582. if (s == e || *e != '/' || !month || month > 12) {
  583. month = 0;
  584. goto out;
  585. }
  586. s = e + 1;
  587. day = simple_strtoul(s, &e, 10);
  588. if (s == y || s == e || *e != '/' || day > 31)
  589. day = 0;
  590. out:
  591. if (yearp)
  592. *yearp = year;
  593. if (monthp)
  594. *monthp = month;
  595. if (dayp)
  596. *dayp = day;
  597. return exists;
  598. }
  599. EXPORT_SYMBOL(dmi_get_date);
  600. /**
  601. * dmi_walk - Walk the DMI table and get called back for every record
  602. * @decode: Callback function
  603. * @private_data: Private data to be passed to the callback function
  604. *
  605. * Returns -1 when the DMI table can't be reached, 0 on success.
  606. */
  607. int dmi_walk(void (*decode)(const struct dmi_header *, void *),
  608. void *private_data)
  609. {
  610. u8 *buf;
  611. if (!dmi_available)
  612. return -1;
  613. buf = ioremap(dmi_base, dmi_len);
  614. if (buf == NULL)
  615. return -1;
  616. dmi_table(buf, dmi_len, dmi_num, decode, private_data);
  617. iounmap(buf);
  618. return 0;
  619. }
  620. EXPORT_SYMBOL_GPL(dmi_walk);
  621. /**
  622. * dmi_match - compare a string to the dmi field (if exists)
  623. * @f: DMI field identifier
  624. * @str: string to compare the DMI field to
  625. *
  626. * Returns true if the requested field equals to the str (including NULL).
  627. */
  628. bool dmi_match(enum dmi_field f, const char *str)
  629. {
  630. const char *info = dmi_get_system_info(f);
  631. if (info == NULL || str == NULL)
  632. return info == str;
  633. return !strcmp(info, str);
  634. }
  635. EXPORT_SYMBOL_GPL(dmi_match);