smp-bmips.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2011 by Kevin Cernekee (cernekee@gmail.com)
  7. *
  8. * SMP support for BMIPS
  9. */
  10. #include <linux/init.h>
  11. #include <linux/sched.h>
  12. #include <linux/sched/hotplug.h>
  13. #include <linux/sched/task_stack.h>
  14. #include <linux/mm.h>
  15. #include <linux/delay.h>
  16. #include <linux/smp.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/spinlock.h>
  19. #include <linux/cpu.h>
  20. #include <linux/cpumask.h>
  21. #include <linux/reboot.h>
  22. #include <linux/io.h>
  23. #include <linux/compiler.h>
  24. #include <linux/linkage.h>
  25. #include <linux/bug.h>
  26. #include <linux/kernel.h>
  27. #include <linux/kexec.h>
  28. #include <linux/irq.h>
  29. #include <asm/time.h>
  30. #include <asm/processor.h>
  31. #include <asm/bootinfo.h>
  32. #include <asm/cacheflush.h>
  33. #include <asm/tlbflush.h>
  34. #include <asm/mipsregs.h>
  35. #include <asm/bmips.h>
  36. #include <asm/traps.h>
  37. #include <asm/barrier.h>
  38. #include <asm/cpu-features.h>
  39. static int __maybe_unused max_cpus = 1;
  40. /* these may be configured by the platform code */
  41. int bmips_smp_enabled = 1;
  42. int bmips_cpu_offset;
  43. cpumask_t bmips_booted_mask;
  44. unsigned long bmips_tp1_irqs = IE_IRQ1;
  45. #define RESET_FROM_KSEG0 0x80080800
  46. #define RESET_FROM_KSEG1 0xa0080800
  47. static void bmips_set_reset_vec(int cpu, u32 val);
  48. #ifdef CONFIG_SMP
  49. #include <asm/smp.h>
  50. /* initial $sp, $gp - used by arch/mips/kernel/bmips_vec.S */
  51. unsigned long bmips_smp_boot_sp;
  52. unsigned long bmips_smp_boot_gp;
  53. static void bmips43xx_send_ipi_single(int cpu, unsigned int action);
  54. static void bmips5000_send_ipi_single(int cpu, unsigned int action);
  55. static irqreturn_t bmips43xx_ipi_interrupt(int irq, void *dev_id);
  56. static irqreturn_t bmips5000_ipi_interrupt(int irq, void *dev_id);
  57. /* SW interrupts 0,1 are used for interprocessor signaling */
  58. #define IPI0_IRQ (MIPS_CPU_IRQ_BASE + 0)
  59. #define IPI1_IRQ (MIPS_CPU_IRQ_BASE + 1)
  60. #define CPUNUM(cpu, shift) (((cpu) + bmips_cpu_offset) << (shift))
  61. #define ACTION_CLR_IPI(cpu, ipi) (0x2000 | CPUNUM(cpu, 9) | ((ipi) << 8))
  62. #define ACTION_SET_IPI(cpu, ipi) (0x3000 | CPUNUM(cpu, 9) | ((ipi) << 8))
  63. #define ACTION_BOOT_THREAD(cpu) (0x08 | CPUNUM(cpu, 0))
  64. static void __init bmips_smp_setup(void)
  65. {
  66. int i, cpu = 1, boot_cpu = 0;
  67. int cpu_hw_intr;
  68. switch (current_cpu_type()) {
  69. case CPU_BMIPS4350:
  70. case CPU_BMIPS4380:
  71. /* arbitration priority */
  72. clear_c0_brcm_cmt_ctrl(0x30);
  73. /* NBK and weak order flags */
  74. set_c0_brcm_config_0(0x30000);
  75. /* Find out if we are running on TP0 or TP1 */
  76. boot_cpu = !!(read_c0_brcm_cmt_local() & (1 << 31));
  77. /*
  78. * MIPS interrupts 0,1 (SW INT 0,1) cross over to the other
  79. * thread
  80. * MIPS interrupt 2 (HW INT 0) is the CPU0 L1 controller output
  81. * MIPS interrupt 3 (HW INT 1) is the CPU1 L1 controller output
  82. */
  83. if (boot_cpu == 0)
  84. cpu_hw_intr = 0x02;
  85. else
  86. cpu_hw_intr = 0x1d;
  87. change_c0_brcm_cmt_intr(0xf8018000,
  88. (cpu_hw_intr << 27) | (0x03 << 15));
  89. /* single core, 2 threads (2 pipelines) */
  90. max_cpus = 2;
  91. break;
  92. case CPU_BMIPS5000:
  93. /* enable raceless SW interrupts */
  94. set_c0_brcm_config(0x03 << 22);
  95. /* route HW interrupt 0 to CPU0, HW interrupt 1 to CPU1 */
  96. change_c0_brcm_mode(0x1f << 27, 0x02 << 27);
  97. /* N cores, 2 threads per core */
  98. max_cpus = (((read_c0_brcm_config() >> 6) & 0x03) + 1) << 1;
  99. /* clear any pending SW interrupts */
  100. for (i = 0; i < max_cpus; i++) {
  101. write_c0_brcm_action(ACTION_CLR_IPI(i, 0));
  102. write_c0_brcm_action(ACTION_CLR_IPI(i, 1));
  103. }
  104. break;
  105. default:
  106. max_cpus = 1;
  107. }
  108. if (!bmips_smp_enabled)
  109. max_cpus = 1;
  110. /* this can be overridden by the BSP */
  111. if (!board_ebase_setup)
  112. board_ebase_setup = &bmips_ebase_setup;
  113. if (max_cpus > 1) {
  114. __cpu_number_map[boot_cpu] = 0;
  115. __cpu_logical_map[0] = boot_cpu;
  116. for (i = 0; i < max_cpus; i++) {
  117. if (i != boot_cpu) {
  118. __cpu_number_map[i] = cpu;
  119. __cpu_logical_map[cpu] = i;
  120. cpu++;
  121. }
  122. set_cpu_possible(i, 1);
  123. set_cpu_present(i, 1);
  124. }
  125. } else {
  126. __cpu_number_map[0] = boot_cpu;
  127. __cpu_logical_map[0] = 0;
  128. set_cpu_possible(0, 1);
  129. set_cpu_present(0, 1);
  130. }
  131. }
  132. /*
  133. * IPI IRQ setup - runs on CPU0
  134. */
  135. static void bmips_prepare_cpus(unsigned int max_cpus)
  136. {
  137. irqreturn_t (*bmips_ipi_interrupt)(int irq, void *dev_id);
  138. switch (current_cpu_type()) {
  139. case CPU_BMIPS4350:
  140. case CPU_BMIPS4380:
  141. bmips_ipi_interrupt = bmips43xx_ipi_interrupt;
  142. break;
  143. case CPU_BMIPS5000:
  144. bmips_ipi_interrupt = bmips5000_ipi_interrupt;
  145. break;
  146. default:
  147. return;
  148. }
  149. if (request_irq(IPI0_IRQ, bmips_ipi_interrupt,
  150. IRQF_PERCPU | IRQF_NO_SUSPEND, "smp_ipi0", NULL))
  151. panic("Can't request IPI0 interrupt");
  152. if (request_irq(IPI1_IRQ, bmips_ipi_interrupt,
  153. IRQF_PERCPU | IRQF_NO_SUSPEND, "smp_ipi1", NULL))
  154. panic("Can't request IPI1 interrupt");
  155. }
  156. /*
  157. * Tell the hardware to boot CPUx - runs on CPU0
  158. */
  159. static int bmips_boot_secondary(int cpu, struct task_struct *idle)
  160. {
  161. bmips_smp_boot_sp = __KSTK_TOS(idle);
  162. bmips_smp_boot_gp = (unsigned long)task_thread_info(idle);
  163. mb();
  164. /*
  165. * Initial boot sequence for secondary CPU:
  166. * bmips_reset_nmi_vec @ a000_0000 ->
  167. * bmips_smp_entry ->
  168. * plat_wired_tlb_setup (cached function call; optional) ->
  169. * start_secondary (cached jump)
  170. *
  171. * Warm restart sequence:
  172. * play_dead WAIT loop ->
  173. * bmips_smp_int_vec @ BMIPS_WARM_RESTART_VEC ->
  174. * eret to play_dead ->
  175. * bmips_secondary_reentry ->
  176. * start_secondary
  177. */
  178. pr_info("SMP: Booting CPU%d...\n", cpu);
  179. if (cpumask_test_cpu(cpu, &bmips_booted_mask)) {
  180. /* kseg1 might not exist if this CPU enabled XKS01 */
  181. bmips_set_reset_vec(cpu, RESET_FROM_KSEG0);
  182. switch (current_cpu_type()) {
  183. case CPU_BMIPS4350:
  184. case CPU_BMIPS4380:
  185. bmips43xx_send_ipi_single(cpu, 0);
  186. break;
  187. case CPU_BMIPS5000:
  188. bmips5000_send_ipi_single(cpu, 0);
  189. break;
  190. }
  191. } else {
  192. bmips_set_reset_vec(cpu, RESET_FROM_KSEG1);
  193. switch (current_cpu_type()) {
  194. case CPU_BMIPS4350:
  195. case CPU_BMIPS4380:
  196. /* Reset slave TP1 if booting from TP0 */
  197. if (cpu_logical_map(cpu) == 1)
  198. set_c0_brcm_cmt_ctrl(0x01);
  199. break;
  200. case CPU_BMIPS5000:
  201. write_c0_brcm_action(ACTION_BOOT_THREAD(cpu));
  202. break;
  203. }
  204. cpumask_set_cpu(cpu, &bmips_booted_mask);
  205. }
  206. return 0;
  207. }
  208. /*
  209. * Early setup - runs on secondary CPU after cache probe
  210. */
  211. static void bmips_init_secondary(void)
  212. {
  213. bmips_cpu_setup();
  214. switch (current_cpu_type()) {
  215. case CPU_BMIPS4350:
  216. case CPU_BMIPS4380:
  217. clear_c0_cause(smp_processor_id() ? C_SW1 : C_SW0);
  218. break;
  219. case CPU_BMIPS5000:
  220. write_c0_brcm_action(ACTION_CLR_IPI(smp_processor_id(), 0));
  221. cpu_set_core(&current_cpu_data, (read_c0_brcm_config() >> 25) & 3);
  222. break;
  223. }
  224. }
  225. /*
  226. * Late setup - runs on secondary CPU before entering the idle loop
  227. */
  228. static void bmips_smp_finish(void)
  229. {
  230. pr_info("SMP: CPU%d is running\n", smp_processor_id());
  231. /* make sure there won't be a timer interrupt for a little while */
  232. write_c0_compare(read_c0_count() + mips_hpt_frequency / HZ);
  233. irq_enable_hazard();
  234. set_c0_status(IE_SW0 | IE_SW1 | bmips_tp1_irqs | IE_IRQ5 | ST0_IE);
  235. irq_enable_hazard();
  236. }
  237. /*
  238. * BMIPS5000 raceless IPIs
  239. *
  240. * Each CPU has two inbound SW IRQs which are independent of all other CPUs.
  241. * IPI0 is used for SMP_RESCHEDULE_YOURSELF
  242. * IPI1 is used for SMP_CALL_FUNCTION
  243. */
  244. static void bmips5000_send_ipi_single(int cpu, unsigned int action)
  245. {
  246. write_c0_brcm_action(ACTION_SET_IPI(cpu, action == SMP_CALL_FUNCTION));
  247. }
  248. static irqreturn_t bmips5000_ipi_interrupt(int irq, void *dev_id)
  249. {
  250. int action = irq - IPI0_IRQ;
  251. write_c0_brcm_action(ACTION_CLR_IPI(smp_processor_id(), action));
  252. if (action == 0)
  253. scheduler_ipi();
  254. else
  255. generic_smp_call_function_interrupt();
  256. return IRQ_HANDLED;
  257. }
  258. static void bmips5000_send_ipi_mask(const struct cpumask *mask,
  259. unsigned int action)
  260. {
  261. unsigned int i;
  262. for_each_cpu(i, mask)
  263. bmips5000_send_ipi_single(i, action);
  264. }
  265. /*
  266. * BMIPS43xx racey IPIs
  267. *
  268. * We use one inbound SW IRQ for each CPU.
  269. *
  270. * A spinlock must be held in order to keep CPUx from accidentally clearing
  271. * an incoming IPI when it writes CP0 CAUSE to raise an IPI on CPUy. The
  272. * same spinlock is used to protect the action masks.
  273. */
  274. static DEFINE_SPINLOCK(ipi_lock);
  275. static DEFINE_PER_CPU(int, ipi_action_mask);
  276. static void bmips43xx_send_ipi_single(int cpu, unsigned int action)
  277. {
  278. unsigned long flags;
  279. spin_lock_irqsave(&ipi_lock, flags);
  280. set_c0_cause(cpu ? C_SW1 : C_SW0);
  281. per_cpu(ipi_action_mask, cpu) |= action;
  282. irq_enable_hazard();
  283. spin_unlock_irqrestore(&ipi_lock, flags);
  284. }
  285. static irqreturn_t bmips43xx_ipi_interrupt(int irq, void *dev_id)
  286. {
  287. unsigned long flags;
  288. int action, cpu = irq - IPI0_IRQ;
  289. spin_lock_irqsave(&ipi_lock, flags);
  290. action = __this_cpu_read(ipi_action_mask);
  291. per_cpu(ipi_action_mask, cpu) = 0;
  292. clear_c0_cause(cpu ? C_SW1 : C_SW0);
  293. spin_unlock_irqrestore(&ipi_lock, flags);
  294. if (action & SMP_RESCHEDULE_YOURSELF)
  295. scheduler_ipi();
  296. if (action & SMP_CALL_FUNCTION)
  297. generic_smp_call_function_interrupt();
  298. return IRQ_HANDLED;
  299. }
  300. static void bmips43xx_send_ipi_mask(const struct cpumask *mask,
  301. unsigned int action)
  302. {
  303. unsigned int i;
  304. for_each_cpu(i, mask)
  305. bmips43xx_send_ipi_single(i, action);
  306. }
  307. #ifdef CONFIG_HOTPLUG_CPU
  308. static int bmips_cpu_disable(void)
  309. {
  310. unsigned int cpu = smp_processor_id();
  311. pr_info("SMP: CPU%d is offline\n", cpu);
  312. set_cpu_online(cpu, false);
  313. calculate_cpu_foreign_map();
  314. irq_migrate_all_off_this_cpu();
  315. clear_c0_status(IE_IRQ5);
  316. local_flush_tlb_all();
  317. local_flush_icache_range(0, ~0);
  318. return 0;
  319. }
  320. static void bmips_cpu_die(unsigned int cpu)
  321. {
  322. }
  323. void __ref play_dead(void)
  324. {
  325. idle_task_exit();
  326. cpuhp_ap_report_dead();
  327. /* flush data cache */
  328. _dma_cache_wback_inv(0, ~0);
  329. /*
  330. * Wakeup is on SW0 or SW1; disable everything else
  331. * Use BEV !IV (BMIPS_WARM_RESTART_VEC) to avoid the regular Linux
  332. * IRQ handlers; this clears ST0_IE and returns immediately.
  333. */
  334. clear_c0_cause(CAUSEF_IV | C_SW0 | C_SW1);
  335. change_c0_status(
  336. IE_IRQ5 | bmips_tp1_irqs | IE_SW0 | IE_SW1 | ST0_IE | ST0_BEV,
  337. IE_SW0 | IE_SW1 | ST0_IE | ST0_BEV);
  338. irq_disable_hazard();
  339. /*
  340. * wait for SW interrupt from bmips_boot_secondary(), then jump
  341. * back to start_secondary()
  342. */
  343. __asm__ __volatile__(
  344. " wait\n"
  345. " j bmips_secondary_reentry\n"
  346. : : : "memory");
  347. BUG();
  348. }
  349. #endif /* CONFIG_HOTPLUG_CPU */
  350. const struct plat_smp_ops bmips43xx_smp_ops = {
  351. .smp_setup = bmips_smp_setup,
  352. .prepare_cpus = bmips_prepare_cpus,
  353. .boot_secondary = bmips_boot_secondary,
  354. .smp_finish = bmips_smp_finish,
  355. .init_secondary = bmips_init_secondary,
  356. .send_ipi_single = bmips43xx_send_ipi_single,
  357. .send_ipi_mask = bmips43xx_send_ipi_mask,
  358. #ifdef CONFIG_HOTPLUG_CPU
  359. .cpu_disable = bmips_cpu_disable,
  360. .cpu_die = bmips_cpu_die,
  361. #endif
  362. #ifdef CONFIG_KEXEC_CORE
  363. .kexec_nonboot_cpu = kexec_nonboot_cpu_jump,
  364. #endif
  365. };
  366. const struct plat_smp_ops bmips5000_smp_ops = {
  367. .smp_setup = bmips_smp_setup,
  368. .prepare_cpus = bmips_prepare_cpus,
  369. .boot_secondary = bmips_boot_secondary,
  370. .smp_finish = bmips_smp_finish,
  371. .init_secondary = bmips_init_secondary,
  372. .send_ipi_single = bmips5000_send_ipi_single,
  373. .send_ipi_mask = bmips5000_send_ipi_mask,
  374. #ifdef CONFIG_HOTPLUG_CPU
  375. .cpu_disable = bmips_cpu_disable,
  376. .cpu_die = bmips_cpu_die,
  377. #endif
  378. #ifdef CONFIG_KEXEC_CORE
  379. .kexec_nonboot_cpu = kexec_nonboot_cpu_jump,
  380. #endif
  381. };
  382. #endif /* CONFIG_SMP */
  383. /***********************************************************************
  384. * BMIPS vector relocation
  385. * This is primarily used for SMP boot, but it is applicable to some
  386. * UP BMIPS systems as well.
  387. ***********************************************************************/
  388. static void bmips_wr_vec(unsigned long dst, char *start, char *end)
  389. {
  390. memcpy((void *)dst, start, end - start);
  391. dma_cache_wback(dst, end - start);
  392. local_flush_icache_range(dst, dst + (end - start));
  393. instruction_hazard();
  394. }
  395. static inline void bmips_nmi_handler_setup(void)
  396. {
  397. bmips_wr_vec(BMIPS_NMI_RESET_VEC, bmips_reset_nmi_vec,
  398. bmips_reset_nmi_vec_end);
  399. bmips_wr_vec(BMIPS_WARM_RESTART_VEC, bmips_smp_int_vec,
  400. bmips_smp_int_vec_end);
  401. }
  402. struct reset_vec_info {
  403. int cpu;
  404. u32 val;
  405. };
  406. static void bmips_set_reset_vec_remote(void *vinfo)
  407. {
  408. struct reset_vec_info *info = vinfo;
  409. int shift = info->cpu & 0x01 ? 16 : 0;
  410. u32 mask = ~(0xffff << shift), val = info->val >> 16;
  411. preempt_disable();
  412. if (smp_processor_id() > 0) {
  413. smp_call_function_single(0, &bmips_set_reset_vec_remote,
  414. info, 1);
  415. } else {
  416. if (info->cpu & 0x02) {
  417. /* BMIPS5200 "should" use mask/shift, but it's buggy */
  418. bmips_write_zscm_reg(0xa0, (val << 16) | val);
  419. bmips_read_zscm_reg(0xa0);
  420. } else {
  421. write_c0_brcm_bootvec((read_c0_brcm_bootvec() & mask) |
  422. (val << shift));
  423. }
  424. }
  425. preempt_enable();
  426. }
  427. static void bmips_set_reset_vec(int cpu, u32 val)
  428. {
  429. struct reset_vec_info info;
  430. if (current_cpu_type() == CPU_BMIPS5000) {
  431. /* this needs to run from CPU0 (which is always online) */
  432. info.cpu = cpu;
  433. info.val = val;
  434. bmips_set_reset_vec_remote(&info);
  435. } else {
  436. void __iomem *cbr = bmips_cbr_addr;
  437. if (cpu == 0)
  438. __raw_writel(val, cbr + BMIPS_RELO_VECTOR_CONTROL_0);
  439. else {
  440. if (current_cpu_type() != CPU_BMIPS4380)
  441. return;
  442. __raw_writel(val, cbr + BMIPS_RELO_VECTOR_CONTROL_1);
  443. }
  444. }
  445. __sync();
  446. back_to_back_c0_hazard();
  447. }
  448. void bmips_ebase_setup(void)
  449. {
  450. unsigned long new_ebase = ebase;
  451. BUG_ON(ebase != CKSEG0);
  452. switch (current_cpu_type()) {
  453. case CPU_BMIPS4350:
  454. /*
  455. * BMIPS4350 cannot relocate the normal vectors, but it
  456. * can relocate the BEV=1 vectors. So CPU1 starts up at
  457. * the relocated BEV=1, IV=0 general exception vector @
  458. * 0xa000_0380.
  459. *
  460. * set_uncached_handler() is used here because:
  461. * - CPU1 will run this from uncached space
  462. * - None of the cacheflush functions are set up yet
  463. */
  464. set_uncached_handler(BMIPS_WARM_RESTART_VEC - CKSEG0,
  465. &bmips_smp_int_vec, 0x80);
  466. __sync();
  467. return;
  468. case CPU_BMIPS3300:
  469. case CPU_BMIPS4380:
  470. /*
  471. * 0x8000_0000: reset/NMI (initially in kseg1)
  472. * 0x8000_0400: normal vectors
  473. */
  474. new_ebase = 0x80000400;
  475. bmips_set_reset_vec(0, RESET_FROM_KSEG0);
  476. break;
  477. case CPU_BMIPS5000:
  478. /*
  479. * 0x8000_0000: reset/NMI (initially in kseg1)
  480. * 0x8000_1000: normal vectors
  481. */
  482. new_ebase = 0x80001000;
  483. bmips_set_reset_vec(0, RESET_FROM_KSEG0);
  484. write_c0_ebase(new_ebase);
  485. break;
  486. default:
  487. return;
  488. }
  489. board_nmi_handler_setup = &bmips_nmi_handler_setup;
  490. ebase = new_ebase;
  491. }
  492. asmlinkage void __weak plat_wired_tlb_setup(void)
  493. {
  494. /*
  495. * Called when starting/restarting a secondary CPU.
  496. * Kernel stacks and other important data might only be accessible
  497. * once the wired entries are present.
  498. */
  499. }
  500. void bmips_cpu_setup(void)
  501. {
  502. void __iomem __maybe_unused *cbr = bmips_cbr_addr;
  503. u32 __maybe_unused rac_addr;
  504. u32 __maybe_unused cfg;
  505. switch (current_cpu_type()) {
  506. case CPU_BMIPS3300:
  507. /* Set BIU to async mode */
  508. set_c0_brcm_bus_pll(BIT(22));
  509. __sync();
  510. /* put the BIU back in sync mode */
  511. clear_c0_brcm_bus_pll(BIT(22));
  512. /* clear BHTD to enable branch history table */
  513. clear_c0_brcm_reset(BIT(16));
  514. /* Flush and enable RAC */
  515. cfg = __raw_readl(cbr + BMIPS_RAC_CONFIG);
  516. __raw_writel(cfg | 0x100, cbr + BMIPS_RAC_CONFIG);
  517. __raw_readl(cbr + BMIPS_RAC_CONFIG);
  518. cfg = __raw_readl(cbr + BMIPS_RAC_CONFIG);
  519. __raw_writel(cfg | 0xf, cbr + BMIPS_RAC_CONFIG);
  520. __raw_readl(cbr + BMIPS_RAC_CONFIG);
  521. cfg = __raw_readl(cbr + BMIPS_RAC_ADDRESS_RANGE);
  522. __raw_writel(cfg | 0x0fff0000, cbr + BMIPS_RAC_ADDRESS_RANGE);
  523. __raw_readl(cbr + BMIPS_RAC_ADDRESS_RANGE);
  524. break;
  525. case CPU_BMIPS4350:
  526. rac_addr = BMIPS_RAC_CONFIG_1;
  527. if (!(read_c0_brcm_cmt_local() & (1 << 31)))
  528. rac_addr = BMIPS_RAC_CONFIG;
  529. /* Enable data RAC */
  530. cfg = __raw_readl(cbr + rac_addr);
  531. __raw_writel(cfg | 0xf, cbr + rac_addr);
  532. __raw_readl(cbr + rac_addr);
  533. /* Flush stale data out of the readahead cache */
  534. cfg = __raw_readl(cbr + BMIPS_RAC_CONFIG);
  535. __raw_writel(cfg | 0x100, cbr + BMIPS_RAC_CONFIG);
  536. __raw_readl(cbr + BMIPS_RAC_CONFIG);
  537. break;
  538. case CPU_BMIPS4380:
  539. /* CBG workaround for early BMIPS4380 CPUs */
  540. switch (read_c0_prid()) {
  541. case 0x2a040:
  542. case 0x2a042:
  543. case 0x2a044:
  544. case 0x2a060:
  545. cfg = __raw_readl(cbr + BMIPS_L2_CONFIG);
  546. __raw_writel(cfg & ~0x07000000, cbr + BMIPS_L2_CONFIG);
  547. __raw_readl(cbr + BMIPS_L2_CONFIG);
  548. }
  549. /* clear BHTD to enable branch history table */
  550. clear_c0_brcm_config_0(BIT(21));
  551. /* XI/ROTR enable */
  552. set_c0_brcm_config_0(BIT(23));
  553. set_c0_brcm_cmt_ctrl(BIT(15));
  554. break;
  555. case CPU_BMIPS5000:
  556. /* enable RDHWR, BRDHWR */
  557. set_c0_brcm_config(BIT(17) | BIT(21));
  558. /* Disable JTB */
  559. __asm__ __volatile__(
  560. " .set noreorder\n"
  561. " li $8, 0x5a455048\n"
  562. " .word 0x4088b00f\n" /* mtc0 t0, $22, 15 */
  563. " .word 0x4008b008\n" /* mfc0 t0, $22, 8 */
  564. " li $9, 0x00008000\n"
  565. " or $8, $8, $9\n"
  566. " .word 0x4088b008\n" /* mtc0 t0, $22, 8 */
  567. " sync\n"
  568. " li $8, 0x0\n"
  569. " .word 0x4088b00f\n" /* mtc0 t0, $22, 15 */
  570. " .set reorder\n"
  571. : : : "$8", "$9");
  572. /* XI enable */
  573. set_c0_brcm_config(BIT(27));
  574. /* enable MIPS32R2 ROR instruction for XI TLB handlers */
  575. __asm__ __volatile__(
  576. " li $8, 0x5a455048\n"
  577. " .word 0x4088b00f\n" /* mtc0 $8, $22, 15 */
  578. " nop; nop; nop\n"
  579. " .word 0x4008b008\n" /* mfc0 $8, $22, 8 */
  580. " lui $9, 0x0100\n"
  581. " or $8, $9\n"
  582. " .word 0x4088b008\n" /* mtc0 $8, $22, 8 */
  583. : : : "$8", "$9");
  584. break;
  585. }
  586. }