Skip to contentSkip to conversation

replace ioremap_{cache|wt} with memremap

PATCH Applied Dan Williams 5 participants 38 messages Jul 30, 2015 – Aug 6, 2015

Subsystems (44)

v3 of 5 Applied Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover replace ioremap_{cache|wt} with memremap

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=143779222217405&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

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#1 lore raw

PATCH v3 1/24 mm: enhance region_is_ram() to region_intersects()

region_is_ram() is used to prevent the establishment of aliased mappings to physical "System RAM" with incompatible cache settings. However, it uses "-1" to indicate both "unknown" memory ranges (ranges not described by platform firmware) and "mixed" ranges (where the parameters describe a range that partially overlaps "System RAM").

Fix this up by explicitly tracking the "unknown" vs "mixed" resource cases and returning REGION_INTERSECTS, REGION_MIXED, or REGION_DISJOINT. This re-write also adds support for detecting when the requested region completely eclipses all of a resource. Note, the implementation treats overlaps between "unknown" and the requested memory type as REGION_INTERSECTS.

Finally, other memory types can be passed in by name, for now the only usage "System RAM".

---
 include/linux/mm.h |    9 +++++++-
 kernel/resource.c  |   61 +++++++++++++++++++++++++++++++---------------------
 2 files changed, 44 insertions(+), 26 deletions(-)
include/linux/mm.h +8 -1
index 2e872f92dbac..84b05ebedb2d 100644
@@ -369,7 +369,14 @@ static inline int put_page_unless_one(struct page *page)
 }
 
 extern int page_is_ram(unsigned long pfn);
-extern int region_is_ram(resource_size_t phys_addr, unsigned long size);
+
+enum {
+	REGION_INTERSECTS,
+	REGION_DISJOINT,
+	REGION_MIXED,
+};
+
+int region_intersects(resource_size_t offset, size_t size, const char *type);
 
 /* Support for virtually mapped pages */
 struct page *vmalloc_to_page(const void *addr);
kernel/resource.c +36 -25

76 lines not on this page · raw message

#2 lore raw

Re: [PATCH v3 01/24] mm: enhance region_is_ram() to region_intersects()

Quoted 6 lines · Dan Williams
include/linux/mm.h +0 -0
index 2e872f92dbac..84b05ebedb2d 100644
@@ -369,7 +369,14 @@ static inline int put_page_unless_one(struct page *page)
 }

include/linux/mm.h static inline int put_page_unless_one(struct page *page) · line 378

Quoted 10 lines
include/linux/mm.h +7 -1
 
 extern int page_is_ram(unsigned long pfn);
-extern int region_is_ram(resource_size_t phys_addr, unsigned long size);
+
+enum {
+	REGION_INTERSECTS,
+	REGION_DISJOINT,
+	REGION_MIXED,
+};
+

Can you Kdoc'ify this? Part of the reason for the enum request was this could be then documented really well. The helper is documented but here you can go into more detail about each region intersection.

Luis

#3 lore raw

Re: [PATCH v3 01/24] mm: enhance region_is_ram() to region_intersects()

Quoted 8 lines · Luis R. Rodriguez
Quoted 7 lines · Dan Williams
include/linux/mm.h +0 -0
index 2e872f92dbac..84b05ebedb2d 100644
@@ -369,7 +369,14 @@ static inline int put_page_unless_one(struct page *page)
 }
 
Quoted 13 lines

include/linux/mm.h static inline int put_page_unless_one(struct page *page) · line 378

Quoted 9 lines
include/linux/mm.h +7 -1
 extern int page_is_ram(unsigned long pfn);
-extern int region_is_ram(resource_size_t phys_addr, unsigned long size);
+
+enum {
+     REGION_INTERSECTS,
+     REGION_DISJOINT,
+     REGION_MIXED,
+};
+

Can you Kdoc'ify this? Part of the reason for the enum request was this could be then documented really well. The helper is documented but here you can go into more detail about each region intersection.

Given region_intersects() has its own kdoc I'd probably just say "See region_intersects() for details".

#4 lore raw

Re: [PATCH v3 01/24] mm: enhance region_is_ram() to region_intersects()

Quoted 23 lines · Dan Williams
Quoted 8 lines · Luis R. Rodriguez
Quoted 7 lines · Dan Williams
include/linux/mm.h +0 -0
index 2e872f92dbac..84b05ebedb2d 100644
@@ -369,7 +369,14 @@ static inline int put_page_unless_one(struct page *page)
 }
 
Quoted 13 lines

include/linux/mm.h static inline int put_page_unless_one(struct page *page) · line 378

Quoted 9 lines
include/linux/mm.h +7 -1
 extern int page_is_ram(unsigned long pfn);
-extern int region_is_ram(resource_size_t phys_addr, unsigned long size);
+
+enum {
+     REGION_INTERSECTS,
+     REGION_DISJOINT,
+     REGION_MIXED,
+};
+

Can you Kdoc'ify this? Part of the reason for the enum request was this could be then documented really well. The helper is documented but here you can go into more detail about each region intersection.

Quoted 2 lines

Given region_intersects() has its own kdoc I'd probably just say "See region_intersects() for details".

With the kdoc in place in the enum you'd kick people to elaborate when extending the enums, whereas without this you'd hope they do it. With the enum in place you can also be more verbose.

Luis

#5 lore raw

Re: [PATCH v3 01/24] mm: enhance region_is_ram() to region_intersects()

Quoted 24 lines · Luis R. Rodriguez
Quoted 23 lines · Dan Williams
Quoted 21 lines · Luis R. Rodriguez
Quoted 6 lines · Dan Williams
include/linux/mm.h +0 -0
index 2e872f92dbac..84b05ebedb2d 100644
@@ -369,7 +369,14 @@ static inline int put_page_unless_one(struct page *page)
 }

include/linux/mm.h static inline int put_page_unless_one(struct page *page) · line 378

Quoted 10 lines
include/linux/mm.h +7 -1
 
 extern int page_is_ram(unsigned long pfn);
-extern int region_is_ram(resource_size_t phys_addr, unsigned long size);
+
+enum {
+     REGION_INTERSECTS,
+     REGION_DISJOINT,
+     REGION_MIXED,
+};
+

Can you Kdoc'ify this? Part of the reason for the enum request was this could be then documented really well. The helper is documented but here you can go into more detail about each region intersection.

Quoted 7 lines
Quoted 2 lines

Given region_intersects() has its own kdoc I'd probably just say "See region_intersects() for details".

With the kdoc in place in the enum you'd kick people to elaborate when extending the enums, whereas without this you'd hope they do it. With the enum in place you can also be more verbose.

Care to send a patch on what you are thinking? I wasn't planning on this enum growing any other entries.

#6 lore raw

Re: [PATCH v3 01/24] mm: enhance region_is_ram() to region_intersects()

Quoted 28 lines · Dan Williams
Quoted 27 lines · Luis R. Rodriguez
Quoted 25 lines · Dan Williams
Quoted 8 lines · Luis R. Rodriguez
Quoted 7 lines · Dan Williams
include/linux/mm.h +0 -0
index 2e872f92dbac..84b05ebedb2d 100644
@@ -369,7 +369,14 @@ static inline int put_page_unless_one(struct page *page)
 }
 
Quoted 13 lines

include/linux/mm.h static inline int put_page_unless_one(struct page *page) · line 378

Quoted 9 lines
include/linux/mm.h +7 -1
 extern int page_is_ram(unsigned long pfn);
-extern int region_is_ram(resource_size_t phys_addr, unsigned long size);
+
+enum {
+     REGION_INTERSECTS,
+     REGION_DISJOINT,
+     REGION_MIXED,
+};
+

Can you Kdoc'ify this? Part of the reason for the enum request was this could be then documented really well. The helper is documented but here you can go into more detail about each region intersection.

Given region_intersects() has its own kdoc I'd probably just say "See region_intersects() for details".

Quoted 7 lines
Quoted 4 lines

With the kdoc in place in the enum you'd kick people to elaborate when extending the enums, whereas without this you'd hope they do it. With the enum in place you can also be more verbose.

Care to send a patch on what you are thinking? I wasn't planning on this enum growing any other entries.

I mean something like this:

/**
* enum region_intersect_type
*
* @REGION_INTERSECTS: explain and you you can go into any elaborate
* detail as you wish.
* @REGION_DISJOINT: explain
* @REGION_MIXED: explain
*/
enum region_intersect_type {
REGION_INTERSECTS,
REGION_DISJOINT,
REGION_MIXED,
};

Luis

#7 lore raw

Re: [PATCH v3 01/24] mm: enhance region_is_ram() to region_intersects()

In reply to Dan Williams
Quoted 29 lines · Dan Williams

region_is_ram() is used to prevent the establishment of aliased mappings to physical "System RAM" with incompatible cache settings. However, it uses "-1" to indicate both "unknown" memory ranges (ranges not described by platform firmware) and "mixed" ranges (where the parameters describe a range that partially overlaps "System RAM").

Fix this up by explicitly tracking the "unknown" vs "mixed" resource cases and returning REGION_INTERSECTS, REGION_MIXED, or REGION_DISJOINT. This re-write also adds support for detecting when the requested region completely eclipses all of a resource. Note, the implementation treats overlaps between "unknown" and the requested memory type as REGION_INTERSECTS.

Finally, other memory types can be passed in by name, for now the only usage "System RAM".

---
 include/linux/mm.h |    9 +++++++-
 kernel/resource.c  |   61 +++++++++++++++++++++++++++++++---------------------
 2 files changed, 44 insertions(+), 26 deletions(-)
include/linux/mm.h +0 -0
index 2e872f92dbac..84b05ebedb2d 100644

include/linux/mm.h static inline int put_page_unless_one(struct page *page) · line 373

Quoted 6 lines
include/linux/mm.h +2 -1
@@ -369,7 +369,14 @@ static inline int put_page_unless_one(struct page *page)
 }
 
 extern int page_is_ram(unsigned long pfn);
-extern int region_is_ram(resource_size_t phys_addr, unsigned long size);
+
+enum {

If you gave the enum a name, say enum region_intersect_type, you could then use that for the return type of region_intersects.

include/linux/mm.h static inline int put_page_unless_one(struct page *page) · line 379

Quoted 6 lines
include/linux/mm.h +6 -0
+	REGION_INTERSECTS,
+	REGION_DISJOINT,
+	REGION_MIXED,
+};
+
+int region_intersects(resource_size_t offset, size_t size, const char *type);

If you used say a return type enum region_intersect_type, at compile time you'd get a complaint if any branch was not handled for the different enum types.

Luis

#8 lore raw

PATCH v3 2/24 arch, drivers: don't include <asm/io.h> directly, use <linux/io.h> instead

In reply to Dan Williams

Preparation for uniform definition of ioremap, ioremap_wc, ioremap_wt, and ioremap_cache, tree-wide.

---
 arch/arm/mach-shmobile/pm-rcar.c            |    2 +-
 arch/ia64/kernel/cyclone.c                  |    2 +-
 drivers/isdn/icn/icn.h                      |    2 +-
 drivers/mtd/devices/slram.c                 |    2 +-
 drivers/mtd/nand/diskonchip.c               |    2 +-
 drivers/mtd/onenand/generic.c               |    2 +-
 drivers/scsi/sun3x_esp.c                    |    2 +-
 drivers/staging/comedi/drivers/ii_pci20kc.c |    1 +
 drivers/tty/serial/8250/8250_core.c         |    2 +-
 drivers/video/fbdev/s1d13xxxfb.c            |    3 +--
 drivers/video/fbdev/stifb.c                 |    1 +
 include/linux/io-mapping.h                  |    2 +-
 include/linux/mtd/map.h                     |    2 +-
 include/video/vga.h                         |    2 +-
 14 files changed, 14 insertions(+), 13 deletions(-)
arch/arm/mach-shmobile/pm-rcar.c +1 -1
index 00022ee56f80..9d3dde00c2fe 100644
@@ -12,7 +12,7 @@
 #include <linux/err.h>
 #include <linux/mm.h>
 #include <linux/spinlock.h>
-#include <asm/io.h>
+#include <linux/io.h>
 #include "pm-rcar.h"
 
 /* SYSC */
arch/ia64/kernel/cyclone.c +1 -1
index 4826ff957a3d..5fa3848ba224 100644
@@ -4,7 +4,7 @@
 #include <linux/errno.h>
 #include <linux/timex.h>
 #include <linux/clocksource.h>
-#include <asm/io.h>
+#include <linux/io.h>
 
 /* IBM Summit (EXA) Cyclone counter code*/
 #define CYCLONE_CBAR_ADDR 0xFEB00CD0
drivers/isdn/icn/icn.h +1 -1
index b713466997a0..f8f2e76d34bf 100644
@@ -38,7 +38,7 @@ typedef struct icn_cdef {
 #include <linux/errno.h>
 #include <linux/fs.h>
 #include <linux/major.h>
-#include <asm/io.h>
+#include <linux/io.h>
 #include <linux/kernel.h>
 #include <linux/signal.h>
 #include <linux/slab.h>
drivers/mtd/devices/slram.c +1 -1
index 2fc4957cbe7f..a70eb83e68f1 100644
@@ -41,7 +41,7 @@
 #include <linux/fs.h>
 #include <linux/ioctl.h>
 #include <linux/init.h>
-#include <asm/io.h>
+#include <linux/io.h>
 
 #include <linux/mtd/mtd.h>
 
drivers/mtd/nand/diskonchip.c +1 -1
index 7da266a53979..0802158a3f75 100644
@@ -24,7 +24,7 @@
 #include <linux/rslib.h>
 #include <linux/moduleparam.h>
 #include <linux/slab.h>
-#include <asm/io.h>
+#include <linux/io.h>
 
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/nand.h>
drivers/mtd/onenand/generic.c +1 -1
index 32a216d31141..ab7bda0bb245 100644
@@ -18,7 +18,7 @@
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/onenand.h>
 #include <linux/mtd/partitions.h>
-#include <asm/io.h>
+#include <linux/io.h>
 
 /*
  * Note: Driver name and platform data format have been updated!
drivers/scsi/sun3x_esp.c +1 -1
index e26e81de7c45..d50c5ed8f428 100644
@@ -12,9 +12,9 @@
 #include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
 #include <linux/interrupt.h>
+#include <linux/io.h>
 
 #include <asm/sun3x.h>
-#include <asm/io.h>
 #include <asm/dma.h>
 #include <asm/dvma.h>
 
drivers/staging/comedi/drivers/ii_pci20kc.c +1 -0
index 0768bc42a5db..14ef1f67dd42 100644
@@ -28,6 +28,7 @@
  */
 
 #include <linux/module.h>
+#include <linux/io.h>
 #include "../comedidev.h"
 
 /*
drivers/tty/serial/8250/8250_core.c +1 -1
index 37fff12dd4d0..fe902ff52e58 100644
@@ -38,11 +38,11 @@
 #include <linux/slab.h>
 #include <linux/uaccess.h>
 #include <linux/pm_runtime.h>
+#include <linux/io.h>
 #ifdef CONFIG_SPARC
 #include <linux/sunserialcore.h>
 #endif
 
-#include <asm/io.h>
 #include <asm/irq.h>
 
 #include "8250.h"
drivers/video/fbdev/s1d13xxxfb.c +1 -2
index 83433cb0dfba..96aa46dc696c 100644
@@ -32,8 +32,7 @@
 #include <linux/spinlock_types.h>
 #include <linux/spinlock.h>
 #include <linux/slab.h>
-
-#include <asm/io.h>
+#include <linux/io.h>
 
 #include <video/s1d13xxxfb.h>
 
drivers/video/fbdev/stifb.c +1 -0
index 735355b0e023..7df4228e25f0 100644
@@ -64,6 +64,7 @@
 #include <linux/fb.h>
 #include <linux/init.h>
 #include <linux/ioport.h>
+#include <linux/io.h>
 
 #include <asm/grfioctl.h>	/* for HP-UX compatibility */
 #include <asm/uaccess.h>
include/linux/io-mapping.h +1 -1
index c27dde7215b5..e399029b68c5 100644
@@ -21,7 +21,7 @@
 #include <linux/types.h>
 #include <linux/slab.h>
 #include <linux/bug.h>
-#include <asm/io.h>
+#include <linux/io.h>
 #include <asm/page.h>
 
 /*
include/linux/mtd/map.h +1 -1
index 29975c73a953..366cf77953b5 100644
@@ -27,9 +27,9 @@
 #include <linux/string.h>
 #include <linux/bug.h>
 #include <linux/kernel.h>
+#include <linux/io.h>
 
 #include <asm/unaligned.h>
-#include <asm/io.h>
 #include <asm/barrier.h>
 
 #ifdef CONFIG_MTD_MAP_BANK_WIDTH_1
include/video/vga.h +1 -1
index cac567f22e62..d334e64c1c19 100644
@@ -18,7 +18,7 @@
 #define __linux_video_vga_h__
 
 #include <linux/types.h>
-#include <asm/io.h>
+#include <linux/io.h>
 #include <asm/vga.h>
 #include <asm/byteorder.h>
#9 lore raw

PATCH v3 3/24 cleanup IORESOURCE_CACHEABLE vs ioremap()

In reply to Dan Williams

Quoting Arnd:
I was thinking the opposite approach and basically removing all uses of IORESOURCE_CACHEABLE from the kernel. There are only a handful of them.and we can probably replace them all with hardcoded ioremap_cached() calls in the cases they are actually useful.

All existing usages of IORESOURCE_CACHEABLE call ioremap() instead of ioremap_nocache() if the resource is cacheable, however ioremap() is uncached by default. Clearly none of the existing usages care about the cacheability. Particularly devm_ioremap_resource() never worked as advertised since it always fell back to plain ioremap().

Clean this up as the new direction we want is to convert ioremap_<type>() usages to memremap(..., flags).

---
 arch/arm/mach-clps711x/board-cdb89712.c |    2 +-
 arch/powerpc/kernel/pci_of_scan.c       |    2 +-
 arch/sparc/kernel/pci.c                 |    3 +--
 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/video/fbdev/ocfb.c              |    1 -
 lib/devres.c                            |   13 ++++---------
 lib/pci_iomap.c                         |    7 ++-----
 11 files changed, 16 insertions(+), 44 deletions(-)
arch/arm/mach-clps711x/board-cdb89712.c +1 -1
index 1ec378c334e5..972abdb10028 100644
@@ -95,7 +95,7 @@ static struct physmap_flash_data cdb89712_bootrom_pdata __initdata = {
 
 static struct resource cdb89712_bootrom_resources[] __initdata = {
 	DEFINE_RES_NAMED(CS7_PHYS_BASE, SZ_128, "BOOTROM", IORESOURCE_MEM |
-			 IORESOURCE_CACHEABLE | IORESOURCE_READONLY),
+			 IORESOURCE_READONLY),
 };
 
 static struct platform_device cdb89712_bootrom_pdev __initdata = {
arch/powerpc/kernel/pci_of_scan.c +1 -1
index 42e02a2d570b..d4726addff0b 100644
@@ -102,7 +102,7 @@ static void of_pci_parse_addrs(struct device_node *node, struct pci_dev *dev)
 			res = &dev->resource[(i - PCI_BASE_ADDRESS_0) >> 2];
 		} else if (i == dev->rom_base_reg) {
 			res = &dev->resource[PCI_ROM_RESOURCE];
-			flags |= IORESOURCE_READONLY | IORESOURCE_CACHEABLE;
+			flags |= IORESOURCE_READONLY;
 		} else {
 			printk(KERN_ERR "PCI: bad cfg reg num 0x%x\n", i);
 			continue;
arch/sparc/kernel/pci.c +1 -2
index c928bc64b4ba..04da147e0712 100644
@@ -231,8 +231,7 @@ static void pci_parse_of_addrs(struct platform_device *op,
 			res = &dev->resource[(i - PCI_BASE_ADDRESS_0) >> 2];
 		} else if (i == dev->rom_base_reg) {
 			res = &dev->resource[PCI_ROM_RESOURCE];
-			flags |= IORESOURCE_READONLY | IORESOURCE_CACHEABLE
-			      | IORESOURCE_SIZEALIGN;
+			flags |= IORESOURCE_READONLY | IORESOURCE_SIZEALIGN;
 		} else {
 			printk(KERN_ERR "PCI: bad cfg reg num 0x%x\n", i);
 			continue;
drivers/pci/probe.c +1 -2
index cefd636681b6..8ed37dd04056 100644
@@ -326,8 +326,7 @@ static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom)
 		struct resource *res = &dev->resource[PCI_ROM_RESOURCE];
 		dev->rom_base_reg = rom;
 		res->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH |
-				IORESOURCE_READONLY | IORESOURCE_CACHEABLE |
-				IORESOURCE_SIZEALIGN;
+				IORESOURCE_READONLY | IORESOURCE_SIZEALIGN;
 		__pci_read_base(dev, pci_bar_mem32, res, rom);
 	}
 }
drivers/pnp/manager.c +0 -2
index 9357aa779048..7ad3295752ef 100644
@@ -97,8 +97,6 @@ static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx)
 	/* ??? rule->flags restricted to 8 bits, all tests bogus ??? */
 	if (!(rule->flags & IORESOURCE_MEM_WRITEABLE))
 		res->flags |= IORESOURCE_READONLY;
-	if (rule->flags & IORESOURCE_MEM_CACHEABLE)
-		res->flags |= IORESOURCE_CACHEABLE;
 	if (rule->flags & IORESOURCE_MEM_RANGELENGTH)
 		res->flags |= IORESOURCE_RANGELENGTH;
 	if (rule->flags & IORESOURCE_MEM_SHADOWABLE)
drivers/scsi/aic94xx/aic94xx_init.c +1 -6
index 4b135cca42a1..140cb8e6fea2 100644
@@ -100,12 +100,7 @@ static int asd_map_memio(struct asd_ha_struct *asd_ha)
 				   pci_name(asd_ha->pcidev));
 			goto Err;
 		}
-		if (io_handle->flags & IORESOURCE_CACHEABLE)
-			io_handle->addr = ioremap(io_handle->start,
-						  io_handle->len);
-		else
-			io_handle->addr = ioremap_nocache(io_handle->start,
-							  io_handle->len);
+		io_handle->addr = ioremap(io_handle->start, io_handle->len);
 		if (!io_handle->addr) {
 			asd_printk("couldn't map MBAR%d of %s\n", i==0?0:1,
 				   pci_name(asd_ha->pcidev));
drivers/scsi/arcmsr/arcmsr_hba.c +1 -4
index 914c39f9f388..e4f77cad9fd8 100644
@@ -259,10 +259,7 @@ static bool arcmsr_remap_pciregion(struct AdapterControlBlock *acb)
 		addr = (unsigned long)pci_resource_start(pdev, 0);
 		range = pci_resource_len(pdev, 0);
 		flags = pci_resource_flags(pdev, 0);
-		if (flags & IORESOURCE_CACHEABLE)
-			mem_base0 = ioremap(addr, range);
-		else
-			mem_base0 = ioremap_nocache(addr, range);
+		mem_base0 = ioremap(addr, range);
 		if (!mem_base0) {
 			pr_notice("arcmsr%d: memory mapping region fail\n",
 				acb->host->host_no);
drivers/scsi/mvsas/mv_init.c +4 -11
index d40d734aa53a..e654b5cec69e 100644
@@ -324,13 +324,9 @@ int mvs_ioremap(struct mvs_info *mvi, int bar, int bar_ex)
 			goto err_out;
 
 		res_flag_ex = pci_resource_flags(pdev, bar_ex);
-		if (res_flag_ex & IORESOURCE_MEM) {
-			if (res_flag_ex & IORESOURCE_CACHEABLE)
-				mvi->regs_ex = ioremap(res_start, res_len);
-			else
-				mvi->regs_ex = ioremap_nocache(res_start,
-						res_len);
-		} else
+		if (res_flag_ex & IORESOURCE_MEM)
+			mvi->regs_ex = ioremap(res_start, res_len);
+		else
 			mvi->regs_ex = (void *)res_start;
 		if (!mvi->regs_ex)
 			goto err_out;
@@ -342,10 +338,7 @@ int mvs_ioremap(struct mvs_info *mvi, int bar, int bar_ex)
 		goto err_out;
 
 	res_flag = pci_resource_flags(pdev, bar);
-	if (res_flag & IORESOURCE_CACHEABLE)
-		mvi->regs = ioremap(res_start, res_len);
-	else
-		mvi->regs = ioremap_nocache(res_start, res_len);
+	mvi->regs = ioremap(res_start, res_len);
 
 	if (!mvi->regs) {
 		if (mvi->regs_ex && (res_flag_ex & IORESOURCE_MEM))
drivers/video/fbdev/ocfb.c +0 -1
index de9819660ca0..c9293aea8ec3 100644
@@ -325,7 +325,6 @@ static int ocfb_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "I/O resource request failed\n");
 		return -ENXIO;
 	}
-	res->flags &= ~IORESOURCE_CACHEABLE;
 	fbdev->regs = devm_ioremap_resource(&pdev->dev, res);
 	if (IS_ERR(fbdev->regs))
 		return PTR_ERR(fbdev->regs);
lib/devres.c +4 -9
index fbe2aac522e6..f13a2468ff39 100644
@@ -119,10 +119,9 @@ EXPORT_SYMBOL(devm_iounmap);
  * @dev: generic device to handle the resource for
  * @res: resource to be handled
  *
- * Checks that a resource is a valid memory region, requests the memory region
- * and ioremaps it either as cacheable or as non-cacheable memory depending on
- * the resource's flags. All operations are managed and will be undone on
- * driver detach.
+ * Checks that a resource is a valid memory region, requests the memory
+ * region and ioremaps it. All operations are managed and will be undone
+ * on driver detach.
  *
  * Returns a pointer to the remapped memory or an ERR_PTR() encoded error code
  * on failure. Usage example:
@@ -153,11 +152,7 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res)
 		return IOMEM_ERR_PTR(-EBUSY);
 	}
 
-	if (res->flags & IORESOURCE_CACHEABLE)
-		dest_ptr = devm_ioremap(dev, res->start, size);
-	else
-		dest_ptr = devm_ioremap_nocache(dev, res->start, size);
-
+	dest_ptr = devm_ioremap(dev, res->start, size);
 	if (!dest_ptr) {
 		dev_err(dev, "ioremap failed for resource %pR\n", res);
 		devm_release_mem_region(dev, res->start, size);
lib/pci_iomap.c +2 -5
index bcce5f149310..e1930dbab2da 100644
@@ -41,11 +41,8 @@ void __iomem *pci_iomap_range(struct pci_dev *dev,
 		len = maxlen;
 	if (flags & IORESOURCE_IO)
 		return __pci_ioport_map(dev, start, len);
-	if (flags & IORESOURCE_MEM) {
-		if (flags & IORESOURCE_CACHEABLE)
-			return ioremap(start, len);
-		return ioremap_nocache(start, len);
-	}
+	if (flags & IORESOURCE_MEM)
+		return ioremap(start, len);
 	/* What? */
 	return NULL;
 }
#10 lore raw

PATCH v3 4/24 intel_iommu: fix leaked ioremap mapping

In reply to Dan Williams

iommu_load_old_irte() appears to leak the old_irte mapping after use.

---
 drivers/iommu/intel_irq_remapping.c |    2 ++
 1 file changed, 2 insertions(+)
drivers/iommu/intel_irq_remapping.c +2 -0
index f15692a410c7..27cdfa84ec5b 100644
@@ -426,6 +426,8 @@ static int iommu_load_old_irte(struct intel_iommu *iommu)
 			bitmap_set(iommu->ir_table->bitmap, i, 1);
 	}
 
+	iounmap(old_ir_table);
+
 	return 0;
 }
 
Applied
#11 lore raw

Re: [PATCH v3 04/24] intel_iommu: fix leaked ioremap mapping

Quoted 7 lines · Dan Williams

iommu_load_old_irte() appears to leak the old_irte mapping after use.

---
 drivers/iommu/intel_irq_remapping.c |    2 ++
 1 file changed, 2 insertions(+)

Applied, thanks.

#12 lore raw

PATCH v3 5/24 arch: introduce memremap()

In reply to Dan Williams

Existing users of ioremap_cache() are mapping memory that is known in advance to not have i/o side effects. These users are forced to cast away the __iomem annotation, or otherwise neglect to fix the sparse errors thrown when dereferencing pointers to this memory. Provide memremap() as a non __iomem annotated ioremap_*() in the case when ioremap is otherwise a pointer to cacheable memory. Empirically, ioremap_<cacheable-type>() call sites are seeking memory-like semantics (e.g. speculative reads, and prefetching permitted).

memremap() is a break from the ioremap implementation pattern of adding a new memremap_<type>() for each mapping type and having silent compatibility fall backs. Instead, the implementation defines flags that are passed to the central memremap() and if a mapping type is not supported by an arch memremap returns NULL.

We introduce a memremap prototype as a trivial wrapper of ioremap_cache() and ioremap_wt(). Later, once all ioremap_cache() and ioremap_wt() usage has been removed from drivers we teach archs to implement arch_memremap() with the ability to strictly enforce the mapping type.

---
 arch/ia64/include/asm/io.h   |    1 
 arch/sh/include/asm/io.h     |    1 
 arch/xtensa/include/asm/io.h |    1 
 include/linux/io.h           |    9 ++++
 kernel/Makefile              |    2 +
 kernel/memremap.c            |   98 ++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 112 insertions(+)
 create mode 100644 kernel/memremap.c
arch/ia64/include/asm/io.h +1 -0
index 80a7e34be009..9041bbe2b7b4 100644
@@ -435,6 +435,7 @@ static inline void __iomem * ioremap_cache (unsigned long phys_addr, unsigned lo
 {
 	return ioremap(phys_addr, size);
 }
+#define ioremap_cache ioremap_cache
 
 
 /*
arch/sh/include/asm/io.h +1 -0
index 728c4c571f40..6194e20fccca 100644
@@ -342,6 +342,7 @@ ioremap_cache(phys_addr_t offset, unsigned long size)
 {
 	return __ioremap_mode(offset, size, PAGE_KERNEL);
 }
+#define ioremap_cache ioremap_cache
 
 #ifdef CONFIG_HAVE_IOREMAP_PROT
 static inline void __iomem *
arch/xtensa/include/asm/io.h +1 -0
index c39bb6e61911..867840f5400f 100644
@@ -57,6 +57,7 @@ static inline void __iomem *ioremap_cache(unsigned long offset,
 	else
 		BUG();
 }
+#define ioremap_cache ioremap_cache
 
 #define ioremap_wc ioremap_nocache
 #define ioremap_wt ioremap_nocache
include/linux/io.h +9 -0
index fb5a99800e77..3fcf6256c088 100644
@@ -121,4 +121,13 @@ static inline int arch_phys_wc_index(int handle)
 #endif
 #endif
 
+enum {
+	/* See memremap() kernel-doc for usage description... */
+	MEMREMAP_WB = 1 << 0,
+	MEMREMAP_WT = 1 << 1,
+};
+
+void *memremap(resource_size_t offset, size_t size, unsigned long flags);
+void memunmap(void *addr);
+
 #endif /* _LINUX_IO_H */
kernel/Makefile +2 -0
index 43c4c920f30a..92866d36e376 100644
@@ -99,6 +99,8 @@ obj-$(CONFIG_JUMP_LABEL) += jump_label.o
 obj-$(CONFIG_CONTEXT_TRACKING) += context_tracking.o
 obj-$(CONFIG_TORTURE_TEST) += torture.o
 
+obj-$(CONFIG_HAS_IOMEM) += memremap.o
+
 $(obj)/configs.o: $(obj)/config_data.h
 
 # config_data.h contains the same information as ikconfig.h but gzipped.
kernel/memremap.c new file +98 -0

98 lines not on this page · raw message

#13 lore raw

Re: [PATCH v3 05/24] arch: introduce memremap()

include/linux/io.h static inline int arch_phys_wc_index(int handle) · line 128

Quoted 13 lines · Dan Williams
include/linux/io.h +5 -0
index fb5a99800e77..3fcf6256c088 100644
@@ -121,4 +121,13 @@ static inline int arch_phys_wc_index(int handle)
 #endif
 #endif
 
+enum {
+	/* See memremap() kernel-doc for usage description... */
+	MEMREMAP_WB = 1 << 0,
+	MEMREMAP_WT = 1 << 1,
+};

Same feedback for enum nameing and also kdoc style.

kernel/memremap.c

Quoted 5 lines
kernel/memremap.c new file +0 -0
new file mode 100644
index 000000000000..27637f42f30d

<-- ... -->

Quoted 12 lines

+/**
+ * memremap() - remap an iomem_resource as cacheable memory
+ * @offset: iomem resource start address
+ * @size: size of remap
+ * @flags: either MEMREMAP_WB or MEMREMAP_WT
+ *
+ * memremap() is "ioremap" for cases where it is known that the resource
+ * being mapped does not have i/o side effects and the __iomem
+ * annotation is not applicable.
+ *
+ * MEMREMAP_WB - matches the default mapping for "System RAM" on
+ * the architecture. This is usually a read-allocate write-back cache.

Quoted 8 lines

+ * Morever, if MEMREMAP_WB is specified and the requested remap region is RAM
+ * memremap() will bypass establishing a new mapping and instead return
+ * a pointer into the direct map.
+ *
+ * MEMREMAP_WT - establish a mapping whereby writes either bypass the
+ * cache or are written through to memory and never exist in a
+ * cache-dirty state with respect to program visibility. Attempts to
+ * map "System RAM" with this mapping type will fail.

Then you can extrend all this on kdoc on the enum.

kernel/memremap.c line 48

Quoted 4 lines

+ */

kernel/memremap.c new file +3 -0
+void *memremap(resource_size_t offset, size_t size, unsigned long flags)
+{
+	int is_ram = region_intersects(offset, size, "System RAM");

This could be the enum region_intersect_type, then if the region enum is extended you'd get a compiler error if one type was not handled.

Luis

#14 lore raw

Re: [PATCH v3 05/24] arch: introduce memremap()

Quoted 9 lines · Luis R. Rodriguez
Quoted 8 lines · Dan Williams
include/linux/io.h +0 -0
index fb5a99800e77..3fcf6256c088 100644
@@ -121,4 +121,13 @@ static inline int arch_phys_wc_index(int handle)
 #endif
 #endif
 
Quoted 7 lines

include/linux/io.h static inline int arch_phys_wc_index(int handle) · line 128

Quoted 5 lines
include/linux/io.h +5 -0
+enum {
+     /* See memremap() kernel-doc for usage description... */
+     MEMREMAP_WB = 1 << 0,
+     MEMREMAP_WT = 1 << 1,
+};

Same feedback for enum nameing and also kdoc style.

I'm concerned documentation here has the possibility of getting out of sync with the "source of truth" at the definition of memremap(). I think it's better to have the documentation consolidated at it implementation rather than its definition.

Quoted 32 lines

kernel/memremap.c

Quoted 6 lines
kernel/memremap.c new file +0 -0
new file mode 100644
index 000000000000..27637f42f30d

<-- ... -->

Quoted 12 lines

+/**
+ * memremap() - remap an iomem_resource as cacheable memory
+ * @offset: iomem resource start address
+ * @size: size of remap
+ * @flags: either MEMREMAP_WB or MEMREMAP_WT
+ *
+ * memremap() is "ioremap" for cases where it is known that the resource
+ * being mapped does not have i/o side effects and the __iomem
+ * annotation is not applicable.
+ *
+ * MEMREMAP_WB - matches the default mapping for "System RAM" on
+ * the architecture. This is usually a read-allocate write-back cache.

Quoted 8 lines

+ * Morever, if MEMREMAP_WB is specified and the requested remap region is RAM
+ * memremap() will bypass establishing a new mapping and instead return
+ * a pointer into the direct map.
+ *
+ * MEMREMAP_WT - establish a mapping whereby writes either bypass the
+ * cache or are written through to memory and never exist in a
+ * cache-dirty state with respect to program visibility. Attempts to
+ * map "System RAM" with this mapping type will fail.

Then you can extrend all this on kdoc on the enum.

Quoted 7 lines

kernel/memremap.c line 48

Quoted 4 lines

+ */

kernel/memremap.c new file +3 -0
+void *memremap(resource_size_t offset, size_t size, unsigned long flags)
+{
+     int is_ram = region_intersects(offset, size, "System RAM");

This could be the enum region_intersect_type, then if the region enum is extended you'd get a compiler error if one type was not handled.

This already does not handle the REGION_DISJOINT case explicitly, it's implied by handling the other 2. A compiler warning would be verbose for not much benefit afaics.

#15 lore raw

PATCH v3 6/24 arm: switch from ioremap_cache to memremap

In reply to Dan Williams

In preparation for deprecating ioremap_cache() convert its usage in arch/arm[64]/ to memremap.

---
 arch/arm/include/asm/xen/page.h    |    4 ++--
 arch/arm64/include/asm/acpi.h      |    5 +----
 arch/arm64/include/asm/dmi.h       |    8 ++++----
 arch/arm64/kernel/efi.c            |    9 +++++----
 arch/arm64/kernel/smp_spin_table.c |   19 +++++++++----------
 5 files changed, 21 insertions(+), 24 deletions(-)
arch/arm/include/asm/xen/page.h +2 -2
index 1bee8ca12494..b1cf4ee80807 100644
@@ -103,8 +103,8 @@ static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
 	return __set_phys_to_machine(pfn, mfn);
 }
 
-#define xen_remap(cookie, size) ioremap_cache((cookie), (size))
-#define xen_unmap(cookie) iounmap((cookie))
+#define xen_remap(cookie, size) memremap((cookie), (size), MEMREMAP_WB)
+#define xen_unmap(cookie) memunmap((cookie))
 
 bool xen_arch_need_swiotlb(struct device *dev,
 			   unsigned long pfn,
arch/arm64/include/asm/acpi.h +1 -4
index 406485ed110a..fdccacd8f7bb 100644
@@ -33,10 +33,7 @@
 static inline void __iomem *acpi_os_ioremap(acpi_physical_address phys,
 					    acpi_size size)
 {
-	if (!page_is_ram(phys >> PAGE_SHIFT))
-		return ioremap(phys, size);
-
-	return ioremap_cache(phys, size);
+	return memremap(phys, size, MEMREMAP_WB);
 }
 #define acpi_os_ioremap acpi_os_ioremap
 
arch/arm64/include/asm/dmi.h +4 -4
index 69d37d87b159..82682d27c6ee 100644
@@ -22,10 +22,10 @@
  * request a virtual mapping for configuration tables such as SMBIOS.
  * This means we have to map them before use.
  */
-#define dmi_early_remap(x, l)		ioremap_cache(x, l)
-#define dmi_early_unmap(x, l)		iounmap(x)
-#define dmi_remap(x, l)			ioremap_cache(x, l)
-#define dmi_unmap(x)			iounmap(x)
+#define dmi_early_remap(x, l)		memremap(x, l, MEMREMAP_WB)
+#define dmi_early_unmap(x, l)		memunmap(x)
+#define dmi_remap(x, l)			memremap(x, l, MEMREMAP_WB)
+#define dmi_unmap(x)			memunmap(x)
 #define dmi_alloc(l)			kzalloc(l, GFP_KERNEL)
 
 #endif
arch/arm64/kernel/efi.c +5 -4
index 9d4aa18f2a82..71fdc5ff36af 100644
@@ -26,6 +26,7 @@
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/spinlock.h>
+#include <linux/io.h>
 
 #include <asm/cacheflush.h>
 #include <asm/efi.h>
@@ -290,8 +291,8 @@ static int __init arm64_enable_runtime_services(void)
 	pr_info("Remapping and enabling EFI services.\n");
 
 	mapsize = memmap.map_end - memmap.map;
-	memmap.map = (__force void *)ioremap_cache((phys_addr_t)memmap.phys_map,
-						   mapsize);
+	memmap.map = memremap((phys_addr_t) memmap.phys_map, mapsize,
+			MEMREMAP_WB);
 	if (!memmap.map) {
 		pr_err("Failed to remap EFI memory map\n");
 		return -1;
@@ -299,8 +300,8 @@ static int __init arm64_enable_runtime_services(void)
 	memmap.map_end = memmap.map + mapsize;
 	efi.memmap = &memmap;
 
-	efi.systab = (__force void *)ioremap_cache(efi_system_table,
-						   sizeof(efi_system_table_t));
+	efi.systab = memremap(efi_system_table, sizeof(efi_system_table_t),
+			MEMREMAP_WB);
 	if (!efi.systab) {
 		pr_err("Failed to remap EFI System Table\n");
 		return -1;
arch/arm64/kernel/smp_spin_table.c +9 -10
index aef3605a8c47..2c06c1a36154 100644
@@ -21,11 +21,11 @@
 #include <linux/of.h>
 #include <linux/smp.h>
 #include <linux/types.h>
+#include <linux/io.h>
 
 #include <asm/cacheflush.h>
 #include <asm/cpu_ops.h>
 #include <asm/cputype.h>
-#include <asm/io.h>
 #include <asm/smp_plat.h>
 
 extern void secondary_holding_pen(void);
@@ -73,19 +73,19 @@ static int smp_spin_table_cpu_init(unsigned int cpu)
 
 static int smp_spin_table_cpu_prepare(unsigned int cpu)
 {
-	__le64 __iomem *release_addr;
+	__le64 *release_addr;
 
 	if (!cpu_release_addr[cpu])
 		return -ENODEV;
 
 	/*
 	 * The cpu-release-addr may or may not be inside the linear mapping.
-	 * As ioremap_cache will either give us a new mapping or reuse the
-	 * existing linear mapping, we can use it to cover both cases. In
-	 * either case the memory will be MT_NORMAL.
+	 * As memremap will either give us a new mapping or reuse the existing
+	 * linear mapping, we can use it to cover both cases. In either case
+	 * the memory will be MT_NORMAL.
 	 */
-	release_addr = ioremap_cache(cpu_release_addr[cpu],
-				     sizeof(*release_addr));
+	release_addr = memremap(cpu_release_addr[cpu], sizeof(*release_addr),
+			MEMREMAP_WB);
 	if (!release_addr)
 		return -ENOMEM;
 
@@ -97,15 +97,14 @@ static int smp_spin_table_cpu_prepare(unsigned int cpu)
 	 * the boot protocol.
 	 */
 	writeq_relaxed(__pa(secondary_holding_pen), release_addr);
-	__flush_dcache_area((__force void *)release_addr,
-			    sizeof(*release_addr));
+	__flush_dcache_area(release_addr, sizeof(*release_addr));
 
 	/*
 	 * Send an event to wake up the secondary CPU.
 	 */
 	sev();
 
-	iounmap(release_addr);
+	memunmap(release_addr);
 
 	return 0;
 }
#16 lore raw

PATCH v3 7/24 x86: switch from ioremap_cache to memremap

In reply to Dan Williams

In preparation for deprecating ioremap_cache() convert its usage in arch/x86/ to memremap.

Cc Thomas Gleixner <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
---
 arch/x86/include/asm/efi.h      |    3 ++-
 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           |   10 ++++------
 5 files changed, 27 insertions(+), 28 deletions(-)
arch/x86/include/asm/efi.h +2 -1
index 155162ea0e00..f280cdcfbf22 100644
@@ -54,7 +54,8 @@ extern unsigned long asmlinkage efi_call_phys(void *, ...);
 	kernel_fpu_end();						\
 })
 
-#define efi_ioremap(addr, size, type, attr)	ioremap_cache(addr, size)
+#define efi_ioremap(addr, size, type, attr)				\
+	memremap(addr, size, MEMREMAP_WB)
 
 #else /* !CONFIG_X86_32 */
 
arch/x86/kernel/crash_dump_64.c +3 -3
index afa64adb75ee..941609ab9aa9 100644
@@ -31,19 +31,19 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
 	if (!csize)
 		return 0;
 
-	vaddr = ioremap_cache(pfn << PAGE_SHIFT, PAGE_SIZE);
+	vaddr = memremap(pfn << PAGE_SHIFT, PAGE_SIZE, MEMREMAP_WB);
 	if (!vaddr)
 		return -ENOMEM;
 
 	if (userbuf) {
 		if (copy_to_user(buf, vaddr + offset, csize)) {
-			iounmap(vaddr);
+			memunmap(vaddr);
 			return -EFAULT;
 		}
 	} else
 		memcpy(buf, vaddr + offset, csize);
 
 	set_iounmap_nonlazy();
-	iounmap(vaddr);
+	memunmap(vaddr);
 	return csize;
 }
arch/x86/kernel/kdebugfs.c +4 -4
index dc1404bf8e4b..fa30f85b4333 100644
@@ -49,7 +49,7 @@ static ssize_t setup_data_read(struct file *file, char __user *user_buf,
 	pa = node->paddr + sizeof(struct setup_data) + pos;
 	pg = pfn_to_page((pa + count - 1) >> PAGE_SHIFT);
 	if (PageHighMem(pg)) {
-		p = ioremap_cache(pa, count);
+		p = memremap(pa, count, MEMREMAP_WB);
 		if (!p)
 			return -ENXIO;
 	} else
@@ -58,7 +58,7 @@ static ssize_t setup_data_read(struct file *file, char __user *user_buf,
 	remain = copy_to_user(user_buf, p, count);
 
 	if (PageHighMem(pg))
-		iounmap(p);
+		memunmap(p);
 
 	if (remain)
 		return -EFAULT;
@@ -128,7 +128,7 @@ static int __init create_setup_data_nodes(struct dentry *parent)
 
 		pg = pfn_to_page((pa_data+sizeof(*data)-1) >> PAGE_SHIFT);
 		if (PageHighMem(pg)) {
-			data = ioremap_cache(pa_data, sizeof(*data));
+			data = memremap(pa_data, sizeof(*data), MEMREMAP_WB);
 			if (!data) {
 				kfree(node);
 				error = -ENXIO;
@@ -144,7 +144,7 @@ static int __init create_setup_data_nodes(struct dentry *parent)
 		pa_data = data->next;
 
 		if (PageHighMem(pg))
-			iounmap(data);
+			memunmap(data);
 		if (error)
 			goto err_dir;
 		no++;
arch/x86/kernel/ksysfs.c +14 -14
index c2bedaea11f7..2d6ae3baafb8 100644
@@ -16,8 +16,8 @@
 #include <linux/stat.h>
 #include <linux/slab.h>
 #include <linux/mm.h>
+#include <linux/io.h>
 
-#include <asm/io.h>
 #include <asm/setup.h>
 
 static ssize_t version_show(struct kobject *kobj,
@@ -79,12 +79,12 @@ static int get_setup_data_paddr(int nr, u64 *paddr)
 			*paddr = pa_data;
 			return 0;
 		}
-		data = ioremap_cache(pa_data, sizeof(*data));
+		data = memremap(pa_data, sizeof(*data), MEMREMAP_WB);
 		if (!data)
 			return -ENOMEM;
 
 		pa_data = data->next;
-		iounmap(data);
+		memunmap(data);
 		i++;
 	}
 	return -EINVAL;
@@ -97,17 +97,17 @@ static int __init get_setup_data_size(int nr, size_t *size)
 	u64 pa_data = boot_params.hdr.setup_data;
 
 	while (pa_data) {
-		data = ioremap_cache(pa_data, sizeof(*data));
+		data = memremap(pa_data, sizeof(*data), MEMREMAP_WB);
 		if (!data)
 			return -ENOMEM;
 		if (nr == i) {
 			*size = data->len;
-			iounmap(data);
+			memunmap(data);
 			return 0;
 		}
 
 		pa_data = data->next;
-		iounmap(data);
+		memunmap(data);
 		i++;
 	}
 	return -EINVAL;
@@ -127,12 +127,12 @@ static ssize_t type_show(struct kobject *kobj,
 	ret = get_setup_data_paddr(nr, &paddr);
 	if (ret)
 		return ret;
-	data = ioremap_cache(paddr, sizeof(*data));
+	data = memremap(paddr, sizeof(*data), MEMREMAP_WB);
 	if (!data)
 		return -ENOMEM;
 
 	ret = sprintf(buf, "0x%x\n", data->type);
-	iounmap(data);
+	memunmap(data);
 	return ret;
 }
 
@@ -154,7 +154,7 @@ static ssize_t setup_data_data_read(struct file *fp,
 	ret = get_setup_data_paddr(nr, &paddr);
 	if (ret)
 		return ret;
-	data = ioremap_cache(paddr, sizeof(*data));
+	data = memremap(paddr, sizeof(*data), MEMREMAP_WB);
 	if (!data)
 		return -ENOMEM;
 
@@ -170,15 +170,15 @@ static ssize_t setup_data_data_read(struct file *fp,
 		goto out;
 
 	ret = count;
-	p = ioremap_cache(paddr + sizeof(*data), data->len);
+	p = memremap(paddr + sizeof(*data), data->len, MEMREMAP_WB);
 	if (!p) {
 		ret = -ENOMEM;
 		goto out;
 	}
 	memcpy(buf, p + off, count);
-	iounmap(p);
+	memunmap(p);
 out:
-	iounmap(data);
+	memunmap(data);
 	return ret;
 }
 
@@ -250,13 +250,13 @@ static int __init get_setup_data_total_num(u64 pa_data, int *nr)
 	*nr = 0;
 	while (pa_data) {
 		*nr += 1;
-		data = ioremap_cache(pa_data, sizeof(*data));
+		data = memremap(pa_data, sizeof(*data), MEMREMAP_WB);
 		if (!data) {
 			ret = -ENOMEM;
 			goto out;
 		}
 		pa_data = data->next;
-		iounmap(data);
+		memunmap(data);
 	}
 
 out:
arch/x86/mm/ioremap.c +4 -6
index b9c78f3bcd67..ce53e6cff75c 100644
@@ -403,12 +403,10 @@ void *xlate_dev_mem_ptr(phys_addr_t phys)
 	if (page_is_ram(start >> PAGE_SHIFT))
 		return __va(phys);
 
-	vaddr = ioremap_cache(start, PAGE_SIZE);
-	/* Only add the offset on success and return NULL if the ioremap() failed: */
+	vaddr = memremap(start, PAGE_SIZE, MEMREMAP_WB);
 	if (vaddr)
-		vaddr += offset;
-
-	return vaddr;
+		return vaddr + offset;
+	return NULL;
 }
 
 void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr)
@@ -416,7 +414,7 @@ void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr)
 	if (page_is_ram(phys >> PAGE_SHIFT))
 		return;
 
-	iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
+	memunmap((void *)((unsigned long)addr & PAGE_MASK));
 }
 
 static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
#17 lore raw

PATCH v3 8/24 gma500: switch from acpi_os_ioremap to memremap

In reply to Dan Williams

gma500 expects the OpRegion to be cached (i.e. not __iomem), so explicitly map it with memremap rather than the implied cache setting of acpi_os_ioremap().

---
 drivers/gpu/drm/gma500/opregion.c |    8 ++++----
 drivers/gpu/drm/gma500/psb_drv.h  |    2 +-
 drivers/gpu/drm/gma500/psb_lid.c  |    8 ++++----
 3 files changed, 9 insertions(+), 9 deletions(-)
drivers/gpu/drm/gma500/opregion.c +4 -4
index ab696ca7eeec..7672ac4d4217 100644
@@ -297,7 +297,7 @@ void psb_intel_opregion_fini(struct drm_device *dev)
 	cancel_work_sync(&opregion->asle_work);
 
 	/* just clear all opregion memory pointers now */
-	iounmap(opregion->header);
+	memunmap(opregion->header);
 	opregion->header = NULL;
 	opregion->acpi = NULL;
 	opregion->swsci = NULL;
@@ -310,8 +310,8 @@ int psb_intel_opregion_setup(struct drm_device *dev)
 	struct drm_psb_private *dev_priv = dev->dev_private;
 	struct psb_intel_opregion *opregion = &dev_priv->opregion;
 	u32 opregion_phy, mboxes;
-	void __iomem *base;
 	int err = 0;
+	void *base;
 
 	pci_read_config_dword(dev->pdev, PCI_ASLS, &opregion_phy);
 	if (opregion_phy == 0) {
@@ -322,7 +322,7 @@ int psb_intel_opregion_setup(struct drm_device *dev)
 	INIT_WORK(&opregion->asle_work, psb_intel_opregion_asle_work);
 
 	DRM_DEBUG("OpRegion detected at 0x%8x\n", opregion_phy);
-	base = acpi_os_ioremap(opregion_phy, 8*1024);
+	base = memremap(opregion_phy, 8*1024, MEMREMAP_WB);
 	if (!base)
 		return -ENOMEM;
 
@@ -351,7 +351,7 @@ int psb_intel_opregion_setup(struct drm_device *dev)
 	return 0;
 
 err_out:
-	iounmap(base);
+	memunmap(base);
 	return err;
 }
 
drivers/gpu/drm/gma500/psb_drv.h +1 -1
index e38057b91865..189f57135d47 100644
@@ -253,7 +253,7 @@ struct psb_intel_opregion {
 	struct opregion_swsci *swsci;
 	struct opregion_asle *asle;
 	void *vbt;
-	u32 __iomem *lid_state;
+	u32 *lid_state;
 	struct work_struct asle_work;
 };
 
drivers/gpu/drm/gma500/psb_lid.c +4 -4
index 1d2ebb5e530f..6b1b9d0741df 100644
@@ -28,14 +28,14 @@ static void psb_lid_timer_func(unsigned long data)
 	struct drm_psb_private * dev_priv = (struct drm_psb_private *)data;
 	struct drm_device *dev = (struct drm_device *)dev_priv->dev;
 	struct timer_list *lid_timer = &dev_priv->lid_timer;
+	u32 *lid_state = dev_priv->opregion.lid_state;
 	unsigned long irq_flags;
-	u32 __iomem *lid_state = dev_priv->opregion.lid_state;
 	u32 pp_status;
 
-	if (readl(lid_state) == dev_priv->lid_last_state)
+	if (*lid_state == dev_priv->lid_last_state)
 		goto lid_timer_schedule;
 
-	if ((readl(lid_state)) & 0x01) {
+	if ((*lid_state) & 0x01) {
 		/*lid state is open*/
 		REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) | POWER_TARGET_ON);
 		do {
@@ -58,7 +58,7 @@ static void psb_lid_timer_func(unsigned long data)
 			pp_status = REG_READ(PP_STATUS);
 		} while ((pp_status & PP_ON) == 0);
 	}
-	dev_priv->lid_last_state =  readl(lid_state);
+	dev_priv->lid_last_state =  *lid_state;
 
 lid_timer_schedule:
 	spin_lock_irqsave(&dev_priv->lid_lock, irq_flags);
#18 lore raw

PATCH v3 9/24 i915: switch from acpi_os_ioremap to memremap

In reply to Dan Williams

i915 expects the OpRegion to be cached (i.e. not __iomem), so explicitly map it with memremap rather than the implied cache setting of acpi_os_ioremap().

---
 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 -
 5 files changed, 52 insertions(+), 58 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +1 -1
index 82bbe3f2a7e1..9228d6048bde 100644
@@ -1831,7 +1831,7 @@ static int i915_opregion(struct seq_file *m, void *unused)
 		goto out;
 
 	if (opregion->header) {
-		memcpy_fromio(data, opregion->header, OPREGION_SIZE);
+		memcpy(data, opregion->header, OPREGION_SIZE);
 		seq_write(m, data, OPREGION_SIZE);
 	}
 
drivers/gpu/drm/i915/i915_drv.h +6 -6
index 5f27290201e0..2efbfd53be51 100644
@@ -403,14 +403,14 @@ struct opregion_swsci;
 struct opregion_asle;
 
 struct intel_opregion {
-	struct opregion_header __iomem *header;
-	struct opregion_acpi __iomem *acpi;
-	struct opregion_swsci __iomem *swsci;
+	struct opregion_header *header;
+	struct opregion_acpi *acpi;
+	struct opregion_swsci *swsci;
 	u32 swsci_gbda_sub_functions;
 	u32 swsci_sbcb_sub_functions;
-	struct opregion_asle __iomem *asle;
-	void __iomem *vbt;
-	u32 __iomem *lid_state;
+	struct opregion_asle *asle;
+	void *vbt;
+	u32 *lid_state;
 	struct work_struct asle_work;
 };
 #define OPREGION_SIZE            (8*1024)
drivers/gpu/drm/i915/intel_bios.c +3 -4
index 198fc3c3291b..3e2dca4f5e6e 100644
@@ -1206,11 +1206,10 @@ static const struct bdb_header *validate_vbt(const void __iomem *_base,
 {
 	/*
 	 * This is the one place where we explicitly discard the address space
-	 * (__iomem) of the BIOS/VBT. (And this will cause a sparse complaint.)
-	 * From now on everything is based on 'base', and treated as regular
-	 * memory.
+	 * (__iomem) of the BIOS/VBT. From now on everything is based on
+	 * 'base', and treated as regular memory.
 	 */
-	const void *base = (const void *) _base;
+	const void *base = (const void __force *) _base;
 	size_t offset = _vbt - _base;
 	const struct vbt_header *vbt = base + offset;
 	const struct bdb_header *bdb;
drivers/gpu/drm/i915/intel_opregion.c +41 -46

279 lines not on this page · raw message

drivers/gpu/drm/i915/intel_panel.c +1 -1
index 55aad2322e10..3985396e46a2 100644
@@ -384,7 +384,7 @@ intel_panel_detect(struct drm_device *dev)
 
 	/* Assume that the BIOS does not lie through the OpRegion... */
 	if (!i915.panel_ignore_lid && dev_priv->opregion.lid_state) {
-		return ioread32(dev_priv->opregion.lid_state) & 0x1 ?
+		return *(dev_priv->opregion.lid_state) & 0x1 ?
 			connector_status_connected :
 			connector_status_disconnected;
 	}

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#19 lore raw

PATCH v3 10/24 acpi: switch from ioremap_cache to memremap

In reply to Dan Williams

In preparation for deprecating ioremap_cache() convert its usage in drivers/acpi and include/acpi/ to memremap. This includes dropping the __iomem annotation throughout ACPI since the memremap can be treated as a normal memory pointer.

Finally, memremap automatically handles requests to map normal memory pages, so this also drops the calls to "should_use_kmap()".

It seems ARM had a local definition of acpi_os_ioremap() to handle RAM addresses, but it can be deleted now that memremap() handles this generically.

---
 arch/arm64/include/asm/acpi.h |    8 -----
 drivers/acpi/apei/einj.c      |    9 +++--
 drivers/acpi/apei/erst.c      |    6 ++--
 drivers/acpi/nvs.c            |    6 ++--
 drivers/acpi/osl.c            |   70 +++++++++++------------------------------
 include/acpi/acpi_io.h        |    6 +---
 6 files changed, 32 insertions(+), 73 deletions(-)
arch/arm64/include/asm/acpi.h +0 -8
index fdccacd8f7bb..f9f3dcd2bffd 100644
@@ -29,14 +29,6 @@
 
 /* Basic configuration for ACPI */
 #ifdef	CONFIG_ACPI
-/* ACPI table mapping after acpi_gbl_permanent_mmap is set */
-static inline void __iomem *acpi_os_ioremap(acpi_physical_address phys,
-					    acpi_size size)
-{
-	return memremap(phys, size, MEMREMAP_WB);
-}
-#define acpi_os_ioremap acpi_os_ioremap
-
 typedef u64 phys_cpuid_t;
 #define PHYS_CPUID_INVALID INVALID_HWID
 
drivers/acpi/apei/einj.c +5 -4
index a095d4f858da..270636220746 100644
@@ -318,7 +318,8 @@ static int __einj_error_trigger(u64 trigger_paddr, u32 type,
 			    sizeof(*trigger_tab) - 1);
 		goto out;
 	}
-	trigger_tab = ioremap_cache(trigger_paddr, sizeof(*trigger_tab));
+	trigger_tab = memremap(trigger_paddr, sizeof(*trigger_tab),
+			MEMREMAP_WB);
 	if (!trigger_tab) {
 		pr_err(EINJ_PFX "Failed to map trigger table!\n");
 		goto out_rel_header;
@@ -346,8 +347,8 @@ static int __einj_error_trigger(u64 trigger_paddr, u32 type,
 		       (unsigned long long)trigger_paddr + table_size - 1);
 		goto out_rel_header;
 	}
-	iounmap(trigger_tab);
-	trigger_tab = ioremap_cache(trigger_paddr, table_size);
+	memunmap(trigger_tab);
+	trigger_tab = memremap(trigger_paddr, table_size, MEMREMAP_WB);
 	if (!trigger_tab) {
 		pr_err(EINJ_PFX "Failed to map trigger table!\n");
 		goto out_rel_entry;
@@ -409,7 +410,7 @@ out_rel_header:
 	release_mem_region(trigger_paddr, sizeof(*trigger_tab));
 out:
 	if (trigger_tab)
-		iounmap(trigger_tab);
+		memunmap(trigger_tab);
 
 	return rc;
 }
drivers/acpi/apei/erst.c +3 -3
index 3670bbab57a3..569237176e18 100644
@@ -77,7 +77,7 @@ static struct acpi_table_erst *erst_tab;
 static struct erst_erange {
 	u64 base;
 	u64 size;
-	void __iomem *vaddr;
+	void *vaddr;
 	u32 attr;
 } erst_erange;
 
@@ -1185,8 +1185,8 @@ static int __init erst_init(void)
 		goto err_unmap_reg;
 	}
 	rc = -ENOMEM;
-	erst_erange.vaddr = ioremap_cache(erst_erange.base,
-					  erst_erange.size);
+	erst_erange.vaddr = memremap(erst_erange.base, erst_erange.size,
+			MEMREMAP_WB);
 	if (!erst_erange.vaddr)
 		goto err_release_erange;
 
drivers/acpi/nvs.c +3 -3
index 85287b8fe3aa..e0e15af93b22 100644
@@ -136,7 +136,7 @@ void suspend_nvs_free(void)
 			entry->data = NULL;
 			if (entry->kaddr) {
 				if (entry->unmap) {
-					iounmap(entry->kaddr);
+					memunmap(entry->kaddr);
 					entry->unmap = false;
 				} else {
 					acpi_os_unmap_iomem(entry->kaddr,
@@ -180,7 +180,7 @@ int suspend_nvs_save(void)
 
 			entry->kaddr = acpi_os_get_iomem(phys, size);
 			if (!entry->kaddr) {
-				entry->kaddr = acpi_os_ioremap(phys, size);
+				entry->kaddr = acpi_os_memremap(phys, size);
 				entry->unmap = !!entry->kaddr;
 			}
 			if (!entry->kaddr) {
@@ -197,7 +197,7 @@ int suspend_nvs_save(void)
  *	suspend_nvs_restore - restore NVS memory regions
  *
  *	This function is going to be called with interrupts disabled, so it
- *	cannot iounmap the virtual addresses used to access the NVS region.
+ *	cannot memunmap the virtual addresses used to access the NVS region.
  */
 void suspend_nvs_restore(void)
 {
drivers/acpi/osl.c +19 -51

174 lines not on this page · raw message

include/acpi/acpi_io.h +2 -4
index dd86c5fc102d..646ce8714109 100644
@@ -5,13 +5,11 @@
 
 #include <asm/acpi.h>
 
-#ifndef acpi_os_ioremap
-static inline void __iomem *acpi_os_ioremap(acpi_physical_address phys,
+static inline void *acpi_os_memremap(acpi_physical_address phys,
 					    acpi_size size)
 {
-       return ioremap_cache(phys, size);
+       return memremap(phys, size, MEMREMAP_WB);
 }
-#endif
 
 void __iomem *__init_refok
 acpi_os_map_iomem(acpi_physical_address phys, acpi_size size);
#20 lore raw

PATCH v3 11/24 toshiba laptop: replace ioremap_cache with ioremap

In reply to Dan Williams

With ioremap_cache being replaced with memremap there is no longer a guarantee that a mapping will silently fall back to an uncached mapping. Explicitly use a vanilla ioremap() for this short lived mapping.

Cc Arnd Bergmann <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Jonathan Buzzard <[email protected]>
---
 drivers/char/toshiba.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/toshiba.c +1 -1
index 014c9d90d297..f5a45d887a37 100644
@@ -430,7 +430,7 @@ static int tosh_probe(void)
 	int i,major,minor,day,year,month,flag;
 	unsigned char signature[7] = { 0x54,0x4f,0x53,0x48,0x49,0x42,0x41 };
 	SMMRegisters regs;
-	void __iomem *bios = ioremap_cache(0xf0000, 0x10000);
+	void __iomem *bios = ioremap(0xf0000, 0x10000);
 
 	if (!bios)
 		return -ENOMEM;
#21 lore raw

PATCH v3 12/24 memconsole: fix __iomem mishandling, switch to memremap

In reply to Dan Williams

The memconsole driver is not using proper accessors for __iomem. Switch to memremap to fix this issue, and this also prepares the driver for the removal of ioremap_cache.

Cc Mike Waychison <[email protected]>
---
 drivers/firmware/google/memconsole.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/firmware/google/memconsole.c +4 -3
index 2f569aaed4c7..fd5041716860 100644
@@ -52,14 +52,15 @@ static ssize_t memconsole_read(struct file *filp, struct kobject *kobp,
 	char *memconsole;
 	ssize_t ret;
 
-	memconsole = ioremap_cache(memconsole_baseaddr, memconsole_length);
+	memconsole = memremap(memconsole_baseaddr, memconsole_length,
+			MEMREMAP_WB);
 	if (!memconsole) {
-		pr_err("memconsole: ioremap_cache failed\n");
+		pr_err("memconsole: memremap failed\n");
 		return -ENOMEM;
 	}
 	ret = memory_read_from_buffer(buf, count, &pos, memconsole,
 				      memconsole_length);
-	iounmap(memconsole);
+	memunmap(memconsole);
 	return ret;
 }
 
#22 lore raw

PATCH v3 13/24 visorbus: switch from ioremap_cache to memremap

In reply to Dan Williams

In preparation for deprecating ioremap_cache() convert its usage in visorbus to memremap.

Cc Benjamin Romer <[email protected]>
Cc David Kershner <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 drivers/staging/unisys/visorbus/visorchannel.c |   16 +++++++++-------
 drivers/staging/unisys/visorbus/visorchipset.c |   17 +++++++++--------
 2 files changed, 18 insertions(+), 15 deletions(-)
drivers/staging/unisys/visorbus/visorchannel.c +9 -7
index 20b63496e9f2..19c4a78a3617 100644
@@ -21,6 +21,7 @@
  */
 
 #include <linux/uuid.h>
+#include <linux/io.h>
 
 #include "version.h"
 #include "visorbus.h"
@@ -36,7 +37,7 @@ static const uuid_le spar_video_guid = SPAR_CONSOLEVIDEO_CHANNEL_PROTOCOL_GUID;
 struct visorchannel {
 	u64 physaddr;
 	ulong nbytes;
-	void __iomem *mapped;
+	void *mapped;
 	bool requested;
 	struct channel_header chan_hdr;
 	uuid_le guid;
@@ -93,7 +94,7 @@ visorchannel_create_guts(u64 physaddr, unsigned long channel_bytes,
 		}
 	}
 
-	channel->mapped = ioremap_cache(physaddr, size);
+	channel->mapped = memremap(physaddr, size, MEMREMAP_WB);
 	if (!channel->mapped) {
 		release_mem_region(physaddr, size);
 		goto cleanup;
@@ -113,7 +114,7 @@ visorchannel_create_guts(u64 physaddr, unsigned long channel_bytes,
 	if (uuid_le_cmp(guid, NULL_UUID_LE) == 0)
 		guid = channel->chan_hdr.chtype;
 
-	iounmap(channel->mapped);
+	memunmap(channel->mapped);
 	if (channel->requested)
 		release_mem_region(channel->physaddr, channel->nbytes);
 	channel->mapped = NULL;
@@ -126,7 +127,8 @@ visorchannel_create_guts(u64 physaddr, unsigned long channel_bytes,
 		}
 	}
 
-	channel->mapped = ioremap_cache(channel->physaddr, channel_bytes);
+	channel->mapped = memremap(channel->physaddr, channel_bytes,
+			MEMREMAP_WB);
 	if (!channel->mapped) {
 		release_mem_region(channel->physaddr, channel_bytes);
 		goto cleanup;
@@ -167,7 +169,7 @@ visorchannel_destroy(struct visorchannel *channel)
 	if (!channel)
 		return;
 	if (channel->mapped) {
-		iounmap(channel->mapped);
+		memunmap(channel->mapped);
 		if (channel->requested)
 			release_mem_region(channel->physaddr, channel->nbytes);
 	}
@@ -241,7 +243,7 @@ visorchannel_read(struct visorchannel *channel, ulong offset,
 	if (offset + nbytes > channel->nbytes)
 		return -EIO;
 
-	memcpy_fromio(local, channel->mapped + offset, nbytes);
+	memcpy(local, channel->mapped + offset, nbytes);
 
 	return 0;
 }
@@ -262,7 +264,7 @@ visorchannel_write(struct visorchannel *channel, ulong offset,
 		memcpy(&channel->chan_hdr + offset, local, copy_size);
 	}
 
-	memcpy_toio(channel->mapped + offset, local, nbytes);
+	memcpy(channel->mapped + offset, local, nbytes);
 
 	return 0;
 }
drivers/staging/unisys/visorbus/visorchipset.c +9 -8
index bb8087e70127..e3c55ccf929b 100644
@@ -119,7 +119,7 @@ static struct visorchannel *controlvm_channel;
 
 /* Manages the request payload in the controlvm channel */
 struct visor_controlvm_payload_info {
-	u8 __iomem *ptr;	/* pointer to base address of payload pool */
+	u8 *ptr;		/* pointer to base address of payload pool */
 	u64 offset;		/* offset from beginning of controlvm
 				 * channel to beginning of payload * pool */
 	u32 bytes;		/* number of bytes in payload pool */
@@ -401,21 +401,22 @@ parser_init_byte_stream(u64 addr, u32 bytes, bool local, bool *retry)
 		p = __va((unsigned long) (addr));
 		memcpy(ctx->data, p, bytes);
 	} else {
-		void __iomem *mapping;
+		void *mapping;
 
 		if (!request_mem_region(addr, bytes, "visorchipset")) {
 			rc = NULL;
 			goto cleanup;
 		}
 
-		mapping = ioremap_cache(addr, bytes);
+		mapping = memremap(addr, bytes, MEMREMAP_WB);
 		if (!mapping) {
 			release_mem_region(addr, bytes);
 			rc = NULL;
 			goto cleanup;
 		}
-		memcpy_fromio(ctx->data, mapping, bytes);
+		memcpy(ctx->data, mapping, bytes);
 		release_mem_region(addr, bytes);
+		memunmap(mapping);
 	}
 
 	ctx->byte_stream = true;
@@ -1327,7 +1328,7 @@ static int
 initialize_controlvm_payload_info(u64 phys_addr, u64 offset, u32 bytes,
 				  struct visor_controlvm_payload_info *info)
 {
-	u8 __iomem *payload = NULL;
+	u8 *payload = NULL;
 	int rc = CONTROLVM_RESP_SUCCESS;
 
 	if (!info) {
@@ -1339,7 +1340,7 @@ initialize_controlvm_payload_info(u64 phys_addr, u64 offset, u32 bytes,
 		rc = -CONTROLVM_RESP_ERROR_PAYLOAD_INVALID;
 		goto cleanup;
 	}
-	payload = ioremap_cache(phys_addr + offset, bytes);
+	payload = memremap(phys_addr + offset, bytes, MEMREMAP_WB);
 	if (!payload) {
 		rc = -CONTROLVM_RESP_ERROR_IOREMAP_FAILED;
 		goto cleanup;
@@ -1352,7 +1353,7 @@ initialize_controlvm_payload_info(u64 phys_addr, u64 offset, u32 bytes,
 cleanup:
 	if (rc < 0) {
 		if (payload) {
-			iounmap(payload);
+			memunmap(payload);
 			payload = NULL;
 		}
 	}
@@ -1363,7 +1364,7 @@ static void
 destroy_controlvm_payload_info(struct visor_controlvm_payload_info *info)
 {
 	if (info->ptr) {
-		iounmap(info->ptr);
+		memunmap(info->ptr);
 		info->ptr = NULL;
 	}
 	memset(info, 0, sizeof(struct visor_controlvm_payload_info));
maintainer Acked-by on v3 13/24
#23 lore raw

Re: [PATCH v3 13/24] visorbus: switch from ioremap_cache to memremap

Quoted 11 lines · Dan Williams

In preparation for deprecating ioremap_cache() convert its usage in visorbus to memremap.

Cc Benjamin Romer <[email protected]>
Cc David Kershner <[email protected]>
---
 drivers/staging/unisys/visorbus/visorchannel.c |   16 +++++++++-------
 drivers/staging/unisys/visorbus/visorchipset.c |   17 +++++++++--------
 2 files changed, 18 insertions(+), 15 deletions(-)
#24 lore raw

PATCH v3 14/24 intel-iommu: switch from ioremap_cache to memremap

In reply to Dan Williams

In preparation for deprecating ioremap_cache() convert its usage in intel-iommu to memremap. This also eliminates the mishandling of the __iomem annotation in the implementation.

Cc David Woodhouse <[email protected]>
Cc Joerg Roedel <[email protected]>
---
 drivers/iommu/intel-iommu.c         |   10 ++++++----
 drivers/iommu/intel_irq_remapping.c |    4 ++--
 2 files changed, 8 insertions(+), 6 deletions(-)
drivers/iommu/intel-iommu.c +6 -4
index 0649b94f5958..5852df8cc50f 100644
@@ -34,6 +34,7 @@
 #include <linux/mempool.h>
 #include <linux/memory.h>
 #include <linux/timer.h>
+#include <linux/io.h>
 #include <linux/iova.h>
 #include <linux/iommu.h>
 #include <linux/intel-iommu.h>
@@ -2874,7 +2875,8 @@ static int copy_context_table(struct intel_iommu *iommu,
 			}
 
 			ret = -ENOMEM;
-			old_ce = ioremap_cache(old_ce_phys, PAGE_SIZE);
+			old_ce = memremap(old_ce_phys, PAGE_SIZE,
+					MEMREMAP_WB);
 			if (!old_ce)
 				goto out;
 
@@ -2922,7 +2924,7 @@ static int copy_context_table(struct intel_iommu *iommu,
 	__iommu_flush_cache(iommu, new_ce, VTD_PAGE_SIZE);
 
 out_unmap:
-	iounmap(old_ce);
+	memunmap(old_ce);
 
 out:
 	return ret;
@@ -2956,7 +2958,7 @@ static int copy_translation_tables(struct intel_iommu *iommu)
 	if (!old_rt_phys)
 		return -EINVAL;
 
-	old_rt = ioremap_cache(old_rt_phys, PAGE_SIZE);
+	old_rt = memremap(old_rt_phys, PAGE_SIZE, MEMREMAP_WB);
 	if (!old_rt)
 		return -ENOMEM;
 
@@ -3005,7 +3007,7 @@ static int copy_translation_tables(struct intel_iommu *iommu)
 	ret = 0;
 
 out_unmap:
-	iounmap(old_rt);
+	memunmap(old_rt);
 
 	return ret;
 }
drivers/iommu/intel_irq_remapping.c +2 -2
index 27cdfa84ec5b..bdc52cc6ed23 100644
@@ -408,7 +408,7 @@ static int iommu_load_old_irte(struct intel_iommu *iommu)
 	size     = INTR_REMAP_TABLE_ENTRIES*sizeof(struct irte);
 
 	/* Map the old IR table */
-	old_ir_table = ioremap_cache(irt_phys, size);
+	old_ir_table = memremap(irt_phys, size, MEMREMAP_WB);
 	if (!old_ir_table)
 		return -ENOMEM;
 
@@ -426,7 +426,7 @@ static int iommu_load_old_irte(struct intel_iommu *iommu)
 			bitmap_set(iommu->ir_table->bitmap, i, 1);
 	}
 
-	iounmap(old_ir_table);
+	memunmap(old_ir_table);
 
 	return 0;
 }
#25 lore raw

PATCH v3 15/24 libnvdimm, pmem: push call to ioremap_cache out of line

In reply to Dan Williams

In preparation for deprecating ioremap_cache() push its usage into arch code where it deleted in a later globabl conversion of ioremap_cache() to arch_memremap().

---
 arch/x86/include/asm/io.h         |    7 +------
 arch/x86/mm/ioremap.c             |    6 ++++++
 tools/testing/nvdimm/Kbuild       |    2 +-
 tools/testing/nvdimm/test/iomap.c |    6 +++---
 4 files changed, 11 insertions(+), 10 deletions(-)
arch/x86/include/asm/io.h +1 -6
index cc9c61bc1abe..8aeb6456188a 100644
@@ -248,12 +248,7 @@ static inline void flush_write_buffers(void)
 #endif
 }
 
-static inline void __pmem *arch_memremap_pmem(resource_size_t offset,
-	unsigned long size)
-{
-	return (void __force __pmem *) ioremap_cache(offset, size);
-}
-
+void __pmem *arch_memremap_pmem(resource_size_t offset, size_t size);
 #endif /* __KERNEL__ */
 
 extern void native_io_delay(void);
arch/x86/mm/ioremap.c +6 -0
index ce53e6cff75c..dcaadc6a125b 100644
@@ -317,6 +317,12 @@ void __iomem *ioremap_cache(resource_size_t phys_addr, unsigned long size)
 }
 EXPORT_SYMBOL(ioremap_cache);
 
+void __pmem *arch_memremap_pmem(resource_size_t offset, size_t size)
+{
+	return (void __force __pmem *) ioremap_cache(offset, size);
+}
+EXPORT_SYMBOL(arch_memremap_pmem);
+
 void __iomem *ioremap_prot(resource_size_t phys_addr, unsigned long size,
 				unsigned long prot_val)
 {
tools/testing/nvdimm/Kbuild +1 -1
index f56914c7929b..de2912ea78e8 100644
@@ -1,7 +1,7 @@
 ldflags-y += --wrap=ioremap_wt
 ldflags-y += --wrap=ioremap_wc
 ldflags-y += --wrap=devm_ioremap_nocache
-ldflags-y += --wrap=ioremap_cache
+ldflags-y += --wrap=arch_memremap_pmem
 ldflags-y += --wrap=ioremap_nocache
 ldflags-y += --wrap=iounmap
 ldflags-y += --wrap=__request_region
tools/testing/nvdimm/test/iomap.c +3 -3
index 64bfaa50831c..f8486f98f860 100644
@@ -80,11 +80,11 @@ void __iomem *__wrap_devm_ioremap_nocache(struct device *dev,
 }
 EXPORT_SYMBOL(__wrap_devm_ioremap_nocache);
 
-void __iomem *__wrap_ioremap_cache(resource_size_t offset, unsigned long size)
+void *__wrap_arch_memremap_pmem(resource_size_t offset, size_t size)
 {
-	return __nfit_test_ioremap(offset, size, ioremap_cache);
+	return __nfit_test_ioremap(offset, size, arch_memremap_pmem);
 }
-EXPORT_SYMBOL(__wrap_ioremap_cache);
+EXPORT_SYMBOL(__wrap_arch_memremap_pmem);
 
 void __iomem *__wrap_ioremap_nocache(resource_size_t offset, unsigned long size)
 {
#26 lore raw

PATCH v3 16/24 pxa2xx-flash: switch from ioremap_cache to memremap

In reply to Dan Williams

In preparation for deprecating ioremap_cache() convert its usage in pxa2xx-flash to memremap.

Cc David Woodhouse <[email protected]>
Cc Brian Norris <[email protected]>
---
 drivers/mtd/maps/pxa2xx-flash.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/maps/pxa2xx-flash.c +2 -2
index 12fa75df5008..19a3074c58a6 100644
@@ -71,8 +71,8 @@ static int pxa2xx_flash_probe(struct platform_device *pdev)
 		       info->map.name);
 		return -ENOMEM;
 	}
-	info->map.cached =
-		ioremap_cache(info->map.phys, info->map.size);
+	info->map.cached = memremap(info->map.phys, info->map.size,
+			MEMREMAP_WB);
 	if (!info->map.cached)
 		printk(KERN_WARNING "Failed to ioremap cached %s\n",
 		       info->map.name);
#27 lore raw

PATCH v3 17/24 sfi: switch from ioremap_cache to memremap

In reply to Dan Williams

In preparation for deprecating ioremap_cache() convert its usage in sfi to memremap. It's a bit awkward that we go and add back a fake __iomem annotation, but this is to keep consistency with early_ioremap() which does not have a 'memremap' flavor.

---
 drivers/sfi/sfi_core.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/sfi/sfi_core.c +2 -2
index 296db7a69c27..d9430b845dfa 100644
@@ -101,7 +101,7 @@ static void __iomem * __ref sfi_map_memory(u64 phys, u32 size)
 		return NULL;
 
 	if (sfi_use_ioremap)
-		return ioremap_cache(phys, size);
+		return (void __iomem *) memremap(phys, size, MEMREMAP_WB);
 	else
 		return early_ioremap(phys, size);
 }
@@ -112,7 +112,7 @@ static void __ref sfi_unmap_memory(void __iomem *virt, u32 size)
 		return;
 
 	if (sfi_use_ioremap)
-		iounmap(virt);
+		memunmap((void __force *) virt);
 	else
 		early_iounmap(virt, size);
 }
#28 lore raw

PATCH v3 18/24 fbdev: switch from ioremap_wt to memremap

In reply to Dan Williams

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

Cc Jean-Christophe Plagniol-Villard <[email protected]>
Cc Tomi Valkeinen <[email protected]>
---
 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(-)
drivers/video/fbdev/amifb.c +3 -2
index 1d702e13aaff..0cde451046d0 100644
@@ -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");
drivers/video/fbdev/atafb.c +3 -2
index d6ce613e12ad..5615e8c31ea2 100644
@@ -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);
drivers/video/fbdev/hpfb.c +3 -3
index 9476d196f510..d08c320b06fc 100644
@@ -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;
#29 lore raw

PATCH v3 19/24 pmem: switch from ioremap_wt to memremap

In reply to Dan Williams

In preparation for deprecating ioremap_wt() convert its usage in the PMEM API to memremap.

---
 include/linux/pmem.h              |    2 +-
 tools/testing/nvdimm/Kbuild       |    4 ++--
 tools/testing/nvdimm/test/iomap.c |   34 +++++++++++++++++++++++++---------
 3 files changed, 28 insertions(+), 12 deletions(-)
include/linux/pmem.h +1 -1
index d2114045a6c4..1bf74c735fa0 100644
@@ -94,7 +94,7 @@ static void default_memcpy_to_pmem(void __pmem *dst, const void *src,
 static void __pmem *default_memremap_pmem(resource_size_t offset,
 		unsigned long size)
 {
-	return (void __pmem __force *)ioremap_wt(offset, size);
+	return (void __pmem *) memremap(offset, size, MEMREMAP_WT);
 }
 
 /**
tools/testing/nvdimm/Kbuild +2 -2
index de2912ea78e8..8032a49f7873 100644
@@ -1,7 +1,7 @@
-ldflags-y += --wrap=ioremap_wt
 ldflags-y += --wrap=ioremap_wc
 ldflags-y += --wrap=devm_ioremap_nocache
-ldflags-y += --wrap=arch_memremap_pmem
+ldflags-y += --wrap=memremap
+ldflags-y += --wrap=memunmap
 ldflags-y += --wrap=ioremap_nocache
 ldflags-y += --wrap=iounmap
 ldflags-y += --wrap=__request_region
tools/testing/nvdimm/test/iomap.c +25 -9
index f8486f98f860..21288f34a5ca 100644
@@ -80,11 +80,20 @@ void __iomem *__wrap_devm_ioremap_nocache(struct device *dev,
 }
 EXPORT_SYMBOL(__wrap_devm_ioremap_nocache);
 
-void *__wrap_arch_memremap_pmem(resource_size_t offset, size_t size)
+void *__wrap_memremap(resource_size_t offset, size_t size,
+		unsigned long flags)
 {
-	return __nfit_test_ioremap(offset, size, arch_memremap_pmem);
+	struct nfit_test_resource *nfit_res;
+
+	rcu_read_lock();
+	nfit_res = get_nfit_res(offset);
+	rcu_read_unlock();
+	if (nfit_res)
+		return (void __iomem *) nfit_res->buf + offset
+			- nfit_res->res->start;
+	return memremap(offset, size, flags);
 }
-EXPORT_SYMBOL(__wrap_arch_memremap_pmem);
+EXPORT_SYMBOL(__wrap_memremap);
 
 void __iomem *__wrap_ioremap_nocache(resource_size_t offset, unsigned long size)
 {
@@ -92,12 +101,6 @@ void __iomem *__wrap_ioremap_nocache(resource_size_t offset, unsigned long size)
 }
 EXPORT_SYMBOL(__wrap_ioremap_nocache);
 
-void __iomem *__wrap_ioremap_wt(resource_size_t offset, unsigned long size)
-{
-	return __nfit_test_ioremap(offset, size, ioremap_wt);
-}
-EXPORT_SYMBOL(__wrap_ioremap_wt);
-
 void __iomem *__wrap_ioremap_wc(resource_size_t offset, unsigned long size)
 {
 	return __nfit_test_ioremap(offset, size, ioremap_wc);
@@ -117,6 +120,19 @@ void __wrap_iounmap(volatile void __iomem *addr)
 }
 EXPORT_SYMBOL(__wrap_iounmap);
 
+void __wrap_memunmap(void *addr)
+{
+	struct nfit_test_resource *nfit_res;
+
+	rcu_read_lock();
+	nfit_res = get_nfit_res((unsigned long) addr);
+	rcu_read_unlock();
+	if (nfit_res)
+		return;
+	return memunmap(addr);
+}
+EXPORT_SYMBOL(__wrap_memunmap);
+
 struct resource *__wrap___request_region(struct resource *parent,
 		resource_size_t start, resource_size_t n, const char *name,
 		int flags)
#30 lore raw

PATCH v3 20/24 arch: kill ioremap_cached()

In reply to Dan Williams

Nothing calls this helper, and now that ioremap_cache() is being deprecated these can also be removed.

---
 arch/arm/mm/mmu.c               |    2 +-
 arch/metag/include/asm/io.h     |    3 ---
 arch/unicore32/include/asm/io.h |    4 +---
 arch/unicore32/mm/ioremap.c     |    8 --------
 4 files changed, 2 insertions(+), 15 deletions(-)
arch/arm/mm/mmu.c +1 -1
index 870838a46d52..3888018d1a36 100644
@@ -259,7 +259,7 @@ static struct mem_type mem_types[] = {
 		.prot_sect	= PROT_SECT_DEVICE,
 		.domain		= DOMAIN_IO,
 	},
-	[MT_DEVICE_CACHED] = {	  /* ioremap_cached */
+	[MT_DEVICE_CACHED] = {	  /* memremap(MEMREMAP_WB) */
 		.prot_pte	= PROT_PTE_DEVICE | L_PTE_MT_DEV_CACHED,
 		.prot_l1	= PMD_TYPE_TABLE,
 		.prot_sect	= PROT_SECT_DEVICE | PMD_SECT_WB,
arch/metag/include/asm/io.h +0 -3
index 9890f21eadbe..5432949e627e 100644
@@ -154,9 +154,6 @@ extern void __iounmap(void __iomem *addr);
 #define ioremap_nocache(offset, size)           \
 	__ioremap((offset), (size), 0)
 
-#define ioremap_cached(offset, size)            \
-	__ioremap((offset), (size), _PAGE_CACHEABLE)
-
 #define ioremap_wc(offset, size)                \
 	__ioremap((offset), (size), _PAGE_WR_COMBINE)
 
arch/unicore32/include/asm/io.h +1 -3
index cb1d8fd2b16b..1eea482b3cb9 100644
@@ -21,10 +21,9 @@
 #include <asm-generic/io.h>
 
 /*
- * __uc32_ioremap and __uc32_ioremap_cached takes CPU physical address.
+ * __uc32_ioremap takes CPU physical address.
  */
 extern void __iomem *__uc32_ioremap(unsigned long, size_t);
-extern void __iomem *__uc32_ioremap_cached(unsigned long, size_t);
 extern void __uc32_iounmap(volatile void __iomem *addr);
 
 /*
@@ -35,7 +34,6 @@ extern void __uc32_iounmap(volatile void __iomem *addr);
  *
  */
 #define ioremap(cookie, size)		__uc32_ioremap(cookie, size)
-#define ioremap_cached(cookie, size)	__uc32_ioremap_cached(cookie, size)
 #define ioremap_nocache(cookie, size)	__uc32_ioremap(cookie, size)
 #define iounmap(cookie)			__uc32_iounmap(cookie)
 
arch/unicore32/mm/ioremap.c +0 -8
index bf012b2b71a9..f9b6d918de6f 100644
@@ -224,14 +224,6 @@ __uc32_ioremap(unsigned long phys_addr, size_t size)
 }
 EXPORT_SYMBOL(__uc32_ioremap);
 
-void __iomem *
-__uc32_ioremap_cached(unsigned long phys_addr, size_t size)
-{
-	return __uc32_ioremap_caller(phys_addr, size, MT_DEVICE_CACHED,
-			__builtin_return_address(0));
-}
-EXPORT_SYMBOL(__uc32_ioremap_cached);
-
 void __uc32_iounmap(volatile void __iomem *io_addr)
 {
 	void *addr = (void *)(PAGE_MASK & (unsigned long)io_addr);
#31 lore raw

PATCH v3 21/24 arch: kill ioremap_fullcache()

In reply to Dan Williams

Nothing calls this helper, and now that ioremap_cache() is being deprecated these can also be removed.

---
 arch/frv/include/asm/io.h        |    5 -----
 arch/m68k/include/asm/io_mm.h    |    6 ------
 arch/m68k/include/asm/io_no.h    |    5 -----
 arch/microblaze/include/asm/io.h |    1 -
 arch/tile/include/asm/io.h       |    1 -
 5 files changed, 18 deletions(-)
arch/frv/include/asm/io.h +0 -5
index a31b63ec4930..15a49a268754 100644
@@ -272,11 +272,6 @@ static inline void __iomem *ioremap_wt(unsigned long physaddr, unsigned long siz
 	return __ioremap(physaddr, size, IOMAP_WRITETHROUGH);
 }
 
-static inline void __iomem *ioremap_fullcache(unsigned long physaddr, unsigned long size)
-{
-	return __ioremap(physaddr, size, IOMAP_FULL_CACHING);
-}
-
 #define ioremap_wc ioremap_nocache
 
 extern void iounmap(void volatile __iomem *addr);
arch/m68k/include/asm/io_mm.h +0 -6
index f55cad529400..910e90770eb2 100644
@@ -473,12 +473,6 @@ static inline void __iomem *ioremap_wt(unsigned long physaddr,
 {
 	return __ioremap(physaddr, size, IOMAP_WRITETHROUGH);
 }
-static inline void __iomem *ioremap_fullcache(unsigned long physaddr,
-				      unsigned long size)
-{
-	return __ioremap(physaddr, size, IOMAP_FULL_CACHING);
-}
-
 static inline void memset_io(volatile void __iomem *addr, unsigned char val, int count)
 {
 	__builtin_memset((void __force *) addr, val, count);
arch/m68k/include/asm/io_no.h +0 -5
index ad7bd40e6742..2690fa99dc56 100644
@@ -159,11 +159,6 @@ static inline void *ioremap_wt(unsigned long physaddr, unsigned long size)
 {
 	return __ioremap(physaddr, size, IOMAP_WRITETHROUGH);
 }
-static inline void *ioremap_fullcache(unsigned long physaddr, unsigned long size)
-{
-	return __ioremap(physaddr, size, IOMAP_FULL_CACHING);
-}
-
 #define	iounmap(addr)	do { } while(0)
 
 /*
arch/microblaze/include/asm/io.h +0 -1
index 39b6315db82e..5e0cbf4e4204 100644
@@ -40,7 +40,6 @@ extern void iounmap(void __iomem *addr);
 
 extern void __iomem *ioremap(phys_addr_t address, unsigned long size);
 #define ioremap_nocache(addr, size)		ioremap((addr), (size))
-#define ioremap_fullcache(addr, size)		ioremap((addr), (size))
 #define ioremap_wc(addr, size)			ioremap((addr), (size))
 #define ioremap_wt(addr, size)			ioremap((addr), (size))
 
arch/tile/include/asm/io.h +0 -1
index dc61de15c1f9..e2867d235170 100644
@@ -55,7 +55,6 @@ extern void iounmap(volatile void __iomem *addr);
 #define ioremap_nocache(physaddr, size)		ioremap(physaddr, size)
 #define ioremap_wc(physaddr, size)		ioremap(physaddr, size)
 #define ioremap_wt(physaddr, size)		ioremap(physaddr, size)
-#define ioremap_fullcache(physaddr, size)	ioremap(physaddr, size)
 
 #define mmiowb()
 
#32 lore raw

PATCH v3 22/24 arch: remove ioremap_cache, replace with arch_memremap

In reply to Dan Williams

Now that all call sites for ioremap_cache() have been converted to memremap(MEMREMAP_CACHE) we can now proceed with removing the implementation in the archs. This amounts to replacing the per-arch ioremap_cache() implementation with arch_memremap.

Cc Arnd Bergmann <[email protected]>
Cc Russell King <[email protected]>
Cc Tony Luck <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
---
 Documentation/x86/pat.txt    |    4 ++--
 arch/arm/Kconfig             |    1 +
 arch/arm/include/asm/io.h    |    5 +----
 arch/arm/mm/ioremap.c        |   18 ++++++++++++++----
 arch/arm/mm/nommu.c          |   11 +++++++----
 arch/arm64/Kconfig           |    1 +
 arch/arm64/include/asm/io.h  |    1 -
 arch/arm64/mm/ioremap.c      |   20 +++++++-------------
 arch/ia64/Kconfig            |    1 +
 arch/ia64/include/asm/io.h   |    6 ------
 arch/ia64/mm/ioremap.c       |   16 ++++++++++++++++
 arch/sh/Kconfig              |    1 +
 arch/sh/include/asm/io.h     |    7 -------
 arch/sh/mm/ioremap.c         |   15 +++++++++++++++
 arch/x86/Kconfig             |    1 +
 arch/x86/include/asm/io.h    |    2 --
 arch/x86/mm/ioremap.c        |   26 +++++++++++++++++++++-----
 arch/xtensa/include/asm/io.h |   11 -----------
 drivers/nvdimm/Kconfig       |    2 +-
 include/linux/io.h           |    2 ++
 kernel/Makefile              |    2 +-
 kernel/memremap.c            |   28 ++++++++++++++++++++--------
 lib/Kconfig                  |    5 ++++-
 23 files changed, 116 insertions(+), 70 deletions(-)
Documentation/x86/pat.txt +2 -2
index 54944c71b819..73d3635f6a3f 100644
@@ -32,14 +32,14 @@ API                    |    RAM   |  ACPI,...  |  Reserved/Holes  |
                        |          |            |                  |
 ioremap                |    --    |    UC-     |       UC-        |
                        |          |            |                  |
-ioremap_cache          |    --    |    WB      |       WB         |
-                       |          |            |                  |
 ioremap_uc             |    --    |    UC      |       UC         |
                        |          |            |                  |
 ioremap_nocache        |    --    |    UC-     |       UC-        |
                        |          |            |                  |
 ioremap_wc             |    --    |    --      |       WC         |
                        |          |            |                  |
+memremap(MEMREMAP_WB)  |    WB    |    WB      |       WB         |
+                       |          |            |                  |
 ioremap_wt             |    --    |    --      |       WT         |
                        |          |            |                  |
 set_memory_uc          |    UC-   |    --      |       --         |
arch/arm/Kconfig +1 -0
index 1c5021002fe4..1d64aae0a226 100644
@@ -3,6 +3,7 @@ config ARM
 	default y
 	select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
 	select ARCH_HAS_ELF_RANDOMIZE
+	select ARCH_HAS_MEMREMAP
 	select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
 	select ARCH_HAVE_CUSTOM_GPIO_H
 	select ARCH_HAS_GCOV_PROFILE_ALL
arch/arm/include/asm/io.h +1 -4
index 485982084fe9..191d0f6eeead 100644
@@ -355,7 +355,7 @@ static inline void memcpy_toio(volatile void __iomem *to, const void *from,
  * Function		Memory type	Cacheability	Cache hint
  * ioremap()		Device		n/a		n/a
  * ioremap_nocache()	Device		n/a		n/a
- * ioremap_cache()	Normal		Writeback	Read allocate
+ * memremap(WB)		Normal		Writeback	Read allocate
  * ioremap_wc()		Normal		Non-cacheable	n/a
  * ioremap_wt()		Normal		Non-cacheable	n/a
  *
@@ -392,9 +392,6 @@ void __iomem *ioremap(resource_size_t res_cookie, size_t size);
 #define ioremap ioremap
 #define ioremap_nocache ioremap
 
-void __iomem *ioremap_cache(resource_size_t res_cookie, size_t size);
-#define ioremap_cache ioremap_cache
-
 void __iomem *ioremap_wc(resource_size_t res_cookie, size_t size);
 #define ioremap_wc ioremap_wc
 #define ioremap_wt ioremap_wc
arch/arm/mm/ioremap.c +14 -4
index 0c81056c1dd7..8b0c7ce3c520 100644
@@ -378,12 +378,22 @@ void __iomem *ioremap(resource_size_t res_cookie, size_t size)
 }
 EXPORT_SYMBOL(ioremap);
 
-void __iomem *ioremap_cache(resource_size_t res_cookie, size_t size)
+void *arch_memremap(resource_size_t res_cookie, size_t size,
+		unsigned long flags)
 {
-	return arch_ioremap_caller(res_cookie, size, MT_DEVICE_CACHED,
-				   __builtin_return_address(0));
+	if ((flags & MEMREMAP_WB) == 0)
+		return NULL;
+
+	return (void __force *) arch_ioremap_caller(res_cookie, size,
+			MT_DEVICE_CACHED, __builtin_return_address(0));
+}
+EXPORT_SYMBOL(arch_memremap);
+
+void arch_memunmap(void *addr)
+{
+	iounmap((volatile void __iomem *) addr);
 }
-EXPORT_SYMBOL(ioremap_cache);
+EXPORT_SYMBOL(arch_memunmap);
 
 void __iomem *ioremap_wc(resource_size_t res_cookie, size_t size)
 {
arch/arm/mm/nommu.c +7 -4
index 1dd10936d68d..84d033501553 100644
@@ -366,12 +366,15 @@ void __iomem *ioremap(resource_size_t res_cookie, size_t size)
 }
 EXPORT_SYMBOL(ioremap);
 
-void __iomem *ioremap_cache(resource_size_t res_cookie, size_t size)
+void *arch_memremap(resource_size_t res_cookie, size_t size, unsigned long flags)
 {
-	return __arm_ioremap_caller(res_cookie, size, MT_DEVICE_CACHED,
-				    __builtin_return_address(0));
+	if ((flags & MEMREMAP_WB) == 0)
+		return NULL;
+
+	return (void __force *) __arm_ioremap_caller(res_cookie, size,
+			MT_DEVICE_CACHED, __builtin_return_address(0));
 }
-EXPORT_SYMBOL(ioremap_cache);
+EXPORT_SYMBOL(arch_memremap);
 
 void __iomem *ioremap_wc(resource_size_t res_cookie, size_t size)
 {
arch/arm64/Kconfig +1 -0
index 318175f62c24..305def28385f 100644
@@ -6,6 +6,7 @@ config ARM64
 	select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
 	select ARCH_HAS_ELF_RANDOMIZE
 	select ARCH_HAS_GCOV_PROFILE_ALL
+	select ARCH_HAS_MEMREMAP
 	select ARCH_HAS_SG_CHAIN
 	select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
 	select ARCH_USE_CMPXCHG_LOCKREF
arch/arm64/include/asm/io.h +0 -1
index 44be1e03ed65..51376353a722 100644
@@ -165,7 +165,6 @@ extern void __memset_io(volatile void __iomem *, int, size_t);
  */
 extern void __iomem *__ioremap(phys_addr_t phys_addr, size_t size, pgprot_t prot);
 extern void __iounmap(volatile void __iomem *addr);
-extern void __iomem *ioremap_cache(phys_addr_t phys_addr, size_t size);
 
 #define ioremap(addr, size)		__ioremap((addr), (size), __pgprot(PROT_DEVICE_nGnRE))
 #define ioremap_nocache(addr, size)	__ioremap((addr), (size), __pgprot(PROT_DEVICE_nGnRE))
arch/arm64/mm/ioremap.c +7 -13
index 01e88c8bcab0..83b9db4672d1 100644
@@ -84,25 +84,19 @@ void __iounmap(volatile void __iomem *io_addr)
 {
 	unsigned long addr = (unsigned long)io_addr & PAGE_MASK;
 
-	/*
-	 * We could get an address outside vmalloc range in case
-	 * of ioremap_cache() reusing a RAM mapping.
-	 */
-	if (VMALLOC_START <= addr && addr < VMALLOC_END)
-		vunmap((void *)addr);
+	vunmap((void *)addr);
 }
 EXPORT_SYMBOL(__iounmap);
 
-void __iomem *ioremap_cache(phys_addr_t phys_addr, size_t size)
+void *arch_memremap(phys_addr_t phys_addr, size_t size, unsigned long flags)
 {
-	/* For normal memory we already have a cacheable mapping. */
-	if (pfn_valid(__phys_to_pfn(phys_addr)))
-		return (void __iomem *)__phys_to_virt(phys_addr);
+	if ((flags & MEMREMAP_WB) == 0)
+		return NULL;
 
-	return __ioremap_caller(phys_addr, size, __pgprot(PROT_NORMAL),
-				__builtin_return_address(0));
+	return (void __force *) __ioremap_caller(phys_addr, size,
+			__pgprot(PROT_NORMAL), __builtin_return_address(0));
 }
-EXPORT_SYMBOL(ioremap_cache);
+EXPORT_SYMBOL(arch_memremap);
 
 /*
  * Must be called after early_fixmap_init
arch/ia64/Kconfig +1 -0
index 42a91a7aa2b0..aa83a5da1c99 100644
@@ -52,6 +52,7 @@ config IA64
 	select HAVE_MOD_ARCH_SPECIFIC
 	select MODULES_USE_ELF_RELA
 	select ARCH_USE_CMPXCHG_LOCKREF
+	select ARCH_HAS_MEMREMAP
 	select HAVE_ARCH_AUDITSYSCALL
 	default y
 	help
arch/ia64/include/asm/io.h +0 -6
index 9041bbe2b7b4..defcd10bbf54 100644
@@ -431,12 +431,6 @@ extern void __iomem * early_ioremap (unsigned long phys_addr, unsigned long size
 #define early_memremap(phys_addr, size)        early_ioremap(phys_addr, size)
 extern void early_iounmap (volatile void __iomem *addr, unsigned long size);
 #define early_memunmap(addr, size)             early_iounmap(addr, size)
-static inline void __iomem * ioremap_cache (unsigned long phys_addr, unsigned long size)
-{
-	return ioremap(phys_addr, size);
-}
-#define ioremap_cache ioremap_cache
-
 
 /*
  * String version of IO memory access ops:
arch/ia64/mm/ioremap.c +16 -0
index 43964cde6214..3236d28ac2d5 100644
@@ -101,6 +101,22 @@ ioremap (unsigned long phys_addr, unsigned long size)
 }
 EXPORT_SYMBOL(ioremap);
 
+/*
+ * Cache mapping-type is determined internal to ioremap and can't be
+ * externally specified
+ */
+void *arch_memremap(resource_size_t offset, size_t size, unsigned long flags)
+{
+	return (void __force *) ioremap(offset, size);
+}
+EXPORT_SYMBOL(arch_memremap);
+
+void arch_memunmap(void *addr)
+{
+	iounmap((volatile void __iomem *) addr);
+}
+EXPORT_SYMBOL(arch_memunmap);
+
 void __iomem *
 ioremap_nocache (unsigned long phys_addr, unsigned long size)
 {
arch/sh/Kconfig +1 -0
index 50057fed819d..78d2bd6531cc 100644
@@ -54,6 +54,7 @@ config SUPERH32
 	def_bool ARCH = "sh"
 	select HAVE_KPROBES
 	select HAVE_KRETPROBES
+	select ARCH_HAS_MEMREMAP
 	select HAVE_IOREMAP_PROT if MMU && !X2TLB
 	select HAVE_FUNCTION_TRACER
 	select HAVE_FTRACE_MCOUNT_RECORD
arch/sh/include/asm/io.h +0 -7
index 6194e20fccca..7511796ce543 100644
@@ -337,13 +337,6 @@ static inline void __iomem *ioremap(phys_addr_t offset, unsigned long size)
 	return __ioremap_mode(offset, size, PAGE_KERNEL_NOCACHE);
 }
 
-static inline void __iomem *
-ioremap_cache(phys_addr_t offset, unsigned long size)
-{
-	return __ioremap_mode(offset, size, PAGE_KERNEL);
-}
-#define ioremap_cache ioremap_cache
-
 #ifdef CONFIG_HAVE_IOREMAP_PROT
 static inline void __iomem *
 ioremap_prot(phys_addr_t offset, unsigned long size, unsigned long flags)
arch/sh/mm/ioremap.c +15 -0
index 0c99ec2e7ed8..e59605a9ed67 100644
@@ -86,6 +86,21 @@ __ioremap_caller(phys_addr_t phys_addr, unsigned long size,
 }
 EXPORT_SYMBOL(__ioremap_caller);
 
+void *arch_memremap(resource_size_t offset, size_t size, unsigned long flags)
+{
+	if ((flags & MEMREMAP_WB) == 0)
+		return NULL;
+
+	return (void __force *) __ioremap_mode(offset, size, PAGE_KERNEL);
+}
+EXPORT_SYMBOL(arch_memremap);
+
+void arch_memunmap(void *addr)
+{
+	iounmap((volatile void __iomem *) addr);
+}
+EXPORT_SYMBOL(arch_memunmap);
+
 /*
  * Simple checks for non-translatable mappings.
  */
arch/x86/Kconfig +1 -0
index b3a1a5d77d92..9c2fb6b896aa 100644
@@ -27,6 +27,7 @@ config X86
 	select ARCH_HAS_ELF_RANDOMIZE
 	select ARCH_HAS_FAST_MULTIPLIER
 	select ARCH_HAS_GCOV_PROFILE_ALL
+	select ARCH_HAS_MEMREMAP
 	select ARCH_HAS_PMEM_API
 	select ARCH_HAS_SG_CHAIN
 	select ARCH_HAVE_NMI_SAFE_CMPXCHG
arch/x86/include/asm/io.h +0 -2
index 8aeb6456188a..349027c2943d 100644
@@ -180,10 +180,8 @@ static inline unsigned int isa_virt_to_bus(volatile void *address)
  */
 extern void __iomem *ioremap_nocache(resource_size_t offset, unsigned long size);
 extern void __iomem *ioremap_uc(resource_size_t offset, unsigned long size);
-extern void __iomem *ioremap_cache(resource_size_t offset, unsigned long size);
 extern void __iomem *ioremap_prot(resource_size_t offset, unsigned long size,
 				unsigned long prot_val);
-
 /*
  * The default ioremap() behavior is non-cached:
  */
arch/x86/mm/ioremap.c +21 -5
index dcaadc6a125b..4516974f3bad 100644
@@ -310,16 +310,26 @@ void __iomem *ioremap_wt(resource_size_t phys_addr, unsigned long size)
 }
 EXPORT_SYMBOL(ioremap_wt);
 
-void __iomem *ioremap_cache(resource_size_t phys_addr, unsigned long size)
+void *arch_memremap(resource_size_t phys_addr, size_t size,
+		unsigned long flags)
 {
-	return __ioremap_caller(phys_addr, size, _PAGE_CACHE_MODE_WB,
-				__builtin_return_address(0));
+	int prot;
+
+	if (flags & MEMREMAP_WB)
+		prot = _PAGE_CACHE_MODE_WB;
+	else if (flags & MEMREMAP_WT)
+		prot = _PAGE_CACHE_MODE_WT;
+	else
+		return NULL;
+
+	return (void __force *) __ioremap_caller(phys_addr, size, prot,
+			__builtin_return_address(0));
 }
-EXPORT_SYMBOL(ioremap_cache);
+EXPORT_SYMBOL(arch_memremap);
 
 void __pmem *arch_memremap_pmem(resource_size_t offset, size_t size)
 {
-	return (void __force __pmem *) ioremap_cache(offset, size);
+	return (void __pmem *) arch_memremap(offset, size, MEMREMAP_WB);
 }
 EXPORT_SYMBOL(arch_memremap_pmem);
 
@@ -381,6 +391,12 @@ void iounmap(volatile void __iomem *addr)
 }
 EXPORT_SYMBOL(iounmap);
 
+void arch_memunmap(void *addr)
+{
+	iounmap((volatile void __iomem *) addr);
+}
+EXPORT_SYMBOL(arch_memunmap);
+
 int __init arch_ioremap_pud_supported(void)
 {
 #ifdef CONFIG_X86_64
arch/xtensa/include/asm/io.h +0 -11
index 867840f5400f..9bfbecc0fc99 100644
@@ -48,17 +48,6 @@ static inline void __iomem *ioremap_nocache(unsigned long offset,
 		BUG();
 }
 
-static inline void __iomem *ioremap_cache(unsigned long offset,
-		unsigned long size)
-{
-	if (offset >= XCHAL_KIO_PADDR
-	    && offset - XCHAL_KIO_PADDR < XCHAL_KIO_SIZE)
-		return (void*)(offset-XCHAL_KIO_PADDR+XCHAL_KIO_CACHED_VADDR);
-	else
-		BUG();
-}
-#define ioremap_cache ioremap_cache
-
 #define ioremap_wc ioremap_nocache
 #define ioremap_wt ioremap_nocache
 
drivers/nvdimm/Kconfig +1 -1
index 72226acb5c0f..1c249926b6d0 100644
@@ -1,5 +1,6 @@
 menuconfig LIBNVDIMM
 	tristate "NVDIMM (Non-Volatile Memory Device) Support"
+	depends on ARCH_HAS_MEMREMAP
 	depends on PHYS_ADDR_T_64BIT
 	depends on BLK_DEV
 	help
@@ -19,7 +20,6 @@ if LIBNVDIMM
 config BLK_DEV_PMEM
 	tristate "PMEM: Persistent memory block device support"
 	default LIBNVDIMM
-	depends on HAS_IOMEM
 	select ND_BTT if BTT
 	help
 	  Memory ranges for PMEM are described by either an NFIT
include/linux/io.h +2 -0
index 3fcf6256c088..e2546f1f7fef 100644
@@ -129,5 +129,7 @@ enum {
 
 void *memremap(resource_size_t offset, size_t size, unsigned long flags);
 void memunmap(void *addr);
+void *arch_memremap(resource_size_t offset, size_t size, unsigned long flags);
+void arch_memunmap(void *addr);
 
 #endif /* _LINUX_IO_H */
kernel/Makefile +1 -1
index 92866d36e376..6d12e8006150 100644
@@ -99,7 +99,7 @@ obj-$(CONFIG_JUMP_LABEL) += jump_label.o
 obj-$(CONFIG_CONTEXT_TRACKING) += context_tracking.o
 obj-$(CONFIG_TORTURE_TEST) += torture.o
 
-obj-$(CONFIG_HAS_IOMEM) += memremap.o
+obj-$(CONFIG_ARCH_HAS_MEMREMAP) += memremap.o
 
 $(obj)/configs.o: $(obj)/config_data.h
 
kernel/memremap.c +20 -8
index 27637f42f30d..d3cee1460354 100644
@@ -14,13 +14,22 @@
 #include <linux/io.h>
 #include <linux/mm.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)
+__weak void *arch_memremap(resource_size_t offset, size_t size,
+		unsigned long flags)
 {
-	return ioremap(offset, size);
+	if (!IS_ENABLED(CONFIG_MMU))
+		return (void *) (unsigned long) offset;
+	WARN_ONCE(1, "%s in %s should only be called in NOMMU configurations\n",
+			__func__, __FILE__);
+	return NULL;
+}
+
+__weak void arch_memunmap(void *addr)
+{
+	WARN_ONCE(IS_ENABLED(CONFIG_MMU),
+		"%s in %s should only be called in NOMMU configurations\n",
+		__func__, __FILE__);
 }
-#endif
 
 /**
  * memremap() - remap an iomem_resource as cacheable memory
@@ -42,6 +51,9 @@ __weak void __iomem *ioremap_cache(resource_size_t offset, unsigned long size)
  * cache or are written through to memory and never exist in a
  * cache-dirty state with respect to program visibility.  Attempts to
  * map "System RAM" with this mapping type will fail.
+ *
+ * Note, that overlapping mappings can be established provided they are
+ * all of the same mapping type.
  */
 void *memremap(resource_size_t offset, size_t size, unsigned long flags)
 {
@@ -66,7 +78,7 @@ void *memremap(resource_size_t offset, size_t size, unsigned long flags)
 		if (is_ram == REGION_INTERSECTS)
 			addr = __va(offset);
 		else
-			addr = ioremap_cache(offset, size);
+			addr = arch_memremap(offset, size, MEMREMAP_WB);
 	}
 
 	/*
@@ -83,7 +95,7 @@ void *memremap(resource_size_t offset, size_t size, unsigned long flags)
 
 	if (!addr && (flags & MEMREMAP_WT)) {
 		flags &= ~MEMREMAP_WT;
-		addr = ioremap_wt(offset, size);
+		addr = arch_memremap(offset, size, MEMREMAP_WT);
 	}
 
 	return addr;
@@ -93,6 +105,6 @@ EXPORT_SYMBOL(memremap);
 void memunmap(void *addr)
 {
 	if (is_vmalloc_addr(addr))
-		iounmap((void __iomem *) addr);
+		arch_memunmap(addr);
 }
 EXPORT_SYMBOL(memunmap);
lib/Kconfig +4 -1
index 3a2ef67db6c7..097b99073924 100644
@@ -526,7 +526,10 @@ source "lib/fonts/Kconfig"
 #
 
 config ARCH_HAS_SG_CHAIN
-	def_bool n
+	bool
+
+config ARCH_HAS_MEMREMAP
+	bool
 
 config ARCH_HAS_PMEM_API
 	bool
#33 lore raw

PATCH v3 23/24 arch: remove ioremap_wt, optionally replace with arch_memremap

In reply to Dan Williams

Now that all call sites for ioremap_wt() have been converted to memremap(MEMREMAP_WT) we can now proceed with removing the implementation in the archs. This amounts to replacing the per-arch ioremap_wt() implementation with arch_memremap in the case where ioremap_wt() was actually providing "writethrough" semantics. Otherwise, ioremap_wt() support that falls back to ioremap() is simply removed.

Cc Arnd Bergmann <[email protected]>
Cc Russell King <[email protected]>
Cc Tony Luck <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
---
 Documentation/x86/pat.txt        |    2 +-
 arch/arc/include/asm/io.h        |    1 -
 arch/arm/include/asm/io.h        |    2 --
 arch/arm64/include/asm/io.h      |    1 -
 arch/avr32/include/asm/io.h      |    1 -
 arch/frv/include/asm/io.h        |    7 -------
 arch/m32r/include/asm/io.h       |    1 -
 arch/m68k/Kconfig                |    1 +
 arch/m68k/include/asm/io_mm.h    |    8 +-------
 arch/m68k/include/asm/io_no.h    |    6 ------
 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      |    3 ---
 arch/microblaze/include/asm/io.h |    1 -
 arch/mn10300/include/asm/io.h    |    1 -
 arch/nios2/include/asm/io.h      |    1 -
 arch/s390/include/asm/io.h       |    1 -
 arch/sparc/include/asm/io_32.h   |    1 -
 arch/sparc/include/asm/io_64.h   |    1 -
 arch/tile/include/asm/io.h       |    1 -
 arch/x86/include/asm/io.h        |    2 --
 arch/x86/mm/ioremap.c            |   17 -----------------
 arch/xtensa/include/asm/io.h     |    1 -
 drivers/video/fbdev/Kconfig      |    2 +-
 include/asm-generic/io.h         |    8 --------
 include/asm-generic/iomap.h      |    4 ----
 27 files changed, 26 insertions(+), 72 deletions(-)
Documentation/x86/pat.txt +1 -1
index 73d3635f6a3f..7e0e43c648f7 100644
@@ -40,7 +40,7 @@ ioremap_wc             |    --    |    --      |       WC         |
                        |          |            |                  |
 memremap(MEMREMAP_WB)  |    WB    |    WB      |       WB         |
                        |          |            |                  |
-ioremap_wt             |    --    |    --      |       WT         |
+memremap(MEMREMAP_WT)  |    --    |    --      |       WT         |
                        |          |            |                  |
 set_memory_uc          |    UC-   |    --      |       --         |
  set_memory_wb         |          |            |                  |
arch/arc/include/asm/io.h +0 -1
index 694ece8a0243..00f97a2f5fa6 100644
@@ -20,7 +20,6 @@ extern void iounmap(const void __iomem *addr);
 
 #define ioremap_nocache(phy, sz)	ioremap(phy, sz)
 #define ioremap_wc(phy, sz)		ioremap(phy, sz)
-#define ioremap_wt(phy, sz)		ioremap(phy, sz)
 
 /* Change struct page to physical address */
 #define page_to_phys(page)		(page_to_pfn(page) << PAGE_SHIFT)
arch/arm/include/asm/io.h +0 -2
index 191d0f6eeead..5616c4f4304d 100644
@@ -357,7 +357,6 @@ static inline void memcpy_toio(volatile void __iomem *to, const void *from,
  * ioremap_nocache()	Device		n/a		n/a
  * memremap(WB)		Normal		Writeback	Read allocate
  * ioremap_wc()		Normal		Non-cacheable	n/a
- * ioremap_wt()		Normal		Non-cacheable	n/a
  *
  * All device mappings have the following properties:
  * - no access speculation
@@ -394,7 +393,6 @@ void __iomem *ioremap(resource_size_t res_cookie, size_t size);
 
 void __iomem *ioremap_wc(resource_size_t res_cookie, size_t size);
 #define ioremap_wc ioremap_wc
-#define ioremap_wt ioremap_wc
 
 void iounmap(volatile void __iomem *iomem_cookie);
 #define iounmap iounmap
arch/arm64/include/asm/io.h +0 -1
index 51376353a722..054fb4def2c9 100644
@@ -169,7 +169,6 @@ extern void __iounmap(volatile void __iomem *addr);
 #define ioremap(addr, size)		__ioremap((addr), (size), __pgprot(PROT_DEVICE_nGnRE))
 #define ioremap_nocache(addr, size)	__ioremap((addr), (size), __pgprot(PROT_DEVICE_nGnRE))
 #define ioremap_wc(addr, size)		__ioremap((addr), (size), __pgprot(PROT_NORMAL_NC))
-#define ioremap_wt(addr, size)		__ioremap((addr), (size), __pgprot(PROT_DEVICE_nGnRE))
 #define iounmap				__iounmap
 
 /*
arch/avr32/include/asm/io.h +0 -1
index e998ff5d8e1a..4f5ec2bb7172 100644
@@ -296,7 +296,6 @@ extern void __iounmap(void __iomem *addr);
 	__iounmap(addr)
 
 #define ioremap_wc ioremap_nocache
-#define ioremap_wt ioremap_nocache
 
 #define cached(addr) P1SEGADDR(addr)
 #define uncached(addr) P2SEGADDR(addr)
arch/frv/include/asm/io.h +0 -7
index 15a49a268754..2177a164cc67 100644
@@ -17,8 +17,6 @@
 
 #ifdef __KERNEL__
 
-#define ARCH_HAS_IOREMAP_WT
-
 #include <linux/types.h>
 #include <asm/virtconvert.h>
 #include <asm/string.h>
@@ -267,11 +265,6 @@ static inline void __iomem *ioremap_nocache(unsigned long physaddr, unsigned lon
 	return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
 }
 
-static inline void __iomem *ioremap_wt(unsigned long physaddr, unsigned long size)
-{
-	return __ioremap(physaddr, size, IOMAP_WRITETHROUGH);
-}
-
 #define ioremap_wc ioremap_nocache
 
 extern void iounmap(void volatile __iomem *addr);
arch/m32r/include/asm/io.h +0 -1
index f8de767ce2bc..d7a034d8c671 100644
@@ -68,7 +68,6 @@ static inline void __iomem *ioremap(unsigned long offset, unsigned long size)
 extern void iounmap(volatile void __iomem *addr);
 #define ioremap_nocache(off,size) ioremap(off,size)
 #define ioremap_wc ioremap_nocache
-#define ioremap_wt ioremap_nocache
 
 /*
  * IO bus memory addresses are also 1:1 with the physical address
arch/m68k/Kconfig +1 -0
index 2dd8f63bfbbb..693d06dc0a40 100644
@@ -9,6 +9,7 @@ config M68K
 	select GENERIC_ATOMIC64
 	select HAVE_UID16
 	select VIRT_TO_BUS
+	select ARCH_HAS_MEMREMAP
 	select ARCH_HAVE_NMI_SAFE_CMPXCHG if RMW_INSNS
 	select GENERIC_CPU_DEVICES
 	select GENERIC_IOMAP
arch/m68k/include/asm/io_mm.h +1 -7
index 910e90770eb2..fce53a1be7e3 100644
@@ -20,8 +20,6 @@
 
 #ifdef __KERNEL__
 
-#define ARCH_HAS_IOREMAP_WT
-
 #include <linux/compiler.h>
 #include <asm/raw_io.h>
 #include <asm/virtconvert.h>
@@ -468,11 +466,7 @@ static inline void __iomem *ioremap_nocache(unsigned long physaddr, unsigned lon
 {
 	return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
 }
-static inline void __iomem *ioremap_wt(unsigned long physaddr,
-					 unsigned long size)
-{
-	return __ioremap(physaddr, size, IOMAP_WRITETHROUGH);
-}
+
 static inline void memset_io(volatile void __iomem *addr, unsigned char val, int count)
 {
 	__builtin_memset((void __force *) addr, val, count);
arch/m68k/include/asm/io_no.h +0 -6
index 2690fa99dc56..b5890e593961 100644
@@ -3,8 +3,6 @@
 
 #ifdef __KERNEL__
 
-#define ARCH_HAS_IOREMAP_WT
-
 #include <asm/virtconvert.h>
 #include <asm-generic/iomap.h>
 
@@ -155,10 +153,6 @@ static inline void *ioremap_nocache(unsigned long physaddr, unsigned long size)
 {
 	return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
 }
-static inline void *ioremap_wt(unsigned long physaddr, unsigned long size)
-{
-	return __ioremap(physaddr, size, IOMAP_WRITETHROUGH);
-}
 #define	iounmap(addr)	do { } while(0)
 
 /*
arch/m68k/include/asm/raw_io.h +0 -1
index 932faa35655b..9f6e5a4e531b 100644
@@ -25,7 +25,6 @@ extern void __iomem *__ioremap(unsigned long physaddr, unsigned long size,
 		       int cacheflag);
 extern void __iounmap(void *addr, unsigned long size);
 
-
 /* ++roman: The assignments to temp. vars avoid that gcc sometimes generates
  * two accesses to memory, which may be undesirable for some devices.
  */
arch/m68k/mm/kmap.c +16 -1
index 6e4955bc542b..519c45865127 100644
@@ -14,12 +14,12 @@
 #include <linux/types.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
+#include <linux/io.h>
 
 #include <asm/setup.h>
 #include <asm/segment.h>
 #include <asm/page.h>
 #include <asm/pgalloc.h>
-#include <asm/io.h>
 
 #undef DEBUG
 
@@ -223,6 +223,21 @@ void __iomem *__ioremap(unsigned long physaddr, unsigned long size, int cachefla
 }
 EXPORT_SYMBOL(__ioremap);
 
+void *arch_memremap(resource_size_t offset, size_t size, unsigned long flags)
+{
+	int mode;
+
+	if (flags & MEMREMAP_WB)
+		mode = IOMAP_FULL_CACHING;
+	else if (flags & MEMREMAP_WT)
+		mode = IOMAP_WRITETHROUGH;
+	else
+		return NULL;
+
+	return (void __force *) __ioremap(offset, size, mode);
+}
+EXPORT_SYMBOL(arch_memremap);
+
 /*
  * Unmap an ioremap()ed region again
  */
arch/m68k/mm/sun3kmap.c +6 -0
index 3dc41158c05e..46af60b7f0c7 100644
@@ -116,6 +116,12 @@ void __iomem *__ioremap(unsigned long phys, unsigned long size, int cache)
 }
 EXPORT_SYMBOL(__ioremap);
 
+void *arch_memremap(resource_size_t offset, size_t size, unsigned long flags)
+{
+	return (void __force *) sun3_ioremap(offset, size, SUN3_PAGE_TYPE_IO);
+}
+EXPORT_SYMBOL(arch_memremap);
+
 void iounmap(void __iomem *addr)
 {
 	vfree((void *)(PAGE_MASK & (unsigned long)addr));
arch/metag/include/asm/io.h +0 -3
index 5432949e627e..482ef3b5f5ba 100644
@@ -157,9 +157,6 @@ extern void __iounmap(void __iomem *addr);
 #define ioremap_wc(offset, size)                \
 	__ioremap((offset), (size), _PAGE_WR_COMBINE)
 
-#define ioremap_wt(offset, size)                \
-	__ioremap((offset), (size), 0)
-
 #define iounmap(addr)                           \
 	__iounmap(addr)
 
arch/microblaze/include/asm/io.h +0 -1
index 5e0cbf4e4204..df7ffb3d9898 100644
@@ -41,7 +41,6 @@ extern void iounmap(void __iomem *addr);
 extern void __iomem *ioremap(phys_addr_t address, unsigned long size);
 #define ioremap_nocache(addr, size)		ioremap((addr), (size))
 #define ioremap_wc(addr, size)			ioremap((addr), (size))
-#define ioremap_wt(addr, size)			ioremap((addr), (size))
 
 #endif /* CONFIG_MMU */
 
arch/mn10300/include/asm/io.h +0 -1
index 07c5b4a3903b..cc4a2ba9e228 100644
@@ -282,7 +282,6 @@ static inline void __iomem *ioremap_nocache(unsigned long offset, unsigned long
 }
 
 #define ioremap_wc ioremap_nocache
-#define ioremap_wt ioremap_nocache
 
 static inline void iounmap(void __iomem *addr)
 {
arch/nios2/include/asm/io.h +0 -1
index c5a62da22cd2..6e24d7cceb0c 100644
@@ -46,7 +46,6 @@ static inline void iounmap(void __iomem *addr)
 }
 
 #define ioremap_wc ioremap_nocache
-#define ioremap_wt ioremap_nocache
 
 /* Pages to physical address... */
 #define page_to_phys(page)	virt_to_phys(page_to_virt(page))
arch/s390/include/asm/io.h +0 -1
index cb5fdf3a78fc..30fd5c84680e 100644
@@ -29,7 +29,6 @@ void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr);
 
 #define ioremap_nocache(addr, size)	ioremap(addr, size)
 #define ioremap_wc			ioremap_nocache
-#define ioremap_wt			ioremap_nocache
 
 static inline void __iomem *ioremap(unsigned long offset, unsigned long size)
 {
arch/sparc/include/asm/io_32.h +0 -1
index 57f26c398dc9..407ac14295f4 100644
@@ -129,7 +129,6 @@ static inline void sbus_memcpy_toio(volatile void __iomem *dst,
 void __iomem *ioremap(unsigned long offset, unsigned long size);
 #define ioremap_nocache(X,Y)	ioremap((X),(Y))
 #define ioremap_wc(X,Y)		ioremap((X),(Y))
-#define ioremap_wt(X,Y)		ioremap((X),(Y))
 void iounmap(volatile void __iomem *addr);
 
 /* Create a virtual mapping cookie for an IO port range */
arch/sparc/include/asm/io_64.h +0 -1
index c32fa3f752c8..50d4840d9aeb 100644
@@ -402,7 +402,6 @@ static inline void __iomem *ioremap(unsigned long offset, unsigned long size)
 
 #define ioremap_nocache(X,Y)		ioremap((X),(Y))
 #define ioremap_wc(X,Y)			ioremap((X),(Y))
-#define ioremap_wt(X,Y)			ioremap((X),(Y))
 
 static inline void iounmap(volatile void __iomem *addr)
 {
arch/tile/include/asm/io.h +0 -1
index e2867d235170..549ca9548928 100644
@@ -54,7 +54,6 @@ extern void iounmap(volatile void __iomem *addr);
 
 #define ioremap_nocache(physaddr, size)		ioremap(physaddr, size)
 #define ioremap_wc(physaddr, size)		ioremap(physaddr, size)
-#define ioremap_wt(physaddr, size)		ioremap(physaddr, size)
 
 #define mmiowb()
 
arch/x86/include/asm/io.h +0 -2
index 349027c2943d..1a9d44ee9ed0 100644
@@ -35,7 +35,6 @@
   */
 
 #define ARCH_HAS_IOREMAP_WC
-#define ARCH_HAS_IOREMAP_WT
 
 #include <linux/string.h>
 #include <linux/compiler.h>
@@ -320,7 +319,6 @@ extern void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr);
 extern int ioremap_change_attr(unsigned long vaddr, unsigned long size,
 				enum page_cache_mode pcm);
 extern void __iomem *ioremap_wc(resource_size_t offset, unsigned long size);
-extern void __iomem *ioremap_wt(resource_size_t offset, unsigned long size);
 
 extern bool is_early_ioremap_ptep(pte_t *ptep);
 
arch/x86/mm/ioremap.c +0 -17
index 4516974f3bad..ffbfcf2e701b 100644
@@ -293,23 +293,6 @@ void __iomem *ioremap_wc(resource_size_t phys_addr, unsigned long size)
 }
 EXPORT_SYMBOL(ioremap_wc);
 
-/**
- * ioremap_wt	-	map memory into CPU space write through
- * @phys_addr:	bus address of the memory
- * @size:	size of the resource to map
- *
- * This version of ioremap ensures that the memory is marked write through.
- * Write through stores data into memory while keeping the cache up-to-date.
- *
- * Must be freed with iounmap.
- */
-void __iomem *ioremap_wt(resource_size_t phys_addr, unsigned long size)
-{
-	return __ioremap_caller(phys_addr, size, _PAGE_CACHE_MODE_WT,
-					__builtin_return_address(0));
-}
-EXPORT_SYMBOL(ioremap_wt);
-
 void *arch_memremap(resource_size_t phys_addr, size_t size,
 		unsigned long flags)
 {
arch/xtensa/include/asm/io.h +0 -1
index 9bfbecc0fc99..aaafd90c70db 100644
@@ -49,7 +49,6 @@ static inline void __iomem *ioremap_nocache(unsigned long offset,
 }
 
 #define ioremap_wc ioremap_nocache
-#define ioremap_wt ioremap_nocache
 
 static inline void __iomem *ioremap(unsigned long offset, unsigned long size)
 {
drivers/video/fbdev/Kconfig +1 -1
index 2d98de535e0f..b76ec47c6810 100644
@@ -699,7 +699,7 @@ config FB_MAC
 
 config FB_HP300
 	bool
-	depends on (FB = y) && DIO
+	depends on (FB = y) && DIO && ARCH_HAS_MEMREMAP
 	select FB_CFB_IMAGEBLIT
 	default y
 
include/asm-generic/io.h +0 -8
index f56094cfdeff..f5abd5540249 100644
@@ -785,14 +785,6 @@ static inline void __iomem *ioremap_wc(phys_addr_t offset, size_t size)
 }
 #endif
 
-#ifndef ioremap_wt
-#define ioremap_wt ioremap_wt
-static inline void __iomem *ioremap_wt(phys_addr_t offset, size_t size)
-{
-	return ioremap_nocache(offset, size);
-}
-#endif
-
 #ifndef iounmap
 #define iounmap iounmap
 
include/asm-generic/iomap.h +0 -4
index d8f8622fa044..1b41011643a5 100644
@@ -66,10 +66,6 @@ extern void ioport_unmap(void __iomem *);
 #define ioremap_wc ioremap_nocache
 #endif
 
-#ifndef ARCH_HAS_IOREMAP_WT
-#define ioremap_wt ioremap_nocache
-#endif
-
 #ifdef CONFIG_PCI
 /* Destroy a virtual mapping cookie for a PCI BAR (memory or IO) */
 struct pci_dev;
#34 lore raw

PATCH v3 24/24 pmem: convert to generic memremap

In reply to Dan Williams

Update memremap_pmem() to query the architecture for the mapping type of the given persistent memory range and then pass those flags to generic memremap(). arch_memremap_pmem_flags() is provided an address range to evaluate in the event an arch has a need for different mapping types by address range. For example the ACPI NFIT carries EFI mapping types in its memory range description table.

---
 arch/x86/include/asm/io.h |    2 +-
 arch/x86/mm/ioremap.c     |   16 ++++++++++------
 include/linux/pmem.h      |   26 +++++++++++++++-----------
 3 files changed, 26 insertions(+), 18 deletions(-)
arch/x86/include/asm/io.h +1 -1
index 1a9d44ee9ed0..26c81b01419c 100644
@@ -245,7 +245,7 @@ static inline void flush_write_buffers(void)
 #endif
 }
 
-void __pmem *arch_memremap_pmem(resource_size_t offset, size_t size);
+unsigned long arch_memremap_pmem_flags(resource_size_t offset, size_t size);
 #endif /* __KERNEL__ */
 
 extern void native_io_delay(void);
arch/x86/mm/ioremap.c +10 -6
index ffbfcf2e701b..5a41e3e4ea1e 100644
@@ -205,6 +205,16 @@ err_free_memtype:
 	return NULL;
 }
 
+unsigned long arch_memremap_pmem_flags(resource_size_t offset, size_t size)
+{
+	/*
+	 * TODO: check the mapping type provided by platform firmware,
+	 * per range.
+	 */
+	return MEMREMAP_WB;
+}
+EXPORT_SYMBOL(arch_memremap_pmem_flags);
+
 /**
  * ioremap_nocache     -   map bus memory into CPU space
  * @phys_addr:    bus address of the memory
@@ -310,12 +320,6 @@ void *arch_memremap(resource_size_t phys_addr, size_t size,
 }
 EXPORT_SYMBOL(arch_memremap);
 
-void __pmem *arch_memremap_pmem(resource_size_t offset, size_t size)
-{
-	return (void __pmem *) arch_memremap(offset, size, MEMREMAP_WB);
-}
-EXPORT_SYMBOL(arch_memremap_pmem);
-
 void __iomem *ioremap_prot(resource_size_t phys_addr, unsigned long size,
 				unsigned long prot_val)
 {
include/linux/pmem.h +15 -11
index 1bf74c735fa0..03f9d73f3e13 100644
@@ -28,10 +28,10 @@ static inline bool __arch_has_wmb_pmem(void)
 	return false;
 }
 
-static inline void __pmem *arch_memremap_pmem(resource_size_t offset,
+static inline unsigned long arch_memremap_pmem_flags(resource_size_t offset,
 		unsigned long size)
 {
-	return NULL;
+	return 0;
 }
 
 static inline void arch_memcpy_to_pmem(void __pmem *dst, const void *src,
@@ -43,8 +43,8 @@ static inline void arch_memcpy_to_pmem(void __pmem *dst, const void *src,
 
 /*
  * Architectures that define ARCH_HAS_PMEM_API must provide
- * implementations for arch_memremap_pmem(), arch_memcpy_to_pmem(),
- * arch_wmb_pmem(), and __arch_has_wmb_pmem().
+ * implementations for arch_memremap_pmem_flags(),
+ * arch_memcpy_to_pmem(), arch_wmb_pmem(), and __arch_has_wmb_pmem().
  */
 
 static inline void memcpy_from_pmem(void *dst, void __pmem const *src, size_t size)
@@ -54,7 +54,7 @@ static inline void memcpy_from_pmem(void *dst, void __pmem const *src, size_t si
 
 static inline void memunmap_pmem(void __pmem *addr)
 {
-	iounmap((void __force __iomem *) addr);
+	memunmap((void __force *) addr);
 }
 
 /**
@@ -85,16 +85,15 @@ static inline bool arch_has_pmem_api(void)
  * default_memremap_pmem + default_memcpy_to_pmem is sufficient for
  * making data durable relative to i/o completion.
  */
-static void default_memcpy_to_pmem(void __pmem *dst, const void *src,
+static inline void default_memcpy_to_pmem(void __pmem *dst, const void *src,
 		size_t size)
 {
 	memcpy((void __force *) dst, src, size);
 }
 
-static void __pmem *default_memremap_pmem(resource_size_t offset,
-		unsigned long size)
+static inline unsigned long default_memremap_pmem_flags(void)
 {
-	return (void __pmem *) memremap(offset, size, MEMREMAP_WT);
+	return MEMREMAP_WT;
 }
 
 /**
@@ -112,9 +111,14 @@ static void __pmem *default_memremap_pmem(resource_size_t offset,
 static inline void __pmem *memremap_pmem(resource_size_t offset,
 		unsigned long size)
 {
+	unsigned long flags;
+
 	if (arch_has_pmem_api())
-		return arch_memremap_pmem(offset, size);
-	return default_memremap_pmem(offset, size);
+		flags = arch_memremap_pmem_flags(offset, size);
+	else
+		flags = default_memremap_pmem_flags();
+
+	return (void __pmem *) memremap(offset, size, flags);
 }
 
 /**
#35 lore raw

Re: [PATCH v3 24/24] pmem: convert to generic memremap

Quoted 35 lines · Dan Williams

Update memremap_pmem() to query the architecture for the mapping type of the given persistent memory range and then pass those flags to generic memremap(). arch_memremap_pmem_flags() is provided an address range to evaluate in the event an arch has a need for different mapping types by address range. For example the ACPI NFIT carries EFI mapping types in its memory range description table.

---
 arch/x86/include/asm/io.h |    2 +-
 arch/x86/mm/ioremap.c     |   16 ++++++++++------
 include/linux/pmem.h      |   26 +++++++++++++++-----------
 3 files changed, 26 insertions(+), 18 deletions(-)
arch/x86/include/asm/io.h +1 -1
index 1a9d44ee9ed0..26c81b01419c 100644
@@ -245,7 +245,7 @@ static inline void flush_write_buffers(void)
 #endif
 }
 
-void __pmem *arch_memremap_pmem(resource_size_t offset, size_t size);
+unsigned long arch_memremap_pmem_flags(resource_size_t offset, size_t size);
 #endif /* __KERNEL__ */
 
 extern void native_io_delay(void);
arch/x86/mm/ioremap.c +0 -0
index ffbfcf2e701b..5a41e3e4ea1e 100644
@@ -205,6 +205,16 @@ err_free_memtype:
 	return NULL;
 }

arch/x86/mm/ioremap.c err_free_memtype: · line 216

Quoted 10 lines
arch/x86/mm/ioremap.c +9 -0
 
+unsigned long arch_memremap_pmem_flags(resource_size_t offset, size_t size)
+{
+	/*
+	 * TODO: check the mapping type provided by platform firmware,
+	 * per range.
+	 */
+	return MEMREMAP_WB;
+}
+EXPORT_SYMBOL(arch_memremap_pmem_flags);

I'm not sure that the architecture code has the right information to be able to tell the caller what the correct mapping is.

I think what you are ultimately looking for is the "Address Range Memory Mapping Attribute" found in the System Physical Address Range Structure of the NFIT, right? (ACPI 6.0, table 5-128) How can we get to that structure from nfit-independent architecture code like arch_memremap_pmem_flags()? It seems like that if we want to make the mapping type dynamic we should get the flags from ND when the SPA range is provided by ND, and provide a reasonable default (WB, it seems) when we are dealing with legacy PMEM? If PMEM had the flag from whatever source, it could then pass it in to memremap_pmem(), and get a mapping of the appropriate caching.

Another option of course is to just ignore the mapping attribute in the NFIT like we've been doing, and just say "we know WB will be good enough", and remove the TODO.

#36 lore raw

Re: [PATCH v3 24/24] pmem: convert to generic memremap

Quoted 37 lines · Ross Zwisler
Quoted 36 lines · Dan Williams

Update memremap_pmem() to query the architecture for the mapping type of the given persistent memory range and then pass those flags to generic memremap(). arch_memremap_pmem_flags() is provided an address range to evaluate in the event an arch has a need for different mapping types by address range. For example the ACPI NFIT carries EFI mapping types in its memory range description table.

---
 arch/x86/include/asm/io.h |    2 +-
 arch/x86/mm/ioremap.c     |   16 ++++++++++------
 include/linux/pmem.h      |   26 +++++++++++++++-----------
 3 files changed, 26 insertions(+), 18 deletions(-)
arch/x86/include/asm/io.h +1 -1
index 1a9d44ee9ed0..26c81b01419c 100644
@@ -245,7 +245,7 @@ static inline void flush_write_buffers(void)
 #endif
 }
 
-void __pmem *arch_memremap_pmem(resource_size_t offset, size_t size);
+unsigned long arch_memremap_pmem_flags(resource_size_t offset, size_t size);
 #endif /* __KERNEL__ */
 
 extern void native_io_delay(void);
arch/x86/mm/ioremap.c +0 -0
index ffbfcf2e701b..5a41e3e4ea1e 100644
@@ -205,6 +205,16 @@ err_free_memtype:
      return NULL;
 }
 
Quoted 13 lines

arch/x86/mm/ioremap.c err_free_memtype: · line 216

Quoted 9 lines
arch/x86/mm/ioremap.c +9 -0
+unsigned long arch_memremap_pmem_flags(resource_size_t offset, size_t size)
+{
+     /*
+      * TODO: check the mapping type provided by platform firmware,
+      * per range.
+      */
+     return MEMREMAP_WB;
+}
+EXPORT_SYMBOL(arch_memremap_pmem_flags);

I'm not sure that the architecture code has the right information to be able to tell the caller what the correct mapping is.

It does in this instance as it has to pick a mapping type that is compatible with memcpy_to_pmem() and wmb_pmem().

Quoted 9 lines

I think what you are ultimately looking for is the "Address Range Memory Mapping Attribute" found in the System Physical Address Range Structure of the NFIT, right? (ACPI 6.0, table 5-128) How can we get to that structure from nfit-independent architecture code like arch_memremap_pmem_flags()? It seems like that if we want to make the mapping type dynamic we should get the flags from ND when the SPA range is provided by ND, and provide a reasonable default (WB, it seems) when we are dealing with legacy PMEM? If PMEM had the flag from whatever source, it could then pass it in to memremap_pmem(), and get a mapping of the appropriate caching.

We can do what ioremap() does and look it up through other means.

Quoted 3 lines

Another option of course is to just ignore the mapping attribute in the NFIT like we've been doing, and just say "we know WB will be good enough", and remove the TODO.

I agree, but there may be a non-zero chance that a platform implementation wants strict adherence. Maybe move the TODO to a dev_dbg() that flags platforms where the NFIT mapping type is not "WB"?

Reviewed-by
#37 lore raw

Re: [PATCH v3 24/24] pmem: convert to generic memremap

Quoted 10 lines · Dan Williams
Quoted 8 lines · Ross Zwisler
Quoted 7 lines · Dan Williams

Update memremap_pmem() to query the architecture for the mapping type of the given persistent memory range and then pass those flags to generic memremap(). arch_memremap_pmem_flags() is provided an address range to evaluate in the event an arch has a need for different mapping types by address range. For example the ACPI NFIT carries EFI mapping types in its memory range description table.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines