Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  *  This file contains the routines setting up the linux page tables.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2008 Michal Simek
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2008 PetaLogix
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *    Copyright (C) 2007 Xilinx, Inc.  All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *  Derived from arch/ppc/mm/pgtable.c:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *    -- paulus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *  Derived from arch/ppc/mm/init.c:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *  Modifications by Paul Mackerras (PowerMac) (paulus@cs.anu.edu.au)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *  and Cort Dougan (PReP) (cort@cs.nmt.edu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *    Copyright (C) 1996 Paul Mackerras
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *  Amiga/APUS changes by Jesper Skov (jskov@cygnus.co.uk).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *  Derived from "arch/i386/mm/init.c"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *    Copyright (C) 1991, 1992, 1993, 1994  Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  *  This file is subject to the terms and conditions of the GNU General
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  *  Public License.  See the file COPYING in the main directory of this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  *  archive for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <linux/mm_types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <linux/pgtable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <asm/pgalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include <asm/mmu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include <asm/sections.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #include <asm/fixmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) unsigned long ioremap_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) unsigned long ioremap_bot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) EXPORT_SYMBOL(ioremap_bot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static void __iomem *__ioremap(phys_addr_t addr, unsigned long size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		unsigned long flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	unsigned long v, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	phys_addr_t p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	 * Choose an address to map it to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	 * Once the vmalloc system is running, we use it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	 * Before then, we use space going down from ioremap_base
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	 * (ioremap_bot records where we're up to).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	p = addr & PAGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	size = PAGE_ALIGN(addr + size) - p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	 * Don't allow anybody to remap normal RAM that we're using.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	 * mem_init() sets high_memory so only do the check after that.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	 * However, allow remap of rootfs: TBD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	if (mem_init_done &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		p >= memory_start && p < virt_to_phys(high_memory) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		!(p >= __virt_to_phys((phys_addr_t)__bss_stop) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		p < __virt_to_phys((phys_addr_t)__bss_stop))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		pr_warn("__ioremap(): phys addr "PTE_FMT" is RAM lr %ps\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 			(unsigned long)p, __builtin_return_address(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	if (size == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	 * Is it already mapped? If the whole area is mapped then we're
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	 * done, otherwise remap it since we want to keep the virt addrs for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	 * each request contiguous.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	 * We make the assumption here that if the bottom and top
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	 * of the range we want are mapped then it's mapped to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	 * same virt address (and this is contiguous).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	 *  -- Cort
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (mem_init_done) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		struct vm_struct *area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		area = get_vm_area(size, VM_IOREMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		if (area == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		v = (unsigned long) area->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		v = (ioremap_bot -= size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	if ((flags & _PAGE_PRESENT) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		flags |= _PAGE_KERNEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	if (flags & _PAGE_NO_CACHE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		flags |= _PAGE_GUARDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	for (i = 0; i < size && err == 0; i += PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		err = map_page(v + i, p + i, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		if (mem_init_done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			vfree((void *)v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	return (void __iomem *) (v + ((unsigned long)addr & ~PAGE_MASK));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) void __iomem *ioremap(phys_addr_t addr, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	return __ioremap(addr, size, _PAGE_NO_CACHE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) EXPORT_SYMBOL(ioremap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) void iounmap(volatile void __iomem *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	if ((__force void *)addr > high_memory &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 					(unsigned long) addr < ioremap_bot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		vfree((void *) (PAGE_MASK & (unsigned long) addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) EXPORT_SYMBOL(iounmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) int map_page(unsigned long va, phys_addr_t pa, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	p4d_t *p4d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	pud_t *pud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	pmd_t *pd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	pte_t *pg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	int err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	/* Use upper 10 bits of VA to index the first level map */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	p4d = p4d_offset(pgd_offset_k(va), va);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	pud = pud_offset(p4d, va);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	pd = pmd_offset(pud, va);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	/* Use middle 10 bits of VA to index the second-level map */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	pg = pte_alloc_kernel(pd, va); /* from powerpc - pgtable.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	/* pg = pte_alloc_kernel(&init_mm, pd, va); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	if (pg != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		set_pte_at(&init_mm, va, pg, pfn_pte(pa >> PAGE_SHIFT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 				__pgprot(flags)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		if (unlikely(mem_init_done))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			_tlbie(va);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)  * Map in all of physical memory starting at CONFIG_KERNEL_START.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) void __init mapin_ram(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	unsigned long v, p, s, f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	v = CONFIG_KERNEL_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	p = memory_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	for (s = 0; s < lowmem_size; s += PAGE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		f = _PAGE_PRESENT | _PAGE_ACCESSED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 				_PAGE_SHARED | _PAGE_HWEXEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		if ((char *) v < _stext || (char *) v >= _etext)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 			f |= _PAGE_WRENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 			/* On the MicroBlaze, no user access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 			   forces R/W kernel access */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 			f |= _PAGE_USER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		map_page(v, p, f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		v += PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		p += PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) /* is x a power of 2? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) #define is_power_of_2(x)	((x) != 0 && (((x) & ((x) - 1)) == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /* Scan the real Linux page tables and return a PTE pointer for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)  * a virtual address in a context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)  * Returns true (1) if PTE was found, zero otherwise.  The pointer to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)  * the PTE pointer is unmodified if PTE is not found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static int get_pteptr(struct mm_struct *mm, unsigned long addr, pte_t **ptep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	pgd_t	*pgd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	p4d_t	*p4d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	pud_t	*pud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	pmd_t	*pmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	pte_t	*pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	int     retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	pgd = pgd_offset(mm, addr & PAGE_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (pgd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		p4d = p4d_offset(pgd, addr & PAGE_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		pud = pud_offset(p4d, addr & PAGE_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		pmd = pmd_offset(pud, addr & PAGE_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		if (pmd_present(*pmd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			pte = pte_offset_kernel(pmd, addr & PAGE_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			if (pte) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 				retval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 				*ptep = pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) /* Find physical address for this virtual address.  Normally used by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)  * I/O functions, but anyone can call it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) unsigned long iopa(unsigned long addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	unsigned long pa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	pte_t *pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	struct mm_struct *mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	/* Allow mapping of user addresses (within the thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	 * for DMA if necessary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	if (addr < TASK_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		mm = current->mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		mm = &init_mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	pa = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	if (get_pteptr(mm, addr, &pte))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		pa = (pte_val(*pte) & PAGE_MASK) | (addr & ~PAGE_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	return pa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) __ref pte_t *pte_alloc_one_kernel(struct mm_struct *mm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	pte_t *pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	if (mem_init_done) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		pte = (pte_t *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		pte = (pte_t *)early_get_page();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		if (pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 			clear_page(pte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	return pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	unsigned long address = __fix_to_virt(idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	if (idx >= __end_of_fixed_addresses)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	map_page(address, phys, pgprot_val(flags));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }