2 * arch/ppc/syslib/harrier.c
4 * Motorola MCG Harrier northbridge/memory controller support
6 * Author: Dale Farnsworth
7 * dale.farnsworth@mvista.com
9 * 2001 (c) MontaVista, Software, Inc. This file is licensed under
10 * the terms of the GNU General Public License version 2. This program
11 * is licensed "as is" without any warranty of any kind, whether express
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/pci.h>
17 #include <linux/harrier_defs.h>
19 #include <asm/byteorder.h>
23 #include <asm/pci-bridge.h>
24 #include <asm/open_pic.h>
25 #include <asm/harrier.h>
27 /* define defaults for inbound windows */
28 #define HARRIER_ITAT_DEFAULT (HARRIER_ITAT_ENA | \
33 #define HARRIER_MPAT_DEFAULT (HARRIER_ITAT_ENA | \
39 * Initialize the inbound window size on a non-monarch harrier.
41 void __init harrier_setup_nonmonarch(uint ppc_reg_base, uint in0_size)
46 if (in0_size > HARRIER_ITSZ_2GB) {
48 ("harrier_setup_nonmonarch: Invalid window size code %d\n",
53 /* Clear the PCI memory enable bit. If we don't, then when the
54 * inbound windows are enabled below, the corresponding BARs will be
55 * "live" and start answering to PCI memory reads from their default
56 * addresses (0x0), which overlap with system RAM.
58 temps = in_le16((u16 *) (ppc_reg_base +
59 HARRIER_XCSR_CONFIG(PCI_COMMAND)));
60 temps &= ~(PCI_COMMAND_MEMORY);
61 out_le16((u16 *) (ppc_reg_base + HARRIER_XCSR_CONFIG(PCI_COMMAND)),
64 /* Setup a non-prefetchable inbound window */
65 out_le32((u32 *) (ppc_reg_base +
66 HARRIER_XCSR_CONFIG(HARRIER_ITSZ0_OFF)), in0_size);
68 temp = in_le32((u32 *) (ppc_reg_base +
69 HARRIER_XCSR_CONFIG(HARRIER_ITAT0_OFF)));
70 temp &= ~HARRIER_ITAT_PRE;
71 temp |= HARRIER_ITAT_DEFAULT;
72 out_le32((u32 *) (ppc_reg_base +
73 HARRIER_XCSR_CONFIG(HARRIER_ITAT0_OFF)), temp);
75 /* Enable the message passing block */
76 temp = in_le32((u32 *) (ppc_reg_base +
77 HARRIER_XCSR_CONFIG(HARRIER_MPAT_OFF)));
78 temp |= HARRIER_MPAT_DEFAULT;
79 out_le32((u32 *) (ppc_reg_base +
80 HARRIER_XCSR_CONFIG(HARRIER_MPAT_OFF)), temp);
83 void __init harrier_release_eready(uint ppc_reg_base)
88 * Set EREADY to allow the line to be pulled up after everyone is
91 temp = in_be32((uint *) (ppc_reg_base + HARRIER_MISC_CSR_OFF));
92 temp |= HARRIER_EREADY;
93 out_be32((uint *) (ppc_reg_base + HARRIER_MISC_CSR_OFF), temp);
96 void __init harrier_wait_eready(uint ppc_reg_base)
101 * Poll the ERDYS line until it goes high to indicate that all
102 * non-monarch PrPMCs are ready for bus enumeration (or that there are
103 * no PrPMCs present).
106 /* FIXME: Add a timeout of some kind to prevent endless waits. */
109 temp = in_be32((uint *) (ppc_reg_base + HARRIER_MISC_CSR_OFF));
111 } while (!(temp & HARRIER_ERDYS));
115 * Initialize the Motorola MCG Harrier host bridge.
117 * This means setting up the PPC bus to PCI memory and I/O space mappings,
118 * setting the PCI memory space address of the MPIC (mapped straight
119 * through), and ioremap'ing the mpic registers.
120 * 'OpenPIC_Addr' will be set correctly by this routine.
121 * This routine will not change the PCI_CONFIG_ADDR or PCI_CONFIG_DATA
122 * addresses and assumes that the mapping of PCI memory space back to system
123 * memory is set up correctly by PPCBug.
126 harrier_init(struct pci_controller *hose,
128 ulong processor_pci_mem_start,
129 ulong processor_pci_mem_end,
130 ulong processor_pci_io_start,
131 ulong processor_pci_io_end, ulong processor_mpic_base)
136 * Some sanity checks...
138 if (((processor_pci_mem_start & 0xffff0000) != processor_pci_mem_start)
139 || ((processor_pci_io_start & 0xffff0000) !=
140 processor_pci_io_start)) {
141 printk("harrier_init: %s\n",
142 "PPC to PCI mappings must start on 64 KB boundaries");
146 if (((processor_pci_mem_end & 0x0000ffff) != 0x0000ffff) ||
147 ((processor_pci_io_end & 0x0000ffff) != 0x0000ffff)) {
148 printk("harrier_init: PPC to PCI mappings %s\n",
149 "must end just before a 64 KB boundaries");
153 if (((processor_pci_mem_end - processor_pci_mem_start) !=
154 (hose->mem_space.end - hose->mem_space.start)) ||
155 ((processor_pci_io_end - processor_pci_io_start) !=
156 (hose->io_space.end - hose->io_space.start))) {
157 printk("harrier_init: %s\n",
158 "PPC and PCI memory or I/O space sizes don't match");
162 if ((processor_mpic_base & 0xfffc0000) != processor_mpic_base) {
163 printk("harrier_init: %s\n",
164 "MPIC address must start on 256 KB boundary");
168 if ((pci_dram_offset & 0xffff0000) != pci_dram_offset) {
169 printk("harrier_init: %s\n",
170 "pci_dram_offset must be multiple of 64 KB");
175 * Program the OTAD/OTOF registers to set up the PCI Mem & I/O
176 * space mappings. These are the mappings going from the processor to
179 * Note: Don't need to 'AND' start/end addresses with 0xffff0000
180 * because sanity check above ensures that they are properly
184 /* Set up PPC->PCI Mem mapping */
185 addr = processor_pci_mem_start | (processor_pci_mem_end >> 16);
186 #ifdef CONFIG_HARRIER_STORE_GATHERING
187 offset = (hose->mem_space.start - processor_pci_mem_start) | 0x9a;
189 offset = (hose->mem_space.start - processor_pci_mem_start) | 0x92;
191 out_be32((uint *) (ppc_reg_base + HARRIER_OTAD0_OFF), addr);
192 out_be32((uint *) (ppc_reg_base + HARRIER_OTOF0_OFF), offset);
194 /* Set up PPC->PCI I/O mapping -- Contiguous I/O space */
195 addr = processor_pci_io_start | (processor_pci_io_end >> 16);
196 offset = (hose->io_space.start - processor_pci_io_start) | 0x80;
197 out_be32((uint *) (ppc_reg_base + HARRIER_OTAD1_OFF), addr);
198 out_be32((uint *) (ppc_reg_base + HARRIER_OTOF1_OFF), offset);
201 OpenPIC_Addr = (void *)processor_mpic_base;
202 addr = (processor_mpic_base >> 16) | 1;
203 out_be16((ushort *) (ppc_reg_base + HARRIER_MBAR_OFF), addr);
204 out_8((u_char *) (ppc_reg_base + HARRIER_MPIC_CSR_OFF),
205 HARRIER_MPIC_OPI_ENABLE);
211 * Find the amount of RAM present.
212 * This assumes that PPCBug has initialized the memory controller (SMC)
213 * on the Harrier correctly (i.e., it does no sanity checking).
214 * It also assumes that the memory base registers are set to configure the
215 * memory as contigous starting with "RAM A BASE", "RAM B BASE", etc.
216 * however, RAM base registers can be skipped (e.g. A, B, C are set,
217 * D is skipped but E is set is okay).
219 #define MB (1024*1024UL)
221 static uint harrier_size_table[] __initdata = {
222 0 * MB, /* 0 ==> 0 MB */
223 32 * MB, /* 1 ==> 32 MB */
224 64 * MB, /* 2 ==> 64 MB */
225 64 * MB, /* 3 ==> 64 MB */
226 128 * MB, /* 4 ==> 128 MB */
227 128 * MB, /* 5 ==> 128 MB */
228 128 * MB, /* 6 ==> 128 MB */
229 256 * MB, /* 7 ==> 256 MB */
230 256 * MB, /* 8 ==> 256 MB */
231 256 * MB, /* 9 ==> 256 MB */
232 512 * MB, /* a ==> 512 MB */
233 512 * MB, /* b ==> 512 MB */
234 512 * MB, /* c ==> 512 MB */
235 1024 * MB, /* d ==> 1024 MB */
236 1024 * MB, /* e ==> 1024 MB */
237 2048 * MB, /* f ==> 2048 MB */
241 * *** WARNING: You MUST have a BAT set up to map in the XCSR regs ***
243 * Read the memory controller's registers to determine the amount of system
244 * memory. Assumes that the memory controller registers are already mapped
245 * into virtual memory--too early to use ioremap().
247 unsigned long __init harrier_get_mem_size(uint xcsr_base)
256 int size_table_entries;
258 vend_dev_id = in_be32((uint *) xcsr_base + PCI_VENDOR_ID);
260 if (((vend_dev_id & 0xffff0000) >> 16) != PCI_VENDOR_ID_MOTOROLA) {
261 printk("harrier_get_mem_size: %s (0x%x)\n",
262 "Not a Motorola Memory Controller", vend_dev_id);
266 vend_dev_id &= 0x0000ffff;
268 if (vend_dev_id == PCI_DEVICE_ID_MOTOROLA_HARRIER) {
269 size_table = harrier_size_table;
270 size_table_entries = sizeof(harrier_size_table) /
271 sizeof(harrier_size_table[0]);
273 printk("harrier_get_mem_size: %s (0x%x)\n",
274 "Not a Harrier", vend_dev_id);
280 csrp = (uint *) (xcsr_base + HARRIER_SDBA_OFF);
281 for (i = 0; i < 8; i++) {
282 val = in_be32(csrp++);
284 if (val & 0x100) { /* If enabled */
285 size = val >> HARRIER_SDB_SIZE_SHIFT;
286 size &= HARRIER_SDB_SIZE_MASK;
287 if (size >= size_table_entries) {
288 break; /* Register not set correctly */
290 size = size_table[size];
295 if (val > last_addr) {