cps-vec.S 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. /*
  2. * Copyright (C) 2013 Imagination Technologies
  3. * Author: Paul Burton <paul.burton@imgtec.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_CL_COHERENCE_OFS 0x2008
  20. #define GCR_CL_ID_OFS 0x2028
  21. .extern mips_cm_base
  22. .set noreorder
  23. #ifdef CONFIG_64BIT
  24. # define STATUS_BITDEPS ST0_KX
  25. #else
  26. # define STATUS_BITDEPS 0
  27. #endif
  28. #ifdef CONFIG_MIPS_CPS_NS16550
  29. #define DUMP_EXCEP(name) \
  30. PTR_LA a0, 8f; \
  31. jal mips_cps_bev_dump; \
  32. nop; \
  33. TEXT(name)
  34. #else /* !CONFIG_MIPS_CPS_NS16550 */
  35. #define DUMP_EXCEP(name)
  36. #endif /* !CONFIG_MIPS_CPS_NS16550 */
  37. /*
  38. * Set dest to non-zero if the core supports the MT ASE, else zero. If
  39. * MT is not supported then branch to nomt.
  40. */
  41. .macro has_mt dest, nomt
  42. mfc0 \dest, CP0_CONFIG, 1
  43. bgez \dest, \nomt
  44. mfc0 \dest, CP0_CONFIG, 2
  45. bgez \dest, \nomt
  46. mfc0 \dest, CP0_CONFIG, 3
  47. andi \dest, \dest, MIPS_CONF3_MT
  48. beqz \dest, \nomt
  49. nop
  50. .endm
  51. .section .text.cps-vec
  52. .balign 0x1000
  53. LEAF(mips_cps_core_entry)
  54. /*
  55. * These first 4 bytes will be patched by cps_smp_setup to load the
  56. * CCA to use into register s0.
  57. */
  58. .word 0
  59. /* Check whether we're here due to an NMI */
  60. mfc0 k0, CP0_STATUS
  61. and k0, k0, ST0_NMI
  62. beqz k0, not_nmi
  63. nop
  64. /* This is an NMI */
  65. PTR_LA k0, nmi_handler
  66. jr k0
  67. nop
  68. not_nmi:
  69. /* Setup Cause */
  70. li t0, CAUSEF_IV
  71. mtc0 t0, CP0_CAUSE
  72. /* Setup Status */
  73. li t0, ST0_CU1 | ST0_CU0 | ST0_BEV | STATUS_BITDEPS
  74. mtc0 t0, CP0_STATUS
  75. /*
  76. * Clear the bits used to index the caches. Note that the architecture
  77. * dictates that writing to any of TagLo or TagHi selects 0 or 2 should
  78. * be valid for all MIPS32 CPUs, even those for which said writes are
  79. * unnecessary.
  80. */
  81. mtc0 zero, CP0_TAGLO, 0
  82. mtc0 zero, CP0_TAGHI, 0
  83. mtc0 zero, CP0_TAGLO, 2
  84. mtc0 zero, CP0_TAGHI, 2
  85. ehb
  86. /* Primary cache configuration is indicated by Config1 */
  87. mfc0 v0, CP0_CONFIG, 1
  88. /* Detect I-cache line size */
  89. _EXT t0, v0, MIPS_CONF1_IL_SHF, MIPS_CONF1_IL_SZ
  90. beqz t0, icache_done
  91. li t1, 2
  92. sllv t0, t1, t0
  93. /* Detect I-cache size */
  94. _EXT t1, v0, MIPS_CONF1_IS_SHF, MIPS_CONF1_IS_SZ
  95. xori t2, t1, 0x7
  96. beqz t2, 1f
  97. li t3, 32
  98. addiu t1, t1, 1
  99. sllv t1, t3, t1
  100. 1: /* At this point t1 == I-cache sets per way */
  101. _EXT t2, v0, MIPS_CONF1_IA_SHF, MIPS_CONF1_IA_SZ
  102. addiu t2, t2, 1
  103. mul t1, t1, t0
  104. mul t1, t1, t2
  105. li a0, CKSEG0
  106. PTR_ADD a1, a0, t1
  107. 1: cache Index_Store_Tag_I, 0(a0)
  108. PTR_ADD a0, a0, t0
  109. bne a0, a1, 1b
  110. nop
  111. icache_done:
  112. /* Detect D-cache line size */
  113. _EXT t0, v0, MIPS_CONF1_DL_SHF, MIPS_CONF1_DL_SZ
  114. beqz t0, dcache_done
  115. li t1, 2
  116. sllv t0, t1, t0
  117. /* Detect D-cache size */
  118. _EXT t1, v0, MIPS_CONF1_DS_SHF, MIPS_CONF1_DS_SZ
  119. xori t2, t1, 0x7
  120. beqz t2, 1f
  121. li t3, 32
  122. addiu t1, t1, 1
  123. sllv t1, t3, t1
  124. 1: /* At this point t1 == D-cache sets per way */
  125. _EXT t2, v0, MIPS_CONF1_DA_SHF, MIPS_CONF1_DA_SZ
  126. addiu t2, t2, 1
  127. mul t1, t1, t0
  128. mul t1, t1, t2
  129. li a0, CKSEG0
  130. PTR_ADDU a1, a0, t1
  131. PTR_SUBU a1, a1, t0
  132. 1: cache Index_Store_Tag_D, 0(a0)
  133. bne a0, a1, 1b
  134. PTR_ADD a0, a0, t0
  135. dcache_done:
  136. /* Set Kseg0 CCA to that in s0 */
  137. mfc0 t0, CP0_CONFIG
  138. ori t0, 0x7
  139. xori t0, 0x7
  140. or t0, t0, s0
  141. mtc0 t0, CP0_CONFIG
  142. ehb
  143. /* Calculate an uncached address for the CM GCRs */
  144. MFC0 v1, CP0_CMGCRBASE
  145. PTR_SLL v1, v1, 4
  146. PTR_LI t0, UNCAC_BASE
  147. PTR_ADDU v1, v1, t0
  148. /* Enter the coherent domain */
  149. li t0, 0xff
  150. sw t0, GCR_CL_COHERENCE_OFS(v1)
  151. ehb
  152. /* Jump to kseg0 */
  153. PTR_LA t0, 1f
  154. jr t0
  155. nop
  156. /*
  157. * We're up, cached & coherent. Perform any further required core-level
  158. * initialisation.
  159. */
  160. 1: jal mips_cps_core_init
  161. nop
  162. /* Do any EVA initialization if necessary */
  163. eva_init
  164. /*
  165. * Boot any other VPEs within this core that should be online, and
  166. * deactivate this VPE if it should be offline.
  167. */
  168. jal mips_cps_boot_vpes
  169. nop
  170. /* Off we go! */
  171. PTR_L t1, VPEBOOTCFG_PC(v0)
  172. PTR_L gp, VPEBOOTCFG_GP(v0)
  173. PTR_L sp, VPEBOOTCFG_SP(v0)
  174. jr t1
  175. nop
  176. END(mips_cps_core_entry)
  177. .org 0x200
  178. LEAF(excep_tlbfill)
  179. DUMP_EXCEP("TLB Fill")
  180. b .
  181. nop
  182. END(excep_tlbfill)
  183. .org 0x280
  184. LEAF(excep_xtlbfill)
  185. DUMP_EXCEP("XTLB Fill")
  186. b .
  187. nop
  188. END(excep_xtlbfill)
  189. .org 0x300
  190. LEAF(excep_cache)
  191. DUMP_EXCEP("Cache")
  192. b .
  193. nop
  194. END(excep_cache)
  195. .org 0x380
  196. LEAF(excep_genex)
  197. DUMP_EXCEP("General")
  198. b .
  199. nop
  200. END(excep_genex)
  201. .org 0x400
  202. LEAF(excep_intex)
  203. DUMP_EXCEP("Interrupt")
  204. b .
  205. nop
  206. END(excep_intex)
  207. .org 0x480
  208. LEAF(excep_ejtag)
  209. DUMP_EXCEP("EJTAG")
  210. PTR_LA k0, ejtag_debug_handler
  211. jr k0
  212. nop
  213. END(excep_ejtag)
  214. LEAF(mips_cps_core_init)
  215. #ifdef CONFIG_MIPS_MT_SMP
  216. /* Check that the core implements the MT ASE */
  217. has_mt t0, 3f
  218. .set push
  219. .set mt
  220. /* Only allow 1 TC per VPE to execute... */
  221. dmt
  222. /* ...and for the moment only 1 VPE */
  223. dvpe
  224. PTR_LA t1, 1f
  225. jr.hb t1
  226. nop
  227. /* Enter VPE configuration state */
  228. 1: mfc0 t0, CP0_MVPCONTROL
  229. ori t0, t0, MVPCONTROL_VPC
  230. mtc0 t0, CP0_MVPCONTROL
  231. /* Retrieve the number of VPEs within the core */
  232. mfc0 t0, CP0_MVPCONF0
  233. srl t0, t0, MVPCONF0_PVPE_SHIFT
  234. andi t0, t0, (MVPCONF0_PVPE >> MVPCONF0_PVPE_SHIFT)
  235. addiu ta3, t0, 1
  236. /* If there's only 1, we're done */
  237. beqz t0, 2f
  238. nop
  239. /* Loop through each VPE within this core */
  240. li ta1, 1
  241. 1: /* Operate on the appropriate TC */
  242. mtc0 ta1, CP0_VPECONTROL
  243. ehb
  244. /* Bind TC to VPE (1:1 TC:VPE mapping) */
  245. mttc0 ta1, CP0_TCBIND
  246. /* Set exclusive TC, non-active, master */
  247. li t0, VPECONF0_MVP
  248. sll t1, ta1, VPECONF0_XTC_SHIFT
  249. or t0, t0, t1
  250. mttc0 t0, CP0_VPECONF0
  251. /* Set TC non-active, non-allocatable */
  252. mttc0 zero, CP0_TCSTATUS
  253. /* Set TC halted */
  254. li t0, TCHALT_H
  255. mttc0 t0, CP0_TCHALT
  256. /* Next VPE */
  257. addiu ta1, ta1, 1
  258. slt t0, ta1, ta3
  259. bnez t0, 1b
  260. nop
  261. /* Leave VPE configuration state */
  262. 2: mfc0 t0, CP0_MVPCONTROL
  263. xori t0, t0, MVPCONTROL_VPC
  264. mtc0 t0, CP0_MVPCONTROL
  265. 3: .set pop
  266. #endif
  267. jr ra
  268. nop
  269. END(mips_cps_core_init)
  270. LEAF(mips_cps_boot_vpes)
  271. /* Retrieve CM base address */
  272. PTR_LA t0, mips_cm_base
  273. PTR_L t0, 0(t0)
  274. /* Calculate a pointer to this cores struct core_boot_config */
  275. lw t0, GCR_CL_ID_OFS(t0)
  276. li t1, COREBOOTCFG_SIZE
  277. mul t0, t0, t1
  278. PTR_LA t1, mips_cps_core_bootcfg
  279. PTR_L t1, 0(t1)
  280. PTR_ADDU t0, t0, t1
  281. /* Calculate this VPEs ID. If the core doesn't support MT use 0 */
  282. li t9, 0
  283. #ifdef CONFIG_MIPS_MT_SMP
  284. has_mt ta2, 1f
  285. /* Find the number of VPEs present in the core */
  286. mfc0 t1, CP0_MVPCONF0
  287. srl t1, t1, MVPCONF0_PVPE_SHIFT
  288. andi t1, t1, MVPCONF0_PVPE >> MVPCONF0_PVPE_SHIFT
  289. addiu t1, t1, 1
  290. /* Calculate a mask for the VPE ID from EBase.CPUNum */
  291. clz t1, t1
  292. li t2, 31
  293. subu t1, t2, t1
  294. li t2, 1
  295. sll t1, t2, t1
  296. addiu t1, t1, -1
  297. /* Retrieve the VPE ID from EBase.CPUNum */
  298. mfc0 t9, $15, 1
  299. and t9, t9, t1
  300. #endif
  301. 1: /* Calculate a pointer to this VPEs struct vpe_boot_config */
  302. li t1, VPEBOOTCFG_SIZE
  303. mul v0, t9, t1
  304. PTR_L ta3, COREBOOTCFG_VPECONFIG(t0)
  305. PTR_ADDU v0, v0, ta3
  306. #ifdef CONFIG_MIPS_MT_SMP
  307. /* If the core doesn't support MT then return */
  308. bnez ta2, 1f
  309. nop
  310. jr ra
  311. nop
  312. .set push
  313. .set mt
  314. 1: /* Enter VPE configuration state */
  315. dvpe
  316. PTR_LA t1, 1f
  317. jr.hb t1
  318. nop
  319. 1: mfc0 t1, CP0_MVPCONTROL
  320. ori t1, t1, MVPCONTROL_VPC
  321. mtc0 t1, CP0_MVPCONTROL
  322. ehb
  323. /* Loop through each VPE */
  324. PTR_L ta2, COREBOOTCFG_VPEMASK(t0)
  325. move t8, ta2
  326. li ta1, 0
  327. /* Check whether the VPE should be running. If not, skip it */
  328. 1: andi t0, ta2, 1
  329. beqz t0, 2f
  330. nop
  331. /* Operate on the appropriate TC */
  332. mfc0 t0, CP0_VPECONTROL
  333. ori t0, t0, VPECONTROL_TARGTC
  334. xori t0, t0, VPECONTROL_TARGTC
  335. or t0, t0, ta1
  336. mtc0 t0, CP0_VPECONTROL
  337. ehb
  338. /* Skip the VPE if its TC is not halted */
  339. mftc0 t0, CP0_TCHALT
  340. beqz t0, 2f
  341. nop
  342. /* Calculate a pointer to the VPEs struct vpe_boot_config */
  343. li t0, VPEBOOTCFG_SIZE
  344. mul t0, t0, ta1
  345. addu t0, t0, ta3
  346. /* Set the TC restart PC */
  347. lw t1, VPEBOOTCFG_PC(t0)
  348. mttc0 t1, CP0_TCRESTART
  349. /* Set the TC stack pointer */
  350. lw t1, VPEBOOTCFG_SP(t0)
  351. mttgpr t1, sp
  352. /* Set the TC global pointer */
  353. lw t1, VPEBOOTCFG_GP(t0)
  354. mttgpr t1, gp
  355. /* Copy config from this VPE */
  356. mfc0 t0, CP0_CONFIG
  357. mttc0 t0, CP0_CONFIG
  358. /* Ensure no software interrupts are pending */
  359. mttc0 zero, CP0_CAUSE
  360. mttc0 zero, CP0_STATUS
  361. /* Set TC active, not interrupt exempt */
  362. mftc0 t0, CP0_TCSTATUS
  363. li t1, ~TCSTATUS_IXMT
  364. and t0, t0, t1
  365. ori t0, t0, TCSTATUS_A
  366. mttc0 t0, CP0_TCSTATUS
  367. /* Clear the TC halt bit */
  368. mttc0 zero, CP0_TCHALT
  369. /* Set VPE active */
  370. mftc0 t0, CP0_VPECONF0
  371. ori t0, t0, VPECONF0_VPA
  372. mttc0 t0, CP0_VPECONF0
  373. /* Next VPE */
  374. 2: srl ta2, ta2, 1
  375. addiu ta1, ta1, 1
  376. bnez ta2, 1b
  377. nop
  378. /* Leave VPE configuration state */
  379. mfc0 t1, CP0_MVPCONTROL
  380. xori t1, t1, MVPCONTROL_VPC
  381. mtc0 t1, CP0_MVPCONTROL
  382. ehb
  383. evpe
  384. /* Check whether this VPE is meant to be running */
  385. li t0, 1
  386. sll t0, t0, t9
  387. and t0, t0, t8
  388. bnez t0, 2f
  389. nop
  390. /* This VPE should be offline, halt the TC */
  391. li t0, TCHALT_H
  392. mtc0 t0, CP0_TCHALT
  393. PTR_LA t0, 1f
  394. 1: jr.hb t0
  395. nop
  396. 2: .set pop
  397. #endif /* CONFIG_MIPS_MT_SMP */
  398. /* Return */
  399. jr ra
  400. nop
  401. END(mips_cps_boot_vpes)
  402. #if defined(CONFIG_MIPS_CPS_PM) && defined(CONFIG_CPU_PM)
  403. /* Calculate a pointer to this CPUs struct mips_static_suspend_state */
  404. .macro psstate dest
  405. .set push
  406. .set noat
  407. lw $1, TI_CPU(gp)
  408. sll $1, $1, LONGLOG
  409. PTR_LA \dest, __per_cpu_offset
  410. addu $1, $1, \dest
  411. lw $1, 0($1)
  412. PTR_LA \dest, cps_cpu_state
  413. addu \dest, \dest, $1
  414. .set pop
  415. .endm
  416. LEAF(mips_cps_pm_save)
  417. /* Save CPU state */
  418. SUSPEND_SAVE_REGS
  419. psstate t1
  420. SUSPEND_SAVE_STATIC
  421. jr v0
  422. nop
  423. END(mips_cps_pm_save)
  424. LEAF(mips_cps_pm_restore)
  425. /* Restore CPU state */
  426. psstate t1
  427. RESUME_RESTORE_STATIC
  428. RESUME_RESTORE_REGS_RETURN
  429. END(mips_cps_pm_restore)
  430. #endif /* CONFIG_MIPS_CPS_PM && CONFIG_CPU_PM */