import of upstream 2.4.34.4 from kernel.org
[linux-2.4.git] / arch / arm / mach-footbridge / mm.c
1 /*
2  *  linux/arch/arm/mach-footbridge/mm.c
3  *
4  *  Copyright (C) 1998-2000 Russell King, Dave Gilbert.
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  *  Extra MM routines for the EBSA285 architecture
11  */
12 #include <linux/config.h>
13 #include <linux/sched.h>
14 #include <linux/mm.h>
15 #include <linux/init.h>
16  
17 #include <asm/pgtable.h>
18 #include <asm/page.h>
19 #include <asm/io.h>
20 #include <asm/hardware/dec21285.h>
21 #include <asm/mach-types.h>
22
23 #include <asm/mach/map.h>
24
25 /*
26  * Common mapping for all systems.  Note that the outbound write flush is
27  * commented out since there is a "No Fix" problem with it.  Not mapping
28  * it means that we have extra bullet protection on our feet.
29  */
30 static struct map_desc fb_common_io_desc[] __initdata = {
31  { ARMCSR_BASE,  DC21285_ARMCSR_BASE,       ARMCSR_SIZE,  DOMAIN_IO, 0, 1, 0, 0 },
32  { XBUS_BASE,    0x40000000,                XBUS_SIZE,    DOMAIN_IO, 0, 1, 0, 0 },
33  LAST_DESC
34 };
35
36 /*
37  * The mapping when the footbridge is in host mode.  We don't map any of
38  * this when we are in add-in mode.
39  */
40 static struct map_desc ebsa285_host_io_desc[] __initdata = {
41 #if defined(CONFIG_ARCH_FOOTBRIDGE) && defined(CONFIG_FOOTBRIDGE_HOST)
42  { PCIMEM_BASE,  DC21285_PCI_MEM,           PCIMEM_SIZE,  DOMAIN_IO, 0, 1, 0, 0 },
43  { PCICFG0_BASE, DC21285_PCI_TYPE_0_CONFIG, PCICFG0_SIZE, DOMAIN_IO, 0, 1, 0, 0 },
44  { PCICFG1_BASE, DC21285_PCI_TYPE_1_CONFIG, PCICFG1_SIZE, DOMAIN_IO, 0, 1, 0, 0 },
45  { PCIIACK_BASE, DC21285_PCI_IACK,          PCIIACK_SIZE, DOMAIN_IO, 0, 1, 0, 0 },
46  { PCIO_BASE,    DC21285_PCI_IO,            PCIO_SIZE,    DOMAIN_IO, 0, 1, 0, 0 },
47 #endif
48  LAST_DESC
49 };
50
51 /*
52  * The CO-ebsa285 mapping.
53  */
54 static struct map_desc co285_io_desc[] __initdata = {
55 #ifdef CONFIG_ARCH_CO285
56  { PCIO_BASE,    DC21285_PCI_IO,            PCIO_SIZE,    DOMAIN_IO, 0, 1, 0, 0 },
57  { PCIMEM_BASE,  DC21285_PCI_MEM,           PCIMEM_SIZE,  DOMAIN_IO, 0, 1, 0, 0 },
58 #endif
59  LAST_DESC
60 };
61
62 void __init footbridge_map_io(void)
63 {
64         struct map_desc *desc = NULL;
65
66         /*
67          * Set up the common mapping first; we need this to
68          * determine whether we're in host mode or not.
69          */
70         iotable_init(fb_common_io_desc);
71
72         /*
73          * Now, work out what we've got to map in addition on this
74          * platform.
75          */
76         if (machine_is_co285())
77                 desc = co285_io_desc;
78         else if (footbridge_cfn_mode())
79                 desc = ebsa285_host_io_desc;
80
81         if (desc)
82                 iotable_init(desc);
83 }
84
85 #ifdef CONFIG_FOOTBRIDGE_ADDIN
86
87 /*
88  * These two functions convert virtual addresses to PCI addresses and PCI
89  * addresses to virtual addresses.  Note that it is only legal to use these
90  * on memory obtained via get_free_page or kmalloc.
91  */
92 unsigned long __virt_to_bus(unsigned long res)
93 {
94 #ifdef CONFIG_DEBUG_ERRORS
95         if (res < PAGE_OFFSET || res >= (unsigned long)high_memory) {
96                 printk("__virt_to_bus: invalid virtual address 0x%08lx\n", res);
97                 __backtrace();
98         }
99 #endif
100         return (res - PAGE_OFFSET) + (*CSR_PCISDRAMBASE & 0xfffffff0);
101 }
102
103 unsigned long __bus_to_virt(unsigned long res)
104 {
105         res -= (*CSR_PCISDRAMBASE & 0xfffffff0);
106         res += PAGE_OFFSET;
107
108 #ifdef CONFIG_DEBUG_ERRORS
109         if (res < PAGE_OFFSET || res >= (unsigned long)high_memory) {
110                 printk("__bus_to_virt: invalid virtual address 0x%08lx\n", res);
111                 __backtrace();
112         }
113 #endif
114         return res;
115 }
116
117 #endif