linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tomasz Nowicki <tn@semihalf.com>
To: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: helgaas@kernel.org, arnd@arndb.de, will.deacon@arm.com,
	catalin.marinas@arm.com, rafael@kernel.org,
	hanjun.guo@linaro.org, okaya@codeaurora.org,
	jchandra@broadcom.com, robert.richter@caviumnetworks.com,
	mw@semihalf.com, Liviu.Dudau@arm.com, ddaney@caviumnetworks.com,
	wangyijing@huawei.com, Suravee.Suthikulpanit@amd.com,
	msalter@redhat.com, linux-pci@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org,
	linux-kernel@vger.kernel.org, linaro-acpi@lists.linaro.org,
	jcm@redhat.com, andrea.gallo@linaro.org, dhdang@apm.com,
	jeremy.linton@arm.com, liudongdong3@huawei.com,
	cov@codeaurora.org
Subject: Re: [PATCH V8 7/9] acpi: Add generic MCFG table handling
Date: Mon, 6 Jun 2016 14:55:41 +0200	[thread overview]
Message-ID: <575572CD.60107@semihalf.com> (raw)
In-Reply-To: <20160603113810.GA24764@red-moon>

On 03.06.2016 13:38, Lorenzo Pieralisi wrote:
> On Mon, May 30, 2016 at 05:14:20PM +0200, Tomasz Nowicki wrote:
>> In order to handle PCI config space regions properly in ACPI, new MCFG
>> interface is defined which does sanity checks on MCFG table and keeps its
>> root pointer. The user is able to lookup MCFG regions based on
>> host bridge root structure and domain:bus_start:bus_end touple.
>> Use pci_mmcfg_late_init old prototype to avoid another function name.
>
> "According to PCI firmware specifications, on systems booting with ACPI,
> PCI configuration for a host bridge must be set-up through the MCFG table
> regions for non-hotpluggable bridges and _CBA method for hotpluggable ones.
>
> Current MCFG table handling code, as implemented for x86, cannot be
> easily generalized owing to x86 specific quirks handling and related
> code, which makes it hard to reuse on other architectures.
>
> In order to implement MCFG PCI configuration handling for new platforms
> booting with ACPI (eg ARM64) this patch re-implements MCFG handling from
> scratch in a streamlined fashion and provides (through a generic
> interface available to all arches):
>
> - Simplified MCFG table parsing (executed through the pci_mmcfg_late_init()
>    hook as in current x86)
> - MCFG regions look-up interface through domain:bus_start:bus_end tuple
>
> The new MCFG regions handling interface is added to generic ACPI code
> so that existing architectures (eg x86) can be moved over to it and
> architectures relying on MCFG for ACPI PCI config space can rely on it
> without having to resort to arch specific implementations."
>

[...]

>> +
>> +#include <linux/kernel.h>
>> +#include <linux/pci.h>
>> +#include <linux/pci-acpi.h>
>> +
>> +/* Root pointer to the mapped MCFG table */
>> +static struct acpi_table_mcfg *mcfg_table;
>> +static int mcfg_entries;
>> +
>> +int pci_mcfg_lookup(struct acpi_pci_root *root)
>> +{
>> +	struct acpi_mcfg_allocation *mptr, *entry = NULL;
>> +	struct resource *bus_res = &root->secondary;
>> +	int i;
>> +
>> +	if (mcfg_table) {
>> +		mptr = (struct acpi_mcfg_allocation *) &mcfg_table[1];
>> +		for (i = 0; i < mcfg_entries && !entry; i++, mptr++)
>> +			if (mptr->pci_segment == root->segment &&
>> +			    mptr->start_bus_number == bus_res->start)
>> +				entry = mptr;
>> +	}
>> +
>> +	/* not found, use _CBA if available, else error */
>> +	if (!entry) {
>> +		if (root->mcfg_addr)
>> +			return root->mcfg_addr;
>> +		pr_err("%04x:%pR MCFG lookup failed\n", root->segment, bus_res);
>> +		return -ENOENT;
>> +	} else if (root->mcfg_addr && entry->address != root->mcfg_addr) {
>> +		pr_warn("%04x:%pR CBA %pa != MCFG %lx, using CBA\n",
>> +			root->segment, bus_res, &root->mcfg_addr,
>> +			(unsigned long)entry->address);
>> +		return 0;
>> +	}
>> +
>> +	/* found matching entry, bus range check */
>> +	if (entry->end_bus_number != bus_res->end) {
>> +		resource_size_t bus_end = min_t(resource_size_t,
>> +					entry->end_bus_number, bus_res->end);
>> +		pr_warn("%04x:%pR bus end mismatch, using %02lx\n",
>> +			root->segment, bus_res, (unsigned long)bus_end);
>> +		bus_res->end = bus_end;
>> +	}
>> +
>> +	if (!root->mcfg_addr)
>> +		root->mcfg_addr = entry->address;
>
> Let's hope that no one will ever implement a hotplug bridge with config
> space starting at physical address 0x0.
>
> Nit: You should define what the return value means. For success, once you
> return the _CBA address, once 0; this should be consistent.

As we decided to return CFG start address in root->mcfg_addr we should 
return 0 for the case (!entry) && (root->mcfg_addr). I'll fix it.

>
> Anyway, this function is not easy to read but it may well be fine, I will let
> Bjorn decide what to do with corner cases:
>
> a) _CBA is != 0 and you get a MCFG entry that matches its address (I am
>      not sure that capping the _CRS bus numbers is PCI compliant in that case)
> b) bus_end capping, either you leave code as-is (that caps also _CRS) or
>     just warn and fail if the bus->end numbers mismatch
>
> Pending Bjorn's opinion on the above (and commit log update):
>
> Reviewed-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
>

Thanks,
Tomasz

  reply	other threads:[~2016-06-06 12:55 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-30 15:14 [PATCH V8 0/9] Support for ARM64 ACPI based PCI host controller Tomasz Nowicki
2016-05-30 15:14 ` [PATCH V8 1/9] PCI: ecam: move ecam.h to linux/include/pci-ecam.h Tomasz Nowicki
2016-06-02  9:48   ` Lorenzo Pieralisi
2016-05-30 15:14 ` [PATCH V8 2/9] PCI: ecam: Add parent device field to pci_config_window Tomasz Nowicki
2016-06-02 10:13   ` Lorenzo Pieralisi
2016-05-30 15:14 ` [PATCH V8 3/9] pci: Add new function to unmap IO resources Tomasz Nowicki
2016-06-02 16:50   ` Lorenzo Pieralisi
2016-05-30 15:14 ` [PATCH V8 4/9] acpi, pci: Support IO resources when parsing PCI host bridge resources Tomasz Nowicki
2016-06-02 17:30   ` Lorenzo Pieralisi
2016-06-07 23:56   ` Bjorn Helgaas
2016-05-30 15:14 ` [PATCH V8 5/9] pci, acpi: add acpi hook to assign domain number Tomasz Nowicki
2016-06-08  0:15   ` Bjorn Helgaas
2016-06-08 10:21     ` Tomasz Nowicki
2016-06-08 13:22       ` Bjorn Helgaas
2016-06-10 15:14     ` Lorenzo Pieralisi
2016-06-10 15:49       ` Lorenzo Pieralisi
2016-06-10 16:49         ` Tomasz Nowicki
2016-06-10 18:18           ` Bjorn Helgaas
2016-06-10 18:54             ` Jon Masters
2016-05-30 15:14 ` [PATCH V8 6/9] arm64, pci, acpi: ACPI support for legacy IRQs parsing and consolidation with DT code Tomasz Nowicki
2016-05-30 15:14 ` [PATCH V8 7/9] acpi: Add generic MCFG table handling Tomasz Nowicki
2016-06-03 11:38   ` Lorenzo Pieralisi
2016-06-06 12:55     ` Tomasz Nowicki [this message]
2016-06-08  1:56   ` Bjorn Helgaas
2016-06-08 12:21     ` Tomasz Nowicki
2016-06-08 13:17       ` Bjorn Helgaas
2016-06-08 13:44         ` Tomasz Nowicki
2016-05-30 15:14 ` [PATCH V8 8/9] arm64, pci, acpi: Provide ACPI-specific prerequisites for PCI bus enumeration Tomasz Nowicki
2016-06-02  9:45   ` Lorenzo Pieralisi
2016-06-02  9:51     ` Tomasz Nowicki
2016-05-30 15:14 ` [PATCH V8 9/9] pci, acpi: ARM64 support for ACPI based generic PCI host controller Tomasz Nowicki
2016-05-30 15:38   ` Arnd Bergmann
2016-05-30 16:13     ` Jayachandran C
2016-06-02  9:35   ` Lorenzo Pieralisi
2016-06-02  9:44     ` Tomasz Nowicki
2016-06-08  2:14   ` Bjorn Helgaas
2016-06-01  7:36 ` [PATCH V8 0/9] Support for ARM64 ACPI based " Gabriele Paoloni
2016-06-02  7:31   ` Jon Masters
2016-06-02 10:06     ` Gabriele Paoloni
2016-06-02  8:52   ` Tomasz Nowicki
2016-06-02  9:58     ` Gabriele Paoloni
2016-06-02  8:48 ` Jon Masters
2016-06-07 23:13 ` Bjorn Helgaas
2016-06-08  9:20 ` Dongdong Liu
2016-06-09 16:45 ` Suravee Suthikulanit

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=575572CD.60107@semihalf.com \
    --to=tn@semihalf.com \
    --cc=Liviu.Dudau@arm.com \
    --cc=Suravee.Suthikulpanit@amd.com \
    --cc=andrea.gallo@linaro.org \
    --cc=arnd@arndb.de \
    --cc=catalin.marinas@arm.com \
    --cc=cov@codeaurora.org \
    --cc=ddaney@caviumnetworks.com \
    --cc=dhdang@apm.com \
    --cc=hanjun.guo@linaro.org \
    --cc=helgaas@kernel.org \
    --cc=jchandra@broadcom.com \
    --cc=jcm@redhat.com \
    --cc=jeremy.linton@arm.com \
    --cc=linaro-acpi@lists.linaro.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=liudongdong3@huawei.com \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=msalter@redhat.com \
    --cc=mw@semihalf.com \
    --cc=okaya@codeaurora.org \
    --cc=rafael@kernel.org \
    --cc=robert.richter@caviumnetworks.com \
    --cc=wangyijing@huawei.com \
    --cc=will.deacon@arm.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).