1 // SPDX-License-Identifier: GPL-2.0+
5 * Handling for IPMI devices on the PCI bus.
8 #define pr_fmt(fmt) "ipmi_pci: " fmt
10 #include <linux/module.h>
11 #include <linux/pci.h>
14 static bool pci_registered
;
16 static bool si_trypci
= true;
18 module_param_named(trypci
, si_trypci
, bool, 0);
19 MODULE_PARM_DESC(trypci
,
20 "Setting this to zero will disable the default scan of the interfaces identified via pci");
22 #define PCI_DEVICE_ID_HP_MMC 0x121A
24 static int ipmi_pci_probe_regspacing(struct si_sm_io
*io
)
26 if (io
->si_type
== SI_KCS
) {
30 io
->regsize
= DEFAULT_REGSIZE
;
33 /* detect 1, 4, 16byte spacing */
34 for (regspacing
= DEFAULT_REGSPACING
; regspacing
<= 16;) {
35 io
->regspacing
= regspacing
;
36 if (io
->io_setup(io
)) {
37 dev_err(io
->dev
, "Could not setup I/O space\n");
38 return DEFAULT_REGSPACING
;
40 /* write invalid cmd */
41 io
->outputb(io
, 1, 0x10);
42 /* read status back */
43 status
= io
->inputb(io
, 1);
50 return DEFAULT_REGSPACING
;
53 static struct pci_device_id ipmi_pci_blacklist
[] = {
55 * This is a "Virtual IPMI device", whatever that is. It appears
56 * as a KCS device by the class, but it is not one.
58 { PCI_VDEVICE(REALTEK
, 0x816c) },
62 static int ipmi_pci_probe(struct pci_dev
*pdev
,
63 const struct pci_device_id
*ent
)
68 if (pci_match_id(ipmi_pci_blacklist
, pdev
))
71 memset(&io
, 0, sizeof(io
));
72 io
.addr_source
= SI_PCI
;
73 dev_info(&pdev
->dev
, "probing via PCI");
75 switch (pdev
->class) {
76 case PCI_CLASS_SERIAL_IPMI_SMIC
:
80 case PCI_CLASS_SERIAL_IPMI_KCS
:
84 case PCI_CLASS_SERIAL_IPMI_BT
:
89 dev_info(&pdev
->dev
, "Unknown IPMI class: %x\n", pdev
->class);
93 rv
= pcim_enable_device(pdev
);
95 dev_err(&pdev
->dev
, "couldn't enable PCI device\n");
99 if (pci_resource_flags(pdev
, 0) & IORESOURCE_IO
) {
100 if (!IS_ENABLED(CONFIG_HAS_IOPORT
))
103 io
.addr_space
= IPMI_IO_ADDR_SPACE
;
104 io
.io_setup
= ipmi_si_port_setup
;
106 io
.addr_space
= IPMI_MEM_ADDR_SPACE
;
107 io
.io_setup
= ipmi_si_mem_setup
;
109 io
.addr_data
= pci_resource_start(pdev
, 0);
113 io
.regspacing
= ipmi_pci_probe_regspacing(&io
);
114 io
.regsize
= DEFAULT_REGSIZE
;
119 io
.irq_setup
= ipmi_std_irq_setup
;
121 dev_info(&pdev
->dev
, "%pR regsize %d spacing %d irq %d\n",
122 &pdev
->resource
[0], io
.regsize
, io
.regspacing
, io
.irq
);
124 return ipmi_si_add_smi(&io
);
127 static void ipmi_pci_remove(struct pci_dev
*pdev
)
129 ipmi_si_remove_by_dev(&pdev
->dev
);
132 static const struct pci_device_id ipmi_pci_devices
[] = {
133 { PCI_VDEVICE(HP
, PCI_DEVICE_ID_HP_MMC
) },
134 { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_IPMI_SMIC
, ~0) },
135 { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_IPMI_KCS
, ~0) },
136 { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_IPMI_BT
, ~0) },
139 MODULE_DEVICE_TABLE(pci
, ipmi_pci_devices
);
141 static struct pci_driver ipmi_pci_driver
= {
142 .name
= SI_DEVICE_NAME
,
143 .id_table
= ipmi_pci_devices
,
144 .probe
= ipmi_pci_probe
,
145 .remove
= ipmi_pci_remove
,
148 void ipmi_si_pci_init(void)
151 int rv
= pci_register_driver(&ipmi_pci_driver
);
153 pr_err("Unable to register PCI driver: %d\n", rv
);
155 pci_registered
= true;
159 void ipmi_si_pci_shutdown(void)
162 pci_unregister_driver(&ipmi_pci_driver
);