smp-bmips.c 16 KB

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