# \[PATCH v3 00/24\] replace ioremap\_{cache\|wt} with memremap

- Subsystems: FRAMEBUFFER LAYER, 8250/16?50 (AND CLONE UARTS) SERIAL DRIVER, ACPI, ACPI APEI, ACPI COMPONENT ARCHITECTURE (ACPICA), ARM PORT, ARM/RISC-V/RENESAS ARCHITECTURE, ARM64 PORT (AARCH64 ARCHITECTURE), CHAR and MISC DRIVERS, DOCUMENTATION, DRM DRIVERS, DRM DRIVERS AND MISC GPU PATCHES, DRM DRIVERS FOR GMA500 (Poulsbo, Moorestown and derivative chipsets), EPSON S1D13XXX FRAMEBUFFER DRIVER, EXTENSIBLE FIRMWARE INTERFACE (EFI), GENERIC INCLUDE/ASM HEADER FILES, INTEL DRM I915 DRIVER (Meteor Lake, DG2 and older excluding Poulsbo, Moorestown and derivative), IOMMU SUBSYSTEM, LIBNVDIMM: NON-VOLATILE MEMORY DEVICE SUBSYSTEM, LIBRARY CODE, LINUX FOR POWERPC (32-BIT AND 64-BIT), M68K ARCHITECTURE, MEMORY MANAGEMENT - CORE, MEMORY TECHNOLOGY DEVICES (MTD), MICROBLAZE ARCHITECTURE, NAND FLASH SUBSYSTEM, NIOS2 ARCHITECTURE, PARISC ARCHITECTURE, PCI SUBSYSTEM, PNP SUPPORT, PSTORE FILESYSTEM, S390 ARCHITECTURE, SCSI SUBSYSTEM, SPARC + UltraSPARC (sparc/sparc64), STAGING SUBSYSTEM, SUPERH, SYNOPSYS ARC ARCHITECTURE, TENSILICA XTENSA PORT (xtensa), THE REST, TOSHIBA SMM DRIVER, TTY LAYER AND SERIAL DRIVERS, UCLINUX (M68KNOMMU AND COLDFIRE), X86 ARCHITECTURE (32-BIT AND 64-BIT), X86 MM, XEN HYPERVISOR ARM
- Maintainers: Helge Deller, Greg Kroah-Hartman, "Rafael J. Wysocki", Maciej Wieczor-Retman, Pawel Chmielewski, Russell King, Geert Uytterhoeven, Magnus Damm, Catalin Marinas, Will Deacon, Arnd Bergmann, Jonathan Corbet, David Airlie, Simona Vetter, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Patrik Jakobsson, Kristoffer Ericson, Ard Biesheuvel, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, Joerg Roedel, Dan Williams, Vishal Verma, Dave Jiang, Alison Schofield, Andrew Morton, Madhavan Srinivasan, Geert Uytterhoeven, David Hildenbrand, Miquel Raynal, Richard Weinberger, Vignesh Raghavendra, Michal Simek, Dinh Nguyen, Simon Schuster, "James E.J. Bottomley", Bjorn Helgaas, Kees Cook, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, "Martin K. Petersen", "David S. Miller", Andreas Larsson, Yoshinori Sato, Rich Felker, John Paul Adrian Glaubitz, Vineet Gupta, Chris Zankel, Max Filippov, Linus Torvalds, Jonathan Buzzard, Jiri Slaby, Greg Ungerer, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, Andy Lutomirski, Peter Zijlstra, Stefano Stabellini
- Series: 24 patches touching 110 files, +582/-526
- Status: PENDING · 4 of 24 reviewed
- Pending, 4 of 24 reviewed.
- Revision v3 (2 revisions archived).
- List: linux-fbdev
- 2 messages, 1 author
- Page: https://ratatoskr.run/linux-fbdev/2015/07/4546928/t

## \[PATCH v3 00/24\] replace ioremap\_{cache\|wt} with memremap

- From: Dan Williams \<hidden\>
- Date: 2015-07-30 16:59:29 
- Message: https://ratatoskr.run/linux-fbdev/2015/07/4546928.md

```text
Changes since v2 [1]:

1/ Move arch_memremap() and arch_memunmap() out of line (Christoph)

2/ Convert region_is_ram() to region_intersects() and define an enum for
   its 3 return values. (Luis)

3/ Fix gma500 and i915 to explicitly use cached mappings and clean up
   the __iomem usage. (Daniel)

4/ Kill unused ioremap aliases (ioremap_cached() and
   ioremap_fullcache()) (Christoph)

5/ Clarify some change logs and documentation (Luis, Christoph, and
   Ross)

6/ Add a unified CONFIG_MMU=n implementation with __weak symbols. (Luis)

---
While developing the pmem driver we noticed that the __iomem annotation
on the return value from ioremap_cache() was being mishandled by several
callers.  We also observed that all of the call sites expected to be
able to treat the return value from ioremap_cache() as normal
(non-__iomem) pointer to memory.

This patchset takes the opportunity to clean up the above confusion as
well as a few issues with the ioremap_{cache|wt} interface, including:

1/ Eliminating the possibility of function prototypes differing between
   architectures by defining a central memremap() prototype that takes
   flags to determine the mapping type.

2/ Returning NULL rather than falling back silently to a different
   mapping-type.  This allows drivers to be stricter about the
   mapping-type fallbacks that are permissible.

[1]: http://marc.info/?l=linux-arch&m3779222217405&w=2

---

Dan Williams (24):
      mm: enhance region_is_ram() to region_intersects()
      arch, drivers: don't include <asm/io.h> directly, use <linux/io.h> instead
      cleanup IORESOURCE_CACHEABLE vs ioremap()
      intel_iommu: fix leaked ioremap mapping
      arch: introduce memremap()
      arm: switch from ioremap_cache to memremap
      x86: switch from ioremap_cache to memremap
      gma500: switch from acpi_os_ioremap to memremap
      i915: switch from acpi_os_ioremap to memremap
      acpi: switch from ioremap_cache to memremap
      toshiba laptop: replace ioremap_cache with ioremap
      memconsole: fix __iomem mishandling, switch to memremap
      visorbus: switch from ioremap_cache to memremap
      intel-iommu: switch from ioremap_cache to memremap
      libnvdimm, pmem: push call to ioremap_cache out of line
      pxa2xx-flash: switch from ioremap_cache to memremap
      sfi: switch from ioremap_cache to memremap
      fbdev: switch from ioremap_wt to memremap
      pmem: switch from ioremap_wt to memremap
      arch: kill ioremap_cached()
      arch: kill ioremap_fullcache()
      arch: remove ioremap_cache, replace with arch_memremap
      arch: remove ioremap_wt, optionally replace with arch_memremap
      pmem: convert to generic memremap


 Documentation/x86/pat.txt                      |    6 +
 arch/arc/include/asm/io.h                      |    1 
 arch/arm/Kconfig                               |    1 
 arch/arm/include/asm/io.h                      |    7 --
 arch/arm/include/asm/xen/page.h                |    4 -
 arch/arm/mach-clps711x/board-cdb89712.c        |    2 
 arch/arm/mach-shmobile/pm-rcar.c               |    2 
 arch/arm/mm/ioremap.c                          |   18 +++-
 arch/arm/mm/mmu.c                              |    2 
 arch/arm/mm/nommu.c                            |   11 ++
 arch/arm64/Kconfig                             |    1 
 arch/arm64/include/asm/acpi.h                  |   11 --
 arch/arm64/include/asm/dmi.h                   |    8 +-
 arch/arm64/include/asm/io.h                    |    2 
 arch/arm64/kernel/efi.c                        |    9 +-
 arch/arm64/kernel/smp_spin_table.c             |   19 ++--
 arch/arm64/mm/ioremap.c                        |   20 ++--
 arch/avr32/include/asm/io.h                    |    1 
 arch/frv/include/asm/io.h                      |   12 ---
 arch/ia64/Kconfig                              |    1 
 arch/ia64/include/asm/io.h                     |    5 -
 arch/ia64/kernel/cyclone.c                     |    2 
 arch/ia64/mm/ioremap.c                         |   16 +++
 arch/m32r/include/asm/io.h                     |    1 
 arch/m68k/Kconfig                              |    1 
 arch/m68k/include/asm/io_mm.h                  |   12 ---
 arch/m68k/include/asm/io_no.h                  |   11 --
 arch/m68k/include/asm/raw_io.h                 |    1 
 arch/m68k/mm/kmap.c                            |   17 +++-
 arch/m68k/mm/sun3kmap.c                        |    6 +
 arch/metag/include/asm/io.h                    |    6 -
 arch/microblaze/include/asm/io.h               |    2 
 arch/mn10300/include/asm/io.h                  |    1 
 arch/nios2/include/asm/io.h                    |    1 
 arch/powerpc/kernel/pci_of_scan.c              |    2 
 arch/s390/include/asm/io.h                     |    1 
 arch/sh/Kconfig                                |    1 
 arch/sh/include/asm/io.h                       |    6 -
 arch/sh/mm/ioremap.c                           |   15 +++
 arch/sparc/include/asm/io_32.h                 |    1 
 arch/sparc/include/asm/io_64.h                 |    1 
 arch/sparc/kernel/pci.c                        |    3 -
 arch/tile/include/asm/io.h                     |    2 
 arch/unicore32/include/asm/io.h                |    4 -
 arch/unicore32/mm/ioremap.c                    |    8 --
 arch/x86/Kconfig                               |    1 
 arch/x86/include/asm/efi.h                     |    3 -
 arch/x86/include/asm/io.h                      |   11 --
 arch/x86/kernel/crash_dump_64.c                |    6 +
 arch/x86/kernel/kdebugfs.c                     |    8 +-
 arch/x86/kernel/ksysfs.c                       |   28 +++---
 arch/x86/mm/ioremap.c                          |   59 +++++++------
 arch/xtensa/include/asm/io.h                   |   11 --
 drivers/acpi/apei/einj.c                       |    9 +-
 drivers/acpi/apei/erst.c                       |    6 +
 drivers/acpi/nvs.c                             |    6 +
 drivers/acpi/osl.c                             |   70 ++++-----------
 drivers/char/toshiba.c                         |    2 
 drivers/firmware/google/memconsole.c           |    7 +-
 drivers/gpu/drm/gma500/opregion.c              |    8 +-
 drivers/gpu/drm/gma500/psb_drv.h               |    2 
 drivers/gpu/drm/gma500/psb_lid.c               |    8 +-
 drivers/gpu/drm/i915/i915_debugfs.c            |    2 
 drivers/gpu/drm/i915/i915_drv.h                |   12 +--
 drivers/gpu/drm/i915/intel_bios.c              |    7 +-
 drivers/gpu/drm/i915/intel_opregion.c          |   87 +++++++++----------
 drivers/gpu/drm/i915/intel_panel.c             |    2 
 drivers/iommu/intel-iommu.c                    |   10 +-
 drivers/iommu/intel_irq_remapping.c            |    4 +
 drivers/isdn/icn/icn.h                         |    2 
 drivers/mtd/devices/slram.c                    |    2 
 drivers/mtd/maps/pxa2xx-flash.c                |    4 -
 drivers/mtd/nand/diskonchip.c                  |    2 
 drivers/mtd/onenand/generic.c                  |    2 
 drivers/nvdimm/Kconfig                         |    2 
 drivers/pci/probe.c                            |    3 -
 drivers/pnp/manager.c                          |    2 
 drivers/scsi/aic94xx/aic94xx_init.c            |    7 --
 drivers/scsi/arcmsr/arcmsr_hba.c               |    5 -
 drivers/scsi/mvsas/mv_init.c                   |   15 +--
 drivers/scsi/sun3x_esp.c                       |    2 
 drivers/sfi/sfi_core.c                         |    4 -
 drivers/staging/comedi/drivers/ii_pci20kc.c    |    1 
 drivers/staging/unisys/visorbus/visorchannel.c |   16 ++-
 drivers/staging/unisys/visorbus/visorchipset.c |   17 ++--
 drivers/tty/serial/8250/8250_core.c            |    2 
 drivers/video/fbdev/Kconfig                    |    2 
 drivers/video/fbdev/amifb.c                    |    5 +
 drivers/video/fbdev/atafb.c                    |    5 +
 drivers/video/fbdev/hpfb.c                     |    6 +
 drivers/video/fbdev/ocfb.c                     |    1 
 drivers/video/fbdev/s1d13xxxfb.c               |    3 -
 drivers/video/fbdev/stifb.c                    |    1 
 include/acpi/acpi_io.h                         |    6 -
 include/asm-generic/io.h                       |    8 --
 include/asm-generic/iomap.h                    |    4 -
 include/linux/io-mapping.h                     |    2 
 include/linux/io.h                             |   11 ++
 include/linux/mm.h                             |    9 ++
 include/linux/mtd/map.h                        |    2 
 include/linux/pmem.h                           |   26 +++---
 include/video/vga.h                            |    2 
 kernel/Makefile                                |    2 
 kernel/memremap.c                              |  110 ++++++++++++++++++++++++
 kernel/resource.c                              |   61 ++++++++-----
 lib/Kconfig                                    |    5 +
 lib/devres.c                                   |   13 +--
 lib/pci_iomap.c                                |    7 --
 tools/testing/nvdimm/Kbuild                    |    4 -
 tools/testing/nvdimm/test/iomap.c              |   34 +++++--
 110 files changed, 553 insertions(+), 497 deletions(-)
 create mode 100644 kernel/memremap.c
```

## \[PATCH v3 18/24\] fbdev: switch from ioremap\_wt to memremap

- From: Dan Williams \<hidden\>
- Date: 2015-07-30 17:01:06 
- Message: https://ratatoskr.run/linux-fbdev/2015/07/4546946.md

```text
In preparation for deprecating ioremap_wt() convert its usage in
drivers/video/fbdev to memremap.

Cc: Jean-Christophe Plagniol-Villard <redacted>
Cc: Tomi Valkeinen <redacted>
Cc: <redacted>
Signed-off-by: Dan Williams <redacted>
---
 drivers/video/fbdev/amifb.c |    5 +++--
 drivers/video/fbdev/atafb.c |    5 +++--
 drivers/video/fbdev/hpfb.c  |    6 +++---
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/amifb.c b/drivers/video/fbdev/amifb.c
index 1d702e13aaff..0cde451046d0 100644
--- a/drivers/video/fbdev/amifb.c
+++ b/drivers/video/fbdev/amifb.c
@@ -52,6 +52,7 @@
 #include <linux/ioport.h>
 #include <linux/platform_device.h>
 #include <linux/uaccess.h>
+#include <linux/io.h>
 
 #include <asm/irq.h>
 #include <asm/amigahw.h>
@@ -3705,8 +3706,8 @@ default_chipset:
 	 * access the videomem with writethrough cache
 	 */
 	info->fix.smem_start = (u_long)ZTWO_PADDR(videomemory);
-	videomemory = (u_long)ioremap_wt(info->fix.smem_start,
-					 info->fix.smem_len);
+	videomemory = (u_long)memremap(info->fix.smem_start, info->fix.smem_len,
+			MEMREMAP_WT);
 	if (!videomemory) {
 		dev_warn(&pdev->dev,
 			 "Unable to map videomem cached writethrough\n");
diff --git a/drivers/video/fbdev/atafb.c b/drivers/video/fbdev/atafb.c
index d6ce613e12ad..5615e8c31ea2 100644
--- a/drivers/video/fbdev/atafb.c
+++ b/drivers/video/fbdev/atafb.c
@@ -55,12 +55,12 @@
 #include <linux/delay.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
+#include <linux/io.h>
 
 #include <asm/setup.h>
 #include <linux/uaccess.h>
 #include <asm/pgtable.h>
 #include <asm/irq.h>
-#include <asm/io.h>
 
 #include <asm/atarihw.h>
 #include <asm/atariints.h>
@@ -3185,7 +3185,8 @@ int __init atafb_init(void)
 		/* Map the video memory (physical address given) to somewhere
 		 * in the kernel address space.
 		 */
-		external_screen_base = ioremap_wt(external_addr, external_len);
+		external_screen_base = memremap(external_addr, external_len,
+				MEMREMAP_WT);
 		if (external_vgaiobase)
 			external_vgaiobase  			  (unsigned long)ioremap(external_vgaiobase, 0x10000);
diff --git a/drivers/video/fbdev/hpfb.c b/drivers/video/fbdev/hpfb.c
index 9476d196f510..d08c320b06fc 100644
--- a/drivers/video/fbdev/hpfb.c
+++ b/drivers/video/fbdev/hpfb.c
@@ -14,8 +14,8 @@
 #include <linux/init.h>
 #include <linux/fb.h>
 #include <linux/dio.h>
+#include <linux/io.h>
 
-#include <asm/io.h>
 #include <asm/uaccess.h>
 
 static struct fb_info fb_info = {
@@ -241,8 +241,8 @@ static int hpfb_init_one(unsigned long phys_base, unsigned long virt_base)
 	fb_info.fix.line_length = fb_width;
 	fb_height = (in_8(fb_regs + HPFB_FBHMSB) << 8) | in_8(fb_regs + HPFB_FBHLSB);
 	fb_info.fix.smem_len = fb_width * fb_height;
-	fb_start = (unsigned long)ioremap_wt(fb_info.fix.smem_start,
-					     fb_info.fix.smem_len);
+	fb_start = (unsigned long) memremap(fb_info.fix.smem_start,
+					     fb_info.fix.smem_len, MEMREMAP_WT);
 	hpfb_defined.xres = (in_8(fb_regs + HPFB_DWMSB) << 8) | in_8(fb_regs + HPFB_DWLSB);
 	hpfb_defined.yres = (in_8(fb_regs + HPFB_DHMSB) << 8) | in_8(fb_regs + HPFB_DHLSB);
 	hpfb_defined.xres_virtual = hpfb_defined.xres;

```
