From: Bjorn Helgaas <bhelgaas-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
To: Liviu Dudau <Liviu.Dudau-5wv7dgnIgG8@public.gmane.org>
Cc: Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org>,
Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
Jason Gunthorpe
<jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>,
Benjamin Herrenschmidt
<benh-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org>,
Catalin Marinas <catalin.marinas-5wv7dgnIgG8@public.gmane.org>,
Will Deacon <Will.Deacon-5wv7dgnIgG8@public.gmane.org>,
Russell King <linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org>,
linux-pci <linux-pci-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
Linus Walleij
<linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
Tanmay Inamdar <tinamdar-qTEPVZfXA3Y@public.gmane.org>,
Grant Likely
<grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>,
Sinan Kaya <okaya-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>,
Jingoo Han <jg1.han-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>,
Kukjin Kim <kgene.kim-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>,
Suravee Suthikulanit
<suravee.suthikulpanit-5C7GfCeVMHo@public.gmane.org>,
linux-arch <linux-arch-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
LKML <linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
Device Tree ML
<devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
LAKML
<linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org>,
Grant Likely
<grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
Subject: Re: [PATCH v11 02/10] PCI: Introduce helper functions to deal with PCI I/O ranges.
Date: Fri, 19 Sep 2014 14:48:17 -0600 [thread overview]
Message-ID: <20140919204817.GF19374@google.com> (raw)
In-Reply-To: <1411003825-21521-3-git-send-email-Liviu.Dudau-5wv7dgnIgG8@public.gmane.org>
On Thu, Sep 18, 2014 at 02:30:17AM +0100, Liviu Dudau wrote:
> Some architectures do not have a simple view of the PCI I/O space
> and instead use a range of CPU addresses that map to bus addresses.
> For some architectures these ranges will be expressed by OF bindings
> in a device tree file.
>
> This patch introduces a pci_register_io_range() helper function with
> a generic implementation that can be used by such architectures to
> keep track of the I/O ranges described by the PCI bindings. If the
> PCI_IOBASE macro is not defined that signals lack of support for PCI
> and we return an error.
>
> In order to retrieve the CPU address associated with an I/O port, a
> new helper function pci_pio_to_address() is introduced. This will
> search in the list of ranges registered with pci_register_io_range()
> and return the CPU address that corresponds to the given port.
>
> Cc: Grant Likely <grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> Cc: Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org>
> Reviewed-by: Catalin Marinas <catalin.marinas-5wv7dgnIgG8@public.gmane.org>
> Acked-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> Signed-off-by: Liviu Dudau <Liviu.Dudau-5wv7dgnIgG8@public.gmane.org>
> ---
> drivers/of/address.c | 100 +++++++++++++++++++++++++++++++++++++++++++++
> include/linux/of_address.h | 2 +
> 2 files changed, 102 insertions(+)
>
> diff --git a/drivers/of/address.c b/drivers/of/address.c
> index e371825..2373a92 100644
> --- a/drivers/of/address.c
> +++ b/drivers/of/address.c
> @@ -5,6 +5,7 @@
> #include <linux/module.h>
> #include <linux/of_address.h>
> #include <linux/pci_regs.h>
> +#include <linux/slab.h>
> #include <linux/string.h>
>
> /* Max address size we deal with */
> @@ -601,12 +602,111 @@ const __be32 *of_get_address(struct device_node *dev, int index, u64 *size,
> }
> EXPORT_SYMBOL(of_get_address);
>
> +#ifdef PCI_IOBASE
> +struct io_range {
> + struct list_head list;
> + phys_addr_t start;
> + resource_size_t size;
> +};
> +
> +static LIST_HEAD(io_range_list);
> +static DEFINE_SPINLOCK(io_range_lock);
> +#endif
> +
> +/*
> + * Record the PCI IO range (expressed as CPU physical address + size).
> + * Return a negative value if an error has occured, zero otherwise
> + */
> +int __weak pci_register_io_range(phys_addr_t addr, resource_size_t size)
> +{
> +#ifdef PCI_IOBASE
> + struct io_range *range;
> + resource_size_t allocated_size = 0;
> +
> + /* check if the range hasn't been previously recorded */
> + spin_lock(&io_range_lock);
> + list_for_each_entry(range, &io_range_list, list) {
> + if (addr >= range->start && addr + size <= range->start + size)
> + return 0;
This returns while holding io_range_lock.
> + allocated_size += range->size;
> + }
> + spin_unlock(&io_range_lock);
I think this is racy; because you drop the lock between (1) checking
whether the range is already recorded and (2) adding the range to the list,
it's still possible for two callers to add the same range.
> + /* range not registed yet, check for available space */
> + if (allocated_size + size - 1 > IO_SPACE_LIMIT) {
> + /* if it's too big check if 64K space can be reserved */
> + if (allocated_size + SZ_64K - 1 > IO_SPACE_LIMIT)
> + return -E2BIG;
> +
> + size = SZ_64K;
> + pr_warn("Requested IO range too big, new size set to 64K\n");
> + }
> +
> + /* add the range to the list */
> + range = kzalloc(sizeof(*range), GFP_KERNEL);
> + if (!range)
> + return -ENOMEM;
> +
> + range->start = addr;
> + range->size = size;
> +
> + spin_lock(&io_range_lock);
> + list_add_tail(&range->list, &io_range_list);
> + spin_unlock(&io_range_lock);
> +#endif
> +
> + return 0;
> +}
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2014-09-19 20:48 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-18 1:30 [PATCH v11 00/10] Support for creating generic PCI host bridges from DT Liviu Dudau
2014-09-18 1:30 ` [PATCH v11 01/10] Fix ioport_map() for !CONFIG_GENERIC_IOMAP cases Liviu Dudau
2014-09-18 1:30 ` [PATCH v11 02/10] PCI: Introduce helper functions to deal with PCI I/O ranges Liviu Dudau
[not found] ` <1411003825-21521-3-git-send-email-Liviu.Dudau-5wv7dgnIgG8@public.gmane.org>
2014-09-19 20:48 ` Bjorn Helgaas [this message]
2014-09-18 1:30 ` [PATCH v11 03/10] ARM: Define PCI_IOBASE as the base of virtual PCI IO space Liviu Dudau
[not found] ` <1411003825-21521-4-git-send-email-Liviu.Dudau-5wv7dgnIgG8@public.gmane.org>
2014-09-20 2:14 ` Arnd Bergmann
2014-09-18 1:30 ` [PATCH v11 04/10] PCI: OF: Fix the conversion of IO ranges into IO resources Liviu Dudau
2014-09-19 20:56 ` Bjorn Helgaas
2014-09-20 17:33 ` Rob Herring
2014-09-22 15:32 ` Liviu Dudau
2014-09-22 17:18 ` Rob Herring
2014-09-18 1:30 ` [PATCH v11 05/10] PCI: Create pci_host_bridge before its associated bus in pci_create_root_bus Liviu Dudau
2014-09-18 1:30 ` [PATCH v11 06/10] PCI: Introduce generic domain handling for PCI busses Liviu Dudau
2014-09-18 1:30 ` [PATCH v11 07/10] OF: Introduce helper function for getting PCI domain_nr Liviu Dudau
2014-09-19 21:03 ` Bjorn Helgaas
2014-09-22 11:05 ` Liviu Dudau
2014-09-22 15:25 ` Bjorn Helgaas
2014-09-22 15:33 ` Liviu Dudau
2014-09-20 2:24 ` Arnd Bergmann
2014-09-22 15:20 ` Liviu Dudau
2014-09-20 17:52 ` Rob Herring
2014-09-18 1:30 ` [PATCH v11 08/10] OF: PCI: Add support for parsing PCI host bridge resources from DT Liviu Dudau
2014-09-19 21:06 ` Bjorn Helgaas
2014-09-20 0:28 ` Rob Herring
2014-09-22 17:55 ` Liviu Dudau
2014-09-22 22:11 ` Rob Herring
2014-09-22 9:32 ` Robert Richter
2014-09-22 11:43 ` Liviu Dudau
[not found] ` <20140922114317.GN1994-2JSQmVVBSi7ZROr8t4l/smS4ubULX0JqMm0uRHvK7Nw@public.gmane.org>
2014-09-22 12:15 ` Robert Richter
2014-09-23 7:56 ` Arnd Bergmann
2014-09-23 10:49 ` Liviu Dudau
2014-09-23 13:30 ` Rob Herring
2014-09-23 13:58 ` Liviu Dudau
2014-09-18 1:30 ` [PATCH v11 09/10] PCI: Assign unassigned bus resources in pci_scan_root_bus() Liviu Dudau
2014-09-18 1:30 ` [PATCH v11 10/10] PCI: Introduce pci_remap_iospace() for remapping PCI I/O bus resources into CPU space Liviu Dudau
2014-09-19 21:54 ` Bjorn Helgaas
2014-09-20 2:20 ` Arnd Bergmann
2014-09-22 15:29 ` Robert Richter
2014-09-20 0:34 ` Rob Herring
2014-09-19 21:59 ` [PATCH v11 00/10] Support for creating generic PCI host bridges from DT Bjorn Helgaas
2014-09-22 11:35 ` Liviu Dudau
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=20140919204817.GF19374@google.com \
--to=bhelgaas-hpiqsd4aklfqt0dzr+alfa@public.gmane.org \
--cc=Liviu.Dudau-5wv7dgnIgG8@public.gmane.org \
--cc=Will.Deacon-5wv7dgnIgG8@public.gmane.org \
--cc=arnd-r2nGTMty4D4@public.gmane.org \
--cc=benh-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org \
--cc=catalin.marinas-5wv7dgnIgG8@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org \
--cc=jg1.han-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org \
--cc=jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org \
--cc=kgene.kim-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org \
--cc=linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=linux-arch-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org \
--cc=linux-pci-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=okaya-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org \
--cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=suravee.suthikulpanit-5C7GfCeVMHo@public.gmane.org \
--cc=tinamdar-qTEPVZfXA3Y@public.gmane.org \
/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).