1 // SPDX-License-Identifier: GPL-2.0+
5 * Handling for IPMI devices on the PCI bus.
7 #include <linux/module.h>
11 #define PFX "ipmi_pci: "
13 static bool pci_registered
;
15 static bool si_trypci
= true;
17 module_param_named(trypci
, si_trypci
, bool, 0);
18 MODULE_PARM_DESC(trypci
, "Setting this to zero will disable the"
19 " default scan of the interfaces identified via pci");
21 #define PCI_CLASS_SERIAL_IPMI 0x0c07
22 #define PCI_CLASS_SERIAL_IPMI_SMIC 0x0c0700
23 #define PCI_CLASS_SERIAL_IPMI_KCS 0x0c0701
24 #define PCI_CLASS_SERIAL_IPMI_BT 0x0c0702
26 #define PCI_DEVICE_ID_HP_MMC 0x121A
28 static void ipmi_pci_cleanup(struct si_sm_io
*io
)
30 struct pci_dev
*pdev
= io
->addr_source_data
;
32 pci_disable_device(pdev
);
35 static int ipmi_pci_probe_regspacing(struct si_sm_io
*io
)
37 if (io
->si_type
== SI_KCS
) {
41 io
->regsize
= DEFAULT_REGSIZE
;
44 /* detect 1, 4, 16byte spacing */
45 for (regspacing
= DEFAULT_REGSPACING
; regspacing
<= 16;) {
46 io
->regspacing
= regspacing
;
47 if (io
->io_setup(io
)) {
49 "Could not setup I/O space\n");
50 return DEFAULT_REGSPACING
;
52 /* write invalid cmd */
53 io
->outputb(io
, 1, 0x10);
54 /* read status back */
55 status
= io
->inputb(io
, 1);
62 return DEFAULT_REGSPACING
;
65 static struct pci_device_id ipmi_pci_blacklist
[] = {
67 * This is a "Virtual IPMI device", whatever that is. It appears
68 * as a KCS device by the class, but it is not one.
70 { PCI_VDEVICE(REALTEK
, 0x816c) },
74 static int ipmi_pci_probe(struct pci_dev
*pdev
,
75 const struct pci_device_id
*ent
)
80 if (pci_match_id(ipmi_pci_blacklist
, pdev
))
83 memset(&io
, 0, sizeof(io
));
84 io
.addr_source
= SI_PCI
;
85 dev_info(&pdev
->dev
, "probing via PCI");
87 switch (pdev
->class) {
88 case PCI_CLASS_SERIAL_IPMI_SMIC
:
92 case PCI_CLASS_SERIAL_IPMI_KCS
:
96 case PCI_CLASS_SERIAL_IPMI_BT
:
101 dev_info(&pdev
->dev
, "Unknown IPMI class: %x\n", pdev
->class);
105 rv
= pci_enable_device(pdev
);
107 dev_err(&pdev
->dev
, "couldn't enable PCI device\n");
111 io
.addr_source_cleanup
= ipmi_pci_cleanup
;
112 io
.addr_source_data
= pdev
;
114 if (pci_resource_flags(pdev
, 0) & IORESOURCE_IO
) {
115 io
.addr_type
= IPMI_IO_ADDR_SPACE
;
116 io
.io_setup
= ipmi_si_port_setup
;
118 io
.addr_type
= IPMI_MEM_ADDR_SPACE
;
119 io
.io_setup
= ipmi_si_mem_setup
;
121 io
.addr_data
= pci_resource_start(pdev
, 0);
123 io
.regspacing
= ipmi_pci_probe_regspacing(&io
);
124 io
.regsize
= DEFAULT_REGSIZE
;
129 io
.irq_setup
= ipmi_std_irq_setup
;
133 dev_info(&pdev
->dev
, "%pR regsize %d spacing %d irq %d\n",
134 &pdev
->resource
[0], io
.regsize
, io
.regspacing
, io
.irq
);
136 rv
= ipmi_si_add_smi(&io
);
138 pci_disable_device(pdev
);
143 static void ipmi_pci_remove(struct pci_dev
*pdev
)
145 ipmi_si_remove_by_dev(&pdev
->dev
);
148 static const struct pci_device_id ipmi_pci_devices
[] = {
149 { PCI_VDEVICE(HP
, PCI_DEVICE_ID_HP_MMC
) },
150 { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_IPMI_SMIC
, ~0) },
151 { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_IPMI_KCS
, ~0) },
152 { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_IPMI_BT
, ~0) },
155 MODULE_DEVICE_TABLE(pci
, ipmi_pci_devices
);
157 static struct pci_driver ipmi_pci_driver
= {
159 .id_table
= ipmi_pci_devices
,
160 .probe
= ipmi_pci_probe
,
161 .remove
= ipmi_pci_remove
,
164 void ipmi_si_pci_init(void)
167 int rv
= pci_register_driver(&ipmi_pci_driver
);
169 pr_err(PFX
"Unable to register PCI driver: %d\n", rv
);
171 pci_registered
= true;
175 void ipmi_si_pci_shutdown(void)
178 pci_unregister_driver(&ipmi_pci_driver
);