misc_64.S 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. /*
  2. * This file contains miscellaneous low-level functions.
  3. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  4. *
  5. * Largely rewritten by Cort Dougan (cort@cs.nmt.edu)
  6. * and Paul Mackerras.
  7. * Adapted for iSeries by Mike Corrigan (mikejc@us.ibm.com)
  8. * PPC64 updates by Dave Engebretsen (engebret@us.ibm.com)
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version
  13. * 2 of the License, or (at your option) any later version.
  14. *
  15. */
  16. #include <linux/sys.h>
  17. #include <asm/unistd.h>
  18. #include <asm/errno.h>
  19. #include <asm/processor.h>
  20. #include <asm/page.h>
  21. #include <asm/cache.h>
  22. #include <asm/ppc_asm.h>
  23. #include <asm/asm-offsets.h>
  24. #include <asm/cputable.h>
  25. #include <asm/thread_info.h>
  26. #include <asm/kexec.h>
  27. #include <asm/ptrace.h>
  28. .text
  29. _GLOBAL(call_do_softirq)
  30. mflr r0
  31. std r0,16(r1)
  32. stdu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r3)
  33. mr r1,r3
  34. bl .__do_softirq
  35. ld r1,0(r1)
  36. ld r0,16(r1)
  37. mtlr r0
  38. blr
  39. _GLOBAL(call_handle_irq)
  40. ld r8,0(r6)
  41. mflr r0
  42. std r0,16(r1)
  43. mtctr r8
  44. stdu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r5)
  45. mr r1,r5
  46. bctrl
  47. ld r1,0(r1)
  48. ld r0,16(r1)
  49. mtlr r0
  50. blr
  51. .section ".toc","aw"
  52. PPC64_CACHES:
  53. .tc ppc64_caches[TC],ppc64_caches
  54. .section ".text"
  55. /*
  56. * Write any modified data cache blocks out to memory
  57. * and invalidate the corresponding instruction cache blocks.
  58. *
  59. * flush_icache_range(unsigned long start, unsigned long stop)
  60. *
  61. * flush all bytes from start through stop-1 inclusive
  62. */
  63. _KPROBE(__flush_icache_range)
  64. /*
  65. * Flush the data cache to memory
  66. *
  67. * Different systems have different cache line sizes
  68. * and in some cases i-cache and d-cache line sizes differ from
  69. * each other.
  70. */
  71. ld r10,PPC64_CACHES@toc(r2)
  72. lwz r7,DCACHEL1LINESIZE(r10)/* Get cache line size */
  73. addi r5,r7,-1
  74. andc r6,r3,r5 /* round low to line bdy */
  75. subf r8,r6,r4 /* compute length */
  76. add r8,r8,r5 /* ensure we get enough */
  77. lwz r9,DCACHEL1LOGLINESIZE(r10) /* Get log-2 of cache line size */
  78. srw. r8,r8,r9 /* compute line count */
  79. beqlr /* nothing to do? */
  80. mtctr r8
  81. 1: dcbst 0,r6
  82. add r6,r6,r7
  83. bdnz 1b
  84. sync
  85. /* Now invalidate the instruction cache */
  86. lwz r7,ICACHEL1LINESIZE(r10) /* Get Icache line size */
  87. addi r5,r7,-1
  88. andc r6,r3,r5 /* round low to line bdy */
  89. subf r8,r6,r4 /* compute length */
  90. add r8,r8,r5
  91. lwz r9,ICACHEL1LOGLINESIZE(r10) /* Get log-2 of Icache line size */
  92. srw. r8,r8,r9 /* compute line count */
  93. beqlr /* nothing to do? */
  94. mtctr r8
  95. 2: icbi 0,r6
  96. add r6,r6,r7
  97. bdnz 2b
  98. isync
  99. blr
  100. .previous .text
  101. /*
  102. * Like above, but only do the D-cache.
  103. *
  104. * flush_dcache_range(unsigned long start, unsigned long stop)
  105. *
  106. * flush all bytes from start to stop-1 inclusive
  107. */
  108. _GLOBAL(flush_dcache_range)
  109. /*
  110. * Flush the data cache to memory
  111. *
  112. * Different systems have different cache line sizes
  113. */
  114. ld r10,PPC64_CACHES@toc(r2)
  115. lwz r7,DCACHEL1LINESIZE(r10) /* Get dcache line size */
  116. addi r5,r7,-1
  117. andc r6,r3,r5 /* round low to line bdy */
  118. subf r8,r6,r4 /* compute length */
  119. add r8,r8,r5 /* ensure we get enough */
  120. lwz r9,DCACHEL1LOGLINESIZE(r10) /* Get log-2 of dcache line size */
  121. srw. r8,r8,r9 /* compute line count */
  122. beqlr /* nothing to do? */
  123. mtctr r8
  124. 0: dcbst 0,r6
  125. add r6,r6,r7
  126. bdnz 0b
  127. sync
  128. blr
  129. /*
  130. * Like above, but works on non-mapped physical addresses.
  131. * Use only for non-LPAR setups ! It also assumes real mode
  132. * is cacheable. Used for flushing out the DART before using
  133. * it as uncacheable memory
  134. *
  135. * flush_dcache_phys_range(unsigned long start, unsigned long stop)
  136. *
  137. * flush all bytes from start to stop-1 inclusive
  138. */
  139. _GLOBAL(flush_dcache_phys_range)
  140. ld r10,PPC64_CACHES@toc(r2)
  141. lwz r7,DCACHEL1LINESIZE(r10) /* Get dcache line size */
  142. addi r5,r7,-1
  143. andc r6,r3,r5 /* round low to line bdy */
  144. subf r8,r6,r4 /* compute length */
  145. add r8,r8,r5 /* ensure we get enough */
  146. lwz r9,DCACHEL1LOGLINESIZE(r10) /* Get log-2 of dcache line size */
  147. srw. r8,r8,r9 /* compute line count */
  148. beqlr /* nothing to do? */
  149. mfmsr r5 /* Disable MMU Data Relocation */
  150. ori r0,r5,MSR_DR
  151. xori r0,r0,MSR_DR
  152. sync
  153. mtmsr r0
  154. sync
  155. isync
  156. mtctr r8
  157. 0: dcbst 0,r6
  158. add r6,r6,r7
  159. bdnz 0b
  160. sync
  161. isync
  162. mtmsr r5 /* Re-enable MMU Data Relocation */
  163. sync
  164. isync
  165. blr
  166. _GLOBAL(flush_inval_dcache_range)
  167. ld r10,PPC64_CACHES@toc(r2)
  168. lwz r7,DCACHEL1LINESIZE(r10) /* Get dcache line size */
  169. addi r5,r7,-1
  170. andc r6,r3,r5 /* round low to line bdy */
  171. subf r8,r6,r4 /* compute length */
  172. add r8,r8,r5 /* ensure we get enough */
  173. lwz r9,DCACHEL1LOGLINESIZE(r10)/* Get log-2 of dcache line size */
  174. srw. r8,r8,r9 /* compute line count */
  175. beqlr /* nothing to do? */
  176. sync
  177. isync
  178. mtctr r8
  179. 0: dcbf 0,r6
  180. add r6,r6,r7
  181. bdnz 0b
  182. sync
  183. isync
  184. blr
  185. /*
  186. * Flush a particular page from the data cache to RAM.
  187. * Note: this is necessary because the instruction cache does *not*
  188. * snoop from the data cache.
  189. *
  190. * void __flush_dcache_icache(void *page)
  191. */
  192. _GLOBAL(__flush_dcache_icache)
  193. /*
  194. * Flush the data cache to memory
  195. *
  196. * Different systems have different cache line sizes
  197. */
  198. /* Flush the dcache */
  199. ld r7,PPC64_CACHES@toc(r2)
  200. clrrdi r3,r3,PAGE_SHIFT /* Page align */
  201. lwz r4,DCACHEL1LINESPERPAGE(r7) /* Get # dcache lines per page */
  202. lwz r5,DCACHEL1LINESIZE(r7) /* Get dcache line size */
  203. mr r6,r3
  204. mtctr r4
  205. 0: dcbst 0,r6
  206. add r6,r6,r5
  207. bdnz 0b
  208. sync
  209. /* Now invalidate the icache */
  210. lwz r4,ICACHEL1LINESPERPAGE(r7) /* Get # icache lines per page */
  211. lwz r5,ICACHEL1LINESIZE(r7) /* Get icache line size */
  212. mtctr r4
  213. 1: icbi 0,r3
  214. add r3,r3,r5
  215. bdnz 1b
  216. isync
  217. blr
  218. _GLOBAL(__bswapdi2)
  219. srdi r8,r3,32
  220. rlwinm r7,r3,8,0xffffffff
  221. rlwimi r7,r3,24,0,7
  222. rlwinm r9,r8,8,0xffffffff
  223. rlwimi r7,r3,24,16,23
  224. rlwimi r9,r8,24,0,7
  225. rlwimi r9,r8,24,16,23
  226. sldi r7,r7,32
  227. or r3,r7,r9
  228. blr
  229. #if defined(CONFIG_PPC_PMAC) || defined(CONFIG_PPC_MAPLE)
  230. /*
  231. * Do an IO access in real mode
  232. */
  233. _GLOBAL(real_readb)
  234. mfmsr r7
  235. ori r0,r7,MSR_DR
  236. xori r0,r0,MSR_DR
  237. sync
  238. mtmsrd r0
  239. sync
  240. isync
  241. mfspr r6,SPRN_HID4
  242. rldicl r5,r6,32,0
  243. ori r5,r5,0x100
  244. rldicl r5,r5,32,0
  245. sync
  246. mtspr SPRN_HID4,r5
  247. isync
  248. slbia
  249. isync
  250. lbz r3,0(r3)
  251. sync
  252. mtspr SPRN_HID4,r6
  253. isync
  254. slbia
  255. isync
  256. mtmsrd r7
  257. sync
  258. isync
  259. blr
  260. /*
  261. * Do an IO access in real mode
  262. */
  263. _GLOBAL(real_writeb)
  264. mfmsr r7
  265. ori r0,r7,MSR_DR
  266. xori r0,r0,MSR_DR
  267. sync
  268. mtmsrd r0
  269. sync
  270. isync
  271. mfspr r6,SPRN_HID4
  272. rldicl r5,r6,32,0
  273. ori r5,r5,0x100
  274. rldicl r5,r5,32,0
  275. sync
  276. mtspr SPRN_HID4,r5
  277. isync
  278. slbia
  279. isync
  280. stb r3,0(r4)
  281. sync
  282. mtspr SPRN_HID4,r6
  283. isync
  284. slbia
  285. isync
  286. mtmsrd r7
  287. sync
  288. isync
  289. blr
  290. #endif /* defined(CONFIG_PPC_PMAC) || defined(CONFIG_PPC_MAPLE) */
  291. #ifdef CONFIG_PPC_PASEMI
  292. _GLOBAL(real_205_readb)
  293. mfmsr r7
  294. ori r0,r7,MSR_DR
  295. xori r0,r0,MSR_DR
  296. sync
  297. mtmsrd r0
  298. sync
  299. isync
  300. LBZCIX(R3,R0,R3)
  301. isync
  302. mtmsrd r7
  303. sync
  304. isync
  305. blr
  306. _GLOBAL(real_205_writeb)
  307. mfmsr r7
  308. ori r0,r7,MSR_DR
  309. xori r0,r0,MSR_DR
  310. sync
  311. mtmsrd r0
  312. sync
  313. isync
  314. STBCIX(R3,R0,R4)
  315. isync
  316. mtmsrd r7
  317. sync
  318. isync
  319. blr
  320. #endif /* CONFIG_PPC_PASEMI */
  321. #if defined(CONFIG_CPU_FREQ_PMAC64) || defined(CONFIG_CPU_FREQ_MAPLE)
  322. /*
  323. * SCOM access functions for 970 (FX only for now)
  324. *
  325. * unsigned long scom970_read(unsigned int address);
  326. * void scom970_write(unsigned int address, unsigned long value);
  327. *
  328. * The address passed in is the 24 bits register address. This code
  329. * is 970 specific and will not check the status bits, so you should
  330. * know what you are doing.
  331. */
  332. _GLOBAL(scom970_read)
  333. /* interrupts off */
  334. mfmsr r4
  335. ori r0,r4,MSR_EE
  336. xori r0,r0,MSR_EE
  337. mtmsrd r0,1
  338. /* rotate 24 bits SCOM address 8 bits left and mask out it's low 8 bits
  339. * (including parity). On current CPUs they must be 0'd,
  340. * and finally or in RW bit
  341. */
  342. rlwinm r3,r3,8,0,15
  343. ori r3,r3,0x8000
  344. /* do the actual scom read */
  345. sync
  346. mtspr SPRN_SCOMC,r3
  347. isync
  348. mfspr r3,SPRN_SCOMD
  349. isync
  350. mfspr r0,SPRN_SCOMC
  351. isync
  352. /* XXX: fixup result on some buggy 970's (ouch ! we lost a bit, bah
  353. * that's the best we can do). Not implemented yet as we don't use
  354. * the scom on any of the bogus CPUs yet, but may have to be done
  355. * ultimately
  356. */
  357. /* restore interrupts */
  358. mtmsrd r4,1
  359. blr
  360. _GLOBAL(scom970_write)
  361. /* interrupts off */
  362. mfmsr r5
  363. ori r0,r5,MSR_EE
  364. xori r0,r0,MSR_EE
  365. mtmsrd r0,1
  366. /* rotate 24 bits SCOM address 8 bits left and mask out it's low 8 bits
  367. * (including parity). On current CPUs they must be 0'd.
  368. */
  369. rlwinm r3,r3,8,0,15
  370. sync
  371. mtspr SPRN_SCOMD,r4 /* write data */
  372. isync
  373. mtspr SPRN_SCOMC,r3 /* write command */
  374. isync
  375. mfspr 3,SPRN_SCOMC
  376. isync
  377. /* restore interrupts */
  378. mtmsrd r5,1
  379. blr
  380. #endif /* CONFIG_CPU_FREQ_PMAC64 || CONFIG_CPU_FREQ_MAPLE */
  381. /*
  382. * disable_kernel_fp()
  383. * Disable the FPU.
  384. */
  385. _GLOBAL(disable_kernel_fp)
  386. mfmsr r3
  387. rldicl r0,r3,(63-MSR_FP_LG),1
  388. rldicl r3,r0,(MSR_FP_LG+1),0
  389. mtmsrd r3 /* disable use of fpu now */
  390. isync
  391. blr
  392. /* kexec_wait(phys_cpu)
  393. *
  394. * wait for the flag to change, indicating this kernel is going away but
  395. * the slave code for the next one is at addresses 0 to 100.
  396. *
  397. * This is used by all slaves, even those that did not find a matching
  398. * paca in the secondary startup code.
  399. *
  400. * Physical (hardware) cpu id should be in r3.
  401. */
  402. _GLOBAL(kexec_wait)
  403. bl 1f
  404. 1: mflr r5
  405. addi r5,r5,kexec_flag-1b
  406. 99: HMT_LOW
  407. #ifdef CONFIG_KEXEC /* use no memory without kexec */
  408. lwz r4,0(r5)
  409. cmpwi 0,r4,0
  410. bnea 0x60
  411. #endif
  412. b 99b
  413. /* this can be in text because we won't change it until we are
  414. * running in real anyways
  415. */
  416. kexec_flag:
  417. .long 0
  418. #ifdef CONFIG_KEXEC
  419. /* kexec_smp_wait(void)
  420. *
  421. * call with interrupts off
  422. * note: this is a terminal routine, it does not save lr
  423. *
  424. * get phys id from paca
  425. * switch to real mode
  426. * mark the paca as no longer used
  427. * join other cpus in kexec_wait(phys_id)
  428. */
  429. _GLOBAL(kexec_smp_wait)
  430. lhz r3,PACAHWCPUID(r13)
  431. bl real_mode
  432. li r4,KEXEC_STATE_REAL_MODE
  433. stb r4,PACAKEXECSTATE(r13)
  434. SYNC
  435. b .kexec_wait
  436. /*
  437. * switch to real mode (turn mmu off)
  438. * we use the early kernel trick that the hardware ignores bits
  439. * 0 and 1 (big endian) of the effective address in real mode
  440. *
  441. * don't overwrite r3 here, it is live for kexec_wait above.
  442. */
  443. real_mode: /* assume normal blr return */
  444. 1: li r9,MSR_RI
  445. li r10,MSR_DR|MSR_IR
  446. mflr r11 /* return address to SRR0 */
  447. mfmsr r12
  448. andc r9,r12,r9
  449. andc r10,r12,r10
  450. mtmsrd r9,1
  451. mtspr SPRN_SRR1,r10
  452. mtspr SPRN_SRR0,r11
  453. rfid
  454. /*
  455. * kexec_sequence(newstack, start, image, control, clear_all())
  456. *
  457. * does the grungy work with stack switching and real mode switches
  458. * also does simple calls to other code
  459. */
  460. _GLOBAL(kexec_sequence)
  461. mflr r0
  462. std r0,16(r1)
  463. /* switch stacks to newstack -- &kexec_stack.stack */
  464. stdu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r3)
  465. mr r1,r3
  466. li r0,0
  467. std r0,16(r1)
  468. /* save regs for local vars on new stack.
  469. * yes, we won't go back, but ...
  470. */
  471. std r31,-8(r1)
  472. std r30,-16(r1)
  473. std r29,-24(r1)
  474. std r28,-32(r1)
  475. std r27,-40(r1)
  476. std r26,-48(r1)
  477. std r25,-56(r1)
  478. stdu r1,-STACK_FRAME_OVERHEAD-64(r1)
  479. /* save args into preserved regs */
  480. mr r31,r3 /* newstack (both) */
  481. mr r30,r4 /* start (real) */
  482. mr r29,r5 /* image (virt) */
  483. mr r28,r6 /* control, unused */
  484. mr r27,r7 /* clear_all() fn desc */
  485. mr r26,r8 /* spare */
  486. lhz r25,PACAHWCPUID(r13) /* get our phys cpu from paca */
  487. /* disable interrupts, we are overwriting kernel data next */
  488. mfmsr r3
  489. rlwinm r3,r3,0,17,15
  490. mtmsrd r3,1
  491. /* copy dest pages, flush whole dest image */
  492. mr r3,r29
  493. bl .kexec_copy_flush /* (image) */
  494. /* turn off mmu */
  495. bl real_mode
  496. /* copy 0x100 bytes starting at start to 0 */
  497. li r3,0
  498. mr r4,r30 /* start, aka phys mem offset */
  499. li r5,0x100
  500. li r6,0
  501. bl .copy_and_flush /* (dest, src, copy limit, start offset) */
  502. 1: /* assume normal blr return */
  503. /* release other cpus to the new kernel secondary start at 0x60 */
  504. mflr r5
  505. li r6,1
  506. stw r6,kexec_flag-1b(5)
  507. /* clear out hardware hash page table and tlb */
  508. ld r5,0(r27) /* deref function descriptor */
  509. mtctr r5
  510. bctrl /* ppc_md.hpte_clear_all(void); */
  511. /*
  512. * kexec image calling is:
  513. * the first 0x100 bytes of the entry point are copied to 0
  514. *
  515. * all slaves branch to slave = 0x60 (absolute)
  516. * slave(phys_cpu_id);
  517. *
  518. * master goes to start = entry point
  519. * start(phys_cpu_id, start, 0);
  520. *
  521. *
  522. * a wrapper is needed to call existing kernels, here is an approximate
  523. * description of one method:
  524. *
  525. * v2: (2.6.10)
  526. * start will be near the boot_block (maybe 0x100 bytes before it?)
  527. * it will have a 0x60, which will b to boot_block, where it will wait
  528. * and 0 will store phys into struct boot-block and load r3 from there,
  529. * copy kernel 0-0x100 and tell slaves to back down to 0x60 again
  530. *
  531. * v1: (2.6.9)
  532. * boot block will have all cpus scanning device tree to see if they
  533. * are the boot cpu ?????
  534. * other device tree differences (prop sizes, va vs pa, etc)...
  535. */
  536. mr r3,r25 # my phys cpu
  537. mr r4,r30 # start, aka phys mem offset
  538. mtlr 4
  539. li r5,0
  540. blr /* image->start(physid, image->start, 0); */
  541. #endif /* CONFIG_KEXEC */