1 /* 2 * linux/include/asm-arm/memory.h 3 * 4 * Copyright (C) 2000-2002 Russell King 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 2 as 8 * published by the Free Software Foundation. 9 * 10 * Note: this file should not be included by non-asm/.h files 11 */ 12 #ifndef __ASM_ARM_MEMORY_H 13 #define __ASM_ARM_MEMORY_H 14 15 #include <linux/config.h> 16 #include <asm/arch/memory.h> 17 18 /* 19 * PFNs are used to describe any physical page; this means 20 * PFN 0 == physical address 0. 21 * 22 * This is the PFN of the first RAM page in the kernel 23 * direct-mapped view. We assume this is the first page 24 * of RAM in the mem_map as well. 25 */ 26 #define PHYS_PFN_OFFSET (PHYS_OFFSET >> PAGE_SHIFT) 27 28 /* 29 * These are *only* valid on the kernel direct mapped RAM memory. 30 */ virt_to_phys(void * x)31static inline unsigned long virt_to_phys(void *x) 32 { 33 return __virt_to_phys((unsigned long)(x)); 34 } 35 phys_to_virt(unsigned long x)36static inline void *phys_to_virt(unsigned long x) 37 { 38 return (void *)(__phys_to_virt((unsigned long)(x))); 39 } 40 41 #define __pa(x) __virt_to_phys((unsigned long)(x)) 42 #define __va(x) ((void *)__phys_to_virt((unsigned long)(x))) 43 44 /* 45 * Virtual <-> DMA view memory address translations 46 * Again, these are *only* valid on the kernel direct mapped RAM 47 * memory. Use of these is *depreciated*. 48 */ 49 #define virt_to_bus(x) (__virt_to_bus((unsigned long)(x))) 50 #define bus_to_virt(x) ((void *)(__bus_to_virt((unsigned long)(x)))) 51 52 /* 53 * Conversion between a struct page and a physical address. 54 * 55 * Note: when converting an unknown physical address to a 56 * struct page, the resulting pointer must be validated 57 * using VALID_PAGE(). It must return an invalid struct page 58 * for any physical address not corresponding to a system 59 * RAM address. 60 * 61 * page_to_pfn(page) convert a struct page * to a PFN number 62 * pfn_to_page(pfn) convert a _valid_ PFN number to struct page * 63 * pfn_valid(pfn) indicates whether a PFN number is valid 64 * 65 * virt_to_page(k) convert a _valid_ virtual address to struct page * 66 * virt_addr_valid(k) indicates whether a virtual address is valid 67 */ 68 #ifndef CONFIG_DISCONTIGMEM 69 70 #define page_to_pfn(page) (((page) - mem_map) + PHYS_PFN_OFFSET) 71 #define pfn_to_page(pfn) ((mem_map + (pfn)) - PHYS_PFN_OFFSET) 72 #define pfn_valid(pfn) ((pfn) >= PHYS_PFN_OFFSET && (pfn) < (PHYS_PFN_OFFSET + max_mapnr)) 73 74 #define virt_to_page(kaddr) (pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)) 75 #define virt_addr_valid(kaddr) ((kaddr) >= PAGE_OFFSET && (kaddr) < (unsigned long)high_memory) 76 77 #define PHYS_TO_NID(addr) (0) 78 79 #define VALID_PAGE(page) ((page - mem_map) < max_mapnr) 80 81 #else 82 83 /* 84 * This is more complex. We have a set of mem_map arrays spread 85 * around in memory. 86 */ 87 #define page_to_pfn(page) \ 88 (((page) - page_zone(page)->zone_mem_map) \ 89 + (page_zone(page)->zone_start_paddr >> PAGE_SHIFT)) 90 91 #define pfn_to_page(pfn) \ 92 (PFN_TO_MAPBASE(pfn) + LOCAL_MAP_NR((pfn) << PAGE_SHIFT)) 93 94 #define pfn_valid(pfn) \ 95 ({ \ 96 unsigned int node = PFN_TO_NID(pfn); \ 97 struct pglist_data *nd = NODE_DATA(node); \ 98 ((node < NR_NODES) && \ 99 ((pfn - (nd->node_start_paddr >> PAGE_SHIFT)) < nd->node_size));\ 100 }) 101 102 #define virt_to_page(kaddr) \ 103 (ADDR_TO_MAPBASE(kaddr) + LOCAL_MAP_NR(kaddr)) 104 105 #define virt_addr_valid(kaddr) (KVADDR_TO_NID(kaddr) < NR_NODES) 106 107 /* 108 * Common discontigmem stuff. 109 * PHYS_TO_NID is used by the ARM kernel/setup.c 110 */ 111 #define PHYS_TO_NID(addr) PFN_TO_NID((addr) >> PAGE_SHIFT) 112 113 /* 114 * 2.4 compatibility 115 * 116 * VALID_PAGE returns a non-zero value if given page pointer is valid. 117 * This assumes all node's mem_maps are stored within the node they 118 * refer to. This is actually inherently buggy. 119 */ 120 #define VALID_PAGE(page) \ 121 ({ unsigned int node = KVADDR_TO_NID(page); \ 122 ((node < NR_NODES) && \ 123 ((unsigned)((page) - NODE_MEM_MAP(node)) < NODE_DATA(node)->node_size)); \ 124 }) 125 126 #endif 127 128 /* 129 * For BIO. "will die". Kill me when bio_to_phys() and bvec_to_phys() die. 130 */ 131 #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT) 132 133 /* 134 * We should really eliminate virt_to_bus() here - it's depreciated. 135 */ 136 #define page_to_bus(page) (virt_to_bus(page_address(page))) 137 138 #endif 139