MIPS ioremap cleanups v2
Subsystems (5)
Hi Thomas,
below is a bunch of cleanups for the MIPS ioremap code. Compile tested only.
Changes since v1:
- don't remove cpu_has_64bit_gp_regs
- add a new prep patch to stop txx9aclc-ac97 from poking into ioremap internals
PATCH 1/7 ASoC: txx9: don't work around too small resource_size_t
The txx9 sound driver deends on HAS_TXX9_ACLC, which is only set for three tx49xx SOCs, and thus always has a 64-bit phys_addr_t and resource_size_t. Instead of poking into ioremap internals to work around a potentially too small resource_size_t just add a BUILD_BUG_ON to catch such a case.
--- sound/soc/txx9/txx9aclc-ac97.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
sound/soc/txx9/txx9aclc-ac97.c +2 -4
@@ -175,6 +175,8 @@ static int txx9aclc_ac97_dev_probe(struct platform_device *pdev)int err;int irq; +BUILD_BUG_ON (sizeof (drvdata->physbase) >sizeof (r->start)); + irq =platform_get_irq (pdev,0 );if (irq <0 )return irq;
@@ -190,10 +192,6 @@ static int txx9aclc_ac97_dev_probe(struct platform_device *pdev)platform_set_drvdata (pdev, drvdata); drvdata->physbase = r->start; -if (sizeof (drvdata->physbase) >sizeof (r->start) && - r->start >=TXX9_DIRECTMAP_BASE && - r->start <TXX9_DIRECTMAP_BASE +0x400000 ) - drvdata->physbase |=0xf00000000ull ; err =devm_request_irq (&pdev->dev, irq, txx9aclc_ac97_irq,0 ,dev_name (&pdev->dev), drvdata);if (err <0 )
Signature · 1 line
2.25.1
Re: [PATCH 1/7] ASoC: txx9: don't work around too small resource_size_t
Quoted 5 lines · Christoph Hellwig
The txx9 sound driver deends on
HAS_TXX9_ACLC, which is only set for three tx49xx SOCs, and thus always has a 64-bitphys_addr_tandresource_size_t. Instead of poking into ioremap internals to work around a potentially too smallresource_size_tjust add aBUILD_BUG_ONto catch such a case.
or can I just apply this independently of the rest of the series?
Re: [PATCH 1/7] ASoC: txx9: don't work around too small resource_size_t
Quoted 10 lines · Mark Brown
Quoted 5 lines · Christoph Hellwig
The txx9 sound driver deends on
HAS_TXX9_ACLC, which is only set for three tx49xx SOCs, and thus always has a 64-bitphys_addr_tandresource_size_t. Instead of poking into ioremap internals to work around a potentially too smallresource_size_tjust add aBUILD_BUG_ONto catch such a case.Acked-by Mark Brown <[email protected]>or can I just apply this independently of the rest of the series?
No, once ioremap is moved out of line the driver would otherwise fail to compile as it doesn't pull in the defintitions anymore.
PATCH 2/7 MIPS: remove cpu_has_64bit_addresses
In reply to Christoph HellwigThis macro is identical to CONFIG_64BIT, and using a Kconfig variable for the only places that checks them (the ioremap implementation) will simplify later patches in this series.
--- arch/mips/include/asm/cpu-features.h | 6 ------ arch/mips/include/asm/io.h | 4 ++-- arch/mips/include/asm/mach-ath25/cpu-feature-overrides.h | 1 - arch/mips/include/asm/mach-ath79/cpu-feature-overrides.h | 1 - .../include/asm/mach-lantiq/falcon/cpu-feature-overrides.h | 1 - .../include/asm/mach-ralink/mt7620/cpu-feature-overrides.h | 1 - .../include/asm/mach-ralink/mt7621/cpu-feature-overrides.h | 1 - .../include/asm/mach-ralink/rt288x/cpu-feature-overrides.h | 1 - .../include/asm/mach-ralink/rt305x/cpu-feature-overrides.h | 1 - .../include/asm/mach-ralink/rt3883/cpu-feature-overrides.h | 1 - arch/mips/include/asm/mach-rc32434/cpu-feature-overrides.h | 1 - 11 files changed, 2 insertions(+), 17 deletions(-)
arch/mips/include/asm/cpu-features.h +0 -6
@@ -435,9 +435,6 @@# ifndef cpu_has_64bit_gp_regs# define cpu_has_64bit_gp_regs 0# endif -# ifndef cpu_has_64bit_addresses -# define cpu_has_64bit_addresses 0 -# endif # ifndef cpu_vmbits# define cpu_vmbits 31# endif
@@ -456,9 +453,6 @@# ifndef cpu_has_64bit_gp_regs# define cpu_has_64bit_gp_regs 1# endif -# ifndef cpu_has_64bit_addresses -# define cpu_has_64bit_addresses 1 -# endif # ifndef cpu_vmbits# define cpu_vmbits cpu_data[0].vmbits# define __NEED_VMBITS_PROBE
arch/mips/include/asm/io.h +2 -2
@@ -166,7 +166,7 @@ static inline void __iomem * __ioremap_mode(phys_addr_t offset, unsigned long si#define __IS_LOW512 (addr) (!((phys_addr_t)(addr) & (phys_addr_t) ~0x1fffffffULL)) -if (cpu_has_64bit_addresses) { +if (IS_ENABLED (CONFIG_64BIT )) {u64 base =UNCAC_BASE ;/*
@@ -275,7 +275,7 @@ static inline void iounmap(const volatile void __iomem *addr)#define __IS_KSEG1 (addr) (((unsigned long)(addr) & ~0x1fffffffUL) == CKSEG1) -if (cpu_has_64bit_addresses || +if (IS_ENABLED (CONFIG_64BIT ) || (__builtin_constant_p (addr) &&__IS_KSEG1 (addr)))return ;
arch/mips/include/asm/mach-ath25/cpu-feature-overrides.h +0 -1
@@ -56,6 +56,5 @@#define cpu_has_64bits 0#define cpu_has_64bit_zero_reg 0#define cpu_has_64bit_gp_regs 0 -#define cpu_has_64bit_addresses 0#endif /* __ASM_MACH_ATH25_CPU_FEATURE_OVERRIDES_H */
arch/mips/include/asm/mach-ath79/cpu-feature-overrides.h +0 -1
@@ -45,7 +45,6 @@#define cpu_has_64bits 0#define cpu_has_64bit_zero_reg 0#define cpu_has_64bit_gp_regs 0 -#define cpu_has_64bit_addresses 0#define cpu_dcache_line_size () 32#define cpu_icache_line_size () 32
arch/mips/include/asm/mach-lantiq/falcon/cpu-feature-overrides.h +0 -1
@@ -46,7 +46,6 @@#define cpu_has_64bits 0#define cpu_has_64bit_zero_reg 0#define cpu_has_64bit_gp_regs 0 -#define cpu_has_64bit_addresses 0#define cpu_dcache_line_size () 32#define cpu_icache_line_size () 32
arch/mips/include/asm/mach-ralink/mt7620/cpu-feature-overrides.h +0 -1
@@ -45,7 +45,6 @@#define cpu_has_64bits 0#define cpu_has_64bit_zero_reg 0#define cpu_has_64bit_gp_regs 0 -#define cpu_has_64bit_addresses 0#define cpu_dcache_line_size () 32#define cpu_icache_line_size () 32
arch/mips/include/asm/mach-ralink/mt7621/cpu-feature-overrides.h +0 -1
@@ -46,7 +46,6 @@#define cpu_has_64bits 0#define cpu_has_64bit_zero_reg 0#define cpu_has_64bit_gp_regs 0 -#define cpu_has_64bit_addresses 0#define cpu_dcache_line_size () 32#define cpu_icache_line_size () 32
arch/mips/include/asm/mach-ralink/rt288x/cpu-feature-overrides.h +0 -1
@@ -44,7 +44,6 @@#define cpu_has_64bits 0#define cpu_has_64bit_zero_reg 0#define cpu_has_64bit_gp_regs 0 -#define cpu_has_64bit_addresses 0#define cpu_dcache_line_size () 16#define cpu_icache_line_size () 16
arch/mips/include/asm/mach-ralink/rt305x/cpu-feature-overrides.h +0 -1
@@ -44,7 +44,6 @@#define cpu_has_64bits 0#define cpu_has_64bit_zero_reg 0#define cpu_has_64bit_gp_regs 0 -#define cpu_has_64bit_addresses 0#define cpu_dcache_line_size () 32#define cpu_icache_line_size () 32
arch/mips/include/asm/mach-ralink/rt3883/cpu-feature-overrides.h +0 -1
@@ -43,7 +43,6 @@#define cpu_has_64bits 0#define cpu_has_64bit_zero_reg 0#define cpu_has_64bit_gp_regs 0 -#define cpu_has_64bit_addresses 0#define cpu_dcache_line_size () 32#define cpu_icache_line_size () 32
arch/mips/include/asm/mach-rc32434/cpu-feature-overrides.h +0 -1
@@ -54,7 +54,6 @@#define cpu_has_64bits 0#define cpu_has_64bit_zero_reg 0#define cpu_has_64bit_gp_regs 0 -#define cpu_has_64bit_addresses 0#define cpu_has_inclusive_pcaches 0
Signature · 1 line
2.25.1
PATCH 3/7 MIPS: cleanup fixup_bigphys_addr handling
In reply to Christoph Hellwigfixup_bigphys_addr is only provided by the alchemy platform. Remove all the stubs, and ensure we only call it if it is actually implemented.
Also don't bother implementing io_remap_pfn_range if we don't have to, and move the remaining implementation to alchemy platform code.
--- arch/mips/Kconfig | 4 +++ arch/mips/alchemy/common/setup.c | 16 ++++++--- arch/mips/include/asm/mach-au1x00/ioremap.h | 38 -------------------- arch/mips/include/asm/mach-bcm63xx/ioremap.h | 5 --- arch/mips/include/asm/mach-bmips/ioremap.h | 5 --- arch/mips/include/asm/mach-generic/ioremap.h | 9 ----- arch/mips/include/asm/mach-tx39xx/ioremap.h | 9 ----- arch/mips/include/asm/mach-tx49xx/ioremap.h | 9 ----- arch/mips/include/asm/pgtable.h | 23 ++++++------ arch/mips/pci/pci-alchemy.c | 2 +- 10 files changed, 27 insertions(+), 93 deletions(-) delete mode 100644 arch/mips/include/asm/mach-au1x00/ioremap.h
arch/mips/Kconfig +4 -0
@@ -92,6 +92,9 @@ config MIPS select SYSCTL_EXCEPTION_TRACE select VIRT_TO_BUS +config MIPS_FIXUP_BIGPHYS_ADDR + bool + menu "Machine selection" choice
@@ -157,6 +160,7 @@ config MIPS_ALCHEMY select CSRC_R4K select IRQ_MIPS_CPU select DMA_MAYBE_COHERENT # Au1000,1500,1100 aren't, rest is + select MIPS_FIXUP_BIGPHYS_ADDR if PCI select SYS_HAS_CPU_MIPS32_R1 select SYS_SUPPORTS_32BIT_KERNEL select SYS_SUPPORTS_APM_EMULATION
arch/mips/alchemy/common/setup.c +12 -4
@@ -72,9 +72,9 @@ void __init plat_mem_setup(void) iomem_resource.end =IOMEM_RESOURCE_END ; } -#if defined(CONFIG_PHYS_ADDR_T_64BIT ) && defined(CONFIG_PCI ) +#ifdef CONFIG_MIPS_FIXUP_BIGPHYS_ADDR /* This routine should be valid for all Au1x based boards */ -phys_addr_t __fixup_bigphys_addr (phys_addr_t phys_addr,phys_addr_t size) +phys_addr_t fixup_bigphys_addr (phys_addr_t phys_addr,phys_addr_t size) {unsigned long start =ALCHEMY_PCI_MEMWIN_START ;unsigned long end =ALCHEMY_PCI_MEMWIN_END ;
@@ -90,5 +90,13 @@ phys_addr_t __fixup_bigphys_addr(phys_addr_t phys_addr, phys_addr_t size)/* default nop */ return phys_addr; } -EXPORT_SYMBOL (__fixup_bigphys_addr); -#endif + +int io_remap_pfn_range (struct vm_area_struct *vma,unsigned long vaddr, +unsigned long pfn,unsigned long size,pgprot_t prot) +{ +phys_addr_t phys_addr =fixup_bigphys_addr (pfn <<PAGE_SHIFT , size); + +return remap_pfn_range (vma, vaddr, phys_addr >>PAGE_SHIFT , size, prot); +} +EXPORT_SYMBOL (io_remap_pfn_range); +#endif /* CONFIG_MIPS_FIXUP_BIGPHYS_ADDR */
arch/mips/include/asm/mach-au1x00/ioremap.h deleted +0 -38
@@ -1,38 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* -* include/asm-mips/mach-au1x00/ioremap.h -*/ -#ifndef __ASM_MACH_AU1X00_IOREMAP_H -#define __ASM_MACH_AU1X00_IOREMAP_H - -#include <linux/types.h> - -#if defined(CONFIG_PHYS_ADDR_T_64BIT ) && defined(CONFIG_PCI ) -extern phys_addr_t __fixup_bigphys_addr (phys_addr_t ,phys_addr_t ); -#else -static inline phys_addr_t __fixup_bigphys_addr (phys_addr_t phys_addr,phys_addr_t size) -{ -return phys_addr; -} -#endif - -/* -* Allow physical addresses to be fixed up to help 36-bit peripherals. -*/ -static inline phys_addr_t fixup_bigphys_addr (phys_addr_t phys_addr,phys_addr_t size) -{ -return __fixup_bigphys_addr (phys_addr, size); -} - -static inline void __iomem *plat_ioremap (phys_addr_t offset,unsigned long size, -unsigned long flags) -{ -return NULL ; -} - -static inline int plat_iounmap (const volatile void __iomem *addr) -{ -return 0 ; -} - -#endif /* __ASM_MACH_AU1X00_IOREMAP_H */
arch/mips/include/asm/mach-bcm63xx/ioremap.h +0 -5
@@ -4,11 +4,6 @@#include <bcm63xx_cpu.h> -static inline phys_addr_t fixup_bigphys_addr (phys_addr_t phys_addr,phys_addr_t size) -{ -return phys_addr; -} -static inline int is_bcm63xx_internal_registers (phys_addr_t offset) {switch (bcm63xx_get_cpu_id ()) {
arch/mips/include/asm/mach-bmips/ioremap.h +0 -5
@@ -4,11 +4,6 @@#include <linux/types.h> -static inline phys_addr_t fixup_bigphys_addr (phys_addr_t phys_addr,phys_addr_t size) -{ -return phys_addr; -} -static inline int is_bmips_internal_registers (phys_addr_t offset) {if (offset >=0xfff80000 )
arch/mips/include/asm/mach-generic/ioremap.h +0 -9
@@ -7,15 +7,6 @@#include <linux/types.h> -/* -* Allow physical addresses to be fixed up to help peripherals located -* outside the low 32-bit range -- generic pass-through version. -*/ -static inline phys_addr_t fixup_bigphys_addr (phys_addr_t phys_addr,phys_addr_t size) -{ -return phys_addr; -} -static inline void __iomem *plat_ioremap (phys_addr_t offset,unsigned long size,unsigned long flags) {
arch/mips/include/asm/mach-tx39xx/ioremap.h +0 -9
@@ -7,15 +7,6 @@#include <linux/types.h> -/* -* Allow physical addresses to be fixed up to help peripherals located -* outside the low 32-bit range -- generic pass-through version. -*/ -static inline phys_addr_t fixup_bigphys_addr (phys_addr_t phys_addr,phys_addr_t size) -{ -return phys_addr; -} -static inline void __iomem *plat_ioremap (phys_addr_t offset,unsigned long size,unsigned long flags) {
arch/mips/include/asm/mach-tx49xx/ioremap.h +0 -9
@@ -7,15 +7,6 @@#include <linux/types.h> -/* -* Allow physical addresses to be fixed up to help peripherals located -* outside the low 32-bit range -- generic pass-through version. -*/ -static inline phys_addr_t fixup_bigphys_addr (phys_addr_t phys_addr,phys_addr_t size) -{ -return phys_addr; -} -static inline void __iomem *plat_ioremap (phys_addr_t offset,unsigned long size,unsigned long flags) {
arch/mips/include/asm/pgtable.h +10 -13
@@ -507,20 +507,17 @@ static inline void update_mmu_cache_pmd(struct vm_area_struct *vma,#define kern_addr_valid (addr) (1) -#ifdef CONFIG_PHYS_ADDR_T_64BIT -extern int remap_pfn_range (struct vm_area_struct *vma,unsigned long from,unsigned long pfn,unsigned long size,pgprot_t prot); - -static inline int io_remap_pfn_range (struct vm_area_struct *vma, -unsigned long vaddr, -unsigned long pfn, -unsigned long size, -pgprot_t prot) -{ -phys_addr_t phys_addr_high =fixup_bigphys_addr (pfn <<PAGE_SHIFT , size); -return remap_pfn_range (vma, vaddr, phys_addr_high >>PAGE_SHIFT , size, prot); -} +/* +* Allow physical addresses to be fixed up to help 36-bit peripherals. +*/ +#ifdef CONFIG_MIPS_FIXUP_BIGPHYS_ADDR +phys_addr_t fixup_bigphys_addr (phys_addr_t addr,phys_addr_t size); +int io_remap_pfn_range (struct vm_area_struct *vma,unsigned long vaddr, +unsigned long pfn,unsigned long size,pgprot_t prot);#define io_remap_pfn_range io_remap_pfn_range -#endif +#else +#define fixup_bigphys_addr (addr, size) (addr) +#endif /* CONFIG_MIPS_FIXUP_BIGPHYS_ADDR */ #ifdef CONFIG_TRANSPARENT_HUGEPAGE
arch/mips/pci/pci-alchemy.c +1 -1
@@ -52,7 +52,7 @@ struct alchemy_pci_context {static struct alchemy_pci_context *__alchemy_pci_ctx; -/* IO/MEM resources for PCI. Keep the memres in sync with __fixup_bigphys_addr +/* IO/MEM resources for PCI. Keep the memres in sync with fixup_bigphys_addr * in arch/mips/alchemy/common/setup.c */ static struct resource alchemy_pci_def_memres = {
Signature · 1 line
2.25.1
PATCH 4/7 MIPS: merge __ioremap_mode into ioremap_prot
In reply to Christoph HellwigThere is no reason to have two ioremap with flags interfaces. Merge the historic mips __ioremap_mode into ioremap_prot which is a generic kernel interface.
--- arch/mips/include/asm/io.h | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-)
arch/mips/include/asm/io.h +13 -17
@@ -156,9 +156,17 @@ static inline void *isa_bus_to_virt(unsigned long address)extern void __iomem *__ioremap (phys_addr_t offset,phys_addr_t size,unsigned long flags);extern void __iounmap (const volatile void __iomem *addr); -static inline void __iomem *__ioremap_mode (phys_addr_t offset,unsigned long size, -unsigned long flags) +/* +* ioremap_prot - map bus memory into CPU space +* @offset: bus address of the memory +* @size: size of the resource to map + +* ioremap_prot gives the caller control over cache coherency attributes (CCA) +*/ +static inline void __iomem *ioremap_prot (phys_addr_t offset, +unsigned long size,unsigned long prot_val) { +unsigned long flags = prot_val & _CACHE_MASK;void __iomem *addr =plat_ioremap (offset, size, flags);if (addr)
@@ -202,18 +210,6 @@ static inline void __iomem * __ioremap_mode(phys_addr_t offset, unsigned long si#undef __IS_LOW512 } -/* -* ioremap_prot - map bus memory into CPU space -* @offset: bus address of the memory -* @size: size of the resource to map - -* ioremap_prot gives the caller control over cache coherency attributes (CCA) -*/ -static inline void __iomem *ioremap_prot (phys_addr_t offset, -unsigned long size,unsigned long prot_val) { -return __ioremap_mode (offset, size, prot_val & _CACHE_MASK); -} -/* * ioremap - map bus memory into CPU space * @offset: bus address of the memory
@@ -226,7 +222,7 @@ static inline void __iomem *ioremap_prot(phys_addr_t offset,* address. */ #define ioremap (offset, size) \ - __ioremap_mode((offset), (size), _CACHE_UNCACHED) + ioremap_prot((offset), (size), _CACHE_UNCACHED)#define ioremap_uc ioremap/*
@@ -245,7 +241,7 @@ static inline void __iomem *ioremap_prot(phys_addr_t offset,* memory-like regions on I/O busses. */ #define ioremap_cache (offset, size) \ - __ioremap_mode((offset), (size), _page_cachable_default) + ioremap_prot((offset), (size), _page_cachable_default)/* * ioremap_wc - map bus memory into CPU space
@@ -266,7 +262,7 @@ static inline void __iomem *ioremap_prot(phys_addr_t offset,* _CACHE_UNCACHED option (see cpu_probe() method). */ #define ioremap_wc (offset, size) \ - __ioremap_mode((offset), (size), boot_cpu_data.writecombine) + ioremap_prot((offset), (size), boot_cpu_data.writecombine)static inline void iounmap (const volatile void __iomem *addr) {
Signature · 1 line
2.25.1
PATCH 5/7 MIPS: split out the 64-bit ioremap implementation
In reply to Christoph HellwigSplit out the mips64 ioremap implementation entirely, as it will never use page table based remapping.
--- arch/mips/include/asm/io.h | 65 ++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 28 deletions(-)
arch/mips/include/asm/io.h +37 -28
@@ -153,6 +153,25 @@ static inline void *isa_bus_to_virt(unsigned long address)*/ #define page_to_phys (page) ((dma_addr_t)page_to_pfn(page) << PAGE_SHIFT) +#ifdef CONFIG_64BIT +static inline void __iomem *ioremap_prot (phys_addr_t offset, +unsigned long size,unsigned long prot_val) +{ +unsigned long flags = prot_val & _CACHE_MASK; +u64 base = (flags == _CACHE_UNCACHED ?IO_BASE :UNCAC_BASE ); +void __iomem *addr; + + addr =plat_ioremap (offset, size, flags); +if (!addr) + addr = (void __iomem *)(unsigned long )(base + offset); +return addr; +} + +static inline void iounmap (const volatile void __iomem *addr) +{ +plat_iounmap (addr); +} +#else /* CONFIG_64BIT */ extern void __iomem *__ioremap (phys_addr_t offset,phys_addr_t size,unsigned long flags);extern void __iounmap (const volatile void __iomem *addr);
@@ -174,18 +193,8 @@ static inline void __iomem *ioremap_prot(phys_addr_t offset,#define __IS_LOW512 (addr) (!((phys_addr_t)(addr) & (phys_addr_t) ~0x1fffffffULL)) -if (IS_ENABLED (CONFIG_64BIT )) { -u64 base =UNCAC_BASE ; - -/* -* R10000 supports a 2 bit uncached attribute therefore -* UNCAC_BASE may not equal IO_BASE. -*/ -if (flags == _CACHE_UNCACHED) - base = (u64 )IO_BASE ; -return (void __iomem *) (unsigned long ) (base + offset); - }else if (__builtin_constant_p (offset) && -__builtin_constant_p (size) &&__builtin_constant_p (flags)) { +if (__builtin_constant_p (offset) && +__builtin_constant_p (size) &&__builtin_constant_p (flags)) {phys_addr_t phys_addr, last_addr; phys_addr =fixup_bigphys_addr (offset, size);
@@ -210,6 +219,22 @@ static inline void __iomem *ioremap_prot(phys_addr_t offset,#undef __IS_LOW512 } +static inline void iounmap (const volatile void __iomem *addr) +{ +if (plat_iounmap (addr)) +return ; + +#define __IS_KSEG1 (addr) (((unsigned long)(addr) & ~0x1fffffffUL) == CKSEG1) + +if (__builtin_constant_p (addr) &&__IS_KSEG1 (addr)) +return ; + +__iounmap (addr); + +#undef __IS_KSEG1 +} +#endif /* !CONFIG_64BIT */ +/* * ioremap - map bus memory into CPU space * @offset: bus address of the memory
@@ -264,22 +289,6 @@ static inline void __iomem *ioremap_prot(phys_addr_t offset,#define ioremap_wc (offset, size) \ ioremap_prot((offset), (size), boot_cpu_data.writecombine) -static inline void iounmap (const volatile void __iomem *addr) -{ -if (plat_iounmap (addr)) -return ; - -#define __IS_KSEG1 (addr) (((unsigned long)(addr) & ~0x1fffffffUL) == CKSEG1) - -if (IS_ENABLED (CONFIG_64BIT ) || - (__builtin_constant_p (addr) &&__IS_KSEG1 (addr))) -return ; - -__iounmap (addr); - -#undef __IS_KSEG1 -} -#if defined(CONFIG_CPU_CAVIUM_OCTEON ) || defined(CONFIG_CPU_LOONGSON64 )#define war_io_reorder_wmb () wmb()#else
Signature · 1 line
2.25.1
PATCH 6/7 MIPS: move ioremap_prot und iounmap out of line
In reply to Christoph HellwigNeither of these interfaces is anywhere near the fast path. Move them out of line and avoid exposing implementation details to the drivers.
--- arch/mips/include/asm/io.h | 86 ++------------------------------------ arch/mips/mm/Makefile | 2 +- arch/mips/mm/ioremap.c | 45 ++++++++++---------- arch/mips/mm/ioremap64.c | 23 ++++++++++ 4 files changed, 49 insertions(+), 107 deletions(-) create mode 100644 arch/mips/mm/ioremap64.c
arch/mips/include/asm/io.h +3 -83
@@ -30,8 +30,6 @@#include <asm/pgtable-bits.h> #include <asm/processor.h> #include <asm/string.h> - -#include <ioremap.h> #include <mangle-port.h> /*
@@ -153,87 +151,9 @@ static inline void *isa_bus_to_virt(unsigned long address)*/ #define page_to_phys (page) ((dma_addr_t)page_to_pfn(page) << PAGE_SHIFT) -#ifdef CONFIG_64BIT -static inline void __iomem *ioremap_prot (phys_addr_t offset, -unsigned long size,unsigned long prot_val) -{ -unsigned long flags = prot_val & _CACHE_MASK; -u64 base = (flags == _CACHE_UNCACHED ?IO_BASE :UNCAC_BASE ); -void __iomem *addr; - - addr =plat_ioremap (offset, size, flags); -if (!addr) - addr = (void __iomem *)(unsigned long )(base + offset); -return addr; -} - -static inline void iounmap (const volatile void __iomem *addr) -{ -plat_iounmap (addr); -} -#else /* CONFIG_64BIT */ -extern void __iomem *__ioremap (phys_addr_t offset,phys_addr_t size,unsigned long flags); -extern void __iounmap (const volatile void __iomem *addr); - -/* -* ioremap_prot - map bus memory into CPU space -* @offset: bus address of the memory -* @size: size of the resource to map - -* ioremap_prot gives the caller control over cache coherency attributes (CCA) -*/ -static inline void __iomem *ioremap_prot (phys_addr_t offset, -unsigned long size,unsigned long prot_val) -{ -unsigned long flags = prot_val & _CACHE_MASK; -void __iomem *addr =plat_ioremap (offset, size, flags); - -if (addr) -return addr; - -#define __IS_LOW512 (addr) (!((phys_addr_t)(addr) & (phys_addr_t) ~0x1fffffffULL)) - -if (__builtin_constant_p (offset) && -__builtin_constant_p (size) &&__builtin_constant_p (flags)) { -phys_addr_t phys_addr, last_addr; - - phys_addr =fixup_bigphys_addr (offset, size); - -/* Don't allow wraparound or zero size. */ - last_addr = phys_addr + size -1 ; -if (!size || last_addr < phys_addr) -return NULL ; - -/* -* Map uncached objects in the low 512MB of address -* space using KSEG1. -*/ -if (__IS_LOW512 (phys_addr) &&__IS_LOW512 (last_addr) && - flags == _CACHE_UNCACHED) -return (void __iomem *) - (unsigned long )CKSEG1ADDR (phys_addr); - } - -return __ioremap (offset, size, flags); - -#undef __IS_LOW512 -} - -static inline void iounmap (const volatile void __iomem *addr) -{ -if (plat_iounmap (addr)) -return ; - -#define __IS_KSEG1 (addr) (((unsigned long)(addr) & ~0x1fffffffUL) == CKSEG1) - -if (__builtin_constant_p (addr) &&__IS_KSEG1 (addr)) -return ; - -__iounmap (addr); - -#undef __IS_KSEG1 -} -#endif /* !CONFIG_64BIT */ +void __iomem *ioremap_prot (phys_addr_t offset,unsigned long size, +unsigned long prot_val); +void iounmap (const volatile void __iomem *addr);/* * ioremap - map bus memory into CPU space
arch/mips/mm/Makefile +1 -1
@@ -23,7 +23,7 @@ obj-y += uasm-mips.o endif obj-$(CONFIG_32BIT) += ioremap.o pgtable-32.o -obj-$(CONFIG_64BIT) += pgtable-64.o +obj-$(CONFIG_64BIT) += ioremap64.o pgtable-64.o obj-$(CONFIG_HIGHMEM) += highmem.o obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o obj-$(CONFIG_DMA_NONCOHERENT) += dma-noncoherent.o
arch/mips/mm/ioremap.c +22 -23
75 lines not on this page · raw message
arch/mips/mm/ioremap64.c new file +23 -0
@@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include <linux/io.h> +#include <ioremap.h> + +void __iomem *ioremap_prot (phys_addr_t offset,unsigned long size, +unsigned long prot_val) +{ +unsigned long flags = prot_val & _CACHE_MASK; +u64 base = (flags == _CACHE_UNCACHED ?IO_BASE :UNCAC_BASE ); +void __iomem *addr; + + addr =plat_ioremap (offset, size, flags); +if (!addr) + addr = (void __iomem *)(unsigned long )(base + offset); +return addr; +} +EXPORT_SYMBOL (ioremap_prot); + +void iounmap (const volatile void __iomem *addr) +{ +plat_iounmap (addr); +} +EXPORT_SYMBOL (iounmap);
Signature · 1 line
2.25.1
PATCH 7/7 MIPS: use ioremap_page_range
In reply to Christoph HellwigUse the generic ioremap_page_range helper instead of reimplementing it.
--- arch/mips/mm/ioremap.c | 112 ++++------------------------------------- 1 file changed, 11 insertions(+), 101 deletions(-)
arch/mips/mm/ioremap.c +11 -101
@@ -14,99 +14,14 @@#include <linux/slab.h> #include <linux/vmalloc.h> #include <linux/mm_types.h> +#include <linux/io.h> #include <asm/cacheflush.h> -#include <asm/io.h> #include <asm/tlbflush.h> #include <ioremap.h> #define IS_LOW512 (addr) (!((phys_addr_t)(addr) & (phys_addr_t) ~0x1fffffffULL))#define IS_KSEG1 (addr) (((unsigned long)(addr) & ~0x1fffffffUL) == CKSEG1) -static inline void remap_area_pte (pte_t * pte,unsigned long address, -phys_addr_t size,phys_addr_t phys_addr,unsigned long flags) -{ -phys_addr_t end; -unsigned long pfn; -pgprot_t pgprot =__pgprot (_PAGE_GLOBAL | _PAGE_PRESENT | __READABLE - | __WRITEABLE | flags); - - address &= ~PMD_MASK ; - end = address + size; -if (end >PMD_SIZE ) - end =PMD_SIZE ; -BUG_ON (address >= end); - pfn = phys_addr >>PAGE_SHIFT ; -do { -if (!pte_none (*pte)) { -printk ("remap_area_pte: page already exists\n" ); -BUG (); - } -set_pte (pte,pfn_pte (pfn, pgprot)); - address +=PAGE_SIZE ; - pfn++; - pte++; - }while (address && (address < end)); -} - -static inline int remap_area_pmd (pmd_t * pmd,unsigned long address, -phys_addr_t size,phys_addr_t phys_addr,unsigned long flags) -{ -phys_addr_t end; - - address &= ~PGDIR_MASK ; - end = address + size; -if (end >PGDIR_SIZE ) - end =PGDIR_SIZE ; - phys_addr -= address; -BUG_ON (address >= end); -do { -pte_t * pte =pte_alloc_kernel (pmd, address); -if (!pte) -return -ENOMEM ; -remap_area_pte (pte, address, end - address, address + phys_addr, flags); - address = (address +PMD_SIZE ) &PMD_MASK ; - pmd++; - }while (address && (address < end)); -return 0 ; -} - -static int remap_area_pages (unsigned long address,phys_addr_t phys_addr, -phys_addr_t size,unsigned long flags) -{ -int error; -pgd_t * dir; -unsigned long end = address + size; - - phys_addr -= address; - dir =pgd_offset (&init_mm, address); -flush_cache_all (); -BUG_ON (address >= end); -do { -p4d_t *p4d; -pud_t *pud; -pmd_t *pmd; - - error = -ENOMEM ; - p4d =p4d_alloc (&init_mm, dir, address); -if (!p4d) -break ; - pud =pud_alloc (&init_mm, p4d, address); -if (!pud) -break ; - pmd =pmd_alloc (&init_mm, pud, address); -if (!pmd) -break ; -if (remap_area_pmd (pmd, address, end - address, - phys_addr + address, flags)) -break ; - error =0 ; - address = (address +PGDIR_SIZE ) &PGDIR_MASK ; - dir++; - }while (address && (address < end)); -flush_tlb_all (); -return error; -} -static int __ioremap_check_ram (unsigned long start_pfn,unsigned long nr_pages,void *arg) {
@@ -135,7 +50,7 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, unsigned long size,unsigned long offset, pfn, last_pfn;struct vm_struct *area;phys_addr_t last_addr; -void *addr; +unsigned long vaddr;void __iomem *cpu_addr; cpu_addr =plat_ioremap (phys_addr, size, flags);
@@ -183,27 +98,22 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, unsigned long size, area =get_vm_area (size,VM_IOREMAP );if (!area)return NULL ; - addr = area->addr; -if (remap_area_pages ((unsigned long ) addr, phys_addr, size, flags)) { -vunmap (addr); + vaddr = (unsigned long )area->addr; + + flags |= _PAGE_GLOBAL | _PAGE_PRESENT | __READABLE | __WRITEABLE; +if (ioremap_page_range (vaddr, vaddr + size, phys_addr, +__pgprot (flags))) { +free_vm_area (area);return NULL ; } -return (void __iomem *) (offset + (char *)addr); +return (void __iomem *)(vaddr + offset); }EXPORT_SYMBOL (ioremap_prot);void iounmap (const volatile void __iomem *addr) { -struct vm_struct *p; - -if (plat_iounmap (addr) ||IS_KSEG1 (addr)) -return ; - - p =remove_vm_area ((void *) (PAGE_MASK & (unsigned long __force ) addr)); -if (!p) -printk (KERN_ERR "iounmap: bad address %p\n" , addr); - -kfree (p); +if (!plat_iounmap (addr) && !IS_KSEG1 (addr)) +vunmap ((void *)((unsigned long )addr &PAGE_MASK )); }EXPORT_SYMBOL (iounmap);
Signature · 1 line
2.25.1
Thomas Bogendoerfer
maintainerQuoted 9 lines · Christoph Hellwig
Hi Thomas,
below is a bunch of cleanups for the MIPS ioremap code. Compile tested only.
Changes since v1:
- don't removecpu_has_64bit_gp_regs
- add a new prep patch to stop txx9aclc-ac97 from poking into ioremap internals
series applied to mips-next.
Thomas.
Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a good idea. [ RFC1925, 2.3 ]