dell-smbios-base.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /*
  2. * Common functions for kernel modules using Dell SMBIOS
  3. *
  4. * Copyright (c) Red Hat <mjg@redhat.com>
  5. * Copyright (c) 2014 Gabriele Mazzotta <gabriele.mzt@gmail.com>
  6. * Copyright (c) 2014 Pali Rohár <pali.rohar@gmail.com>
  7. *
  8. * Based on documentation in the libsmbios package:
  9. * Copyright (C) 2005-2014 Dell Inc.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  16. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include <linux/capability.h>
  19. #include <linux/dmi.h>
  20. #include <linux/err.h>
  21. #include <linux/mutex.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/slab.h>
  24. #include "dell-smbios.h"
  25. static u32 da_supported_commands;
  26. static int da_num_tokens;
  27. static struct platform_device *platform_device;
  28. static struct calling_interface_token *da_tokens;
  29. static struct device_attribute *token_location_attrs;
  30. static struct device_attribute *token_value_attrs;
  31. static struct attribute **token_attrs;
  32. static DEFINE_MUTEX(smbios_mutex);
  33. struct smbios_device {
  34. struct list_head list;
  35. struct device *device;
  36. int (*call_fn)(struct calling_interface_buffer *arg);
  37. };
  38. struct smbios_call {
  39. u32 need_capability;
  40. int cmd_class;
  41. int cmd_select;
  42. };
  43. /* calls that are whitelisted for given capabilities */
  44. static struct smbios_call call_whitelist[] = {
  45. /* generally tokens are allowed, but may be further filtered or
  46. * restricted by token blacklist or whitelist
  47. */
  48. {CAP_SYS_ADMIN, CLASS_TOKEN_READ, SELECT_TOKEN_STD},
  49. {CAP_SYS_ADMIN, CLASS_TOKEN_READ, SELECT_TOKEN_AC},
  50. {CAP_SYS_ADMIN, CLASS_TOKEN_READ, SELECT_TOKEN_BAT},
  51. {CAP_SYS_ADMIN, CLASS_TOKEN_WRITE, SELECT_TOKEN_STD},
  52. {CAP_SYS_ADMIN, CLASS_TOKEN_WRITE, SELECT_TOKEN_AC},
  53. {CAP_SYS_ADMIN, CLASS_TOKEN_WRITE, SELECT_TOKEN_BAT},
  54. /* used by userspace: fwupdate */
  55. {CAP_SYS_ADMIN, CLASS_ADMIN_PROP, SELECT_ADMIN_PROP},
  56. /* used by userspace: fwupd */
  57. {CAP_SYS_ADMIN, CLASS_INFO, SELECT_DOCK},
  58. {CAP_SYS_ADMIN, CLASS_FLASH_INTERFACE, SELECT_FLASH_INTERFACE},
  59. };
  60. /* calls that are explicitly blacklisted */
  61. static struct smbios_call call_blacklist[] = {
  62. {0x0000, 1, 7}, /* manufacturing use */
  63. {0x0000, 6, 5}, /* manufacturing use */
  64. {0x0000, 11, 3}, /* write once */
  65. {0x0000, 11, 7}, /* write once */
  66. {0x0000, 11, 11}, /* write once */
  67. {0x0000, 19, -1}, /* diagnostics */
  68. /* handled by kernel: dell-laptop */
  69. {0x0000, CLASS_INFO, SELECT_RFKILL},
  70. {0x0000, CLASS_KBD_BACKLIGHT, SELECT_KBD_BACKLIGHT},
  71. };
  72. struct token_range {
  73. u32 need_capability;
  74. u16 min;
  75. u16 max;
  76. };
  77. /* tokens that are whitelisted for given capabilities */
  78. static struct token_range token_whitelist[] = {
  79. /* used by userspace: fwupdate */
  80. {CAP_SYS_ADMIN, CAPSULE_EN_TOKEN, CAPSULE_DIS_TOKEN},
  81. /* can indicate to userspace that WMI is needed */
  82. {0x0000, WSMT_EN_TOKEN, WSMT_DIS_TOKEN}
  83. };
  84. /* tokens that are explicitly blacklisted */
  85. static struct token_range token_blacklist[] = {
  86. {0x0000, 0x0058, 0x0059}, /* ME use */
  87. {0x0000, 0x00CD, 0x00D0}, /* raid shadow copy */
  88. {0x0000, 0x013A, 0x01FF}, /* sata shadow copy */
  89. {0x0000, 0x0175, 0x0176}, /* write once */
  90. {0x0000, 0x0195, 0x0197}, /* diagnostics */
  91. {0x0000, 0x01DC, 0x01DD}, /* manufacturing use */
  92. {0x0000, 0x027D, 0x0284}, /* diagnostics */
  93. {0x0000, 0x02E3, 0x02E3}, /* manufacturing use */
  94. {0x0000, 0x02FF, 0x02FF}, /* manufacturing use */
  95. {0x0000, 0x0300, 0x0302}, /* manufacturing use */
  96. {0x0000, 0x0325, 0x0326}, /* manufacturing use */
  97. {0x0000, 0x0332, 0x0335}, /* fan control */
  98. {0x0000, 0x0350, 0x0350}, /* manufacturing use */
  99. {0x0000, 0x0363, 0x0363}, /* manufacturing use */
  100. {0x0000, 0x0368, 0x0368}, /* manufacturing use */
  101. {0x0000, 0x03F6, 0x03F7}, /* manufacturing use */
  102. {0x0000, 0x049E, 0x049F}, /* manufacturing use */
  103. {0x0000, 0x04A0, 0x04A3}, /* disagnostics */
  104. {0x0000, 0x04E6, 0x04E7}, /* manufacturing use */
  105. {0x0000, 0x4000, 0x7FFF}, /* internal BIOS use */
  106. {0x0000, 0x9000, 0x9001}, /* internal BIOS use */
  107. {0x0000, 0xA000, 0xBFFF}, /* write only */
  108. {0x0000, 0xEFF0, 0xEFFF}, /* internal BIOS use */
  109. /* handled by kernel: dell-laptop */
  110. {0x0000, BRIGHTNESS_TOKEN, BRIGHTNESS_TOKEN},
  111. {0x0000, KBD_LED_OFF_TOKEN, KBD_LED_AUTO_TOKEN},
  112. {0x0000, KBD_LED_AC_TOKEN, KBD_LED_AC_TOKEN},
  113. {0x0000, KBD_LED_AUTO_25_TOKEN, KBD_LED_AUTO_75_TOKEN},
  114. {0x0000, KBD_LED_AUTO_100_TOKEN, KBD_LED_AUTO_100_TOKEN},
  115. {0x0000, GLOBAL_MIC_MUTE_ENABLE, GLOBAL_MIC_MUTE_DISABLE},
  116. };
  117. static LIST_HEAD(smbios_device_list);
  118. int dell_smbios_error(int value)
  119. {
  120. switch (value) {
  121. case 0: /* Completed successfully */
  122. return 0;
  123. case -1: /* Completed with error */
  124. return -EIO;
  125. case -2: /* Function not supported */
  126. return -ENXIO;
  127. default: /* Unknown error */
  128. return -EINVAL;
  129. }
  130. }
  131. EXPORT_SYMBOL_GPL(dell_smbios_error);
  132. int dell_smbios_register_device(struct device *d, void *call_fn)
  133. {
  134. struct smbios_device *priv;
  135. priv = devm_kzalloc(d, sizeof(struct smbios_device), GFP_KERNEL);
  136. if (!priv)
  137. return -ENOMEM;
  138. get_device(d);
  139. priv->device = d;
  140. priv->call_fn = call_fn;
  141. mutex_lock(&smbios_mutex);
  142. list_add_tail(&priv->list, &smbios_device_list);
  143. mutex_unlock(&smbios_mutex);
  144. dev_dbg(d, "Added device: %s\n", d->driver->name);
  145. return 0;
  146. }
  147. EXPORT_SYMBOL_GPL(dell_smbios_register_device);
  148. void dell_smbios_unregister_device(struct device *d)
  149. {
  150. struct smbios_device *priv;
  151. mutex_lock(&smbios_mutex);
  152. list_for_each_entry(priv, &smbios_device_list, list) {
  153. if (priv->device == d) {
  154. list_del(&priv->list);
  155. put_device(d);
  156. break;
  157. }
  158. }
  159. mutex_unlock(&smbios_mutex);
  160. dev_dbg(d, "Remove device: %s\n", d->driver->name);
  161. }
  162. EXPORT_SYMBOL_GPL(dell_smbios_unregister_device);
  163. int dell_smbios_call_filter(struct device *d,
  164. struct calling_interface_buffer *buffer)
  165. {
  166. u16 t = 0;
  167. int i;
  168. /* can't make calls over 30 */
  169. if (buffer->cmd_class > 30) {
  170. dev_dbg(d, "class too big: %u\n", buffer->cmd_class);
  171. return -EINVAL;
  172. }
  173. /* supported calls on the particular system */
  174. if (!(da_supported_commands & (1 << buffer->cmd_class))) {
  175. dev_dbg(d, "invalid command, supported commands: 0x%8x\n",
  176. da_supported_commands);
  177. return -EINVAL;
  178. }
  179. /* match against call blacklist */
  180. for (i = 0; i < ARRAY_SIZE(call_blacklist); i++) {
  181. if (buffer->cmd_class != call_blacklist[i].cmd_class)
  182. continue;
  183. if (buffer->cmd_select != call_blacklist[i].cmd_select &&
  184. call_blacklist[i].cmd_select != -1)
  185. continue;
  186. dev_dbg(d, "blacklisted command: %u/%u\n",
  187. buffer->cmd_class, buffer->cmd_select);
  188. return -EINVAL;
  189. }
  190. /* if a token call, find token ID */
  191. if ((buffer->cmd_class == CLASS_TOKEN_READ ||
  192. buffer->cmd_class == CLASS_TOKEN_WRITE) &&
  193. buffer->cmd_select < 3) {
  194. /* find the matching token ID */
  195. for (i = 0; i < da_num_tokens; i++) {
  196. if (da_tokens[i].location != buffer->input[0])
  197. continue;
  198. t = da_tokens[i].tokenID;
  199. break;
  200. }
  201. /* token call; but token didn't exist */
  202. if (!t) {
  203. dev_dbg(d, "token at location %04x doesn't exist\n",
  204. buffer->input[0]);
  205. return -EINVAL;
  206. }
  207. /* match against token blacklist */
  208. for (i = 0; i < ARRAY_SIZE(token_blacklist); i++) {
  209. if (!token_blacklist[i].min || !token_blacklist[i].max)
  210. continue;
  211. if (t >= token_blacklist[i].min &&
  212. t <= token_blacklist[i].max)
  213. return -EINVAL;
  214. }
  215. /* match against token whitelist */
  216. for (i = 0; i < ARRAY_SIZE(token_whitelist); i++) {
  217. if (!token_whitelist[i].min || !token_whitelist[i].max)
  218. continue;
  219. if (t < token_whitelist[i].min ||
  220. t > token_whitelist[i].max)
  221. continue;
  222. if (!token_whitelist[i].need_capability ||
  223. capable(token_whitelist[i].need_capability)) {
  224. dev_dbg(d, "whitelisted token: %x\n", t);
  225. return 0;
  226. }
  227. }
  228. }
  229. /* match against call whitelist */
  230. for (i = 0; i < ARRAY_SIZE(call_whitelist); i++) {
  231. if (buffer->cmd_class != call_whitelist[i].cmd_class)
  232. continue;
  233. if (buffer->cmd_select != call_whitelist[i].cmd_select)
  234. continue;
  235. if (!call_whitelist[i].need_capability ||
  236. capable(call_whitelist[i].need_capability)) {
  237. dev_dbg(d, "whitelisted capable command: %u/%u\n",
  238. buffer->cmd_class, buffer->cmd_select);
  239. return 0;
  240. }
  241. dev_dbg(d, "missing capability %d for %u/%u\n",
  242. call_whitelist[i].need_capability,
  243. buffer->cmd_class, buffer->cmd_select);
  244. }
  245. /* not in a whitelist, only allow processes with capabilities */
  246. if (capable(CAP_SYS_RAWIO)) {
  247. dev_dbg(d, "Allowing %u/%u due to CAP_SYS_RAWIO\n",
  248. buffer->cmd_class, buffer->cmd_select);
  249. return 0;
  250. }
  251. return -EACCES;
  252. }
  253. EXPORT_SYMBOL_GPL(dell_smbios_call_filter);
  254. int dell_smbios_call(struct calling_interface_buffer *buffer)
  255. {
  256. int (*call_fn)(struct calling_interface_buffer *) = NULL;
  257. struct device *selected_dev = NULL;
  258. struct smbios_device *priv;
  259. int ret;
  260. mutex_lock(&smbios_mutex);
  261. list_for_each_entry(priv, &smbios_device_list, list) {
  262. if (!selected_dev || priv->device->id >= selected_dev->id) {
  263. dev_dbg(priv->device, "Trying device ID: %d\n",
  264. priv->device->id);
  265. call_fn = priv->call_fn;
  266. selected_dev = priv->device;
  267. }
  268. }
  269. if (!selected_dev) {
  270. ret = -ENODEV;
  271. pr_err("No dell-smbios drivers are loaded\n");
  272. goto out_smbios_call;
  273. }
  274. ret = call_fn(buffer);
  275. out_smbios_call:
  276. mutex_unlock(&smbios_mutex);
  277. return ret;
  278. }
  279. EXPORT_SYMBOL_GPL(dell_smbios_call);
  280. struct calling_interface_token *dell_smbios_find_token(int tokenid)
  281. {
  282. int i;
  283. for (i = 0; i < da_num_tokens; i++) {
  284. if (da_tokens[i].tokenID == tokenid)
  285. return &da_tokens[i];
  286. }
  287. return NULL;
  288. }
  289. EXPORT_SYMBOL_GPL(dell_smbios_find_token);
  290. static BLOCKING_NOTIFIER_HEAD(dell_laptop_chain_head);
  291. int dell_laptop_register_notifier(struct notifier_block *nb)
  292. {
  293. return blocking_notifier_chain_register(&dell_laptop_chain_head, nb);
  294. }
  295. EXPORT_SYMBOL_GPL(dell_laptop_register_notifier);
  296. int dell_laptop_unregister_notifier(struct notifier_block *nb)
  297. {
  298. return blocking_notifier_chain_unregister(&dell_laptop_chain_head, nb);
  299. }
  300. EXPORT_SYMBOL_GPL(dell_laptop_unregister_notifier);
  301. void dell_laptop_call_notifier(unsigned long action, void *data)
  302. {
  303. blocking_notifier_call_chain(&dell_laptop_chain_head, action, data);
  304. }
  305. EXPORT_SYMBOL_GPL(dell_laptop_call_notifier);
  306. static void __init parse_da_table(const struct dmi_header *dm)
  307. {
  308. /* Final token is a terminator, so we don't want to copy it */
  309. int tokens = (dm->length-11)/sizeof(struct calling_interface_token)-1;
  310. struct calling_interface_token *new_da_tokens;
  311. struct calling_interface_structure *table =
  312. container_of(dm, struct calling_interface_structure, header);
  313. /*
  314. * 4 bytes of table header, plus 7 bytes of Dell header
  315. * plus at least 6 bytes of entry
  316. */
  317. if (dm->length < 17)
  318. return;
  319. da_supported_commands = table->supportedCmds;
  320. new_da_tokens = krealloc(da_tokens, (da_num_tokens + tokens) *
  321. sizeof(struct calling_interface_token),
  322. GFP_KERNEL);
  323. if (!new_da_tokens)
  324. return;
  325. da_tokens = new_da_tokens;
  326. memcpy(da_tokens+da_num_tokens, table->tokens,
  327. sizeof(struct calling_interface_token) * tokens);
  328. da_num_tokens += tokens;
  329. }
  330. static void zero_duplicates(struct device *dev)
  331. {
  332. int i, j;
  333. for (i = 0; i < da_num_tokens; i++) {
  334. if (da_tokens[i].tokenID == 0)
  335. continue;
  336. for (j = i+1; j < da_num_tokens; j++) {
  337. if (da_tokens[j].tokenID == 0)
  338. continue;
  339. if (da_tokens[i].tokenID == da_tokens[j].tokenID) {
  340. dev_dbg(dev, "Zeroing dup token ID %x(%x/%x)\n",
  341. da_tokens[j].tokenID,
  342. da_tokens[j].location,
  343. da_tokens[j].value);
  344. da_tokens[j].tokenID = 0;
  345. }
  346. }
  347. }
  348. }
  349. static void __init find_tokens(const struct dmi_header *dm, void *dummy)
  350. {
  351. switch (dm->type) {
  352. case 0xd4: /* Indexed IO */
  353. case 0xd5: /* Protected Area Type 1 */
  354. case 0xd6: /* Protected Area Type 2 */
  355. break;
  356. case 0xda: /* Calling interface */
  357. parse_da_table(dm);
  358. break;
  359. }
  360. }
  361. static int match_attribute(struct device *dev,
  362. struct device_attribute *attr)
  363. {
  364. int i;
  365. for (i = 0; i < da_num_tokens * 2; i++) {
  366. if (!token_attrs[i])
  367. continue;
  368. if (strcmp(token_attrs[i]->name, attr->attr.name) == 0)
  369. return i/2;
  370. }
  371. dev_dbg(dev, "couldn't match: %s\n", attr->attr.name);
  372. return -EINVAL;
  373. }
  374. static ssize_t location_show(struct device *dev,
  375. struct device_attribute *attr, char *buf)
  376. {
  377. int i;
  378. if (!capable(CAP_SYS_ADMIN))
  379. return -EPERM;
  380. i = match_attribute(dev, attr);
  381. if (i > 0)
  382. return scnprintf(buf, PAGE_SIZE, "%08x", da_tokens[i].location);
  383. return 0;
  384. }
  385. static ssize_t value_show(struct device *dev,
  386. struct device_attribute *attr, char *buf)
  387. {
  388. int i;
  389. if (!capable(CAP_SYS_ADMIN))
  390. return -EPERM;
  391. i = match_attribute(dev, attr);
  392. if (i > 0)
  393. return scnprintf(buf, PAGE_SIZE, "%08x", da_tokens[i].value);
  394. return 0;
  395. }
  396. static struct attribute_group smbios_attribute_group = {
  397. .name = "tokens"
  398. };
  399. static struct platform_driver platform_driver = {
  400. .driver = {
  401. .name = "dell-smbios",
  402. },
  403. };
  404. static int build_tokens_sysfs(struct platform_device *dev)
  405. {
  406. char *location_name;
  407. char *value_name;
  408. size_t size;
  409. int ret;
  410. int i, j;
  411. /* (number of tokens + 1 for null terminated */
  412. size = sizeof(struct device_attribute) * (da_num_tokens + 1);
  413. token_location_attrs = kzalloc(size, GFP_KERNEL);
  414. if (!token_location_attrs)
  415. return -ENOMEM;
  416. token_value_attrs = kzalloc(size, GFP_KERNEL);
  417. if (!token_value_attrs)
  418. goto out_allocate_value;
  419. /* need to store both location and value + terminator*/
  420. size = sizeof(struct attribute *) * ((2 * da_num_tokens) + 1);
  421. token_attrs = kzalloc(size, GFP_KERNEL);
  422. if (!token_attrs)
  423. goto out_allocate_attrs;
  424. for (i = 0, j = 0; i < da_num_tokens; i++) {
  425. /* skip empty */
  426. if (da_tokens[i].tokenID == 0)
  427. continue;
  428. /* add location */
  429. location_name = kasprintf(GFP_KERNEL, "%04x_location",
  430. da_tokens[i].tokenID);
  431. if (location_name == NULL)
  432. goto out_unwind_strings;
  433. sysfs_attr_init(&token_location_attrs[i].attr);
  434. token_location_attrs[i].attr.name = location_name;
  435. token_location_attrs[i].attr.mode = 0444;
  436. token_location_attrs[i].show = location_show;
  437. token_attrs[j++] = &token_location_attrs[i].attr;
  438. /* add value */
  439. value_name = kasprintf(GFP_KERNEL, "%04x_value",
  440. da_tokens[i].tokenID);
  441. if (value_name == NULL)
  442. goto loop_fail_create_value;
  443. sysfs_attr_init(&token_value_attrs[i].attr);
  444. token_value_attrs[i].attr.name = value_name;
  445. token_value_attrs[i].attr.mode = 0444;
  446. token_value_attrs[i].show = value_show;
  447. token_attrs[j++] = &token_value_attrs[i].attr;
  448. continue;
  449. loop_fail_create_value:
  450. kfree(location_name);
  451. goto out_unwind_strings;
  452. }
  453. smbios_attribute_group.attrs = token_attrs;
  454. ret = sysfs_create_group(&dev->dev.kobj, &smbios_attribute_group);
  455. if (ret)
  456. goto out_unwind_strings;
  457. return 0;
  458. out_unwind_strings:
  459. while (i--) {
  460. kfree(token_location_attrs[i].attr.name);
  461. kfree(token_value_attrs[i].attr.name);
  462. }
  463. kfree(token_attrs);
  464. out_allocate_attrs:
  465. kfree(token_value_attrs);
  466. out_allocate_value:
  467. kfree(token_location_attrs);
  468. return -ENOMEM;
  469. }
  470. static void free_group(struct platform_device *pdev)
  471. {
  472. int i;
  473. sysfs_remove_group(&pdev->dev.kobj,
  474. &smbios_attribute_group);
  475. for (i = 0; i < da_num_tokens; i++) {
  476. kfree(token_location_attrs[i].attr.name);
  477. kfree(token_value_attrs[i].attr.name);
  478. }
  479. kfree(token_attrs);
  480. kfree(token_value_attrs);
  481. kfree(token_location_attrs);
  482. }
  483. static int __init dell_smbios_init(void)
  484. {
  485. const struct dmi_device *valid;
  486. int ret, wmi, smm;
  487. valid = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, "Dell System", NULL);
  488. if (!valid) {
  489. pr_err("Unable to run on non-Dell system\n");
  490. return -ENODEV;
  491. }
  492. dmi_walk(find_tokens, NULL);
  493. if (!da_tokens) {
  494. pr_info("Unable to find dmi tokens\n");
  495. return -ENODEV;
  496. }
  497. ret = platform_driver_register(&platform_driver);
  498. if (ret)
  499. goto fail_platform_driver;
  500. platform_device = platform_device_alloc("dell-smbios", 0);
  501. if (!platform_device) {
  502. ret = -ENOMEM;
  503. goto fail_platform_device_alloc;
  504. }
  505. ret = platform_device_add(platform_device);
  506. if (ret)
  507. goto fail_platform_device_add;
  508. /* duplicate tokens will cause problems building sysfs files */
  509. zero_duplicates(&platform_device->dev);
  510. ret = build_tokens_sysfs(platform_device);
  511. if (ret)
  512. goto fail_create_group;
  513. /* register backends */
  514. wmi = init_dell_smbios_wmi();
  515. if (wmi)
  516. pr_debug("Failed to initialize WMI backend: %d\n", wmi);
  517. smm = init_dell_smbios_smm();
  518. if (smm)
  519. pr_debug("Failed to initialize SMM backend: %d\n", smm);
  520. if (wmi && smm) {
  521. pr_err("No SMBIOS backends available (wmi: %d, smm: %d)\n",
  522. wmi, smm);
  523. goto fail_sysfs;
  524. }
  525. return 0;
  526. fail_sysfs:
  527. free_group(platform_device);
  528. fail_create_group:
  529. platform_device_del(platform_device);
  530. fail_platform_device_add:
  531. platform_device_put(platform_device);
  532. fail_platform_device_alloc:
  533. platform_driver_unregister(&platform_driver);
  534. fail_platform_driver:
  535. kfree(da_tokens);
  536. return ret;
  537. }
  538. static void __exit dell_smbios_exit(void)
  539. {
  540. exit_dell_smbios_wmi();
  541. exit_dell_smbios_smm();
  542. mutex_lock(&smbios_mutex);
  543. if (platform_device) {
  544. free_group(platform_device);
  545. platform_device_unregister(platform_device);
  546. platform_driver_unregister(&platform_driver);
  547. }
  548. kfree(da_tokens);
  549. mutex_unlock(&smbios_mutex);
  550. }
  551. module_init(dell_smbios_init);
  552. module_exit(dell_smbios_exit);
  553. MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
  554. MODULE_AUTHOR("Gabriele Mazzotta <gabriele.mzt@gmail.com>");
  555. MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>");
  556. MODULE_AUTHOR("Mario Limonciello <mario.limonciello@dell.com>");
  557. MODULE_DESCRIPTION("Common functions for kernel modules using Dell SMBIOS");
  558. MODULE_LICENSE("GPL");