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

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

Version: ~ [ linux-5.19-rc3 ] ~ [ linux-5.18.5 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.48 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.123 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.199 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.248 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.284 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.319 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.302 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ 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.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Based on arch/arm/mm/ioremap.c
  3  *
  4  * (C) Copyright 1995 1996 Linus Torvalds
  5  * Hacked for ARM by Phil Blundell <philb@gnu.org>
  6  * Hacked to allow all architectures to build, and various cleanups
  7  * by Russell King
  8  * Copyright (C) 2012 ARM Ltd.
  9  *
 10  * This program is free software; you can redistribute it and/or modify
 11  * it under the terms of the GNU General Public License version 2 as
 12  * published by the Free Software Foundation.
 13  *
 14  * This program is distributed in the hope that it will be useful,
 15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 17  * GNU General Public License for more details.
 18  *
 19  * You should have received a copy of the GNU General Public License
 20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 21  */
 22 
 23 #include <linux/export.h>
 24 #include <linux/mm.h>
 25 #include <linux/vmalloc.h>
 26 #include <linux/io.h>
 27 
 28 #include <asm/fixmap.h>
 29 #include <asm/tlbflush.h>
 30 #include <asm/pgalloc.h>
 31 
 32 static void __iomem *__ioremap_caller(phys_addr_t phys_addr, size_t size,
 33                                       pgprot_t prot, void *caller)
 34 {
 35         unsigned long last_addr;
 36         unsigned long offset = phys_addr & ~PAGE_MASK;
 37         int err;
 38         unsigned long addr;
 39         struct vm_struct *area;
 40 
 41         /*
 42          * Page align the mapping address and size, taking account of any
 43          * offset.
 44          */
 45         phys_addr &= PAGE_MASK;
 46         size = PAGE_ALIGN(size + offset);
 47 
 48         /*
 49          * Don't allow wraparound, zero size or outside PHYS_MASK.
 50          */
 51         last_addr = phys_addr + size - 1;
 52         if (!size || last_addr < phys_addr || (last_addr & ~PHYS_MASK))
 53                 return NULL;
 54 
 55         /*
 56          * Don't allow RAM to be mapped.
 57          */
 58         if (WARN_ON(pfn_valid(__phys_to_pfn(phys_addr))))
 59                 return NULL;
 60 
 61         area = get_vm_area_caller(size, VM_IOREMAP, caller);
 62         if (!area)
 63                 return NULL;
 64         addr = (unsigned long)area->addr;
 65         area->phys_addr = phys_addr;
 66 
 67         err = ioremap_page_range(addr, addr + size, phys_addr, prot);
 68         if (err) {
 69                 vunmap((void *)addr);
 70                 return NULL;
 71         }
 72 
 73         return (void __iomem *)(offset + addr);
 74 }
 75 
 76 void __iomem *__ioremap(phys_addr_t phys_addr, size_t size, pgprot_t prot)
 77 {
 78         return __ioremap_caller(phys_addr, size, prot,
 79                                 __builtin_return_address(0));
 80 }
 81 EXPORT_SYMBOL(__ioremap);
 82 
 83 void __iounmap(volatile void __iomem *io_addr)
 84 {
 85         unsigned long addr = (unsigned long)io_addr & PAGE_MASK;
 86 
 87         /*
 88          * We could get an address outside vmalloc range in case
 89          * of ioremap_cache() reusing a RAM mapping.
 90          */
 91         if (VMALLOC_START <= addr && addr < VMALLOC_END)
 92                 vunmap((void *)addr);
 93 }
 94 EXPORT_SYMBOL(__iounmap);
 95 
 96 void __iomem *ioremap_cache(phys_addr_t phys_addr, size_t size)
 97 {
 98         /* For normal memory we already have a cacheable mapping. */
 99         if (pfn_valid(__phys_to_pfn(phys_addr)))
100                 return (void __iomem *)__phys_to_virt(phys_addr);
101 
102         return __ioremap_caller(phys_addr, size, __pgprot(PROT_NORMAL),
103                                 __builtin_return_address(0));
104 }
105 EXPORT_SYMBOL(ioremap_cache);
106 
107 /*
108  * Must be called after early_fixmap_init
109  */
110 void __init early_ioremap_init(void)
111 {
112         early_ioremap_setup();
113 }
114 

~ [ 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