summaryrefslogtreecommitdiffstats
path: root/arch/ppc/syslib/harrier.c
blob: a6b3f86457932144ab87895bb39c1bfdde4d223c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*
 * arch/ppc/syslib/harrier.c
 *
 * Motorola MCG Harrier northbridge/memory controller support
 *
 * Author: Dale Farnsworth
 *         dale.farnsworth@mvista.com
 *
 * 2001 (c) MontaVista, Software, Inc.  This file is licensed under
 * the terms of the GNU General Public License version 2.  This program
 * is licensed "as is" without any warranty of any kind, whether express
 * or implied.
 */
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/pci.h>
#include <linux/harrier_defs.h>

#include <asm/byteorder.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/pci.h>
#include <asm/pci-bridge.h>
#include <asm/open_pic.h>
#include <asm/harrier.h>

/* define defaults for inbound windows */
#define HARRIER_ITAT_DEFAULT		(HARRIER_ITAT_ENA | \
					 HARRIER_ITAT_MEM | \
					 HARRIER_ITAT_WPE | \
					 HARRIER_ITAT_GBL)

#define HARRIER_MPAT_DEFAULT		(HARRIER_ITAT_ENA | \
					 HARRIER_ITAT_MEM | \
					 HARRIER_ITAT_WPE | \
					 HARRIER_ITAT_GBL)

/*
 * Initialize the inbound window size on a non-monarch harrier.
 */
void __init harrier_setup_nonmonarch(uint ppc_reg_base, uint in0_size)
{
	u16 temps;
	u32 temp;

	if (in0_size > HARRIER_ITSZ_2GB) {
		printk
		    ("harrier_setup_nonmonarch: Invalid window size code %d\n",
		     in0_size);
		return;
	}

	/* Clear the PCI memory enable bit. If we don't, then when the
	 * inbound windows are enabled below, the corresponding BARs will be
	 * "live" and start answering to PCI memory reads from their default
	 * addresses (0x0), which overlap with system RAM.
	 */
	temps = in_le16((u16 *) (ppc_reg_base +
				 HARRIER_XCSR_CONFIG(PCI_COMMAND)));
	temps &= ~(PCI_COMMAND_MEMORY);
	out_le16((u16 *) (ppc_reg_base + HARRIER_XCSR_CONFIG(PCI_COMMAND)),
		 temps);

	/* Setup a non-prefetchable inbound window */
	out_le32((u32 *) (ppc_reg_base +
			  HARRIER_XCSR_CONFIG(HARRIER_ITSZ0_OFF)), in0_size);

	temp = in_le32((u32 *) (ppc_reg_base +
				HARRIER_XCSR_CONFIG(HARRIER_ITAT0_OFF)));
	temp &= ~HARRIER_ITAT_PRE;
	temp |= HARRIER_ITAT_DEFAULT;
	out_le32((u32 *) (ppc_reg_base +
			  HARRIER_XCSR_CONFIG(HARRIER_ITAT0_OFF)), temp);

	/* Enable the message passing block */
	temp = in_le32((u32 *) (ppc_reg_base +
				HARRIER_XCSR_CONFIG(HARRIER_MPAT_OFF)));
	temp |= HARRIER_MPAT_DEFAULT;
	out_le32((u32 *) (ppc_reg_base +
			  HARRIER_XCSR_CONFIG(HARRIER_MPAT_OFF)), temp);
}

void __init harrier_release_eready(uint ppc_reg_base)
{
	ulong temp;

	/*
	 * Set EREADY to allow the line to be pulled up after everyone is
	 * ready.
	 */
	temp = in_be32((uint *) (ppc_reg_base + HARRIER_MISC_CSR_OFF));
	temp |= HARRIER_EREADY;
	out_be32((uint *) (ppc_reg_base + HARRIER_MISC_CSR_OFF), temp);
}

void __init harrier_wait_eready(uint ppc_reg_base)
{
	ulong temp;

	/*
	 * Poll the ERDYS line until it goes high to indicate that all
	 * non-monarch PrPMCs are ready for bus enumeration (or that there are
	 * no PrPMCs present).
	 */

	/* FIXME: Add a timeout of some kind to prevent endless waits. */
	do {

		temp = in_be32((uint *) (ppc_reg_base + HARRIER_MISC_CSR_OFF));

	} while (!(temp & HARRIER_ERDYS));
}

/*
 * Initialize the Motorola MCG Harrier host bridge.
 *
 * This means setting up the PPC bus to PCI memory and I/O space mappings,
 * setting the PCI memory space address of the MPIC (mapped straight
 * through), and ioremap'ing the mpic registers.
 * 'OpenPIC_Addr' will be set correctly by this routine.
 * This routine will not change the PCI_CONFIG_ADDR or PCI_CONFIG_DATA
 * addresses and assumes that the mapping of PCI memory space back to system
 * memory is set up correctly by PPCBug.
 */
int __init
harrier_init(struct pci_controller *hose,
	     uint ppc_reg_base,
	     ulong processor_pci_mem_start,
	     ulong processor_pci_mem_end,
	     ulong processor_pci_io_start,
	     ulong processor_pci_io_end, ulong processor_mpic_base)
{
	uint addr, offset;

	/*
	 * Some sanity checks...
	 */
	if (((processor_pci_mem_start & 0xffff0000) != processor_pci_mem_start)
	    || ((processor_pci_io_start & 0xffff0000) !=
		processor_pci_io_start)) {
		printk("harrier_init: %s\n",
		       "PPC to PCI mappings must start on 64 KB boundaries");
		return -1;
	}

	if (((processor_pci_mem_end & 0x0000ffff) != 0x0000ffff) ||
	    ((processor_pci_io_end & 0x0000ffff) != 0x0000ffff)) {
		printk("harrier_init: PPC to PCI mappings %s\n",
		       "must end just before a 64 KB boundaries");
		return -1;
	}

	if (((processor_pci_mem_end - processor_pci_mem_start) !=
	     (hose->mem_space.end - hose->mem_space.start)) ||
	    ((processor_pci_io_end - processor_pci_io_start) !=
	     (hose->io_space.end - hose->io_space.start))) {
		printk("harrier_init: %s\n",
		       "PPC and PCI memory or I/O space sizes don't match");
		return -1;
	}

	if ((processor_mpic_base & 0xfffc0000) != processor_mpic_base) {
		printk("harrier_init: %s\n",
		       "MPIC address must start on 256 KB boundary");
		return -1;
	}

	if ((pci_dram_offset & 0xffff0000) != pci_dram_offset) {
		printk("harrier_init: %s\n",
		       "pci_dram_offset must be multiple of 64 KB");
		return -1;
	}

	/*
	 * Program the OTAD/OTOF registers to set up the PCI Mem & I/O
	 * space mappings.  These are the mappings going from the processor to
	 * the PCI bus.
	 *
	 * Note: Don't need to 'AND' start/end addresses with 0xffff0000
	 *       because sanity check above ensures that they are properly
	 *       aligned.
	 */

	/* Set up PPC->PCI Mem mapping */
	addr = processor_pci_mem_start | (processor_pci_mem_end >> 16);
#ifdef CONFIG_HARRIER_STORE_GATHERING
	offset = (hose->mem_space.start - processor_pci_mem_start) | 0x9a;
#else
	offset = (hose->mem_space.start - processor_pci_mem_start) | 0x92;
#endif
	out_be32((uint *) (ppc_reg_base + HARRIER_OTAD0_OFF), addr);
	out_be32((uint *) (ppc_reg_base + HARRIER_OTOF0_OFF), offset);

	/* Set up PPC->PCI I/O mapping -- Contiguous I/O space */
	addr = processor_pci_io_start | (processor_pci_io_end >> 16);
	offset = (hose->io_space.start - processor_pci_io_start) | 0x80;
	out_be32((uint *) (ppc_reg_base + HARRIER_OTAD1_OFF), addr);
	out_be32((uint *) (ppc_reg_base + HARRIER_OTOF1_OFF), offset);

	/* Enable MPIC */
	OpenPIC_Addr = (void *)processor_mpic_base;
	addr = (processor_mpic_base >> 16) | 1;
	out_be16((ushort *) (ppc_reg_base + HARRIER_MBAR_OFF), addr);
	out_8((u_char *) (ppc_reg_base + HARRIER_MPIC_CSR_OFF),
	      HARRIER_MPIC_OPI_ENABLE);

	return 0;
}

/*
 * Find the amount of RAM present.
 * This assumes that PPCBug has initialized the memory controller (SMC)
 * on the Harrier correctly (i.e., it does no sanity checking).
 * It also assumes that the memory base registers are set to configure the
 * memory as contigous starting with "RAM A BASE", "RAM B BASE", etc.
 * however, RAM base registers can be skipped (e.g. A, B, C are set,
 * D is skipped but E is set is okay).
 */
#define	MB	(1024*1024UL)

static uint harrier_size_table[] __initdata = {
	0 * MB,			/* 0 ==>    0 MB */
	32 * MB,		/* 1 ==>   32 MB */
	64 * MB,		/* 2 ==>   64 MB */
	64 * MB,		/* 3 ==>   64 MB */
	128 * MB,		/* 4 ==>  128 MB */
	128 * MB,		/* 5 ==>  128 MB */
	128 * MB,		/* 6 ==>  128 MB */
	256 * MB,		/* 7 ==>  256 MB */
	256 * MB,		/* 8 ==>  256 MB */
	256 * MB,		/* 9 ==>  256 MB */
	512 * MB,		/* a ==>  512 MB */
	512 * MB,		/* b ==>  512 MB */
	512 * MB,		/* c ==>  512 MB */
	1024 * MB,		/* d ==> 1024 MB */
	1024 * MB,		/* e ==> 1024 MB */
	2048 * MB,		/* f ==> 2048 MB */
};

/*
 * *** WARNING: You MUST have a BAT set up to map in the XCSR regs ***
 *
 * Read the memory controller's registers to determine the amount of system
 * memory.  Assumes that the memory controller registers are already mapped
 * into virtual memory--too early to use ioremap().
 */
unsigned long __init harrier_get_mem_size(uint xcsr_base)
{
	ulong last_addr;
	int i;
	uint vend_dev_id;
	uint *size_table;
	uint val;
	uint *csrp;
	uint size;
	int size_table_entries;

	vend_dev_id = in_be32((uint *) xcsr_base + PCI_VENDOR_ID);

	if (((vend_dev_id & 0xffff0000) >> 16) != PCI_VENDOR_ID_MOTOROLA) {
		printk("harrier_get_mem_size: %s (0x%x)\n",
		       "Not a Motorola Memory Controller", vend_dev_id);
		return 0;
	}

	vend_dev_id &= 0x0000ffff;

	if (vend_dev_id == PCI_DEVICE_ID_MOTOROLA_HARRIER) {
		size_table = harrier_size_table;
		size_table_entries = sizeof(harrier_size_table) /
		    sizeof(harrier_size_table[0]);
	} else {
		printk("harrier_get_mem_size: %s (0x%x)\n",
		       "Not a Harrier", vend_dev_id);
		return 0;
	}

	last_addr = 0;

	csrp = (uint *) (xcsr_base + HARRIER_SDBA_OFF);
	for (i = 0; i < 8; i++) {
		val = in_be32(csrp++);

		if (val & 0x100) {	/* If enabled */
			size = val >> HARRIER_SDB_SIZE_SHIFT;
			size &= HARRIER_SDB_SIZE_MASK;
			if (size >= size_table_entries) {
				break;	/* Register not set correctly */
			}
			size = size_table[size];

			val &= ~(size - 1);
			val += size;

			if (val > last_addr) {
				last_addr = val;
			}
		}
	}

	return last_addr;
}
OpenPOWER on IntegriCloud