x86/PCI: dynamically allocate pci_root_info for native host bridge drivers

This dynamically allocates struct pci_root_info instead of using a
static array.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
This commit is contained in:
Yinghai Lu 2012-04-02 18:31:54 -07:00 committed by Bjorn Helgaas
parent 35cb05e5bd
commit d28e5ac2a0
4 changed files with 90 additions and 89 deletions

View File

@ -32,6 +32,18 @@ static struct pci_hostbridge_probe pci_probes[] __initdata = {
#define RANGE_NUM 16 #define RANGE_NUM 16
static struct pci_root_info __init *find_pci_root_info(int node, int link)
{
struct pci_root_info *info;
/* find the position */
list_for_each_entry(info, &pci_root_infos, list)
if (info->node == node && info->link == link)
return info;
return NULL;
}
/** /**
* early_fill_mp_bus_to_node() * early_fill_mp_bus_to_node()
* called before pcibios_scan_root and pci_scan_bus * called before pcibios_scan_root and pci_scan_bus
@ -50,7 +62,6 @@ static int __init early_fill_mp_bus_info(void)
int def_link; int def_link;
struct pci_root_info *info; struct pci_root_info *info;
u32 reg; u32 reg;
struct resource *res;
u64 start; u64 start;
u64 end; u64 end;
struct range range[RANGE_NUM]; struct range range[RANGE_NUM];
@ -86,7 +97,6 @@ static int __init early_fill_mp_bus_info(void)
if (!found) if (!found)
return 0; return 0;
pci_root_num = 0;
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
int min_bus; int min_bus;
int max_bus; int max_bus;
@ -105,13 +115,8 @@ static int __init early_fill_mp_bus_info(void)
#endif #endif
link = (reg >> 8) & 0x03; link = (reg >> 8) & 0x03;
info = &pci_root_info[pci_root_num]; info = alloc_pci_root_info(min_bus, max_bus, node, link);
info->bus_min = min_bus;
info->bus_max = max_bus;
info->node = node;
info->link = link;
sprintf(info->name, "PCI Bus #%02x", min_bus); sprintf(info->name, "PCI Bus #%02x", min_bus);
pci_root_num++;
} }
/* get the default node and link for left over res */ /* get the default node and link for left over res */
@ -134,16 +139,10 @@ static int __init early_fill_mp_bus_info(void)
link = (reg >> 4) & 0x03; link = (reg >> 4) & 0x03;
end = (reg & 0xfff000) | 0xfff; end = (reg & 0xfff000) | 0xfff;
/* find the position */ info = find_pci_root_info(node, link);
for (j = 0; j < pci_root_num; j++) { if (!info)
info = &pci_root_info[j];
if (info->node == node && info->link == link)
break;
}
if (j == pci_root_num)
continue; /* not found */ continue; /* not found */
info = &pci_root_info[j];
printk(KERN_DEBUG "node %d link %d: io port [%llx, %llx]\n", printk(KERN_DEBUG "node %d link %d: io port [%llx, %llx]\n",
node, link, start, end); node, link, start, end);
@ -155,13 +154,8 @@ static int __init early_fill_mp_bus_info(void)
} }
/* add left over io port range to def node/link, [0, 0xffff] */ /* add left over io port range to def node/link, [0, 0xffff] */
/* find the position */ /* find the position */
for (j = 0; j < pci_root_num; j++) { info = find_pci_root_info(def_node, def_link);
info = &pci_root_info[j]; if (info) {
if (info->node == def_node && info->link == def_link)
break;
}
if (j < pci_root_num) {
info = &pci_root_info[j];
for (i = 0; i < RANGE_NUM; i++) { for (i = 0; i < RANGE_NUM; i++) {
if (!range[i].end) if (!range[i].end)
continue; continue;
@ -214,16 +208,10 @@ static int __init early_fill_mp_bus_info(void)
end <<= 8; end <<= 8;
end |= 0xffff; end |= 0xffff;
/* find the position */ info = find_pci_root_info(node, link);
for (j = 0; j < pci_root_num; j++) {
info = &pci_root_info[j];
if (info->node == node && info->link == link)
break;
}
if (j == pci_root_num)
continue; /* not found */
info = &pci_root_info[j]; if (!info)
continue;
printk(KERN_DEBUG "node %d link %d: mmio [%llx, %llx]", printk(KERN_DEBUG "node %d link %d: mmio [%llx, %llx]",
node, link, start, end); node, link, start, end);
@ -291,14 +279,8 @@ static int __init early_fill_mp_bus_info(void)
* add left over mmio range to def node/link ? * add left over mmio range to def node/link ?
* that is tricky, just record range in from start_min to 4G * that is tricky, just record range in from start_min to 4G
*/ */
for (j = 0; j < pci_root_num; j++) { info = find_pci_root_info(def_node, def_link);
info = &pci_root_info[j]; if (info) {
if (info->node == def_node && info->link == def_link)
break;
}
if (j < pci_root_num) {
info = &pci_root_info[j];
for (i = 0; i < RANGE_NUM; i++) { for (i = 0; i < RANGE_NUM; i++) {
if (!range[i].end) if (!range[i].end)
continue; continue;
@ -309,20 +291,16 @@ static int __init early_fill_mp_bus_info(void)
} }
} }
for (i = 0; i < pci_root_num; i++) { list_for_each_entry(info, &pci_root_infos, list) {
int res_num;
int busnum; int busnum;
struct pci_root_res *root_res;
info = &pci_root_info[i];
res_num = info->res_num;
busnum = info->bus_min; busnum = info->bus_min;
printk(KERN_DEBUG "bus: [%02x, %02x] on node %x link %x\n", printk(KERN_DEBUG "bus: [%02x, %02x] on node %x link %x\n",
info->bus_min, info->bus_max, info->node, info->link); info->bus_min, info->bus_max, info->node, info->link);
for (j = 0; j < res_num; j++) { list_for_each_entry(root_res, &info->resources, list)
res = &info->res[j]; printk(KERN_DEBUG "bus: %02x %pR\n",
printk(KERN_DEBUG "bus: %02x index %x %pR\n", busnum, &root_res->res);
busnum, j, res);
}
} }
return 0; return 0;

View File

@ -22,19 +22,15 @@
static void __init cnb20le_res(u8 bus, u8 slot, u8 func) static void __init cnb20le_res(u8 bus, u8 slot, u8 func)
{ {
struct pci_root_info *info; struct pci_root_info *info;
struct pci_root_res *root_res;
struct resource res; struct resource res;
u16 word1, word2; u16 word1, word2;
u8 fbus, lbus; u8 fbus, lbus;
int i;
info = &pci_root_info[pci_root_num];
pci_root_num++;
/* read the PCI bus numbers */ /* read the PCI bus numbers */
fbus = read_pci_config_byte(bus, slot, func, 0x44); fbus = read_pci_config_byte(bus, slot, func, 0x44);
lbus = read_pci_config_byte(bus, slot, func, 0x45); lbus = read_pci_config_byte(bus, slot, func, 0x45);
info->bus_min = fbus; info = alloc_pci_root_info(fbus, lbus, 0, 0);
info->bus_max = lbus;
/* /*
* Add the legacy IDE ports on bus 0 * Add the legacy IDE ports on bus 0
@ -86,8 +82,8 @@ static void __init cnb20le_res(u8 bus, u8 slot, u8 func)
res.flags = IORESOURCE_BUS; res.flags = IORESOURCE_BUS;
printk(KERN_INFO "CNB20LE PCI Host Bridge (domain 0000 %pR)\n", &res); printk(KERN_INFO "CNB20LE PCI Host Bridge (domain 0000 %pR)\n", &res);
for (i = 0; i < info->res_num; i++) list_for_each_entry(root_res, &info->resources, list)
printk(KERN_INFO "host bridge window %pR\n", &info->res[i]); printk(KERN_INFO "host bridge window %pR\n", &root_res->res);
} }
static int __init broadcom_postcore_init(void) static int __init broadcom_postcore_init(void)

View File

@ -4,35 +4,38 @@
#include "bus_numa.h" #include "bus_numa.h"
int pci_root_num; LIST_HEAD(pci_root_infos);
struct pci_root_info pci_root_info[PCI_ROOT_NR];
static struct pci_root_info *x86_find_pci_root_info(int bus)
{
struct pci_root_info *info;
if (list_empty(&pci_root_infos))
return NULL;
list_for_each_entry(info, &pci_root_infos, list)
if (info->bus_min == bus)
return info;
return NULL;
}
void x86_pci_root_bus_resources(int bus, struct list_head *resources) void x86_pci_root_bus_resources(int bus, struct list_head *resources)
{ {
int i; struct pci_root_info *info = x86_find_pci_root_info(bus);
int j; struct pci_root_res *root_res;
struct pci_root_info *info;
if (!pci_root_num) if (!info)
goto default_resources;
for (i = 0; i < pci_root_num; i++) {
if (pci_root_info[i].bus_min == bus)
break;
}
if (i == pci_root_num)
goto default_resources; goto default_resources;
printk(KERN_DEBUG "PCI: root bus %02x: hardware-probed resources\n", printk(KERN_DEBUG "PCI: root bus %02x: hardware-probed resources\n",
bus); bus);
info = &pci_root_info[i]; list_for_each_entry(root_res, &info->resources, list) {
for (j = 0; j < info->res_num; j++) {
struct resource *res; struct resource *res;
struct resource *root; struct resource *root;
res = &info->res[j]; res = &root_res->res;
pci_add_resource(resources, res); pci_add_resource(resources, res);
if (res->flags & IORESOURCE_IO) if (res->flags & IORESOURCE_IO)
root = &ioport_resource; root = &ioport_resource;
@ -53,11 +56,32 @@ default_resources:
pci_add_resource(resources, &iomem_resource); pci_add_resource(resources, &iomem_resource);
} }
struct pci_root_info __init *alloc_pci_root_info(int bus_min, int bus_max,
int node, int link)
{
struct pci_root_info *info;
info = kzalloc(sizeof(*info), GFP_KERNEL);
if (!info)
return info;
INIT_LIST_HEAD(&info->resources);
info->bus_min = bus_min;
info->bus_max = bus_max;
info->node = node;
info->link = link;
list_add_tail(&info->list, &pci_root_infos);
return info;
}
void __devinit update_res(struct pci_root_info *info, resource_size_t start, void __devinit update_res(struct pci_root_info *info, resource_size_t start,
resource_size_t end, unsigned long flags, int merge) resource_size_t end, unsigned long flags, int merge)
{ {
int i;
struct resource *res; struct resource *res;
struct pci_root_res *root_res;
if (start > end) if (start > end)
return; return;
@ -69,11 +93,11 @@ void __devinit update_res(struct pci_root_info *info, resource_size_t start,
goto addit; goto addit;
/* try to merge it with old one */ /* try to merge it with old one */
for (i = 0; i < info->res_num; i++) { list_for_each_entry(root_res, &info->resources, list) {
resource_size_t final_start, final_end; resource_size_t final_start, final_end;
resource_size_t common_start, common_end; resource_size_t common_start, common_end;
res = &info->res[i]; res = &root_res->res;
if (res->flags != flags) if (res->flags != flags)
continue; continue;
@ -93,14 +117,15 @@ void __devinit update_res(struct pci_root_info *info, resource_size_t start,
addit: addit:
/* need to add that */ /* need to add that */
if (info->res_num >= RES_NUM) root_res = kzalloc(sizeof(*root_res), GFP_KERNEL);
if (!root_res)
return; return;
res = &info->res[info->res_num]; res = &root_res->res;
res->name = info->name; res->name = info->name;
res->flags = flags; res->flags = flags;
res->start = start; res->start = start;
res->end = end; res->end = end;
res->child = NULL;
info->res_num++; list_add_tail(&root_res->list, &info->resources);
} }

View File

@ -4,22 +4,24 @@
* sub bus (transparent) will use entres from 3 to store extra from * sub bus (transparent) will use entres from 3 to store extra from
* root, so need to make sure we have enough slot there. * root, so need to make sure we have enough slot there.
*/ */
#define RES_NUM 16 struct pci_root_res {
struct list_head list;
struct resource res;
};
struct pci_root_info { struct pci_root_info {
struct list_head list;
char name[12]; char name[12];
unsigned int res_num; struct list_head resources;
struct resource res[RES_NUM];
int bus_min; int bus_min;
int bus_max; int bus_max;
int node; int node;
int link; int link;
}; };
/* 4 at this time, it may become to 32 */ extern struct list_head pci_root_infos;
#define PCI_ROOT_NR 4 struct pci_root_info *alloc_pci_root_info(int bus_min, int bus_max,
extern int pci_root_num; int node, int link);
extern struct pci_root_info pci_root_info[PCI_ROOT_NR];
extern void update_res(struct pci_root_info *info, resource_size_t start, extern void update_res(struct pci_root_info *info, resource_size_t start,
resource_size_t end, unsigned long flags, int merge); resource_size_t end, unsigned long flags, int merge);
#endif #endif