aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/IPMI.txt27
-rw-r--r--drivers/acpi/Kconfig11
-rw-r--r--drivers/acpi/Makefile1
-rw-r--r--drivers/acpi/acpi_ipmi.c525
-rw-r--r--drivers/char/ipmi/ipmi_msghandler.c27
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c20
-rw-r--r--include/linux/ipmi.h38
-rw-r--r--include/linux/ipmi_smi.h8
8 files changed, 653 insertions, 4 deletions
diff --git a/Documentation/IPMI.txt b/Documentation/IPMI.txt
index 69dd29ed824e..b2bea15137d2 100644
--- a/Documentation/IPMI.txt
+++ b/Documentation/IPMI.txt
@@ -533,6 +533,33 @@ completion during sending a panic event.
533Other Pieces 533Other Pieces
534------------ 534------------
535 535
536Get the detailed info related with the IPMI device
537--------------------------------------------------
538
539Some users need more detailed information about a device, like where
540the address came from or the raw base device for the IPMI interface.
541You can use the IPMI smi_watcher to catch the IPMI interfaces as they
542come or go, and to grab the information, you can use the function
543ipmi_get_smi_info(), which returns the following structure:
544
545struct ipmi_smi_info {
546 enum ipmi_addr_src addr_src;
547 struct device *dev;
548 union {
549 struct {
550 void *acpi_handle;
551 } acpi_info;
552 } addr_info;
553};
554
555Currently special info for only for SI_ACPI address sources is
556returned. Others may be added as necessary.
557
558Note that the dev pointer is included in the above structure, and
559assuming ipmi_smi_get_info returns success, you must call put_device
560on the dev pointer.
561
562
536Watchdog 563Watchdog
537-------- 564--------
538 565
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index 788e88eb18ec..865fcb3c4807 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -207,6 +207,17 @@ config ACPI_PROCESSOR
207 207
208 To compile this driver as a module, choose M here: 208 To compile this driver as a module, choose M here:
209 the module will be called processor. 209 the module will be called processor.
210config ACPI_IPMI
211 tristate "IPMI"
212 depends on EXPERIMENTAL && IPMI_SI && IPMI_HANDLER
213 default n
214 help
215 This driver enables the ACPI to access the BMC controller. And it
216 uses the IPMI request/response message to communicate with BMC
217 controller, which can be found on on the server.
218
219 To compile this driver as a module, choose M here:
220 the module will be called as acpi_ipmi.
210 221
211config ACPI_HOTPLUG_CPU 222config ACPI_HOTPLUG_CPU
212 bool 223 bool
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 9cc9f2c4da79..d113fa5100b2 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -69,5 +69,6 @@ processor-y += processor_idle.o processor_thermal.o
69processor-$(CONFIG_CPU_FREQ) += processor_perflib.o 69processor-$(CONFIG_CPU_FREQ) += processor_perflib.o
70 70
71obj-$(CONFIG_ACPI_PROCESSOR_AGGREGATOR) += acpi_pad.o 71obj-$(CONFIG_ACPI_PROCESSOR_AGGREGATOR) += acpi_pad.o
72obj-$(CONFIG_ACPI_IPMI) += acpi_ipmi.o
72 73
73obj-$(CONFIG_ACPI_APEI) += apei/ 74obj-$(CONFIG_ACPI_APEI) += apei/
diff --git a/drivers/acpi/acpi_ipmi.c b/drivers/acpi/acpi_ipmi.c
new file mode 100644
index 000000000000..f40acef80269
--- /dev/null
+++ b/drivers/acpi/acpi_ipmi.c
@@ -0,0 +1,525 @@
1/*
2 * acpi_ipmi.c - ACPI IPMI opregion
3 *
4 * Copyright (C) 2010 Intel Corporation
5 * Copyright (C) 2010 Zhao Yakui <yakui.zhao@intel.com>
6 *
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or (at
12 * your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 *
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24 */
25
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/init.h>
29#include <linux/types.h>
30#include <linux/delay.h>
31#include <linux/proc_fs.h>
32#include <linux/seq_file.h>
33#include <linux/interrupt.h>
34#include <linux/list.h>
35#include <linux/spinlock.h>
36#include <linux/io.h>
37#include <acpi/acpi_bus.h>
38#include <acpi/acpi_drivers.h>
39#include <linux/ipmi.h>
40#include <linux/device.h>
41#include <linux/pnp.h>
42
43MODULE_AUTHOR("Zhao Yakui");
44MODULE_DESCRIPTION("ACPI IPMI Opregion driver");
45MODULE_LICENSE("GPL");
46
47#define IPMI_FLAGS_HANDLER_INSTALL 0
48
49#define ACPI_IPMI_OK 0
50#define ACPI_IPMI_TIMEOUT 0x10
51#define ACPI_IPMI_UNKNOWN 0x07
52/* the IPMI timeout is 5s */
53#define IPMI_TIMEOUT (5 * HZ)
54
55struct acpi_ipmi_device {
56 /* the device list attached to driver_data.ipmi_devices */
57 struct list_head head;
58 /* the IPMI request message list */
59 struct list_head tx_msg_list;
60 struct mutex tx_msg_lock;
61 acpi_handle handle;
62 struct pnp_dev *pnp_dev;
63 ipmi_user_t user_interface;
64 int ipmi_ifnum; /* IPMI interface number */
65 long curr_msgid;
66 unsigned long flags;
67 struct ipmi_smi_info smi_data;
68};
69
70struct ipmi_driver_data {
71 struct list_head ipmi_devices;
72 struct ipmi_smi_watcher bmc_events;
73 struct ipmi_user_hndl ipmi_hndlrs;
74 struct mutex ipmi_lock;
75};
76
77struct acpi_ipmi_msg {
78 struct list_head head;
79 /*
80 * General speaking the addr type should be SI_ADDR_TYPE. And
81 * the addr channel should be BMC.
82 * In fact it can also be IPMB type. But we will have to
83 * parse it from the Netfn command buffer. It is so complex
84 * that it is skipped.
85 */
86 struct ipmi_addr addr;
87 long tx_msgid;
88 /* it is used to track whether the IPMI message is finished */
89 struct completion tx_complete;
90 struct kernel_ipmi_msg tx_message;
91 int msg_done;
92 /* tx data . And copy it from ACPI object buffer */
93 u8 tx_data[64];
94 int tx_len;
95 u8 rx_data[64];
96 int rx_len;
97 struct acpi_ipmi_device *device;
98};
99
100/* IPMI request/response buffer per ACPI 4.0, sec 5.5.2.4.3.2 */
101struct acpi_ipmi_buffer {
102 u8 status;
103 u8 length;
104 u8 data[64];
105};
106
107static void ipmi_register_bmc(int iface, struct device *dev);
108static void ipmi_bmc_gone(int iface);
109static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data);
110static void acpi_add_ipmi_device(struct acpi_ipmi_device *ipmi_device);
111static void acpi_remove_ipmi_device(struct acpi_ipmi_device *ipmi_device);
112
113static struct ipmi_driver_data driver_data = {
114 .ipmi_devices = LIST_HEAD_INIT(driver_data.ipmi_devices),
115 .bmc_events = {
116 .owner = THIS_MODULE,
117 .new_smi = ipmi_register_bmc,
118 .smi_gone = ipmi_bmc_gone,
119 },
120 .ipmi_hndlrs = {
121 .ipmi_recv_hndl = ipmi_msg_handler,
122 },
123};
124
125static struct acpi_ipmi_msg *acpi_alloc_ipmi_msg(struct acpi_ipmi_device *ipmi)
126{
127 struct acpi_ipmi_msg *ipmi_msg;
128 struct pnp_dev *pnp_dev = ipmi->pnp_dev;
129
130 ipmi_msg = kzalloc(sizeof(struct acpi_ipmi_msg), GFP_KERNEL);
131 if (!ipmi_msg) {
132 dev_warn(&pnp_dev->dev, "Can't allocate memory for ipmi_msg\n");
133 return NULL;
134 }
135 init_completion(&ipmi_msg->tx_complete);
136 INIT_LIST_HEAD(&ipmi_msg->head);
137 ipmi_msg->device = ipmi;
138 return ipmi_msg;
139}
140
141#define IPMI_OP_RGN_NETFN(offset) ((offset >> 8) & 0xff)
142#define IPMI_OP_RGN_CMD(offset) (offset & 0xff)
143static void acpi_format_ipmi_msg(struct acpi_ipmi_msg *tx_msg,
144 acpi_physical_address address,
145 acpi_integer *value)
146{
147 struct kernel_ipmi_msg *msg;
148 struct acpi_ipmi_buffer *buffer;
149 struct acpi_ipmi_device *device;
150
151 msg = &tx_msg->tx_message;
152 /*
153 * IPMI network function and command are encoded in the address
154 * within the IPMI OpRegion; see ACPI 4.0, sec 5.5.2.4.3.
155 */
156 msg->netfn = IPMI_OP_RGN_NETFN(address);
157 msg->cmd = IPMI_OP_RGN_CMD(address);
158 msg->data = tx_msg->tx_data;
159 /*
160 * value is the parameter passed by the IPMI opregion space handler.
161 * It points to the IPMI request message buffer
162 */
163 buffer = (struct acpi_ipmi_buffer *)value;
164 /* copy the tx message data */
165 msg->data_len = buffer->length;
166 memcpy(tx_msg->tx_data, buffer->data, msg->data_len);
167 /*
168 * now the default type is SYSTEM_INTERFACE and channel type is BMC.
169 * If the netfn is APP_REQUEST and the cmd is SEND_MESSAGE,
170 * the addr type should be changed to IPMB. Then we will have to parse
171 * the IPMI request message buffer to get the IPMB address.
172 * If so, please fix me.
173 */
174 tx_msg->addr.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
175 tx_msg->addr.channel = IPMI_BMC_CHANNEL;
176 tx_msg->addr.data[0] = 0;
177
178 /* Get the msgid */
179 device = tx_msg->device;
180 mutex_lock(&device->tx_msg_lock);
181 device->curr_msgid++;
182 tx_msg->tx_msgid = device->curr_msgid;
183 mutex_unlock(&device->tx_msg_lock);
184}
185
186static void acpi_format_ipmi_response(struct acpi_ipmi_msg *msg,
187 acpi_integer *value, int rem_time)
188{
189 struct acpi_ipmi_buffer *buffer;
190
191 /*
192 * value is also used as output parameter. It represents the response
193 * IPMI message returned by IPMI command.
194 */
195 buffer = (struct acpi_ipmi_buffer *)value;
196 if (!rem_time && !msg->msg_done) {
197 buffer->status = ACPI_IPMI_TIMEOUT;
198 return;
199 }
200 /*
201 * If the flag of msg_done is not set or the recv length is zero, it
202 * means that the IPMI command is not executed correctly.
203 * The status code will be ACPI_IPMI_UNKNOWN.
204 */
205 if (!msg->msg_done || !msg->rx_len) {
206 buffer->status = ACPI_IPMI_UNKNOWN;
207 return;
208 }
209 /*
210 * If the IPMI response message is obtained correctly, the status code
211 * will be ACPI_IPMI_OK
212 */
213 buffer->status = ACPI_IPMI_OK;
214 buffer->length = msg->rx_len;
215 memcpy(buffer->data, msg->rx_data, msg->rx_len);
216}
217
218static void ipmi_flush_tx_msg(struct acpi_ipmi_device *ipmi)
219{
220 struct acpi_ipmi_msg *tx_msg, *temp;
221 int count = HZ / 10;
222 struct pnp_dev *pnp_dev = ipmi->pnp_dev;
223
224 list_for_each_entry_safe(tx_msg, temp, &ipmi->tx_msg_list, head) {
225 /* wake up the sleep thread on the Tx msg */
226 complete(&tx_msg->tx_complete);
227 }
228
229 /* wait for about 100ms to flush the tx message list */
230 while (count--) {
231 if (list_empty(&ipmi->tx_msg_list))
232 break;
233 schedule_timeout(1);
234 }
235 if (!list_empty(&ipmi->tx_msg_list))
236 dev_warn(&pnp_dev->dev, "tx msg list is not NULL\n");
237}
238
239static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data)
240{
241 struct acpi_ipmi_device *ipmi_device = user_msg_data;
242 int msg_found = 0;
243 struct acpi_ipmi_msg *tx_msg;
244 struct pnp_dev *pnp_dev = ipmi_device->pnp_dev;
245
246 if (msg->user != ipmi_device->user_interface) {
247 dev_warn(&pnp_dev->dev, "Unexpected response is returned. "
248 "returned user %p, expected user %p\n",
249 msg->user, ipmi_device->user_interface);
250 ipmi_free_recv_msg(msg);
251 return;
252 }
253 mutex_lock(&ipmi_device->tx_msg_lock);
254 list_for_each_entry(tx_msg, &ipmi_device->tx_msg_list, head) {
255 if (msg->msgid == tx_msg->tx_msgid) {
256 msg_found = 1;
257 break;
258 }
259 }
260
261 mutex_unlock(&ipmi_device->tx_msg_lock);
262 if (!msg_found) {
263 dev_warn(&pnp_dev->dev, "Unexpected response (msg id %ld) is "
264 "returned.\n", msg->msgid);
265 ipmi_free_recv_msg(msg);
266 return;
267 }
268
269 if (msg->msg.data_len) {
270 /* copy the response data to Rx_data buffer */
271 memcpy(tx_msg->rx_data, msg->msg_data, msg->msg.data_len);
272 tx_msg->rx_len = msg->msg.data_len;
273 tx_msg->msg_done = 1;
274 }
275 complete(&tx_msg->tx_complete);
276 ipmi_free_recv_msg(msg);
277};
278
279static void ipmi_register_bmc(int iface, struct device *dev)
280{
281 struct acpi_ipmi_device *ipmi_device, *temp;
282 struct pnp_dev *pnp_dev;
283 ipmi_user_t user;
284 int err;
285 struct ipmi_smi_info smi_data;
286 acpi_handle handle;
287
288 err = ipmi_get_smi_info(iface, &smi_data);
289
290 if (err)
291 return;
292
293 if (smi_data.addr_src != SI_ACPI) {
294 put_device(smi_data.dev);
295 return;
296 }
297
298 handle = smi_data.addr_info.acpi_info.acpi_handle;
299
300 mutex_lock(&driver_data.ipmi_lock);
301 list_for_each_entry(temp, &driver_data.ipmi_devices, head) {
302 /*
303 * if the corresponding ACPI handle is already added
304 * to the device list, don't add it again.
305 */
306 if (temp->handle == handle)
307 goto out;
308 }
309
310 ipmi_device = kzalloc(sizeof(*ipmi_device), GFP_KERNEL);
311
312 if (!ipmi_device)
313 goto out;
314
315 pnp_dev = to_pnp_dev(smi_data.dev);
316 ipmi_device->handle = handle;
317 ipmi_device->pnp_dev = pnp_dev;
318
319 err = ipmi_create_user(iface, &driver_data.ipmi_hndlrs,
320 ipmi_device, &user);
321 if (err) {
322 dev_warn(&pnp_dev->dev, "Can't create IPMI user interface\n");
323 kfree(ipmi_device);
324 goto out;
325 }
326 acpi_add_ipmi_device(ipmi_device);
327 ipmi_device->user_interface = user;
328 ipmi_device->ipmi_ifnum = iface;
329 mutex_unlock(&driver_data.ipmi_lock);
330 memcpy(&ipmi_device->smi_data, &smi_data, sizeof(struct ipmi_smi_info));
331 return;
332
333out:
334 mutex_unlock(&driver_data.ipmi_lock);
335 put_device(smi_data.dev);
336 return;
337}
338
339static void ipmi_bmc_gone(int iface)
340{
341 struct acpi_ipmi_device *ipmi_device, *temp;
342
343 mutex_lock(&driver_data.ipmi_lock);
344 list_for_each_entry_safe(ipmi_device, temp,
345 &driver_data.ipmi_devices, head) {
346 if (ipmi_device->ipmi_ifnum != iface)
347 continue;
348
349 acpi_remove_ipmi_device(ipmi_device);
350 put_device(ipmi_device->smi_data.dev);
351 kfree(ipmi_device);
352 break;
353 }
354 mutex_unlock(&driver_data.ipmi_lock);
355}
356/* --------------------------------------------------------------------------
357 * Address Space Management
358 * -------------------------------------------------------------------------- */
359/*
360 * This is the IPMI opregion space handler.
361 * @function: indicates the read/write. In fact as the IPMI message is driven
362 * by command, only write is meaningful.
363 * @address: This contains the netfn/command of IPMI request message.
364 * @bits : not used.
365 * @value : it is an in/out parameter. It points to the IPMI message buffer.
366 * Before the IPMI message is sent, it represents the actual request
367 * IPMI message. After the IPMI message is finished, it represents
368 * the response IPMI message returned by IPMI command.
369 * @handler_context: IPMI device context.
370 */
371
372static acpi_status
373acpi_ipmi_space_handler(u32 function, acpi_physical_address address,
374 u32 bits, acpi_integer *value,
375 void *handler_context, void *region_context)
376{
377 struct acpi_ipmi_msg *tx_msg;
378 struct acpi_ipmi_device *ipmi_device = handler_context;
379 int err, rem_time;
380 acpi_status status;
381 /*
382 * IPMI opregion message.
383 * IPMI message is firstly written to the BMC and system software
384 * can get the respsonse. So it is unmeaningful for the read access
385 * of IPMI opregion.
386 */
387 if ((function & ACPI_IO_MASK) == ACPI_READ)
388 return AE_TYPE;
389
390 if (!ipmi_device->user_interface)
391 return AE_NOT_EXIST;
392
393 tx_msg = acpi_alloc_ipmi_msg(ipmi_device);
394 if (!tx_msg)
395 return AE_NO_MEMORY;
396
397 acpi_format_ipmi_msg(tx_msg, address, value);
398 mutex_lock(&ipmi_device->tx_msg_lock);
399 list_add_tail(&tx_msg->head, &ipmi_device->tx_msg_list);
400 mutex_unlock(&ipmi_device->tx_msg_lock);
401 err = ipmi_request_settime(ipmi_device->user_interface,
402 &tx_msg->addr,
403 tx_msg->tx_msgid,
404 &tx_msg->tx_message,
405 NULL, 0, 0, 0);
406 if (err) {
407 status = AE_ERROR;
408 goto end_label;
409 }
410 rem_time = wait_for_completion_timeout(&tx_msg->tx_complete,
411 IPMI_TIMEOUT);
412 acpi_format_ipmi_response(tx_msg, value, rem_time);
413 status = AE_OK;
414
415end_label:
416 mutex_lock(&ipmi_device->tx_msg_lock);
417 list_del(&tx_msg->head);
418 mutex_unlock(&ipmi_device->tx_msg_lock);
419 kfree(tx_msg);
420 return status;
421}
422
423static void ipmi_remove_space_handler(struct acpi_ipmi_device *ipmi)
424{
425 if (!test_bit(IPMI_FLAGS_HANDLER_INSTALL, &ipmi->flags))
426 return;
427
428 acpi_remove_address_space_handler(ipmi->handle,
429 ACPI_ADR_SPACE_IPMI, &acpi_ipmi_space_handler);
430
431 clear_bit(IPMI_FLAGS_HANDLER_INSTALL, &ipmi->flags);
432}
433
434static int ipmi_install_space_handler(struct acpi_ipmi_device *ipmi)
435{
436 acpi_status status;
437
438 if (test_bit(IPMI_FLAGS_HANDLER_INSTALL, &ipmi->flags))
439 return 0;
440
441 status = acpi_install_address_space_handler(ipmi->handle,
442 ACPI_ADR_SPACE_IPMI,
443 &acpi_ipmi_space_handler,
444 NULL, ipmi);
445 if (ACPI_FAILURE(status)) {
446 struct pnp_dev *pnp_dev = ipmi->pnp_dev;
447 dev_warn(&pnp_dev->dev, "Can't register IPMI opregion space "
448 "handle\n");
449 return -EINVAL;
450 }
451 set_bit(IPMI_FLAGS_HANDLER_INSTALL, &ipmi->flags);
452 return 0;
453}
454
455static void acpi_add_ipmi_device(struct acpi_ipmi_device *ipmi_device)
456{
457
458 INIT_LIST_HEAD(&ipmi_device->head);
459
460 mutex_init(&ipmi_device->tx_msg_lock);
461 INIT_LIST_HEAD(&ipmi_device->tx_msg_list);
462 ipmi_install_space_handler(ipmi_device);
463
464 list_add_tail(&ipmi_device->head, &driver_data.ipmi_devices);
465}
466
467static void acpi_remove_ipmi_device(struct acpi_ipmi_device *ipmi_device)
468{
469 /*
470 * If the IPMI user interface is created, it should be
471 * destroyed.
472 */
473 if (ipmi_device->user_interface) {
474 ipmi_destroy_user(ipmi_device->user_interface);
475 ipmi_device->user_interface = NULL;
476 }
477 /* flush the Tx_msg list */
478 if (!list_empty(&ipmi_device->tx_msg_list))
479 ipmi_flush_tx_msg(ipmi_device);
480
481 list_del(&ipmi_device->head);
482 ipmi_remove_space_handler(ipmi_device);
483}
484
485static int __init acpi_ipmi_init(void)
486{
487 int result = 0;
488
489 if (acpi_disabled)
490 return result;
491
492 mutex_init(&driver_data.ipmi_lock);
493
494 result = ipmi_smi_watcher_register(&driver_data.bmc_events);
495
496 return result;
497}
498
499static void __exit acpi_ipmi_exit(void)
500{
501 struct acpi_ipmi_device *ipmi_device, *temp;
502
503 if (acpi_disabled)
504 return;
505
506 ipmi_smi_watcher_unregister(&driver_data.bmc_events);
507
508 /*
509 * When one smi_watcher is unregistered, it is only deleted
510 * from the smi_watcher list. But the smi_gone callback function
511 * is not called. So explicitly uninstall the ACPI IPMI oregion
512 * handler and free it.
513 */
514 mutex_lock(&driver_data.ipmi_lock);
515 list_for_each_entry_safe(ipmi_device, temp,
516 &driver_data.ipmi_devices, head) {
517 acpi_remove_ipmi_device(ipmi_device);
518 put_device(ipmi_device->smi_data.dev);
519 kfree(ipmi_device);
520 }
521 mutex_unlock(&driver_data.ipmi_lock);
522}
523
524module_init(acpi_ipmi_init);
525module_exit(acpi_ipmi_exit);
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 2fe72f8edf44..38223e93aa98 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -970,6 +970,33 @@ out_kfree:
970} 970}
971EXPORT_SYMBOL(ipmi_create_user); 971EXPORT_SYMBOL(ipmi_create_user);
972 972
973int ipmi_get_smi_info(int if_num, struct ipmi_smi_info *data)
974{
975 int rv = 0;
976 ipmi_smi_t intf;
977 struct ipmi_smi_handlers *handlers;
978
979 mutex_lock(&ipmi_interfaces_mutex);
980 list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
981 if (intf->intf_num == if_num)
982 goto found;
983 }
984 /* Not found, return an error */
985 rv = -EINVAL;
986 mutex_unlock(&ipmi_interfaces_mutex);
987 return rv;
988
989found:
990 handlers = intf->handlers;
991 rv = -ENOSYS;
992 if (handlers->get_smi_info)
993 rv = handlers->get_smi_info(intf->send_info, data);
994 mutex_unlock(&ipmi_interfaces_mutex);
995
996 return rv;
997}
998EXPORT_SYMBOL(ipmi_get_smi_info);
999
973static void free_user(struct kref *ref) 1000static void free_user(struct kref *ref)
974{ 1001{
975 ipmi_user_t user = container_of(ref, struct ipmi_user, refcount); 1002 ipmi_user_t user = container_of(ref, struct ipmi_user, refcount);
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index c4bacc6ec450..3a3643c6a579 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -57,6 +57,7 @@
57#include <asm/irq.h> 57#include <asm/irq.h>
58#include <linux/interrupt.h> 58#include <linux/interrupt.h>
59#include <linux/rcupdate.h> 59#include <linux/rcupdate.h>
60#include <linux/ipmi.h>
60#include <linux/ipmi_smi.h> 61#include <linux/ipmi_smi.h>
61#include <asm/io.h> 62#include <asm/io.h>
62#include "ipmi_si_sm.h" 63#include "ipmi_si_sm.h"
@@ -107,10 +108,6 @@ enum si_type {
107}; 108};
108static char *si_to_str[] = { "kcs", "smic", "bt" }; 109static char *si_to_str[] = { "kcs", "smic", "bt" };
109 110
110enum ipmi_addr_src {
111 SI_INVALID = 0, SI_HOTMOD, SI_HARDCODED, SI_SPMI, SI_ACPI, SI_SMBIOS,
112 SI_PCI, SI_DEVICETREE, SI_DEFAULT
113};
114static char *ipmi_addr_src_to_str[] = { NULL, "hotmod", "hardcoded", "SPMI", 111static char *ipmi_addr_src_to_str[] = { NULL, "hotmod", "hardcoded", "SPMI",
115 "ACPI", "SMBIOS", "PCI", 112 "ACPI", "SMBIOS", "PCI",
116 "device-tree", "default" }; 113 "device-tree", "default" };
@@ -291,6 +288,7 @@ struct smi_info {
291 struct task_struct *thread; 288 struct task_struct *thread;
292 289
293 struct list_head link; 290 struct list_head link;
291 union ipmi_smi_info_union addr_info;
294}; 292};
295 293
296#define smi_inc_stat(smi, stat) \ 294#define smi_inc_stat(smi, stat) \
@@ -1186,6 +1184,18 @@ static int smi_start_processing(void *send_info,
1186 return 0; 1184 return 0;
1187} 1185}
1188 1186
1187static int get_smi_info(void *send_info, struct ipmi_smi_info *data)
1188{
1189 struct smi_info *smi = send_info;
1190
1191 data->addr_src = smi->addr_source;
1192 data->dev = smi->dev;
1193 data->addr_info = smi->addr_info;
1194 get_device(smi->dev);
1195
1196 return 0;
1197}
1198
1189static void set_maintenance_mode(void *send_info, int enable) 1199static void set_maintenance_mode(void *send_info, int enable)
1190{ 1200{
1191 struct smi_info *smi_info = send_info; 1201 struct smi_info *smi_info = send_info;
@@ -1197,6 +1207,7 @@ static void set_maintenance_mode(void *send_info, int enable)
1197static struct ipmi_smi_handlers handlers = { 1207static struct ipmi_smi_handlers handlers = {
1198 .owner = THIS_MODULE, 1208 .owner = THIS_MODULE,
1199 .start_processing = smi_start_processing, 1209 .start_processing = smi_start_processing,
1210 .get_smi_info = get_smi_info,
1200 .sender = sender, 1211 .sender = sender,
1201 .request_events = request_events, 1212 .request_events = request_events,
1202 .set_maintenance_mode = set_maintenance_mode, 1213 .set_maintenance_mode = set_maintenance_mode,
@@ -2157,6 +2168,7 @@ static int __devinit ipmi_pnp_probe(struct pnp_dev *dev,
2157 printk(KERN_INFO PFX "probing via ACPI\n"); 2168 printk(KERN_INFO PFX "probing via ACPI\n");
2158 2169
2159 handle = acpi_dev->handle; 2170 handle = acpi_dev->handle;
2171 info->addr_info.acpi_info.acpi_handle = handle;
2160 2172
2161 /* _IFT tells us the interface type: KCS, BT, etc */ 2173 /* _IFT tells us the interface type: KCS, BT, etc */
2162 status = acpi_evaluate_integer(handle, "_IFT", NULL, &tmp); 2174 status = acpi_evaluate_integer(handle, "_IFT", NULL, &tmp);
diff --git a/include/linux/ipmi.h b/include/linux/ipmi.h
index 65aae34759de..045f2f275cd0 100644
--- a/include/linux/ipmi.h
+++ b/include/linux/ipmi.h
@@ -454,6 +454,44 @@ unsigned int ipmi_addr_length(int addr_type);
454/* Validate that the given IPMI address is valid. */ 454/* Validate that the given IPMI address is valid. */
455int ipmi_validate_addr(struct ipmi_addr *addr, int len); 455int ipmi_validate_addr(struct ipmi_addr *addr, int len);
456 456
457/*
458 * How did the IPMI driver find out about the device?
459 */
460enum ipmi_addr_src {
461 SI_INVALID = 0, SI_HOTMOD, SI_HARDCODED, SI_SPMI, SI_ACPI, SI_SMBIOS,
462 SI_PCI, SI_DEVICETREE, SI_DEFAULT
463};
464
465union ipmi_smi_info_union {
466 /*
467 * the acpi_info element is defined for the SI_ACPI
468 * address type
469 */
470 struct {
471 void *acpi_handle;
472 } acpi_info;
473};
474
475struct ipmi_smi_info {
476 enum ipmi_addr_src addr_src;
477
478 /*
479 * Base device for the interface. Don't forget to put this when
480 * you are done.
481 */
482 struct device *dev;
483
484 /*
485 * The addr_info provides more detailed info for some IPMI
486 * devices, depending on the addr_src. Currently only SI_ACPI
487 * info is provided.
488 */
489 union ipmi_smi_info_union addr_info;
490};
491
492/* This is to get the private info of ipmi_smi_t */
493extern int ipmi_get_smi_info(int if_num, struct ipmi_smi_info *data);
494
457#endif /* __KERNEL__ */ 495#endif /* __KERNEL__ */
458 496
459 497
diff --git a/include/linux/ipmi_smi.h b/include/linux/ipmi_smi.h
index 4b48318ac542..906590aa6907 100644
--- a/include/linux/ipmi_smi.h
+++ b/include/linux/ipmi_smi.h
@@ -39,6 +39,7 @@
39#include <linux/module.h> 39#include <linux/module.h>
40#include <linux/device.h> 40#include <linux/device.h>
41#include <linux/platform_device.h> 41#include <linux/platform_device.h>
42#include <linux/ipmi.h>
42 43
43/* This files describes the interface for IPMI system management interface 44/* This files describes the interface for IPMI system management interface
44 drivers to bind into the IPMI message handler. */ 45 drivers to bind into the IPMI message handler. */
@@ -86,6 +87,13 @@ struct ipmi_smi_handlers {
86 int (*start_processing)(void *send_info, 87 int (*start_processing)(void *send_info,
87 ipmi_smi_t new_intf); 88 ipmi_smi_t new_intf);
88 89
90 /*
91 * Get the detailed private info of the low level interface and store
92 * it into the structure of ipmi_smi_data. For example: the
93 * ACPI device handle will be returned for the pnp_acpi IPMI device.
94 */
95 int (*get_smi_info)(void *send_info, struct ipmi_smi_info *data);
96
89 /* Called to enqueue an SMI message to be sent. This 97 /* Called to enqueue an SMI message to be sent. This
90 operation is not allowed to fail. If an error occurs, it 98 operation is not allowed to fail. If an error occurs, it
91 should report back the error in a received message. It may 99 should report back the error in a received message. It may