acpi_ipmi.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. /*
  2. * acpi_ipmi.c - ACPI IPMI opregion
  3. *
  4. * Copyright (C) 2010, 2013 Intel Corporation
  5. * Author: Zhao Yakui <yakui.zhao@intel.com>
  6. * Lv Zheng <lv.zheng@intel.com>
  7. *
  8. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or (at
  13. * your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License along
  21. * with this program; if not, write to the Free Software Foundation, Inc.,
  22. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  23. *
  24. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  25. */
  26. #include <linux/kernel.h>
  27. #include <linux/module.h>
  28. #include <linux/init.h>
  29. #include <linux/types.h>
  30. #include <linux/delay.h>
  31. #include <linux/proc_fs.h>
  32. #include <linux/seq_file.h>
  33. #include <linux/interrupt.h>
  34. #include <linux/list.h>
  35. #include <linux/spinlock.h>
  36. #include <linux/io.h>
  37. #include <acpi/acpi_bus.h>
  38. #include <acpi/acpi_drivers.h>
  39. #include <linux/ipmi.h>
  40. #include <linux/device.h>
  41. #include <linux/pnp.h>
  42. #include <linux/spinlock.h>
  43. MODULE_AUTHOR("Zhao Yakui");
  44. MODULE_DESCRIPTION("ACPI IPMI Opregion driver");
  45. MODULE_LICENSE("GPL");
  46. #define ACPI_IPMI_OK 0
  47. #define ACPI_IPMI_TIMEOUT 0x10
  48. #define ACPI_IPMI_UNKNOWN 0x07
  49. /* the IPMI timeout is 5s */
  50. #define IPMI_TIMEOUT (5000)
  51. #define ACPI_IPMI_MAX_MSG_LENGTH 64
  52. struct acpi_ipmi_device {
  53. /* the device list attached to driver_data.ipmi_devices */
  54. struct list_head head;
  55. /* the IPMI request message list */
  56. struct list_head tx_msg_list;
  57. spinlock_t tx_msg_lock;
  58. acpi_handle handle;
  59. struct pnp_dev *pnp_dev;
  60. ipmi_user_t user_interface;
  61. int ipmi_ifnum; /* IPMI interface number */
  62. long curr_msgid;
  63. struct ipmi_smi_info smi_data;
  64. bool dead;
  65. struct kref kref;
  66. };
  67. struct ipmi_driver_data {
  68. struct list_head ipmi_devices;
  69. struct ipmi_smi_watcher bmc_events;
  70. struct ipmi_user_hndl ipmi_hndlrs;
  71. struct mutex ipmi_lock;
  72. /*
  73. * NOTE: IPMI System Interface Selection
  74. * There is no system interface specified by the IPMI operation
  75. * region access. We try to select one system interface with ACPI
  76. * handle set. IPMI messages passed from the ACPI codes are sent
  77. * to this selected global IPMI system interface.
  78. */
  79. struct acpi_ipmi_device *selected_smi;
  80. };
  81. struct acpi_ipmi_msg {
  82. struct list_head head;
  83. /*
  84. * General speaking the addr type should be SI_ADDR_TYPE. And
  85. * the addr channel should be BMC.
  86. * In fact it can also be IPMB type. But we will have to
  87. * parse it from the Netfn command buffer. It is so complex
  88. * that it is skipped.
  89. */
  90. struct ipmi_addr addr;
  91. long tx_msgid;
  92. /* it is used to track whether the IPMI message is finished */
  93. struct completion tx_complete;
  94. struct kernel_ipmi_msg tx_message;
  95. int msg_done;
  96. /* tx/rx data . And copy it from/to ACPI object buffer */
  97. u8 data[ACPI_IPMI_MAX_MSG_LENGTH];
  98. u8 rx_len;
  99. struct acpi_ipmi_device *device;
  100. };
  101. /* IPMI request/response buffer per ACPI 4.0, sec 5.5.2.4.3.2 */
  102. struct acpi_ipmi_buffer {
  103. u8 status;
  104. u8 length;
  105. u8 data[ACPI_IPMI_MAX_MSG_LENGTH];
  106. };
  107. static void ipmi_register_bmc(int iface, struct device *dev);
  108. static void ipmi_bmc_gone(int iface);
  109. static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data);
  110. static struct ipmi_driver_data driver_data = {
  111. .ipmi_devices = LIST_HEAD_INIT(driver_data.ipmi_devices),
  112. .bmc_events = {
  113. .owner = THIS_MODULE,
  114. .new_smi = ipmi_register_bmc,
  115. .smi_gone = ipmi_bmc_gone,
  116. },
  117. .ipmi_hndlrs = {
  118. .ipmi_recv_hndl = ipmi_msg_handler,
  119. },
  120. };
  121. static struct acpi_ipmi_device *
  122. ipmi_dev_alloc(int iface, struct ipmi_smi_info *smi_data, acpi_handle handle)
  123. {
  124. struct acpi_ipmi_device *ipmi_device;
  125. int err;
  126. ipmi_user_t user;
  127. ipmi_device = kzalloc(sizeof(*ipmi_device), GFP_KERNEL);
  128. if (!ipmi_device)
  129. return NULL;
  130. kref_init(&ipmi_device->kref);
  131. INIT_LIST_HEAD(&ipmi_device->head);
  132. INIT_LIST_HEAD(&ipmi_device->tx_msg_list);
  133. spin_lock_init(&ipmi_device->tx_msg_lock);
  134. ipmi_device->handle = handle;
  135. ipmi_device->pnp_dev = to_pnp_dev(get_device(smi_data->dev));
  136. memcpy(&ipmi_device->smi_data, smi_data, sizeof(struct ipmi_smi_info));
  137. ipmi_device->ipmi_ifnum = iface;
  138. err = ipmi_create_user(iface, &driver_data.ipmi_hndlrs,
  139. ipmi_device, &user);
  140. if (err) {
  141. put_device(smi_data->dev);
  142. kfree(ipmi_device);
  143. return NULL;
  144. }
  145. ipmi_device->user_interface = user;
  146. return ipmi_device;
  147. }
  148. static void ipmi_dev_release(struct acpi_ipmi_device *ipmi_device)
  149. {
  150. ipmi_destroy_user(ipmi_device->user_interface);
  151. put_device(ipmi_device->smi_data.dev);
  152. kfree(ipmi_device);
  153. }
  154. static void ipmi_dev_release_kref(struct kref *kref)
  155. {
  156. struct acpi_ipmi_device *ipmi =
  157. container_of(kref, struct acpi_ipmi_device, kref);
  158. ipmi_dev_release(ipmi);
  159. }
  160. static void __ipmi_dev_kill(struct acpi_ipmi_device *ipmi_device)
  161. {
  162. list_del(&ipmi_device->head);
  163. if (driver_data.selected_smi == ipmi_device)
  164. driver_data.selected_smi = NULL;
  165. /*
  166. * Always setting dead flag after deleting from the list or
  167. * list_for_each_entry() codes must get changed.
  168. */
  169. ipmi_device->dead = true;
  170. }
  171. static struct acpi_ipmi_device *acpi_ipmi_dev_get(void)
  172. {
  173. struct acpi_ipmi_device *ipmi_device = NULL;
  174. mutex_lock(&driver_data.ipmi_lock);
  175. if (driver_data.selected_smi) {
  176. ipmi_device = driver_data.selected_smi;
  177. kref_get(&ipmi_device->kref);
  178. }
  179. mutex_unlock(&driver_data.ipmi_lock);
  180. return ipmi_device;
  181. }
  182. static void acpi_ipmi_dev_put(struct acpi_ipmi_device *ipmi_device)
  183. {
  184. kref_put(&ipmi_device->kref, ipmi_dev_release_kref);
  185. }
  186. static struct acpi_ipmi_msg *acpi_alloc_ipmi_msg(struct acpi_ipmi_device *ipmi)
  187. {
  188. struct acpi_ipmi_msg *ipmi_msg;
  189. struct pnp_dev *pnp_dev = ipmi->pnp_dev;
  190. ipmi_msg = kzalloc(sizeof(struct acpi_ipmi_msg), GFP_KERNEL);
  191. if (!ipmi_msg) {
  192. dev_warn(&pnp_dev->dev, "Can't allocate memory for ipmi_msg\n");
  193. return NULL;
  194. }
  195. init_completion(&ipmi_msg->tx_complete);
  196. INIT_LIST_HEAD(&ipmi_msg->head);
  197. ipmi_msg->device = ipmi;
  198. ipmi_msg->msg_done = ACPI_IPMI_UNKNOWN;
  199. return ipmi_msg;
  200. }
  201. #define IPMI_OP_RGN_NETFN(offset) ((offset >> 8) & 0xff)
  202. #define IPMI_OP_RGN_CMD(offset) (offset & 0xff)
  203. static int acpi_format_ipmi_request(struct acpi_ipmi_msg *tx_msg,
  204. acpi_physical_address address,
  205. acpi_integer *value)
  206. {
  207. struct kernel_ipmi_msg *msg;
  208. struct acpi_ipmi_buffer *buffer;
  209. struct acpi_ipmi_device *device;
  210. unsigned long flags;
  211. msg = &tx_msg->tx_message;
  212. /*
  213. * IPMI network function and command are encoded in the address
  214. * within the IPMI OpRegion; see ACPI 4.0, sec 5.5.2.4.3.
  215. */
  216. msg->netfn = IPMI_OP_RGN_NETFN(address);
  217. msg->cmd = IPMI_OP_RGN_CMD(address);
  218. msg->data = tx_msg->data;
  219. /*
  220. * value is the parameter passed by the IPMI opregion space handler.
  221. * It points to the IPMI request message buffer
  222. */
  223. buffer = (struct acpi_ipmi_buffer *)value;
  224. /* copy the tx message data */
  225. if (buffer->length > ACPI_IPMI_MAX_MSG_LENGTH) {
  226. dev_WARN_ONCE(&tx_msg->device->pnp_dev->dev, true,
  227. "Unexpected request (msg len %d).\n",
  228. buffer->length);
  229. return -EINVAL;
  230. }
  231. msg->data_len = buffer->length;
  232. memcpy(tx_msg->data, buffer->data, msg->data_len);
  233. /*
  234. * now the default type is SYSTEM_INTERFACE and channel type is BMC.
  235. * If the netfn is APP_REQUEST and the cmd is SEND_MESSAGE,
  236. * the addr type should be changed to IPMB. Then we will have to parse
  237. * the IPMI request message buffer to get the IPMB address.
  238. * If so, please fix me.
  239. */
  240. tx_msg->addr.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
  241. tx_msg->addr.channel = IPMI_BMC_CHANNEL;
  242. tx_msg->addr.data[0] = 0;
  243. /* Get the msgid */
  244. device = tx_msg->device;
  245. spin_lock_irqsave(&device->tx_msg_lock, flags);
  246. device->curr_msgid++;
  247. tx_msg->tx_msgid = device->curr_msgid;
  248. spin_unlock_irqrestore(&device->tx_msg_lock, flags);
  249. return 0;
  250. }
  251. static void acpi_format_ipmi_response(struct acpi_ipmi_msg *msg,
  252. acpi_integer *value)
  253. {
  254. struct acpi_ipmi_buffer *buffer;
  255. /*
  256. * value is also used as output parameter. It represents the response
  257. * IPMI message returned by IPMI command.
  258. */
  259. buffer = (struct acpi_ipmi_buffer *)value;
  260. /*
  261. * If the flag of msg_done is not set, it means that the IPMI command is
  262. * not executed correctly.
  263. */
  264. buffer->status = msg->msg_done;
  265. if (msg->msg_done != ACPI_IPMI_OK)
  266. return;
  267. /*
  268. * If the IPMI response message is obtained correctly, the status code
  269. * will be ACPI_IPMI_OK
  270. */
  271. buffer->length = msg->rx_len;
  272. memcpy(buffer->data, msg->data, msg->rx_len);
  273. }
  274. static void ipmi_flush_tx_msg(struct acpi_ipmi_device *ipmi)
  275. {
  276. struct acpi_ipmi_msg *tx_msg, *temp;
  277. unsigned long flags;
  278. /*
  279. * NOTE: On-going ipmi_recv_msg
  280. * ipmi_msg_handler() may still be invoked by ipmi_si after
  281. * flushing. But it is safe to do a fast flushing on module_exit()
  282. * without waiting for all ipmi_recv_msg(s) to complete from
  283. * ipmi_msg_handler() as it is ensured by ipmi_si that all
  284. * ipmi_recv_msg(s) are freed after invoking ipmi_destroy_user().
  285. */
  286. spin_lock_irqsave(&ipmi->tx_msg_lock, flags);
  287. list_for_each_entry_safe(tx_msg, temp, &ipmi->tx_msg_list, head) {
  288. /* wake up the sleep thread on the Tx msg */
  289. complete(&tx_msg->tx_complete);
  290. }
  291. spin_unlock_irqrestore(&ipmi->tx_msg_lock, flags);
  292. }
  293. static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data)
  294. {
  295. struct acpi_ipmi_device *ipmi_device = user_msg_data;
  296. int msg_found = 0;
  297. struct acpi_ipmi_msg *tx_msg;
  298. struct pnp_dev *pnp_dev = ipmi_device->pnp_dev;
  299. unsigned long flags;
  300. if (msg->user != ipmi_device->user_interface) {
  301. dev_warn(&pnp_dev->dev, "Unexpected response is returned. "
  302. "returned user %p, expected user %p\n",
  303. msg->user, ipmi_device->user_interface);
  304. goto out_msg;
  305. }
  306. spin_lock_irqsave(&ipmi_device->tx_msg_lock, flags);
  307. list_for_each_entry(tx_msg, &ipmi_device->tx_msg_list, head) {
  308. if (msg->msgid == tx_msg->tx_msgid) {
  309. msg_found = 1;
  310. break;
  311. }
  312. }
  313. if (!msg_found) {
  314. dev_warn(&pnp_dev->dev, "Unexpected response (msg id %ld) is "
  315. "returned.\n", msg->msgid);
  316. goto out_lock;
  317. }
  318. /* copy the response data to Rx_data buffer */
  319. if (msg->msg.data_len > ACPI_IPMI_MAX_MSG_LENGTH) {
  320. dev_WARN_ONCE(&pnp_dev->dev, true,
  321. "Unexpected response (msg len %d).\n",
  322. msg->msg.data_len);
  323. goto out_comp;
  324. }
  325. /* response msg is an error msg */
  326. msg->recv_type = IPMI_RESPONSE_RECV_TYPE;
  327. if (msg->recv_type == IPMI_RESPONSE_RECV_TYPE &&
  328. msg->msg.data_len == 1) {
  329. if (msg->msg.data[0] == IPMI_TIMEOUT_COMPLETION_CODE) {
  330. dev_WARN_ONCE(&pnp_dev->dev, true,
  331. "Unexpected response (timeout).\n");
  332. tx_msg->msg_done = ACPI_IPMI_TIMEOUT;
  333. }
  334. goto out_comp;
  335. }
  336. tx_msg->rx_len = msg->msg.data_len;
  337. memcpy(tx_msg->data, msg->msg.data, tx_msg->rx_len);
  338. tx_msg->msg_done = ACPI_IPMI_OK;
  339. out_comp:
  340. complete(&tx_msg->tx_complete);
  341. out_lock:
  342. spin_unlock_irqrestore(&ipmi_device->tx_msg_lock, flags);
  343. out_msg:
  344. ipmi_free_recv_msg(msg);
  345. };
  346. static void ipmi_register_bmc(int iface, struct device *dev)
  347. {
  348. struct acpi_ipmi_device *ipmi_device, *temp;
  349. struct pnp_dev *pnp_dev;
  350. int err;
  351. struct ipmi_smi_info smi_data;
  352. acpi_handle handle;
  353. err = ipmi_get_smi_info(iface, &smi_data);
  354. if (err)
  355. return;
  356. if (smi_data.addr_src != SI_ACPI)
  357. goto err_ref;
  358. handle = smi_data.addr_info.acpi_info.acpi_handle;
  359. if (!handle)
  360. goto err_ref;
  361. pnp_dev = to_pnp_dev(smi_data.dev);
  362. ipmi_device = ipmi_dev_alloc(iface, &smi_data, handle);
  363. if (!ipmi_device) {
  364. dev_warn(&pnp_dev->dev, "Can't create IPMI user interface\n");
  365. goto err_ref;
  366. }
  367. mutex_lock(&driver_data.ipmi_lock);
  368. list_for_each_entry(temp, &driver_data.ipmi_devices, head) {
  369. /*
  370. * if the corresponding ACPI handle is already added
  371. * to the device list, don't add it again.
  372. */
  373. if (temp->handle == handle)
  374. goto err_lock;
  375. }
  376. if (!driver_data.selected_smi)
  377. driver_data.selected_smi = ipmi_device;
  378. list_add_tail(&ipmi_device->head, &driver_data.ipmi_devices);
  379. mutex_unlock(&driver_data.ipmi_lock);
  380. put_device(smi_data.dev);
  381. return;
  382. err_lock:
  383. mutex_unlock(&driver_data.ipmi_lock);
  384. ipmi_dev_release(ipmi_device);
  385. err_ref:
  386. put_device(smi_data.dev);
  387. return;
  388. }
  389. static void ipmi_bmc_gone(int iface)
  390. {
  391. struct acpi_ipmi_device *ipmi_device, *temp;
  392. bool dev_found = false;
  393. mutex_lock(&driver_data.ipmi_lock);
  394. list_for_each_entry_safe(ipmi_device, temp,
  395. &driver_data.ipmi_devices, head) {
  396. if (ipmi_device->ipmi_ifnum != iface) {
  397. dev_found = true;
  398. __ipmi_dev_kill(ipmi_device);
  399. break;
  400. }
  401. }
  402. if (!driver_data.selected_smi)
  403. driver_data.selected_smi = list_first_entry_or_null(
  404. &driver_data.ipmi_devices,
  405. struct acpi_ipmi_device, head);
  406. mutex_unlock(&driver_data.ipmi_lock);
  407. if (dev_found) {
  408. ipmi_flush_tx_msg(ipmi_device);
  409. acpi_ipmi_dev_put(ipmi_device);
  410. }
  411. }
  412. /* --------------------------------------------------------------------------
  413. * Address Space Management
  414. * -------------------------------------------------------------------------- */
  415. /*
  416. * This is the IPMI opregion space handler.
  417. * @function: indicates the read/write. In fact as the IPMI message is driven
  418. * by command, only write is meaningful.
  419. * @address: This contains the netfn/command of IPMI request message.
  420. * @bits : not used.
  421. * @value : it is an in/out parameter. It points to the IPMI message buffer.
  422. * Before the IPMI message is sent, it represents the actual request
  423. * IPMI message. After the IPMI message is finished, it represents
  424. * the response IPMI message returned by IPMI command.
  425. * @handler_context: IPMI device context.
  426. */
  427. static acpi_status
  428. acpi_ipmi_space_handler(u32 function, acpi_physical_address address,
  429. u32 bits, acpi_integer *value,
  430. void *handler_context, void *region_context)
  431. {
  432. struct acpi_ipmi_msg *tx_msg;
  433. struct acpi_ipmi_device *ipmi_device;
  434. int err;
  435. acpi_status status;
  436. unsigned long flags;
  437. /*
  438. * IPMI opregion message.
  439. * IPMI message is firstly written to the BMC and system software
  440. * can get the respsonse. So it is unmeaningful for the read access
  441. * of IPMI opregion.
  442. */
  443. if ((function & ACPI_IO_MASK) == ACPI_READ)
  444. return AE_TYPE;
  445. ipmi_device = acpi_ipmi_dev_get();
  446. if (!ipmi_device)
  447. return AE_NOT_EXIST;
  448. tx_msg = acpi_alloc_ipmi_msg(ipmi_device);
  449. if (!tx_msg) {
  450. status = AE_NO_MEMORY;
  451. goto out_ref;
  452. }
  453. if (acpi_format_ipmi_request(tx_msg, address, value) != 0) {
  454. status = AE_TYPE;
  455. goto out_msg;
  456. }
  457. mutex_lock(&driver_data.ipmi_lock);
  458. /* Do not add a tx_msg that can not be flushed. */
  459. if (ipmi_device->dead) {
  460. status = AE_NOT_EXIST;
  461. mutex_unlock(&driver_data.ipmi_lock);
  462. goto out_msg;
  463. }
  464. spin_lock_irqsave(&ipmi_device->tx_msg_lock, flags);
  465. list_add_tail(&tx_msg->head, &ipmi_device->tx_msg_list);
  466. spin_unlock_irqrestore(&ipmi_device->tx_msg_lock, flags);
  467. mutex_unlock(&driver_data.ipmi_lock);
  468. err = ipmi_request_settime(ipmi_device->user_interface,
  469. &tx_msg->addr,
  470. tx_msg->tx_msgid,
  471. &tx_msg->tx_message,
  472. NULL, 0, 0, IPMI_TIMEOUT);
  473. if (err) {
  474. status = AE_ERROR;
  475. goto out_list;
  476. }
  477. wait_for_completion(&tx_msg->tx_complete);
  478. acpi_format_ipmi_response(tx_msg, value);
  479. status = AE_OK;
  480. out_list:
  481. spin_lock_irqsave(&ipmi_device->tx_msg_lock, flags);
  482. list_del(&tx_msg->head);
  483. spin_unlock_irqrestore(&ipmi_device->tx_msg_lock, flags);
  484. out_msg:
  485. kfree(tx_msg);
  486. out_ref:
  487. acpi_ipmi_dev_put(ipmi_device);
  488. return status;
  489. }
  490. static int __init acpi_ipmi_init(void)
  491. {
  492. int result = 0;
  493. acpi_status status;
  494. if (acpi_disabled)
  495. return result;
  496. mutex_init(&driver_data.ipmi_lock);
  497. status = acpi_install_address_space_handler(ACPI_ROOT_OBJECT,
  498. ACPI_ADR_SPACE_IPMI, &acpi_ipmi_space_handler,
  499. NULL, NULL);
  500. if (ACPI_FAILURE(status)) {
  501. pr_warn("Can't register IPMI opregion space handle\n");
  502. return -EINVAL;
  503. }
  504. result = ipmi_smi_watcher_register(&driver_data.bmc_events);
  505. if (result)
  506. pr_err("Can't register IPMI system interface watcher\n");
  507. return result;
  508. }
  509. static void __exit acpi_ipmi_exit(void)
  510. {
  511. struct acpi_ipmi_device *ipmi_device;
  512. if (acpi_disabled)
  513. return;
  514. ipmi_smi_watcher_unregister(&driver_data.bmc_events);
  515. /*
  516. * When one smi_watcher is unregistered, it is only deleted
  517. * from the smi_watcher list. But the smi_gone callback function
  518. * is not called. So explicitly uninstall the ACPI IPMI oregion
  519. * handler and free it.
  520. */
  521. mutex_lock(&driver_data.ipmi_lock);
  522. while (!list_empty(&driver_data.ipmi_devices)) {
  523. ipmi_device = list_first_entry(&driver_data.ipmi_devices,
  524. struct acpi_ipmi_device,
  525. head);
  526. __ipmi_dev_kill(ipmi_device);
  527. mutex_unlock(&driver_data.ipmi_lock);
  528. ipmi_flush_tx_msg(ipmi_device);
  529. acpi_ipmi_dev_put(ipmi_device);
  530. mutex_lock(&driver_data.ipmi_lock);
  531. }
  532. mutex_unlock(&driver_data.ipmi_lock);
  533. acpi_remove_address_space_handler(ACPI_ROOT_OBJECT,
  534. ACPI_ADR_SPACE_IPMI, &acpi_ipmi_space_handler);
  535. }
  536. module_init(acpi_ipmi_init);
  537. module_exit(acpi_ipmi_exit);