4 * Handling for platform devices in IPMI (ACPI, OF, and things
5 * coming from the platform.
7 #include <linux/types.h>
8 #include <linux/module.h>
9 #include <linux/of_device.h>
10 #include <linux/of_platform.h>
11 #include <linux/of_address.h>
12 #include <linux/of_irq.h>
13 #include <linux/acpi.h>
17 #define PFX "ipmi_platform: "
19 static bool si_tryplatform
= true;
21 static bool si_tryacpi
= true;
24 static bool si_tryopenfirmware
= true;
27 static bool si_trydmi
= true;
29 static bool si_trydmi
= false;
32 module_param_named(tryplatform
, si_tryplatform
, bool, 0);
33 MODULE_PARM_DESC(tryplatform
, "Setting this to zero will disable the"
34 " default scan of the interfaces identified via platform"
35 " interfaces besides ACPI, OpenFirmware, and DMI");
37 module_param_named(tryacpi
, si_tryacpi
, bool, 0);
38 MODULE_PARM_DESC(tryacpi
, "Setting this to zero will disable the"
39 " default scan of the interfaces identified via ACPI");
42 module_param_named(tryopenfirmware
, si_tryopenfirmware
, bool, 0);
43 MODULE_PARM_DESC(tryopenfirmware
, "Setting this to zero will disable the"
44 " default scan of the interfaces identified via OpenFirmware");
47 module_param_named(trydmi
, si_trydmi
, bool, 0);
48 MODULE_PARM_DESC(trydmi
, "Setting this to zero will disable the"
49 " default scan of the interfaces identified via DMI");
55 * Once we get an ACPI failure, we don't try any more, because we go
56 * through the tables sequentially. Once we don't find a table, there
59 static int acpi_failure
;
61 /* For GPE-type interrupts. */
62 static u32
ipmi_acpi_gpe(acpi_handle gpe_device
,
63 u32 gpe_number
, void *context
)
65 struct si_sm_io
*io
= context
;
67 ipmi_si_irq_handler(io
->irq
, io
->irq_handler_data
);
68 return ACPI_INTERRUPT_HANDLED
;
71 static void acpi_gpe_irq_cleanup(struct si_sm_io
*io
)
76 ipmi_irq_start_cleanup(io
);
77 acpi_remove_gpe_handler(NULL
, io
->irq
, &ipmi_acpi_gpe
);
80 static int acpi_gpe_irq_setup(struct si_sm_io
*io
)
87 status
= acpi_install_gpe_handler(NULL
,
89 ACPI_GPE_LEVEL_TRIGGERED
,
92 if (status
!= AE_OK
) {
94 "Unable to claim ACPI GPE %d, running polled\n",
99 io
->irq_cleanup
= acpi_gpe_irq_cleanup
;
100 ipmi_irq_finish_setup(io
);
101 dev_info(io
->dev
, "Using ACPI GPE %d\n", io
->irq
);
108 * http://h21007.www2.hp.com/portal/download/files/unprot/hpspmi.pdf
119 s8 CreatorRevision
[4];
122 s16 SpecificationRevision
;
125 * Bit 0 - SCI interrupt supported
126 * Bit 1 - I/O APIC/SAPIC
131 * If bit 0 of InterruptType is set, then this is the SCI
132 * interrupt in the GPEx_STS register.
139 * If bit 1 of InterruptType is set, then this is the I/O
140 * APIC/SAPIC interrupt.
142 u32 GlobalSystemInterrupt
;
144 /* The actual register address. */
145 struct acpi_generic_address addr
;
149 s8 spmi_id
[1]; /* A '\0' terminated array starts here. */
152 static int try_init_spmi(struct SPMITable
*spmi
)
156 if (spmi
->IPMIlegacy
!= 1) {
157 pr_info(PFX
"Bad SPMI legacy %d\n", spmi
->IPMIlegacy
);
161 memset(&io
, 0, sizeof(io
));
162 io
.addr_source
= SI_SPMI
;
163 pr_info(PFX
"probing via SPMI\n");
165 /* Figure out the interface type. */
166 switch (spmi
->InterfaceType
) {
171 io
.si_type
= SI_SMIC
;
176 case 4: /* SSIF, just ignore */
179 pr_info(PFX
"Unknown ACPI/SPMI SI type %d\n",
180 spmi
->InterfaceType
);
184 if (spmi
->InterruptType
& 1) {
185 /* We've got a GPE interrupt. */
187 io
.irq_setup
= acpi_gpe_irq_setup
;
188 } else if (spmi
->InterruptType
& 2) {
189 /* We've got an APIC/SAPIC interrupt. */
190 io
.irq
= spmi
->GlobalSystemInterrupt
;
191 io
.irq_setup
= ipmi_std_irq_setup
;
193 /* Use the default interrupt setting. */
198 if (spmi
->addr
.bit_width
) {
199 /* A (hopefully) properly formed register bit width. */
200 io
.regspacing
= spmi
->addr
.bit_width
/ 8;
202 io
.regspacing
= DEFAULT_REGSPACING
;
204 io
.regsize
= io
.regspacing
;
205 io
.regshift
= spmi
->addr
.bit_offset
;
207 if (spmi
->addr
.space_id
== ACPI_ADR_SPACE_SYSTEM_MEMORY
) {
208 io
.addr_type
= IPMI_MEM_ADDR_SPACE
;
209 } else if (spmi
->addr
.space_id
== ACPI_ADR_SPACE_SYSTEM_IO
) {
210 io
.addr_type
= IPMI_IO_ADDR_SPACE
;
212 pr_warn(PFX
"Unknown ACPI I/O Address type\n");
215 io
.addr_data
= spmi
->addr
.address
;
217 pr_info("ipmi_si: SPMI: %s %#lx regsize %d spacing %d irq %d\n",
218 (io
.addr_type
== IPMI_IO_ADDR_SPACE
) ? "io" : "mem",
219 io
.addr_data
, io
.regsize
, io
.regspacing
, io
.irq
);
221 return ipmi_si_add_smi(&io
);
224 static void spmi_find_bmc(void)
227 struct SPMITable
*spmi
;
237 status
= acpi_get_table(ACPI_SIG_SPMI
, i
+1,
238 (struct acpi_table_header
**)&spmi
);
247 static struct resource
*
248 ipmi_get_info_from_resources(struct platform_device
*pdev
,
251 struct resource
*res
, *res_second
;
253 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
255 io
->addr_type
= IPMI_IO_ADDR_SPACE
;
257 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
259 io
->addr_type
= IPMI_MEM_ADDR_SPACE
;
262 dev_err(&pdev
->dev
, "no I/O or memory address\n");
265 io
->addr_data
= res
->start
;
267 io
->regspacing
= DEFAULT_REGSPACING
;
268 res_second
= platform_get_resource(pdev
,
269 (io
->addr_type
== IPMI_IO_ADDR_SPACE
) ?
270 IORESOURCE_IO
: IORESOURCE_MEM
,
273 if (res_second
->start
> io
->addr_data
)
274 io
->regspacing
= res_second
->start
- io
->addr_data
;
276 io
->regsize
= DEFAULT_REGSIZE
;
282 static int platform_ipmi_probe(struct platform_device
*pdev
)
285 u8 type
, slave_addr
, addr_source
;
288 rv
= device_property_read_u8(&pdev
->dev
, "addr-source", &addr_source
);
290 addr_source
= SI_PLATFORM
;
291 if (addr_source
>= SI_LAST
)
294 if (addr_source
== SI_SMBIOS
) {
302 rv
= device_property_read_u8(&pdev
->dev
, "ipmi-type", &type
);
306 memset(&io
, 0, sizeof(io
));
307 io
.addr_source
= addr_source
;
308 dev_info(&pdev
->dev
, PFX
"probing via %s\n",
309 ipmi_addr_src_to_str(addr_source
));
318 dev_err(&pdev
->dev
, "ipmi-type property is invalid\n");
322 if (!ipmi_get_info_from_resources(pdev
, &io
))
325 rv
= device_property_read_u8(&pdev
->dev
, "slave-addr", &slave_addr
);
327 dev_warn(&pdev
->dev
, "device has no slave-addr property\n");
328 io
.slave_addr
= 0x20;
330 io
.slave_addr
= slave_addr
;
333 io
.irq
= platform_get_irq(pdev
, 0);
335 io
.irq_setup
= ipmi_std_irq_setup
;
341 pr_info("ipmi_si: SMBIOS: %s %#lx regsize %d spacing %d irq %d\n",
342 (io
.addr_type
== IPMI_IO_ADDR_SPACE
) ? "io" : "mem",
343 io
.addr_data
, io
.regsize
, io
.regspacing
, io
.irq
);
345 ipmi_si_add_smi(&io
);
351 static const struct of_device_id of_ipmi_match
[] = {
352 { .type
= "ipmi", .compatible
= "ipmi-kcs",
353 .data
= (void *)(unsigned long) SI_KCS
},
354 { .type
= "ipmi", .compatible
= "ipmi-smic",
355 .data
= (void *)(unsigned long) SI_SMIC
},
356 { .type
= "ipmi", .compatible
= "ipmi-bt",
357 .data
= (void *)(unsigned long) SI_BT
},
360 MODULE_DEVICE_TABLE(of
, of_ipmi_match
);
362 static int of_ipmi_probe(struct platform_device
*pdev
)
364 const struct of_device_id
*match
;
366 struct resource resource
;
367 const __be32
*regsize
, *regspacing
, *regshift
;
368 struct device_node
*np
= pdev
->dev
.of_node
;
372 if (!si_tryopenfirmware
)
375 dev_info(&pdev
->dev
, "probing via device tree\n");
377 match
= of_match_device(of_ipmi_match
, &pdev
->dev
);
381 if (!of_device_is_available(np
))
384 ret
= of_address_to_resource(np
, 0, &resource
);
386 dev_warn(&pdev
->dev
, PFX
"invalid address from OF\n");
390 regsize
= of_get_property(np
, "reg-size", &proplen
);
391 if (regsize
&& proplen
!= 4) {
392 dev_warn(&pdev
->dev
, PFX
"invalid regsize from OF\n");
396 regspacing
= of_get_property(np
, "reg-spacing", &proplen
);
397 if (regspacing
&& proplen
!= 4) {
398 dev_warn(&pdev
->dev
, PFX
"invalid regspacing from OF\n");
402 regshift
= of_get_property(np
, "reg-shift", &proplen
);
403 if (regshift
&& proplen
!= 4) {
404 dev_warn(&pdev
->dev
, PFX
"invalid regshift from OF\n");
408 memset(&io
, 0, sizeof(io
));
409 io
.si_type
= (enum si_type
) match
->data
;
410 io
.addr_source
= SI_DEVICETREE
;
411 io
.irq_setup
= ipmi_std_irq_setup
;
413 if (resource
.flags
& IORESOURCE_IO
)
414 io
.addr_type
= IPMI_IO_ADDR_SPACE
;
416 io
.addr_type
= IPMI_MEM_ADDR_SPACE
;
418 io
.addr_data
= resource
.start
;
420 io
.regsize
= regsize
? be32_to_cpup(regsize
) : DEFAULT_REGSIZE
;
421 io
.regspacing
= regspacing
? be32_to_cpup(regspacing
) : DEFAULT_REGSPACING
;
422 io
.regshift
= regshift
? be32_to_cpup(regshift
) : 0;
424 io
.irq
= irq_of_parse_and_map(pdev
->dev
.of_node
, 0);
427 dev_dbg(&pdev
->dev
, "addr 0x%lx regsize %d spacing %d irq %d\n",
428 io
.addr_data
, io
.regsize
, io
.regspacing
, io
.irq
);
430 return ipmi_si_add_smi(&io
);
433 #define of_ipmi_match NULL
434 static int of_ipmi_probe(struct platform_device
*dev
)
441 static int find_slave_address(struct si_sm_io
*io
, int slave_addr
)
443 #ifdef CONFIG_IPMI_DMI_DECODE
445 u32 flags
= IORESOURCE_IO
;
447 if (io
->addr_type
== IPMI_MEM_ADDR_SPACE
)
448 flags
= IORESOURCE_MEM
;
450 slave_addr
= ipmi_dmi_get_slave_addr(io
->si_type
, flags
,
458 static int acpi_ipmi_probe(struct platform_device
*pdev
)
463 unsigned long long tmp
;
464 struct resource
*res
;
470 handle
= ACPI_HANDLE(&pdev
->dev
);
474 memset(&io
, 0, sizeof(io
));
475 io
.addr_source
= SI_ACPI
;
476 dev_info(&pdev
->dev
, PFX
"probing via ACPI\n");
478 io
.addr_info
.acpi_info
.acpi_handle
= handle
;
480 /* _IFT tells us the interface type: KCS, BT, etc */
481 status
= acpi_evaluate_integer(handle
, "_IFT", NULL
, &tmp
);
482 if (ACPI_FAILURE(status
)) {
484 "Could not find ACPI IPMI interface type\n");
493 io
.si_type
= SI_SMIC
;
498 case 4: /* SSIF, just ignore */
502 dev_info(&pdev
->dev
, "unknown IPMI type %lld\n", tmp
);
506 res
= ipmi_get_info_from_resources(pdev
, &io
);
512 /* If _GPE exists, use it; otherwise use standard interrupts */
513 status
= acpi_evaluate_integer(handle
, "_GPE", NULL
, &tmp
);
514 if (ACPI_SUCCESS(status
)) {
516 io
.irq_setup
= acpi_gpe_irq_setup
;
518 int irq
= platform_get_irq(pdev
, 0);
522 io
.irq_setup
= ipmi_std_irq_setup
;
526 io
.slave_addr
= find_slave_address(&io
, io
.slave_addr
);
530 dev_info(io
.dev
, "%pR regsize %d spacing %d irq %d\n",
531 res
, io
.regsize
, io
.regspacing
, io
.irq
);
533 return ipmi_si_add_smi(&io
);
539 static const struct acpi_device_id acpi_ipmi_match
[] = {
543 MODULE_DEVICE_TABLE(acpi
, acpi_ipmi_match
);
545 static int acpi_ipmi_probe(struct platform_device
*dev
)
551 static int ipmi_probe(struct platform_device
*pdev
)
553 if (pdev
->dev
.of_node
&& of_ipmi_probe(pdev
) == 0)
556 if (acpi_ipmi_probe(pdev
) == 0)
559 return platform_ipmi_probe(pdev
);
562 static int ipmi_remove(struct platform_device
*pdev
)
564 return ipmi_si_remove_by_dev(&pdev
->dev
);
567 struct platform_driver ipmi_platform_driver
= {
570 .of_match_table
= of_ipmi_match
,
571 .acpi_match_table
= ACPI_PTR(acpi_ipmi_match
),
574 .remove
= ipmi_remove
,
577 void ipmi_si_platform_init(void)
579 int rv
= platform_driver_register(&ipmi_platform_driver
);
581 pr_err(PFX
"Unable to register driver: %d\n", rv
);
590 void ipmi_si_platform_shutdown(void)
592 platform_driver_unregister(&ipmi_platform_driver
);