From: Liviu Dudau <Liviu.Dudau-5wv7dgnIgG8@public.gmane.org>
To: Bjorn Helgaas <bhelgaas-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
Cc: linux-pci <linux-pci-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
Catalin Marinas <Catalin.Marinas-5wv7dgnIgG8@public.gmane.org>,
Will Deacon <Will.Deacon-5wv7dgnIgG8@public.gmane.org>,
Benjamin Herrenschmidt
<benh-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org>,
linaro-kernel
<linaro-kernel-cunTk1MwBs8s++Sfvej+rw@public.gmane.org>,
Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org>,
LKML <linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
"devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
<devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
LAKML
<linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org>,
Tanmay Inamdar <tinamdar-qTEPVZfXA3Y@public.gmane.org>,
Grant Likely
<grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
Subject: Re: [PATCH v7 3/3] arm64: Add architecture support for PCI
Date: Tue, 8 Apr 2014 10:52:46 +0100 [thread overview]
Message-ID: <20140408095246.GU17163@e106497-lin.cambridge.arm.com> (raw)
In-Reply-To: <20140407235830.GA9959-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
On Tue, Apr 08, 2014 at 12:58:30AM +0100, Bjorn Helgaas wrote:
> On Fri, Mar 14, 2014 at 03:34:18PM +0000, Liviu Dudau wrote:
> > Use the generic host bridge functions to provide support for
> > PCI Express on arm64. There is no support for ISA memory.
> >
> > Signed-off-by: Liviu Dudau <Liviu.Dudau-5wv7dgnIgG8@public.gmane.org>
> > Tested-by: Tanmay Inamdar <tinamdar-qTEPVZfXA3Y@public.gmane.org>
> > ---
> > arch/arm64/Kconfig | 19 +++-
> > arch/arm64/include/asm/Kbuild | 1 +
> > arch/arm64/include/asm/io.h | 3 +-
> > arch/arm64/include/asm/pci.h | 51 ++++++++++
> > arch/arm64/kernel/Makefile | 1 +
> > arch/arm64/kernel/pci.c | 173 ++++++++++++++++++++++++++++++++
> > 6 files changed, 246 insertions(+), 2 deletions(-)
> > create mode 100644 arch/arm64/include/asm/pci.h
> > create mode 100644 arch/arm64/kernel/pci.c
> >
> > diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> > index 27bbcfc..d1c8568 100644
> > --- a/arch/arm64/Kconfig
> > +++ b/arch/arm64/Kconfig
> > @@ -62,7 +62,7 @@ config MMU
> > def_bool y
> >
> > config NO_IOPORT
> > - def_bool y
> > + def_bool y if !PCI
> >
> > config STACKTRACE_SUPPORT
> > def_bool y
> > @@ -134,6 +134,23 @@ menu "Bus support"
> > config ARM_AMBA
> > bool
> >
> > +config PCI
> > + bool "PCI support"
> > + help
> > + This feature enables support for PCIe bus system. If you say Y
> > + here, the kernel will include drivers and infrastructure code
> > + to support PCIe bus devices.
> > +
> > +config PCI_DOMAINS
> > + def_bool PCI
> > +
> > +config PCI_SYSCALL
> > + def_bool PCI
> > +
> > +source "drivers/pci/Kconfig"
> > +source "drivers/pci/pcie/Kconfig"
> > +source "drivers/pci/hotplug/Kconfig"
> > +
> > endmenu
> >
> > menu "Kernel Features"
> > diff --git a/arch/arm64/include/asm/Kbuild b/arch/arm64/include/asm/Kbuild
> > index 71c53ec..46924bc 100644
> > --- a/arch/arm64/include/asm/Kbuild
> > +++ b/arch/arm64/include/asm/Kbuild
> > @@ -26,6 +26,7 @@ generic-y += mman.h
> > generic-y += msgbuf.h
> > generic-y += mutex.h
> > generic-y += pci.h
> > +generic-y += pci-bridge.h
> > generic-y += poll.h
> > generic-y += posix_types.h
> > generic-y += resource.h
> > diff --git a/arch/arm64/include/asm/io.h b/arch/arm64/include/asm/io.h
> > index 7846a6b..67463a5 100644
> > --- a/arch/arm64/include/asm/io.h
> > +++ b/arch/arm64/include/asm/io.h
> > @@ -120,7 +120,8 @@ static inline u64 __raw_readq(const volatile void __iomem *addr)
> > /*
> > * I/O port access primitives.
> > */
> > -#define IO_SPACE_LIMIT 0xffff
> > +#define arch_has_dev_port() (1)
> > +#define IO_SPACE_LIMIT 0x1ffffff
> > #define PCI_IOBASE ((void __iomem *)(MODULES_VADDR - SZ_32M))
> >
> > static inline u8 inb(unsigned long addr)
> > diff --git a/arch/arm64/include/asm/pci.h b/arch/arm64/include/asm/pci.h
> > new file mode 100644
> > index 0000000..d93576f
> > --- /dev/null
> > +++ b/arch/arm64/include/asm/pci.h
> > @@ -0,0 +1,51 @@
> > +#ifndef __ASM_PCI_H
> > +#define __ASM_PCI_H
> > +#ifdef __KERNEL__
> > +
> > +#include <linux/types.h>
> > +#include <linux/slab.h>
> > +#include <linux/dma-mapping.h>
> > +
> > +#include <asm/io.h>
> > +#include <asm-generic/pci-bridge.h>
> > +#include <asm-generic/pci-dma-compat.h>
> > +
> > +#define PCIBIOS_MIN_IO 0x1000
> > +#define PCIBIOS_MIN_MEM 0
> > +
> > +struct pci_host_bridge *find_pci_host_bridge(struct pci_bus *bus);
> > +
> > +/*
> > + * Set to 1 if the kernel should re-assign all PCI bus numbers
> > + */
> > +#define pcibios_assign_all_busses() \
> > + (pci_has_flag(PCI_REASSIGN_ALL_BUS))
> > +
> > +/*
> > + * PCI address space differs from physical memory address space
> > + */
> > +#define PCI_DMA_BUS_IS_PHYS (0)
> > +
> > +extern int isa_dma_bridge_buggy;
> > +
> > +#ifdef CONFIG_PCI
> > +static inline int pci_domain_nr(struct pci_bus *bus)
> > +{
> > + struct pci_host_bridge *bridge = find_pci_host_bridge(bus);
> > +
> > + if (bridge)
> > + return bridge->domain_nr;
> > +
> > + return 0;
> > +}
> > +
> > +static inline int pci_proc_domain(struct pci_bus *bus)
> > +{
> > + return 1;
> > +}
> > +#endif
> > +
> > +extern unsigned long pci_ioremap_io(const struct resource *res, phys_addr_t phys_addr);
> > +
> > +#endif /* __KERNEL__ */
> > +#endif /* __ASM_PCI_H */
> > diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
> > index 2d4554b..64fc479 100644
> > --- a/arch/arm64/kernel/Makefile
> > +++ b/arch/arm64/kernel/Makefile
> > @@ -20,6 +20,7 @@ arm64-obj-$(CONFIG_HAVE_HW_BREAKPOINT)+= hw_breakpoint.o
> > arm64-obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
> > arm64-obj-$(CONFIG_ARM64_CPU_SUSPEND) += sleep.o suspend.o
> > arm64-obj-$(CONFIG_JUMP_LABEL) += jump_label.o
> > +arm64-obj-$(CONFIG_PCI) += pci.o
> >
> > obj-y += $(arm64-obj-y) vdso/
> > obj-m += $(arm64-obj-m)
> > diff --git a/arch/arm64/kernel/pci.c b/arch/arm64/kernel/pci.c
> > new file mode 100644
> > index 0000000..9f29c9a
> > --- /dev/null
> > +++ b/arch/arm64/kernel/pci.c
> > @@ -0,0 +1,173 @@
> > +/*
> > + * Code borrowed from powerpc/kernel/pci-common.c
> > + *
> > + * Copyright (C) 2003 Anton Blanchard <anton-hXjcm30GF6XQT0dZR+AlfA@public.gmane.org>, IBM
> > + * Copyright (C) 2014 ARM Ltd.
> > + *
> > + * This program is free software; you can redistribute it and/or
> > + * modify it under the terms of the GNU General Public License
> > + * version 2 as published by the Free Software Foundation.
> > + *
> > + */
> > +
> > +#include <linux/init.h>
> > +#include <linux/io.h>
> > +#include <linux/kernel.h>
> > +#include <linux/mm.h>
> > +#include <linux/of_pci.h>
> > +#include <linux/of_platform.h>
> > +#include <linux/slab.h>
> > +
> > +#include <asm/pci-bridge.h>
> > +
> > +struct ioresource {
> > + struct list_head list;
> > + phys_addr_t start;
> > + resource_size_t size;
> > +};
> > +
> > +static LIST_HEAD(io_list);
> > +
> > +int pci_register_io_range(phys_addr_t address, resource_size_t size)
> > +{
> > + struct ioresource *res;
> > + resource_size_t allocated_size = 0;
> > +
> > + /* find if the range has not been already allocated */
> > + list_for_each_entry(res, &io_list, list) {
> > + if (address >= res->start &&
> > + address + size <= res->start + size)
> > + return 0;
> > + allocated_size += res->size;
> > + }
> > +
> > + /* range not already registered, check for space */
> > + if (allocated_size + size > IO_SPACE_LIMIT)
> > + return -E2BIG;
> > +
> > + /* add the range in the list */
> > + res = kzalloc(sizeof(*res), GFP_KERNEL);
> > + if (!res)
> > + return -ENOMEM;
> > + res->start = address;
> > + res->size = size;
> > +
> > + list_add_tail(&res->list, &io_list);
> > +
> > + return 0;
> > +}
> > +EXPORT_SYMBOL_GPL(pci_register_io_range);
> > +
> > +unsigned long pci_address_to_pio(phys_addr_t address)
> > +{
> > + struct ioresource *res;
> > +
> > + list_for_each_entry(res, &io_list, list) {
> > + if (address >= res->start &&
> > + address < res->start + res->size) {
> > + return res->start - address;
> > + }
> > + }
> > +
> > + return (unsigned long)-1;
> > +}
> > +EXPORT_SYMBOL_GPL(pci_address_to_pio);
> > +
> > +/*
> > + * Called after each bus is probed, but before its children are examined
> > + */
> > +void pcibios_fixup_bus(struct pci_bus *bus)
> > +{
> > + struct pci_dev *dev;
> > + struct resource *res;
> > + int i;
> > +
> > + if (!pci_is_root_bus(bus)) {
> > + pci_read_bridge_bases(bus);
> > +
> > + pci_bus_for_each_resource(bus, res, i) {
> > + if (!res || !res->flags || res->parent)
> > + continue;
> > +
> > + /*
> > + * If we are going to reassign everything, we can
> > + * shrink the P2P resource to have zero size to
> > + * save space
> > + */
> > + if (pci_has_flag(PCI_REASSIGN_ALL_RSRC)) {
> > + res->flags |= IORESOURCE_UNSET;
> > + res->start = 0;
> > + res->end = -1;
> > + continue;
> > + }
> > + }
> > + }
>
> Is there any other place we can put this? I'm trying to nuke
> pcibios_fixup_bus() because things like hotplug work better if we can do
> them in a per-device way rather than a per-bus way.
That's good. I'm all for removing this one, will give it a go.
>
> > +
> > + list_for_each_entry(dev, &bus->devices, bus_list) {
> > + /* Ignore fully discovered devices */
> > + if (dev->is_added)
> > + continue;
> > +
> > + set_dev_node(&dev->dev, pcibus_to_node(dev->bus));
>
> Do you really need this? pci_device_add() already contains the same line.
OK.
>
> > +
> > + /* Read default IRQs and fixup if necessary */
> > + dev->irq = of_irq_parse_and_map_pci(dev, 0, 0);
>
> Could this be done in pcibios_add_device() or someplace similar?
Will do.
>
> > + }
> > +}
> > +EXPORT_SYMBOL(pcibios_fixup_bus);
> > +
> > +/*
> > + * We don't have to worry about legacy ISA devices, so nothing to do here
> > + */
> > +resource_size_t pcibios_align_resource(void *data, const struct resource *res,
> > + resource_size_t size, resource_size_t align)
> > +{
> > + return res->start;
> > +}
> > +
> > +int pcibios_enable_device(struct pci_dev *dev, int mask)
> > +{
> > + return pci_enable_resources(dev, mask);
> > +}
>
> There is already a weak default implementation of pcibios_enable_device()
> that does this, so you should be able to just drop this.
OK.
Thanks for reviewing the series!
Liviu
>
> > +#define IO_SPACE_PAGES ((IO_SPACE_LIMIT + 1) / PAGE_SIZE)
> > +static DECLARE_BITMAP(pci_iospace, IO_SPACE_PAGES);
> > +
> > +unsigned long pci_ioremap_io(const struct resource *res, phys_addr_t phys_addr)
> > +{
> > + unsigned long start, len, virt_start;
> > + int err;
> > +
> > + if (res->end > IO_SPACE_LIMIT)
> > + return -EINVAL;
> > +
> > + /*
> > + * try finding free space for the whole size first,
> > + * fall back to 64K if not available
> > + */
> > + len = resource_size(res);
> > + start = bitmap_find_next_zero_area(pci_iospace, IO_SPACE_PAGES,
> > + res->start / PAGE_SIZE, len / PAGE_SIZE, 0);
> > + if (start == IO_SPACE_PAGES && len > SZ_64K) {
> > + len = SZ_64K;
> > + start = 0;
> > + start = bitmap_find_next_zero_area(pci_iospace, IO_SPACE_PAGES,
> > + start, len / PAGE_SIZE, 0);
> > + }
> > +
> > + /* no 64K area found */
> > + if (start == IO_SPACE_PAGES)
> > + return -ENOMEM;
> > +
> > + /* ioremap physical aperture to virtual aperture */
> > + virt_start = start * PAGE_SIZE + (unsigned long)PCI_IOBASE;
> > + err = ioremap_page_range(virt_start, virt_start + len,
> > + phys_addr, __pgprot(PROT_DEVICE_nGnRE));
> > + if (err)
> > + return err;
> > +
> > + bitmap_set(pci_iospace, start, len / PAGE_SIZE);
> > +
> > + /* return io_offset */
> > + return start * PAGE_SIZE - res->start;
> > +}
> > --
> > 1.9.0
> >
>
--
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯
--
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-04-08 9:52 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-14 15:34 [PATCH v7 0/3] Add support for PCI in AArch64 Liviu Dudau
2014-03-14 15:34 ` [PATCH v7 1/3] Fix ioport_map() for !CONFIG_GENERIC_IOMAP cases Liviu Dudau
2014-03-14 15:34 ` [PATCH v7 2/3] arm64: Extend the PCI I/O space to 16MB Liviu Dudau
2014-03-14 15:34 ` [PATCH v7 3/3] arm64: Add architecture support for PCI Liviu Dudau
2014-03-14 17:14 ` Catalin Marinas
2014-03-14 17:38 ` Arnd Bergmann
2014-03-14 18:05 ` Liviu Dudau
2014-03-14 19:10 ` Arnd Bergmann
2014-03-16 6:22 ` Benjamin Herrenschmidt
2014-03-17 17:38 ` Catalin Marinas
2014-03-17 18:05 ` Liviu Dudau
2014-03-19 13:56 ` Catalin Marinas
2014-03-19 17:21 ` Liviu Dudau
[not found] ` <20140319172140.GA16328-2JSQmVVBSi7ZROr8t4l/smS4ubULX0JqMm0uRHvK7Nw@public.gmane.org>
2014-03-19 17:53 ` Rob Herring
2014-03-19 18:36 ` Arnd Bergmann
2014-03-19 18:37 ` Arnd Bergmann
2014-03-20 9:46 ` Liviu Dudau
2014-03-20 11:17 ` Arnd Bergmann
2014-03-20 11:38 ` Liviu Dudau
2014-03-20 12:26 ` Arnd Bergmann
2014-03-20 12:50 ` Liviu Dudau
[not found] ` <1394811258-1500-4-git-send-email-Liviu.Dudau-5wv7dgnIgG8@public.gmane.org>
2014-03-17 16:05 ` Rob Herring
2014-03-17 16:22 ` Liviu Dudau
2014-04-07 23:58 ` Bjorn Helgaas
[not found] ` <20140407235830.GA9959-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2014-04-08 9:52 ` Liviu Dudau [this message]
2014-04-22 8:58 ` [PATCH v7 0/3] Add support for PCI in AArch64 Sandeepa Prabhu
[not found] ` <CA+b37P3HqMFU6kGA+GH3YpGM_Z=TwNXL6jKu+ConR3kCk-Tp4g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-04-22 10:11 ` Liviu Dudau
2014-04-22 11:50 ` Sandeepa Prabhu
2014-04-22 12:34 ` Liviu Dudau
2014-04-23 20:32 ` Tanmay Inamdar
2014-04-24 3:08 ` Sandeepa Prabhu
2014-05-16 10:33 ` Sunil Kovvuri
[not found] ` <CA+sq2Ccok5wtKjCZUkBhhj3WsiqFAoMgHK7LY210aBtMku+8SA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-05-16 13:24 ` Liviu Dudau
2014-05-16 17:42 ` Sunil Kovvuri
2014-05-21 11:15 ` Sunil Kovvuri
[not found] ` <CA+sq2Ccp0_4hgbbWa27bkYcqiXY6Ckr8eckWnHwANvhWNo97fg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-05-21 11:34 ` Liviu Dudau
[not found] ` <20140521113421.GB13511-hOhETlTuV5niMG9XS5x8Mg@public.gmane.org>
2014-05-21 17:06 ` Jason Gunthorpe
2014-05-19 13:01 ` Arnd Bergmann
2014-05-20 4:22 ` Sunil Kovvuri
[not found] ` <CA+sq2Ce+8YB+02B7zhxTXwropZXv9spy-w=AJ8YXCP69kr-_1A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-05-20 8:44 ` Arnd Bergmann
2014-05-20 8:55 ` Sunil Kovvuri
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=20140408095246.GU17163@e106497-lin.cambridge.arm.com \
--to=liviu.dudau-5wv7dgnigg8@public.gmane.org \
--cc=Catalin.Marinas-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=bhelgaas-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org \
--cc=linaro-kernel-cunTk1MwBs8s++Sfvej+rw@public.gmane.org \
--cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-pci-u79uwXL29TY76Z2rM5mHXA@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).