~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/openrisc/mm/ioremap.c

Version: ~ [ linux-5.13-rc1 ] ~ [ linux-5.12.2 ] ~ [ linux-5.11.19 ] ~ [ linux-5.10.35 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.117 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.190 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.232 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.268 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.268 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * OpenRISC ioremap.c
  3  *
  4  * Linux architectural port borrowing liberally from similar works of
  5  * others.  All original copyrights apply as per the original source
  6  * declaration.
  7  *
  8  * Modifications for the OpenRISC architecture:
  9  * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>
 10  * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
 11  *
 12  *      This program is free software; you can redistribute it and/or
 13  *      modify it under the terms of the GNU General Public License
 14  *      as published by the Free Software Foundation; either version
 15  *      2 of the License, or (at your option) any later version.
 16  */
 17 
 18 #include <linux/vmalloc.h>
 19 #include <linux/io.h>
 20 #include <asm/pgalloc.h>
 21 #include <asm/kmap_types.h>
 22 #include <asm/fixmap.h>
 23 #include <asm/bug.h>
 24 #include <asm/pgtable.h>
 25 #include <linux/sched.h>
 26 #include <asm/tlbflush.h>
 27 
 28 extern int mem_init_done;
 29 
 30 static unsigned int fixmaps_used __initdata;
 31 
 32 /*
 33  * Remap an arbitrary physical address space into the kernel virtual
 34  * address space. Needed when the kernel wants to access high addresses
 35  * directly.
 36  *
 37  * NOTE! We need to allow non-page-aligned mappings too: we will obviously
 38  * have to convert them into an offset in a page-aligned mapping, but the
 39  * caller shouldn't need to know that small detail.
 40  */
 41 void __iomem *__init_refok
 42 __ioremap(phys_addr_t addr, unsigned long size, pgprot_t prot)
 43 {
 44         phys_addr_t p;
 45         unsigned long v;
 46         unsigned long offset, last_addr;
 47         struct vm_struct *area = NULL;
 48 
 49         /* Don't allow wraparound or zero size */
 50         last_addr = addr + size - 1;
 51         if (!size || last_addr < addr)
 52                 return NULL;
 53 
 54         /*
 55          * Mappings have to be page-aligned
 56          */
 57         offset = addr & ~PAGE_MASK;
 58         p = addr & PAGE_MASK;
 59         size = PAGE_ALIGN(last_addr + 1) - p;
 60 
 61         if (likely(mem_init_done)) {
 62                 area = get_vm_area(size, VM_IOREMAP);
 63                 if (!area)
 64                         return NULL;
 65                 v = (unsigned long)area->addr;
 66         } else {
 67                 if ((fixmaps_used + (size >> PAGE_SHIFT)) > FIX_N_IOREMAPS)
 68                         return NULL;
 69                 v = fix_to_virt(FIX_IOREMAP_BEGIN + fixmaps_used);
 70                 fixmaps_used += (size >> PAGE_SHIFT);
 71         }
 72 
 73         if (ioremap_page_range(v, v + size, p, prot)) {
 74                 if (likely(mem_init_done))
 75                         vfree(area->addr);
 76                 else
 77                         fixmaps_used -= (size >> PAGE_SHIFT);
 78                 return NULL;
 79         }
 80 
 81         return (void __iomem *)(offset + (char *)v);
 82 }
 83 
 84 void iounmap(void *addr)
 85 {
 86         /* If the page is from the fixmap pool then we just clear out
 87          * the fixmap mapping.
 88          */
 89         if (unlikely((unsigned long)addr > FIXADDR_START)) {
 90                 /* This is a bit broken... we don't really know
 91                  * how big the area is so it's difficult to know
 92                  * how many fixed pages to invalidate...
 93                  * just flush tlb and hope for the best...
 94                  * consider this a FIXME
 95                  *
 96                  * Really we should be clearing out one or more page
 97                  * table entries for these virtual addresses so that
 98                  * future references cause a page fault... for now, we
 99                  * rely on two things:
100                  *   i)  this code never gets called on known boards
101                  *   ii) invalid accesses to the freed areas aren't made
102                  */
103                 flush_tlb_all();
104                 return;
105         }
106 
107         return vfree((void *)(PAGE_MASK & (unsigned long)addr));
108 }
109 
110 /**
111  * OK, this one's a bit tricky... ioremap can get called before memory is
112  * initialized (early serial console does this) and will want to alloc a page
113  * for its mapping.  No userspace pages will ever get allocated before memory
114  * is initialized so this applies only to kernel pages.  In the event that
115  * this is called before memory is initialized we allocate the page using
116  * the memblock infrastructure.
117  */
118 
119 pte_t __init_refok *pte_alloc_one_kernel(struct mm_struct *mm,
120                                          unsigned long address)
121 {
122         pte_t *pte;
123 
124         if (likely(mem_init_done)) {
125                 pte = (pte_t *) __get_free_page(GFP_KERNEL | __GFP_REPEAT);
126         } else {
127                 pte = (pte_t *) alloc_bootmem_low_pages(PAGE_SIZE);
128 #if 0
129                 /* FIXME: use memblock... */
130                 pte = (pte_t *) __va(memblock_alloc(PAGE_SIZE, PAGE_SIZE));
131 #endif
132         }
133 
134         if (pte)
135                 clear_page(pte);
136         return pte;
137 }
138 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp