hdpu.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053
  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. struct pt_regs *regs)
  544. {
  545. volatile unsigned int doorbell;
  546. doorbell = mv64x60_read(&bh, MV64360_CPU0_DOORBELL);
  547. /* Ack the doorbell interrupts */
  548. mv64x60_write(&bh, MV64360_CPU0_DOORBELL_CLR, doorbell);
  549. if (doorbell & 1) {
  550. smp_message_recv(0, regs);
  551. }
  552. if (doorbell & 2) {
  553. smp_message_recv(1, regs);
  554. }
  555. if (doorbell & 4) {
  556. smp_message_recv(2, regs);
  557. }
  558. if (doorbell & 8) {
  559. smp_message_recv(3, regs);
  560. }
  561. return IRQ_HANDLED;
  562. }
  563. static irqreturn_t hdpu_smp_cpu1_int_handler(int irq, void *dev_id,
  564. struct pt_regs *regs)
  565. {
  566. volatile unsigned int doorbell;
  567. doorbell = mv64x60_read(&bh, MV64360_CPU1_DOORBELL);
  568. /* Ack the doorbell interrupts */
  569. mv64x60_write(&bh, MV64360_CPU1_DOORBELL_CLR, doorbell);
  570. if (doorbell & 1) {
  571. smp_message_recv(0, regs);
  572. }
  573. if (doorbell & 2) {
  574. smp_message_recv(1, regs);
  575. }
  576. if (doorbell & 4) {
  577. smp_message_recv(2, regs);
  578. }
  579. if (doorbell & 8) {
  580. smp_message_recv(3, regs);
  581. }
  582. return IRQ_HANDLED;
  583. }
  584. static void smp_hdpu_CPU_two(void)
  585. {
  586. __asm__ __volatile__
  587. ("\n"
  588. "lis 3,0x0000\n"
  589. "ori 3,3,0x00c0\n"
  590. "mtspr 26, 3\n" "li 4,0\n" "mtspr 27,4\n" "rfi");
  591. }
  592. static int smp_hdpu_probe(void)
  593. {
  594. int *cpu_count_reg;
  595. int num_cpus = 0;
  596. cpu_count_reg = ioremap(HDPU_NEXUS_ID_BASE, HDPU_NEXUS_ID_SIZE);
  597. if (cpu_count_reg) {
  598. num_cpus = (*cpu_count_reg >> 20) & 0x3;
  599. iounmap(cpu_count_reg);
  600. }
  601. /* Validate the bits in the CPLD. If we could not map the reg, return 2.
  602. * If the register reported 0 or 3, return 2.
  603. * Older CPLD revisions set these bits to all ones (val = 3).
  604. */
  605. if ((num_cpus < 1) || (num_cpus > 2)) {
  606. printk
  607. ("Unable to determine the number of processors %d . deafulting to 2.\n",
  608. num_cpus);
  609. num_cpus = 2;
  610. }
  611. return num_cpus;
  612. }
  613. static void
  614. smp_hdpu_message_pass(int target, int msg)
  615. {
  616. if (msg > 0x3) {
  617. printk("SMP %d: smp_message_pass: unknown msg %d\n",
  618. smp_processor_id(), msg);
  619. return;
  620. }
  621. switch (target) {
  622. case MSG_ALL:
  623. mv64x60_write(&bh, MV64360_CPU0_DOORBELL, 1 << msg);
  624. mv64x60_write(&bh, MV64360_CPU1_DOORBELL, 1 << msg);
  625. break;
  626. case MSG_ALL_BUT_SELF:
  627. if (smp_processor_id())
  628. mv64x60_write(&bh, MV64360_CPU0_DOORBELL, 1 << msg);
  629. else
  630. mv64x60_write(&bh, MV64360_CPU1_DOORBELL, 1 << msg);
  631. break;
  632. default:
  633. if (target == 0)
  634. mv64x60_write(&bh, MV64360_CPU0_DOORBELL, 1 << msg);
  635. else
  636. mv64x60_write(&bh, MV64360_CPU1_DOORBELL, 1 << msg);
  637. break;
  638. }
  639. }
  640. static void smp_hdpu_kick_cpu(int nr)
  641. {
  642. volatile unsigned int *bootaddr;
  643. if (ppc_md.progress)
  644. ppc_md.progress("smp_hdpu_kick_cpu", 0);
  645. hdpu_cpustate_set(CPUSTATE_KERNEL_MAJOR | CPUSTATE_KERNEL_CPU1_KICK);
  646. /* Disable BootCS. Must also reduce the windows size to zero. */
  647. bh.ci->disable_window_32bit(&bh, MV64x60_CPU2BOOT_WIN);
  648. mv64x60_set_32bit_window(&bh, MV64x60_CPU2BOOT_WIN, 0, 0, 0);
  649. bootaddr = ioremap(HDPU_INTERNAL_SRAM_BASE, HDPU_INTERNAL_SRAM_SIZE);
  650. if (!bootaddr) {
  651. if (ppc_md.progress)
  652. ppc_md.progress("smp_hdpu_kick_cpu: ioremap failed", 0);
  653. return;
  654. }
  655. memcpy((void *)(bootaddr + 0x40), (void *)&smp_hdpu_CPU_two, 0x20);
  656. /* map SRAM to 0xfff00000 */
  657. bh.ci->disable_window_32bit(&bh, MV64x60_CPU2SRAM_WIN);
  658. mv64x60_set_32bit_window(&bh, MV64x60_CPU2SRAM_WIN,
  659. 0xfff00000, HDPU_INTERNAL_SRAM_SIZE, 0);
  660. bh.ci->enable_window_32bit(&bh, MV64x60_CPU2SRAM_WIN);
  661. /* Enable CPU1 arbitration */
  662. mv64x60_clr_bits(&bh, MV64x60_CPU_MASTER_CNTL, (1 << 9));
  663. /*
  664. * Wait 100mSecond until other CPU has reached __secondary_start.
  665. * When it reaches, it is permittable to rever the SRAM mapping etc...
  666. */
  667. mdelay(100);
  668. *(unsigned long *)KERNELBASE = nr;
  669. asm volatile ("dcbf 0,%0"::"r" (KERNELBASE):"memory");
  670. iounmap(bootaddr);
  671. /* Set up window for internal sram (256KByte insize) */
  672. bh.ci->disable_window_32bit(&bh, MV64x60_CPU2SRAM_WIN);
  673. mv64x60_set_32bit_window(&bh, MV64x60_CPU2SRAM_WIN,
  674. HDPU_INTERNAL_SRAM_BASE,
  675. HDPU_INTERNAL_SRAM_SIZE, 0);
  676. bh.ci->enable_window_32bit(&bh, MV64x60_CPU2SRAM_WIN);
  677. /*
  678. * Set up windows for embedded FLASH (using boot CS window).
  679. */
  680. bh.ci->disable_window_32bit(&bh, MV64x60_CPU2BOOT_WIN);
  681. mv64x60_set_32bit_window(&bh, MV64x60_CPU2BOOT_WIN,
  682. HDPU_EMB_FLASH_BASE, HDPU_EMB_FLASH_SIZE, 0);
  683. bh.ci->enable_window_32bit(&bh, MV64x60_CPU2BOOT_WIN);
  684. }
  685. static void smp_hdpu_setup_cpu(int cpu_nr)
  686. {
  687. if (cpu_nr == 0) {
  688. if (ppc_md.progress)
  689. ppc_md.progress("smp_hdpu_setup_cpu 0", 0);
  690. mv64x60_write(&bh, MV64360_CPU0_DOORBELL_CLR, 0xff);
  691. mv64x60_write(&bh, MV64360_CPU0_DOORBELL_MASK, 0xff);
  692. request_irq(60, hdpu_smp_cpu0_int_handler,
  693. IRQF_DISABLED, hdpu_smp0, 0);
  694. }
  695. if (cpu_nr == 1) {
  696. if (ppc_md.progress)
  697. ppc_md.progress("smp_hdpu_setup_cpu 1", 0);
  698. hdpu_cpustate_set(CPUSTATE_KERNEL_MAJOR |
  699. CPUSTATE_KERNEL_CPU1_OK);
  700. /* Enable L1 Parity Bits */
  701. hdpu_set_l1pe();
  702. /* Enable L2 cache */
  703. _set_L2CR(0);
  704. _set_L2CR(0x80080000);
  705. mv64x60_write(&bh, MV64360_CPU1_DOORBELL_CLR, 0x0);
  706. mv64x60_write(&bh, MV64360_CPU1_DOORBELL_MASK, 0xff);
  707. request_irq(28, hdpu_smp_cpu1_int_handler,
  708. IRQF_DISABLED, hdpu_smp1, 0);
  709. }
  710. }
  711. void __devinit hdpu_tben_give()
  712. {
  713. volatile unsigned long *val = 0;
  714. /* By writing 0 to the TBEN_BASE, the timebases is frozen */
  715. val = ioremap(HDPU_TBEN_BASE, 4);
  716. *val = 0;
  717. mb();
  718. spin_lock(&timebase_lock);
  719. timebase_upper = get_tbu();
  720. timebase_lower = get_tbl();
  721. spin_unlock(&timebase_lock);
  722. while (timebase_upper || timebase_lower)
  723. barrier();
  724. /* By writing 1 to the TBEN_BASE, the timebases is thawed */
  725. *val = 1;
  726. mb();
  727. iounmap(val);
  728. }
  729. void __devinit hdpu_tben_take()
  730. {
  731. while (!(timebase_upper || timebase_lower))
  732. barrier();
  733. spin_lock(&timebase_lock);
  734. set_tb(timebase_upper, timebase_lower);
  735. timebase_upper = 0;
  736. timebase_lower = 0;
  737. spin_unlock(&timebase_lock);
  738. }
  739. static struct smp_ops_t hdpu_smp_ops = {
  740. .message_pass = smp_hdpu_message_pass,
  741. .probe = smp_hdpu_probe,
  742. .kick_cpu = smp_hdpu_kick_cpu,
  743. .setup_cpu = smp_hdpu_setup_cpu,
  744. .give_timebase = hdpu_tben_give,
  745. .take_timebase = hdpu_tben_take,
  746. };
  747. #endif /* CONFIG_SMP */
  748. void __init
  749. platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  750. unsigned long r6, unsigned long r7)
  751. {
  752. parse_bootinfo(r3, r4, r5, r6, r7);
  753. isa_mem_base = 0;
  754. ppc_md.setup_arch = hdpu_setup_arch;
  755. ppc_md.init = hdpu_init2;
  756. ppc_md.show_cpuinfo = hdpu_show_cpuinfo;
  757. ppc_md.init_IRQ = hdpu_init_irq;
  758. ppc_md.get_irq = mv64360_get_irq;
  759. ppc_md.restart = hdpu_restart;
  760. ppc_md.power_off = hdpu_power_off;
  761. ppc_md.halt = hdpu_halt;
  762. ppc_md.find_end_of_memory = hdpu_find_end_of_memory;
  763. ppc_md.calibrate_decr = hdpu_calibrate_decr;
  764. ppc_md.setup_io_mappings = hdpu_map_io;
  765. bh.p_base = CONFIG_MV64X60_NEW_BASE;
  766. bh.v_base = (unsigned long *)bh.p_base;
  767. hdpu_set_bat();
  768. #if defined(CONFIG_SERIAL_TEXT_DEBUG)
  769. ppc_md.progress = hdpu_mpsc_progress; /* embedded UART */
  770. mv64x60_progress_init(bh.p_base);
  771. #endif /* CONFIG_SERIAL_TEXT_DEBUG */
  772. #ifdef CONFIG_SMP
  773. smp_ops = &hdpu_smp_ops;
  774. #endif /* CONFIG_SMP */
  775. #if defined(CONFIG_SERIAL_MPSC) || defined(CONFIG_MV643XX_ETH)
  776. platform_notify = hdpu_platform_notify;
  777. #endif
  778. return;
  779. }
  780. #if defined(CONFIG_SERIAL_TEXT_DEBUG) && defined(CONFIG_SERIAL_MPSC_CONSOLE)
  781. /* SMP safe version of the serial text debug routine. Uses Semaphore 0 */
  782. void hdpu_mpsc_progress(char *s, unsigned short hex)
  783. {
  784. while (mv64x60_read(&bh, MV64360_WHO_AM_I) !=
  785. mv64x60_read(&bh, MV64360_SEMAPHORE_0)) {
  786. }
  787. mv64x60_mpsc_progress(s, hex);
  788. mv64x60_write(&bh, MV64360_SEMAPHORE_0, 0xff);
  789. }
  790. #endif
  791. static void hdpu_cpustate_set(unsigned char new_state)
  792. {
  793. unsigned int state = (new_state << 21);
  794. mv64x60_write(&bh, MV64x60_GPP_VALUE_CLR, (0xff << 21));
  795. mv64x60_write(&bh, MV64x60_GPP_VALUE_CLR, state);
  796. }
  797. #ifdef CONFIG_MTD_PHYSMAP
  798. static struct mtd_partition hdpu_partitions[] = {
  799. {
  800. .name = "Root FS",
  801. .size = 0x03400000,
  802. .offset = 0,
  803. .mask_flags = 0,
  804. },{
  805. .name = "User FS",
  806. .size = 0x00800000,
  807. .offset = 0x03400000,
  808. .mask_flags = 0,
  809. },{
  810. .name = "Kernel Image",
  811. .size = 0x002C0000,
  812. .offset = 0x03C00000,
  813. .mask_flags = 0,
  814. },{
  815. .name = "bootEnv",
  816. .size = 0x00040000,
  817. .offset = 0x03EC0000,
  818. .mask_flags = 0,
  819. },{
  820. .name = "bootROM",
  821. .size = 0x00100000,
  822. .offset = 0x03F00000,
  823. .mask_flags = 0,
  824. }
  825. };
  826. static int __init hdpu_setup_mtd(void)
  827. {
  828. physmap_set_partitions(hdpu_partitions, 5);
  829. return 0;
  830. }
  831. arch_initcall(hdpu_setup_mtd);
  832. #endif
  833. #ifdef CONFIG_HDPU_FEATURES
  834. static struct resource hdpu_cpustate_resources[] = {
  835. [0] = {
  836. .name = "addr base",
  837. .start = MV64x60_GPP_VALUE_SET,
  838. .end = MV64x60_GPP_VALUE_CLR + 1,
  839. .flags = IORESOURCE_MEM,
  840. },
  841. };
  842. static struct resource hdpu_nexus_resources[] = {
  843. [0] = {
  844. .name = "nexus register",
  845. .start = HDPU_NEXUS_ID_BASE,
  846. .end = HDPU_NEXUS_ID_BASE + HDPU_NEXUS_ID_SIZE,
  847. .flags = IORESOURCE_MEM,
  848. },
  849. };
  850. static struct platform_device hdpu_cpustate_device = {
  851. .name = HDPU_CPUSTATE_NAME,
  852. .id = 0,
  853. .num_resources = ARRAY_SIZE(hdpu_cpustate_resources),
  854. .resource = hdpu_cpustate_resources,
  855. };
  856. static struct platform_device hdpu_nexus_device = {
  857. .name = HDPU_NEXUS_NAME,
  858. .id = 0,
  859. .num_resources = ARRAY_SIZE(hdpu_nexus_resources),
  860. .resource = hdpu_nexus_resources,
  861. };
  862. static int __init hdpu_add_pds(void)
  863. {
  864. platform_device_register(&hdpu_cpustate_device);
  865. platform_device_register(&hdpu_nexus_device);
  866. return 0;
  867. }
  868. arch_initcall(hdpu_add_pds);
  869. #endif