Re: [PATCH 05/17] powerpc: move io mapping functions into ioremap.c

2018-05-16 Thread Christophe LEROY



Le 11/05/2018 à 08:01, Michael Ellerman a écrit :

Christophe Leroy  writes:



[...]


+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 


I needed:

+#include 


Oops, yes it was added in the following patch. Ok I move it one patch back.

Thanks
Christophe



To fix:

../arch/powerpc/mm/ioremap.c: In function ‘ioremap_wc’:
../arch/powerpc/mm/ioremap.c:290:6: error: ‘ppc_md’ undeclared (first use in 
this function)
   if (ppc_md.ioremap)
   ^~

cheers



Re: [PATCH 05/17] powerpc: move io mapping functions into ioremap.c

2018-05-11 Thread Michael Ellerman
Christophe Leroy  writes:

> diff --git a/arch/powerpc/mm/ioremap.c b/arch/powerpc/mm/ioremap.c
> new file mode 100644
> index ..5d2645193568
> --- /dev/null
> +++ b/arch/powerpc/mm/ioremap.c
> @@ -0,0 +1,350 @@
> +/*
> + * This file contains the routines for mapping IO areas
> + *
> + *  Derived from arch/powerpc/mm/pgtable_32.c and
> + *  arch/powerpc/mm/pgtable_64.c
> + *
> + * SPDX-License-Identifier: GPL-2.0

This goes at the top of the file as:

// SPDX-License-Identifier: GPL-2.0

See:

  
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/license-rules.rst?#n56

> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 

I needed:

+#include 

To fix:

../arch/powerpc/mm/ioremap.c: In function ‘ioremap_wc’:
../arch/powerpc/mm/ioremap.c:290:6: error: ‘ppc_md’ undeclared (first use in 
this function)
  if (ppc_md.ioremap)
  ^~

cheers


[PATCH 05/17] powerpc: move io mapping functions into ioremap.c

2018-05-04 Thread Christophe Leroy
This patch is the first of a serie that intends to make
io mappings common to PPC32 and PPC64.

It moves ioremap/unmap fonctions into a new file called ioremap.c with
no other modification to the functions.
For the time being, the PPC32 and PPC64 parts get enclosed into #ifdef.
Following patches will aim at making those functions as common as
possible between PPC32 and PPC64.

This patch also moves EXPORT_SYMBOL at the end of each function

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/mm/Makefile |   2 +-
 arch/powerpc/mm/ioremap.c| 350 +++
 arch/powerpc/mm/pgtable_32.c | 139 -
 arch/powerpc/mm/pgtable_64.c | 177 --
 4 files changed, 351 insertions(+), 317 deletions(-)
 create mode 100644 arch/powerpc/mm/ioremap.c

diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile
index f06f3577d8d1..22d54c1d90e1 100644
--- a/arch/powerpc/mm/Makefile
+++ b/arch/powerpc/mm/Makefile
@@ -9,7 +9,7 @@ ccflags-$(CONFIG_PPC64) := $(NO_MINIMAL_TOC)
 
 obj-y  := fault.o mem.o pgtable.o mmap.o \
   init_$(BITS).o pgtable_$(BITS).o \
-  init-common.o mmu_context.o drmem.o
+  init-common.o mmu_context.o drmem.o ioremap.o
 obj-$(CONFIG_PPC_MMU_NOHASH)   += mmu_context_nohash.o tlb_nohash.o \
   tlb_nohash_low.o
 obj-$(CONFIG_PPC_BOOK3E)   += tlb_low_$(BITS)e.o
diff --git a/arch/powerpc/mm/ioremap.c b/arch/powerpc/mm/ioremap.c
new file mode 100644
index ..5d2645193568
--- /dev/null
+++ b/arch/powerpc/mm/ioremap.c
@@ -0,0 +1,350 @@
+/*
+ * This file contains the routines for mapping IO areas
+ *
+ *  Derived from arch/powerpc/mm/pgtable_32.c and
+ *  arch/powerpc/mm/pgtable_64.c
+ *
+ * SPDX-License-Identifier: GPL-2.0
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "mmu_decl.h"
+
+#ifdef CONFIG_PPC32
+
+unsigned long ioremap_bot;
+EXPORT_SYMBOL(ioremap_bot);/* aka VMALLOC_END */
+
+void __iomem *
+ioremap(phys_addr_t addr, unsigned long size)
+{
+   return __ioremap_caller(addr, size, _PAGE_NO_CACHE | _PAGE_GUARDED,
+   __builtin_return_address(0));
+}
+EXPORT_SYMBOL(ioremap);
+
+void __iomem *
+ioremap_wc(phys_addr_t addr, unsigned long size)
+{
+   return __ioremap_caller(addr, size, _PAGE_NO_CACHE,
+   __builtin_return_address(0));
+}
+EXPORT_SYMBOL(ioremap_wc);
+
+void __iomem *
+ioremap_prot(phys_addr_t addr, unsigned long size, unsigned long flags)
+{
+   /* writeable implies dirty for kernel addresses */
+   if ((flags & (_PAGE_RW | _PAGE_RO)) != _PAGE_RO)
+   flags |= _PAGE_DIRTY | _PAGE_HWWRITE;
+
+   /* we don't want to let _PAGE_USER and _PAGE_EXEC leak out */
+   flags &= ~(_PAGE_USER | _PAGE_EXEC);
+   flags |= _PAGE_PRIVILEGED;
+
+   return __ioremap_caller(addr, size, flags, __builtin_return_address(0));
+}
+EXPORT_SYMBOL(ioremap_prot);
+
+void __iomem *
+__ioremap(phys_addr_t addr, unsigned long size, unsigned long flags)
+{
+   return __ioremap_caller(addr, size, flags, __builtin_return_address(0));
+}
+EXPORT_SYMBOL(__ioremap);
+
+void __iomem *
+__ioremap_caller(phys_addr_t addr, unsigned long size, unsigned long flags,
+void *caller)
+{
+   unsigned long v, i;
+   phys_addr_t p;
+   int err;
+
+   /* Make sure we have the base flags */
+   if ((flags & _PAGE_PRESENT) == 0)
+   flags |= pgprot_val(PAGE_KERNEL);
+
+   /* Non-cacheable page cannot be coherent */
+   if (flags & _PAGE_NO_CACHE)
+   flags &= ~_PAGE_COHERENT;
+
+   /*
+* Choose an address to map it to.
+* Once the vmalloc system is running, we use it.
+* Before then, we use space going down from IOREMAP_TOP
+* (ioremap_bot records where we're up to).
+*/
+   p = addr & PAGE_MASK;
+   size = PAGE_ALIGN(addr + size) - p;
+
+   /*
+* If the address lies within the first 16 MB, assume it's in ISA
+* memory space
+*/
+   if (p < 16*1024*1024)
+   p += _ISA_MEM_BASE;
+
+#ifndef CONFIG_CRASH_DUMP
+   /*
+* Don't allow anybody to remap normal RAM that we're using.
+* mem_init() sets high_memory so only do the check after that.
+*/
+   if (slab_is_available() && (p < virt_to_phys(high_memory)) &&
+   page_is_ram(__phys_to_pfn(p))) {
+   printk("__ioremap(): phys addr 0x%llx is RAM lr %ps\n",
+  (unsigned long long)p, __builtin_return_address(0));
+   return NULL;
+   }
+#endif
+
+   if (size == 0)
+   return NULL;
+
+   /*
+* Is it already mapped?  Perhaps