dmi_scan.c 18 KB

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