diff mbox

[18/28] PCI/sparc: Use pci_scan_root_bridge() for simplicity

Message ID 1421372666-12288-19-git-send-email-wangyijing@huawei.com (mailing list archive)
State New, archived
Delegated to: Bjorn Helgaas
Headers show

Commit Message

Yijing Wang Jan. 16, 2015, 1:44 a.m. UTC
Now we could use pci_scan_root_bridge() to scan
pci buses, provide sparc specific pci_host_bridge_ops.

Signed-off-by: Yijing Wang <wangyijing@huawei.com>
---
 arch/sparc/kernel/pci.c |   30 ++++++++++++++++++++++++------
 1 files changed, 24 insertions(+), 6 deletions(-)

Comments

Arnd Bergmann Jan. 16, 2015, 10:01 a.m. UTC | #1
On Friday 16 January 2015 09:44:16 Yijing Wang wrote:
> +static void pci_host_bridge_probe_mode(
> +               struct pci_host_bridge *host)
> +{
> +       host->of_scan = true;
> +}
> 

I probably missed something here, but where does host->of_scan
get used?

	Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Yijing Wang Jan. 19, 2015, 3:17 a.m. UTC | #2
On 2015/1/16 18:01, Arnd Bergmann wrote:
> On Friday 16 January 2015 09:44:16 Yijing Wang wrote:
>> +static void pci_host_bridge_probe_mode(
>> +               struct pci_host_bridge *host)
>> +{
>> +       host->of_scan = true;
>> +}
>>
> 
> I probably missed something here, but where does host->of_scan
> get used?
> 

It is used in __pci_scan_root_bus() to detect whether of scan bus is needed in patch 11.


@@ -2051,10 +2053,17 @@ static struct pci_bus *__pci_scan_root_bus(
 		pci_bus_insert_busn_res(b, host->busnum, 255);
 	}

-	max = pci_scan_child_bus(b);
+	if (host->ops && host->ops->phb_probe_mode)
+		host->ops->phb_probe_mode(host);

-	if (!found)
-		pci_bus_update_busn_res_end(b, max);
+	if (host->of_scan) {
+		if (host->ops &&host->ops->phb_of_scan_bus)
+			host->ops->phb_of_scan_bus(host);
+	} else {
+		max = pci_scan_child_bus(b);
+		if (!found)
+			pci_bus_update_busn_res_end(b, max);
+	}

 	return b;

Thanks!
Yijing.


> 	Arnd
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
> 
> .
>
Arnd Bergmann Jan. 19, 2015, 8:44 a.m. UTC | #3
On Monday 19 January 2015 11:17:02 Yijing Wang wrote:
> On 2015/1/16 18:01, Arnd Bergmann wrote:
> > On Friday 16 January 2015 09:44:16 Yijing Wang wrote:
> >> +static void pci_host_bridge_probe_mode(
> >> +               struct pci_host_bridge *host)
> >> +{
> >> +       host->of_scan = true;
> >> +}
> >>
> > 
> > I probably missed something here, but where does host->of_scan
> > get used?
> > 
> 
> It is used in __pci_scan_root_bus() to detect whether of scan bus is needed in patch 11.

Ok, I see it now.

> @@ -2051,10 +2053,17 @@ static struct pci_bus *__pci_scan_root_bus(
>  		pci_bus_insert_busn_res(b, host->busnum, 255);
>  	}
> 
> -	max = pci_scan_child_bus(b);
> +	if (host->ops && host->ops->phb_probe_mode)
> +		host->ops->phb_probe_mode(host);
> 
> -	if (!found)
> -		pci_bus_update_busn_res_end(b, max);
> +	if (host->of_scan) {
> +		if (host->ops &&host->ops->phb_of_scan_bus)
> +			host->ops->phb_of_scan_bus(host);
> +	} else {
> +		max = pci_scan_child_bus(b);
> +		if (!found)
> +			pci_bus_update_busn_res_end(b, max);
> +	}
> 

I think we can simplify this based on the knowledge that this code
will remain powerpc specific. How about removing the phb_probe_mode()
callback and replacing it with just a phb_scan_bus() callback that
will always get set on sparc, and do this on powerpc:

+static void pci_host_bridge_of_scan_bus(struct pci_host_bridge *host)
+{
+       int mode = PCI_PROBE_NORMAL;
+       struct pci_bus *bus = host->bus;
+       struct pci_controller *hose = dev_get_drvdata(&host->dev);
+
+       /* Get probe mode and perform scan */
+       if (hose->dn && ppc_md.pci_probe_mode)
+               mode = ppc_md.pci_probe_mode(bus);
+
+       pr_debug("    probe mode: %d\n", mode);
+       if (mode == PCI_PROBE_DEVTREE) {
+               of_scan_bus(host->dn, bus);
+		return max; // XXX need to get this from somewhere
+	}
+	return pci_scan_child_bus(b);
+}

Would that work?

	Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Yijing Wang Jan. 19, 2015, 10:53 a.m. UTC | #4
On 2015/1/19 16:44, Arnd Bergmann wrote:
> On Monday 19 January 2015 11:17:02 Yijing Wang wrote:
>> On 2015/1/16 18:01, Arnd Bergmann wrote:
>>> On Friday 16 January 2015 09:44:16 Yijing Wang wrote:
>>>> +static void pci_host_bridge_probe_mode(
>>>> +               struct pci_host_bridge *host)
>>>> +{
>>>> +       host->of_scan = true;
>>>> +}
>>>>
>>>
>>> I probably missed something here, but where does host->of_scan
>>> get used?
>>>
>>
>> It is used in __pci_scan_root_bus() to detect whether of scan bus is needed in patch 11.
> 
> Ok, I see it now.
> 
>> @@ -2051,10 +2053,17 @@ static struct pci_bus *__pci_scan_root_bus(
>>  		pci_bus_insert_busn_res(b, host->busnum, 255);
>>  	}
>>
>> -	max = pci_scan_child_bus(b);
>> +	if (host->ops && host->ops->phb_probe_mode)
>> +		host->ops->phb_probe_mode(host);
>>
>> -	if (!found)
>> -		pci_bus_update_busn_res_end(b, max);
>> +	if (host->of_scan) {
>> +		if (host->ops &&host->ops->phb_of_scan_bus)
>> +			host->ops->phb_of_scan_bus(host);
>> +	} else {
>> +		max = pci_scan_child_bus(b);
>> +		if (!found)
>> +			pci_bus_update_busn_res_end(b, max);
>> +	}
>>
> 
> I think we can simplify this based on the knowledge that this code
> will remain powerpc specific. How about removing the phb_probe_mode()
> callback and replacing it with just a phb_scan_bus() callback that
> will always get set on sparc, and do this on powerpc:
> 
> +static void pci_host_bridge_of_scan_bus(struct pci_host_bridge *host)
> +{
> +       int mode = PCI_PROBE_NORMAL;
> +       struct pci_bus *bus = host->bus;
> +       struct pci_controller *hose = dev_get_drvdata(&host->dev);
> +
> +       /* Get probe mode and perform scan */
> +       if (hose->dn && ppc_md.pci_probe_mode)
> +               mode = ppc_md.pci_probe_mode(bus);
> +
> +       pr_debug("    probe mode: %d\n", mode);
> +       if (mode == PCI_PROBE_DEVTREE) {
> +               of_scan_bus(host->dn, bus);
> +		return max; // XXX need to get this from somewhere
> +	}
> +	return pci_scan_child_bus(b);
> +}
> 
> Would that work?

This looks good to me, it is more simple.

Thanks!
Yijing.


> 	Arnd
> 
> .
>
diff mbox

Patch

diff --git a/arch/sparc/kernel/pci.c b/arch/sparc/kernel/pci.c
index d798b42..42dc21f 100644
--- a/arch/sparc/kernel/pci.c
+++ b/arch/sparc/kernel/pci.c
@@ -647,12 +647,31 @@  static void pci_claim_bus_resources(struct pci_bus *bus)
 		pci_claim_bus_resources(child_bus);
 }
 
+static void pci_host_bridge_probe_mode(
+		struct pci_host_bridge *host)
+{
+	host->of_scan = true;
+}
+
+static void pci_host_bridge_of_scan_bus(
+		struct pci_host_bridge *host)
+{
+	struct pci_pbm_info *pbm = dev_get_drvdata(&host->dev);
+	struct device_node *node = pbm->op->dev.of_node;
+
+	pci_of_scan_bus(pbm, node, host->bus);
+}
+
+static struct pci_host_bridge_ops phb_ops = {
+	.phb_of_scan_bus,
+};
+
 struct pci_bus *pci_scan_one_pbm(struct pci_pbm_info *pbm,
 				 struct device *parent)
 {
 	LIST_HEAD(resources);
 	struct device_node *node = pbm->op->dev.of_node;
-	struct pci_bus *bus;
+	struct pci_host_bridge *host;
 
 	printk("PCI: Scanning PBM %s\n", node->full_name);
 
@@ -664,17 +683,16 @@  struct pci_bus *pci_scan_one_pbm(struct pci_pbm_info *pbm,
 	pbm->busn.end	= pbm->pci_last_busno;
 	pbm->busn.flags	= IORESOURCE_BUS;
 	pci_add_resource(&resources, &pbm->busn);
-	bus = pci_create_root_bus(parent, 
+	host = pci_scan_root_bridge(parent,
 			PCI_DOMBUS(pbm->index, pbm->pci_first_busno), 
-			pbm->pci_ops, pbm, &resources);
-	if (!bus) {
-		printk(KERN_ERR "Failed to create bus for %s\n",
+			pbm->pci_ops, pbm, &resources, &phb_ops);
+	if (!host) {
+		printk(KERN_ERR "Failed to create host bridge for %s\n",
 		       node->full_name);
 		pci_free_resource_list(&resources);
 		return NULL;
 	}
 
-	pci_of_scan_bus(pbm, node, bus);
 	pci_bus_add_devices(bus);
 	pci_bus_register_of_sysfs(bus);