diff mbox series

[1/5] arm: ioremap: Implement standard PCI function pci_remap_iospace()

Message ID 20211124154116.916-2-pali@kernel.org
State New
Headers show
Series arm: ioremap: Remove pci_ioremap_io() and mvebu_pci_host_probe() | expand

Commit Message

Pali Rohár Nov. 24, 2021, 3:41 p.m. UTC
pci_remap_iospace() is standard PCI core function. Architecture code can
reimplement default core implementation if needs custom arch specific
functionality.

ARM needs custom implementation due to pci_ioremap_set_mem_type() hook
which allows ARM platforms to change mem type for iospace.

Implement this pci_remap_iospace() function for ARM architecture to
correctly handle pci_ioremap_set_mem_type() hook, which allows usage of
this standard PCI core function also for platforms which needs different
mem type (e.g. Marvell Armada 375, 38x and 39x).

Signed-off-by: Pali Rohár <pali@kernel.org>
---
 arch/arm/include/asm/io.h |  5 +++++
 arch/arm/mm/ioremap.c     | 15 +++++++++++++++
 2 files changed, 20 insertions(+)

Comments

Russell King (Oracle) Nov. 24, 2021, 3:51 p.m. UTC | #1
On Wed, Nov 24, 2021 at 04:41:12PM +0100, Pali Rohár wrote:
> pci_remap_iospace() is standard PCI core function. Architecture code can
> reimplement default core implementation if needs custom arch specific
> functionality.
> 
> ARM needs custom implementation due to pci_ioremap_set_mem_type() hook
> which allows ARM platforms to change mem type for iospace.
> 
> Implement this pci_remap_iospace() function for ARM architecture to
> correctly handle pci_ioremap_set_mem_type() hook, which allows usage of
> this standard PCI core function also for platforms which needs different
> mem type (e.g. Marvell Armada 375, 38x and 39x).
> 
> Signed-off-by: Pali Rohár <pali@kernel.org>

Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
diff mbox series

Patch

diff --git a/arch/arm/include/asm/io.h b/arch/arm/include/asm/io.h
index c576fa7d9bf8..12eca75bdee9 100644
--- a/arch/arm/include/asm/io.h
+++ b/arch/arm/include/asm/io.h
@@ -182,6 +182,11 @@  static inline void pci_ioremap_set_mem_type(int mem_type) {}
 
 extern int pci_ioremap_io(unsigned int offset, phys_addr_t phys_addr);
 
+struct resource;
+
+#define pci_remap_iospace pci_remap_iospace
+int pci_remap_iospace(const struct resource *res, phys_addr_t phys_addr);
+
 /*
  * PCI configuration space mapping function.
  *
diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
index 6e830b9418c9..fa3bde48d6a7 100644
--- a/arch/arm/mm/ioremap.c
+++ b/arch/arm/mm/ioremap.c
@@ -459,6 +459,21 @@  void pci_ioremap_set_mem_type(int mem_type)
 	pci_ioremap_mem_type = mem_type;
 }
 
+int pci_remap_iospace(const struct resource *res, phys_addr_t phys_addr)
+{
+	unsigned long vaddr = (unsigned long)PCI_IOBASE + res->start;
+
+	if (!(res->flags & IORESOURCE_IO))
+		return -EINVAL;
+
+	if (res->end > IO_SPACE_LIMIT)
+		return -EINVAL;
+
+	return ioremap_page_range(vaddr, vaddr + resource_size(res), phys_addr,
+				  __pgprot(get_mem_type(pci_ioremap_mem_type)->prot_pte));
+}
+EXPORT_SYMBOL(pci_remap_iospace);
+
 int pci_ioremap_io(unsigned int offset, phys_addr_t phys_addr)
 {
 	BUG_ON(offset + SZ_64K - 1 > IO_SPACE_LIMIT);