Skip to content

Commit ffc7bb3

Browse files
Andreas Wernergregkh
authored andcommitted
mcb: Added bar descriptor support for non PCI bus MCB carrier
Added support for the bar descriptor. This type is used for FPGAs connect to the LPC or to a non PCI bus. The Bar descriptor could have a maximum of 6 BARs. Each of the devices within the FPGA could be mapped to a different BAR. The BAR descriptor is comparable to the PCI header. Signed-off-by: Andreas Werner <andreas.werner@men.de> [ free bar descriptor in the non-error case ] Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 73edc8f commit ffc7bb3

2 files changed

Lines changed: 121 additions & 14 deletions

File tree

‎drivers/mcb/mcb-internal.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ struct chameleon_bdd {
112112
u32 size;
113113
} __packed;
114114

115+
struct chameleon_bar {
116+
u32 addr;
117+
u32 size;
118+
};
119+
120+
#define BAR_CNT(x) ((x) & 0x07)
121+
#define CHAMELEON_BAR_MAX 6
122+
#define BAR_DESC_SIZE(x) ((x) * sizeof(struct chameleon_bar) + sizeof(__le32))
123+
115124
int chameleon_parse_cells(struct mcb_bus *bus, phys_addr_t mapbase,
116125
void __iomem *base);
117126

‎drivers/mcb/mcb-parse.c‎

Lines changed: 112 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,20 @@ static inline uint32_t get_next_dtype(void __iomem *p)
2626
}
2727

2828
static int chameleon_parse_bdd(struct mcb_bus *bus,
29-
phys_addr_t mapbase,
29+
struct chameleon_bar *cb,
3030
void __iomem *base)
3131
{
3232
return 0;
3333
}
3434

3535
static int chameleon_parse_gdd(struct mcb_bus *bus,
36-
phys_addr_t mapbase,
37-
void __iomem *base)
36+
struct chameleon_bar *cb,
37+
void __iomem *base, int bar_count)
3838
{
3939
struct chameleon_gdd __iomem *gdd =
4040
(struct chameleon_gdd __iomem *) base;
4141
struct mcb_device *mdev;
42+
u32 dev_mapbase;
4243
u32 offset;
4344
u32 size;
4445
int ret;
@@ -61,13 +62,39 @@ static int chameleon_parse_gdd(struct mcb_bus *bus,
6162
mdev->group = GDD_GRP(reg2);
6263
mdev->inst = GDD_INS(reg2);
6364

65+
/*
66+
* If the BAR is missing, dev_mapbase is zero, or if the
67+
* device is IO mapped we just print a warning and go on with the
68+
* next device, instead of completely stop the gdd parser
69+
*/
70+
if (mdev->bar > bar_count - 1) {
71+
pr_info("No BAR for 16z%03d\n", mdev->id);
72+
ret = 0;
73+
goto err;
74+
}
75+
76+
dev_mapbase = cb[mdev->bar].addr;
77+
if (!dev_mapbase) {
78+
pr_info("BAR not assigned for 16z%03d\n", mdev->id);
79+
ret = 0;
80+
goto err;
81+
}
82+
83+
if (dev_mapbase & 0x01) {
84+
pr_info("IO mapped Device (16z%03d) not yet supported\n",
85+
mdev->id);
86+
ret = 0;
87+
goto err;
88+
}
89+
6490
pr_debug("Found a 16z%03d\n", mdev->id);
6591

6692
mdev->irq.start = GDD_IRQ(reg1);
6793
mdev->irq.end = GDD_IRQ(reg1);
6894
mdev->irq.flags = IORESOURCE_IRQ;
6995

70-
mdev->mem.start = mapbase + offset;
96+
mdev->mem.start = dev_mapbase + offset;
97+
7198
mdev->mem.end = mdev->mem.start + size - 1;
7299
mdev->mem.flags = IORESOURCE_MEM;
73100

@@ -85,13 +112,76 @@ static int chameleon_parse_gdd(struct mcb_bus *bus,
85112
return ret;
86113
}
87114

115+
static void chameleon_parse_bar(void __iomem *base,
116+
struct chameleon_bar *cb, int bar_count)
117+
{
118+
char __iomem *p = base;
119+
int i;
120+
121+
/* skip reg1 */
122+
p += sizeof(__le32);
123+
124+
for (i = 0; i < bar_count; i++) {
125+
cb[i].addr = readl(p);
126+
cb[i].size = readl(p + 4);
127+
128+
p += sizeof(struct chameleon_bar);
129+
}
130+
}
131+
132+
static int chameleon_get_bar(char __iomem **base, phys_addr_t mapbase,
133+
struct chameleon_bar **cb)
134+
{
135+
struct chameleon_bar *c;
136+
int bar_count;
137+
__le32 reg;
138+
u32 dtype;
139+
140+
/*
141+
* For those devices which are not connected
142+
* to the PCI Bus (e.g. LPC) there is a bar
143+
* descriptor located directly after the
144+
* chameleon header. This header is comparable
145+
* to a PCI header.
146+
*/
147+
dtype = get_next_dtype(*base);
148+
if (dtype == CHAMELEON_DTYPE_BAR) {
149+
reg = readl(*base);
150+
151+
bar_count = BAR_CNT(reg);
152+
if (bar_count <= 0 && bar_count > CHAMELEON_BAR_MAX)
153+
return -ENODEV;
154+
155+
c = kcalloc(bar_count, sizeof(struct chameleon_bar),
156+
GFP_KERNEL);
157+
if (!c)
158+
return -ENOMEM;
159+
160+
chameleon_parse_bar(*base, c, bar_count);
161+
*base += BAR_DESC_SIZE(bar_count);
162+
} else {
163+
c = kzalloc(sizeof(struct chameleon_bar), GFP_KERNEL);
164+
if (!c)
165+
return -ENOMEM;
166+
167+
bar_count = 1;
168+
c->addr = mapbase;
169+
}
170+
171+
*cb = c;
172+
173+
return bar_count;
174+
}
175+
88176
int chameleon_parse_cells(struct mcb_bus *bus, phys_addr_t mapbase,
89177
void __iomem *base)
90178
{
91-
char __iomem *p = base;
92179
struct chameleon_fpga_header *header;
93-
uint32_t dtype;
180+
struct chameleon_bar *cb;
181+
char __iomem *p = base;
94182
int num_cells = 0;
183+
uint32_t dtype;
184+
int bar_count;
95185
int ret = 0;
96186
u32 hsize;
97187

@@ -108,8 +198,8 @@ int chameleon_parse_cells(struct mcb_bus *bus, phys_addr_t mapbase,
108198
if (header->magic != CHAMELEONV2_MAGIC) {
109199
pr_err("Unsupported chameleon version 0x%x\n",
110200
header->magic);
111-
kfree(header);
112-
return -ENODEV;
201+
ret = -ENODEV;
202+
goto free_header;
113203
}
114204
p += hsize;
115205

@@ -119,37 +209,45 @@ int chameleon_parse_cells(struct mcb_bus *bus, phys_addr_t mapbase,
119209
snprintf(bus->name, CHAMELEON_FILENAME_LEN + 1, "%s",
120210
header->filename);
121211

212+
bar_count = chameleon_get_bar(&p, mapbase, &cb);
213+
if (bar_count < 0)
214+
goto free_header;
215+
122216
for_each_chameleon_cell(dtype, p) {
123217
switch (dtype) {
124218
case CHAMELEON_DTYPE_GENERAL:
125-
ret = chameleon_parse_gdd(bus, mapbase, p);
219+
ret = chameleon_parse_gdd(bus, cb, p, bar_count);
126220
if (ret < 0)
127-
goto out;
221+
goto free_bar;
128222
p += sizeof(struct chameleon_gdd);
129223
break;
130224
case CHAMELEON_DTYPE_BRIDGE:
131-
chameleon_parse_bdd(bus, mapbase, p);
225+
chameleon_parse_bdd(bus, cb, p);
132226
p += sizeof(struct chameleon_bdd);
133227
break;
134228
case CHAMELEON_DTYPE_END:
135229
break;
136230
default:
137231
pr_err("Invalid chameleon descriptor type 0x%x\n",
138232
dtype);
139-
kfree(header);
140-
return -EINVAL;
233+
ret = -EINVAL;
234+
goto free_bar;
141235
}
142236
num_cells++;
143237
}
144238

145239
if (num_cells == 0)
146240
num_cells = -EINVAL;
147241

242+
kfree(cb);
148243
kfree(header);
149244
return num_cells;
150245

151-
out:
246+
free_bar:
247+
kfree(cb);
248+
free_header:
152249
kfree(header);
250+
153251
return ret;
154252
}
155253
EXPORT_SYMBOL_GPL(chameleon_parse_cells);

0 commit comments

Comments
 (0)