Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *  acpi_ipmi.c - ACPI IPMI opregion
0004  *
0005  *  Copyright (C) 2010, 2013 Intel Corporation
0006  *    Author: Zhao Yakui <yakui.zhao@intel.com>
0007  *            Lv Zheng <lv.zheng@intel.com>
0008  */
0009 
0010 #include <linux/module.h>
0011 #include <linux/acpi.h>
0012 #include <linux/ipmi.h>
0013 #include <linux/spinlock.h>
0014 
0015 MODULE_AUTHOR("Zhao Yakui");
0016 MODULE_DESCRIPTION("ACPI IPMI Opregion driver");
0017 MODULE_LICENSE("GPL");
0018 
0019 #define ACPI_IPMI_OK            0
0020 #define ACPI_IPMI_TIMEOUT       0x10
0021 #define ACPI_IPMI_UNKNOWN       0x07
0022 /* the IPMI timeout is 5s */
0023 #define IPMI_TIMEOUT            (5000)
0024 #define ACPI_IPMI_MAX_MSG_LENGTH    64
0025 
0026 struct acpi_ipmi_device {
0027     /* the device list attached to driver_data.ipmi_devices */
0028     struct list_head head;
0029 
0030     /* the IPMI request message list */
0031     struct list_head tx_msg_list;
0032 
0033     spinlock_t tx_msg_lock;
0034     acpi_handle handle;
0035     struct device *dev;
0036     struct ipmi_user *user_interface;
0037     int ipmi_ifnum; /* IPMI interface number */
0038     long curr_msgid;
0039     bool dead;
0040     struct kref kref;
0041 };
0042 
0043 struct ipmi_driver_data {
0044     struct list_head ipmi_devices;
0045     struct ipmi_smi_watcher bmc_events;
0046     const struct ipmi_user_hndl ipmi_hndlrs;
0047     struct mutex ipmi_lock;
0048 
0049     /*
0050      * NOTE: IPMI System Interface Selection
0051      * There is no system interface specified by the IPMI operation
0052      * region access.  We try to select one system interface with ACPI
0053      * handle set.  IPMI messages passed from the ACPI codes are sent
0054      * to this selected global IPMI system interface.
0055      */
0056     struct acpi_ipmi_device *selected_smi;
0057 };
0058 
0059 struct acpi_ipmi_msg {
0060     struct list_head head;
0061 
0062     /*
0063      * General speaking the addr type should be SI_ADDR_TYPE. And
0064      * the addr channel should be BMC.
0065      * In fact it can also be IPMB type. But we will have to
0066      * parse it from the Netfn command buffer. It is so complex
0067      * that it is skipped.
0068      */
0069     struct ipmi_addr addr;
0070     long tx_msgid;
0071 
0072     /* it is used to track whether the IPMI message is finished */
0073     struct completion tx_complete;
0074 
0075     struct kernel_ipmi_msg tx_message;
0076     int msg_done;
0077 
0078     /* tx/rx data . And copy it from/to ACPI object buffer */
0079     u8 data[ACPI_IPMI_MAX_MSG_LENGTH];
0080     u8 rx_len;
0081 
0082     struct acpi_ipmi_device *device;
0083     struct kref kref;
0084 };
0085 
0086 /* IPMI request/response buffer per ACPI 4.0, sec 5.5.2.4.3.2 */
0087 struct acpi_ipmi_buffer {
0088     u8 status;
0089     u8 length;
0090     u8 data[ACPI_IPMI_MAX_MSG_LENGTH];
0091 };
0092 
0093 static void ipmi_register_bmc(int iface, struct device *dev);
0094 static void ipmi_bmc_gone(int iface);
0095 static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data);
0096 
0097 static struct ipmi_driver_data driver_data = {
0098     .ipmi_devices = LIST_HEAD_INIT(driver_data.ipmi_devices),
0099     .bmc_events = {
0100         .owner = THIS_MODULE,
0101         .new_smi = ipmi_register_bmc,
0102         .smi_gone = ipmi_bmc_gone,
0103     },
0104     .ipmi_hndlrs = {
0105         .ipmi_recv_hndl = ipmi_msg_handler,
0106     },
0107     .ipmi_lock = __MUTEX_INITIALIZER(driver_data.ipmi_lock)
0108 };
0109 
0110 static struct acpi_ipmi_device *
0111 ipmi_dev_alloc(int iface, struct device *dev, acpi_handle handle)
0112 {
0113     struct acpi_ipmi_device *ipmi_device;
0114     int err;
0115     struct ipmi_user *user;
0116 
0117     ipmi_device = kzalloc(sizeof(*ipmi_device), GFP_KERNEL);
0118     if (!ipmi_device)
0119         return NULL;
0120 
0121     kref_init(&ipmi_device->kref);
0122     INIT_LIST_HEAD(&ipmi_device->head);
0123     INIT_LIST_HEAD(&ipmi_device->tx_msg_list);
0124     spin_lock_init(&ipmi_device->tx_msg_lock);
0125     ipmi_device->handle = handle;
0126     ipmi_device->dev = get_device(dev);
0127     ipmi_device->ipmi_ifnum = iface;
0128 
0129     err = ipmi_create_user(iface, &driver_data.ipmi_hndlrs,
0130                    ipmi_device, &user);
0131     if (err) {
0132         put_device(dev);
0133         kfree(ipmi_device);
0134         return NULL;
0135     }
0136     ipmi_device->user_interface = user;
0137 
0138     return ipmi_device;
0139 }
0140 
0141 static void ipmi_dev_release(struct acpi_ipmi_device *ipmi_device)
0142 {
0143     ipmi_destroy_user(ipmi_device->user_interface);
0144     put_device(ipmi_device->dev);
0145     kfree(ipmi_device);
0146 }
0147 
0148 static void ipmi_dev_release_kref(struct kref *kref)
0149 {
0150     struct acpi_ipmi_device *ipmi =
0151         container_of(kref, struct acpi_ipmi_device, kref);
0152 
0153     ipmi_dev_release(ipmi);
0154 }
0155 
0156 static void __ipmi_dev_kill(struct acpi_ipmi_device *ipmi_device)
0157 {
0158     list_del(&ipmi_device->head);
0159     if (driver_data.selected_smi == ipmi_device)
0160         driver_data.selected_smi = NULL;
0161 
0162     /*
0163      * Always setting dead flag after deleting from the list or
0164      * list_for_each_entry() codes must get changed.
0165      */
0166     ipmi_device->dead = true;
0167 }
0168 
0169 static struct acpi_ipmi_device *acpi_ipmi_dev_get(void)
0170 {
0171     struct acpi_ipmi_device *ipmi_device = NULL;
0172 
0173     mutex_lock(&driver_data.ipmi_lock);
0174     if (driver_data.selected_smi) {
0175         ipmi_device = driver_data.selected_smi;
0176         kref_get(&ipmi_device->kref);
0177     }
0178     mutex_unlock(&driver_data.ipmi_lock);
0179 
0180     return ipmi_device;
0181 }
0182 
0183 static void acpi_ipmi_dev_put(struct acpi_ipmi_device *ipmi_device)
0184 {
0185     kref_put(&ipmi_device->kref, ipmi_dev_release_kref);
0186 }
0187 
0188 static struct acpi_ipmi_msg *ipmi_msg_alloc(void)
0189 {
0190     struct acpi_ipmi_device *ipmi;
0191     struct acpi_ipmi_msg *ipmi_msg;
0192 
0193     ipmi = acpi_ipmi_dev_get();
0194     if (!ipmi)
0195         return NULL;
0196 
0197     ipmi_msg = kzalloc(sizeof(struct acpi_ipmi_msg), GFP_KERNEL);
0198     if (!ipmi_msg) {
0199         acpi_ipmi_dev_put(ipmi);
0200         return NULL;
0201     }
0202 
0203     kref_init(&ipmi_msg->kref);
0204     init_completion(&ipmi_msg->tx_complete);
0205     INIT_LIST_HEAD(&ipmi_msg->head);
0206     ipmi_msg->device = ipmi;
0207     ipmi_msg->msg_done = ACPI_IPMI_UNKNOWN;
0208 
0209     return ipmi_msg;
0210 }
0211 
0212 static void ipmi_msg_release(struct acpi_ipmi_msg *tx_msg)
0213 {
0214     acpi_ipmi_dev_put(tx_msg->device);
0215     kfree(tx_msg);
0216 }
0217 
0218 static void ipmi_msg_release_kref(struct kref *kref)
0219 {
0220     struct acpi_ipmi_msg *tx_msg =
0221         container_of(kref, struct acpi_ipmi_msg, kref);
0222 
0223     ipmi_msg_release(tx_msg);
0224 }
0225 
0226 static struct acpi_ipmi_msg *acpi_ipmi_msg_get(struct acpi_ipmi_msg *tx_msg)
0227 {
0228     kref_get(&tx_msg->kref);
0229 
0230     return tx_msg;
0231 }
0232 
0233 static void acpi_ipmi_msg_put(struct acpi_ipmi_msg *tx_msg)
0234 {
0235     kref_put(&tx_msg->kref, ipmi_msg_release_kref);
0236 }
0237 
0238 #define IPMI_OP_RGN_NETFN(offset)   ((offset >> 8) & 0xff)
0239 #define IPMI_OP_RGN_CMD(offset)     (offset & 0xff)
0240 static int acpi_format_ipmi_request(struct acpi_ipmi_msg *tx_msg,
0241                     acpi_physical_address address,
0242                     acpi_integer *value)
0243 {
0244     struct kernel_ipmi_msg *msg;
0245     struct acpi_ipmi_buffer *buffer;
0246     struct acpi_ipmi_device *device;
0247     unsigned long flags;
0248 
0249     msg = &tx_msg->tx_message;
0250 
0251     /*
0252      * IPMI network function and command are encoded in the address
0253      * within the IPMI OpRegion; see ACPI 4.0, sec 5.5.2.4.3.
0254      */
0255     msg->netfn = IPMI_OP_RGN_NETFN(address);
0256     msg->cmd = IPMI_OP_RGN_CMD(address);
0257     msg->data = tx_msg->data;
0258 
0259     /*
0260      * value is the parameter passed by the IPMI opregion space handler.
0261      * It points to the IPMI request message buffer
0262      */
0263     buffer = (struct acpi_ipmi_buffer *)value;
0264 
0265     /* copy the tx message data */
0266     if (buffer->length > ACPI_IPMI_MAX_MSG_LENGTH) {
0267         dev_WARN_ONCE(tx_msg->device->dev, true,
0268                   "Unexpected request (msg len %d).\n",
0269                   buffer->length);
0270         return -EINVAL;
0271     }
0272     msg->data_len = buffer->length;
0273     memcpy(tx_msg->data, buffer->data, msg->data_len);
0274 
0275     /*
0276      * now the default type is SYSTEM_INTERFACE and channel type is BMC.
0277      * If the netfn is APP_REQUEST and the cmd is SEND_MESSAGE,
0278      * the addr type should be changed to IPMB. Then we will have to parse
0279      * the IPMI request message buffer to get the IPMB address.
0280      * If so, please fix me.
0281      */
0282     tx_msg->addr.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
0283     tx_msg->addr.channel = IPMI_BMC_CHANNEL;
0284     tx_msg->addr.data[0] = 0;
0285 
0286     /* Get the msgid */
0287     device = tx_msg->device;
0288 
0289     spin_lock_irqsave(&device->tx_msg_lock, flags);
0290     device->curr_msgid++;
0291     tx_msg->tx_msgid = device->curr_msgid;
0292     spin_unlock_irqrestore(&device->tx_msg_lock, flags);
0293 
0294     return 0;
0295 }
0296 
0297 static void acpi_format_ipmi_response(struct acpi_ipmi_msg *msg,
0298                       acpi_integer *value)
0299 {
0300     struct acpi_ipmi_buffer *buffer;
0301 
0302     /*
0303      * value is also used as output parameter. It represents the response
0304      * IPMI message returned by IPMI command.
0305      */
0306     buffer = (struct acpi_ipmi_buffer *)value;
0307 
0308     /*
0309      * If the flag of msg_done is not set, it means that the IPMI command is
0310      * not executed correctly.
0311      */
0312     buffer->status = msg->msg_done;
0313     if (msg->msg_done != ACPI_IPMI_OK)
0314         return;
0315 
0316     /*
0317      * If the IPMI response message is obtained correctly, the status code
0318      * will be ACPI_IPMI_OK
0319      */
0320     buffer->length = msg->rx_len;
0321     memcpy(buffer->data, msg->data, msg->rx_len);
0322 }
0323 
0324 static void ipmi_flush_tx_msg(struct acpi_ipmi_device *ipmi)
0325 {
0326     struct acpi_ipmi_msg *tx_msg;
0327     unsigned long flags;
0328 
0329     /*
0330      * NOTE: On-going ipmi_recv_msg
0331      * ipmi_msg_handler() may still be invoked by ipmi_si after
0332      * flushing.  But it is safe to do a fast flushing on module_exit()
0333      * without waiting for all ipmi_recv_msg(s) to complete from
0334      * ipmi_msg_handler() as it is ensured by ipmi_si that all
0335      * ipmi_recv_msg(s) are freed after invoking ipmi_destroy_user().
0336      */
0337     spin_lock_irqsave(&ipmi->tx_msg_lock, flags);
0338     while (!list_empty(&ipmi->tx_msg_list)) {
0339         tx_msg = list_first_entry(&ipmi->tx_msg_list,
0340                       struct acpi_ipmi_msg,
0341                       head);
0342         list_del(&tx_msg->head);
0343         spin_unlock_irqrestore(&ipmi->tx_msg_lock, flags);
0344 
0345         /* wake up the sleep thread on the Tx msg */
0346         complete(&tx_msg->tx_complete);
0347         acpi_ipmi_msg_put(tx_msg);
0348         spin_lock_irqsave(&ipmi->tx_msg_lock, flags);
0349     }
0350     spin_unlock_irqrestore(&ipmi->tx_msg_lock, flags);
0351 }
0352 
0353 static void ipmi_cancel_tx_msg(struct acpi_ipmi_device *ipmi,
0354                    struct acpi_ipmi_msg *msg)
0355 {
0356     struct acpi_ipmi_msg *tx_msg = NULL, *iter, *temp;
0357     unsigned long flags;
0358 
0359     spin_lock_irqsave(&ipmi->tx_msg_lock, flags);
0360     list_for_each_entry_safe(iter, temp, &ipmi->tx_msg_list, head) {
0361         if (msg == iter) {
0362             tx_msg = iter;
0363             list_del(&iter->head);
0364             break;
0365         }
0366     }
0367     spin_unlock_irqrestore(&ipmi->tx_msg_lock, flags);
0368 
0369     if (tx_msg)
0370         acpi_ipmi_msg_put(tx_msg);
0371 }
0372 
0373 static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data)
0374 {
0375     struct acpi_ipmi_device *ipmi_device = user_msg_data;
0376     struct acpi_ipmi_msg *tx_msg = NULL, *iter, *temp;
0377     struct device *dev = ipmi_device->dev;
0378     unsigned long flags;
0379 
0380     if (msg->user != ipmi_device->user_interface) {
0381         dev_warn(dev,
0382              "Unexpected response is returned. returned user %p, expected user %p\n",
0383              msg->user, ipmi_device->user_interface);
0384         goto out_msg;
0385     }
0386 
0387     spin_lock_irqsave(&ipmi_device->tx_msg_lock, flags);
0388     list_for_each_entry_safe(iter, temp, &ipmi_device->tx_msg_list, head) {
0389         if (msg->msgid == iter->tx_msgid) {
0390             tx_msg = iter;
0391             list_del(&iter->head);
0392             break;
0393         }
0394     }
0395     spin_unlock_irqrestore(&ipmi_device->tx_msg_lock, flags);
0396 
0397     if (!tx_msg) {
0398         dev_warn(dev,
0399              "Unexpected response (msg id %ld) is returned.\n",
0400              msg->msgid);
0401         goto out_msg;
0402     }
0403 
0404     /* copy the response data to Rx_data buffer */
0405     if (msg->msg.data_len > ACPI_IPMI_MAX_MSG_LENGTH) {
0406         dev_WARN_ONCE(dev, true,
0407                   "Unexpected response (msg len %d).\n",
0408                   msg->msg.data_len);
0409         goto out_comp;
0410     }
0411 
0412     /* response msg is an error msg */
0413     msg->recv_type = IPMI_RESPONSE_RECV_TYPE;
0414     if (msg->recv_type == IPMI_RESPONSE_RECV_TYPE &&
0415         msg->msg.data_len == 1) {
0416         if (msg->msg.data[0] == IPMI_TIMEOUT_COMPLETION_CODE) {
0417             dev_dbg_once(dev, "Unexpected response (timeout).\n");
0418             tx_msg->msg_done = ACPI_IPMI_TIMEOUT;
0419         }
0420         goto out_comp;
0421     }
0422 
0423     tx_msg->rx_len = msg->msg.data_len;
0424     memcpy(tx_msg->data, msg->msg.data, tx_msg->rx_len);
0425     tx_msg->msg_done = ACPI_IPMI_OK;
0426 
0427 out_comp:
0428     complete(&tx_msg->tx_complete);
0429     acpi_ipmi_msg_put(tx_msg);
0430 out_msg:
0431     ipmi_free_recv_msg(msg);
0432 }
0433 
0434 static void ipmi_register_bmc(int iface, struct device *dev)
0435 {
0436     struct acpi_ipmi_device *ipmi_device, *temp;
0437     int err;
0438     struct ipmi_smi_info smi_data;
0439     acpi_handle handle;
0440 
0441     err = ipmi_get_smi_info(iface, &smi_data);
0442     if (err)
0443         return;
0444 
0445     if (smi_data.addr_src != SI_ACPI)
0446         goto err_ref;
0447     handle = smi_data.addr_info.acpi_info.acpi_handle;
0448     if (!handle)
0449         goto err_ref;
0450 
0451     ipmi_device = ipmi_dev_alloc(iface, smi_data.dev, handle);
0452     if (!ipmi_device) {
0453         dev_warn(smi_data.dev, "Can't create IPMI user interface\n");
0454         goto err_ref;
0455     }
0456 
0457     mutex_lock(&driver_data.ipmi_lock);
0458     list_for_each_entry(temp, &driver_data.ipmi_devices, head) {
0459         /*
0460          * if the corresponding ACPI handle is already added
0461          * to the device list, don't add it again.
0462          */
0463         if (temp->handle == handle)
0464             goto err_lock;
0465     }
0466     if (!driver_data.selected_smi)
0467         driver_data.selected_smi = ipmi_device;
0468     list_add_tail(&ipmi_device->head, &driver_data.ipmi_devices);
0469     mutex_unlock(&driver_data.ipmi_lock);
0470 
0471     put_device(smi_data.dev);
0472     return;
0473 
0474 err_lock:
0475     mutex_unlock(&driver_data.ipmi_lock);
0476     ipmi_dev_release(ipmi_device);
0477 err_ref:
0478     put_device(smi_data.dev);
0479 }
0480 
0481 static void ipmi_bmc_gone(int iface)
0482 {
0483     struct acpi_ipmi_device *ipmi_device = NULL, *iter, *temp;
0484 
0485     mutex_lock(&driver_data.ipmi_lock);
0486     list_for_each_entry_safe(iter, temp,
0487                  &driver_data.ipmi_devices, head) {
0488         if (iter->ipmi_ifnum != iface) {
0489             ipmi_device = iter;
0490             __ipmi_dev_kill(iter);
0491             break;
0492         }
0493     }
0494     if (!driver_data.selected_smi)
0495         driver_data.selected_smi = list_first_entry_or_null(
0496                     &driver_data.ipmi_devices,
0497                     struct acpi_ipmi_device, head);
0498     mutex_unlock(&driver_data.ipmi_lock);
0499 
0500     if (ipmi_device) {
0501         ipmi_flush_tx_msg(ipmi_device);
0502         acpi_ipmi_dev_put(ipmi_device);
0503     }
0504 }
0505 
0506 /*
0507  * This is the IPMI opregion space handler.
0508  * @function: indicates the read/write. In fact as the IPMI message is driven
0509  * by command, only write is meaningful.
0510  * @address: This contains the netfn/command of IPMI request message.
0511  * @bits   : not used.
0512  * @value  : it is an in/out parameter. It points to the IPMI message buffer.
0513  *       Before the IPMI message is sent, it represents the actual request
0514  *       IPMI message. After the IPMI message is finished, it represents
0515  *       the response IPMI message returned by IPMI command.
0516  * @handler_context: IPMI device context.
0517  */
0518 static acpi_status
0519 acpi_ipmi_space_handler(u32 function, acpi_physical_address address,
0520             u32 bits, acpi_integer *value,
0521             void *handler_context, void *region_context)
0522 {
0523     struct acpi_ipmi_msg *tx_msg;
0524     struct acpi_ipmi_device *ipmi_device;
0525     int err;
0526     acpi_status status;
0527     unsigned long flags;
0528 
0529     /*
0530      * IPMI opregion message.
0531      * IPMI message is firstly written to the BMC and system software
0532      * can get the respsonse. So it is unmeaningful for the read access
0533      * of IPMI opregion.
0534      */
0535     if ((function & ACPI_IO_MASK) == ACPI_READ)
0536         return AE_TYPE;
0537 
0538     tx_msg = ipmi_msg_alloc();
0539     if (!tx_msg)
0540         return AE_NOT_EXIST;
0541     ipmi_device = tx_msg->device;
0542 
0543     if (acpi_format_ipmi_request(tx_msg, address, value) != 0) {
0544         ipmi_msg_release(tx_msg);
0545         return AE_TYPE;
0546     }
0547 
0548     acpi_ipmi_msg_get(tx_msg);
0549     mutex_lock(&driver_data.ipmi_lock);
0550     /* Do not add a tx_msg that can not be flushed. */
0551     if (ipmi_device->dead) {
0552         mutex_unlock(&driver_data.ipmi_lock);
0553         ipmi_msg_release(tx_msg);
0554         return AE_NOT_EXIST;
0555     }
0556     spin_lock_irqsave(&ipmi_device->tx_msg_lock, flags);
0557     list_add_tail(&tx_msg->head, &ipmi_device->tx_msg_list);
0558     spin_unlock_irqrestore(&ipmi_device->tx_msg_lock, flags);
0559     mutex_unlock(&driver_data.ipmi_lock);
0560 
0561     err = ipmi_request_settime(ipmi_device->user_interface,
0562                    &tx_msg->addr,
0563                    tx_msg->tx_msgid,
0564                    &tx_msg->tx_message,
0565                    NULL, 0, 0, IPMI_TIMEOUT);
0566     if (err) {
0567         status = AE_ERROR;
0568         goto out_msg;
0569     }
0570     wait_for_completion(&tx_msg->tx_complete);
0571 
0572     acpi_format_ipmi_response(tx_msg, value);
0573     status = AE_OK;
0574 
0575 out_msg:
0576     ipmi_cancel_tx_msg(ipmi_device, tx_msg);
0577     acpi_ipmi_msg_put(tx_msg);
0578     return status;
0579 }
0580 
0581 static int __init acpi_ipmi_init(void)
0582 {
0583     int result;
0584     acpi_status status;
0585 
0586     if (acpi_disabled)
0587         return 0;
0588 
0589     status = acpi_install_address_space_handler(ACPI_ROOT_OBJECT,
0590                             ACPI_ADR_SPACE_IPMI,
0591                             &acpi_ipmi_space_handler,
0592                             NULL, NULL);
0593     if (ACPI_FAILURE(status)) {
0594         pr_warn("Can't register IPMI opregion space handle\n");
0595         return -EINVAL;
0596     }
0597 
0598     result = ipmi_smi_watcher_register(&driver_data.bmc_events);
0599     if (result) {
0600         acpi_remove_address_space_handler(ACPI_ROOT_OBJECT,
0601                                           ACPI_ADR_SPACE_IPMI,
0602                                           &acpi_ipmi_space_handler);
0603         pr_err("Can't register IPMI system interface watcher\n");
0604     }
0605 
0606     return result;
0607 }
0608 
0609 static void __exit acpi_ipmi_exit(void)
0610 {
0611     struct acpi_ipmi_device *ipmi_device;
0612 
0613     if (acpi_disabled)
0614         return;
0615 
0616     ipmi_smi_watcher_unregister(&driver_data.bmc_events);
0617 
0618     /*
0619      * When one smi_watcher is unregistered, it is only deleted
0620      * from the smi_watcher list. But the smi_gone callback function
0621      * is not called. So explicitly uninstall the ACPI IPMI oregion
0622      * handler and free it.
0623      */
0624     mutex_lock(&driver_data.ipmi_lock);
0625     while (!list_empty(&driver_data.ipmi_devices)) {
0626         ipmi_device = list_first_entry(&driver_data.ipmi_devices,
0627                            struct acpi_ipmi_device,
0628                            head);
0629         __ipmi_dev_kill(ipmi_device);
0630         mutex_unlock(&driver_data.ipmi_lock);
0631 
0632         ipmi_flush_tx_msg(ipmi_device);
0633         acpi_ipmi_dev_put(ipmi_device);
0634 
0635         mutex_lock(&driver_data.ipmi_lock);
0636     }
0637     mutex_unlock(&driver_data.ipmi_lock);
0638     acpi_remove_address_space_handler(ACPI_ROOT_OBJECT,
0639                       ACPI_ADR_SPACE_IPMI,
0640                       &acpi_ipmi_space_handler);
0641 }
0642 
0643 module_init(acpi_ipmi_init);
0644 module_exit(acpi_ipmi_exit);