Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0+
  2
  3#define pr_fmt(fmt) "ipmi_hardcode: " fmt
  4
  5#include <linux/moduleparam.h>
  6#include <linux/platform_device.h>
  7#include "ipmi_si.h"
  8#include "ipmi_plat_data.h"
  9
 10/*
 11 * There can be 4 IO ports passed in (with or without IRQs), 4 addresses,
 12 * a default IO port, and 1 ACPI/SPMI address.  That sets SI_MAX_DRIVERS.
 13 */
 14
 15#define SI_MAX_PARMS 4
 16
 17#define MAX_SI_TYPE_STR 30
 18static char          si_type_str[MAX_SI_TYPE_STR] __initdata;
 19static unsigned long addrs[SI_MAX_PARMS];
 20static unsigned int num_addrs;
 21static unsigned int  ports[SI_MAX_PARMS];
 22static unsigned int num_ports;
 23static int           irqs[SI_MAX_PARMS] __initdata;
 24static unsigned int num_irqs __initdata;
 25static int           regspacings[SI_MAX_PARMS] __initdata;
 26static unsigned int num_regspacings __initdata;
 27static int           regsizes[SI_MAX_PARMS] __initdata;
 28static unsigned int num_regsizes __initdata;
 29static int           regshifts[SI_MAX_PARMS] __initdata;
 30static unsigned int num_regshifts __initdata;
 31static int slave_addrs[SI_MAX_PARMS] __initdata;
 32static unsigned int num_slave_addrs __initdata;
 33
 34module_param_string(type, si_type_str, MAX_SI_TYPE_STR, 0);
 35MODULE_PARM_DESC(type,
 36		 "Defines the type of each interface, each interface separated by commas.  The types are 'kcs', 'smic', and 'bt'.  For example si_type=kcs,bt will set the first interface to kcs and the second to bt");
 
 
 37module_param_hw_array(addrs, ulong, iomem, &num_addrs, 0);
 38MODULE_PARM_DESC(addrs,
 39		 "Sets the memory address of each interface, the addresses separated by commas.  Only use if an interface is in memory.  Otherwise, set it to zero or leave it blank.");
 
 
 40module_param_hw_array(ports, uint, ioport, &num_ports, 0);
 41MODULE_PARM_DESC(ports,
 42		 "Sets the port address of each interface, the addresses separated by commas.  Only use if an interface is a port.  Otherwise, set it to zero or leave it blank.");
 
 
 43module_param_hw_array(irqs, int, irq, &num_irqs, 0);
 44MODULE_PARM_DESC(irqs,
 45		 "Sets the interrupt of each interface, the addresses separated by commas.  Only use if an interface has an interrupt.  Otherwise, set it to zero or leave it blank.");
 
 
 46module_param_hw_array(regspacings, int, other, &num_regspacings, 0);
 47MODULE_PARM_DESC(regspacings,
 48		 "The number of bytes between the start address and each successive register used by the interface.  For instance, if the start address is 0xca2 and the spacing is 2, then the second address is at 0xca4.  Defaults to 1.");
 
 
 
 49module_param_hw_array(regsizes, int, other, &num_regsizes, 0);
 50MODULE_PARM_DESC(regsizes,
 51		 "The size of the specific IPMI register in bytes. This should generally be 1, 2, 4, or 8 for an 8-bit, 16-bit, 32-bit, or 64-bit register.  Use this if you the 8-bit IPMI register has to be read from a larger register.");
 
 
 
 52module_param_hw_array(regshifts, int, other, &num_regshifts, 0);
 53MODULE_PARM_DESC(regshifts,
 54		 "The amount to shift the data read from the. IPMI register, in bits.  For instance, if the data is read from a 32-bit word and the IPMI data is in bit 8-15, then the shift would be 8");
 
 
 55module_param_hw_array(slave_addrs, int, other, &num_slave_addrs, 0);
 56MODULE_PARM_DESC(slave_addrs,
 57		 "Set the default IPMB slave address for the controller.  Normally this is 0x20, but can be overridden by this parm.  This is an array indexed by interface number.");
 
 
 58
 59static void __init ipmi_hardcode_init_one(const char *si_type_str,
 60					  unsigned int i,
 61					  unsigned long addr,
 62					  enum ipmi_addr_space addr_space)
 63{
 64	struct ipmi_plat_data p;
 65	int t;
 66
 67	memset(&p, 0, sizeof(p));
 68
 69	p.iftype = IPMI_PLAT_IF_SI;
 70	if (!si_type_str || !*si_type_str) {
 71		p.type = SI_KCS;
 
 
 
 
 
 
 
 
 
 
 72	} else {
 73		t = match_string(si_to_str, -1, si_type_str);
 74		if (t < 0) {
 75			pr_warn("Interface type specified for interface %d, was invalid: %s\n",
 76				i, si_type_str);
 77			return;
 78		}
 79		p.type = t;
 80	}
 81
 82	p.regsize = regsizes[i];
 83	p.regspacing = regspacings[i];
 84	p.slave_addr = slave_addrs[i];
 85	p.addr_source = SI_HARDCODED;
 86	p.regshift = regshifts[i];
 
 87	p.addr = addr;
 88	p.space = addr_space;
 89
 90	ipmi_platform_add("hardcode-ipmi-si", i, &p);
 91}
 92
 93void __init ipmi_hardcode_init(void)
 94{
 95	unsigned int i;
 96	char *str;
 97	char *si_type[SI_MAX_PARMS];
 98
 99	memset(si_type, 0, sizeof(si_type));
100
101	/* Parse out the si_type string into its components. */
102	str = si_type_str;
103	if (*str != '\0') {
104		for (i = 0; (i < SI_MAX_PARMS) && (*str != '\0'); i++) {
105			si_type[i] = str;
106			str = strchr(str, ',');
107			if (str) {
108				*str = '\0';
109				str++;
110			} else {
111				break;
112			}
113		}
114	}
115
116	for (i = 0; i < SI_MAX_PARMS; i++) {
117		if (i < num_ports && ports[i])
118			ipmi_hardcode_init_one(si_type[i], i, ports[i],
119					       IPMI_IO_ADDR_SPACE);
120		if (i < num_addrs && addrs[i])
121			ipmi_hardcode_init_one(si_type[i], i, addrs[i],
122					       IPMI_MEM_ADDR_SPACE);
123	}
124}
125
126
127void ipmi_si_hardcode_exit(void)
128{
129	ipmi_remove_platform_device_by_name("hardcode-ipmi-si");
130}
131
132/*
133 * Returns true of the given address exists as a hardcoded address,
134 * false if not.
135 */
136int ipmi_si_hardcode_match(int addr_space, unsigned long addr)
137{
138	unsigned int i;
139
140	if (addr_space == IPMI_IO_ADDR_SPACE) {
141		for (i = 0; i < num_ports; i++) {
142			if (ports[i] == addr)
143				return 1;
144		}
145	} else {
146		for (i = 0; i < num_addrs; i++) {
147			if (addrs[i] == addr)
148				return 1;
149		}
150	}
151
152	return 0;
153}
v5.9
  1// SPDX-License-Identifier: GPL-2.0+
  2
  3#define pr_fmt(fmt) "ipmi_hardcode: " fmt
  4
  5#include <linux/moduleparam.h>
  6#include <linux/platform_device.h>
  7#include "ipmi_si.h"
  8#include "ipmi_plat_data.h"
  9
 10/*
 11 * There can be 4 IO ports passed in (with or without IRQs), 4 addresses,
 12 * a default IO port, and 1 ACPI/SPMI address.  That sets SI_MAX_DRIVERS.
 13 */
 14
 15#define SI_MAX_PARMS 4
 16
 17#define MAX_SI_TYPE_STR 30
 18static char          si_type_str[MAX_SI_TYPE_STR] __initdata;
 19static unsigned long addrs[SI_MAX_PARMS];
 20static unsigned int num_addrs;
 21static unsigned int  ports[SI_MAX_PARMS];
 22static unsigned int num_ports;
 23static int           irqs[SI_MAX_PARMS] __initdata;
 24static unsigned int num_irqs __initdata;
 25static int           regspacings[SI_MAX_PARMS] __initdata;
 26static unsigned int num_regspacings __initdata;
 27static int           regsizes[SI_MAX_PARMS] __initdata;
 28static unsigned int num_regsizes __initdata;
 29static int           regshifts[SI_MAX_PARMS] __initdata;
 30static unsigned int num_regshifts __initdata;
 31static int slave_addrs[SI_MAX_PARMS] __initdata;
 32static unsigned int num_slave_addrs __initdata;
 33
 34module_param_string(type, si_type_str, MAX_SI_TYPE_STR, 0);
 35MODULE_PARM_DESC(type, "Defines the type of each interface, each"
 36		 " interface separated by commas.  The types are 'kcs',"
 37		 " 'smic', and 'bt'.  For example si_type=kcs,bt will set"
 38		 " the first interface to kcs and the second to bt");
 39module_param_hw_array(addrs, ulong, iomem, &num_addrs, 0);
 40MODULE_PARM_DESC(addrs, "Sets the memory address of each interface, the"
 41		 " addresses separated by commas.  Only use if an interface"
 42		 " is in memory.  Otherwise, set it to zero or leave"
 43		 " it blank.");
 44module_param_hw_array(ports, uint, ioport, &num_ports, 0);
 45MODULE_PARM_DESC(ports, "Sets the port address of each interface, the"
 46		 " addresses separated by commas.  Only use if an interface"
 47		 " is a port.  Otherwise, set it to zero or leave"
 48		 " it blank.");
 49module_param_hw_array(irqs, int, irq, &num_irqs, 0);
 50MODULE_PARM_DESC(irqs, "Sets the interrupt of each interface, the"
 51		 " addresses separated by commas.  Only use if an interface"
 52		 " has an interrupt.  Otherwise, set it to zero or leave"
 53		 " it blank.");
 54module_param_hw_array(regspacings, int, other, &num_regspacings, 0);
 55MODULE_PARM_DESC(regspacings, "The number of bytes between the start address"
 56		 " and each successive register used by the interface.  For"
 57		 " instance, if the start address is 0xca2 and the spacing"
 58		 " is 2, then the second address is at 0xca4.  Defaults"
 59		 " to 1.");
 60module_param_hw_array(regsizes, int, other, &num_regsizes, 0);
 61MODULE_PARM_DESC(regsizes, "The size of the specific IPMI register in bytes."
 62		 " This should generally be 1, 2, 4, or 8 for an 8-bit,"
 63		 " 16-bit, 32-bit, or 64-bit register.  Use this if you"
 64		 " the 8-bit IPMI register has to be read from a larger"
 65		 " register.");
 66module_param_hw_array(regshifts, int, other, &num_regshifts, 0);
 67MODULE_PARM_DESC(regshifts, "The amount to shift the data read from the."
 68		 " IPMI register, in bits.  For instance, if the data"
 69		 " is read from a 32-bit word and the IPMI data is in"
 70		 " bit 8-15, then the shift would be 8");
 71module_param_hw_array(slave_addrs, int, other, &num_slave_addrs, 0);
 72MODULE_PARM_DESC(slave_addrs, "Set the default IPMB slave address for"
 73		 " the controller.  Normally this is 0x20, but can be"
 74		 " overridden by this parm.  This is an array indexed"
 75		 " by interface number.");
 76
 77static void __init ipmi_hardcode_init_one(const char *si_type_str,
 78					  unsigned int i,
 79					  unsigned long addr,
 80					  enum ipmi_addr_space addr_space)
 81{
 82	struct ipmi_plat_data p;
 
 83
 84	memset(&p, 0, sizeof(p));
 85
 86	p.iftype = IPMI_PLAT_IF_SI;
 87	if (!si_type_str || !*si_type_str || strcmp(si_type_str, "kcs") == 0) {
 88		p.type = SI_KCS;
 89	} else if (strcmp(si_type_str, "smic") == 0) {
 90		p.type = SI_SMIC;
 91	} else if (strcmp(si_type_str, "bt") == 0) {
 92		p.type = SI_BT;
 93	} else if (strcmp(si_type_str, "invalid") == 0) {
 94		/*
 95		 * Allow a firmware-specified interface to be
 96		 * disabled.
 97		 */
 98		p.type = SI_TYPE_INVALID;
 99	} else {
100		pr_warn("Interface type specified for interface %d, was invalid: %s\n",
101			i, si_type_str);
102		return;
 
 
 
 
103	}
104
105	p.regsize = regsizes[i];
 
106	p.slave_addr = slave_addrs[i];
107	p.addr_source = SI_HARDCODED;
108	p.regshift = regshifts[i];
109	p.regsize = regsizes[i];
110	p.addr = addr;
111	p.space = addr_space;
112
113	ipmi_platform_add("hardcode-ipmi-si", i, &p);
114}
115
116void __init ipmi_hardcode_init(void)
117{
118	unsigned int i;
119	char *str;
120	char *si_type[SI_MAX_PARMS];
121
122	memset(si_type, 0, sizeof(si_type));
123
124	/* Parse out the si_type string into its components. */
125	str = si_type_str;
126	if (*str != '\0') {
127		for (i = 0; (i < SI_MAX_PARMS) && (*str != '\0'); i++) {
128			si_type[i] = str;
129			str = strchr(str, ',');
130			if (str) {
131				*str = '\0';
132				str++;
133			} else {
134				break;
135			}
136		}
137	}
138
139	for (i = 0; i < SI_MAX_PARMS; i++) {
140		if (i < num_ports && ports[i])
141			ipmi_hardcode_init_one(si_type[i], i, ports[i],
142					       IPMI_IO_ADDR_SPACE);
143		if (i < num_addrs && addrs[i])
144			ipmi_hardcode_init_one(si_type[i], i, addrs[i],
145					       IPMI_MEM_ADDR_SPACE);
146	}
147}
148
149
150void ipmi_si_hardcode_exit(void)
151{
152	ipmi_remove_platform_device_by_name("hardcode-ipmi-si");
153}
154
155/*
156 * Returns true of the given address exists as a hardcoded address,
157 * false if not.
158 */
159int ipmi_si_hardcode_match(int addr_space, unsigned long addr)
160{
161	unsigned int i;
162
163	if (addr_space == IPMI_IO_ADDR_SPACE) {
164		for (i = 0; i < num_ports; i++) {
165			if (ports[i] == addr)
166				return 1;
167		}
168	} else {
169		for (i = 0; i < num_addrs; i++) {
170			if (addrs[i] == addr)
171				return 1;
172		}
173	}
174
175	return 0;
176}