2 * A hack to create a platform device from a DMI entry. This will
3 * allow autoloading of the IPMI drive based on SMBIOS entries.
6 #include <linux/ipmi.h>
7 #include <linux/init.h>
9 #include <linux/platform_device.h>
10 #include <linux/property.h>
13 struct ipmi_dmi_info {
18 struct ipmi_dmi_info *next;
21 static struct ipmi_dmi_info *ipmi_dmi_infos;
23 static int ipmi_dmi_nr __initdata;
25 static void __init dmi_add_platform_ipmi(unsigned long base_addr,
32 struct platform_device *pdev;
34 unsigned int num_r = 1, size;
35 struct property_entry p[4] = {
36 PROPERTY_ENTRY_U8("slave-addr", slave_addr),
37 PROPERTY_ENTRY_U8("ipmi-type", type),
38 PROPERTY_ENTRY_U16("i2c-addr", base_addr),
41 char *name, *override;
43 struct ipmi_dmi_info *info;
45 info = kmalloc(sizeof(*info), GFP_KERNEL);
47 pr_warn("ipmi:dmi: Could not allocate dmi info\n");
51 info->addr = base_addr;
52 info->slave_addr = slave_addr;
53 info->next = ipmi_dmi_infos;
54 ipmi_dmi_infos = info;
60 case IPMI_DMI_TYPE_SSIF:
61 name = "dmi-ipmi-ssif";
62 override = "ipmi_ssif";
66 case IPMI_DMI_TYPE_BT:
69 case IPMI_DMI_TYPE_KCS:
70 case IPMI_DMI_TYPE_SMIC:
74 pr_err("ipmi:dmi: Invalid IPMI type: %d", type);
78 pdev = platform_device_alloc(name, ipmi_dmi_nr);
80 pr_err("ipmi:dmi: Error allocation IPMI platform device");
83 pdev->driver_override = override;
85 if (type == IPMI_DMI_TYPE_SSIF)
88 memset(r, 0, sizeof(r));
90 r[0].start = base_addr;
91 r[0].end = r[0].start + offset - 1;
92 r[0].name = "IPMI Address 1";
96 r[1].start = r[0].start + offset;
97 r[1].end = r[1].start + offset - 1;
98 r[1].name = "IPMI Address 2";
104 r[2].start = r[1].start + offset;
105 r[2].end = r[2].start + offset - 1;
106 r[2].name = "IPMI Address 3";
112 r[num_r].start = irq;
114 r[num_r].name = "IPMI IRQ";
115 r[num_r].flags = IORESOURCE_IRQ;
119 rv = platform_device_add_resources(pdev, r, num_r);
122 "ipmi:dmi: Unable to add resources: %d\n", rv);
127 rv = platform_device_add_properties(pdev, p);
130 "ipmi:dmi: Unable to add properties: %d\n", rv);
134 rv = platform_device_add(pdev);
136 dev_err(&pdev->dev, "ipmi:dmi: Unable to add device: %d\n", rv);
144 platform_device_put(pdev);
148 * Look up the slave address for a given interface. This is here
149 * because ACPI doesn't have a slave address while SMBIOS does, but we
150 * prefer using ACPI so the ACPI code can use the IPMI namespace.
151 * This function allows an ACPI-specified IPMI device to look up the
152 * slave address from the DMI table.
154 int ipmi_dmi_get_slave_addr(int type, u32 flags, unsigned long base_addr)
156 struct ipmi_dmi_info *info = ipmi_dmi_infos;
159 if (info->type == type &&
160 info->flags == flags &&
161 info->addr == base_addr)
162 return info->slave_addr;
168 EXPORT_SYMBOL(ipmi_dmi_get_slave_addr);
170 #define DMI_IPMI_MIN_LENGTH 0x10
171 #define DMI_IPMI_VER2_LENGTH 0x12
172 #define DMI_IPMI_TYPE 4
173 #define DMI_IPMI_SLAVEADDR 6
174 #define DMI_IPMI_ADDR 8
175 #define DMI_IPMI_ACCESS 0x10
176 #define DMI_IPMI_IRQ 0x11
177 #define DMI_IPMI_IO_MASK 0xfffe
179 static void __init dmi_decode_ipmi(const struct dmi_header *dm)
181 const u8 *data = (const u8 *) dm;
182 u32 flags = IORESOURCE_IO;
183 unsigned long base_addr;
189 if (len < DMI_IPMI_MIN_LENGTH)
192 type = data[DMI_IPMI_TYPE];
193 slave_addr = data[DMI_IPMI_SLAVEADDR];
195 memcpy(&base_addr, data + DMI_IPMI_ADDR, sizeof(unsigned long));
196 if (len >= DMI_IPMI_VER2_LENGTH) {
197 if (type == IPMI_DMI_TYPE_SSIF) {
200 base_addr = data[DMI_IPMI_ADDR] >> 1;
201 if (base_addr == 0) {
203 * Some broken systems put the I2C address in
204 * the slave address field. We try to
205 * accommodate them here.
207 base_addr = data[DMI_IPMI_SLAVEADDR] >> 1;
213 base_addr &= DMI_IPMI_IO_MASK;
216 flags = IORESOURCE_MEM;
220 * If bit 4 of byte 0x10 is set, then the lsb
221 * for the address is odd.
223 base_addr |= (data[DMI_IPMI_ACCESS] >> 4) & 1;
225 irq = data[DMI_IPMI_IRQ];
228 * The top two bits of byte 0x10 hold the
231 switch ((data[DMI_IPMI_ACCESS] >> 6) & 3) {
232 case 0: /* Byte boundaries */
235 case 1: /* 32-bit boundaries */
238 case 2: /* 16-byte boundaries */
242 pr_err("ipmi:dmi: Invalid offset: 0");
249 * Note that technically, the lower bit of the base
250 * address should be 1 if the address is I/O and 0 if
251 * the address is in memory. So many systems get that
252 * wrong (and all that I have seen are I/O) so we just
253 * ignore that bit and assume I/O. Systems that use
254 * memory should use the newer spec, anyway.
256 base_addr = base_addr & DMI_IPMI_IO_MASK;
260 dmi_add_platform_ipmi(base_addr, flags, slave_addr, irq,
264 static int __init scan_for_dmi_ipmi(void)
266 const struct dmi_device *dev = NULL;
268 while ((dev = dmi_find_device(DMI_DEV_TYPE_IPMI, NULL, dev)))
269 dmi_decode_ipmi((const struct dmi_header *) dev->device_data);
273 subsys_initcall(scan_for_dmi_ipmi);