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