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