Skip to content

Commit 29473ec

Browse files
committed
Merge branch 'topic/yinghai-hostbridge-cleanup' into next
2 parents 977f857 + c57ca65 commit 29473ec

10 files changed

Lines changed: 304 additions & 267 deletions

File tree

‎arch/x86/pci/acpi.c‎

Lines changed: 71 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
struct pci_root_info {
1111
struct acpi_device *bridge;
12-
char *name;
12+
char name[16];
1313
unsigned int res_num;
1414
struct resource *res;
15-
struct list_head *resources;
1615
int busnum;
16+
struct pci_sysdata sd;
1717
};
1818

1919
static bool pci_use_crs = true;
@@ -287,7 +287,8 @@ static void coalesce_windows(struct pci_root_info *info, unsigned long type)
287287
}
288288
}
289289

290-
static void add_resources(struct pci_root_info *info)
290+
static void add_resources(struct pci_root_info *info,
291+
struct list_head *resources)
291292
{
292293
int i;
293294
struct resource *res, *root, *conflict;
@@ -311,53 +312,74 @@ static void add_resources(struct pci_root_info *info)
311312
"ignoring host bridge window %pR (conflicts with %s %pR)\n",
312313
res, conflict->name, conflict);
313314
else
314-
pci_add_resource(info->resources, res);
315+
pci_add_resource(resources, res);
315316
}
316317
}
317318

319+
static void free_pci_root_info_res(struct pci_root_info *info)
320+
{
321+
kfree(info->res);
322+
info->res = NULL;
323+
info->res_num = 0;
324+
}
325+
326+
static void __release_pci_root_info(struct pci_root_info *info)
327+
{
328+
int i;
329+
struct resource *res;
330+
331+
for (i = 0; i < info->res_num; i++) {
332+
res = &info->res[i];
333+
334+
if (!res->parent)
335+
continue;
336+
337+
if (!(res->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
338+
continue;
339+
340+
release_resource(res);
341+
}
342+
343+
free_pci_root_info_res(info);
344+
345+
kfree(info);
346+
}
347+
static void release_pci_root_info(struct pci_host_bridge *bridge)
348+
{
349+
struct pci_root_info *info = bridge->release_data;
350+
351+
__release_pci_root_info(info);
352+
}
353+
318354
static void
319-
get_current_resources(struct acpi_device *device, int busnum,
320-
int domain, struct list_head *resources)
355+
probe_pci_root_info(struct pci_root_info *info, struct acpi_device *device,
356+
int busnum, int domain)
321357
{
322-
struct pci_root_info info;
323358
size_t size;
324359

325-
info.bridge = device;
326-
info.res_num = 0;
327-
info.resources = resources;
360+
info->bridge = device;
361+
info->res_num = 0;
328362
acpi_walk_resources(device->handle, METHOD_NAME__CRS, count_resource,
329-
&info);
330-
if (!info.res_num)
363+
info);
364+
if (!info->res_num)
331365
return;
332366

333-
size = sizeof(*info.res) * info.res_num;
334-
info.res = kmalloc(size, GFP_KERNEL);
335-
if (!info.res)
367+
size = sizeof(*info->res) * info->res_num;
368+
info->res_num = 0;
369+
info->res = kmalloc(size, GFP_KERNEL);
370+
if (!info->res)
336371
return;
337372

338-
info.name = kasprintf(GFP_KERNEL, "PCI Bus %04x:%02x", domain, busnum);
339-
if (!info.name)
340-
goto name_alloc_fail;
373+
sprintf(info->name, "PCI Bus %04x:%02x", domain, busnum);
341374

342-
info.res_num = 0;
343375
acpi_walk_resources(device->handle, METHOD_NAME__CRS, setup_resource,
344-
&info);
345-
346-
if (pci_use_crs) {
347-
add_resources(&info);
348-
349-
return;
350-
}
351-
352-
kfree(info.name);
353-
354-
name_alloc_fail:
355-
kfree(info.res);
376+
info);
356377
}
357378

358379
struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_pci_root *root)
359380
{
360381
struct acpi_device *device = root->device;
382+
struct pci_root_info *info = NULL;
361383
int domain = root->segment;
362384
int busnum = root->secondary.start;
363385
LIST_HEAD(resources);
@@ -389,17 +411,14 @@ struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_pci_root *root)
389411
if (node != -1 && !node_online(node))
390412
node = -1;
391413

392-
/* Allocate per-root-bus (not per bus) arch-specific data.
393-
* TODO: leak; this memory is never freed.
394-
* It's arguable whether it's worth the trouble to care.
395-
*/
396-
sd = kzalloc(sizeof(*sd), GFP_KERNEL);
397-
if (!sd) {
414+
info = kzalloc(sizeof(*info), GFP_KERNEL);
415+
if (!info) {
398416
printk(KERN_WARNING "pci_bus %04x:%02x: "
399417
"ignored (out of memory)\n", domain, busnum);
400418
return NULL;
401419
}
402420

421+
sd = &info->sd;
403422
sd->domain = domain;
404423
sd->node = node;
405424
/*
@@ -413,22 +432,32 @@ struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_pci_root *root)
413432
* be replaced by sd.
414433
*/
415434
memcpy(bus->sysdata, sd, sizeof(*sd));
416-
kfree(sd);
435+
kfree(info);
417436
} else {
418-
get_current_resources(device, busnum, domain, &resources);
437+
probe_pci_root_info(info, device, busnum, domain);
419438

420439
/*
421440
* _CRS with no apertures is normal, so only fall back to
422441
* defaults or native bridge info if we're ignoring _CRS.
423442
*/
424-
if (!pci_use_crs)
443+
if (pci_use_crs)
444+
add_resources(info, &resources);
445+
else {
446+
free_pci_root_info_res(info);
425447
x86_pci_root_bus_resources(busnum, &resources);
448+
}
449+
426450
bus = pci_create_root_bus(NULL, busnum, &pci_root_ops, sd,
427451
&resources);
428-
if (bus)
452+
if (bus) {
429453
bus->subordinate = pci_scan_child_bus(bus);
430-
else
454+
pci_set_host_bridge_release(
455+
to_pci_host_bridge(bus->bridge),
456+
release_pci_root_info, info);
457+
} else {
431458
pci_free_resource_list(&resources);
459+
__release_pci_root_info(info);
460+
}
432461
}
433462

434463
/* After the PCI-E bus has been walked and all devices discovered,
@@ -445,9 +474,6 @@ struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_pci_root *root)
445474
}
446475
}
447476

448-
if (!bus)
449-
kfree(sd);
450-
451477
if (bus && node != -1) {
452478
#ifdef CONFIG_ACPI_NUMA
453479
if (pxm >= 0)

‎arch/x86/pci/amd_bus.c‎

Lines changed: 27 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ static struct pci_hostbridge_probe pci_probes[] __initdata = {
3232

3333
#define RANGE_NUM 16
3434

35+
static struct pci_root_info __init *find_pci_root_info(int node, int link)
36+
{
37+
struct pci_root_info *info;
38+
39+
/* find the position */
40+
list_for_each_entry(info, &pci_root_infos, list)
41+
if (info->node == node && info->link == link)
42+
return info;
43+
44+
return NULL;
45+
}
46+
3547
/**
3648
* early_fill_mp_bus_to_node()
3749
* called before pcibios_scan_root and pci_scan_bus
@@ -50,7 +62,6 @@ static int __init early_fill_mp_bus_info(void)
5062
int def_link;
5163
struct pci_root_info *info;
5264
u32 reg;
53-
struct resource *res;
5465
u64 start;
5566
u64 end;
5667
struct range range[RANGE_NUM];
@@ -86,7 +97,6 @@ static int __init early_fill_mp_bus_info(void)
8697
if (!found)
8798
return 0;
8899

89-
pci_root_num = 0;
90100
for (i = 0; i < 4; i++) {
91101
int min_bus;
92102
int max_bus;
@@ -105,13 +115,8 @@ static int __init early_fill_mp_bus_info(void)
105115
#endif
106116
link = (reg >> 8) & 0x03;
107117

108-
info = &pci_root_info[pci_root_num];
109-
info->bus_min = min_bus;
110-
info->bus_max = max_bus;
111-
info->node = node;
112-
info->link = link;
118+
info = alloc_pci_root_info(min_bus, max_bus, node, link);
113119
sprintf(info->name, "PCI Bus #%02x", min_bus);
114-
pci_root_num++;
115120
}
116121

117122
/* get the default node and link for left over res */
@@ -134,16 +139,10 @@ static int __init early_fill_mp_bus_info(void)
134139
link = (reg >> 4) & 0x03;
135140
end = (reg & 0xfff000) | 0xfff;
136141

137-
/* find the position */
138-
for (j = 0; j < pci_root_num; j++) {
139-
info = &pci_root_info[j];
140-
if (info->node == node && info->link == link)
141-
break;
142-
}
143-
if (j == pci_root_num)
142+
info = find_pci_root_info(node, link);
143+
if (!info)
144144
continue; /* not found */
145145

146-
info = &pci_root_info[j];
147146
printk(KERN_DEBUG "node %d link %d: io port [%llx, %llx]\n",
148147
node, link, start, end);
149148

@@ -155,13 +154,8 @@ static int __init early_fill_mp_bus_info(void)
155154
}
156155
/* add left over io port range to def node/link, [0, 0xffff] */
157156
/* find the position */
158-
for (j = 0; j < pci_root_num; j++) {
159-
info = &pci_root_info[j];
160-
if (info->node == def_node && info->link == def_link)
161-
break;
162-
}
163-
if (j < pci_root_num) {
164-
info = &pci_root_info[j];
157+
info = find_pci_root_info(def_node, def_link);
158+
if (info) {
165159
for (i = 0; i < RANGE_NUM; i++) {
166160
if (!range[i].end)
167161
continue;
@@ -214,16 +208,10 @@ static int __init early_fill_mp_bus_info(void)
214208
end <<= 8;
215209
end |= 0xffff;
216210

217-
/* find the position */
218-
for (j = 0; j < pci_root_num; j++) {
219-
info = &pci_root_info[j];
220-
if (info->node == node && info->link == link)
221-
break;
222-
}
223-
if (j == pci_root_num)
224-
continue; /* not found */
211+
info = find_pci_root_info(node, link);
225212

226-
info = &pci_root_info[j];
213+
if (!info)
214+
continue;
227215

228216
printk(KERN_DEBUG "node %d link %d: mmio [%llx, %llx]",
229217
node, link, start, end);
@@ -291,14 +279,8 @@ static int __init early_fill_mp_bus_info(void)
291279
* add left over mmio range to def node/link ?
292280
* that is tricky, just record range in from start_min to 4G
293281
*/
294-
for (j = 0; j < pci_root_num; j++) {
295-
info = &pci_root_info[j];
296-
if (info->node == def_node && info->link == def_link)
297-
break;
298-
}
299-
if (j < pci_root_num) {
300-
info = &pci_root_info[j];
301-
282+
info = find_pci_root_info(def_node, def_link);
283+
if (info) {
302284
for (i = 0; i < RANGE_NUM; i++) {
303285
if (!range[i].end)
304286
continue;
@@ -309,20 +291,16 @@ static int __init early_fill_mp_bus_info(void)
309291
}
310292
}
311293

312-
for (i = 0; i < pci_root_num; i++) {
313-
int res_num;
294+
list_for_each_entry(info, &pci_root_infos, list) {
314295
int busnum;
296+
struct pci_root_res *root_res;
315297

316-
info = &pci_root_info[i];
317-
res_num = info->res_num;
318298
busnum = info->bus_min;
319299
printk(KERN_DEBUG "bus: [%02x, %02x] on node %x link %x\n",
320300
info->bus_min, info->bus_max, info->node, info->link);
321-
for (j = 0; j < res_num; j++) {
322-
res = &info->res[j];
323-
printk(KERN_DEBUG "bus: %02x index %x %pR\n",
324-
busnum, j, res);
325-
}
301+
list_for_each_entry(root_res, &info->resources, list)
302+
printk(KERN_DEBUG "bus: %02x %pR\n",
303+
busnum, &root_res->res);
326304
}
327305

328306
return 0;

‎arch/x86/pci/broadcom_bus.c‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,15 @@
2222
static void __init cnb20le_res(u8 bus, u8 slot, u8 func)
2323
{
2424
struct pci_root_info *info;
25+
struct pci_root_res *root_res;
2526
struct resource res;
2627
u16 word1, word2;
2728
u8 fbus, lbus;
28-
int i;
29-
30-
info = &pci_root_info[pci_root_num];
31-
pci_root_num++;
3229

3330
/* read the PCI bus numbers */
3431
fbus = read_pci_config_byte(bus, slot, func, 0x44);
3532
lbus = read_pci_config_byte(bus, slot, func, 0x45);
36-
info->bus_min = fbus;
37-
info->bus_max = lbus;
33+
info = alloc_pci_root_info(fbus, lbus, 0, 0);
3834

3935
/*
4036
* Add the legacy IDE ports on bus 0
@@ -86,8 +82,8 @@ static void __init cnb20le_res(u8 bus, u8 slot, u8 func)
8682
res.flags = IORESOURCE_BUS;
8783
printk(KERN_INFO "CNB20LE PCI Host Bridge (domain 0000 %pR)\n", &res);
8884

89-
for (i = 0; i < info->res_num; i++)
90-
printk(KERN_INFO "host bridge window %pR\n", &info->res[i]);
85+
list_for_each_entry(root_res, &info->resources, list)
86+
printk(KERN_INFO "host bridge window %pR\n", &root_res->res);
9187
}
9288

9389
static int __init broadcom_postcore_init(void)

0 commit comments

Comments
 (0)