2 * Motorola MCG Harrier northbridge/memory controller support
4 * Author: Dale Farnsworth
5 * dale.farnsworth@mvista.com
7 * 2001 (c) MontaVista, Software, Inc. This file is licensed under
8 * the terms of the GNU General Public License version 2. This program
9 * is licensed "as is" without any warranty of any kind, whether express
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/pci.h>
15 #include <linux/harrier_defs.h>
17 #include <asm/byteorder.h>
21 #include <asm/pci-bridge.h>
22 #include <asm/open_pic.h>
23 #include <asm/harrier.h>
25 /* define defaults for inbound windows */
26 #define HARRIER_ITAT_DEFAULT (HARRIER_ITAT_ENA | \
31 #define HARRIER_MPAT_DEFAULT (HARRIER_ITAT_ENA | \
37 * Initialize the inbound window size on a non-monarch harrier.
39 void __init
harrier_setup_nonmonarch(uint ppc_reg_base
, uint in0_size
)
44 if (in0_size
> HARRIER_ITSZ_2GB
) {
46 ("harrier_setup_nonmonarch: Invalid window size code %d\n",
51 /* Clear the PCI memory enable bit. If we don't, then when the
52 * inbound windows are enabled below, the corresponding BARs will be
53 * "live" and start answering to PCI memory reads from their default
54 * addresses (0x0), which overlap with system RAM.
56 temps
= in_le16((u16
*) (ppc_reg_base
+
57 HARRIER_XCSR_CONFIG(PCI_COMMAND
)));
58 temps
&= ~(PCI_COMMAND_MEMORY
);
59 out_le16((u16
*) (ppc_reg_base
+ HARRIER_XCSR_CONFIG(PCI_COMMAND
)),
62 /* Setup a non-prefetchable inbound window */
63 out_le32((u32
*) (ppc_reg_base
+
64 HARRIER_XCSR_CONFIG(HARRIER_ITSZ0_OFF
)), in0_size
);
66 temp
= in_le32((u32
*) (ppc_reg_base
+
67 HARRIER_XCSR_CONFIG(HARRIER_ITAT0_OFF
)));
68 temp
&= ~HARRIER_ITAT_PRE
;
69 temp
|= HARRIER_ITAT_DEFAULT
;
70 out_le32((u32
*) (ppc_reg_base
+
71 HARRIER_XCSR_CONFIG(HARRIER_ITAT0_OFF
)), temp
);
73 /* Enable the message passing block */
74 temp
= in_le32((u32
*) (ppc_reg_base
+
75 HARRIER_XCSR_CONFIG(HARRIER_MPAT_OFF
)));
76 temp
|= HARRIER_MPAT_DEFAULT
;
77 out_le32((u32
*) (ppc_reg_base
+
78 HARRIER_XCSR_CONFIG(HARRIER_MPAT_OFF
)), temp
);
81 void __init
harrier_release_eready(uint ppc_reg_base
)
86 * Set EREADY to allow the line to be pulled up after everyone is
89 temp
= in_be32((uint
*) (ppc_reg_base
+ HARRIER_MISC_CSR_OFF
));
90 temp
|= HARRIER_EREADY
;
91 out_be32((uint
*) (ppc_reg_base
+ HARRIER_MISC_CSR_OFF
), temp
);
94 void __init
harrier_wait_eready(uint ppc_reg_base
)
99 * Poll the ERDYS line until it goes high to indicate that all
100 * non-monarch PrPMCs are ready for bus enumeration (or that there are
101 * no PrPMCs present).
104 /* FIXME: Add a timeout of some kind to prevent endless waits. */
107 temp
= in_be32((uint
*) (ppc_reg_base
+ HARRIER_MISC_CSR_OFF
));
109 } while (!(temp
& HARRIER_ERDYS
));
113 * Initialize the Motorola MCG Harrier host bridge.
115 * This means setting up the PPC bus to PCI memory and I/O space mappings,
116 * setting the PCI memory space address of the MPIC (mapped straight
117 * through), and ioremap'ing the mpic registers.
118 * 'OpenPIC_Addr' will be set correctly by this routine.
119 * This routine will not change the PCI_CONFIG_ADDR or PCI_CONFIG_DATA
120 * addresses and assumes that the mapping of PCI memory space back to system
121 * memory is set up correctly by PPCBug.
124 harrier_init(struct pci_controller
*hose
,
126 ulong processor_pci_mem_start
,
127 ulong processor_pci_mem_end
,
128 ulong processor_pci_io_start
,
129 ulong processor_pci_io_end
, ulong processor_mpic_base
)
134 * Some sanity checks...
136 if (((processor_pci_mem_start
& 0xffff0000) != processor_pci_mem_start
)
137 || ((processor_pci_io_start
& 0xffff0000) !=
138 processor_pci_io_start
)) {
139 printk("harrier_init: %s\n",
140 "PPC to PCI mappings must start on 64 KB boundaries");
144 if (((processor_pci_mem_end
& 0x0000ffff) != 0x0000ffff) ||
145 ((processor_pci_io_end
& 0x0000ffff) != 0x0000ffff)) {
146 printk("harrier_init: PPC to PCI mappings %s\n",
147 "must end just before a 64 KB boundaries");
151 if (((processor_pci_mem_end
- processor_pci_mem_start
) !=
152 (hose
->mem_space
.end
- hose
->mem_space
.start
)) ||
153 ((processor_pci_io_end
- processor_pci_io_start
) !=
154 (hose
->io_space
.end
- hose
->io_space
.start
))) {
155 printk("harrier_init: %s\n",
156 "PPC and PCI memory or I/O space sizes don't match");
160 if ((processor_mpic_base
& 0xfffc0000) != processor_mpic_base
) {
161 printk("harrier_init: %s\n",
162 "MPIC address must start on 256 KB boundary");
166 if ((pci_dram_offset
& 0xffff0000) != pci_dram_offset
) {
167 printk("harrier_init: %s\n",
168 "pci_dram_offset must be multiple of 64 KB");
173 * Program the OTAD/OTOF registers to set up the PCI Mem & I/O
174 * space mappings. These are the mappings going from the processor to
177 * Note: Don't need to 'AND' start/end addresses with 0xffff0000
178 * because sanity check above ensures that they are properly
182 /* Set up PPC->PCI Mem mapping */
183 addr
= processor_pci_mem_start
| (processor_pci_mem_end
>> 16);
184 #ifdef CONFIG_HARRIER_STORE_GATHERING
185 offset
= (hose
->mem_space
.start
- processor_pci_mem_start
) | 0x9a;
187 offset
= (hose
->mem_space
.start
- processor_pci_mem_start
) | 0x92;
189 out_be32((uint
*) (ppc_reg_base
+ HARRIER_OTAD0_OFF
), addr
);
190 out_be32((uint
*) (ppc_reg_base
+ HARRIER_OTOF0_OFF
), offset
);
192 /* Set up PPC->PCI I/O mapping -- Contiguous I/O space */
193 addr
= processor_pci_io_start
| (processor_pci_io_end
>> 16);
194 offset
= (hose
->io_space
.start
- processor_pci_io_start
) | 0x80;
195 out_be32((uint
*) (ppc_reg_base
+ HARRIER_OTAD1_OFF
), addr
);
196 out_be32((uint
*) (ppc_reg_base
+ HARRIER_OTOF1_OFF
), offset
);
199 OpenPIC_Addr
= (void *)processor_mpic_base
;
200 addr
= (processor_mpic_base
>> 16) | 1;
201 out_be16((ushort
*) (ppc_reg_base
+ HARRIER_MBAR_OFF
), addr
);
202 out_8((u_char
*) (ppc_reg_base
+ HARRIER_MPIC_CSR_OFF
),
203 HARRIER_MPIC_OPI_ENABLE
);
209 * Find the amount of RAM present.
210 * This assumes that PPCBug has initialized the memory controller (SMC)
211 * on the Harrier correctly (i.e., it does no sanity checking).
212 * It also assumes that the memory base registers are set to configure the
213 * memory as contiguous starting with "RAM A BASE", "RAM B BASE", etc.
214 * however, RAM base registers can be skipped (e.g. A, B, C are set,
215 * D is skipped but E is set is okay).
217 #define MB (1024*1024UL)
219 static uint harrier_size_table
[] __initdata
= {
220 0 * MB
, /* 0 ==> 0 MB */
221 32 * MB
, /* 1 ==> 32 MB */
222 64 * MB
, /* 2 ==> 64 MB */
223 64 * MB
, /* 3 ==> 64 MB */
224 128 * MB
, /* 4 ==> 128 MB */
225 128 * MB
, /* 5 ==> 128 MB */
226 128 * MB
, /* 6 ==> 128 MB */
227 256 * MB
, /* 7 ==> 256 MB */
228 256 * MB
, /* 8 ==> 256 MB */
229 256 * MB
, /* 9 ==> 256 MB */
230 512 * MB
, /* a ==> 512 MB */
231 512 * MB
, /* b ==> 512 MB */
232 512 * MB
, /* c ==> 512 MB */
233 1024 * MB
, /* d ==> 1024 MB */
234 1024 * MB
, /* e ==> 1024 MB */
235 2048 * MB
, /* f ==> 2048 MB */
239 * *** WARNING: You MUST have a BAT set up to map in the XCSR regs ***
241 * Read the memory controller's registers to determine the amount of system
242 * memory. Assumes that the memory controller registers are already mapped
243 * into virtual memory--too early to use ioremap().
245 unsigned long __init
harrier_get_mem_size(uint xcsr_base
)
254 int size_table_entries
;
256 vend_dev_id
= in_be32((uint
*) xcsr_base
+ PCI_VENDOR_ID
);
258 if (((vend_dev_id
& 0xffff0000) >> 16) != PCI_VENDOR_ID_MOTOROLA
) {
259 printk("harrier_get_mem_size: %s (0x%x)\n",
260 "Not a Motorola Memory Controller", vend_dev_id
);
264 vend_dev_id
&= 0x0000ffff;
266 if (vend_dev_id
== PCI_DEVICE_ID_MOTOROLA_HARRIER
) {
267 size_table
= harrier_size_table
;
268 size_table_entries
= sizeof(harrier_size_table
) /
269 sizeof(harrier_size_table
[0]);
271 printk("harrier_get_mem_size: %s (0x%x)\n",
272 "Not a Harrier", vend_dev_id
);
278 csrp
= (uint
*) (xcsr_base
+ HARRIER_SDBA_OFF
);
279 for (i
= 0; i
< 8; i
++) {
280 val
= in_be32(csrp
++);
282 if (val
& 0x100) { /* If enabled */
283 size
= val
>> HARRIER_SDB_SIZE_SHIFT
;
284 size
&= HARRIER_SDB_SIZE_MASK
;
285 if (size
>= size_table_entries
) {
286 break; /* Register not set correctly */
288 size
= size_table
[size
];
293 if (val
> last_addr
) {