Skip to content

Commit 3cd83ba

Browse files
committed
ipmi: Consolidate the adding of platform devices
It was being done in two different places now that hard-coded devices use platform devices, and it's about to be three with hotmod switching to platform devices. So put the code in one place. This required some rework on some interfaces to make the type space clean. Signed-off-by: Corey Minyard <cminyard@mvista.com>
1 parent f6296bd commit 3cd83ba

9 files changed

Lines changed: 205 additions & 214 deletions

File tree

‎drivers/char/ipmi/Kconfig‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ menuconfig IPMI_HANDLER
1818
If unsure, say N.
1919

2020
config IPMI_DMI_DECODE
21+
select IPMI_PLAT_DATA
22+
bool
23+
24+
config IPMI_PLAT_DATA
2125
bool
2226

2327
if IPMI_HANDLER
@@ -56,6 +60,7 @@ config IPMI_DEVICE_INTERFACE
5660

5761
config IPMI_SI
5862
tristate 'IPMI System Interface handler'
63+
select IPMI_PLAT_DATA
5964
help
6065
Provides a driver for System Interfaces (KCS, SMIC, BT).
6166
Currently, only KCS and SMIC are supported. If

‎drivers/char/ipmi/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ obj-$(CONFIG_IPMI_HANDLER) += ipmi_msghandler.o
1717
obj-$(CONFIG_IPMI_DEVICE_INTERFACE) += ipmi_devintf.o
1818
obj-$(CONFIG_IPMI_SI) += ipmi_si.o
1919
obj-$(CONFIG_IPMI_DMI_DECODE) += ipmi_dmi.o
20+
obj-$(CONFIG_IPMI_PLAT_DATA) += ipmi_plat_data.o
2021
obj-$(CONFIG_IPMI_SSIF) += ipmi_ssif.o
2122
obj-$(CONFIG_IPMI_POWERNV) += ipmi_powernv.o
2223
obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o

‎drivers/char/ipmi/ipmi_dmi.c‎

Lines changed: 33 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/property.h>
1515
#include "ipmi_si_sm.h"
1616
#include "ipmi_dmi.h"
17+
#include "ipmi_plat_data.h"
1718

1819
#define IPMI_DMI_TYPE_KCS 0x01
1920
#define IPMI_DMI_TYPE_SMIC 0x02
@@ -22,7 +23,7 @@
2223

2324
struct ipmi_dmi_info {
2425
enum si_type si_type;
25-
u32 flags;
26+
unsigned int space; /* addr space for si, intf# for ssif */
2627
unsigned long addr;
2728
u8 slave_addr;
2829
struct ipmi_dmi_info *next;
@@ -33,133 +34,60 @@ static struct ipmi_dmi_info *ipmi_dmi_infos;
3334
static int ipmi_dmi_nr __initdata;
3435

3536
static void __init dmi_add_platform_ipmi(unsigned long base_addr,
36-
u32 flags,
37+
unsigned int space,
3738
u8 slave_addr,
3839
int irq,
3940
int offset,
4041
int type)
4142
{
42-
struct platform_device *pdev;
43-
struct resource r[4];
44-
unsigned int num_r = 1, size;
45-
struct property_entry p[5];
46-
unsigned int pidx = 0;
47-
char *name;
48-
int rv;
49-
enum si_type si_type;
43+
const char *name;
5044
struct ipmi_dmi_info *info;
45+
struct ipmi_plat_data p;
5146

52-
memset(p, 0, sizeof(p));
47+
memset(&p, 0, sizeof(p));
5348

5449
name = "dmi-ipmi-si";
5550
switch (type) {
5651
case IPMI_DMI_TYPE_SSIF:
5752
name = "dmi-ipmi-ssif";
58-
offset = 1;
59-
size = 1;
60-
si_type = SI_TYPE_INVALID;
53+
p.type = SI_TYPE_INVALID;
6154
break;
6255
case IPMI_DMI_TYPE_BT:
63-
size = 3;
64-
si_type = SI_BT;
56+
p.type = SI_BT;
6557
break;
6658
case IPMI_DMI_TYPE_KCS:
67-
size = 2;
68-
si_type = SI_KCS;
59+
p.type = SI_KCS;
6960
break;
7061
case IPMI_DMI_TYPE_SMIC:
71-
size = 2;
72-
si_type = SI_SMIC;
62+
p.type = SI_SMIC;
7363
break;
7464
default:
7565
pr_err("Invalid IPMI type: %d\n", type);
7666
return;
7767
}
7868

79-
if (si_type != SI_TYPE_INVALID)
80-
p[pidx++] = PROPERTY_ENTRY_U8("ipmi-type", si_type);
81-
82-
p[pidx++] = PROPERTY_ENTRY_U8("slave-addr", slave_addr);
83-
p[pidx++] = PROPERTY_ENTRY_U8("addr-source", SI_SMBIOS);
69+
memset(&p, 0, sizeof(p));
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;
8476

8577
info = kmalloc(sizeof(*info), GFP_KERNEL);
8678
if (!info) {
8779
pr_warn("Could not allocate dmi info\n");
8880
} else {
89-
info->si_type = si_type;
90-
info->flags = flags;
81+
info->si_type = p.type;
82+
info->space = space;
9183
info->addr = base_addr;
9284
info->slave_addr = slave_addr;
9385
info->next = ipmi_dmi_infos;
9486
ipmi_dmi_infos = info;
9587
}
9688

97-
pdev = platform_device_alloc(name, ipmi_dmi_nr);
98-
if (!pdev) {
99-
pr_err("Error allocation IPMI platform device\n");
100-
return;
101-
}
102-
103-
if (type == IPMI_DMI_TYPE_SSIF) {
104-
p[pidx++] = PROPERTY_ENTRY_U16("i2c-addr", base_addr);
105-
goto add_properties;
106-
}
107-
108-
memset(r, 0, sizeof(r));
109-
110-
r[0].start = base_addr;
111-
r[0].end = r[0].start + offset - 1;
112-
r[0].name = "IPMI Address 1";
113-
r[0].flags = flags;
114-
115-
if (size > 1) {
116-
r[1].start = r[0].start + offset;
117-
r[1].end = r[1].start + offset - 1;
118-
r[1].name = "IPMI Address 2";
119-
r[1].flags = flags;
120-
num_r++;
121-
}
122-
123-
if (size > 2) {
124-
r[2].start = r[1].start + offset;
125-
r[2].end = r[2].start + offset - 1;
126-
r[2].name = "IPMI Address 3";
127-
r[2].flags = flags;
128-
num_r++;
129-
}
130-
131-
if (irq) {
132-
r[num_r].start = irq;
133-
r[num_r].end = irq;
134-
r[num_r].name = "IPMI IRQ";
135-
r[num_r].flags = IORESOURCE_IRQ;
136-
num_r++;
137-
}
138-
139-
rv = platform_device_add_resources(pdev, r, num_r);
140-
if (rv) {
141-
dev_err(&pdev->dev, "Unable to add resources: %d\n", rv);
142-
goto err;
143-
}
144-
145-
add_properties:
146-
rv = platform_device_add_properties(pdev, p);
147-
if (rv) {
148-
dev_err(&pdev->dev, "Unable to add properties: %d\n", rv);
149-
goto err;
150-
}
151-
152-
rv = platform_device_add(pdev);
153-
if (rv) {
154-
dev_err(&pdev->dev, "Unable to add device: %d\n", rv);
155-
goto err;
156-
}
157-
158-
ipmi_dmi_nr++;
159-
return;
160-
161-
err:
162-
platform_device_put(pdev);
89+
if (ipmi_platform_add(name, ipmi_dmi_nr, &p))
90+
ipmi_dmi_nr++;
16391
}
16492

16593
/*
@@ -169,14 +97,14 @@ static void __init dmi_add_platform_ipmi(unsigned long base_addr,
16997
* This function allows an ACPI-specified IPMI device to look up the
17098
* slave address from the DMI table.
17199
*/
172-
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,
173101
unsigned long base_addr)
174102
{
175103
struct ipmi_dmi_info *info = ipmi_dmi_infos;
176104

177105
while (info) {
178106
if (info->si_type == si_type &&
179-
info->flags == flags &&
107+
info->space == space &&
180108
info->addr == base_addr)
181109
return info->slave_addr;
182110
info = info->next;
@@ -197,13 +125,13 @@ EXPORT_SYMBOL(ipmi_dmi_get_slave_addr);
197125

198126
static void __init dmi_decode_ipmi(const struct dmi_header *dm)
199127
{
200-
const u8 *data = (const u8 *) dm;
201-
u32 flags = IORESOURCE_IO;
202-
unsigned long base_addr;
203-
u8 len = dm->length;
204-
u8 slave_addr;
205-
int irq = 0, offset;
206-
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;
207135

208136
if (len < DMI_IPMI_MIN_LENGTH)
209137
return;
@@ -218,8 +146,7 @@ static void __init dmi_decode_ipmi(const struct dmi_header *dm)
218146
}
219147
if (len >= DMI_IPMI_VER2_LENGTH) {
220148
if (type == IPMI_DMI_TYPE_SSIF) {
221-
offset = 0;
222-
flags = 0;
149+
space = 0; /* Match I2C interface 0. */
223150
base_addr = data[DMI_IPMI_ADDR] >> 1;
224151
if (base_addr == 0) {
225152
/*
@@ -236,7 +163,7 @@ static void __init dmi_decode_ipmi(const struct dmi_header *dm)
236163
base_addr &= DMI_IPMI_IO_MASK;
237164
} else {
238165
/* Memory */
239-
flags = IORESOURCE_MEM;
166+
space = IPMI_MEM_ADDR_SPACE;
240167
}
241168

242169
/*
@@ -280,7 +207,7 @@ static void __init dmi_decode_ipmi(const struct dmi_header *dm)
280207
offset = 1;
281208
}
282209

283-
dmi_add_platform_ipmi(base_addr, flags, slave_addr, irq,
210+
dmi_add_platform_ipmi(base_addr, space, slave_addr, irq,
284211
offset, type);
285212
}
286213

‎drivers/char/ipmi/ipmi_dmi.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
*/
55

66
#ifdef CONFIG_IPMI_DMI_DECODE
7-
int ipmi_dmi_get_slave_addr(enum si_type si_type, u32 flags,
7+
int ipmi_dmi_get_slave_addr(enum si_type si_type, unsigned int space,
88
unsigned long base_addr);
99
#endif

‎drivers/char/ipmi/ipmi_plat_data.c‎

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
3+
/*
4+
* Add an IPMI platform device.
5+
*/
6+
7+
#include <linux/platform_device.h>
8+
#include "ipmi_plat_data.h"
9+
#include "ipmi_si.h"
10+
11+
struct platform_device *ipmi_platform_add(const char *name, unsigned int inst,
12+
struct ipmi_plat_data *p)
13+
{
14+
struct platform_device *pdev;
15+
unsigned int num_r = 1, size, pidx = 0;
16+
struct resource r[4];
17+
struct property_entry pr[6];
18+
u32 flags;
19+
int rv;
20+
21+
memset(pr, 0, sizeof(pr));
22+
memset(r, 0, sizeof(r));
23+
24+
if (p->type == SI_BT)
25+
size = 3;
26+
else if (p->type == SI_TYPE_INVALID)
27+
size = 0;
28+
else
29+
size = 2;
30+
31+
if (p->regsize == 0)
32+
p->regsize = DEFAULT_REGSIZE;
33+
if (p->regspacing == 0)
34+
p->regspacing = p->regsize;
35+
36+
pr[pidx++] = PROPERTY_ENTRY_U8("ipmi-type", p->type);
37+
if (p->slave_addr)
38+
pr[pidx++] = PROPERTY_ENTRY_U8("slave-addr", p->slave_addr);
39+
pr[pidx++] = PROPERTY_ENTRY_U8("addr-source", p->addr_source);
40+
if (p->regshift)
41+
pr[pidx++] = PROPERTY_ENTRY_U8("reg-shift", p->regshift);
42+
pr[pidx++] = PROPERTY_ENTRY_U8("reg-size", p->regsize);
43+
/* Last entry must be left NULL to terminate it. */
44+
45+
pdev = platform_device_alloc(name, inst);
46+
if (!pdev) {
47+
pr_err("Error allocating IPMI platform device %s.%d\n",
48+
name, inst);
49+
return NULL;
50+
}
51+
52+
if (size == 0)
53+
/* An invalid or SSIF interface, no resources. */
54+
goto add_properties;
55+
56+
/*
57+
* Register spacing is derived from the resources in
58+
* the IPMI platform code.
59+
*/
60+
61+
if (p->space == IPMI_IO_ADDR_SPACE)
62+
flags = IORESOURCE_IO;
63+
else
64+
flags = IORESOURCE_MEM;
65+
66+
r[0].start = p->addr;
67+
r[0].end = r[0].start + p->regsize - 1;
68+
r[0].name = "IPMI Address 1";
69+
r[0].flags = flags;
70+
71+
if (size > 1) {
72+
r[1].start = r[0].start + p->regspacing;
73+
r[1].end = r[1].start + p->regsize - 1;
74+
r[1].name = "IPMI Address 2";
75+
r[1].flags = flags;
76+
num_r++;
77+
}
78+
79+
if (size > 2) {
80+
r[2].start = r[1].start + p->regspacing;
81+
r[2].end = r[2].start + p->regsize - 1;
82+
r[2].name = "IPMI Address 3";
83+
r[2].flags = flags;
84+
num_r++;
85+
}
86+
87+
if (p->irq) {
88+
r[num_r].start = p->irq;
89+
r[num_r].end = p->irq;
90+
r[num_r].name = "IPMI IRQ";
91+
r[num_r].flags = IORESOURCE_IRQ;
92+
num_r++;
93+
}
94+
95+
rv = platform_device_add_resources(pdev, r, num_r);
96+
if (rv) {
97+
dev_err(&pdev->dev,
98+
"Unable to add hard-code resources: %d\n", rv);
99+
goto err;
100+
}
101+
add_properties:
102+
rv = platform_device_add_properties(pdev, pr);
103+
if (rv) {
104+
dev_err(&pdev->dev,
105+
"Unable to add hard-code properties: %d\n", rv);
106+
goto err;
107+
}
108+
109+
rv = platform_device_add(pdev);
110+
if (rv) {
111+
dev_err(&pdev->dev,
112+
"Unable to add hard-code device: %d\n", rv);
113+
goto err;
114+
}
115+
return pdev;
116+
117+
err:
118+
platform_device_put(pdev);
119+
return NULL;
120+
}
121+
EXPORT_SYMBOL(ipmi_platform_add);

0 commit comments

Comments
 (0)