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