linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Honghui Zhang <honghui.zhang@mediatek.com>
To: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: <bhelgaas@google.com>, <linux-arm-kernel@lists.infradead.org>,
	<linux-mediatek@lists.infradead.org>, <linux-pci@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <ryder.lee@mediatek.com>,
	<devicetree@vger.kernel.org>, <youlin.pei@mediatek.com>,
	<jianjun.wang@mediatek.com>
Subject: Re: [PATCH v2] PCI: mediatek: Use devm_of_pci_get_host_bridge_resources() to parse DT
Date: Fri, 30 Nov 2018 10:30:59 +0800	[thread overview]
Message-ID: <1543545059.3753.4.camel@mhfsdcap03> (raw)
In-Reply-To: <20181129113324.GA27228@e107981-ln.cambridge.arm.com>

On Thu, 2018-11-29 at 11:33 +0000, Lorenzo Pieralisi wrote:
> On Thu, Nov 08, 2018 at 10:56:55AM +0800, honghui.zhang@mediatek.com wrote:
> > From: Honghui Zhang <honghui.zhang@mediatek.com>
> > 
> > Use the devm_of_pci_get_host_bridge_resources() API in place of the PCI OF
> > DT parser.
> > 
> > Signed-off-by: Honghui Zhang <honghui.zhang@mediatek.com>
> > ---
> >  drivers/pci/controller/pcie-mediatek.c | 98 +++++++++-------------------------
> >  1 file changed, 24 insertions(+), 74 deletions(-)
> > 
> > diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c
> > index 2a1f97c..0590a93 100644
> > --- a/drivers/pci/controller/pcie-mediatek.c
> > +++ b/drivers/pci/controller/pcie-mediatek.c
> > @@ -197,11 +197,7 @@ struct mtk_pcie_port {
> >   * @dev: pointer to PCIe device
> >   * @base: IO mapped register base
> >   * @free_ck: free-run reference clock
> > - * @io: IO resource
> > - * @pio: PIO resource
> >   * @mem: non-prefetchable memory resource
> > - * @busn: bus range
> > - * @offset: IO / Memory offset
> >   * @ports: pointer to PCIe port information
> >   * @soc: pointer to SoC-dependent operations
> >   */
> > @@ -210,14 +206,7 @@ struct mtk_pcie {
> >  	void __iomem *base;
> >  	struct clk *free_ck;
> >  
> > -	struct resource io;
> > -	struct resource pio;
> >  	struct resource mem;
> > -	struct resource busn;
> > -	struct {
> > -		resource_size_t mem;
> > -		resource_size_t io;
> > -	} offset;
> >  	struct list_head ports;
> >  	const struct mtk_pcie_soc *soc;
> >  };
> > @@ -1045,55 +1034,43 @@ static int mtk_pcie_setup(struct mtk_pcie *pcie)
> >  {
> >  	struct device *dev = pcie->dev;
> >  	struct device_node *node = dev->of_node, *child;
> > -	struct of_pci_range_parser parser;
> > -	struct of_pci_range range;
> > -	struct resource res;
> >  	struct mtk_pcie_port *port, *tmp;
> > +	struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie);
> > +	struct list_head *windows = &host->windows;
> > +	struct resource_entry *win, *tmp_win;
> > +	resource_size_t io_base;
> >  	int err;
> >  
> > -	if (of_pci_range_parser_init(&parser, node)) {
> > -		dev_err(dev, "missing \"ranges\" property\n");
> > -		return -EINVAL;
> > -	}
> > +	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
> > +						    windows, &io_base);
> > +	if (err)
> > +		return err;
> >  
> > -	for_each_of_pci_range(&parser, &range) {
> > -		err = of_pci_range_to_resource(&range, node, &res);
> > -		if (err < 0)
> > -			return err;
> > +	err = devm_request_pci_bus_resources(dev, windows);
> > +	if (err < 0)
> > +		return err;
> >  
> > -		switch (res.flags & IORESOURCE_TYPE_BITS) {
> > +	/* Get the I/O and memory ranges from DT */
> > +	resource_list_for_each_entry_safe(win, tmp_win, windows) {
> > +		switch (resource_type(win->res)) {
> >  		case IORESOURCE_IO:
> > -			pcie->offset.io = res.start - range.pci_addr;
> > -
> > -			memcpy(&pcie->pio, &res, sizeof(res));
> > -			pcie->pio.name = node->full_name;
> > -
> > -			pcie->io.start = range.cpu_addr;
> > -			pcie->io.end = range.cpu_addr + range.size - 1;
> > -			pcie->io.flags = IORESOURCE_MEM;
> > -			pcie->io.name = "I/O";
> > -
> > -			memcpy(&res, &pcie->io, sizeof(res));
> > +			err = devm_pci_remap_iospace(dev, win->res, io_base);
> > +			if (err) {
> > +				dev_warn(dev, "error %d: failed to map resource %pR\n",
> > +					 err, win->res);
> > +				resource_list_destroy_entry(win);
> > +			}
> >  			break;
> > -
> >  		case IORESOURCE_MEM:
> > -			pcie->offset.mem = res.start - range.pci_addr;
> > -
> > -			memcpy(&pcie->mem, &res, sizeof(res));
> > +			memcpy(&pcie->mem, win->res, sizeof(*win->res));
> >  			pcie->mem.name = "non-prefetchable";
> >  			break;
> > +		case IORESOURCE_BUS:
> > +			host->busnr = win->res->start;
> > +			break;
> >  		}
> >  	}
> >  
> > -	err = of_pci_parse_bus_range(node, &pcie->busn);
> > -	if (err < 0) {
> > -		dev_err(dev, "failed to parse bus ranges property: %d\n", err);
> > -		pcie->busn.name = node->name;
> > -		pcie->busn.start = 0;
> > -		pcie->busn.end = 0xff;
> > -		pcie->busn.flags = IORESOURCE_BUS;
> > -	}
> > -
> >  	for_each_available_child_of_node(node, child) {
> >  		int slot;
> >  
> > @@ -1125,28 +1102,6 @@ static int mtk_pcie_setup(struct mtk_pcie *pcie)
> >  	return 0;
> >  }
> >  
> > -static int mtk_pcie_request_resources(struct mtk_pcie *pcie)
> > -{
> > -	struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie);
> > -	struct list_head *windows = &host->windows;
> > -	struct device *dev = pcie->dev;
> > -	int err;
> > -
> > -	pci_add_resource_offset(windows, &pcie->pio, pcie->offset.io);
> > -	pci_add_resource_offset(windows, &pcie->mem, pcie->offset.mem);
> > -	pci_add_resource(windows, &pcie->busn);
> > -
> > -	err = devm_request_pci_bus_resources(dev, windows);
> > -	if (err < 0)
> > -		return err;
> > -
> > -	err = devm_pci_remap_iospace(dev, &pcie->pio, pcie->io.start);
> > -	if (err < 0)
> > -		return err;
> > -
> > -	return 0;
> > -}
> > -
> >  static int mtk_pcie_probe(struct platform_device *pdev)
> >  {
> >  	struct device *dev = &pdev->dev;
> > @@ -1169,11 +1124,6 @@ static int mtk_pcie_probe(struct platform_device *pdev)
> >  	if (err)
> >  		return err;
> >  
> > -	err = mtk_pcie_request_resources(pcie);
> > -	if (err)
> > -		goto put_resources;
> > -
> > -	host->busnr = pcie->busn.start;
> >  	host->dev.parent = pcie->dev;
> >  	host->ops = pcie->soc->ops;
> >  	host->map_irq = of_irq_parse_and_map_pci;
> 
> I would prefer having all the host initialization carried out in a
> single function. I appreciate you may need to reintroduce a temporary
> busnumber value or reshuffle the code to do that, sorry for asking to
> change it again but I do not want to see the struct pci_host_bridge
> variables initialization scattered around, it is confusing.
> 
Okay, I will change it in the next version, and I will ask Ryder for
review internally and if it's OK with him I will add his ack directly in
the next version.

Thanks.

> Thanks,
> Lorenzo



      reply	other threads:[~2018-11-30  2:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-08  2:56 [PATCH v2] PCI: mediatek: Use devm_of_pci_get_host_bridge_resources() to parse DT honghui.zhang
2018-11-21  5:47 ` Ryder Lee
2018-11-29 11:33 ` Lorenzo Pieralisi
2018-11-30  2:30   ` Honghui Zhang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1543545059.3753.4.camel@mhfsdcap03 \
    --to=honghui.zhang@mediatek.com \
    --cc=bhelgaas@google.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jianjun.wang@mediatek.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=ryder.lee@mediatek.com \
    --cc=youlin.pei@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).