powerpc/mm: cleanup and refactoring in ioremap
Subsystems (3)
v2 cover powerpc/mm: cleanup and refactoring in ioremap
The purpose of this series is to cleanup and refactor ioremap.
At the time being, ioremap is duplicated in PPC32 and PPC64. In addition, some additional duplication also appear within PPC64.
First part of this series drops as much as unused functions. Then io-workaround is reworked to avoid indirect function call. Then common parts of PPC32 and PPC64 are regrouped into a new file called ioremap.c
Then other parts linked to ioremap are respectively moved out of pgtable_32/64.c
The last part of the series tries to refactor ioremap_range() and make use of ioremap_page_range() for all, then separates the early path from the regular ioremap.
A future follow-up of this series will be to try and eliminate the early ioremap part and use the generic early_ioremap instead.
v2:
- dropped the change of ioremap_bot growing direction for PPC64 and kept separate __ioremap_caller() and friends.
- separating more clearly early_ioremap() from regular ioremap()
- addressed received comments.
Christophe Leroy (12):
powerpc: remove the ppc44x ocm.c file
powerpc/ps3: replace __ioremap() by ioremap_prot() powerpc/mm: drop ppc_md.iounmap() and __iounmap() powerpc/mm: drop function __ioremap()
powerpc/mm: rework io-workaround invocation.
powerpc/mm: move common 32/64 bits ioremap functions into ioremap.c powerpc/mm: move ioremap_prot() into ioremap.c powerpc/mm: make ioremap_bot common to all
powerpc/mm: Move ioremap functions out of pgtable_32/64.c powerpc/mm: refactor ioremap_range() and use ioremap_page_range() powerpc/mm: refactor ioremap vm area setup.
powerpc/mm: split out early ioremap path.
arch/powerpc/configs/ppc40x_defconfig | 1 - arch/powerpc/include/asm/book3s/32/pgtable.h | 6 +- arch/powerpc/include/asm/book3s/64/pgtable.h | 2 +- arch/powerpc/include/asm/book3s/64/radix.h | 3 - arch/powerpc/include/asm/io-workarounds.h | 20 ++ arch/powerpc/include/asm/io.h | 16 +- arch/powerpc/include/asm/machdep.h | 4 - arch/powerpc/include/asm/nohash/32/pgtable.h | 6 +- arch/powerpc/include/asm/nohash/64/pgtable.h | 1 + arch/powerpc/include/asm/pgtable.h | 2 + arch/powerpc/include/asm/ppc4xx_ocm.h | 31 --- arch/powerpc/kernel/io-workarounds.c | 13 +- arch/powerpc/mm/Makefile | 2 +- arch/powerpc/mm/book3s64/pgtable.c | 21 -- arch/powerpc/mm/book3s64/radix_pgtable.c | 20 -- arch/powerpc/mm/ioremap.c | 99 +++++++ arch/powerpc/mm/ioremap_32.c | 92 +++++++ arch/powerpc/mm/ioremap_64.c | 113 ++++++++ arch/powerpc/mm/mmu_decl.h | 1 - arch/powerpc/mm/nohash/tlb.c | 2 + arch/powerpc/mm/pgtable_32.c | 153 ----------- arch/powerpc/mm/pgtable_64.c | 203 +------------- arch/powerpc/platforms/44x/Kconfig | 8 - arch/powerpc/platforms/4xx/Makefile | 1 - arch/powerpc/platforms/4xx/ocm.c | 390 --------------------------- arch/powerpc/platforms/ps3/spu.c | 10 +- 26 files changed, 353 insertions(+), 867 deletions(-) delete mode 100644 arch/powerpc/include/asm/ppc4xx_ocm.h create mode 100644 arch/powerpc/mm/ioremap.c create mode 100644 arch/powerpc/mm/ioremap_32.c create mode 100644 arch/powerpc/mm/ioremap_64.c delete mode 100644 arch/powerpc/platforms/4xx/ocm.c
Signature · 1 line
2.13.3
PATCH v2 1/12 powerpc: remove the ppc44x ocm.c file
From: Christoph Hellwig <[email protected]>
The on chip memory allocator is entirely unused in the kernel tree.
--- arch/powerpc/configs/ppc40x_defconfig | 1 - arch/powerpc/include/asm/ppc4xx_ocm.h | 31 --- arch/powerpc/platforms/44x/Kconfig | 8 - arch/powerpc/platforms/4xx/Makefile | 1 - arch/powerpc/platforms/4xx/ocm.c | 390 ---------------------------------- 5 files changed, 431 deletions(-) delete mode 100644 arch/powerpc/include/asm/ppc4xx_ocm.h delete mode 100644 arch/powerpc/platforms/4xx/ocm.c
arch/powerpc/configs/ppc40x_defconfig +0 -1
@@ -84,4 +84,3 @@ CONFIG_CRYPTO_ECB=y CONFIG_CRYPTO_PCBC=y CONFIG_CRYPTO_MD5=y CONFIG_CRYPTO_DES=y -CONFIG_PPC4xx_OCM=y
arch/powerpc/include/asm/ppc4xx_ocm.h deleted +0 -31
@@ -1,31 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* -* PowerPC 4xx OCM memory allocation support -* -* (C) Copyright 2009, Applied Micro Circuits Corporation -* Victor Gallardo ([email protected]) -* -* See file CREDITS for list of people who contributed to this -* project. -*/ - -#ifndef __ASM_POWERPC_PPC4XX_OCM_H__ -#define __ASM_POWERPC_PPC4XX_OCM_H__ - -#define PPC4XX_OCM_NON_CACHED 0 -#define PPC4XX_OCM_CACHED 1 - -#if defined(CONFIG_PPC4xx_OCM) - -void *ppc4xx_ocm_alloc (phys_addr_t *phys,int size,int align, -int flags,const char *owner); -void ppc4xx_ocm_free (const void *virt); - -#else - -#define ppc4xx_ocm_alloc (phys, size, align, flags, owner) NULL -#define ppc4xx_ocm_free (addr) ((void)0) - -#endif /* CONFIG_PPC4xx_OCM */ - -#endif /* __ASM_POWERPC_PPC4XX_OCM_H__ */
arch/powerpc/platforms/44x/Kconfig +0 -8
@@ -272,14 +272,6 @@ config PPC4xx_GPIO help Enable gpiolib support for ppc440 based boards -config PPC4xx_OCM - bool "PPC4xx On Chip Memory (OCM) support" - depends on 4xx - select PPC_LIB_RHEAP - help - Enable OCM support for PowerPC 4xx platforms with on chip memory, - OCM provides the fast place for memory access to improve performance. - # 44x specific CPU modules, selected based on the board above. config 440EP bool
arch/powerpc/platforms/4xx/Makefile +0 -1
@@ -1,6 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only obj-y += uic.o machine_check.o -obj-$(CONFIG_PPC4xx_OCM) += ocm.o obj-$(CONFIG_4xx_SOC) += soc.o obj-$(CONFIG_PCI) += pci.o obj-$(CONFIG_PPC4xx_HSTA_MSI) += hsta_msi.o
arch/powerpc/platforms/4xx/ocm.c deleted +0 -390
390 lines not on this page · raw message
Signature · 1 line
2.13.3
Re: [PATCH v2 01/12] powerpc: remove the ppc44x ocm.c file
Quoted 7 lines · Christophe Leroy
From: Christoph Hellwig <[email protected]>
The on chip memory allocator is entirely unused in the kernel tree.
Signed-off-by Christoph Hellwig <[email protected]>Acked-by Christophe Leroy <[email protected]>Signed-off-by Christophe Leroy <[email protected]>
Series applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/f0f8d7ae3924ed93453e30123e4aaf6f888ca555
cheers
PATCH v2 2/12 powerpc/ps3: replace __ioremap() by ioremap_prot()
In reply to Christophe Leroy__ioremap() is similar to ioremap_prot() except that ioremap_prot() does a few sanity changes in addition.
The flags used by PS3 are not impacted by those changes so for PS3 both functions are equivalent.
At the same time, drop parts of the comment that have been invalid since commit e58e87adc8bf ("powerpc/mm: Update _PAGE_KERNEL_RO")
--- arch/powerpc/platforms/ps3/spu.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
arch/powerpc/platforms/ps3/spu.c +3 -7
@@ -184,10 +184,7 @@ static void spu_unmap(struct spu *spu)* setup_areas - Map the spu regions into the address space. * * The current HV requires the spu shadow regs to be mapped with the -* PTE page protection bits set as read-only (PP=3). This implementation -* uses the low level __ioremap() to bypass the page protection settings -* inforced by ioremap_prot() to get the needed PTE bits set for the -* shadow regs. +* PTE page protection bits set as read-only. */ static int __init setup_areas (struct spu *spu)
@@ -195,9 +192,8 @@ static int __init setup_areas(struct spu *spu)struct table {char * name;unsigned long addr;unsigned long size;};unsigned long shadow_flags =pgprot_val (pgprot_noncached_wc (PAGE_KERNEL_RO )); -spu_pdata (spu)->shadow =__ioremap (spu_pdata (spu)->shadow_addr, -sizeof (struct spe_shadow ), - shadow_flags); +spu_pdata (spu)->shadow =ioremap_prot (spu_pdata (spu)->shadow_addr, +sizeof (struct spe_shadow ), shadow_flags);if (!spu_pdata (spu)->shadow) {pr_debug ("%s:%d: ioremap shadow failed\n" , __func__, __LINE__); goto fail_ioremap;
Signature · 1 line
2.13.3
Re: [PATCH v2 02/12] powerpc/ps3: replace __ioremap() by ioremap_prot()
Quoted 11 lines · Christophe Leroy
__ioremap()is similar toioremap_prot()except thatioremap_prot()does a few sanity changes in addition.The flags used by PS3 are not impacted by those changes so for PS3 both functions are equivalent.
At the same time, drop parts of the comment that have been invalid since commit
e58e87adc8bf("powerpc/mm: Update_PAGE_KERNEL_RO")Suggested-by Christoph Hellwig <[email protected]>Signed-off-by Christophe Leroy <[email protected]>
Looks good,
PATCH v2 3/12 powerpc/mm: drop ppc_md.iounmap() and __iounmap()
In reply to Christophe Leroyppc_md.iounmap() is never set, drop it.
Once ppc_md.iounmap() is gone, iounmap() remains the only user of __iounmap() and iounmap() does nothing else than calling __iounmap(). So drop iounmap() and make __iounmap() the new iounmap().
--- arch/powerpc/include/asm/io.h | 5 ----- arch/powerpc/include/asm/machdep.h | 2 -- arch/powerpc/mm/pgtable_64.c | 11 +---------- 3 files changed, 1 insertion(+), 17 deletions(-)
arch/powerpc/include/asm/io.h +0 -5
@@ -712,9 +712,6 @@ static inline void iosync(void)* * __ioremap_caller is the same as above but takes an explicit caller * reference rather than using __builtin_return_address(0) * -* * __iounmap, is the low level implementation used by iounmap and cannot -* be hooked (but can be used by a hook on iounmap) -* */ extern void __iomem *ioremap (phys_addr_t address,unsigned long size); extern void __iomem *ioremap_prot(phys_addr_t address, unsigned long size,
@@ -734,8 +731,6 @@ extern void __iomem *__ioremap(phys_addr_t, unsigned long size,extern void __iomem *__ioremap_caller (phys_addr_t ,unsigned long size,pgprot_t prot,void *caller); -extern void __iounmap (volatile void __iomem *addr); -extern void __iomem *__ioremap_at (phys_addr_t pa,void *ea,unsigned long size,pgprot_t prot);extern void __iounmap_at (void *ea,unsigned long size);
arch/powerpc/include/asm/machdep.h +0 -2
@@ -33,8 +33,6 @@ struct machdep_calls {#ifdef CONFIG_PPC64 void __iomem * (*ioremap)(phys_addr_t addr,unsigned long size,pgprot_t prot,void *caller); -void (*iounmap)(volatile void __iomem *token); -#ifdef CONFIG_PM void (*iommu_save)(void );void (*iommu_restore)(void );
arch/powerpc/mm/pgtable_64.c +1 -10
@@ -266,7 +266,7 @@ void __iomem * ioremap_prot(phys_addr_t addr, unsigned long size,* Unmap an IO region and remove it from imalloc'd list. * Access to IO memory should be serialized by driver. */ -void __iounmap (volatile void __iomem *token) +void iounmap (volatile void __iomem *token) {void *addr;
@@ -283,21 +283,12 @@ void __iounmap(volatile void __iomem *token)vunmap (addr); } -void iounmap (volatile void __iomem *token) -{ -if (ppc_md.iounmap) - ppc_md.iounmap (token); -else -__iounmap (token); -} -EXPORT_SYMBOL (ioremap);EXPORT_SYMBOL (ioremap_wc);EXPORT_SYMBOL (ioremap_prot);EXPORT_SYMBOL (__ioremap);EXPORT_SYMBOL (__ioremap_at);EXPORT_SYMBOL (iounmap); -EXPORT_SYMBOL (__iounmap);EXPORT_SYMBOL (__iounmap_at);#ifndef __PAGETABLE_PUD_FOLDED
Signature · 1 line
2.13.3
PATCH v2 4/12 powerpc/mm: drop function __ioremap()
In reply to Christophe Leroy__ioremap() is not used anymore, drop it.
--- arch/powerpc/include/asm/io.h | 6 ------ arch/powerpc/mm/pgtable_32.c | 11 ++--------- arch/powerpc/mm/pgtable_64.c | 7 ------- 3 files changed, 2 insertions(+), 22 deletions(-)
arch/powerpc/include/asm/io.h +0 -6
@@ -705,10 +705,6 @@ static inline void iosync(void)* create hand-made mappings for use only by the PCI code and cannot * currently be hooked. Must be page aligned. * -* * __ioremap is the low level implementation used by ioremap and -* ioremap_prot and cannot be hooked (but can be used by a hook on one -* of the previous ones) -* * * __ioremap_caller is the same as above but takes an explicit caller * reference rather than using __builtin_return_address(0) *
@@ -726,8 +722,6 @@ void __iomem *ioremap_coherent(phys_addr_t address, unsigned long size);extern void iounmap (volatile void __iomem *addr); -extern void __iomem *__ioremap (phys_addr_t ,unsigned long size, -unsigned long flags);extern void __iomem *__ioremap_caller (phys_addr_t ,unsigned long size,pgprot_t prot,void *caller);
arch/powerpc/mm/pgtable_32.c +2 -9
@@ -92,12 +92,6 @@ ioremap_prot(phys_addr_t addr, unsigned long size, unsigned long flags)EXPORT_SYMBOL (ioremap_prot);void __iomem * -__ioremap (phys_addr_t addr,unsigned long size,unsigned long flags) -{ -return __ioremap_caller (addr, size,__pgprot (flags),__builtin_return_address (0 )); -} - -void __iomem *__ioremap_caller (phys_addr_t addr,unsigned long size,pgprot_t prot,void *caller) {unsigned long v, i;
@@ -127,8 +121,8 @@ __ioremap_caller(phys_addr_t addr, unsigned long size, pgprot_t prot, void *call*/ if (slab_is_available () && p <=virt_to_phys (high_memory -1 ) &&page_is_ram (__phys_to_pfn (p))) { -printk ("__ioremap(): phys addr 0x%llx is RAM lr %ps\n" , - (unsigned long long )p,__builtin_return_address (0 )); +pr_warn ("%s(): phys addr 0x%llx is RAM lr %ps\n" , __func__, + (unsigned long long )p,__builtin_return_address (0 ));return NULL ; }#endif
@@ -171,7 +165,6 @@ __ioremap_caller(phys_addr_t addr, unsigned long size, pgprot_t prot, void *call out:return (void __iomem *) (v + ((unsigned long )addr & ~PAGE_MASK )); } -EXPORT_SYMBOL (__ioremap);void iounmap (volatile void __iomem *addr) {
arch/powerpc/mm/pgtable_64.c +0 -7
@@ -203,12 +203,6 @@ void __iomem * __ioremap_caller(phys_addr_t addr, unsigned long size,return ret; } -void __iomem *__ioremap (phys_addr_t addr,unsigned long size, -unsigned long flags) -{ -return __ioremap_caller (addr, size,__pgprot (flags),__builtin_return_address (0 )); -} -void __iomem *ioremap (phys_addr_t addr,unsigned long size) {pgprot_t prot =pgprot_noncached (PAGE_KERNEL );
@@ -286,7 +280,6 @@ void iounmap(volatile void __iomem *token)EXPORT_SYMBOL (ioremap);EXPORT_SYMBOL (ioremap_wc);EXPORT_SYMBOL (ioremap_prot); -EXPORT_SYMBOL (__ioremap);EXPORT_SYMBOL (__ioremap_at);EXPORT_SYMBOL (iounmap);EXPORT_SYMBOL (__iounmap_at);
Signature · 1 line
2.13.3
Re: [PATCH v2 04/12] powerpc/mm: drop function __ioremap()
Quoted 4 lines · Christophe Leroy
__ioremap()is not used anymore, drop it.Suggested-by Christoph Hellwig <[email protected]>Signed-off-by Christophe Leroy <[email protected]>
Looks good, I've already dropped my version of this from the generic ioremap series:
PATCH v2 5/12 powerpc/mm: rework io-workaround invocation.
In reply to Christophe Leroyppc_md.ioremap() is only used for I/O workaround on CELL platform, so indirect function call can be avoided.
This patch reworks the io-workaround and ioremap() functions to use the global 'io_workaround_inited' flag for the activation of io-workaround.
When CONFIG_PPC_IO_WORKAROUNDS or CONFIG_PPC_INDIRECT_MMIO are not selected, the I/O workaround ioremap() voids and the global flag is not used.
--- arch/powerpc/include/asm/io-workarounds.h | 20 ++++++++++++++++++++ arch/powerpc/include/asm/machdep.h | 2 -- arch/powerpc/kernel/io-workarounds.c | 13 +++++-------- arch/powerpc/mm/pgtable_64.c | 17 +++++++++-------- 4 files changed, 34 insertions(+), 18 deletions(-)
arch/powerpc/include/asm/io-workarounds.h +20 -0
@@ -8,6 +8,7 @@#ifndef _IO_WORKAROUNDS_H#define _IO_WORKAROUNDS_H +#ifdef CONFIG_PPC_IO_WORKAROUNDS #include <linux/io.h> #include <asm/pci-bridge.h>
@@ -32,4 +33,23 @@ extern int spiderpci_iowa_init(struct iowa_bus *, void *);#define SPIDER_PCI_DUMMY_READ 0x0810#define SPIDER_PCI_DUMMY_READ_BASE 0x0814 +#endif + +#if defined(CONFIG_PPC_IO_WORKAROUNDS ) && defined(CONFIG_PPC_INDIRECT_MMIO ) +extern bool io_workaround_inited; + +static inline bool iowa_is_active (void ) +{ +return unlikely (io_workaround_inited); +} +#else +static inline bool iowa_is_active (void ) +{ +return false; +} +#endif + +void __iomem *iowa_ioremap (phys_addr_t addr,unsigned long size, +pgprot_t prot,void *caller); +#endif /* _IO_WORKAROUNDS_H */
arch/powerpc/include/asm/machdep.h +0 -2
@@ -31,8 +31,6 @@ struct pci_host_bridge;struct machdep_calls {char *name;#ifdef CONFIG_PPC64 -void __iomem * (*ioremap)(phys_addr_t addr,unsigned long size, -pgprot_t prot,void *caller);#ifdef CONFIG_PM void (*iommu_save)(void );void (*iommu_restore)(void );
arch/powerpc/kernel/io-workarounds.c +5 -8
@@ -149,8 +149,8 @@ static const struct ppc_pci_io iowa_pci_io = { };#ifdef CONFIG_PPC_INDIRECT_MMIO -static void __iomem *iowa_ioremap (phys_addr_t addr,unsigned long size, -pgprot_t prot,void *caller) +void __iomem *iowa_ioremap (phys_addr_t addr,unsigned long size, +pgprot_t prot,void *caller) {struct iowa_bus *bus;void __iomem *res =__ioremap_caller (addr, size, prot, caller);
@@ -163,20 +163,17 @@ static void __iomem *iowa_ioremap(phys_addr_t addr, unsigned long size, }return res; } -#else /* CONFIG_PPC_INDIRECT_MMIO */ -#define iowa_ioremap NULL#endif /* !CONFIG_PPC_INDIRECT_MMIO */ +bool io_workaround_inited; +/* Enable IO workaround */ static void io_workaround_init (void ) { -static int io_workaround_inited; -if (io_workaround_inited)return ; ppc_pci_io = iowa_pci_io; - ppc_md.ioremap = iowa_ioremap; - io_workaround_inited =1 ; + io_workaround_inited = true; }/* Register new bus to support workaround */
arch/powerpc/mm/pgtable_64.c +9 -8
@@ -35,6 +35,7 @@#include <asm/page.h> #include <asm/prom.h> #include <asm/io.h> +#include <asm/io-workarounds.h> #include <asm/mmu_context.h> #include <asm/pgtable.h> #include <asm/mmu.h>
@@ -208,8 +209,8 @@ void __iomem * ioremap(phys_addr_t addr, unsigned long size)pgprot_t prot =pgprot_noncached (PAGE_KERNEL );void *caller =__builtin_return_address (0 ); -if (ppc_md.ioremap) -return ppc_md.ioremap (addr, size, prot, caller); +if (iowa_is_active ()) +return iowa_ioremap (addr, size, prot, caller);return __ioremap_caller (addr, size, prot, caller); }
@@ -218,8 +219,8 @@ void __iomem * ioremap_wc(phys_addr_t addr, unsigned long size)pgprot_t prot =pgprot_noncached_wc (PAGE_KERNEL );void *caller =__builtin_return_address (0 ); -if (ppc_md.ioremap) -return ppc_md.ioremap (addr, size, prot, caller); +if (iowa_is_active ()) +return iowa_ioremap (addr, size, prot, caller);return __ioremap_caller (addr, size, prot, caller); }
@@ -228,8 +229,8 @@ void __iomem *ioremap_coherent(phys_addr_t addr, unsigned long size)pgprot_t prot =pgprot_cached (PAGE_KERNEL );void *caller =__builtin_return_address (0 ); -if (ppc_md.ioremap) -return ppc_md.ioremap (addr, size, prot, caller); +if (iowa_is_active ()) +return iowa_ioremap (addr, size, prot, caller);return __ioremap_caller (addr, size, prot, caller); }
@@ -250,8 +251,8 @@ void __iomem * ioremap_prot(phys_addr_t addr, unsigned long size,*/ pte =pte_mkprivileged (pte); -if (ppc_md.ioremap) -return ppc_md.ioremap (addr, size,pte_pgprot (pte), caller); +if (iowa_is_active ()) +return iowa_ioremap (addr, size,pte_pgprot (pte), caller);return __ioremap_caller (addr, size,pte_pgprot (pte), caller); }
Signature · 1 line
2.13.3
Re: [PATCH v2 05/12] powerpc/mm: rework io-workaround invocation.
Quoted 10 lines · Christophe Leroy
ppc_md.ioremap()is only used for I/O workaround on CELL platform, so indirect function call can be avoided.This patch reworks the io-workaround and
ioremap()functions to use the global 'io_workaround_inited' flag for the activation of io-workaround.When
CONFIG_PPC_IO_WORKAROUNDSorCONFIG_PPC_INDIRECT_MMIOare not selected, the I/O workaroundioremap()voids and the global flag is not used.
Note that CONFIG_PPC_IO_WORKAROUNDS is only selected by a specific cell config, and CONFIG_PPC_INDIRECT_MMIO is always selected by cell, so I think we can make CONFIG_PPC_IO_WORKAROUNDS depend on CONFIG_PPC_INDIRECT_MMIO
arch/powerpc/include/asm/io-workarounds.h extern int spiderpci_iowa_init(struct iowa_bus *, void *); · line 38
Quoted 13 lines
#define
_IO_WORKAROUNDS_Harch/powerpc/include/asm/io-workarounds.h +4
-0+#ifdef CONFIG_PPC_IO_WORKAROUNDS #include <linux/io.h> #include <asm/pci-bridge.h> @@ -32,4 +33,23 @@ extern int spiderpci_iowa_init(struct iowa_bus *, void *);#define SPIDER_PCI_DUMMY_READ 0x0810#define SPIDER_PCI_DUMMY_READ_BASE 0x0814 +#endif + +#if defined(CONFIG_PPC_IO_WORKAROUNDS ) && defined(CONFIG_PPC_INDIRECT_MMIO )
and simplify the ifdefs here a bit.
Otherwise this looks fine:
Re: [PATCH v2 05/12] powerpc/mm: rework io-workaround invocation.
Quoted 8 lines · Christoph Hellwig
Quoted 7 lines · Christophe Leroy
ppc_md.ioremap()is only used for I/O workaround on CELL platform, so indirect function call can be avoided.This patch reworks the io-workaround and
ioremap()functions to use the global 'io_workaround_inited' flag for the activation of io-workaround.
Quoted 8 lines
Quoted 3 lines
When
CONFIG_PPC_IO_WORKAROUNDSorCONFIG_PPC_INDIRECT_MMIOare not selected, the I/O workaroundioremap()voids and the global flag is not used.Note that
CONFIG_PPC_IO_WORKAROUNDSis only selected by a specific cell config, andCONFIG_PPC_INDIRECT_MMIOis always selected by cell, so I think we can makeCONFIG_PPC_IO_WORKAROUNDSdepend onCONFIG_PPC_INDIRECT_MMIO
Or we can deprecate that old platform... not sure anybody uses it anymore (if anybody ever did).
Cheers,
ben.
PATCH v2 6/12 powerpc/mm: move common 32/64 bits ioremap functions into ioremap.c
In reply to Christophe Leroyioremap(), ioremap_wc() and ioremap_coherent() are now identical on PPC32 and PPC64 as iowa_is_active() will always return false on PPC32. Move them into a new common location called ioremap.c
--- arch/powerpc/mm/Makefile | 2 +- arch/powerpc/mm/ioremap.c | 36 ++++++++++++++++++++++++++++++++++++ arch/powerpc/mm/pgtable_32.c | 27 --------------------------- arch/powerpc/mm/pgtable_64.c | 33 --------------------------------- 4 files changed, 37 insertions(+), 61 deletions(-) create mode 100644 arch/powerpc/mm/ioremap.c
arch/powerpc/mm/Makefile +1 -1
@@ -7,7 +7,7 @@ ccflags-$(CONFIG_PPC64) := $(NO_MINIMAL_TOC) obj-y := fault.o mem.o pgtable.o mmap.o \ init_$(BITS).o pgtable_$(BITS).o \ - pgtable-frag.o \ + pgtable-frag.o ioremap.o \ init-common.o mmu_context.o drmem.o obj-$(CONFIG_PPC_MMU_NOHASH) += nohash/ obj-$(CONFIG_PPC_BOOK3S_32) += book3s32/
arch/powerpc/mm/ioremap.c new file +36 -0
@@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <linux/io.h> +#include <asm/io-workarounds.h> + +void __iomem *ioremap (phys_addr_t addr,unsigned long size) +{ +pgprot_t prot =pgprot_noncached (PAGE_KERNEL ); +void *caller =__builtin_return_address (0 ); + +if (iowa_is_active ()) +return iowa_ioremap (addr, size, prot, caller); +return __ioremap_caller (addr, size, prot, caller); +} +EXPORT_SYMBOL (ioremap); + +void __iomem *ioremap_wc (phys_addr_t addr,unsigned long size) +{ +pgprot_t prot =pgprot_noncached_wc (PAGE_KERNEL ); +void *caller =__builtin_return_address (0 ); + +if (iowa_is_active ()) +return iowa_ioremap (addr, size, prot, caller); +return __ioremap_caller (addr, size, prot, caller); +} +EXPORT_SYMBOL (ioremap_wc); + +void __iomem *ioremap_coherent (phys_addr_t addr,unsigned long size) +{ +pgprot_t prot =pgprot_cached (PAGE_KERNEL ); +void *caller =__builtin_return_address (0 ); + +if (iowa_is_active ()) +return iowa_ioremap (addr, size, prot, caller); +return __ioremap_caller (addr, size, prot, caller); +}
arch/powerpc/mm/pgtable_32.c +0 -27
@@ -39,24 +39,6 @@ EXPORT_SYMBOL(ioremap_bot); /* aka VMALLOC_END */extern char etext[], _stext[], _sinittext[], _einittext[];void __iomem * -ioremap (phys_addr_t addr,unsigned long size) -{ -pgprot_t prot =pgprot_noncached (PAGE_KERNEL ); - -return __ioremap_caller (addr, size, prot,__builtin_return_address (0 )); -} -EXPORT_SYMBOL (ioremap); - -void __iomem * -ioremap_wc (phys_addr_t addr,unsigned long size) -{ -pgprot_t prot =pgprot_noncached_wc (PAGE_KERNEL ); - -return __ioremap_caller (addr, size, prot,__builtin_return_address (0 )); -} -EXPORT_SYMBOL (ioremap_wc); - -void __iomem *ioremap_wt (phys_addr_t addr,unsigned long size) {pgprot_t prot =pgprot_cached_wthru (PAGE_KERNEL );
@@ -66,15 +48,6 @@ ioremap_wt(phys_addr_t addr, unsigned long size)EXPORT_SYMBOL (ioremap_wt);void __iomem * -ioremap_coherent (phys_addr_t addr,unsigned long size) -{ -pgprot_t prot =pgprot_cached (PAGE_KERNEL ); - -return __ioremap_caller (addr, size, prot,__builtin_return_address (0 )); -} -EXPORT_SYMBOL (ioremap_coherent); - -void __iomem *ioremap_prot (phys_addr_t addr,unsigned long size,unsigned long flags) {pte_t pte =__pte (flags);
arch/powerpc/mm/pgtable_64.c +0 -33
@@ -35,7 +35,6 @@#include <asm/page.h> #include <asm/prom.h> #include <asm/io.h> -#include <asm/io-workarounds.h> #include <asm/mmu_context.h> #include <asm/pgtable.h> #include <asm/mmu.h>
@@ -204,36 +203,6 @@ void __iomem * __ioremap_caller(phys_addr_t addr, unsigned long size,return ret; } -void __iomem *ioremap (phys_addr_t addr,unsigned long size) -{ -pgprot_t prot =pgprot_noncached (PAGE_KERNEL ); -void *caller =__builtin_return_address (0 ); - -if (iowa_is_active ()) -return iowa_ioremap (addr, size, prot, caller); -return __ioremap_caller (addr, size, prot, caller); -} - -void __iomem *ioremap_wc (phys_addr_t addr,unsigned long size) -{ -pgprot_t prot =pgprot_noncached_wc (PAGE_KERNEL ); -void *caller =__builtin_return_address (0 ); - -if (iowa_is_active ()) -return iowa_ioremap (addr, size, prot, caller); -return __ioremap_caller (addr, size, prot, caller); -} - -void __iomem *ioremap_coherent (phys_addr_t addr,unsigned long size) -{ -pgprot_t prot =pgprot_cached (PAGE_KERNEL ); -void *caller =__builtin_return_address (0 ); - -if (iowa_is_active ()) -return iowa_ioremap (addr, size, prot, caller); -return __ioremap_caller (addr, size, prot, caller); -} -void __iomem *ioremap_prot (phys_addr_t addr,unsigned long size,unsigned long flags) {
@@ -278,8 +247,6 @@ void iounmap(volatile void __iomem *token)vunmap (addr); } -EXPORT_SYMBOL (ioremap); -EXPORT_SYMBOL (ioremap_wc);EXPORT_SYMBOL (ioremap_prot);EXPORT_SYMBOL (__ioremap_at);EXPORT_SYMBOL (iounmap);
Signature · 1 line
2.13.3
PATCH v2 7/12 powerpc/mm: move ioremap_prot() into ioremap.c
In reply to Christophe LeroyBoth ioremap_prot() are idenfical, move them into ioremap.c
--- arch/powerpc/mm/ioremap.c | 19 +++++++++++++++++++ arch/powerpc/mm/pgtable_32.c | 17 ----------------- arch/powerpc/mm/pgtable_64.c | 24 ------------------------ 3 files changed, 19 insertions(+), 41 deletions(-)
arch/powerpc/mm/ioremap.c +19 -0
@@ -34,3 +34,22 @@ void __iomem *ioremap_coherent(phys_addr_t addr, unsigned long size)return iowa_ioremap (addr, size, prot, caller);return __ioremap_caller (addr, size, prot, caller); } + +void __iomem *ioremap_prot (phys_addr_t addr,unsigned long size,unsigned long flags) +{ +pte_t pte =__pte (flags); +void *caller =__builtin_return_address (0 ); + +/* writeable implies dirty for kernel addresses */ +if (pte_write (pte)) + pte =pte_mkdirty (pte); + +/* we don't want to let _PAGE_USER and _PAGE_EXEC leak out */ + pte =pte_exprotect (pte); + pte =pte_mkprivileged (pte); + +if (iowa_is_active ()) +return iowa_ioremap (addr, size,pte_pgprot (pte), caller); +return __ioremap_caller (addr, size,pte_pgprot (pte), caller); +} +EXPORT_SYMBOL (ioremap_prot);
arch/powerpc/mm/pgtable_32.c +0 -17
@@ -48,23 +48,6 @@ ioremap_wt(phys_addr_t addr, unsigned long size)EXPORT_SYMBOL (ioremap_wt);void __iomem * -ioremap_prot (phys_addr_t addr,unsigned long size,unsigned long flags) -{ -pte_t pte =__pte (flags); - -/* writeable implies dirty for kernel addresses */ -if (pte_write (pte)) - pte =pte_mkdirty (pte); - -/* we don't want to let _PAGE_USER and _PAGE_EXEC leak out */ - pte =pte_exprotect (pte); - pte =pte_mkprivileged (pte); - -return __ioremap_caller (addr, size,pte_pgprot (pte),__builtin_return_address (0 )); -} -EXPORT_SYMBOL (ioremap_prot); - -void __iomem *__ioremap_caller (phys_addr_t addr,unsigned long size,pgprot_t prot,void *caller) {unsigned long v, i;
arch/powerpc/mm/pgtable_64.c +0 -24
@@ -203,29 +203,6 @@ void __iomem * __ioremap_caller(phys_addr_t addr, unsigned long size,return ret; } -void __iomem *ioremap_prot (phys_addr_t addr,unsigned long size, -unsigned long flags) -{ -pte_t pte =__pte (flags); -void *caller =__builtin_return_address (0 ); - -/* writeable implies dirty for kernel addresses */ -if (pte_write (pte)) - pte =pte_mkdirty (pte); - -/* we don't want to let _PAGE_EXEC leak out */ - pte =pte_exprotect (pte); -/* -* Force kernel mapping. -*/ - pte =pte_mkprivileged (pte); - -if (iowa_is_active ()) -return iowa_ioremap (addr, size,pte_pgprot (pte), caller); -return __ioremap_caller (addr, size,pte_pgprot (pte), caller); -} - -/* * Unmap an IO region and remove it from imalloc'd list. * Access to IO memory should be serialized by driver.
@@ -247,7 +224,6 @@ void iounmap(volatile void __iomem *token)vunmap (addr); } -EXPORT_SYMBOL (ioremap_prot);EXPORT_SYMBOL (__ioremap_at);EXPORT_SYMBOL (iounmap);EXPORT_SYMBOL (__iounmap_at);
Signature · 1 line
2.13.3
Re: [PATCH v2 07/12] powerpc/mm: move ioremap_prot() into ioremap.c
Quoted 1 line · Christophe Leroy
Both
ioremap_prot()are idenfical, move them intoioremap.c
s/idenfical/identical/
PATCH v2 8/12 powerpc/mm: make ioremap_bot common to all
In reply to Christophe LeroyDrop multiple definitions of ioremap_bot and make one common to all subarches.
Only CONFIG_PPC_BOOK3E_64 had a global static init value for ioremap_bot. Now ioremap_bot is set in early_init_mmu_global().
--- arch/powerpc/include/asm/book3s/32/pgtable.h | 2 -- arch/powerpc/include/asm/book3s/64/pgtable.h | 1 - arch/powerpc/include/asm/nohash/32/pgtable.h | 2 -- arch/powerpc/include/asm/pgtable.h | 2 ++ arch/powerpc/mm/ioremap.c | 3 +++ arch/powerpc/mm/mmu_decl.h | 1 - arch/powerpc/mm/nohash/tlb.c | 2 ++ arch/powerpc/mm/pgtable_32.c | 3 --- arch/powerpc/mm/pgtable_64.c | 3 --- 9 files changed, 7 insertions(+), 12 deletions(-)
arch/powerpc/include/asm/book3s/32/pgtable.h +0 -2
@@ -201,8 +201,6 @@ int map_kernel_page(unsigned long va, phys_addr_t pa, pgprot_t prot);#include <linux/sched.h> #include <linux/threads.h> -extern unsigned long ioremap_bot; -/* Bits to mask out from a PGD to get to the PUD page */ #define PGD_MASKED_BITS 0
arch/powerpc/include/asm/book3s/64/pgtable.h +0 -1
@@ -289,7 +289,6 @@ extern unsigned long __kernel_io_end;#define KERN_IO_END __kernel_io_endextern struct page *vmemmap; -extern unsigned long ioremap_bot;extern unsigned long pci_io_base;#endif /* __ASSEMBLY__ */
arch/powerpc/include/asm/nohash/32/pgtable.h +0 -2
@@ -11,8 +11,6 @@#include <asm/mmu.h> /* For sub-arch specific PPC_PIN_SIZE */ #include <asm/asm-405.h> -extern unsigned long ioremap_bot; -#ifdef CONFIG_44xextern int icache_44x_need_flush;#endif
arch/powerpc/include/asm/pgtable.h +2 -0
@@ -68,6 +68,8 @@ extern pgd_t swapper_pg_dir[];extern void paging_init (void ); +extern unsigned long ioremap_bot; +/* * kern_addr_valid is intended to indicate whether an address is a valid * kernel address. Most 32-bit archs define it as always true (like this)
arch/powerpc/mm/ioremap.c +3 -0
@@ -3,6 +3,9 @@#include <linux/io.h> #include <asm/io-workarounds.h> +unsigned long ioremap_bot; +EXPORT_SYMBOL (ioremap_bot); +void __iomem *ioremap (phys_addr_t addr,unsigned long size) {pgprot_t prot =pgprot_noncached (PAGE_KERNEL );
arch/powerpc/mm/mmu_decl.h +0 -1
@@ -108,7 +108,6 @@ extern u8 early_hash[];#endif /* CONFIG_PPC32 */ -extern unsigned long ioremap_bot;extern unsigned long __max_low_memory;extern phys_addr_t __initial_memory_limit_addr;extern phys_addr_t total_memory;
arch/powerpc/mm/nohash/tlb.c +2 -0
@@ -703,6 +703,8 @@ static void __init early_init_mmu_global(void)* for use by the TLB miss code */ linear_map_top =memblock_end_of_DRAM (); + + ioremap_bot =IOREMAP_BASE ; }static void __init early_mmu_set_memory_limit (void )
arch/powerpc/mm/pgtable_32.c +0 -3
@@ -33,9 +33,6 @@#include <mm/mmu_decl.h> -unsigned long ioremap_bot; -EXPORT_SYMBOL (ioremap_bot);/* aka VMALLOC_END */ -extern char etext[], _stext[], _sinittext[], _einittext[]; void __iomem *
arch/powerpc/mm/pgtable_64.c +0 -3
@@ -98,9 +98,6 @@ unsigned long __pte_frag_nr;EXPORT_SYMBOL (__pte_frag_nr);unsigned long __pte_frag_size_shift;EXPORT_SYMBOL (__pte_frag_size_shift); -unsigned long ioremap_bot; -#else /* !CONFIG_PPC_BOOK3S_64 */ -unsigned long ioremap_bot =IOREMAP_BASE ;#endif int __weak ioremap_range (unsigned long ea,phys_addr_t pa,unsigned long size,pgprot_t prot,int nid)
Signature · 1 line
2.13.3
PATCH v2 9/12 powerpc/mm: Move ioremap functions out of pgtable_32/64.c
In reply to Christophe LeroyCreate ioremap_32.c and ioremap_64.c and move respective ioremap functions out of pgtable_32.c and pgtable_64.c
In the meantime, fix a few comments and changes a printk() to pr_warn(). Also fix a few oversplitted lines.
--- arch/powerpc/mm/Makefile | 2 +- arch/powerpc/mm/ioremap_32.c | 104 +++++++++++++++++++++++++++++++++++ arch/powerpc/mm/ioremap_64.c | 123 +++++++++++++++++++++++++++++++++++++++++ arch/powerpc/mm/pgtable_32.c | 99 --------------------------------- arch/powerpc/mm/pgtable_64.c | 128 +------------------------------------------ 5 files changed, 229 insertions(+), 227 deletions(-) create mode 100644 arch/powerpc/mm/ioremap_32.c create mode 100644 arch/powerpc/mm/ioremap_64.c
arch/powerpc/mm/Makefile +1 -1
@@ -7,7 +7,7 @@ ccflags-$(CONFIG_PPC64) := $(NO_MINIMAL_TOC) obj-y := fault.o mem.o pgtable.o mmap.o \ init_$(BITS).o pgtable_$(BITS).o \ - pgtable-frag.o ioremap.o \ + pgtable-frag.o ioremap.o ioremap_$(BITS).o \ init-common.o mmu_context.o drmem.o obj-$(CONFIG_PPC_MMU_NOHASH) += nohash/ obj-$(CONFIG_PPC_BOOK3S_32) += book3s32/
arch/powerpc/mm/ioremap_32.c new file +104 -0
104 lines not on this page · raw message
arch/powerpc/mm/ioremap_64.c new file +123 -0
123 lines not on this page · raw message
arch/powerpc/mm/pgtable_32.c +0 -99
111 lines not on this page · raw message
arch/powerpc/mm/pgtable_64.c +1 -127
145 lines not on this page · raw message
Signature · 1 line
2.13.3
PATCH v2 10/12 powerpc/mm: refactor ioremap_range() and use ioremap_page_range()
In reply to Christophe Leroybook3s64's ioremap_range() is almost same as fallback ioremap_range(), except that it calls radix__ioremap_range() when radix is enabled.
radix__ioremap_range() is also very similar to the other ones, expect that it calls ioremap_page_range when slab is available.
PPC32 __ioremap_caller() have a loop doing the same thing as ioremap_range() so use it on PPC32 as well.
Lets keep only one version of ioremap_range() which calls ioremap_page_range() on all platforms when slab is available.
At the same time, drop the nid parameter which is not used.
--- arch/powerpc/include/asm/book3s/64/radix.h | 3 --- arch/powerpc/include/asm/io.h | 2 ++ arch/powerpc/mm/book3s64/pgtable.c | 21 --------------------- arch/powerpc/mm/book3s64/radix_pgtable.c | 20 -------------------- arch/powerpc/mm/ioremap.c | 24 ++++++++++++++++++++++++ arch/powerpc/mm/ioremap_32.c | 6 ++---- arch/powerpc/mm/ioremap_64.c | 21 +-------------------- 7 files changed, 29 insertions(+), 68 deletions(-)
arch/powerpc/include/asm/book3s/64/radix.h +0 -3
@@ -266,9 +266,6 @@ extern void radix__vmemmap_remove_mapping(unsigned long start,extern int radix__map_kernel_page (unsigned long ea,unsigned long pa,pgprot_t flags,unsigned int psz); -extern int radix__ioremap_range (unsigned long ea,phys_addr_t pa, -unsigned long size,pgprot_t prot,int nid); -static inline unsigned long radix__get_tree_size (void ) {unsigned long rts_field;
arch/powerpc/include/asm/io.h +2 -0
@@ -722,6 +722,8 @@ void __iomem *ioremap_coherent(phys_addr_t address, unsigned long size);extern void iounmap (volatile void __iomem *addr); +int ioremap_range (unsigned long ea,phys_addr_t pa,unsigned long size,pgprot_t prot); +extern void __iomem *__ioremap_caller (phys_addr_t ,unsigned long size,pgprot_t prot,void *caller);
arch/powerpc/mm/book3s64/pgtable.c +0 -21
@@ -446,24 +446,3 @@ int pmd_move_must_withdraw(struct spinlock *new_pmd_ptl,return true; } - -int ioremap_range (unsigned long ea,phys_addr_t pa,unsigned long size,pgprot_t prot,int nid) -{ -unsigned long i; - -if (radix_enabled ()) -return radix__ioremap_range (ea, pa, size, prot, nid); - -for (i =0 ; i < size; i +=PAGE_SIZE ) { -int err =map_kernel_page (ea + i, pa + i, prot); -if (err) { -if (slab_is_available ()) -unmap_kernel_range (ea, size); -else -WARN_ON_ONCE (1 );/* Should clean up */ -return err; - } - } - -return 0 ; -}
arch/powerpc/mm/book3s64/radix_pgtable.c +0 -20
@@ -1218,26 +1218,6 @@ int pmd_free_pte_page(pmd_t *pmd, unsigned long addr)return 1 ; } -int radix__ioremap_range (unsigned long ea,phys_addr_t pa,unsigned long size, -pgprot_t prot,int nid) -{ -if (likely (slab_is_available ())) { -int err =ioremap_page_range (ea, ea + size, pa, prot); -if (err) -unmap_kernel_range (ea, size); -return err; - }else { -unsigned long i; - -for (i =0 ; i < size; i +=PAGE_SIZE ) { -int err =map_kernel_page (ea + i, pa + i, prot); -if (WARN_ON_ONCE (err))/* Should clean up */ -return err; - } -return 0 ; - } -} -int __init arch_ioremap_p4d_supported (void ) {return 0 ;
arch/powerpc/mm/ioremap.c +24 -0
@@ -1,6 +1,8 @@// SPDX-License-Identifier: GPL-2.0-or-later #include <linux/io.h> +#include <linux/slab.h> +#include <linux/vmalloc.h> #include <asm/io-workarounds.h> unsigned long ioremap_bot;
@@ -56,3 +58,25 @@ void __iomem *ioremap_prot(phys_addr_t addr, unsigned long size, unsigned long freturn __ioremap_caller (addr, size,pte_pgprot (pte), caller); }EXPORT_SYMBOL (ioremap_prot); + +int ioremap_range (unsigned long ea,phys_addr_t pa,unsigned long size,pgprot_t prot) +{ +unsigned long i; + +if (slab_is_available ()) { +int err =ioremap_page_range (ea, ea + size, pa, prot); + +if (err) +unmap_kernel_range (ea, size); +return err; + } + +for (i =0 ; i < size; i +=PAGE_SIZE ) { +int err =map_kernel_page (ea + i, pa + i, prot); + +if (WARN_ON_ONCE (err))/* Should clean up */ +return err; + } + +return 0 ; +}
arch/powerpc/mm/ioremap_32.c +2 -4
@@ -17,7 +17,7 @@ EXPORT_SYMBOL(ioremap_wt);void __iomem *__ioremap_caller (phys_addr_t addr,unsigned long size,pgprot_t prot,void *caller) { -unsigned long v, i; +unsigned long v;phys_addr_t p;int err;
@@ -76,9 +76,7 @@ __ioremap_caller(phys_addr_t addr, unsigned long size, pgprot_t prot, void *call* Should check if it is a candidate for a BAT mapping */ - err =0 ; -for (i =0 ; i < size && err ==0 ; i +=PAGE_SIZE ) - err =map_kernel_page (v + i, p + i, prot); + err =ioremap_range ((unsigned long )v, p, size, prot);if (err) {if (slab_is_available ())vunmap ((void *)v);
arch/powerpc/mm/ioremap_64.c +1 -20
@@ -4,25 +4,6 @@#include <linux/slab.h> #include <linux/vmalloc.h> -int __weak ioremap_range (unsigned long ea,phys_addr_t pa,unsigned long size, -pgprot_t prot,int nid) -{ -unsigned long i; - -for (i =0 ; i < size; i +=PAGE_SIZE ) { -int err =map_kernel_page (ea + i, pa + i, prot); -if (err) { -if (slab_is_available ()) -unmap_kernel_range (ea, size); -else -WARN_ON_ONCE (1 );/* Should clean up */ -return err; - } - } - -return 0 ; -} -/** * Low level function to establish the page tables for an IO mapping */
@@ -41,7 +22,7 @@ void __iomem *__ioremap_at(phys_addr_t pa, void *ea, unsigned long size, pgprot_WARN_ON (((unsigned long )ea) & ~PAGE_MASK );WARN_ON (size & ~PAGE_MASK ); -if (ioremap_range ((unsigned long )ea, pa, size, prot,NUMA_NO_NODE )) +if (ioremap_range ((unsigned long )ea, pa, size, prot))return NULL ;return (void __iomem *)ea;
Signature · 1 line
2.13.3
PATCH v2 11/12 powerpc/mm: refactor ioremap vm area setup.
In reply to Christophe LeroyPPC32 and PPC64 are doing the same once SLAB is available. Create a do_ioremap() function that calls get_vm_area and do the mapping.
For PPC64, we add the 4K PFN hack sanity check to __ioremap_caller() in order to avoid using __ioremap_at(). Other checks in __ioremap_at() are irrelevant for __ioremap_caller().
On PPC64, VM area is allocated in the range [ioremap_bot ; IOREMAP_END] On PPC32, VM area is allocated in the range [VMALLOC_START ; VMALLOC_END]
Lets define IOREMAP_START is ioremap_bot for PPC64, and alias IOREMAP_START/END to VMALLOC_START/END on PPC32
--- arch/powerpc/include/asm/book3s/32/pgtable.h | 4 ++++ arch/powerpc/include/asm/book3s/64/pgtable.h | 1 + arch/powerpc/include/asm/io.h | 2 ++ arch/powerpc/include/asm/nohash/32/pgtable.h | 4 ++++ arch/powerpc/include/asm/nohash/64/pgtable.h | 1 + arch/powerpc/mm/ioremap.c | 20 ++++++++++++++++++++ arch/powerpc/mm/ioremap_32.c | 15 ++++----------- arch/powerpc/mm/ioremap_64.c | 17 +++++++---------- 8 files changed, 43 insertions(+), 21 deletions(-)
arch/powerpc/include/asm/book3s/32/pgtable.h +4 -0
@@ -165,6 +165,10 @@ int map_kernel_page(unsigned long va, phys_addr_t pa, pgprot_t prot);#define IOREMAP_TOP KVIRT_TOP#endif +/* PPC32 shares vmalloc area with ioremap */ +#define IOREMAP_START VMALLOC_START +#define IOREMAP_END VMALLOC_END +/* * Just any arbitrary offset to the start of the vmalloc VM area: the * current 16MB value just means that there will be a 64MB "hole" after the
arch/powerpc/include/asm/book3s/64/pgtable.h +1 -0
@@ -316,6 +316,7 @@ extern unsigned long pci_io_base;#define PHB_IO_BASE (ISA_IO_END)#define PHB_IO_END (KERN_IO_START + FULL_IO_SIZE)#define IOREMAP_BASE (PHB_IO_END) +#define IOREMAP_START (ioremap_bot)#define IOREMAP_END (KERN_IO_END)/* Advertise special mapping type for AGP */
arch/powerpc/include/asm/io.h +2 -0
@@ -723,6 +723,8 @@ void __iomem *ioremap_coherent(phys_addr_t address, unsigned long size);extern void iounmap (volatile void __iomem *addr);int ioremap_range (unsigned long ea,phys_addr_t pa,unsigned long size,pgprot_t prot); +void __iomem *do_ioremap (phys_addr_t pa,phys_addr_t offset,unsigned long size, +pgprot_t prot,void *caller);extern void __iomem *__ioremap_caller (phys_addr_t ,unsigned long size,pgprot_t prot,void *caller);
arch/powerpc/include/asm/nohash/32/pgtable.h +4 -0
@@ -93,6 +93,10 @@ int map_kernel_page(unsigned long va, phys_addr_t pa, pgprot_t prot);#define IOREMAP_TOP KVIRT_TOP#endif +/* PPC32 shares vmalloc area with ioremap */ +#define IOREMAP_START VMALLOC_START +#define IOREMAP_END VMALLOC_END +/* * Just any arbitrary offset to the start of the vmalloc VM area: the * current 16MB value just means that there will be a 64MB "hole" after the
arch/powerpc/include/asm/nohash/64/pgtable.h +1 -0
@@ -53,6 +53,7 @@#define PHB_IO_BASE (ISA_IO_END)#define PHB_IO_END (KERN_IO_START + FULL_IO_SIZE)#define IOREMAP_BASE (PHB_IO_END) +#define IOREMAP_START (ioremap_bot)#define IOREMAP_END (KERN_VIRT_START + KERN_VIRT_SIZE)
arch/powerpc/mm/ioremap.c +20 -0
@@ -80,3 +80,23 @@ int ioremap_range(unsigned long ea, phys_addr_t pa, unsigned long size, pgprot_treturn 0 ; } + +void __iomem *do_ioremap (phys_addr_t pa,phys_addr_t offset,unsigned long size, +pgprot_t prot,void *caller) +{ +struct vm_struct *area; +int ret; + + area =__get_vm_area_caller (size,VM_IOREMAP ,IOREMAP_START ,IOREMAP_END , caller); +if (area ==NULL ) +return NULL ; + + area->phys_addr = pa; + ret =ioremap_range ((unsigned long )area->addr, pa, size, prot); +if (!ret) +return (void __iomem *)area->addr + offset; + +free_vm_area (area); + +return NULL ; +}
arch/powerpc/mm/ioremap_32.c +4 -11
@@ -18,7 +18,7 @@ void __iomem * __ioremap_caller(phys_addr_t addr, unsigned long size, pgprot_t prot, void *caller) { unsigned long v; -phys_addr_t p; +phys_addr_t p, offset;int err;/*
@@ -28,6 +28,7 @@ __ioremap_caller(phys_addr_t addr, unsigned long size, pgprot_t prot, void *call* (ioremap_bot records where we're up to). */ p = addr &PAGE_MASK ; + offset = addr & ~PAGE_MASK ; size =PAGE_ALIGN (addr + size) - p;/*
@@ -62,12 +63,7 @@ __ioremap_caller(phys_addr_t addr, unsigned long size, pgprot_t prot, void *call goto out;if (slab_is_available ()) { -struct vm_struct *area; - area =get_vm_area_caller (size,VM_IOREMAP , caller); -if (area ==0 ) -return NULL ; - area->phys_addr = p; - v = (unsigned long )area->addr; +return do_ioremap (p, offset, size, prot, caller); }else { v = (ioremap_bot -= size); }
@@ -77,11 +73,8 @@ __ioremap_caller(phys_addr_t addr, unsigned long size, pgprot_t prot, void *call*/ err =ioremap_range ((unsigned long )v, p, size, prot); -if (err) { -if (slab_is_available ()) -vunmap ((void *)v); +if (err)return NULL ; - } out:return (void __iomem *)(v + ((unsigned long )addr & ~PAGE_MASK ));
arch/powerpc/mm/ioremap_64.c +7 -10
@@ -46,9 +46,13 @@ EXPORT_SYMBOL(__iounmap_at);void __iomem *__ioremap_caller (phys_addr_t addr,unsigned long size,pgprot_t prot,void *caller) { -phys_addr_t paligned; +phys_addr_t paligned, offset;void __iomem *ret; +/* We don't support the 4K PFN hack with ioremap */ +if (pgprot_val (prot) &H_PAGE_4K_PFN ) +return NULL ; +/* * Choose an address to map it to. Once the vmalloc system is running, * we use it. Before that, we map using addresses going up from
@@ -56,21 +60,14 @@ void __iomem *__ioremap_caller(phys_addr_t addr, unsigned long size,* through ioremap_bot. */ paligned = addr &PAGE_MASK ; + offset = addr & ~PAGE_MASK ; size =PAGE_ALIGN (addr + size) - paligned;if (size ==0 || paligned ==0 )return NULL ;if (slab_is_available ()) { -struct vm_struct *area; - - area =__get_vm_area_caller (size,VM_IOREMAP , ioremap_bot, -IOREMAP_END , caller); -if (area ==NULL ) -return NULL ; - - area->phys_addr = paligned; - ret =__ioremap_at (paligned, area->addr, size, prot); +return do_ioremap (paligned, offset, size, prot, caller); }else { ret =__ioremap_at (paligned, (void *)ioremap_bot, size, prot);if (ret)
Signature · 1 line
2.13.3
PATCH v2 12/12 powerpc/mm: split out early ioremap path.
In reply to Christophe Leroyioremap does things differently depending on whether SLAB is available or not at different levels.
Try to separate the early path from the beginning.
--- arch/powerpc/include/asm/io.h | 3 ++- arch/powerpc/mm/ioremap.c | 17 +++++++---------- arch/powerpc/mm/ioremap_32.c | 13 +++++-------- arch/powerpc/mm/ioremap_64.c | 30 +++++++++++++++++++++--------- 4 files changed, 35 insertions(+), 28 deletions(-)
arch/powerpc/include/asm/io.h +2 -1
@@ -722,7 +722,8 @@ void __iomem *ioremap_coherent(phys_addr_t address, unsigned long size);extern void iounmap (volatile void __iomem *addr); -int ioremap_range (unsigned long ea,phys_addr_t pa,unsigned long size,pgprot_t prot); +int early_ioremap_range (unsigned long ea,phys_addr_t pa, +unsigned long size,pgprot_t prot);void __iomem *do_ioremap (phys_addr_t pa,phys_addr_t offset,unsigned long size,pgprot_t prot,void *caller);
arch/powerpc/mm/ioremap.c +7 -10
@@ -59,18 +59,11 @@ void __iomem *ioremap_prot(phys_addr_t addr, unsigned long size, unsigned long f }EXPORT_SYMBOL (ioremap_prot); -int ioremap_range (unsigned long ea,phys_addr_t pa,unsigned long size,pgprot_t prot) +int early_ioremap_range (unsigned long ea,phys_addr_t pa, +unsigned long size,pgprot_t prot) {unsigned long i; -if (slab_is_available ()) { -int err =ioremap_page_range (ea, ea + size, pa, prot); - -if (err) -unmap_kernel_range (ea, size); -return err; - } -for (i =0 ; i < size; i +=PAGE_SIZE ) {int err =map_kernel_page (ea + i, pa + i, prot);
@@ -86,16 +79,20 @@ void __iomem *do_ioremap(phys_addr_t pa, phys_addr_t offset, unsigned long size, {struct vm_struct *area;int ret; +unsigned long va; area =__get_vm_area_caller (size,VM_IOREMAP ,IOREMAP_START ,IOREMAP_END , caller);if (area ==NULL )return NULL ; area->phys_addr = pa; - ret =ioremap_range ((unsigned long )area->addr, pa, size, prot); + va = (unsigned long )area->addr; + + ret =ioremap_page_range (va, va + size, pa, prot);if (!ret)return (void __iomem *)area->addr + offset; +unmap_kernel_range (va, size);free_vm_area (area);return NULL ;
arch/powerpc/mm/ioremap_32.c +5 -8
@@ -60,24 +60,21 @@ __ioremap_caller(phys_addr_t addr, unsigned long size, pgprot_t prot, void *call*/ v =p_block_mapped (p);if (v) - goto out; +return (void __iomem *)v + offset; -if (slab_is_available ()) { +if (slab_is_available ())return do_ioremap (p, offset, size, prot, caller); - }else { - v = (ioremap_bot -= size); - }/* * Should check if it is a candidate for a BAT mapping */ - err =ioremap_range ((unsigned long )v, p, size, prot); + err =early_ioremap_range (ioremap_bot - size, p, size, prot);if (err)return NULL ; + ioremap_bot -= size; -out: -return (void __iomem *)(v + ((unsigned long )addr & ~PAGE_MASK )); +return (void __iomem *)ioremap_bot + offset; }void iounmap (volatile void __iomem *addr)
arch/powerpc/mm/ioremap_64.c +21 -9
@@ -9,6 +9,9 @@*/ void __iomem *__ioremap_at (phys_addr_t pa,void *ea,unsigned long size,pgprot_t prot) { +int ret; +unsigned long va = (unsigned long )ea; +/* We don't support the 4K PFN hack with ioremap */ if (pgprot_val (prot) &H_PAGE_4K_PFN )return NULL ;
@@ -22,7 +25,15 @@ void __iomem *__ioremap_at(phys_addr_t pa, void *ea, unsigned long size, pgprot_WARN_ON (((unsigned long )ea) & ~PAGE_MASK );WARN_ON (size & ~PAGE_MASK ); -if (ioremap_range ((unsigned long )ea, pa, size, prot)) +if (slab_is_available ()) { + ret =ioremap_page_range (va, va + size, pa, prot); +if (ret) +unmap_kernel_range (va, size); + }else { + ret =early_ioremap_range (va, pa, size, prot); + } + +if (ret)return NULL ;return (void __iomem *)ea;
@@ -48,6 +59,7 @@ void __iomem *__ioremap_caller(phys_addr_t addr, unsigned long size, {phys_addr_t paligned, offset;void __iomem *ret; +int err;/* We don't support the 4K PFN hack with ioremap */ if (pgprot_val (prot) &H_PAGE_4K_PFN )
@@ -66,16 +78,16 @@ void __iomem *__ioremap_caller(phys_addr_t addr, unsigned long size,if (size ==0 || paligned ==0 )return NULL ; -if (slab_is_available ()) { +if (slab_is_available ())return do_ioremap (paligned, offset, size, prot, caller); - }else { - ret =__ioremap_at (paligned, (void *)ioremap_bot, size, prot); -if (ret) - ioremap_bot += size; - } -if (ret) - ret += addr & ~PAGE_MASK ; + err =early_ioremap_range (ioremap_bot, paligned, size, prot); +if (err) +return NULL ; + + ret = (void __iomem *)ioremap_bot + offset; + ioremap_bot += size; +return ret; }
Signature · 1 line
2.13.3