cps-vec.S 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. /*
  2. * Copyright (C) 2013 Imagination Technologies
  3. * Author: Paul Burton <paul.burton@mips.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. */
  10. #include <asm/addrspace.h>
  11. #include <asm/asm.h>
  12. #include <asm/asm-offsets.h>
  13. #include <asm/asmmacro.h>
  14. #include <asm/cacheops.h>
  15. #include <asm/eva.h>
  16. #include <asm/mipsregs.h>
  17. #include <asm/mipsmtregs.h>
  18. #include <asm/pm.h>
  19. #define GCR_CPC_BASE_OFS 0x0088
  20. #define GCR_CL_COHERENCE_OFS 0x2008
  21. #define GCR_CL_ID_OFS 0x2028
  22. #define CPC_CL_VC_STOP_OFS 0x2020
  23. #define CPC_CL_VC_RUN_OFS 0x2028
  24. .extern mips_cm_base
  25. .set noreorder
  26. #ifdef CONFIG_64BIT
  27. # define STATUS_BITDEPS ST0_KX
  28. #else
  29. # define STATUS_BITDEPS 0
  30. #endif
  31. #ifdef CONFIG_MIPS_CPS_NS16550
  32. #define DUMP_EXCEP(name) \
  33. PTR_LA a0, 8f; \
  34. jal mips_cps_bev_dump; \
  35. nop; \
  36. TEXT(name)
  37. #else /* !CONFIG_MIPS_CPS_NS16550 */
  38. #define DUMP_EXCEP(name)
  39. #endif /* !CONFIG_MIPS_CPS_NS16550 */
  40. /*
  41. * Set dest to non-zero if the core supports the MT ASE, else zero. If
  42. * MT is not supported then branch to nomt.
  43. */
  44. .macro has_mt dest, nomt
  45. mfc0 \dest, CP0_CONFIG, 1
  46. bgez \dest, \nomt
  47. mfc0 \dest, CP0_CONFIG, 2
  48. bgez \dest, \nomt
  49. mfc0 \dest, CP0_CONFIG, 3
  50. andi \dest, \dest, MIPS_CONF3_MT
  51. beqz \dest, \nomt
  52. nop
  53. .endm
  54. /*
  55. * Set dest to non-zero if the core supports MIPSr6 multithreading
  56. * (ie. VPs), else zero. If MIPSr6 multithreading is not supported then
  57. * branch to nomt.
  58. */
  59. .macro has_vp dest, nomt
  60. mfc0 \dest, CP0_CONFIG, 1
  61. bgez \dest, \nomt
  62. mfc0 \dest, CP0_CONFIG, 2
  63. bgez \dest, \nomt
  64. mfc0 \dest, CP0_CONFIG, 3
  65. bgez \dest, \nomt
  66. mfc0 \dest, CP0_CONFIG, 4
  67. bgez \dest, \nomt
  68. mfc0 \dest, CP0_CONFIG, 5
  69. andi \dest, \dest, MIPS_CONF5_VP
  70. beqz \dest, \nomt
  71. nop
  72. .endm
  73. /* Calculate an uncached address for the CM GCRs */
  74. .macro cmgcrb dest
  75. .set push
  76. .set noat
  77. MFC0 $1, CP0_CMGCRBASE
  78. PTR_SLL $1, $1, 4
  79. PTR_LI \dest, UNCAC_BASE
  80. PTR_ADDU \dest, \dest, $1
  81. .set pop
  82. .endm
  83. .section .text.cps-vec
  84. .balign 0x1000
  85. LEAF(mips_cps_core_entry)
  86. /*
  87. * These first 4 bytes will be patched by cps_smp_setup to load the
  88. * CCA to use into register s0.
  89. */
  90. .word 0
  91. /* Check whether we're here due to an NMI */
  92. mfc0 k0, CP0_STATUS
  93. and k0, k0, ST0_NMI
  94. beqz k0, not_nmi
  95. nop
  96. /* This is an NMI */
  97. PTR_LA k0, nmi_handler
  98. jr k0
  99. nop
  100. not_nmi:
  101. /* Setup Cause */
  102. li t0, CAUSEF_IV
  103. mtc0 t0, CP0_CAUSE
  104. /* Setup Status */
  105. li t0, ST0_CU1 | ST0_CU0 | ST0_BEV | STATUS_BITDEPS
  106. mtc0 t0, CP0_STATUS
  107. /* Skip cache & coherence setup if we're already coherent */
  108. cmgcrb v1
  109. lw s7, GCR_CL_COHERENCE_OFS(v1)
  110. bnez s7, 1f
  111. nop
  112. /* Initialize the L1 caches */
  113. jal mips_cps_cache_init
  114. nop
  115. /* Enter the coherent domain */
  116. li t0, 0xff
  117. sw t0, GCR_CL_COHERENCE_OFS(v1)
  118. ehb
  119. /* Set Kseg0 CCA to that in s0 */
  120. 1: mfc0 t0, CP0_CONFIG
  121. ori t0, 0x7
  122. xori t0, 0x7
  123. or t0, t0, s0
  124. mtc0 t0, CP0_CONFIG
  125. ehb
  126. /* Jump to kseg0 */
  127. PTR_LA t0, 1f
  128. jr t0
  129. nop
  130. /*
  131. * We're up, cached & coherent. Perform any EVA initialization necessary
  132. * before we access memory.
  133. */
  134. 1: eva_init
  135. /* Retrieve boot configuration pointers */
  136. jal mips_cps_get_bootcfg
  137. nop
  138. /* Skip core-level init if we started up coherent */
  139. bnez s7, 1f
  140. nop
  141. /* Perform any further required core-level initialisation */
  142. jal mips_cps_core_init
  143. nop
  144. /*
  145. * Boot any other VPEs within this core that should be online, and
  146. * deactivate this VPE if it should be offline.
  147. */
  148. move a1, t9
  149. jal mips_cps_boot_vpes
  150. move a0, v0
  151. /* Off we go! */
  152. 1: PTR_L t1, VPEBOOTCFG_PC(v1)
  153. PTR_L gp, VPEBOOTCFG_GP(v1)
  154. PTR_L sp, VPEBOOTCFG_SP(v1)
  155. jr t1
  156. nop
  157. END(mips_cps_core_entry)
  158. .org 0x200
  159. LEAF(excep_tlbfill)
  160. DUMP_EXCEP("TLB Fill")
  161. b .
  162. nop
  163. END(excep_tlbfill)
  164. .org 0x280
  165. LEAF(excep_xtlbfill)
  166. DUMP_EXCEP("XTLB Fill")
  167. b .
  168. nop
  169. END(excep_xtlbfill)
  170. .org 0x300
  171. LEAF(excep_cache)
  172. DUMP_EXCEP("Cache")
  173. b .
  174. nop
  175. END(excep_cache)
  176. .org 0x380
  177. LEAF(excep_genex)
  178. DUMP_EXCEP("General")
  179. b .
  180. nop
  181. END(excep_genex)
  182. .org 0x400
  183. LEAF(excep_intex)
  184. DUMP_EXCEP("Interrupt")
  185. b .
  186. nop
  187. END(excep_intex)
  188. .org 0x480
  189. LEAF(excep_ejtag)
  190. PTR_LA k0, ejtag_debug_handler
  191. jr k0
  192. nop
  193. END(excep_ejtag)
  194. LEAF(mips_cps_core_init)
  195. #ifdef CONFIG_MIPS_MT_SMP
  196. /* Check that the core implements the MT ASE */
  197. has_mt t0, 3f
  198. .set push
  199. .set mt
  200. /* Only allow 1 TC per VPE to execute... */
  201. dmt
  202. /* ...and for the moment only 1 VPE */
  203. dvpe
  204. PTR_LA t1, 1f
  205. jr.hb t1
  206. nop
  207. /* Enter VPE configuration state */
  208. 1: mfc0 t0, CP0_MVPCONTROL
  209. ori t0, t0, MVPCONTROL_VPC
  210. mtc0 t0, CP0_MVPCONTROL
  211. /* Retrieve the number of VPEs within the core */
  212. mfc0 t0, CP0_MVPCONF0
  213. srl t0, t0, MVPCONF0_PVPE_SHIFT
  214. andi t0, t0, (MVPCONF0_PVPE >> MVPCONF0_PVPE_SHIFT)
  215. addiu ta3, t0, 1
  216. /* If there's only 1, we're done */
  217. beqz t0, 2f
  218. nop
  219. /* Loop through each VPE within this core */
  220. li ta1, 1
  221. 1: /* Operate on the appropriate TC */
  222. mtc0 ta1, CP0_VPECONTROL
  223. ehb
  224. /* Bind TC to VPE (1:1 TC:VPE mapping) */
  225. mttc0 ta1, CP0_TCBIND
  226. /* Set exclusive TC, non-active, master */
  227. li t0, VPECONF0_MVP
  228. sll t1, ta1, VPECONF0_XTC_SHIFT
  229. or t0, t0, t1
  230. mttc0 t0, CP0_VPECONF0
  231. /* Set TC non-active, non-allocatable */
  232. mttc0 zero, CP0_TCSTATUS
  233. /* Set TC halted */
  234. li t0, TCHALT_H
  235. mttc0 t0, CP0_TCHALT
  236. /* Next VPE */
  237. addiu ta1, ta1, 1
  238. slt t0, ta1, ta3
  239. bnez t0, 1b
  240. nop
  241. /* Leave VPE configuration state */
  242. 2: mfc0 t0, CP0_MVPCONTROL
  243. xori t0, t0, MVPCONTROL_VPC
  244. mtc0 t0, CP0_MVPCONTROL
  245. 3: .set pop
  246. #endif
  247. jr ra
  248. nop
  249. END(mips_cps_core_init)
  250. /**
  251. * mips_cps_get_bootcfg() - retrieve boot configuration pointers
  252. *
  253. * Returns: pointer to struct core_boot_config in v0, pointer to
  254. * struct vpe_boot_config in v1, VPE ID in t9
  255. */
  256. LEAF(mips_cps_get_bootcfg)
  257. /* Calculate a pointer to this cores struct core_boot_config */
  258. cmgcrb t0
  259. lw t0, GCR_CL_ID_OFS(t0)
  260. li t1, COREBOOTCFG_SIZE
  261. mul t0, t0, t1
  262. PTR_LA t1, mips_cps_core_bootcfg
  263. PTR_L t1, 0(t1)
  264. PTR_ADDU v0, t0, t1
  265. /* Calculate this VPEs ID. If the core doesn't support MT use 0 */
  266. li t9, 0
  267. #if defined(CONFIG_CPU_MIPSR6)
  268. has_vp ta2, 1f
  269. /*
  270. * Assume non-contiguous numbering. Perhaps some day we'll need
  271. * to handle contiguous VP numbering, but no such systems yet
  272. * exist.
  273. */
  274. mfc0 t9, CP0_GLOBALNUMBER
  275. andi t9, t9, MIPS_GLOBALNUMBER_VP
  276. #elif defined(CONFIG_MIPS_MT_SMP)
  277. has_mt ta2, 1f
  278. /* Find the number of VPEs present in the core */
  279. mfc0 t1, CP0_MVPCONF0
  280. srl t1, t1, MVPCONF0_PVPE_SHIFT
  281. andi t1, t1, MVPCONF0_PVPE >> MVPCONF0_PVPE_SHIFT
  282. addiu t1, t1, 1
  283. /* Calculate a mask for the VPE ID from EBase.CPUNum */
  284. clz t1, t1
  285. li t2, 31
  286. subu t1, t2, t1
  287. li t2, 1
  288. sll t1, t2, t1
  289. addiu t1, t1, -1
  290. /* Retrieve the VPE ID from EBase.CPUNum */
  291. mfc0 t9, $15, 1
  292. and t9, t9, t1
  293. #endif
  294. 1: /* Calculate a pointer to this VPEs struct vpe_boot_config */
  295. li t1, VPEBOOTCFG_SIZE
  296. mul v1, t9, t1
  297. PTR_L ta3, COREBOOTCFG_VPECONFIG(v0)
  298. PTR_ADDU v1, v1, ta3
  299. jr ra
  300. nop
  301. END(mips_cps_get_bootcfg)
  302. LEAF(mips_cps_boot_vpes)
  303. lw ta2, COREBOOTCFG_VPEMASK(a0)
  304. PTR_L ta3, COREBOOTCFG_VPECONFIG(a0)
  305. #if defined(CONFIG_CPU_MIPSR6)
  306. has_vp t0, 5f
  307. /* Find base address of CPC */
  308. cmgcrb t3
  309. PTR_L t1, GCR_CPC_BASE_OFS(t3)
  310. PTR_LI t2, ~0x7fff
  311. and t1, t1, t2
  312. PTR_LI t2, UNCAC_BASE
  313. PTR_ADD t1, t1, t2
  314. /* Start any other VPs that ought to be running */
  315. PTR_S ta2, CPC_CL_VC_RUN_OFS(t1)
  316. /* Ensure this VP stops running if it shouldn't be */
  317. not ta2
  318. PTR_S ta2, CPC_CL_VC_STOP_OFS(t1)
  319. ehb
  320. #elif defined(CONFIG_MIPS_MT)
  321. .set push
  322. .set mt
  323. /* If the core doesn't support MT then return */
  324. has_mt t0, 5f
  325. /* Enter VPE configuration state */
  326. dvpe
  327. PTR_LA t1, 1f
  328. jr.hb t1
  329. nop
  330. 1: mfc0 t1, CP0_MVPCONTROL
  331. ori t1, t1, MVPCONTROL_VPC
  332. mtc0 t1, CP0_MVPCONTROL
  333. ehb
  334. /* Loop through each VPE */
  335. move t8, ta2
  336. li ta1, 0
  337. /* Check whether the VPE should be running. If not, skip it */
  338. 1: andi t0, ta2, 1
  339. beqz t0, 2f
  340. nop
  341. /* Operate on the appropriate TC */
  342. mfc0 t0, CP0_VPECONTROL
  343. ori t0, t0, VPECONTROL_TARGTC
  344. xori t0, t0, VPECONTROL_TARGTC
  345. or t0, t0, ta1
  346. mtc0 t0, CP0_VPECONTROL
  347. ehb
  348. /* Skip the VPE if its TC is not halted */
  349. mftc0 t0, CP0_TCHALT
  350. beqz t0, 2f
  351. nop
  352. /* Calculate a pointer to the VPEs struct vpe_boot_config */
  353. li t0, VPEBOOTCFG_SIZE
  354. mul t0, t0, ta1
  355. addu t0, t0, ta3
  356. /* Set the TC restart PC */
  357. lw t1, VPEBOOTCFG_PC(t0)
  358. mttc0 t1, CP0_TCRESTART
  359. /* Set the TC stack pointer */
  360. lw t1, VPEBOOTCFG_SP(t0)
  361. mttgpr t1, sp
  362. /* Set the TC global pointer */
  363. lw t1, VPEBOOTCFG_GP(t0)
  364. mttgpr t1, gp
  365. /* Copy config from this VPE */
  366. mfc0 t0, CP0_CONFIG
  367. mttc0 t0, CP0_CONFIG
  368. /*
  369. * Copy the EVA config from this VPE if the CPU supports it.
  370. * CONFIG3 must exist to be running MT startup - just read it.
  371. */
  372. mfc0 t0, CP0_CONFIG, 3
  373. and t0, t0, MIPS_CONF3_SC
  374. beqz t0, 3f
  375. nop
  376. mfc0 t0, CP0_SEGCTL0
  377. mttc0 t0, CP0_SEGCTL0
  378. mfc0 t0, CP0_SEGCTL1
  379. mttc0 t0, CP0_SEGCTL1
  380. mfc0 t0, CP0_SEGCTL2
  381. mttc0 t0, CP0_SEGCTL2
  382. 3:
  383. /* Ensure no software interrupts are pending */
  384. mttc0 zero, CP0_CAUSE
  385. mttc0 zero, CP0_STATUS
  386. /* Set TC active, not interrupt exempt */
  387. mftc0 t0, CP0_TCSTATUS
  388. li t1, ~TCSTATUS_IXMT
  389. and t0, t0, t1
  390. ori t0, t0, TCSTATUS_A
  391. mttc0 t0, CP0_TCSTATUS
  392. /* Clear the TC halt bit */
  393. mttc0 zero, CP0_TCHALT
  394. /* Set VPE active */
  395. mftc0 t0, CP0_VPECONF0
  396. ori t0, t0, VPECONF0_VPA
  397. mttc0 t0, CP0_VPECONF0
  398. /* Next VPE */
  399. 2: srl ta2, ta2, 1
  400. addiu ta1, ta1, 1
  401. bnez ta2, 1b
  402. nop
  403. /* Leave VPE configuration state */
  404. mfc0 t1, CP0_MVPCONTROL
  405. xori t1, t1, MVPCONTROL_VPC
  406. mtc0 t1, CP0_MVPCONTROL
  407. ehb
  408. evpe
  409. /* Check whether this VPE is meant to be running */
  410. li t0, 1
  411. sll t0, t0, a1
  412. and t0, t0, t8
  413. bnez t0, 2f
  414. nop
  415. /* This VPE should be offline, halt the TC */
  416. li t0, TCHALT_H
  417. mtc0 t0, CP0_TCHALT
  418. PTR_LA t0, 1f
  419. 1: jr.hb t0
  420. nop
  421. 2: .set pop
  422. #endif /* CONFIG_MIPS_MT_SMP */
  423. /* Return */
  424. 5: jr ra
  425. nop
  426. END(mips_cps_boot_vpes)
  427. LEAF(mips_cps_cache_init)
  428. /*
  429. * Clear the bits used to index the caches. Note that the architecture
  430. * dictates that writing to any of TagLo or TagHi selects 0 or 2 should
  431. * be valid for all MIPS32 CPUs, even those for which said writes are
  432. * unnecessary.
  433. */
  434. mtc0 zero, CP0_TAGLO, 0
  435. mtc0 zero, CP0_TAGHI, 0
  436. mtc0 zero, CP0_TAGLO, 2
  437. mtc0 zero, CP0_TAGHI, 2
  438. ehb
  439. /* Primary cache configuration is indicated by Config1 */
  440. mfc0 v0, CP0_CONFIG, 1
  441. /* Detect I-cache line size */
  442. _EXT t0, v0, MIPS_CONF1_IL_SHF, MIPS_CONF1_IL_SZ
  443. beqz t0, icache_done
  444. li t1, 2
  445. sllv t0, t1, t0
  446. /* Detect I-cache size */
  447. _EXT t1, v0, MIPS_CONF1_IS_SHF, MIPS_CONF1_IS_SZ
  448. xori t2, t1, 0x7
  449. beqz t2, 1f
  450. li t3, 32
  451. addiu t1, t1, 1
  452. sllv t1, t3, t1
  453. 1: /* At this point t1 == I-cache sets per way */
  454. _EXT t2, v0, MIPS_CONF1_IA_SHF, MIPS_CONF1_IA_SZ
  455. addiu t2, t2, 1
  456. mul t1, t1, t0
  457. mul t1, t1, t2
  458. li a0, CKSEG0
  459. PTR_ADD a1, a0, t1
  460. 1: cache Index_Store_Tag_I, 0(a0)
  461. PTR_ADD a0, a0, t0
  462. bne a0, a1, 1b
  463. nop
  464. icache_done:
  465. /* Detect D-cache line size */
  466. _EXT t0, v0, MIPS_CONF1_DL_SHF, MIPS_CONF1_DL_SZ
  467. beqz t0, dcache_done
  468. li t1, 2
  469. sllv t0, t1, t0
  470. /* Detect D-cache size */
  471. _EXT t1, v0, MIPS_CONF1_DS_SHF, MIPS_CONF1_DS_SZ
  472. xori t2, t1, 0x7
  473. beqz t2, 1f
  474. li t3, 32
  475. addiu t1, t1, 1
  476. sllv t1, t3, t1
  477. 1: /* At this point t1 == D-cache sets per way */
  478. _EXT t2, v0, MIPS_CONF1_DA_SHF, MIPS_CONF1_DA_SZ
  479. addiu t2, t2, 1
  480. mul t1, t1, t0
  481. mul t1, t1, t2
  482. li a0, CKSEG0
  483. PTR_ADDU a1, a0, t1
  484. PTR_SUBU a1, a1, t0
  485. 1: cache Index_Store_Tag_D, 0(a0)
  486. bne a0, a1, 1b
  487. PTR_ADD a0, a0, t0
  488. dcache_done:
  489. jr ra
  490. nop
  491. END(mips_cps_cache_init)
  492. #if defined(CONFIG_MIPS_CPS_PM) && defined(CONFIG_CPU_PM)
  493. /* Calculate a pointer to this CPUs struct mips_static_suspend_state */
  494. .macro psstate dest
  495. .set push
  496. .set noat
  497. lw $1, TI_CPU(gp)
  498. sll $1, $1, LONGLOG
  499. PTR_LA \dest, __per_cpu_offset
  500. addu $1, $1, \dest
  501. lw $1, 0($1)
  502. PTR_LA \dest, cps_cpu_state
  503. addu \dest, \dest, $1
  504. .set pop
  505. .endm
  506. LEAF(mips_cps_pm_save)
  507. /* Save CPU state */
  508. SUSPEND_SAVE_REGS
  509. psstate t1
  510. SUSPEND_SAVE_STATIC
  511. jr v0
  512. nop
  513. END(mips_cps_pm_save)
  514. LEAF(mips_cps_pm_restore)
  515. /* Restore CPU state */
  516. psstate t1
  517. RESUME_RESTORE_STATIC
  518. RESUME_RESTORE_REGS_RETURN
  519. END(mips_cps_pm_restore)
  520. #endif /* CONFIG_MIPS_CPS_PM && CONFIG_CPU_PM */