aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-orion/addr-map.c
diff options
context:
space:
mode:
authorTzachi Perelstein <tzachi@marvell.com>2007-10-23 15:14:42 -0400
committerRussell King <rmk+kernel@arm.linux.org.uk>2008-01-26 10:03:44 -0500
commitc67de5b3c0bb48ac56f14928e11f1f7d76add26f (patch)
treefe611cc5bc571fc8d9068330b3ac95f2c85be19a /arch/arm/mach-orion/addr-map.c
parent038ee0832ee1b1e2bd2be4599cd535ea9aaaf658 (diff)
[ARM] Orion: programable address map support
The Orion has fully programable address map. There's a separate address map for each of the device _master_ interfaces, e.g. CPU, PCI, PCIE, USB, Gigabit Ethernet, DMA/XOR engines, etc. Signed-off-by: Tzachi Perelstein <tzachi@marvell.com> Reviewed-by: Nicolas Pitre <nico@marvell.com> Reviewed-by: Lennert Buytenhek <buytenh@marvell.com>
Diffstat (limited to 'arch/arm/mach-orion/addr-map.c')
-rw-r--r--arch/arm/mach-orion/addr-map.c482
1 files changed, 482 insertions, 0 deletions
diff --git a/arch/arm/mach-orion/addr-map.c b/arch/arm/mach-orion/addr-map.c
new file mode 100644
index 000000000000..ff6e010bccb2
--- /dev/null
+++ b/arch/arm/mach-orion/addr-map.c
@@ -0,0 +1,482 @@
1/*
2 * arch/arm/mach-orion/addr-map.c
3 *
4 * Address map functions for Marvell Orion System On Chip
5 *
6 * Maintainer: Tzachi Perelstein <tzachi@marvell.com>
7 *
8 * This file is licensed under the terms of the GNU General Public
9 * License version 2. This program is licensed "as is" without any
10 * warranty of any kind, whether express or implied.
11 */
12
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <asm/hardware.h>
16#include "common.h"
17
18/*
19 * The Orion has fully programable address map. There's a separate address
20 * map for each of the device _master_ interfaces, e.g. CPU, PCI, PCIE, USB,
21 * Gigabit Ethernet, DMA/XOR engines, etc. Each interface has its own
22 * address decode windows that allow it to access any of the Orion resources.
23 *
24 * CPU address decoding --
25 * Linux assumes that it is the boot loader that already setup the access to
26 * DDR and internal registers.
27 * Setup access to PCI and PCI-E IO/MEM space is issued by core.c.
28 * Setup access to various devices located on the device bus interface (e.g.
29 * flashes, RTC, etc) should be issued by machine-setup.c according to
30 * specific board population (by using orion_setup_cpu_win()).
31 *
32 * Non-CPU Masters address decoding --
33 * Unlike the CPU, we setup the access from Orion's master interfaces to DDR
34 * banks only (the typical use case).
35 * Setup access for each master to DDR is issued by common.c.
36 *
37 * Note: although orion_setbits() and orion_clrbits() are not atomic
38 * no locking is necessary here since code in this file is only called
39 * at boot time when there is no concurrency issues.
40 */
41
42/*
43 * Generic Address Decode Windows bit settings
44 */
45#define TARGET_DDR 0
46#define TARGET_PCI 3
47#define TARGET_PCIE 4
48#define TARGET_DEV_BUS 1
49#define ATTR_DDR_CS(n) (((n) ==0) ? 0xe : \
50 ((n) == 1) ? 0xd : \
51 ((n) == 2) ? 0xb : \
52 ((n) == 3) ? 0x7 : 0xf)
53#define ATTR_PCIE_MEM 0x59
54#define ATTR_PCIE_IO 0x51
55#define ATTR_PCI_MEM 0x59
56#define ATTR_PCI_IO 0x51
57#define ATTR_DEV_CS0 0x1e
58#define ATTR_DEV_CS1 0x1d
59#define ATTR_DEV_CS2 0x1b
60#define ATTR_DEV_BOOT 0xf
61#define WIN_EN 1
62
63/*
64 * Helpers to get DDR banks info
65 */
66#define DDR_BASE_CS(n) ORION_DDR_REG(0x1500 + ((n) * 8))
67#define DDR_SIZE_CS(n) ORION_DDR_REG(0x1504 + ((n) * 8))
68#define DDR_MAX_CS 4
69#define DDR_REG_TO_SIZE(reg) (((reg) | 0xffffff) + 1)
70#define DDR_REG_TO_BASE(reg) ((reg) & 0xff000000)
71#define DDR_BANK_EN 1
72
73/*
74 * CPU Address Decode Windows registers
75 */
76#define CPU_WIN_CTRL(n) ORION_BRIDGE_REG(0x000 | ((n) << 4))
77#define CPU_WIN_BASE(n) ORION_BRIDGE_REG(0x004 | ((n) << 4))
78#define CPU_WIN_REMAP_LO(n) ORION_BRIDGE_REG(0x008 | ((n) << 4))
79#define CPU_WIN_REMAP_HI(n) ORION_BRIDGE_REG(0x00c | ((n) << 4))
80#define CPU_MAX_WIN 8
81
82/*
83 * Use this CPU address decode windows allocation
84 */
85#define CPU_WIN_PCIE_IO 0
86#define CPU_WIN_PCI_IO 1
87#define CPU_WIN_PCIE_MEM 2
88#define CPU_WIN_PCI_MEM 3
89#define CPU_WIN_DEV_BOOT 4
90#define CPU_WIN_DEV_CS0 5
91#define CPU_WIN_DEV_CS1 6
92#define CPU_WIN_DEV_CS2 7
93
94/*
95 * PCIE Address Decode Windows registers
96 */
97#define PCIE_BAR_CTRL(n) ORION_PCIE_REG(0x1804 + ((n - 1) * 4))
98#define PCIE_BAR_LO(n) ORION_PCIE_REG(0x0010 + ((n) * 8))
99#define PCIE_BAR_HI(n) ORION_PCIE_REG(0x0014 + ((n) * 8))
100#define PCIE_WIN_CTRL(n) ORION_PCIE_REG(0x1820 + ((n) << 4))
101#define PCIE_WIN_BASE(n) ORION_PCIE_REG(0x1824 + ((n) << 4))
102#define PCIE_WIN_REMAP(n) ORION_PCIE_REG(0x182c + ((n) << 4))
103#define PCIE_DEFWIN_CTRL ORION_PCIE_REG(0x18b0)
104#define PCIE_EXPROM_WIN_CTRL ORION_PCIE_REG(0x18c0)
105#define PCIE_EXPROM_WIN_REMP ORION_PCIE_REG(0x18c4)
106#define PCIE_MAX_BARS 3
107#define PCIE_MAX_WINS 5
108
109/*
110 * Use PCIE BAR '1' for all DDR banks
111 */
112#define PCIE_DRAM_BAR 1
113
114/*
115 * PCI Address Decode Windows registers
116 */
117#define PCI_BAR_SIZE_DDR_CS(n) (((n) == 0) ? ORION_PCI_REG(0xc08) : \
118 ((n) == 1) ? ORION_PCI_REG(0xd08) : \
119 ((n) == 2) ? ORION_PCI_REG(0xc0c) : \
120 ((n) == 3) ? ORION_PCI_REG(0xd0c) : 0)
121#define PCI_BAR_REMAP_DDR_CS(n) (((n) ==0) ? ORION_PCI_REG(0xc48) : \
122 ((n) == 1) ? ORION_PCI_REG(0xd48) : \
123 ((n) == 2) ? ORION_PCI_REG(0xc4c) : \
124 ((n) == 3) ? ORION_PCI_REG(0xd4c) : 0)
125#define PCI_BAR_ENABLE ORION_PCI_REG(0xc3c)
126#define PCI_CTRL_BASE_LO(n) ORION_PCI_REG(0x1e00 | ((n) << 4))
127#define PCI_CTRL_BASE_HI(n) ORION_PCI_REG(0x1e04 | ((n) << 4))
128#define PCI_CTRL_SIZE(n) ORION_PCI_REG(0x1e08 | ((n) << 4))
129#define PCI_ADDR_DECODE_CTRL ORION_PCI_REG(0xd3c)
130
131/*
132 * PCI configuration heleprs for BAR settings
133 */
134#define PCI_CONF_FUNC_BAR_CS(n) ((n) >> 1)
135#define PCI_CONF_REG_BAR_LO_CS(n) (((n) & 1) ? 0x18 : 0x10)
136#define PCI_CONF_REG_BAR_HI_CS(n) (((n) & 1) ? 0x1c : 0x14)
137
138/*
139 * Gigabit Ethernet Address Decode Windows registers
140 */
141#define ETH_WIN_BASE(win) ORION_ETH_REG(0x200 + ((win) * 8))
142#define ETH_WIN_SIZE(win) ORION_ETH_REG(0x204 + ((win) * 8))
143#define ETH_WIN_REMAP(win) ORION_ETH_REG(0x280 + ((win) * 4))
144#define ETH_WIN_EN ORION_ETH_REG(0x290)
145#define ETH_WIN_PROT ORION_ETH_REG(0x294)
146#define ETH_MAX_WIN 6
147#define ETH_MAX_REMAP_WIN 4
148
149/*
150 * USB Address Decode Windows registers
151 */
152#define USB_WIN_CTRL(i, w) ((i == 0) ? ORION_USB0_REG(0x320 + ((w) << 4)) \
153 : ORION_USB1_REG(0x320 + ((w) << 4)))
154#define USB_WIN_BASE(i, w) ((i == 0) ? ORION_USB0_REG(0x324 + ((w) << 4)) \
155 : ORION_USB1_REG(0x324 + ((w) << 4)))
156#define USB_MAX_WIN 4
157
158/*
159 * SATA Address Decode Windows registers
160 */
161#define SATA_WIN_CTRL(win) ORION_SATA_REG(0x30 + ((win) * 0x10))
162#define SATA_WIN_BASE(win) ORION_SATA_REG(0x34 + ((win) * 0x10))
163#define SATA_MAX_WIN 4
164
165static int __init orion_cpu_win_can_remap(u32 win)
166{
167 u32 dev, rev;
168
169 orion_pcie_id(&dev, &rev);
170 if ((dev == MV88F5281_DEV_ID && win < 4) || (dev == MV88F5182_DEV_ID && win < 2))
171 return 1;
172
173 return 0;
174}
175
176void __init orion_setup_cpu_win(enum orion_target target, u32 base, u32 size, int remap)
177{
178 u32 win, attr, ctrl;
179
180 switch (target) {
181 case ORION_PCIE_IO:
182 target = TARGET_PCIE;
183 attr = ATTR_PCIE_IO;
184 win = CPU_WIN_PCIE_IO;
185 break;
186 case ORION_PCI_IO:
187 target = TARGET_PCI;
188 attr = ATTR_PCI_IO;
189 win = CPU_WIN_PCI_IO;
190 break;
191 case ORION_PCIE_MEM:
192 target = TARGET_PCIE;
193 attr = ATTR_PCIE_MEM;
194 win = CPU_WIN_PCIE_MEM;
195 break;
196 case ORION_PCI_MEM:
197 target = TARGET_PCI;
198 attr = ATTR_PCI_MEM;
199 win = CPU_WIN_PCI_MEM;
200 break;
201 case ORION_DEV_BOOT:
202 target = TARGET_DEV_BUS;
203 attr = ATTR_DEV_BOOT;
204 win = CPU_WIN_DEV_BOOT;
205 break;
206 case ORION_DEV0:
207 target = TARGET_DEV_BUS;
208 attr = ATTR_DEV_CS0;
209 win = CPU_WIN_DEV_CS0;
210 break;
211 case ORION_DEV1:
212 target = TARGET_DEV_BUS;
213 attr = ATTR_DEV_CS1;
214 win = CPU_WIN_DEV_CS1;
215 break;
216 case ORION_DEV2:
217 target = TARGET_DEV_BUS;
218 attr = ATTR_DEV_CS2;
219 win = CPU_WIN_DEV_CS2;
220 break;
221 case ORION_DDR:
222 case ORION_REGS:
223 /*
224 * Must be mapped by bootloader.
225 */
226 default:
227 target = attr = win = -1;
228 BUG();
229 }
230
231 base &= 0xffff0000;
232 ctrl = (((size - 1) & 0xffff0000) | (attr << 8) |
233 (target << 4) | WIN_EN);
234
235 orion_write(CPU_WIN_BASE(win), base);
236 orion_write(CPU_WIN_CTRL(win), ctrl);
237
238 if (orion_cpu_win_can_remap(win)) {
239 if (remap >= 0) {
240 orion_write(CPU_WIN_REMAP_LO(win), remap & 0xffff0000);
241 orion_write(CPU_WIN_REMAP_HI(win), 0);
242 } else {
243 orion_write(CPU_WIN_REMAP_LO(win), base);
244 orion_write(CPU_WIN_REMAP_HI(win), 0);
245 }
246 }
247}
248
249void __init orion_setup_cpu_wins(void)
250{
251 int i;
252
253 /*
254 * First, disable and clear windows
255 */
256 for (i = 0; i < CPU_MAX_WIN; i++) {
257 orion_write(CPU_WIN_BASE(i), 0);
258 orion_write(CPU_WIN_CTRL(i), 0);
259 if (orion_cpu_win_can_remap(i)) {
260 orion_write(CPU_WIN_REMAP_LO(i), 0);
261 orion_write(CPU_WIN_REMAP_HI(i), 0);
262 }
263 }
264
265 /*
266 * Setup windows for PCI+PCIE IO+MAM space
267 */
268 orion_setup_cpu_win(ORION_PCIE_IO, ORION_PCIE_IO_BASE,
269 ORION_PCIE_IO_SIZE, ORION_PCIE_IO_REMAP);
270 orion_setup_cpu_win(ORION_PCI_IO, ORION_PCI_IO_BASE,
271 ORION_PCI_IO_SIZE, ORION_PCI_IO_REMAP);
272 orion_setup_cpu_win(ORION_PCIE_MEM, ORION_PCIE_MEM_BASE,
273 ORION_PCIE_MEM_SIZE, -1);
274 orion_setup_cpu_win(ORION_PCI_MEM, ORION_PCI_MEM_BASE,
275 ORION_PCI_MEM_SIZE, -1);
276}
277
278/*
279 * Setup PCIE BARs and Address Decode Wins:
280 * BAR[0,2] -> disabled, BAR[1] -> covers all DRAM banks
281 * WIN[0-3] -> DRAM bank[0-3]
282 */
283void __init orion_setup_pcie_wins(void)
284{
285 u32 base, size, i;
286
287 /*
288 * First, disable and clear BARs and windows
289 */
290 for (i = 1; i < PCIE_MAX_BARS; i++) {
291 orion_write(PCIE_BAR_CTRL(i), 0);
292 orion_write(PCIE_BAR_LO(i), 0);
293 orion_write(PCIE_BAR_HI(i), 0);
294 }
295
296 for (i = 0; i < PCIE_MAX_WINS; i++) {
297 orion_write(PCIE_WIN_CTRL(i), 0);
298 orion_write(PCIE_WIN_BASE(i), 0);
299 orion_write(PCIE_WIN_REMAP(i), 0);
300 }
301
302 /*
303 * Setup windows for DDR banks. Count total DDR size on the fly.
304 */
305 base = DDR_REG_TO_BASE(orion_read(DDR_BASE_CS(0)));
306 size = 0;
307 for (i = 0; i < DDR_MAX_CS; i++) {
308 u32 bank_base, bank_size;
309 bank_size = orion_read(DDR_SIZE_CS(i));
310 bank_base = orion_read(DDR_BASE_CS(i));
311 if (bank_size & DDR_BANK_EN) {
312 bank_size = DDR_REG_TO_SIZE(bank_size);
313 bank_base = DDR_REG_TO_BASE(bank_base);
314 orion_write(PCIE_WIN_BASE(i), bank_base & 0xffff0000);
315 orion_write(PCIE_WIN_REMAP(i), 0);
316 orion_write(PCIE_WIN_CTRL(i),
317 ((bank_size-1) & 0xffff0000) |
318 (ATTR_DDR_CS(i) << 8) |
319 (TARGET_DDR << 4) |
320 (PCIE_DRAM_BAR << 1) | WIN_EN);
321 size += bank_size;
322 }
323 }
324
325 /*
326 * Setup BAR[1] to all DRAM banks
327 */
328 orion_write(PCIE_BAR_LO(PCIE_DRAM_BAR), base & 0xffff0000);
329 orion_write(PCIE_BAR_HI(PCIE_DRAM_BAR), 0);
330 orion_write(PCIE_BAR_CTRL(PCIE_DRAM_BAR),
331 ((size - 1) & 0xffff0000) | WIN_EN);
332}
333
334void __init orion_setup_pci_wins(void)
335{
336 u32 base, size, i;
337
338 /*
339 * First, disable windows
340 */
341 orion_write(PCI_BAR_ENABLE, 0xffffffff);
342
343 /*
344 * Setup windows for DDR banks.
345 */
346 for (i = 0; i < DDR_MAX_CS; i++) {
347 base = orion_read(DDR_BASE_CS(i));
348 size = orion_read(DDR_SIZE_CS(i));
349 if (size & DDR_BANK_EN) {
350 u32 bus, dev, func, reg, val;
351 size = DDR_REG_TO_SIZE(size);
352 base = DDR_REG_TO_BASE(base);
353 bus = orion_pci_local_bus_nr();
354 dev = orion_pci_local_dev_nr();
355 func = PCI_CONF_FUNC_BAR_CS(i);
356 reg = PCI_CONF_REG_BAR_LO_CS(i);
357 orion_pci_hw_rd_conf(bus, dev, func, reg, 4, &val);
358 orion_pci_hw_wr_conf(bus, dev, func, reg, 4,
359 (base & 0xfffff000) | (val & 0xfff));
360 reg = PCI_CONF_REG_BAR_HI_CS(i);
361 orion_pci_hw_wr_conf(bus, dev, func, reg, 4, 0);
362 orion_write(PCI_BAR_SIZE_DDR_CS(i),
363 (size - 1) & 0xfffff000);
364 orion_write(PCI_BAR_REMAP_DDR_CS(i),
365 base & 0xfffff000);
366 orion_clrbits(PCI_BAR_ENABLE, (1 << i));
367 }
368 }
369
370 /*
371 * Disable automatic update of address remaping when writing to BARs
372 */
373 orion_setbits(PCI_ADDR_DECODE_CTRL, 1);
374}
375
376void __init orion_setup_usb_wins(void)
377{
378 int i;
379 u32 usb_if, dev, rev;
380 u32 max_usb_if = 1;
381
382 orion_pcie_id(&dev, &rev);
383 if (dev == MV88F5182_DEV_ID)
384 max_usb_if = 2;
385
386 for (usb_if = 0; usb_if < max_usb_if; usb_if++) {
387 /*
388 * First, disable and clear windows
389 */
390 for (i = 0; i < USB_MAX_WIN; i++) {
391 orion_write(USB_WIN_BASE(usb_if, i), 0);
392 orion_write(USB_WIN_CTRL(usb_if, i), 0);
393 }
394
395 /*
396 * Setup windows for DDR banks.
397 */
398 for (i = 0; i < DDR_MAX_CS; i++) {
399 u32 base, size;
400 size = orion_read(DDR_SIZE_CS(i));
401 base = orion_read(DDR_BASE_CS(i));
402 if (size & DDR_BANK_EN) {
403 base = DDR_REG_TO_BASE(base);
404 size = DDR_REG_TO_SIZE(size);
405 orion_write(USB_WIN_CTRL(usb_if, i),
406 ((size-1) & 0xffff0000) |
407 (ATTR_DDR_CS(i) << 8) |
408 (TARGET_DDR << 4) | WIN_EN);
409 orion_write(USB_WIN_BASE(usb_if, i),
410 base & 0xffff0000);
411 }
412 }
413 }
414}
415
416void __init orion_setup_eth_wins(void)
417{
418 int i;
419
420 /*
421 * First, disable and clear windows
422 */
423 for (i = 0; i < ETH_MAX_WIN; i++) {
424 orion_write(ETH_WIN_BASE(i), 0);
425 orion_write(ETH_WIN_SIZE(i), 0);
426 orion_setbits(ETH_WIN_EN, 1 << i);
427 orion_clrbits(ETH_WIN_PROT, 0x3 << (i * 2));
428 if (i < ETH_MAX_REMAP_WIN)
429 orion_write(ETH_WIN_REMAP(i), 0);
430 }
431
432 /*
433 * Setup windows for DDR banks.
434 */
435 for (i = 0; i < DDR_MAX_CS; i++) {
436 u32 base, size;
437 size = orion_read(DDR_SIZE_CS(i));
438 base = orion_read(DDR_BASE_CS(i));
439 if (size & DDR_BANK_EN) {
440 base = DDR_REG_TO_BASE(base);
441 size = DDR_REG_TO_SIZE(size);
442 orion_write(ETH_WIN_SIZE(i), (size-1) & 0xffff0000);
443 orion_write(ETH_WIN_BASE(i), (base & 0xffff0000) |
444 (ATTR_DDR_CS(i) << 8) |
445 TARGET_DDR);
446 orion_clrbits(ETH_WIN_EN, 1 << i);
447 orion_setbits(ETH_WIN_PROT, 0x3 << (i * 2));
448 }
449 }
450}
451
452void __init orion_setup_sata_wins(void)
453{
454 int i;
455
456 /*
457 * First, disable and clear windows
458 */
459 for (i = 0; i < SATA_MAX_WIN; i++) {
460 orion_write(SATA_WIN_BASE(i), 0);
461 orion_write(SATA_WIN_CTRL(i), 0);
462 }
463
464 /*
465 * Setup windows for DDR banks.
466 */
467 for (i = 0; i < DDR_MAX_CS; i++) {
468 u32 base, size;
469 size = orion_read(DDR_SIZE_CS(i));
470 base = orion_read(DDR_BASE_CS(i));
471 if (size & DDR_BANK_EN) {
472 base = DDR_REG_TO_BASE(base);
473 size = DDR_REG_TO_SIZE(size);
474 orion_write(SATA_WIN_CTRL(i),
475 ((size-1) & 0xffff0000) |
476 (ATTR_DDR_CS(i) << 8) |
477 (TARGET_DDR << 4) | WIN_EN);
478 orion_write(SATA_WIN_BASE(i),
479 base & 0xffff0000);
480 }
481 }
482}