patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / include / asm-arm / arch-lh7a40x / memory.h
1 /* include/asm-arm/arch-lh7a40x/memory.h
2  *
3  *  Copyright (C) 2004 Coastal Environmental Systems
4  *
5  *  This program is free software; you can redistribute it and/or
6  *  modify it under the terms of the GNU General Public License
7  *  version 2 as published by the Free Software Foundation.
8  *
9  */
10
11 #ifndef __ASM_ARCH_MEMORY_H
12 #define __ASM_ARCH_MEMORY_H
13
14
15 #define BANKS_PER_NODE 1        /* Define as either 1 or 2 */
16
17 /*
18  * Physical DRAM offset.
19  */
20 #define PHYS_OFFSET     (0xc0000000UL)
21
22 /*
23  * Virtual view <-> DMA view memory address translations
24  * virt_to_bus: Used to translate the virtual address to an
25  *              address suitable to be passed to set_dma_addr
26  * bus_to_virt: Used to convert an address for DMA operations
27  *              to an address that the kernel can use.
28  */
29 #define __virt_to_bus(x)         __virt_to_phys(x)
30 #define __bus_to_virt(x)         __phys_to_virt(x)
31
32 #ifdef CONFIG_DISCONTIGMEM
33 /*
34  * Because of the wide memory address space between physical RAM
35  * banks, it's convenient to use Linux's NUMA support to represent our
36  * memory map.  Assuming all memory nodes have equal access
37  * characteristics, we then have a generic discontiguous memory setup.
38  *
39  * Of course, all this isn't mandatory for implementations with only
40  * one used memory bank.  For those, simply undefine
41  * CONFIG_DISCONTIGMEM.  However, keep in mind that a featurefull
42  * system will need more than 4MiB of RAM.
43  *
44  * The contiguous memory blocks are small enough that it pays to
45  * aggregate two banks into one node.  Setting BANKS_PER_NODE to 2
46  * puts pairs of banks into a node.
47  *
48  * A typical layout would start like this:
49  *
50  *  node 0: 0xc0000000
51  *          0xc1000000
52  *  node 1: 0xc4000000
53  *          0xc5000000
54  *  node 2: 0xc8000000
55  *          0xc9000000
56  *
57  * The proximity of the pairs of blocks makes it feasible to combine them.
58  *
59  */
60
61 /*
62  * Given a kernel address, find the home node of the underlying memory.
63  */
64
65 #if BANKS_PER_NODE==1
66 #define KVADDR_TO_NID(addr) \
67   (  ((((unsigned long) (addr) - PAGE_OFFSET) >> 24) &  1)\
68    | ((((unsigned long) (addr) - PAGE_OFFSET) >> 25) & ~1))
69 #else  /* 2 banks per node */
70 #define KVADDR_TO_NID(addr) \
71        ((unsigned long) (addr) - PAGE_OFFSET) >> 26)
72 #endif
73
74 /*
75  * Given a page frame number, convert it to a node id.
76  */
77
78 #if BANKS_PER_NODE==1
79 #define PFN_TO_NID(pfn) \
80   (((((pfn) - PHYS_PFN_OFFSET) >> (24 - PAGE_SHIFT)) &  1)\
81  | ((((pfn) - PHYS_PFN_OFFSET) >> (25 - PAGE_SHIFT)) & ~1))
82 #else  /* 2 banks per node */
83 #define PFN_TO_NID(addr) \
84     (((pfn) - PHYS_PFN_OFFSET) >> (26 - PAGE_SHIFT))
85 #endif
86
87 /*
88  * Given a kaddr, ADDR_TO_MAPBASE finds the owning node of the memory
89  * and return the mem_map of that node.
90  */
91 #define ADDR_TO_MAPBASE(kaddr)  NODE_MEM_MAP(KVADDR_TO_NID(kaddr))
92
93 /*
94  * Given a page frame number, find the owning node of the memory
95  * and return the mem_map of that node.
96  */
97 #define PFN_TO_MAPBASE(pfn)     NODE_MEM_MAP(PFN_TO_NID(pfn))
98
99 /*
100  * Given a kaddr, LOCAL_MEM_MAP finds the owning node of the memory
101  * and returns the index corresponding to the appropriate page in the
102  * node's mem_map.
103  */
104
105 #if BANKS_PER_NODE==1
106 #define LOCAL_MAP_NR(addr) \
107        (((unsigned long)(addr) & 0x003fffff) >> PAGE_SHIFT)
108 #else  /* 2 banks per node */
109 #define LOCAL_MAP_NR(addr) \
110        (((unsigned long)(addr) & 0x01ffffff) >> PAGE_SHIFT)
111 #endif
112
113 #else
114
115 #define PFN_TO_NID(addr)        (0)
116
117 #endif
118
119 #endif