1 // SPDX-License-Identifier: GPL-2.0+
3 #define pr_fmt(fmt) "ipmi_hardcode: " fmt
5 #include <linux/moduleparam.h>
9 * There can be 4 IO ports passed in (with or without IRQs), 4 addresses,
10 * a default IO port, and 1 ACPI/SPMI address. That sets SI_MAX_DRIVERS.
13 #define SI_MAX_PARMS 4
15 static char *si_type
[SI_MAX_PARMS
];
16 #define MAX_SI_TYPE_STR 30
17 static char si_type_str
[MAX_SI_TYPE_STR
];
18 static unsigned long addrs
[SI_MAX_PARMS
];
19 static unsigned int num_addrs
;
20 static unsigned int ports
[SI_MAX_PARMS
];
21 static unsigned int num_ports
;
22 static int irqs
[SI_MAX_PARMS
];
23 static unsigned int num_irqs
;
24 static int regspacings
[SI_MAX_PARMS
];
25 static unsigned int num_regspacings
;
26 static int regsizes
[SI_MAX_PARMS
];
27 static unsigned int num_regsizes
;
28 static int regshifts
[SI_MAX_PARMS
];
29 static unsigned int num_regshifts
;
30 static int slave_addrs
[SI_MAX_PARMS
]; /* Leaving 0 chooses the default value */
31 static unsigned int num_slave_addrs
;
33 module_param_string(type
, si_type_str
, MAX_SI_TYPE_STR
, 0);
34 MODULE_PARM_DESC(type
, "Defines the type of each interface, each"
35 " interface separated by commas. The types are 'kcs',"
36 " 'smic', and 'bt'. For example si_type=kcs,bt will set"
37 " the first interface to kcs and the second to bt");
38 module_param_hw_array(addrs
, ulong
, iomem
, &num_addrs
, 0);
39 MODULE_PARM_DESC(addrs
, "Sets the memory address of each interface, the"
40 " addresses separated by commas. Only use if an interface"
41 " is in memory. Otherwise, set it to zero or leave"
43 module_param_hw_array(ports
, uint
, ioport
, &num_ports
, 0);
44 MODULE_PARM_DESC(ports
, "Sets the port address of each interface, the"
45 " addresses separated by commas. Only use if an interface"
46 " is a port. Otherwise, set it to zero or leave"
48 module_param_hw_array(irqs
, int, irq
, &num_irqs
, 0);
49 MODULE_PARM_DESC(irqs
, "Sets the interrupt of each interface, the"
50 " addresses separated by commas. Only use if an interface"
51 " has an interrupt. Otherwise, set it to zero or leave"
53 module_param_hw_array(regspacings
, int, other
, &num_regspacings
, 0);
54 MODULE_PARM_DESC(regspacings
, "The number of bytes between the start address"
55 " and each successive register used by the interface. For"
56 " instance, if the start address is 0xca2 and the spacing"
57 " is 2, then the second address is at 0xca4. Defaults"
59 module_param_hw_array(regsizes
, int, other
, &num_regsizes
, 0);
60 MODULE_PARM_DESC(regsizes
, "The size of the specific IPMI register in bytes."
61 " This should generally be 1, 2, 4, or 8 for an 8-bit,"
62 " 16-bit, 32-bit, or 64-bit register. Use this if you"
63 " the 8-bit IPMI register has to be read from a larger"
65 module_param_hw_array(regshifts
, int, other
, &num_regshifts
, 0);
66 MODULE_PARM_DESC(regshifts
, "The amount to shift the data read from the."
67 " IPMI register, in bits. For instance, if the data"
68 " is read from a 32-bit word and the IPMI data is in"
69 " bit 8-15, then the shift would be 8");
70 module_param_hw_array(slave_addrs
, int, other
, &num_slave_addrs
, 0);
71 MODULE_PARM_DESC(slave_addrs
, "Set the default IPMB slave address for"
72 " the controller. Normally this is 0x20, but can be"
73 " overridden by this parm. This is an array indexed"
74 " by interface number.");
76 int ipmi_si_hardcode_find_bmc(void)
83 /* Parse out the si_type string into its components. */
86 for (i
= 0; (i
< SI_MAX_PARMS
) && (*str
!= '\0'); i
++) {
88 str
= strchr(str
, ',');
98 memset(&io
, 0, sizeof(io
));
99 for (i
= 0; i
< SI_MAX_PARMS
; i
++) {
100 if (!ports
[i
] && !addrs
[i
])
103 io
.addr_source
= SI_HARDCODED
;
104 pr_info("probing via hardcoded address\n");
106 if (!si_type
[i
] || strcmp(si_type
[i
], "kcs") == 0) {
108 } else if (strcmp(si_type
[i
], "smic") == 0) {
109 io
.si_type
= SI_SMIC
;
110 } else if (strcmp(si_type
[i
], "bt") == 0) {
113 pr_warn("Interface type specified for interface %d, was invalid: %s\n",
120 io
.addr_data
= ports
[i
];
121 io
.addr_type
= IPMI_IO_ADDR_SPACE
;
122 } else if (addrs
[i
]) {
124 io
.addr_data
= addrs
[i
];
125 io
.addr_type
= IPMI_MEM_ADDR_SPACE
;
127 pr_warn("Interface type specified for interface %d, but port and address were not set or set to zero\n",
133 io
.regspacing
= regspacings
[i
];
135 io
.regspacing
= DEFAULT_REGSPACING
;
136 io
.regsize
= regsizes
[i
];
138 io
.regsize
= DEFAULT_REGSIZE
;
139 io
.regshift
= regshifts
[i
];
142 io
.irq_setup
= ipmi_std_irq_setup
;
143 io
.slave_addr
= slave_addrs
[i
];
145 ret
= ipmi_si_add_smi(&io
);