.. | .. |
---|
4 | 4 | * allow autoloading of the IPMI drive based on SMBIOS entries. |
---|
5 | 5 | */ |
---|
6 | 6 | |
---|
| 7 | +#define pr_fmt(fmt) "%s" fmt, "ipmi:dmi: " |
---|
| 8 | +#define dev_fmt pr_fmt |
---|
| 9 | + |
---|
7 | 10 | #include <linux/ipmi.h> |
---|
8 | 11 | #include <linux/init.h> |
---|
9 | 12 | #include <linux/dmi.h> |
---|
10 | 13 | #include <linux/platform_device.h> |
---|
11 | 14 | #include <linux/property.h> |
---|
12 | | -#include "ipmi_si_sm.h" |
---|
13 | 15 | #include "ipmi_dmi.h" |
---|
| 16 | +#include "ipmi_plat_data.h" |
---|
14 | 17 | |
---|
15 | 18 | #define IPMI_DMI_TYPE_KCS 0x01 |
---|
16 | 19 | #define IPMI_DMI_TYPE_SMIC 0x02 |
---|
.. | .. |
---|
19 | 22 | |
---|
20 | 23 | struct ipmi_dmi_info { |
---|
21 | 24 | enum si_type si_type; |
---|
22 | | - u32 flags; |
---|
| 25 | + unsigned int space; /* addr space for si, intf# for ssif */ |
---|
23 | 26 | unsigned long addr; |
---|
24 | 27 | u8 slave_addr; |
---|
25 | 28 | struct ipmi_dmi_info *next; |
---|
.. | .. |
---|
30 | 33 | static int ipmi_dmi_nr __initdata; |
---|
31 | 34 | |
---|
32 | 35 | static void __init dmi_add_platform_ipmi(unsigned long base_addr, |
---|
33 | | - u32 flags, |
---|
| 36 | + unsigned int space, |
---|
34 | 37 | u8 slave_addr, |
---|
35 | 38 | int irq, |
---|
36 | 39 | int offset, |
---|
37 | 40 | int type) |
---|
38 | 41 | { |
---|
39 | | - struct platform_device *pdev; |
---|
40 | | - struct resource r[4]; |
---|
41 | | - unsigned int num_r = 1, size; |
---|
42 | | - struct property_entry p[5]; |
---|
43 | | - unsigned int pidx = 0; |
---|
44 | | - char *name, *override; |
---|
45 | | - int rv; |
---|
46 | | - enum si_type si_type; |
---|
| 42 | + const char *name; |
---|
47 | 43 | struct ipmi_dmi_info *info; |
---|
| 44 | + struct ipmi_plat_data p; |
---|
48 | 45 | |
---|
49 | | - memset(p, 0, sizeof(p)); |
---|
| 46 | + memset(&p, 0, sizeof(p)); |
---|
50 | 47 | |
---|
51 | 48 | name = "dmi-ipmi-si"; |
---|
52 | | - override = "ipmi_si"; |
---|
| 49 | + p.iftype = IPMI_PLAT_IF_SI; |
---|
53 | 50 | switch (type) { |
---|
54 | 51 | case IPMI_DMI_TYPE_SSIF: |
---|
55 | 52 | name = "dmi-ipmi-ssif"; |
---|
56 | | - override = "ipmi_ssif"; |
---|
57 | | - offset = 1; |
---|
58 | | - size = 1; |
---|
59 | | - si_type = SI_TYPE_INVALID; |
---|
| 53 | + p.iftype = IPMI_PLAT_IF_SSIF; |
---|
| 54 | + p.type = SI_TYPE_INVALID; |
---|
60 | 55 | break; |
---|
61 | 56 | case IPMI_DMI_TYPE_BT: |
---|
62 | | - size = 3; |
---|
63 | | - si_type = SI_BT; |
---|
| 57 | + p.type = SI_BT; |
---|
64 | 58 | break; |
---|
65 | 59 | case IPMI_DMI_TYPE_KCS: |
---|
66 | | - size = 2; |
---|
67 | | - si_type = SI_KCS; |
---|
| 60 | + p.type = SI_KCS; |
---|
68 | 61 | break; |
---|
69 | 62 | case IPMI_DMI_TYPE_SMIC: |
---|
70 | | - size = 2; |
---|
71 | | - si_type = SI_SMIC; |
---|
| 63 | + p.type = SI_SMIC; |
---|
72 | 64 | break; |
---|
73 | 65 | default: |
---|
74 | | - pr_err("ipmi:dmi: Invalid IPMI type: %d\n", type); |
---|
| 66 | + pr_err("Invalid IPMI type: %d\n", type); |
---|
75 | 67 | return; |
---|
76 | 68 | } |
---|
77 | 69 | |
---|
78 | | - if (si_type != SI_TYPE_INVALID) |
---|
79 | | - p[pidx++] = PROPERTY_ENTRY_U8("ipmi-type", si_type); |
---|
80 | | - |
---|
81 | | - p[pidx++] = PROPERTY_ENTRY_U8("slave-addr", slave_addr); |
---|
82 | | - p[pidx++] = PROPERTY_ENTRY_U8("addr-source", SI_SMBIOS); |
---|
| 70 | + p.addr = base_addr; |
---|
| 71 | + p.space = space; |
---|
| 72 | + p.regspacing = offset; |
---|
| 73 | + p.irq = irq; |
---|
| 74 | + p.slave_addr = slave_addr; |
---|
| 75 | + p.addr_source = SI_SMBIOS; |
---|
83 | 76 | |
---|
84 | 77 | info = kmalloc(sizeof(*info), GFP_KERNEL); |
---|
85 | 78 | if (!info) { |
---|
86 | | - pr_warn("ipmi:dmi: Could not allocate dmi info\n"); |
---|
| 79 | + pr_warn("Could not allocate dmi info\n"); |
---|
87 | 80 | } else { |
---|
88 | | - info->si_type = si_type; |
---|
89 | | - info->flags = flags; |
---|
| 81 | + info->si_type = p.type; |
---|
| 82 | + info->space = space; |
---|
90 | 83 | info->addr = base_addr; |
---|
91 | 84 | info->slave_addr = slave_addr; |
---|
92 | 85 | info->next = ipmi_dmi_infos; |
---|
93 | 86 | ipmi_dmi_infos = info; |
---|
94 | 87 | } |
---|
95 | 88 | |
---|
96 | | - pdev = platform_device_alloc(name, ipmi_dmi_nr); |
---|
97 | | - if (!pdev) { |
---|
98 | | - pr_err("ipmi:dmi: Error allocation IPMI platform device\n"); |
---|
99 | | - return; |
---|
100 | | - } |
---|
101 | | - pdev->driver_override = kasprintf(GFP_KERNEL, "%s", |
---|
102 | | - override); |
---|
103 | | - if (!pdev->driver_override) |
---|
104 | | - goto err; |
---|
105 | | - |
---|
106 | | - if (type == IPMI_DMI_TYPE_SSIF) { |
---|
107 | | - p[pidx++] = PROPERTY_ENTRY_U16("i2c-addr", base_addr); |
---|
108 | | - goto add_properties; |
---|
109 | | - } |
---|
110 | | - |
---|
111 | | - memset(r, 0, sizeof(r)); |
---|
112 | | - |
---|
113 | | - r[0].start = base_addr; |
---|
114 | | - r[0].end = r[0].start + offset - 1; |
---|
115 | | - r[0].name = "IPMI Address 1"; |
---|
116 | | - r[0].flags = flags; |
---|
117 | | - |
---|
118 | | - if (size > 1) { |
---|
119 | | - r[1].start = r[0].start + offset; |
---|
120 | | - r[1].end = r[1].start + offset - 1; |
---|
121 | | - r[1].name = "IPMI Address 2"; |
---|
122 | | - r[1].flags = flags; |
---|
123 | | - num_r++; |
---|
124 | | - } |
---|
125 | | - |
---|
126 | | - if (size > 2) { |
---|
127 | | - r[2].start = r[1].start + offset; |
---|
128 | | - r[2].end = r[2].start + offset - 1; |
---|
129 | | - r[2].name = "IPMI Address 3"; |
---|
130 | | - r[2].flags = flags; |
---|
131 | | - num_r++; |
---|
132 | | - } |
---|
133 | | - |
---|
134 | | - if (irq) { |
---|
135 | | - r[num_r].start = irq; |
---|
136 | | - r[num_r].end = irq; |
---|
137 | | - r[num_r].name = "IPMI IRQ"; |
---|
138 | | - r[num_r].flags = IORESOURCE_IRQ; |
---|
139 | | - num_r++; |
---|
140 | | - } |
---|
141 | | - |
---|
142 | | - rv = platform_device_add_resources(pdev, r, num_r); |
---|
143 | | - if (rv) { |
---|
144 | | - dev_err(&pdev->dev, |
---|
145 | | - "ipmi:dmi: Unable to add resources: %d\n", rv); |
---|
146 | | - goto err; |
---|
147 | | - } |
---|
148 | | - |
---|
149 | | -add_properties: |
---|
150 | | - rv = platform_device_add_properties(pdev, p); |
---|
151 | | - if (rv) { |
---|
152 | | - dev_err(&pdev->dev, |
---|
153 | | - "ipmi:dmi: Unable to add properties: %d\n", rv); |
---|
154 | | - goto err; |
---|
155 | | - } |
---|
156 | | - |
---|
157 | | - rv = platform_device_add(pdev); |
---|
158 | | - if (rv) { |
---|
159 | | - dev_err(&pdev->dev, "ipmi:dmi: Unable to add device: %d\n", rv); |
---|
160 | | - goto err; |
---|
161 | | - } |
---|
162 | | - |
---|
163 | | - ipmi_dmi_nr++; |
---|
164 | | - return; |
---|
165 | | - |
---|
166 | | -err: |
---|
167 | | - platform_device_put(pdev); |
---|
| 89 | + if (ipmi_platform_add(name, ipmi_dmi_nr, &p)) |
---|
| 90 | + ipmi_dmi_nr++; |
---|
168 | 91 | } |
---|
169 | 92 | |
---|
170 | 93 | /* |
---|
.. | .. |
---|
174 | 97 | * This function allows an ACPI-specified IPMI device to look up the |
---|
175 | 98 | * slave address from the DMI table. |
---|
176 | 99 | */ |
---|
177 | | -int ipmi_dmi_get_slave_addr(enum si_type si_type, u32 flags, |
---|
| 100 | +int ipmi_dmi_get_slave_addr(enum si_type si_type, unsigned int space, |
---|
178 | 101 | unsigned long base_addr) |
---|
179 | 102 | { |
---|
180 | 103 | struct ipmi_dmi_info *info = ipmi_dmi_infos; |
---|
181 | 104 | |
---|
182 | 105 | while (info) { |
---|
183 | 106 | if (info->si_type == si_type && |
---|
184 | | - info->flags == flags && |
---|
| 107 | + info->space == space && |
---|
185 | 108 | info->addr == base_addr) |
---|
186 | 109 | return info->slave_addr; |
---|
187 | 110 | info = info->next; |
---|
.. | .. |
---|
202 | 125 | |
---|
203 | 126 | static void __init dmi_decode_ipmi(const struct dmi_header *dm) |
---|
204 | 127 | { |
---|
205 | | - const u8 *data = (const u8 *) dm; |
---|
206 | | - u32 flags = IORESOURCE_IO; |
---|
207 | | - unsigned long base_addr; |
---|
208 | | - u8 len = dm->length; |
---|
209 | | - u8 slave_addr; |
---|
210 | | - int irq = 0, offset; |
---|
211 | | - int type; |
---|
| 128 | + const u8 *data = (const u8 *) dm; |
---|
| 129 | + int space = IPMI_IO_ADDR_SPACE; |
---|
| 130 | + unsigned long base_addr; |
---|
| 131 | + u8 len = dm->length; |
---|
| 132 | + u8 slave_addr; |
---|
| 133 | + int irq = 0, offset = 0; |
---|
| 134 | + int type; |
---|
212 | 135 | |
---|
213 | 136 | if (len < DMI_IPMI_MIN_LENGTH) |
---|
214 | 137 | return; |
---|
.. | .. |
---|
223 | 146 | } |
---|
224 | 147 | if (len >= DMI_IPMI_VER2_LENGTH) { |
---|
225 | 148 | if (type == IPMI_DMI_TYPE_SSIF) { |
---|
226 | | - offset = 0; |
---|
227 | | - flags = 0; |
---|
| 149 | + space = 0; /* Match I2C interface 0. */ |
---|
228 | 150 | base_addr = data[DMI_IPMI_ADDR] >> 1; |
---|
229 | 151 | if (base_addr == 0) { |
---|
230 | 152 | /* |
---|
.. | .. |
---|
241 | 163 | base_addr &= DMI_IPMI_IO_MASK; |
---|
242 | 164 | } else { |
---|
243 | 165 | /* Memory */ |
---|
244 | | - flags = IORESOURCE_MEM; |
---|
| 166 | + space = IPMI_MEM_ADDR_SPACE; |
---|
245 | 167 | } |
---|
246 | 168 | |
---|
247 | 169 | /* |
---|
.. | .. |
---|
267 | 189 | offset = 16; |
---|
268 | 190 | break; |
---|
269 | 191 | default: |
---|
270 | | - pr_err("ipmi:dmi: Invalid offset: 0\n"); |
---|
| 192 | + pr_err("Invalid offset: 0\n"); |
---|
271 | 193 | return; |
---|
272 | 194 | } |
---|
273 | 195 | } |
---|
.. | .. |
---|
285 | 207 | offset = 1; |
---|
286 | 208 | } |
---|
287 | 209 | |
---|
288 | | - dmi_add_platform_ipmi(base_addr, flags, slave_addr, irq, |
---|
| 210 | + dmi_add_platform_ipmi(base_addr, space, slave_addr, irq, |
---|
289 | 211 | offset, type); |
---|
290 | 212 | } |
---|
291 | 213 | |
---|