head.S 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  1. /* head.S: Initial boot code for the Sparc64 port of Linux.
  2. *
  3. * Copyright (C) 1996, 1997, 2007 David S. Miller (davem@davemloft.net)
  4. * Copyright (C) 1996 David Sitsky (David.Sitsky@anu.edu.au)
  5. * Copyright (C) 1997, 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  6. * Copyright (C) 1997 Miguel de Icaza (miguel@nuclecu.unam.mx)
  7. */
  8. #include <linux/version.h>
  9. #include <linux/errno.h>
  10. #include <linux/threads.h>
  11. #include <linux/init.h>
  12. #include <asm/thread_info.h>
  13. #include <asm/asi.h>
  14. #include <asm/pstate.h>
  15. #include <asm/ptrace.h>
  16. #include <asm/spitfire.h>
  17. #include <asm/page.h>
  18. #include <asm/pgtable.h>
  19. #include <asm/errno.h>
  20. #include <asm/signal.h>
  21. #include <asm/processor.h>
  22. #include <asm/lsu.h>
  23. #include <asm/dcr.h>
  24. #include <asm/dcu.h>
  25. #include <asm/head.h>
  26. #include <asm/ttable.h>
  27. #include <asm/mmu.h>
  28. #include <asm/cpudata.h>
  29. /* This section from from _start to sparc64_boot_end should fit into
  30. * 0x0000000000404000 to 0x0000000000408000.
  31. */
  32. .text
  33. .globl start, _start, stext, _stext
  34. _start:
  35. start:
  36. _stext:
  37. stext:
  38. ! 0x0000000000404000
  39. b sparc64_boot
  40. flushw /* Flush register file. */
  41. /* This stuff has to be in sync with SILO and other potential boot loaders
  42. * Fields should be kept upward compatible and whenever any change is made,
  43. * HdrS version should be incremented.
  44. */
  45. .global root_flags, ram_flags, root_dev
  46. .global sparc_ramdisk_image, sparc_ramdisk_size
  47. .global sparc_ramdisk_image64
  48. .ascii "HdrS"
  49. .word LINUX_VERSION_CODE
  50. /* History:
  51. *
  52. * 0x0300 : Supports being located at other than 0x4000
  53. * 0x0202 : Supports kernel params string
  54. * 0x0201 : Supports reboot_command
  55. */
  56. .half 0x0301 /* HdrS version */
  57. root_flags:
  58. .half 1
  59. root_dev:
  60. .half 0
  61. ram_flags:
  62. .half 0
  63. sparc_ramdisk_image:
  64. .word 0
  65. sparc_ramdisk_size:
  66. .word 0
  67. .xword reboot_command
  68. .xword bootstr_info
  69. sparc_ramdisk_image64:
  70. .xword 0
  71. .word _end
  72. /* PROM cif handler code address is in %o4. */
  73. sparc64_boot:
  74. mov %o4, %l7
  75. /* We need to remap the kernel. Use position independant
  76. * code to remap us to KERNBASE.
  77. *
  78. * SILO can invoke us with 32-bit address masking enabled,
  79. * so make sure that's clear.
  80. */
  81. rdpr %pstate, %g1
  82. andn %g1, PSTATE_AM, %g1
  83. wrpr %g1, 0x0, %pstate
  84. ba,a,pt %xcc, 1f
  85. .globl prom_finddev_name, prom_chosen_path, prom_root_node
  86. .globl prom_getprop_name, prom_mmu_name, prom_peer_name
  87. .globl prom_callmethod_name, prom_translate_name, prom_root_compatible
  88. .globl prom_map_name, prom_unmap_name, prom_mmu_ihandle_cache
  89. .globl prom_boot_mapped_pc, prom_boot_mapping_mode
  90. .globl prom_boot_mapping_phys_high, prom_boot_mapping_phys_low
  91. .globl prom_compatible_name, prom_cpu_path, prom_cpu_compatible
  92. .globl is_sun4v, sun4v_chip_type, prom_set_trap_table_name
  93. prom_peer_name:
  94. .asciz "peer"
  95. prom_compatible_name:
  96. .asciz "compatible"
  97. prom_finddev_name:
  98. .asciz "finddevice"
  99. prom_chosen_path:
  100. .asciz "/chosen"
  101. prom_cpu_path:
  102. .asciz "/cpu"
  103. prom_getprop_name:
  104. .asciz "getprop"
  105. prom_mmu_name:
  106. .asciz "mmu"
  107. prom_callmethod_name:
  108. .asciz "call-method"
  109. prom_translate_name:
  110. .asciz "translate"
  111. prom_map_name:
  112. .asciz "map"
  113. prom_unmap_name:
  114. .asciz "unmap"
  115. prom_set_trap_table_name:
  116. .asciz "SUNW,set-trap-table"
  117. prom_sun4v_name:
  118. .asciz "sun4v"
  119. prom_niagara_prefix:
  120. .asciz "SUNW,UltraSPARC-T"
  121. .align 4
  122. prom_root_compatible:
  123. .skip 64
  124. prom_cpu_compatible:
  125. .skip 64
  126. prom_root_node:
  127. .word 0
  128. prom_mmu_ihandle_cache:
  129. .word 0
  130. prom_boot_mapped_pc:
  131. .word 0
  132. prom_boot_mapping_mode:
  133. .word 0
  134. .align 8
  135. prom_boot_mapping_phys_high:
  136. .xword 0
  137. prom_boot_mapping_phys_low:
  138. .xword 0
  139. is_sun4v:
  140. .word 0
  141. sun4v_chip_type:
  142. .word SUN4V_CHIP_INVALID
  143. 1:
  144. rd %pc, %l0
  145. mov (1b - prom_peer_name), %l1
  146. sub %l0, %l1, %l1
  147. mov 0, %l2
  148. /* prom_root_node = prom_peer(0) */
  149. stx %l1, [%sp + 2047 + 128 + 0x00] ! service, "peer"
  150. mov 1, %l3
  151. stx %l3, [%sp + 2047 + 128 + 0x08] ! num_args, 1
  152. stx %l3, [%sp + 2047 + 128 + 0x10] ! num_rets, 1
  153. stx %l2, [%sp + 2047 + 128 + 0x18] ! arg1, 0
  154. stx %g0, [%sp + 2047 + 128 + 0x20] ! ret1
  155. call %l7
  156. add %sp, (2047 + 128), %o0 ! argument array
  157. ldx [%sp + 2047 + 128 + 0x20], %l4 ! prom root node
  158. mov (1b - prom_root_node), %l1
  159. sub %l0, %l1, %l1
  160. stw %l4, [%l1]
  161. mov (1b - prom_getprop_name), %l1
  162. mov (1b - prom_compatible_name), %l2
  163. mov (1b - prom_root_compatible), %l5
  164. sub %l0, %l1, %l1
  165. sub %l0, %l2, %l2
  166. sub %l0, %l5, %l5
  167. /* prom_getproperty(prom_root_node, "compatible",
  168. * &prom_root_compatible, 64)
  169. */
  170. stx %l1, [%sp + 2047 + 128 + 0x00] ! service, "getprop"
  171. mov 4, %l3
  172. stx %l3, [%sp + 2047 + 128 + 0x08] ! num_args, 4
  173. mov 1, %l3
  174. stx %l3, [%sp + 2047 + 128 + 0x10] ! num_rets, 1
  175. stx %l4, [%sp + 2047 + 128 + 0x18] ! arg1, prom_root_node
  176. stx %l2, [%sp + 2047 + 128 + 0x20] ! arg2, "compatible"
  177. stx %l5, [%sp + 2047 + 128 + 0x28] ! arg3, &prom_root_compatible
  178. mov 64, %l3
  179. stx %l3, [%sp + 2047 + 128 + 0x30] ! arg4, size
  180. stx %g0, [%sp + 2047 + 128 + 0x38] ! ret1
  181. call %l7
  182. add %sp, (2047 + 128), %o0 ! argument array
  183. mov (1b - prom_finddev_name), %l1
  184. mov (1b - prom_chosen_path), %l2
  185. mov (1b - prom_boot_mapped_pc), %l3
  186. sub %l0, %l1, %l1
  187. sub %l0, %l2, %l2
  188. sub %l0, %l3, %l3
  189. stw %l0, [%l3]
  190. sub %sp, (192 + 128), %sp
  191. /* chosen_node = prom_finddevice("/chosen") */
  192. stx %l1, [%sp + 2047 + 128 + 0x00] ! service, "finddevice"
  193. mov 1, %l3
  194. stx %l3, [%sp + 2047 + 128 + 0x08] ! num_args, 1
  195. stx %l3, [%sp + 2047 + 128 + 0x10] ! num_rets, 1
  196. stx %l2, [%sp + 2047 + 128 + 0x18] ! arg1, "/chosen"
  197. stx %g0, [%sp + 2047 + 128 + 0x20] ! ret1
  198. call %l7
  199. add %sp, (2047 + 128), %o0 ! argument array
  200. ldx [%sp + 2047 + 128 + 0x20], %l4 ! chosen device node
  201. mov (1b - prom_getprop_name), %l1
  202. mov (1b - prom_mmu_name), %l2
  203. mov (1b - prom_mmu_ihandle_cache), %l5
  204. sub %l0, %l1, %l1
  205. sub %l0, %l2, %l2
  206. sub %l0, %l5, %l5
  207. /* prom_mmu_ihandle_cache = prom_getint(chosen_node, "mmu") */
  208. stx %l1, [%sp + 2047 + 128 + 0x00] ! service, "getprop"
  209. mov 4, %l3
  210. stx %l3, [%sp + 2047 + 128 + 0x08] ! num_args, 4
  211. mov 1, %l3
  212. stx %l3, [%sp + 2047 + 128 + 0x10] ! num_rets, 1
  213. stx %l4, [%sp + 2047 + 128 + 0x18] ! arg1, chosen_node
  214. stx %l2, [%sp + 2047 + 128 + 0x20] ! arg2, "mmu"
  215. stx %l5, [%sp + 2047 + 128 + 0x28] ! arg3, &prom_mmu_ihandle_cache
  216. mov 4, %l3
  217. stx %l3, [%sp + 2047 + 128 + 0x30] ! arg4, sizeof(arg3)
  218. stx %g0, [%sp + 2047 + 128 + 0x38] ! ret1
  219. call %l7
  220. add %sp, (2047 + 128), %o0 ! argument array
  221. mov (1b - prom_callmethod_name), %l1
  222. mov (1b - prom_translate_name), %l2
  223. sub %l0, %l1, %l1
  224. sub %l0, %l2, %l2
  225. lduw [%l5], %l5 ! prom_mmu_ihandle_cache
  226. stx %l1, [%sp + 2047 + 128 + 0x00] ! service, "call-method"
  227. mov 3, %l3
  228. stx %l3, [%sp + 2047 + 128 + 0x08] ! num_args, 3
  229. mov 5, %l3
  230. stx %l3, [%sp + 2047 + 128 + 0x10] ! num_rets, 5
  231. stx %l2, [%sp + 2047 + 128 + 0x18] ! arg1: "translate"
  232. stx %l5, [%sp + 2047 + 128 + 0x20] ! arg2: prom_mmu_ihandle_cache
  233. /* PAGE align */
  234. srlx %l0, 13, %l3
  235. sllx %l3, 13, %l3
  236. stx %l3, [%sp + 2047 + 128 + 0x28] ! arg3: vaddr, our PC
  237. stx %g0, [%sp + 2047 + 128 + 0x30] ! res1
  238. stx %g0, [%sp + 2047 + 128 + 0x38] ! res2
  239. stx %g0, [%sp + 2047 + 128 + 0x40] ! res3
  240. stx %g0, [%sp + 2047 + 128 + 0x48] ! res4
  241. stx %g0, [%sp + 2047 + 128 + 0x50] ! res5
  242. call %l7
  243. add %sp, (2047 + 128), %o0 ! argument array
  244. ldx [%sp + 2047 + 128 + 0x40], %l1 ! translation mode
  245. mov (1b - prom_boot_mapping_mode), %l4
  246. sub %l0, %l4, %l4
  247. stw %l1, [%l4]
  248. mov (1b - prom_boot_mapping_phys_high), %l4
  249. sub %l0, %l4, %l4
  250. ldx [%sp + 2047 + 128 + 0x48], %l2 ! physaddr high
  251. stx %l2, [%l4 + 0x0]
  252. ldx [%sp + 2047 + 128 + 0x50], %l3 ! physaddr low
  253. /* 4MB align */
  254. srlx %l3, 22, %l3
  255. sllx %l3, 22, %l3
  256. stx %l3, [%l4 + 0x8]
  257. /* Leave service as-is, "call-method" */
  258. mov 7, %l3
  259. stx %l3, [%sp + 2047 + 128 + 0x08] ! num_args, 7
  260. mov 1, %l3
  261. stx %l3, [%sp + 2047 + 128 + 0x10] ! num_rets, 1
  262. mov (1b - prom_map_name), %l3
  263. sub %l0, %l3, %l3
  264. stx %l3, [%sp + 2047 + 128 + 0x18] ! arg1: "map"
  265. /* Leave arg2 as-is, prom_mmu_ihandle_cache */
  266. mov -1, %l3
  267. stx %l3, [%sp + 2047 + 128 + 0x28] ! arg3: mode (-1 default)
  268. sethi %hi(8 * 1024 * 1024), %l3
  269. stx %l3, [%sp + 2047 + 128 + 0x30] ! arg4: size (8MB)
  270. sethi %hi(KERNBASE), %l3
  271. stx %l3, [%sp + 2047 + 128 + 0x38] ! arg5: vaddr (KERNBASE)
  272. stx %g0, [%sp + 2047 + 128 + 0x40] ! arg6: empty
  273. mov (1b - prom_boot_mapping_phys_low), %l3
  274. sub %l0, %l3, %l3
  275. ldx [%l3], %l3
  276. stx %l3, [%sp + 2047 + 128 + 0x48] ! arg7: phys addr
  277. call %l7
  278. add %sp, (2047 + 128), %o0 ! argument array
  279. add %sp, (192 + 128), %sp
  280. sethi %hi(prom_root_compatible), %g1
  281. or %g1, %lo(prom_root_compatible), %g1
  282. sethi %hi(prom_sun4v_name), %g7
  283. or %g7, %lo(prom_sun4v_name), %g7
  284. mov 5, %g3
  285. 90: ldub [%g7], %g2
  286. ldub [%g1], %g4
  287. cmp %g2, %g4
  288. bne,pn %icc, 80f
  289. add %g7, 1, %g7
  290. subcc %g3, 1, %g3
  291. bne,pt %xcc, 90b
  292. add %g1, 1, %g1
  293. sethi %hi(is_sun4v), %g1
  294. or %g1, %lo(is_sun4v), %g1
  295. mov 1, %g7
  296. stw %g7, [%g1]
  297. /* cpu_node = prom_finddevice("/cpu") */
  298. mov (1b - prom_finddev_name), %l1
  299. mov (1b - prom_cpu_path), %l2
  300. sub %l0, %l1, %l1
  301. sub %l0, %l2, %l2
  302. sub %sp, (192 + 128), %sp
  303. stx %l1, [%sp + 2047 + 128 + 0x00] ! service, "finddevice"
  304. mov 1, %l3
  305. stx %l3, [%sp + 2047 + 128 + 0x08] ! num_args, 1
  306. stx %l3, [%sp + 2047 + 128 + 0x10] ! num_rets, 1
  307. stx %l2, [%sp + 2047 + 128 + 0x18] ! arg1, "/cpu"
  308. stx %g0, [%sp + 2047 + 128 + 0x20] ! ret1
  309. call %l7
  310. add %sp, (2047 + 128), %o0 ! argument array
  311. ldx [%sp + 2047 + 128 + 0x20], %l4 ! cpu device node
  312. mov (1b - prom_getprop_name), %l1
  313. mov (1b - prom_compatible_name), %l2
  314. mov (1b - prom_cpu_compatible), %l5
  315. sub %l0, %l1, %l1
  316. sub %l0, %l2, %l2
  317. sub %l0, %l5, %l5
  318. /* prom_getproperty(cpu_node, "compatible",
  319. * &prom_cpu_compatible, 64)
  320. */
  321. stx %l1, [%sp + 2047 + 128 + 0x00] ! service, "getprop"
  322. mov 4, %l3
  323. stx %l3, [%sp + 2047 + 128 + 0x08] ! num_args, 4
  324. mov 1, %l3
  325. stx %l3, [%sp + 2047 + 128 + 0x10] ! num_rets, 1
  326. stx %l4, [%sp + 2047 + 128 + 0x18] ! arg1, cpu_node
  327. stx %l2, [%sp + 2047 + 128 + 0x20] ! arg2, "compatible"
  328. stx %l5, [%sp + 2047 + 128 + 0x28] ! arg3, &prom_cpu_compatible
  329. mov 64, %l3
  330. stx %l3, [%sp + 2047 + 128 + 0x30] ! arg4, size
  331. stx %g0, [%sp + 2047 + 128 + 0x38] ! ret1
  332. call %l7
  333. add %sp, (2047 + 128), %o0 ! argument array
  334. add %sp, (192 + 128), %sp
  335. sethi %hi(prom_cpu_compatible), %g1
  336. or %g1, %lo(prom_cpu_compatible), %g1
  337. sethi %hi(prom_niagara_prefix), %g7
  338. or %g7, %lo(prom_niagara_prefix), %g7
  339. mov 17, %g3
  340. 90: ldub [%g7], %g2
  341. ldub [%g1], %g4
  342. cmp %g2, %g4
  343. bne,pn %icc, 4f
  344. add %g7, 1, %g7
  345. subcc %g3, 1, %g3
  346. bne,pt %xcc, 90b
  347. add %g1, 1, %g1
  348. sethi %hi(prom_cpu_compatible), %g1
  349. or %g1, %lo(prom_cpu_compatible), %g1
  350. ldub [%g1 + 17], %g2
  351. cmp %g2, '1'
  352. be,pt %xcc, 5f
  353. mov SUN4V_CHIP_NIAGARA1, %g4
  354. cmp %g2, '2'
  355. be,pt %xcc, 5f
  356. mov SUN4V_CHIP_NIAGARA2, %g4
  357. 4:
  358. mov SUN4V_CHIP_UNKNOWN, %g4
  359. 5: sethi %hi(sun4v_chip_type), %g2
  360. or %g2, %lo(sun4v_chip_type), %g2
  361. stw %g4, [%g2]
  362. 80:
  363. BRANCH_IF_SUN4V(g1, jump_to_sun4u_init)
  364. BRANCH_IF_CHEETAH_BASE(g1,g7,cheetah_boot)
  365. BRANCH_IF_CHEETAH_PLUS_OR_FOLLOWON(g1,g7,cheetah_plus_boot)
  366. ba,pt %xcc, spitfire_boot
  367. nop
  368. cheetah_plus_boot:
  369. /* Preserve OBP chosen DCU and DCR register settings. */
  370. ba,pt %xcc, cheetah_generic_boot
  371. nop
  372. cheetah_boot:
  373. mov DCR_BPE | DCR_RPE | DCR_SI | DCR_IFPOE | DCR_MS, %g1
  374. wr %g1, %asr18
  375. sethi %uhi(DCU_ME|DCU_RE|DCU_HPE|DCU_SPE|DCU_SL|DCU_WE), %g7
  376. or %g7, %ulo(DCU_ME|DCU_RE|DCU_HPE|DCU_SPE|DCU_SL|DCU_WE), %g7
  377. sllx %g7, 32, %g7
  378. or %g7, DCU_DM | DCU_IM | DCU_DC | DCU_IC, %g7
  379. stxa %g7, [%g0] ASI_DCU_CONTROL_REG
  380. membar #Sync
  381. cheetah_generic_boot:
  382. mov TSB_EXTENSION_P, %g3
  383. stxa %g0, [%g3] ASI_DMMU
  384. stxa %g0, [%g3] ASI_IMMU
  385. membar #Sync
  386. mov TSB_EXTENSION_S, %g3
  387. stxa %g0, [%g3] ASI_DMMU
  388. membar #Sync
  389. mov TSB_EXTENSION_N, %g3
  390. stxa %g0, [%g3] ASI_DMMU
  391. stxa %g0, [%g3] ASI_IMMU
  392. membar #Sync
  393. ba,a,pt %xcc, jump_to_sun4u_init
  394. spitfire_boot:
  395. /* Typically PROM has already enabled both MMU's and both on-chip
  396. * caches, but we do it here anyway just to be paranoid.
  397. */
  398. mov (LSU_CONTROL_IC|LSU_CONTROL_DC|LSU_CONTROL_IM|LSU_CONTROL_DM), %g1
  399. stxa %g1, [%g0] ASI_LSU_CONTROL
  400. membar #Sync
  401. jump_to_sun4u_init:
  402. /*
  403. * Make sure we are in privileged mode, have address masking,
  404. * using the ordinary globals and have enabled floating
  405. * point.
  406. *
  407. * Again, typically PROM has left %pil at 13 or similar, and
  408. * (PSTATE_PRIV | PSTATE_PEF | PSTATE_IE) in %pstate.
  409. */
  410. wrpr %g0, (PSTATE_PRIV|PSTATE_PEF|PSTATE_IE), %pstate
  411. wr %g0, 0, %fprs
  412. set sun4u_init, %g2
  413. jmpl %g2 + %g0, %g0
  414. nop
  415. .section .text.init.refok
  416. sun4u_init:
  417. BRANCH_IF_SUN4V(g1, sun4v_init)
  418. /* Set ctx 0 */
  419. mov PRIMARY_CONTEXT, %g7
  420. stxa %g0, [%g7] ASI_DMMU
  421. membar #Sync
  422. mov SECONDARY_CONTEXT, %g7
  423. stxa %g0, [%g7] ASI_DMMU
  424. membar #Sync
  425. ba,pt %xcc, sun4u_continue
  426. nop
  427. sun4v_init:
  428. /* Set ctx 0 */
  429. mov PRIMARY_CONTEXT, %g7
  430. stxa %g0, [%g7] ASI_MMU
  431. membar #Sync
  432. mov SECONDARY_CONTEXT, %g7
  433. stxa %g0, [%g7] ASI_MMU
  434. membar #Sync
  435. ba,pt %xcc, niagara_tlb_fixup
  436. nop
  437. sun4u_continue:
  438. BRANCH_IF_ANY_CHEETAH(g1, g7, cheetah_tlb_fixup)
  439. ba,pt %xcc, spitfire_tlb_fixup
  440. nop
  441. niagara_tlb_fixup:
  442. mov 3, %g2 /* Set TLB type to hypervisor. */
  443. sethi %hi(tlb_type), %g1
  444. stw %g2, [%g1 + %lo(tlb_type)]
  445. /* Patch copy/clear ops. */
  446. sethi %hi(sun4v_chip_type), %g1
  447. lduw [%g1 + %lo(sun4v_chip_type)], %g1
  448. cmp %g1, SUN4V_CHIP_NIAGARA1
  449. be,pt %xcc, niagara_patch
  450. cmp %g1, SUN4V_CHIP_NIAGARA2
  451. be,pt %xcc, niagara2_patch
  452. nop
  453. call generic_patch_copyops
  454. nop
  455. call generic_patch_bzero
  456. nop
  457. call generic_patch_pageops
  458. nop
  459. ba,a,pt %xcc, 80f
  460. niagara2_patch:
  461. call niagara2_patch_copyops
  462. nop
  463. call niagara_patch_bzero
  464. nop
  465. call niagara2_patch_pageops
  466. nop
  467. ba,a,pt %xcc, 80f
  468. niagara_patch:
  469. call niagara_patch_copyops
  470. nop
  471. call niagara_patch_bzero
  472. nop
  473. call niagara_patch_pageops
  474. nop
  475. 80:
  476. /* Patch TLB/cache ops. */
  477. call hypervisor_patch_cachetlbops
  478. nop
  479. ba,pt %xcc, tlb_fixup_done
  480. nop
  481. cheetah_tlb_fixup:
  482. mov 2, %g2 /* Set TLB type to cheetah+. */
  483. BRANCH_IF_CHEETAH_PLUS_OR_FOLLOWON(g1,g7,1f)
  484. mov 1, %g2 /* Set TLB type to cheetah. */
  485. 1: sethi %hi(tlb_type), %g1
  486. stw %g2, [%g1 + %lo(tlb_type)]
  487. /* Patch copy/page operations to cheetah optimized versions. */
  488. call cheetah_patch_copyops
  489. nop
  490. call cheetah_patch_copy_page
  491. nop
  492. call cheetah_patch_cachetlbops
  493. nop
  494. ba,pt %xcc, tlb_fixup_done
  495. nop
  496. spitfire_tlb_fixup:
  497. /* Set TLB type to spitfire. */
  498. mov 0, %g2
  499. sethi %hi(tlb_type), %g1
  500. stw %g2, [%g1 + %lo(tlb_type)]
  501. tlb_fixup_done:
  502. sethi %hi(init_thread_union), %g6
  503. or %g6, %lo(init_thread_union), %g6
  504. ldx [%g6 + TI_TASK], %g4
  505. mov %sp, %l6
  506. wr %g0, ASI_P, %asi
  507. mov 1, %g1
  508. sllx %g1, THREAD_SHIFT, %g1
  509. sub %g1, (STACKFRAME_SZ + STACK_BIAS), %g1
  510. add %g6, %g1, %sp
  511. mov 0, %fp
  512. /* Set per-cpu pointer initially to zero, this makes
  513. * the boot-cpu use the in-kernel-image per-cpu areas
  514. * before setup_per_cpu_area() is invoked.
  515. */
  516. clr %g5
  517. wrpr %g0, 0, %wstate
  518. wrpr %g0, 0x0, %tl
  519. /* Clear the bss */
  520. sethi %hi(__bss_start), %o0
  521. or %o0, %lo(__bss_start), %o0
  522. sethi %hi(_end), %o1
  523. or %o1, %lo(_end), %o1
  524. call __bzero
  525. sub %o1, %o0, %o1
  526. #ifdef CONFIG_LOCKDEP
  527. /* We have this call this super early, as even prom_init can grab
  528. * spinlocks and thus call into the lockdep code.
  529. */
  530. call lockdep_init
  531. nop
  532. #endif
  533. mov %l6, %o1 ! OpenPROM stack
  534. call prom_init
  535. mov %l7, %o0 ! OpenPROM cif handler
  536. /* Initialize current_thread_info()->cpu as early as possible.
  537. * In order to do that accurately we have to patch up the get_cpuid()
  538. * assembler sequences. And that, in turn, requires that we know
  539. * if we are on a Starfire box or not. While we're here, patch up
  540. * the sun4v sequences as well.
  541. */
  542. call check_if_starfire
  543. nop
  544. call per_cpu_patch
  545. nop
  546. call sun4v_patch
  547. nop
  548. #ifdef CONFIG_SMP
  549. call hard_smp_processor_id
  550. nop
  551. cmp %o0, NR_CPUS
  552. blu,pt %xcc, 1f
  553. nop
  554. call boot_cpu_id_too_large
  555. nop
  556. /* Not reached... */
  557. 1:
  558. #else
  559. mov 0, %o0
  560. #endif
  561. sth %o0, [%g6 + TI_CPU]
  562. /* Off we go.... */
  563. call start_kernel
  564. nop
  565. /* Not reached... */
  566. .previous
  567. /* This is meant to allow the sharing of this code between
  568. * boot processor invocation (via setup_tba() below) and
  569. * secondary processor startup (via trampoline.S). The
  570. * former does use this code, the latter does not yet due
  571. * to some complexities. That should be fixed up at some
  572. * point.
  573. *
  574. * There used to be enormous complexity wrt. transferring
  575. * over from the firwmare's trap table to the Linux kernel's.
  576. * For example, there was a chicken & egg problem wrt. building
  577. * the OBP page tables, yet needing to be on the Linux kernel
  578. * trap table (to translate PAGE_OFFSET addresses) in order to
  579. * do that.
  580. *
  581. * We now handle OBP tlb misses differently, via linear lookups
  582. * into the prom_trans[] array. So that specific problem no
  583. * longer exists. Yet, unfortunately there are still some issues
  584. * preventing trampoline.S from using this code... ho hum.
  585. */
  586. .globl setup_trap_table
  587. setup_trap_table:
  588. save %sp, -192, %sp
  589. /* Force interrupts to be disabled. */
  590. rdpr %pstate, %l0
  591. andn %l0, PSTATE_IE, %o1
  592. wrpr %o1, 0x0, %pstate
  593. rdpr %pil, %l1
  594. wrpr %g0, 15, %pil
  595. /* Make the firmware call to jump over to the Linux trap table. */
  596. sethi %hi(is_sun4v), %o0
  597. lduw [%o0 + %lo(is_sun4v)], %o0
  598. brz,pt %o0, 1f
  599. nop
  600. TRAP_LOAD_TRAP_BLOCK(%g2, %g3)
  601. add %g2, TRAP_PER_CPU_FAULT_INFO, %g2
  602. stxa %g2, [%g0] ASI_SCRATCHPAD
  603. /* Compute physical address:
  604. *
  605. * paddr = kern_base + (mmfsa_vaddr - KERNBASE)
  606. */
  607. sethi %hi(KERNBASE), %g3
  608. sub %g2, %g3, %g2
  609. sethi %hi(kern_base), %g3
  610. ldx [%g3 + %lo(kern_base)], %g3
  611. add %g2, %g3, %o1
  612. sethi %hi(sparc64_ttable_tl0), %o0
  613. set prom_set_trap_table_name, %g2
  614. stx %g2, [%sp + 2047 + 128 + 0x00]
  615. mov 2, %g2
  616. stx %g2, [%sp + 2047 + 128 + 0x08]
  617. mov 0, %g2
  618. stx %g2, [%sp + 2047 + 128 + 0x10]
  619. stx %o0, [%sp + 2047 + 128 + 0x18]
  620. stx %o1, [%sp + 2047 + 128 + 0x20]
  621. sethi %hi(p1275buf), %g2
  622. or %g2, %lo(p1275buf), %g2
  623. ldx [%g2 + 0x08], %o1
  624. call %o1
  625. add %sp, (2047 + 128), %o0
  626. ba,pt %xcc, 2f
  627. nop
  628. 1: sethi %hi(sparc64_ttable_tl0), %o0
  629. set prom_set_trap_table_name, %g2
  630. stx %g2, [%sp + 2047 + 128 + 0x00]
  631. mov 1, %g2
  632. stx %g2, [%sp + 2047 + 128 + 0x08]
  633. mov 0, %g2
  634. stx %g2, [%sp + 2047 + 128 + 0x10]
  635. stx %o0, [%sp + 2047 + 128 + 0x18]
  636. sethi %hi(p1275buf), %g2
  637. or %g2, %lo(p1275buf), %g2
  638. ldx [%g2 + 0x08], %o1
  639. call %o1
  640. add %sp, (2047 + 128), %o0
  641. /* Start using proper page size encodings in ctx register. */
  642. 2: sethi %hi(sparc64_kern_pri_context), %g3
  643. ldx [%g3 + %lo(sparc64_kern_pri_context)], %g2
  644. mov PRIMARY_CONTEXT, %g1
  645. 661: stxa %g2, [%g1] ASI_DMMU
  646. .section .sun4v_1insn_patch, "ax"
  647. .word 661b
  648. stxa %g2, [%g1] ASI_MMU
  649. .previous
  650. membar #Sync
  651. BRANCH_IF_SUN4V(o2, 1f)
  652. /* Kill PROM timer */
  653. sethi %hi(0x80000000), %o2
  654. sllx %o2, 32, %o2
  655. wr %o2, 0, %tick_cmpr
  656. BRANCH_IF_ANY_CHEETAH(o2, o3, 1f)
  657. ba,pt %xcc, 2f
  658. nop
  659. /* Disable STICK_INT interrupts. */
  660. 1:
  661. sethi %hi(0x80000000), %o2
  662. sllx %o2, 32, %o2
  663. wr %o2, %asr25
  664. 2:
  665. wrpr %g0, %g0, %wstate
  666. call init_irqwork_curcpu
  667. nop
  668. /* Now we can restore interrupt state. */
  669. wrpr %l0, 0, %pstate
  670. wrpr %l1, 0x0, %pil
  671. ret
  672. restore
  673. .globl setup_tba
  674. setup_tba:
  675. save %sp, -192, %sp
  676. /* The boot processor is the only cpu which invokes this
  677. * routine, the other cpus set things up via trampoline.S.
  678. * So save the OBP trap table address here.
  679. */
  680. rdpr %tba, %g7
  681. sethi %hi(prom_tba), %o1
  682. or %o1, %lo(prom_tba), %o1
  683. stx %g7, [%o1]
  684. call setup_trap_table
  685. nop
  686. ret
  687. restore
  688. sparc64_boot_end:
  689. #include "etrap.S"
  690. #include "rtrap.S"
  691. #include "winfixup.S"
  692. #include "entry.S"
  693. #include "sun4v_tlb_miss.S"
  694. #include "sun4v_ivec.S"
  695. #include "ktlb.S"
  696. #include "tsb.S"
  697. /*
  698. * The following skip makes sure the trap table in ttable.S is aligned
  699. * on a 32K boundary as required by the v9 specs for TBA register.
  700. *
  701. * We align to a 32K boundary, then we have the 32K kernel TSB,
  702. * the 64K kernel 4MB TSB, and then the 32K aligned trap table.
  703. */
  704. 1:
  705. .skip 0x4000 + _start - 1b
  706. ! 0x0000000000408000
  707. .globl swapper_tsb
  708. swapper_tsb:
  709. .skip (32 * 1024)
  710. .globl swapper_4m_tsb
  711. swapper_4m_tsb:
  712. .skip (64 * 1024)
  713. ! 0x0000000000420000
  714. /* Some care needs to be exercised if you try to move the
  715. * location of the trap table relative to other things. For
  716. * one thing there are br* instructions in some of the
  717. * trap table entires which branch back to code in ktlb.S
  718. * Those instructions can only handle a signed 16-bit
  719. * displacement.
  720. *
  721. * There is a binutils bug (bugzilla #4558) which causes
  722. * the relocation overflow checks for such instructions to
  723. * not be done correctly. So bintuils will not notice the
  724. * error and will instead write junk into the relocation and
  725. * you'll have an unbootable kernel.
  726. */
  727. #include "ttable.S"
  728. ! 0x0000000000428000
  729. #include "systbls.S"
  730. .data
  731. .align 8
  732. .globl prom_tba, tlb_type
  733. prom_tba: .xword 0
  734. tlb_type: .word 0 /* Must NOT end up in BSS */
  735. .section ".fixup",#alloc,#execinstr
  736. .globl __ret_efault, __retl_efault
  737. __ret_efault:
  738. ret
  739. restore %g0, -EFAULT, %o0
  740. __retl_efault:
  741. retl
  742. mov -EFAULT, %o0