[PATCH v1 11/18] x86/PCI: MMCONFIG: add resource to struct pci_mmcfg_region

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch adds a resource and corresponding name to the MMCONFIG
structure.  This makes allocation simpler (we can allocate the
resource and name at the same time we allocate the pci_mmcfg_region),
and gives us a way to hang onto the resource after inserting it.
This will be needed so we can release and free it when hot-removing
a host bridge.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@xxxxxx>
---
 arch/x86/include/asm/pci_x86.h |    5 +++
 arch/x86/pci/mmconfig-shared.c |   61 ++++++++++++++++++++--------------------
 2 files changed, 35 insertions(+), 31 deletions(-)

diff --git a/arch/x86/include/asm/pci_x86.h b/arch/x86/include/asm/pci_x86.h
index a752d61..a6d42c1 100644
--- a/arch/x86/include/asm/pci_x86.h
+++ b/arch/x86/include/asm/pci_x86.h
@@ -118,11 +118,16 @@ extern int __init pcibios_init(void);
 
 /* pci-mmconfig.c */
 
+/* "PCI MMCONFIG %04x [bus %02x-%02x]" */
+#define PCI_MMCFG_RESOURCE_NAME_LEN (22 + 4 + 2 + 2)
+
 struct pci_mmcfg_region {
+	struct resource res;
 	u64 address;
 	u16 segment;
 	u8 start_bus;
 	u8 end_bus;
+	char name[PCI_MMCFG_RESOURCE_NAME_LEN];
 };
 
 extern int __init pci_mmcfg_arch_init(void);
diff --git a/arch/x86/pci/mmconfig-shared.c b/arch/x86/pci/mmconfig-shared.c
index 28ac9f5..3e9fa63 100644
--- a/arch/x86/pci/mmconfig-shared.c
+++ b/arch/x86/pci/mmconfig-shared.c
@@ -28,7 +28,15 @@ static int __initdata pci_mmcfg_resources_inserted;
 
 static __init void free_all_mmcfg(void)
 {
+	int i;
+	struct pci_mmcfg_region *cfg;
+
 	pci_mmcfg_arch_free();
+	for (i = 0; i < pci_mmcfg_config_num; i++) {
+		cfg = &pci_mmcfg_config[i];
+		if (cfg->res.parent)
+			release_resource(&cfg->res);
+	}
 	pci_mmcfg_config_num = 0;
 	kfree(pci_mmcfg_config);
 	pci_mmcfg_config = NULL;
@@ -40,6 +48,8 @@ static __init struct pci_mmcfg_region *pci_mmconfig_add(int segment, int start,
 	struct pci_mmcfg_region *new;
 	int new_num = pci_mmcfg_config_num + 1;
 	int i = pci_mmcfg_config_num;
+	int num_buses;
+	struct resource *res;
 
 	if (addr == 0)
 		return NULL;
@@ -63,6 +73,15 @@ static __init struct pci_mmcfg_region *pci_mmconfig_add(int segment, int start,
 	new->start_bus = start;
 	new->end_bus = end;
 
+	num_buses = end - start + 1;
+	res = &new->res;
+	res->start = addr + PCI_MMCFG_BUS_OFFSET(start);
+	res->end = addr + PCI_MMCFG_BUS_OFFSET(num_buses) - 1;
+	res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
+	snprintf(new->name, PCI_MMCFG_RESOURCE_NAME_LEN,
+		 "PCI MMCONFIG %04x [bus %02x-%02x]", segment, start, end);
+	res->name = new->name;
+
 	return &pci_mmcfg_config[i];
 }
 
@@ -336,33 +355,12 @@ static int __init pci_mmcfg_check_hostbridge(void)
 
 static void __init pci_mmcfg_insert_resources(void)
 {
-#define PCI_MMCFG_RESOURCE_NAME_LEN 24
 	int i;
-	struct resource *res;
-	char *names;
-	unsigned num_buses;
-
-	res = kcalloc(PCI_MMCFG_RESOURCE_NAME_LEN + sizeof(*res),
-			pci_mmcfg_config_num, GFP_KERNEL);
-	if (!res) {
-		printk(KERN_ERR "PCI: Unable to allocate MMCONFIG resources\n");
-		return;
-	}
+	struct pci_mmcfg_region *cfg;
 
-	names = (void *)&res[pci_mmcfg_config_num];
-	for (i = 0; i < pci_mmcfg_config_num; i++, res++) {
-		struct pci_mmcfg_region *cfg = &pci_mmcfg_config[i];
-		num_buses = cfg->end_bus - cfg->start_bus + 1;
-		res->name = names;
-		snprintf(names, PCI_MMCFG_RESOURCE_NAME_LEN,
-			 "PCI MMCONFIG %u [%02x-%02x]", cfg->segment,
-			 cfg->start_bus, cfg->end_bus);
-		res->start = cfg->address +
-			PCI_MMCFG_BUS_OFFSET(cfg->start_bus);
-		res->end = res->start + PCI_MMCFG_BUS_OFFSET(num_buses) - 1;
-		res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
-		insert_resource(&iomem_resource, res);
-		names += PCI_MMCFG_RESOURCE_NAME_LEN;
+	for (i = 0; i < pci_mmcfg_config_num; i++) {
+		cfg = &pci_mmcfg_config[i];
+		insert_resource(&iomem_resource, &cfg->res);
 	}
 
 	/* Mark that the resources have been inserted. */
@@ -444,7 +442,7 @@ static int __init is_mmconf_reserved(check_reserved_t is_reserved,
 		typeof(pci_mmcfg_config[0]) *cfg, int with_e820)
 {
 	u64 old_size = size;
-	int valid = 0;
+	int valid = 0, num_buses;
 
 	while (!is_reserved(addr, addr + size, E820_RESERVED)) {
 		size >>= 1;
@@ -461,6 +459,9 @@ static int __init is_mmconf_reserved(check_reserved_t is_reserved,
 		if (old_size != size) {
 			/* update end_bus */
 			cfg->end_bus = cfg->start_bus + ((size>>20) - 1);
+			num_buses = cfg->end_bus - cfg->start_bus + 1;
+			cfg->res.end = cfg->res.start +
+			    PCI_MMCFG_BUS_OFFSET(num_buses) - 1;
 			printk(KERN_NOTICE "PCI: updated MCFG configuration %d: base %lx "
 			       "segment %hu buses %u - %u\n",
 			       i, (unsigned long)cfg->address, cfg->segment,
@@ -481,14 +482,12 @@ static void __init pci_mmcfg_reject_broken(int early)
 		return;
 
 	for (i = 0; i < pci_mmcfg_config_num; i++) {
-		int num_buses, valid = 0;
+		int valid = 0;
 		u64 addr, size;
 
 		cfg = &pci_mmcfg_config[i];
-		addr = cfg->address +
-			PCI_MMCFG_BUS_OFFSET(cfg->start_bus);
-		num_buses = cfg->end_bus - cfg->start_bus + 1;
-		size = PCI_MMCFG_BUS_OFFSET(num_buses);
+		addr = cfg->res.start;
+		size = resource_size(&cfg->res);
 		printk(KERN_NOTICE "PCI: MCFG configuration %d: base %lx "
 		       "segment %hu buses %u - %u\n",
 		       i, (unsigned long)cfg->address, cfg->segment,

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux