dmi_scan.c 17 KB

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