hdpu.c 25 KB

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