Skip to contentSkip to conversation

iomem: remove __weak ioremap_cache helper

PATCH Applied Arnd Bergmann 4 participants 6 messages Jul 26, 2023 – Aug 1, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iomem: remove __weak ioremap_cache helper

From: Arnd Bergmann <[email protected]>

No portable code calls into this function any more, and on architectures that don't use or define their own, it causes a warning:

kernel/iomem.c:10:22: warning: no previous prototype for 'ioremap_cache' [-Wmissing-prototypes]
10 | __weak void __iomem *ioremap_cache(resource_size_t offset, unsigned long size)

Fold it into the only caller that uses it on architectures without the #define.

Note that the fallback to ioremap is probably still wrong on those architectures, but this is what it's always done there.

---
 kernel/iomem.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
kernel/iomem.c +4 -8
index 9682471e64717..dc2120776e1c3 100644
@@ -5,18 +5,14 @@
 #include <linux/mm.h>
 #include <linux/ioremap.h>
 
-#ifndef ioremap_cache
-/* temporary while we convert existing ioremap_cache users to memremap */
-__weak void __iomem *ioremap_cache(resource_size_t offset, unsigned long size)
-{
-	return ioremap(offset, size);
-}
-#endif
-
 #ifndef arch_memremap_wb
 static void *arch_memremap_wb(resource_size_t offset, unsigned long size)
 {
+#ifdef ioremap_cache
 	return (__force void *)ioremap_cache(offset, size);
+#else
+	return (__force void *)ioremap(offset, size);
+#endif
 }
 #endif
 
Signature · 1 line
2.39.2
#1 lore raw

Hi Arnd,

Quoted 6 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

No portable code calls into this function any more, and on architectures that don't use or define their own, it causes a warning:

Quoted 8 lines

kernel/iomem.c:10:22: warning: no previous prototype for 'ioremap_cache' [-Wmissing-prototypes]
10 | __weak void __iomem *ioremap_cache(resource_size_t offset, unsigned long size)

Fold it into the only caller that uses it on architectures without the #define.

Note that the fallback to ioremap is probably still wrong on those architectures, but this is what it's always done there.

Do we need to add a definition of ioremap_cache in asm-generic/io.h like ioremap_wc|wt?

#ifndef ioremap_cache
#define ioremap_cahce ioremap
#endif

Unless it's for sure that drivers calling ioremap_cache are only built in on those architecures defining it. Or we just want to see the breakage on those ARCH-es so that they will add their own definition.

Not sure if I missed anything when understanding this.

drivers/acpi/apei/bert.c:       boot_error_region = ioremap_cache(bert_tab->address, region_len);
drivers/acpi/apei/einj.c:       trigger_tab = ioremap_cache(trigger_paddr, sizeof(*trigger_tab));
drivers/acpi/apei/einj.c:       trigger_tab = ioremap_cache(trigger_paddr, table_size);
drivers/acpi/apei/erst.c:       erst_erange.vaddr = ioremap_cache(erst_erange.base,
drivers/firmware/efi/memmap.c: * Setup a mapping of the EFI memory map using ioremap_cache(). This

drivers/firmware/meson/meson_sm.c: return ioremap_cache(sm_phy_base, size);
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c: adev->mman.aper_base_kaddr = ioremap_cache(adev->gmc.aper_base,
drivers/gpu/drm/hyperv/hyperv_drm_drv.c: hv->vram = ioremap_cache(hv->mem->start, hv->fb_size);
drivers/gpu/drm/ttm/ttm_bo_util.c: map->virtual = ioremap_cache(res, size);
drivers/gpu/drm/ttm/ttm_bo_util.c: vaddr_iomem = ioremap_cache(mem->bus.offset,

drivers/hv/hv.c:                /* Mask out vTOM bit. ioremap_cache() maps decrypted */
drivers/hv/hv.c:                        = (void *)ioremap_cache(base, HV_HYP_PAGE_SIZE);
drivers/hv/hv.c:                /* Mask out vTOM bit. ioremap_cache() maps decrypted */
drivers/hv/hv.c:                        = (void *)ioremap_cache(base, HV_HYP_PAGE_SIZE);
drivers/mtd/devices/bcm47xxsflash.c:            b47s->window = ioremap_cache(res->start, resource_size(res));
drivers/mtd/maps/pxa2xx-flash.c:        info->map.cached = ioremap_cache(info->map.phys, info->map.size);
drivers/soc/fsl/qbman/qman_ccsr.c:      void __iomem *tmpp = ioremap_cache(addr, sz);
drivers/video/fbdev/hyperv_fb.c:        fb_virt = ioremap_cache(par->mem->start, screen_fb_size);

include/acpi/acpi_io.h: return ioremap_cache(phys, size);

Quoted 36 lines
---
 kernel/iomem.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
kernel/iomem.c +4 -8
index 9682471e64717..dc2120776e1c3 100644
@@ -5,18 +5,14 @@
 #include <linux/mm.h>
 #include <linux/ioremap.h>
 
-#ifndef ioremap_cache
-/* temporary while we convert existing ioremap_cache users to memremap */
-__weak void __iomem *ioremap_cache(resource_size_t offset, unsigned long size)
-{
-	return ioremap(offset, size);
-}
-#endif
-
 #ifndef arch_memremap_wb
 static void *arch_memremap_wb(resource_size_t offset, unsigned long size)
 {
+#ifdef ioremap_cache
 	return (__force void *)ioremap_cache(offset, size);
+#else
+	return (__force void *)ioremap(offset, size);
+#endif
 }
 #endif
 
Signature · 1 line
2.39.2
#2 lore raw
Quoted 16 lines · Baoquan He
Quoted 6 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

No portable code calls into this function any more, and on architectures that don't use or define their own, it causes a warning:

Quoted 8 lines

kernel/iomem.c:10:22: warning: no previous prototype for 'ioremap_cache' [-Wmissing-prototypes]
10 | __weak void __iomem *ioremap_cache(resource_size_t offset, unsigned long size)

Fold it into the only caller that uses it on architectures without the #define.

Note that the fallback to ioremap is probably still wrong on those architectures, but this is what it's always done there.

Quoted 6 lines

Do we need to add a definition of ioremap_cache in asm-generic/io.h like ioremap_wc|wt?

#ifndef ioremap_cache
#define ioremap_cahce ioremap
#endif

No, we really want to eliminate ioremap_cache() from the API, not make it more visible.

Quoted 3 lines

Unless it's for sure that drivers calling ioremap_cache are only built in on those architecures defining it. Or we just want to see the breakage on those ARCH-es so that they will add their own definition.

Right now, it's only possible to call ioremap_cache() on the couple of architectures that explicitly declare this in their asm/io.h header (arm, arm64, ia64, loongarch, mips, powerpc, sh, x86, and xtensa).

I think we could also go ahead and remove it from sh and xtensa.

Quoted 11 lines

Not sure if I missed anything when understanding this.

drivers/acpi/apei/bert.c: boot_error_region =
ioremap_cache(bert_tab->address, region_len);
drivers/acpi/apei/einj.c: trigger_tab =
ioremap_cache(trigger_paddr, sizeof(*trigger_tab));
drivers/acpi/apei/einj.c: trigger_tab =
ioremap_cache(trigger_paddr, table_size);
drivers/acpi/apei/erst.c: erst_erange.vaddr =
ioremap_cache(erst_erange.base,
include/acpi/acpi_io.h: return ioremap_cache(phys, size);

acpi is used on x86, arm64 ia64, and loongarch

Quoted 2 lines

drivers/firmware/meson/meson_sm.c: return
ioremap_cache(sm_phy_base, size);

arm/arm64 specific

Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c:
adev->mman.aper_base_kaddr = ioremap_cache(adev->gmc.aper_base,
drivers/gpu/drm/hyperv/hyperv_drm_drv.c: hv->vram =
ioremap_cache(hv->mem->start, hv->fb_size);
drivers/gpu/drm/ttm/ttm_bo_util.c: map->virtual =
ioremap_cache(res, size);
drivers/gpu/drm/ttm/ttm_bo_util.c: vaddr_iomem =
ioremap_cache(mem->bus.offset,

All guardeded with an x86 check

Quoted 10 lines

drivers/hv/hv.c: /* Mask out vTOM bit. ioremap_cache()
maps decrypted */
drivers/hv/hv.c: = (void *)ioremap_cache(base,
HV_HYP_PAGE_SIZE);
drivers/hv/hv.c: /* Mask out vTOM bit. ioremap_cache()
maps decrypted */
drivers/hv/hv.c: = (void *)ioremap_cache(base,
HV_HYP_PAGE_SIZE);
drivers/video/fbdev/hyperv_fb.c: fb_virt =
ioremap_cache(par->mem->start, screen_fb_size);

x86 and arm64 specific

Quoted 6 lines

drivers/mtd/devices/bcm47xxsflash.c: b47s->window =
ioremap_cache(res->start, resource_size(res));
drivers/mtd/maps/pxa2xx-flash.c: info->map.cached =
ioremap_cache(info->map.phys, info->map.size);
drivers/soc/fsl/qbman/qman_ccsr.c: void __iomem *tmpp =
ioremap_cache(addr, sz);

arm/arm64 specific.

There is also one more caller in mips that gets used by dmi:

arch/mips/include/asm/dmi.h:#define dmi_early_remap(x, l) ioremap_cache(x, l)
arch/mips/include/asm/dmi.h:#define dmi_remap(x, l) ioremap_cache(x, l)

Arnd

#3 lore raw
Quoted 20 lines · Arnd Bergmann
Quoted 19 lines · Baoquan He
Quoted 6 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

No portable code calls into this function any more, and on architectures that don't use or define their own, it causes a warning:

Quoted 8 lines

kernel/iomem.c:10:22: warning: no previous prototype for 'ioremap_cache' [-Wmissing-prototypes]
10 | __weak void __iomem *ioremap_cache(resource_size_t offset, unsigned long size)

Fold it into the only caller that uses it on architectures without the #define.

Note that the fallback to ioremap is probably still wrong on those architectures, but this is what it's always done there.

Do we need to add a definition of ioremap_cache in asm-generic/io.h like ioremap_wc|wt?

Quoted 6 lines
Quoted 3 lines

#ifndef ioremap_cache
#define ioremap_cahce ioremap
#endif

No, we really want to eliminate ioremap_cache() from the API, not make it more visible.

Got it now, thanks a lot for explanation.

Quoted 10 lines
Quoted 4 lines

Unless it's for sure that drivers calling ioremap_cache are only built in on those architecures defining it. Or we just want to see the breakage on those ARCH-es so that they will add their own definition.

Right now, it's only possible to call ioremap_cache() on the couple of architectures that explicitly declare this in their asm/io.h header (arm, arm64, ia64, loongarch, mips, powerpc, sh, x86, and xtensa).

I think we could also go ahead and remove it from sh and xtensa.

Agree, if no actual need of ioremap_cache() on sh and xtensa.

Quoted 60 lines
Quoted 12 lines

Not sure if I missed anything when understanding this.

drivers/acpi/apei/bert.c: boot_error_region =
ioremap_cache(bert_tab->address, region_len);
drivers/acpi/apei/einj.c: trigger_tab =
ioremap_cache(trigger_paddr, sizeof(*trigger_tab));
drivers/acpi/apei/einj.c: trigger_tab =
ioremap_cache(trigger_paddr, table_size);
drivers/acpi/apei/erst.c: erst_erange.vaddr =
ioremap_cache(erst_erange.base,
include/acpi/acpi_io.h: return ioremap_cache(phys, size);

acpi is used on x86, arm64 ia64, and loongarch

Quoted 2 lines

drivers/firmware/meson/meson_sm.c: return
ioremap_cache(sm_phy_base, size);

arm/arm64 specific

Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c:
adev->mman.aper_base_kaddr = ioremap_cache(adev->gmc.aper_base,
drivers/gpu/drm/hyperv/hyperv_drm_drv.c: hv->vram =
ioremap_cache(hv->mem->start, hv->fb_size);
drivers/gpu/drm/ttm/ttm_bo_util.c: map->virtual =
ioremap_cache(res, size);
drivers/gpu/drm/ttm/ttm_bo_util.c: vaddr_iomem =
ioremap_cache(mem->bus.offset,

All guardeded with an x86 check

Quoted 10 lines

drivers/hv/hv.c: /* Mask out vTOM bit. ioremap_cache()
maps decrypted */
drivers/hv/hv.c: = (void *)ioremap_cache(base,
HV_HYP_PAGE_SIZE);
drivers/hv/hv.c: /* Mask out vTOM bit. ioremap_cache()
maps decrypted */
drivers/hv/hv.c: = (void *)ioremap_cache(base,
HV_HYP_PAGE_SIZE);
drivers/video/fbdev/hyperv_fb.c: fb_virt =
ioremap_cache(par->mem->start, screen_fb_size);

x86 and arm64 specific

Quoted 6 lines

drivers/mtd/devices/bcm47xxsflash.c: b47s->window =
ioremap_cache(res->start, resource_size(res));
drivers/mtd/maps/pxa2xx-flash.c: info->map.cached =
ioremap_cache(info->map.phys, info->map.size);
drivers/soc/fsl/qbman/qman_ccsr.c: void __iomem *tmpp =
ioremap_cache(addr, sz);

arm/arm64 specific.

There is also one more caller in mips that gets used by dmi:

arch/mips/include/asm/dmi.h:#define dmi_early_remap(x, l) ioremap_cache(x, l)
arch/mips/include/asm/dmi.h:#define dmi_remap(x, l) ioremap_cache(x, l)

Arnd

Reviewed-by on v1 1/1
#4 lore raw
In reply to Arnd Bergmann
Quoted 36 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

No portable code calls into this function any more, and on architectures that don't use or define their own, it causes a warning:

kernel/iomem.c:10:22: warning: no previous prototype for 'ioremap_cache' [-Wmissing-prototypes]
10 | __weak void __iomem *ioremap_cache(resource_size_t offset, unsigned long size)

Fold it into the only caller that uses it on architectures without the #define.

Note that the fallback to ioremap is probably still wrong on those architectures, but this is what it's always done there.

---
 kernel/iomem.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
kernel/iomem.c +0 -8
index 9682471e64717..dc2120776e1c3 100644
@@ -5,18 +5,14 @@
 #include <linux/mm.h>
 #include <linux/ioremap.h>
 
-#ifndef ioremap_cache
-/* temporary while we convert existing ioremap_cache users to memremap */
-__weak void __iomem *ioremap_cache(resource_size_t offset, unsigned long size)
-{
-	return ioremap(offset, size);
-}
-#endif
-

kernel/iomem.c line 17

Quoted 10 lines
kernel/iomem.c +4 -0
 #ifndef arch_memremap_wb
 static void *arch_memremap_wb(resource_size_t offset, unsigned long size)
 {
+#ifdef ioremap_cache
 	return (__force void *)ioremap_cache(offset, size);
+#else
+	return (__force void *)ioremap(offset, size);
+#endif
 }
 #endif

This looks good to me, thanks.