acpi_ipmi.c 16 KB

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