hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/char/ipmi/ipmi_si_platform.c
....@@ -5,6 +5,10 @@
55 * Handling for platform devices in IPMI (ACPI, OF, and things
66 * coming from the platform.
77 */
8
+
9
+#define pr_fmt(fmt) "ipmi_platform: " fmt
10
+#define dev_fmt pr_fmt
11
+
812 #include <linux/types.h>
913 #include <linux/module.h>
1014 #include <linux/of_device.h>
....@@ -15,8 +19,7 @@
1519 #include "ipmi_si.h"
1620 #include "ipmi_dmi.h"
1721
18
-#define PFX "ipmi_platform: "
19
-
22
+static bool platform_registered;
2023 static bool si_tryplatform = true;
2124 #ifdef CONFIG_ACPI
2225 static bool si_tryacpi = true;
....@@ -105,11 +108,11 @@
105108
106109 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
107110 if (res) {
108
- io->addr_type = IPMI_IO_ADDR_SPACE;
111
+ io->addr_space = IPMI_IO_ADDR_SPACE;
109112 } else {
110113 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
111114 if (res)
112
- io->addr_type = IPMI_MEM_ADDR_SPACE;
115
+ io->addr_space = IPMI_MEM_ADDR_SPACE;
113116 }
114117 if (!res) {
115118 dev_err(&pdev->dev, "no I/O or memory address\n");
....@@ -119,7 +122,7 @@
119122
120123 io->regspacing = DEFAULT_REGSPACING;
121124 res_second = platform_get_resource(pdev,
122
- (io->addr_type == IPMI_IO_ADDR_SPACE) ?
125
+ (io->addr_space == IPMI_IO_ADDR_SPACE) ?
123126 IORESOURCE_IO : IORESOURCE_MEM,
124127 1);
125128 if (res_second) {
....@@ -156,7 +159,7 @@
156159
157160 memset(&io, 0, sizeof(io));
158161 io.addr_source = addr_source;
159
- dev_info(&pdev->dev, PFX "probing via %s\n",
162
+ dev_info(&pdev->dev, "probing via %s\n",
160163 ipmi_addr_src_to_str(addr_source));
161164
162165 switch (type) {
....@@ -186,14 +189,12 @@
186189 return -EINVAL;
187190
188191 rv = device_property_read_u8(&pdev->dev, "slave-addr", &slave_addr);
189
- if (rv) {
190
- dev_warn(&pdev->dev, "device has no slave-addr property\n");
192
+ if (rv)
191193 io.slave_addr = 0x20;
192
- } else {
194
+ else
193195 io.slave_addr = slave_addr;
194
- }
195196
196
- io.irq = platform_get_irq(pdev, 0);
197
+ io.irq = platform_get_irq_optional(pdev, 0);
197198 if (io.irq > 0)
198199 io.irq_setup = ipmi_std_irq_setup;
199200 else
....@@ -203,7 +204,7 @@
203204
204205 pr_info("ipmi_si: %s: %s %#lx regsize %d spacing %d irq %d\n",
205206 ipmi_addr_src_to_str(addr_source),
206
- (io.addr_type == IPMI_IO_ADDR_SPACE) ? "io" : "mem",
207
+ (io.addr_space == IPMI_IO_ADDR_SPACE) ? "io" : "mem",
207208 io.addr_data, io.regsize, io.regspacing, io.irq);
208209
209210 ipmi_si_add_smi(&io);
....@@ -247,25 +248,25 @@
247248
248249 ret = of_address_to_resource(np, 0, &resource);
249250 if (ret) {
250
- dev_warn(&pdev->dev, PFX "invalid address from OF\n");
251
+ dev_warn(&pdev->dev, "invalid address from OF\n");
251252 return ret;
252253 }
253254
254255 regsize = of_get_property(np, "reg-size", &proplen);
255256 if (regsize && proplen != 4) {
256
- dev_warn(&pdev->dev, PFX "invalid regsize from OF\n");
257
+ dev_warn(&pdev->dev, "invalid regsize from OF\n");
257258 return -EINVAL;
258259 }
259260
260261 regspacing = of_get_property(np, "reg-spacing", &proplen);
261262 if (regspacing && proplen != 4) {
262
- dev_warn(&pdev->dev, PFX "invalid regspacing from OF\n");
263
+ dev_warn(&pdev->dev, "invalid regspacing from OF\n");
263264 return -EINVAL;
264265 }
265266
266267 regshift = of_get_property(np, "reg-shift", &proplen);
267268 if (regshift && proplen != 4) {
268
- dev_warn(&pdev->dev, PFX "invalid regshift from OF\n");
269
+ dev_warn(&pdev->dev, "invalid regshift from OF\n");
269270 return -EINVAL;
270271 }
271272
....@@ -275,9 +276,9 @@
275276 io.irq_setup = ipmi_std_irq_setup;
276277
277278 if (resource.flags & IORESOURCE_IO)
278
- io.addr_type = IPMI_IO_ADDR_SPACE;
279
+ io.addr_space = IPMI_IO_ADDR_SPACE;
279280 else
280
- io.addr_type = IPMI_MEM_ADDR_SPACE;
281
+ io.addr_space = IPMI_MEM_ADDR_SPACE;
281282
282283 io.addr_data = resource.start;
283284
....@@ -305,15 +306,10 @@
305306 static int find_slave_address(struct si_sm_io *io, int slave_addr)
306307 {
307308 #ifdef CONFIG_IPMI_DMI_DECODE
308
- if (!slave_addr) {
309
- u32 flags = IORESOURCE_IO;
310
-
311
- if (io->addr_type == IPMI_MEM_ADDR_SPACE)
312
- flags = IORESOURCE_MEM;
313
-
314
- slave_addr = ipmi_dmi_get_slave_addr(io->si_type, flags,
309
+ if (!slave_addr)
310
+ slave_addr = ipmi_dmi_get_slave_addr(io->si_type,
311
+ io->addr_space,
315312 io->addr_data);
316
- }
317313 #endif
318314
319315 return slave_addr;
....@@ -337,7 +333,7 @@
337333
338334 memset(&io, 0, sizeof(io));
339335 io.addr_source = SI_ACPI;
340
- dev_info(&pdev->dev, PFX "probing via ACPI\n");
336
+ dev_info(&pdev->dev, "probing via ACPI\n");
341337
342338 io.addr_info.acpi_info.acpi_handle = handle;
343339
....@@ -382,7 +378,7 @@
382378 io.irq = tmp;
383379 io.irq_setup = acpi_gpe_irq_setup;
384380 } else {
385
- int irq = platform_get_irq(pdev, 0);
381
+ int irq = platform_get_irq_optional(pdev, 0);
386382
387383 if (irq > 0) {
388384 io.irq = irq;
....@@ -396,6 +392,8 @@
396392
397393 dev_info(io.dev, "%pR regsize %d spacing %d irq %d\n",
398394 res, io.regsize, io.regspacing, io.irq);
395
+
396
+ request_module("acpi_ipmi");
399397
400398 return ipmi_si_add_smi(&io);
401399
....@@ -431,14 +429,37 @@
431429 return ipmi_si_remove_by_dev(&pdev->dev);
432430 }
433431
432
+static int pdev_match_name(struct device *dev, const void *data)
433
+{
434
+ struct platform_device *pdev = to_platform_device(dev);
435
+ const char *name = data;
436
+
437
+ return strcmp(pdev->name, name) == 0;
438
+}
439
+
440
+void ipmi_remove_platform_device_by_name(char *name)
441
+{
442
+ struct device *dev;
443
+
444
+ while ((dev = bus_find_device(&platform_bus_type, NULL, name,
445
+ pdev_match_name))) {
446
+ struct platform_device *pdev = to_platform_device(dev);
447
+
448
+ platform_device_unregister(pdev);
449
+ put_device(dev);
450
+ }
451
+}
452
+
434453 static const struct platform_device_id si_plat_ids[] = {
435
- { "hardcode-ipmi-si", 0 },
436
- { }
454
+ { "dmi-ipmi-si", 0 },
455
+ { "hardcode-ipmi-si", 0 },
456
+ { "hotmod-ipmi-si", 0 },
457
+ { }
437458 };
438459
439460 struct platform_driver ipmi_platform_driver = {
440461 .driver = {
441
- .name = DEVICE_NAME,
462
+ .name = SI_DEVICE_NAME,
442463 .of_match_table = of_ipmi_match,
443464 .acpi_match_table = ACPI_PTR(acpi_ipmi_match),
444465 },
....@@ -451,10 +472,13 @@
451472 {
452473 int rv = platform_driver_register(&ipmi_platform_driver);
453474 if (rv)
454
- pr_err(PFX "Unable to register driver: %d\n", rv);
475
+ pr_err("Unable to register driver: %d\n", rv);
476
+ else
477
+ platform_registered = true;
455478 }
456479
457480 void ipmi_si_platform_shutdown(void)
458481 {
459
- platform_driver_unregister(&ipmi_platform_driver);
482
+ if (platform_registered)
483
+ platform_driver_unregister(&ipmi_platform_driver);
460484 }