blob: 0f07e963de3c39bed141daf45e3df1ba0b70c123 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
2/*
3 * arch/ppc/platforms/hdpu_setup.c
4 *
5 * Board setup routines for the Sky Computers HDPU Compute Blade.
6 *
7 * Written by Brian Waite <waite@skycomputers.com>
8 *
9 * Based on code done by - Mark A. Greer <mgreer@mvista.com>
10 * Rabeeh Khoury - rabeeh@galileo.co.il
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
16 */
17
18#include <linux/config.h>
19
20#include <linux/pci.h>
21#include <linux/delay.h>
22#include <linux/irq.h>
23#include <linux/ide.h>
24#include <linux/seq_file.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010025#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27#include <linux/initrd.h>
28#include <linux/root_dev.h>
29#include <linux/smp.h>
30
31#include <asm/time.h>
32#include <asm/machdep.h>
33#include <asm/todc.h>
34#include <asm/mv64x60.h>
35#include <asm/ppcboot.h>
36#include <platforms/hdpu.h>
37#include <linux/mv643xx.h>
38#include <linux/hdpu_features.h>
39#include <linux/device.h>
40#include <linux/mtd/physmap.h>
41
42#define BOARD_VENDOR "Sky Computers"
43#define BOARD_MACHINE "HDPU-CB-A"
44
45bd_t ppcboot_bd;
46int ppcboot_bd_valid = 0;
47
48static mv64x60_handle_t bh;
49
50extern char cmd_line[];
51
52unsigned long hdpu_find_end_of_memory(void);
53void hdpu_mpsc_progress(char *s, unsigned short hex);
54void hdpu_heartbeat(void);
55
56static void parse_bootinfo(unsigned long r3,
57 unsigned long r4, unsigned long r5,
58 unsigned long r6, unsigned long r7);
59static void hdpu_set_l1pe(void);
60static void hdpu_cpustate_set(unsigned char new_state);
61#ifdef CONFIG_SMP
Ingo Molnara9f6a0d2005-09-09 13:10:41 -070062static DEFINE_SPINLOCK(timebase_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063static unsigned int timebase_upper = 0, timebase_lower = 0;
64extern int smp_tb_synchronized;
65
66void __devinit hdpu_tben_give(void);
67void __devinit hdpu_tben_take(void);
68#endif
69
70static int __init
71hdpu_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
72{
73 struct pci_controller *hose = pci_bus_to_hose(dev->bus->number);
74
75 if (hose->index == 0) {
76 static char pci_irq_table[][4] = {
77 {HDPU_PCI_0_IRQ, 0, 0, 0},
78 {HDPU_PCI_0_IRQ, 0, 0, 0},
79 };
80
81 const long min_idsel = 1, max_idsel = 2, irqs_per_slot = 4;
82 return PCI_IRQ_TABLE_LOOKUP;
83 } else {
84 static char pci_irq_table[][4] = {
85 {HDPU_PCI_1_IRQ, 0, 0, 0},
86 };
87
88 const long min_idsel = 1, max_idsel = 1, irqs_per_slot = 4;
89 return PCI_IRQ_TABLE_LOOKUP;
90 }
91}
92
93static void __init hdpu_intr_setup(void)
94{
95 mv64x60_write(&bh, MV64x60_GPP_IO_CNTL,
96 (1 | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5) |
97 (1 << 6) | (1 << 7) | (1 << 12) | (1 << 16) |
98 (1 << 18) | (1 << 19) | (1 << 20) | (1 << 21) |
99 (1 << 22) | (1 << 23) | (1 << 24) | (1 << 25) |
100 (1 << 26) | (1 << 27) | (1 << 28) | (1 << 29)));
101
102 /* XXXX Erranum FEr PCI-#8 */
103 mv64x60_clr_bits(&bh, MV64x60_PCI0_CMD, (1 << 5) | (1 << 9));
104 mv64x60_clr_bits(&bh, MV64x60_PCI1_CMD, (1 << 5) | (1 << 9));
105
106 /*
107 * Dismiss and then enable interrupt on GPP interrupt cause
108 * for CPU #0
109 */
110 mv64x60_write(&bh, MV64x60_GPP_INTR_CAUSE, ~((1 << 8) | (1 << 13)));
111 mv64x60_set_bits(&bh, MV64x60_GPP_INTR_MASK, (1 << 8) | (1 << 13));
112
113 /*
114 * Dismiss and then enable interrupt on CPU #0 high cause reg
115 * BIT25 summarizes GPP interrupts 8-15
116 */
117 mv64x60_set_bits(&bh, MV64360_IC_CPU0_INTR_MASK_HI, (1 << 25));
118}
119
120static void __init hdpu_setup_peripherals(void)
121{
122 unsigned int val;
123
124 mv64x60_set_32bit_window(&bh, MV64x60_CPU2BOOT_WIN,
125 HDPU_EMB_FLASH_BASE, HDPU_EMB_FLASH_SIZE, 0);
126 bh.ci->enable_window_32bit(&bh, MV64x60_CPU2BOOT_WIN);
127
128 mv64x60_set_32bit_window(&bh, MV64x60_CPU2DEV_0_WIN,
129 HDPU_TBEN_BASE, HDPU_TBEN_SIZE, 0);
130 bh.ci->enable_window_32bit(&bh, MV64x60_CPU2DEV_0_WIN);
131
132 mv64x60_set_32bit_window(&bh, MV64x60_CPU2DEV_1_WIN,
133 HDPU_NEXUS_ID_BASE, HDPU_NEXUS_ID_SIZE, 0);
134 bh.ci->enable_window_32bit(&bh, MV64x60_CPU2DEV_1_WIN);
135
136 mv64x60_set_32bit_window(&bh, MV64x60_CPU2SRAM_WIN,
137 HDPU_INTERNAL_SRAM_BASE,
138 HDPU_INTERNAL_SRAM_SIZE, 0);
139 bh.ci->enable_window_32bit(&bh, MV64x60_CPU2SRAM_WIN);
140
141 bh.ci->disable_window_32bit(&bh, MV64x60_ENET2MEM_4_WIN);
142 mv64x60_set_32bit_window(&bh, MV64x60_ENET2MEM_4_WIN, 0, 0, 0);
143
144 mv64x60_clr_bits(&bh, MV64x60_PCI0_PCI_DECODE_CNTL, (1 << 3));
145 mv64x60_clr_bits(&bh, MV64x60_PCI1_PCI_DECODE_CNTL, (1 << 3));
146 mv64x60_clr_bits(&bh, MV64x60_TIMR_CNTR_0_3_CNTL,
147 ((1 << 0) | (1 << 8) | (1 << 16) | (1 << 24)));
148
149 /* Enable pipelining */
150 mv64x60_set_bits(&bh, MV64x60_CPU_CONFIG, (1 << 13));
151 /* Enable Snoop Pipelineing */
152 mv64x60_set_bits(&bh, MV64360_D_UNIT_CONTROL_HIGH, (1 << 24));
153
154 /*
155 * Change DRAM read buffer assignment.
156 * Assign read buffer 0 dedicated only for CPU,
157 * and the rest read buffer 1.
158 */
159 val = mv64x60_read(&bh, MV64360_SDRAM_CONFIG);
160 val = val & 0x03ffffff;
161 val = val | 0xf8000000;
162 mv64x60_write(&bh, MV64360_SDRAM_CONFIG, val);
163
164 /*
165 * Configure internal SRAM -
166 * Cache coherent write back, if CONFIG_MV64360_SRAM_CACHE_COHERENT set
167 * Parity enabled.
168 * Parity error propagation
169 * Arbitration not parked for CPU only
170 * Other bits are reserved.
171 */
172#ifdef CONFIG_MV64360_SRAM_CACHE_COHERENT
173 mv64x60_write(&bh, MV64360_SRAM_CONFIG, 0x001600b2);
174#else
175 mv64x60_write(&bh, MV64360_SRAM_CONFIG, 0x001600b0);
176#endif
177
178 hdpu_intr_setup();
179}
180
181static void __init hdpu_setup_bridge(void)
182{
183 struct mv64x60_setup_info si;
184 int i;
185
186 memset(&si, 0, sizeof(si));
187
188 si.phys_reg_base = HDPU_BRIDGE_REG_BASE;
189 si.pci_0.enable_bus = 1;
190 si.pci_0.pci_io.cpu_base = HDPU_PCI0_IO_START_PROC_ADDR;
191 si.pci_0.pci_io.pci_base_hi = 0;
192 si.pci_0.pci_io.pci_base_lo = HDPU_PCI0_IO_START_PCI_ADDR;
193 si.pci_0.pci_io.size = HDPU_PCI0_IO_SIZE;
194 si.pci_0.pci_io.swap = MV64x60_CPU2PCI_SWAP_NONE;
195 si.pci_0.pci_mem[0].cpu_base = HDPU_PCI0_MEM_START_PROC_ADDR;
196 si.pci_0.pci_mem[0].pci_base_hi = HDPU_PCI0_MEM_START_PCI_HI_ADDR;
197 si.pci_0.pci_mem[0].pci_base_lo = HDPU_PCI0_MEM_START_PCI_LO_ADDR;
198 si.pci_0.pci_mem[0].size = HDPU_PCI0_MEM_SIZE;
199 si.pci_0.pci_mem[0].swap = MV64x60_CPU2PCI_SWAP_NONE;
200 si.pci_0.pci_cmd_bits = 0;
201 si.pci_0.latency_timer = 0x80;
202
203 si.pci_1.enable_bus = 1;
204 si.pci_1.pci_io.cpu_base = HDPU_PCI1_IO_START_PROC_ADDR;
205 si.pci_1.pci_io.pci_base_hi = 0;
206 si.pci_1.pci_io.pci_base_lo = HDPU_PCI1_IO_START_PCI_ADDR;
207 si.pci_1.pci_io.size = HDPU_PCI1_IO_SIZE;
208 si.pci_1.pci_io.swap = MV64x60_CPU2PCI_SWAP_NONE;
209 si.pci_1.pci_mem[0].cpu_base = HDPU_PCI1_MEM_START_PROC_ADDR;
210 si.pci_1.pci_mem[0].pci_base_hi = HDPU_PCI1_MEM_START_PCI_HI_ADDR;
211 si.pci_1.pci_mem[0].pci_base_lo = HDPU_PCI1_MEM_START_PCI_LO_ADDR;
212 si.pci_1.pci_mem[0].size = HDPU_PCI1_MEM_SIZE;
213 si.pci_1.pci_mem[0].swap = MV64x60_CPU2PCI_SWAP_NONE;
214 si.pci_1.pci_cmd_bits = 0;
215 si.pci_1.latency_timer = 0x80;
216
217 for (i = 0; i < MV64x60_CPU2MEM_WINDOWS; i++) {
218#if defined(CONFIG_NOT_COHERENT_CACHE)
219 si.cpu_prot_options[i] = 0;
220 si.enet_options[i] = MV64360_ENET2MEM_SNOOP_NONE;
221 si.mpsc_options[i] = MV64360_MPSC2MEM_SNOOP_NONE;
222 si.idma_options[i] = MV64360_IDMA2MEM_SNOOP_NONE;
223
224 si.pci_1.acc_cntl_options[i] =
225 MV64360_PCI_ACC_CNTL_SNOOP_NONE |
226 MV64360_PCI_ACC_CNTL_SWAP_NONE |
227 MV64360_PCI_ACC_CNTL_MBURST_128_BYTES |
228 MV64360_PCI_ACC_CNTL_RDSIZE_256_BYTES;
229
230 si.pci_0.acc_cntl_options[i] =
231 MV64360_PCI_ACC_CNTL_SNOOP_NONE |
232 MV64360_PCI_ACC_CNTL_SWAP_NONE |
233 MV64360_PCI_ACC_CNTL_MBURST_128_BYTES |
234 MV64360_PCI_ACC_CNTL_RDSIZE_256_BYTES;
235
236#else
237 si.cpu_prot_options[i] = 0;
238 si.enet_options[i] = MV64360_ENET2MEM_SNOOP_WB; /* errata */
239 si.mpsc_options[i] = MV64360_MPSC2MEM_SNOOP_WB; /* errata */
240 si.idma_options[i] = MV64360_IDMA2MEM_SNOOP_WB; /* errata */
241
242 si.pci_0.acc_cntl_options[i] =
243 MV64360_PCI_ACC_CNTL_SNOOP_WB |
244 MV64360_PCI_ACC_CNTL_SWAP_NONE |
245 MV64360_PCI_ACC_CNTL_MBURST_32_BYTES |
246 MV64360_PCI_ACC_CNTL_RDSIZE_256_BYTES;
247
248 si.pci_1.acc_cntl_options[i] =
249 MV64360_PCI_ACC_CNTL_SNOOP_WB |
250 MV64360_PCI_ACC_CNTL_SWAP_NONE |
251 MV64360_PCI_ACC_CNTL_MBURST_32_BYTES |
252 MV64360_PCI_ACC_CNTL_RDSIZE_256_BYTES;
253#endif
254 }
255
256 hdpu_cpustate_set(CPUSTATE_KERNEL_MAJOR | CPUSTATE_KERNEL_INIT_PCI);
257
258 /* Lookup PCI host bridges */
259 mv64x60_init(&bh, &si);
260 pci_dram_offset = 0; /* System mem at same addr on PCI & cpu bus */
261 ppc_md.pci_swizzle = common_swizzle;
262 ppc_md.pci_map_irq = hdpu_map_irq;
263
264 mv64x60_set_bus(&bh, 0, 0);
265 bh.hose_a->first_busno = 0;
266 bh.hose_a->last_busno = 0xff;
267 bh.hose_a->last_busno = pciauto_bus_scan(bh.hose_a, 0);
268
269 bh.hose_b->first_busno = bh.hose_a->last_busno + 1;
270 mv64x60_set_bus(&bh, 1, bh.hose_b->first_busno);
271 bh.hose_b->last_busno = 0xff;
272 bh.hose_b->last_busno = pciauto_bus_scan(bh.hose_b,
273 bh.hose_b->first_busno);
274
275 ppc_md.pci_exclude_device = mv64x60_pci_exclude_device;
276
277 hdpu_cpustate_set(CPUSTATE_KERNEL_MAJOR | CPUSTATE_KERNEL_INIT_REG);
278 /*
279 * Enabling of PCI internal-vs-external arbitration
280 * is a platform- and errata-dependent decision.
281 */
282 return;
283}
284
285#if defined(CONFIG_SERIAL_MPSC_CONSOLE)
286static void __init hdpu_early_serial_map(void)
287{
288#ifdef CONFIG_KGDB
289 static char first_time = 1;
290
291#if defined(CONFIG_KGDB_TTYS0)
292#define KGDB_PORT 0
293#elif defined(CONFIG_KGDB_TTYS1)
294#define KGDB_PORT 1
295#else
296#error "Invalid kgdb_tty port"
297#endif
298
299 if (first_time) {
300 gt_early_mpsc_init(KGDB_PORT,
301 B9600 | CS8 | CREAD | HUPCL | CLOCAL);
302 first_time = 0;
303 }
304
305 return;
306#endif
307}
308#endif
309
310static void hdpu_init2(void)
311{
312 return;
313}
314
315#if defined(CONFIG_MV643XX_ETH)
316static void __init hdpu_fixup_eth_pdata(struct platform_device *pd)
317{
318
319 struct mv643xx_eth_platform_data *eth_pd;
320 eth_pd = pd->dev.platform_data;
321
322 eth_pd->port_serial_control =
323 mv64x60_read(&bh, MV643XX_ETH_PORT_SERIAL_CONTROL_REG(pd->id) & ~1);
324
325 eth_pd->force_phy_addr = 1;
326 eth_pd->phy_addr = pd->id;
327 eth_pd->tx_queue_size = 400;
328 eth_pd->rx_queue_size = 800;
329}
330#endif
331
332static void __init hdpu_fixup_mpsc_pdata(struct platform_device *pd)
333{
334
335 struct mpsc_pdata *pdata;
336
337 pdata = (struct mpsc_pdata *)pd->dev.platform_data;
338
339 pdata->max_idle = 40;
340 if (ppcboot_bd_valid)
341 pdata->default_baud = ppcboot_bd.bi_baudrate;
342 else
343 pdata->default_baud = HDPU_DEFAULT_BAUD;
344 pdata->brg_clk_src = HDPU_MPSC_CLK_SRC;
345 pdata->brg_clk_freq = HDPU_MPSC_CLK_FREQ;
346}
347
348#if defined(CONFIG_HDPU_FEATURES)
349static void __init hdpu_fixup_cpustate_pdata(struct platform_device *pd)
350{
351 struct platform_device *pds[1];
352 pds[0] = pd;
353 mv64x60_pd_fixup(&bh, pds, 1);
354}
355#endif
356
357static int __init hdpu_platform_notify(struct device *dev)
358{
359 static struct {
360 char *bus_id;
361 void ((*rtn) (struct platform_device * pdev));
362 } dev_map[] = {
363 {
364 MPSC_CTLR_NAME ".0", hdpu_fixup_mpsc_pdata},
365#if defined(CONFIG_MV643XX_ETH)
366 {
367 MV643XX_ETH_NAME ".0", hdpu_fixup_eth_pdata},
368#endif
369#if defined(CONFIG_HDPU_FEATURES)
370 {
371 HDPU_CPUSTATE_NAME ".0", hdpu_fixup_cpustate_pdata},
372#endif
373 };
374 struct platform_device *pdev;
375 int i;
376
377 if (dev && dev->bus_id)
378 for (i = 0; i < ARRAY_SIZE(dev_map); i++)
379 if (!strncmp(dev->bus_id, dev_map[i].bus_id,
380 BUS_ID_SIZE)) {
381
382 pdev = container_of(dev,
383 struct platform_device,
384 dev);
385 dev_map[i].rtn(pdev);
386 }
387
388 return 0;
389}
390
391static void __init hdpu_setup_arch(void)
392{
393 if (ppc_md.progress)
394 ppc_md.progress("hdpu_setup_arch: enter", 0);
395#ifdef CONFIG_BLK_DEV_INITRD
396 if (initrd_start)
397 ROOT_DEV = Root_RAM0;
398 else
399#endif
400#ifdef CONFIG_ROOT_NFS
401 ROOT_DEV = Root_NFS;
402#else
403 ROOT_DEV = Root_SDA2;
404#endif
405
406 ppc_md.heartbeat = hdpu_heartbeat;
407
408 ppc_md.heartbeat_reset = HZ;
409 ppc_md.heartbeat_count = 1;
410
411 if (ppc_md.progress)
412 ppc_md.progress("hdpu_setup_arch: Enabling L2 cache", 0);
413
414 /* Enable L1 Parity Bits */
415 hdpu_set_l1pe();
416
417 /* Enable L2 and L3 caches (if 745x) */
418 _set_L2CR(0x80080000);
419
420 if (ppc_md.progress)
421 ppc_md.progress("hdpu_setup_arch: enter", 0);
422
423 hdpu_setup_bridge();
424
425 hdpu_setup_peripherals();
426
427#ifdef CONFIG_SERIAL_MPSC_CONSOLE
428 hdpu_early_serial_map();
429#endif
430
431 printk("SKY HDPU Compute Blade \n");
432
433 if (ppc_md.progress)
434 ppc_md.progress("hdpu_setup_arch: exit", 0);
435
436 hdpu_cpustate_set(CPUSTATE_KERNEL_MAJOR | CPUSTATE_KERNEL_OK);
437 return;
438}
439static void __init hdpu_init_irq(void)
440{
441 mv64360_init_irq();
442}
443
444static void __init hdpu_set_l1pe()
445{
446 unsigned long ictrl;
447 asm volatile ("mfspr %0, 1011":"=r" (ictrl):);
448 ictrl |= ICTRL_EICE | ICTRL_EDC | ICTRL_EICP;
449 asm volatile ("mtspr 1011, %0"::"r" (ictrl));
450}
451
452/*
453 * Set BAT 1 to map 0xf1000000 to end of physical memory space.
454 */
455static __inline__ void hdpu_set_bat(void)
456{
457 mb();
458 mtspr(SPRN_DBAT1U, 0xf10001fe);
459 mtspr(SPRN_DBAT1L, 0xf100002a);
460 mb();
461
462 return;
463}
464
465unsigned long __init hdpu_find_end_of_memory(void)
466{
467 return mv64x60_get_mem_size(CONFIG_MV64X60_NEW_BASE,
468 MV64x60_TYPE_MV64360);
469}
470
471static void hdpu_reset_board(void)
472{
473 volatile int infinite = 1;
474
475 hdpu_cpustate_set(CPUSTATE_KERNEL_MAJOR | CPUSTATE_KERNEL_RESET);
476
477 local_irq_disable();
478
479 /* Clear all the LEDs */
480 mv64x60_write(&bh, MV64x60_GPP_VALUE_CLR, ((1 << 4) |
481 (1 << 5) | (1 << 6)));
482
483 /* disable and invalidate the L2 cache */
484 _set_L2CR(0);
485 _set_L2CR(0x200000);
486
487 /* flush and disable L1 I/D cache */
488 __asm__ __volatile__
489 ("\n"
490 "mfspr 3,1008\n"
491 "ori 5,5,0xcc00\n"
492 "ori 4,3,0xc00\n"
493 "andc 5,3,5\n"
494 "sync\n"
495 "mtspr 1008,4\n"
496 "isync\n" "sync\n" "mtspr 1008,5\n" "isync\n" "sync\n");
497
498 /* Hit the reset bit */
499 mv64x60_write(&bh, MV64x60_GPP_VALUE_CLR, (1 << 3));
500
501 while (infinite)
502 infinite = infinite;
503
504 return;
505}
506
507static void hdpu_restart(char *cmd)
508{
509 volatile ulong i = 10000000;
510
511 hdpu_reset_board();
512
513 while (i-- > 0) ;
514 panic("restart failed\n");
515}
516
517static void hdpu_halt(void)
518{
519 local_irq_disable();
520
521 hdpu_cpustate_set(CPUSTATE_KERNEL_MAJOR | CPUSTATE_KERNEL_HALT);
522
523 /* Clear all the LEDs */
524 mv64x60_write(&bh, MV64x60_GPP_VALUE_CLR, ((1 << 4) | (1 << 5) |
525 (1 << 6)));
526 while (1) ;
527 /* NOTREACHED */
528}
529
530static void hdpu_power_off(void)
531{
532 hdpu_halt();
533 /* NOTREACHED */
534}
535
536static int hdpu_show_cpuinfo(struct seq_file *m)
537{
538 uint pvid;
539
540 pvid = mfspr(SPRN_PVR);
541 seq_printf(m, "vendor\t\t: Sky Computers\n");
542 seq_printf(m, "machine\t\t: HDPU Compute Blade\n");
543 seq_printf(m, "PVID\t\t: 0x%x, vendor: %s\n",
544 pvid, (pvid & (1 << 15) ? "IBM" : "Motorola"));
545
546 return 0;
547}
548
549static void __init hdpu_calibrate_decr(void)
550{
551 ulong freq;
552
553 if (ppcboot_bd_valid)
554 freq = ppcboot_bd.bi_busfreq / 4;
555 else
556 freq = 133000000;
557
558 printk("time_init: decrementer frequency = %lu.%.6lu MHz\n",
559 freq / 1000000, freq % 1000000);
560
561 tb_ticks_per_jiffy = freq / HZ;
562 tb_to_us = mulhwu_scale_factor(freq, 1000000);
563
564 return;
565}
566
567static void parse_bootinfo(unsigned long r3,
568 unsigned long r4, unsigned long r5,
569 unsigned long r6, unsigned long r7)
570{
571 bd_t *bd = NULL;
572 char *cmdline_start = NULL;
573 int cmdline_len = 0;
574
575 if (r3) {
576 if ((r3 & 0xf0000000) == 0)
577 r3 += KERNELBASE;
578 if ((r3 & 0xf0000000) == KERNELBASE) {
579 bd = (void *)r3;
580
581 memcpy(&ppcboot_bd, bd, sizeof(ppcboot_bd));
582 ppcboot_bd_valid = 1;
583 }
584 }
585#ifdef CONFIG_BLK_DEV_INITRD
586 if (r4 && r5 && r5 > r4) {
587 if ((r4 & 0xf0000000) == 0)
588 r4 += KERNELBASE;
589 if ((r5 & 0xf0000000) == 0)
590 r5 += KERNELBASE;
591 if ((r4 & 0xf0000000) == KERNELBASE) {
592 initrd_start = r4;
593 initrd_end = r5;
594 initrd_below_start_ok = 1;
595 }
596 }
597#endif /* CONFIG_BLK_DEV_INITRD */
598
599 if (r6 && r7 && r7 > r6) {
600 if ((r6 & 0xf0000000) == 0)
601 r6 += KERNELBASE;
602 if ((r7 & 0xf0000000) == 0)
603 r7 += KERNELBASE;
604 if ((r6 & 0xf0000000) == KERNELBASE) {
605 cmdline_start = (void *)r6;
606 cmdline_len = (r7 - r6);
607 strncpy(cmd_line, cmdline_start, cmdline_len);
608 }
609 }
610}
611
612#if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
613static int hdpu_ide_check_region(ide_ioreg_t from, unsigned int extent)
614{
615 return check_region(from, extent);
616}
617
618static void
619hdpu_ide_request_region(ide_ioreg_t from, unsigned int extent, const char *name)
620{
621 request_region(from, extent, name);
622 return;
623}
624
625static void hdpu_ide_release_region(ide_ioreg_t from, unsigned int extent)
626{
627 release_region(from, extent);
628 return;
629}
630
631static void __init
632hdpu_ide_pci_init_hwif_ports(hw_regs_t * hw, ide_ioreg_t data_port,
633 ide_ioreg_t ctrl_port, int *irq)
634{
635 struct pci_dev *dev;
636
637 pci_for_each_dev(dev) {
638 if (((dev->class >> 8) == PCI_CLASS_STORAGE_IDE) ||
639 ((dev->class >> 8) == PCI_CLASS_STORAGE_RAID)) {
640 hw->irq = dev->irq;
641
642 if (irq != NULL) {
643 *irq = dev->irq;
644 }
645 }
646 }
647
648 return;
649}
650#endif
651
652void hdpu_heartbeat(void)
653{
654 if (mv64x60_read(&bh, MV64x60_GPP_VALUE) & (1 << 5))
655 mv64x60_write(&bh, MV64x60_GPP_VALUE_CLR, (1 << 5));
656 else
657 mv64x60_write(&bh, MV64x60_GPP_VALUE_SET, (1 << 5));
658
659 ppc_md.heartbeat_count = ppc_md.heartbeat_reset;
660
661}
662
663static void __init hdpu_map_io(void)
664{
665 io_block_mapping(0xf1000000, 0xf1000000, 0x20000, _PAGE_IO);
666}
667
668#ifdef CONFIG_SMP
669char hdpu_smp0[] = "SMP Cpu #0";
670char hdpu_smp1[] = "SMP Cpu #1";
671
672static irqreturn_t hdpu_smp_cpu0_int_handler(int irq, void *dev_id,
673 struct pt_regs *regs)
674{
675 volatile unsigned int doorbell;
676
677 doorbell = mv64x60_read(&bh, MV64360_CPU0_DOORBELL);
678
679 /* Ack the doorbell interrupts */
680 mv64x60_write(&bh, MV64360_CPU0_DOORBELL_CLR, doorbell);
681
682 if (doorbell & 1) {
683 smp_message_recv(0, regs);
684 }
685 if (doorbell & 2) {
686 smp_message_recv(1, regs);
687 }
688 if (doorbell & 4) {
689 smp_message_recv(2, regs);
690 }
691 if (doorbell & 8) {
692 smp_message_recv(3, regs);
693 }
694 return IRQ_HANDLED;
695}
696
697static irqreturn_t hdpu_smp_cpu1_int_handler(int irq, void *dev_id,
698 struct pt_regs *regs)
699{
700 volatile unsigned int doorbell;
701
702 doorbell = mv64x60_read(&bh, MV64360_CPU1_DOORBELL);
703
704 /* Ack the doorbell interrupts */
705 mv64x60_write(&bh, MV64360_CPU1_DOORBELL_CLR, doorbell);
706
707 if (doorbell & 1) {
708 smp_message_recv(0, regs);
709 }
710 if (doorbell & 2) {
711 smp_message_recv(1, regs);
712 }
713 if (doorbell & 4) {
714 smp_message_recv(2, regs);
715 }
716 if (doorbell & 8) {
717 smp_message_recv(3, regs);
718 }
719 return IRQ_HANDLED;
720}
721
722static void smp_hdpu_CPU_two(void)
723{
724 __asm__ __volatile__
725 ("\n"
726 "lis 3,0x0000\n"
727 "ori 3,3,0x00c0\n"
728 "mtspr 26, 3\n" "li 4,0\n" "mtspr 27,4\n" "rfi");
729
730}
731
732static int smp_hdpu_probe(void)
733{
734 int *cpu_count_reg;
735 int num_cpus = 0;
736
737 cpu_count_reg = ioremap(HDPU_NEXUS_ID_BASE, HDPU_NEXUS_ID_SIZE);
738 if (cpu_count_reg) {
739 num_cpus = (*cpu_count_reg >> 20) & 0x3;
740 iounmap(cpu_count_reg);
741 }
742
743 /* Validate the bits in the CPLD. If we could not map the reg, return 2.
744 * If the register reported 0 or 3, return 2.
745 * Older CPLD revisions set these bits to all ones (val = 3).
746 */
747 if ((num_cpus < 1) || (num_cpus > 2)) {
748 printk
749 ("Unable to determine the number of processors %d . deafulting to 2.\n",
750 num_cpus);
751 num_cpus = 2;
752 }
753 return num_cpus;
754}
755
756static void
757smp_hdpu_message_pass(int target, int msg, unsigned long data, int wait)
758{
759 if (msg > 0x3) {
760 printk("SMP %d: smp_message_pass: unknown msg %d\n",
761 smp_processor_id(), msg);
762 return;
763 }
764 switch (target) {
765 case MSG_ALL:
766 mv64x60_write(&bh, MV64360_CPU0_DOORBELL, 1 << msg);
767 mv64x60_write(&bh, MV64360_CPU1_DOORBELL, 1 << msg);
768 break;
769 case MSG_ALL_BUT_SELF:
770 if (smp_processor_id())
771 mv64x60_write(&bh, MV64360_CPU0_DOORBELL, 1 << msg);
772 else
773 mv64x60_write(&bh, MV64360_CPU1_DOORBELL, 1 << msg);
774 break;
775 default:
776 if (target == 0)
777 mv64x60_write(&bh, MV64360_CPU0_DOORBELL, 1 << msg);
778 else
779 mv64x60_write(&bh, MV64360_CPU1_DOORBELL, 1 << msg);
780 break;
781 }
782}
783
784static void smp_hdpu_kick_cpu(int nr)
785{
786 volatile unsigned int *bootaddr;
787
788 if (ppc_md.progress)
789 ppc_md.progress("smp_hdpu_kick_cpu", 0);
790
791 hdpu_cpustate_set(CPUSTATE_KERNEL_MAJOR | CPUSTATE_KERNEL_CPU1_KICK);
792
793 /* Disable BootCS. Must also reduce the windows size to zero. */
794 bh.ci->disable_window_32bit(&bh, MV64x60_CPU2BOOT_WIN);
795 mv64x60_set_32bit_window(&bh, MV64x60_CPU2BOOT_WIN, 0, 0, 0);
796
797 bootaddr = ioremap(HDPU_INTERNAL_SRAM_BASE, HDPU_INTERNAL_SRAM_SIZE);
798 if (!bootaddr) {
799 if (ppc_md.progress)
800 ppc_md.progress("smp_hdpu_kick_cpu: ioremap failed", 0);
801 return;
802 }
803
804 memcpy((void *)(bootaddr + 0x40), (void *)&smp_hdpu_CPU_two, 0x20);
805
806 /* map SRAM to 0xfff00000 */
807 bh.ci->disable_window_32bit(&bh, MV64x60_CPU2SRAM_WIN);
808
809 mv64x60_set_32bit_window(&bh, MV64x60_CPU2SRAM_WIN,
810 0xfff00000, HDPU_INTERNAL_SRAM_SIZE, 0);
811 bh.ci->enable_window_32bit(&bh, MV64x60_CPU2SRAM_WIN);
812
813 /* Enable CPU1 arbitration */
814 mv64x60_clr_bits(&bh, MV64x60_CPU_MASTER_CNTL, (1 << 9));
815
816 /*
817 * Wait 100mSecond until other CPU has reached __secondary_start.
818 * When it reaches, it is permittable to rever the SRAM mapping etc...
819 */
820 mdelay(100);
821 *(unsigned long *)KERNELBASE = nr;
822 asm volatile ("dcbf 0,%0"::"r" (KERNELBASE):"memory");
823
824 iounmap(bootaddr);
825
826 /* Set up window for internal sram (256KByte insize) */
827 bh.ci->disable_window_32bit(&bh, MV64x60_CPU2SRAM_WIN);
828 mv64x60_set_32bit_window(&bh, MV64x60_CPU2SRAM_WIN,
829 HDPU_INTERNAL_SRAM_BASE,
830 HDPU_INTERNAL_SRAM_SIZE, 0);
831 bh.ci->enable_window_32bit(&bh, MV64x60_CPU2SRAM_WIN);
832 /*
833 * Set up windows for embedded FLASH (using boot CS window).
834 */
835
836 bh.ci->disable_window_32bit(&bh, MV64x60_CPU2BOOT_WIN);
837 mv64x60_set_32bit_window(&bh, MV64x60_CPU2BOOT_WIN,
838 HDPU_EMB_FLASH_BASE, HDPU_EMB_FLASH_SIZE, 0);
839 bh.ci->enable_window_32bit(&bh, MV64x60_CPU2BOOT_WIN);
840}
841
842static void smp_hdpu_setup_cpu(int cpu_nr)
843{
844 if (cpu_nr == 0) {
845 if (ppc_md.progress)
846 ppc_md.progress("smp_hdpu_setup_cpu 0", 0);
847 mv64x60_write(&bh, MV64360_CPU0_DOORBELL_CLR, 0xff);
848 mv64x60_write(&bh, MV64360_CPU0_DOORBELL_MASK, 0xff);
849 request_irq(60, hdpu_smp_cpu0_int_handler,
850 SA_INTERRUPT, hdpu_smp0, 0);
851 }
852
853 if (cpu_nr == 1) {
854 if (ppc_md.progress)
855 ppc_md.progress("smp_hdpu_setup_cpu 1", 0);
856
857 hdpu_cpustate_set(CPUSTATE_KERNEL_MAJOR |
858 CPUSTATE_KERNEL_CPU1_OK);
859
860 /* Enable L1 Parity Bits */
861 hdpu_set_l1pe();
862
863 /* Enable L2 cache */
864 _set_L2CR(0);
865 _set_L2CR(0x80080000);
866
867 mv64x60_write(&bh, MV64360_CPU1_DOORBELL_CLR, 0x0);
868 mv64x60_write(&bh, MV64360_CPU1_DOORBELL_MASK, 0xff);
869 request_irq(28, hdpu_smp_cpu1_int_handler,
870 SA_INTERRUPT, hdpu_smp1, 0);
871 }
872
873}
874
875void __devinit hdpu_tben_give()
876{
877 volatile unsigned long *val = 0;
878
879 /* By writing 0 to the TBEN_BASE, the timebases is frozen */
880 val = ioremap(HDPU_TBEN_BASE, 4);
881 *val = 0;
882 mb();
883
884 spin_lock(&timebase_lock);
885 timebase_upper = get_tbu();
886 timebase_lower = get_tbl();
887 spin_unlock(&timebase_lock);
888
889 while (timebase_upper || timebase_lower)
890 barrier();
891
892 /* By writing 1 to the TBEN_BASE, the timebases is thawed */
893 *val = 1;
894 mb();
895
896 iounmap(val);
897
898}
899
900void __devinit hdpu_tben_take()
901{
902 while (!(timebase_upper || timebase_lower))
903 barrier();
904
905 spin_lock(&timebase_lock);
906 set_tb(timebase_upper, timebase_lower);
907 timebase_upper = 0;
908 timebase_lower = 0;
909 spin_unlock(&timebase_lock);
910}
911
912static struct smp_ops_t hdpu_smp_ops = {
913 .message_pass = smp_hdpu_message_pass,
914 .probe = smp_hdpu_probe,
915 .kick_cpu = smp_hdpu_kick_cpu,
916 .setup_cpu = smp_hdpu_setup_cpu,
917 .give_timebase = hdpu_tben_give,
918 .take_timebase = hdpu_tben_take,
919};
920#endif /* CONFIG_SMP */
921
922void __init
923platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
924 unsigned long r6, unsigned long r7)
925{
926 parse_bootinfo(r3, r4, r5, r6, r7);
927
928 isa_mem_base = 0;
929
930 ppc_md.setup_arch = hdpu_setup_arch;
931 ppc_md.init = hdpu_init2;
932 ppc_md.show_cpuinfo = hdpu_show_cpuinfo;
933 ppc_md.init_IRQ = hdpu_init_irq;
934 ppc_md.get_irq = mv64360_get_irq;
935 ppc_md.restart = hdpu_restart;
936 ppc_md.power_off = hdpu_power_off;
937 ppc_md.halt = hdpu_halt;
938 ppc_md.find_end_of_memory = hdpu_find_end_of_memory;
939 ppc_md.calibrate_decr = hdpu_calibrate_decr;
940 ppc_md.setup_io_mappings = hdpu_map_io;
941
942 bh.p_base = CONFIG_MV64X60_NEW_BASE;
943 bh.v_base = (unsigned long *)bh.p_base;
944
945 hdpu_set_bat();
946
947#if defined(CONFIG_SERIAL_TEXT_DEBUG)
948 ppc_md.progress = hdpu_mpsc_progress; /* embedded UART */
949 mv64x60_progress_init(bh.p_base);
950#endif /* CONFIG_SERIAL_TEXT_DEBUG */
951
952#ifdef CONFIG_SMP
953 ppc_md.smp_ops = &hdpu_smp_ops;
954#endif /* CONFIG_SMP */
955
956#if defined(CONFIG_SERIAL_MPSC) || defined(CONFIG_MV643XX_ETH)
957 platform_notify = hdpu_platform_notify;
958#endif
959 return;
960}
961
962#if defined(CONFIG_SERIAL_TEXT_DEBUG) && defined(CONFIG_SERIAL_MPSC_CONSOLE)
963/* SMP safe version of the serial text debug routine. Uses Semaphore 0 */
964void hdpu_mpsc_progress(char *s, unsigned short hex)
965{
966 while (mv64x60_read(&bh, MV64360_WHO_AM_I) !=
967 mv64x60_read(&bh, MV64360_SEMAPHORE_0)) {
968 }
969 mv64x60_mpsc_progress(s, hex);
970 mv64x60_write(&bh, MV64360_SEMAPHORE_0, 0xff);
971}
972#endif
973
974static void hdpu_cpustate_set(unsigned char new_state)
975{
976 unsigned int state = (new_state << 21);
977 mv64x60_write(&bh, MV64x60_GPP_VALUE_CLR, (0xff << 21));
978 mv64x60_write(&bh, MV64x60_GPP_VALUE_CLR, state);
979}
980
981#ifdef CONFIG_MTD_PHYSMAP
982static struct mtd_partition hdpu_partitions[] = {
983 {
984 .name = "Root FS",
985 .size = 0x03400000,
986 .offset = 0,
987 .mask_flags = 0,
988 },{
989 .name = "User FS",
990 .size = 0x00800000,
991 .offset = 0x03400000,
992 .mask_flags = 0,
993 },{
994 .name = "Kernel Image",
995 .size = 0x002C0000,
996 .offset = 0x03C00000,
997 .mask_flags = 0,
998 },{
999 .name = "bootEnv",
1000 .size = 0x00040000,
1001 .offset = 0x03EC0000,
1002 .mask_flags = 0,
1003 },{
1004 .name = "bootROM",
1005 .size = 0x00100000,
1006 .offset = 0x03F00000,
1007 .mask_flags = 0,
1008 }
1009};
1010
1011static int __init hdpu_setup_mtd(void)
1012{
1013
1014 physmap_set_partitions(hdpu_partitions, 5);
1015 return 0;
1016}
1017
1018arch_initcall(hdpu_setup_mtd);
1019#endif
1020
1021#ifdef CONFIG_HDPU_FEATURES
1022
1023static struct resource hdpu_cpustate_resources[] = {
1024 [0] = {
1025 .name = "addr base",
1026 .start = MV64x60_GPP_VALUE_SET,
1027 .end = MV64x60_GPP_VALUE_CLR + 1,
1028 .flags = IORESOURCE_MEM,
1029 },
1030};
1031
1032static struct resource hdpu_nexus_resources[] = {
1033 [0] = {
1034 .name = "nexus register",
1035 .start = HDPU_NEXUS_ID_BASE,
1036 .end = HDPU_NEXUS_ID_BASE + HDPU_NEXUS_ID_SIZE,
1037 .flags = IORESOURCE_MEM,
1038 },
1039};
1040
1041static struct platform_device hdpu_cpustate_device = {
1042 .name = HDPU_CPUSTATE_NAME,
1043 .id = 0,
1044 .num_resources = ARRAY_SIZE(hdpu_cpustate_resources),
1045 .resource = hdpu_cpustate_resources,
1046};
1047
1048static struct platform_device hdpu_nexus_device = {
1049 .name = HDPU_NEXUS_NAME,
1050 .id = 0,
1051 .num_resources = ARRAY_SIZE(hdpu_nexus_resources),
1052 .resource = hdpu_nexus_resources,
1053};
1054
1055static int __init hdpu_add_pds(void)
1056{
1057 platform_device_register(&hdpu_cpustate_device);
1058 platform_device_register(&hdpu_nexus_device);
1059 return 0;
1060}
1061
1062arch_initcall(hdpu_add_pds);
1063#endif