misc_64.S 14 KB

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