hdpu.c 26 KB

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