misc_32.S 23 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  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. *
  8. * kexec bits:
  9. * Copyright (C) 2002-2003 Eric Biederman <ebiederm@xmission.com>
  10. * GameCube/ppc32 port Copyright (C) 2004 Albert Herranz
  11. * PPC44x port. Copyright (C) 2011, IBM Corporation
  12. * Author: Suzuki Poulose <suzuki@in.ibm.com>
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version
  17. * 2 of the License, or (at your option) any later version.
  18. *
  19. */
  20. #include <linux/sys.h>
  21. #include <asm/unistd.h>
  22. #include <asm/errno.h>
  23. #include <asm/reg.h>
  24. #include <asm/page.h>
  25. #include <asm/cache.h>
  26. #include <asm/cputable.h>
  27. #include <asm/mmu.h>
  28. #include <asm/ppc_asm.h>
  29. #include <asm/thread_info.h>
  30. #include <asm/asm-offsets.h>
  31. #include <asm/processor.h>
  32. #include <asm/kexec.h>
  33. #include <asm/bug.h>
  34. #include <asm/ptrace.h>
  35. #include <asm/export.h>
  36. #include <asm/feature-fixups.h>
  37. .text
  38. /*
  39. * We store the saved ksp_limit in the unused part
  40. * of the STACK_FRAME_OVERHEAD
  41. */
  42. _GLOBAL(call_do_softirq)
  43. mflr r0
  44. stw r0,4(r1)
  45. lwz r10,THREAD+KSP_LIMIT(r2)
  46. addi r11,r3,THREAD_INFO_GAP
  47. stwu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r3)
  48. mr r1,r3
  49. stw r10,8(r1)
  50. stw r11,THREAD+KSP_LIMIT(r2)
  51. bl __do_softirq
  52. lwz r10,8(r1)
  53. lwz r1,0(r1)
  54. lwz r0,4(r1)
  55. stw r10,THREAD+KSP_LIMIT(r2)
  56. mtlr r0
  57. blr
  58. /*
  59. * void call_do_irq(struct pt_regs *regs, struct thread_info *irqtp);
  60. */
  61. _GLOBAL(call_do_irq)
  62. mflr r0
  63. stw r0,4(r1)
  64. lwz r10,THREAD+KSP_LIMIT(r2)
  65. addi r11,r4,THREAD_INFO_GAP
  66. stwu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r4)
  67. mr r1,r4
  68. stw r10,8(r1)
  69. stw r11,THREAD+KSP_LIMIT(r2)
  70. bl __do_irq
  71. lwz r10,8(r1)
  72. lwz r1,0(r1)
  73. lwz r0,4(r1)
  74. stw r10,THREAD+KSP_LIMIT(r2)
  75. mtlr r0
  76. blr
  77. /*
  78. * This returns the high 64 bits of the product of two 64-bit numbers.
  79. */
  80. _GLOBAL(mulhdu)
  81. cmpwi r6,0
  82. cmpwi cr1,r3,0
  83. mr r10,r4
  84. mulhwu r4,r4,r5
  85. beq 1f
  86. mulhwu r0,r10,r6
  87. mullw r7,r10,r5
  88. addc r7,r0,r7
  89. addze r4,r4
  90. 1: beqlr cr1 /* all done if high part of A is 0 */
  91. mullw r9,r3,r5
  92. mulhwu r10,r3,r5
  93. beq 2f
  94. mullw r0,r3,r6
  95. mulhwu r8,r3,r6
  96. addc r7,r0,r7
  97. adde r4,r4,r8
  98. addze r10,r10
  99. 2: addc r4,r4,r9
  100. addze r3,r10
  101. blr
  102. /*
  103. * reloc_got2 runs through the .got2 section adding an offset
  104. * to each entry.
  105. */
  106. _GLOBAL(reloc_got2)
  107. mflr r11
  108. lis r7,__got2_start@ha
  109. addi r7,r7,__got2_start@l
  110. lis r8,__got2_end@ha
  111. addi r8,r8,__got2_end@l
  112. subf r8,r7,r8
  113. srwi. r8,r8,2
  114. beqlr
  115. mtctr r8
  116. bl 1f
  117. 1: mflr r0
  118. lis r4,1b@ha
  119. addi r4,r4,1b@l
  120. subf r0,r4,r0
  121. add r7,r0,r7
  122. 2: lwz r0,0(r7)
  123. add r0,r0,r3
  124. stw r0,0(r7)
  125. addi r7,r7,4
  126. bdnz 2b
  127. mtlr r11
  128. blr
  129. /*
  130. * call_setup_cpu - call the setup_cpu function for this cpu
  131. * r3 = data offset, r24 = cpu number
  132. *
  133. * Setup function is called with:
  134. * r3 = data offset
  135. * r4 = ptr to CPU spec (relocated)
  136. */
  137. _GLOBAL(call_setup_cpu)
  138. addis r4,r3,cur_cpu_spec@ha
  139. addi r4,r4,cur_cpu_spec@l
  140. lwz r4,0(r4)
  141. add r4,r4,r3
  142. lwz r5,CPU_SPEC_SETUP(r4)
  143. cmpwi 0,r5,0
  144. add r5,r5,r3
  145. beqlr
  146. mtctr r5
  147. bctr
  148. #if defined(CONFIG_CPU_FREQ_PMAC) && defined(CONFIG_6xx)
  149. /* This gets called by via-pmu.c to switch the PLL selection
  150. * on 750fx CPU. This function should really be moved to some
  151. * other place (as most of the cpufreq code in via-pmu
  152. */
  153. _GLOBAL(low_choose_750fx_pll)
  154. /* Clear MSR:EE */
  155. mfmsr r7
  156. rlwinm r0,r7,0,17,15
  157. mtmsr r0
  158. /* If switching to PLL1, disable HID0:BTIC */
  159. cmplwi cr0,r3,0
  160. beq 1f
  161. mfspr r5,SPRN_HID0
  162. rlwinm r5,r5,0,27,25
  163. sync
  164. mtspr SPRN_HID0,r5
  165. isync
  166. sync
  167. 1:
  168. /* Calc new HID1 value */
  169. mfspr r4,SPRN_HID1 /* Build a HID1:PS bit from parameter */
  170. rlwinm r5,r3,16,15,15 /* Clear out HID1:PS from value read */
  171. rlwinm r4,r4,0,16,14 /* Could have I used rlwimi here ? */
  172. or r4,r4,r5
  173. mtspr SPRN_HID1,r4
  174. /* Store new HID1 image */
  175. CURRENT_THREAD_INFO(r6, r1)
  176. lwz r6,TI_CPU(r6)
  177. slwi r6,r6,2
  178. addis r6,r6,nap_save_hid1@ha
  179. stw r4,nap_save_hid1@l(r6)
  180. /* If switching to PLL0, enable HID0:BTIC */
  181. cmplwi cr0,r3,0
  182. bne 1f
  183. mfspr r5,SPRN_HID0
  184. ori r5,r5,HID0_BTIC
  185. sync
  186. mtspr SPRN_HID0,r5
  187. isync
  188. sync
  189. 1:
  190. /* Return */
  191. mtmsr r7
  192. blr
  193. _GLOBAL(low_choose_7447a_dfs)
  194. /* Clear MSR:EE */
  195. mfmsr r7
  196. rlwinm r0,r7,0,17,15
  197. mtmsr r0
  198. /* Calc new HID1 value */
  199. mfspr r4,SPRN_HID1
  200. insrwi r4,r3,1,9 /* insert parameter into bit 9 */
  201. sync
  202. mtspr SPRN_HID1,r4
  203. sync
  204. isync
  205. /* Return */
  206. mtmsr r7
  207. blr
  208. #endif /* CONFIG_CPU_FREQ_PMAC && CONFIG_6xx */
  209. /*
  210. * complement mask on the msr then "or" some values on.
  211. * _nmask_and_or_msr(nmask, value_to_or)
  212. */
  213. _GLOBAL(_nmask_and_or_msr)
  214. mfmsr r0 /* Get current msr */
  215. andc r0,r0,r3 /* And off the bits set in r3 (first parm) */
  216. or r0,r0,r4 /* Or on the bits in r4 (second parm) */
  217. SYNC /* Some chip revs have problems here... */
  218. mtmsr r0 /* Update machine state */
  219. isync
  220. blr /* Done */
  221. #ifdef CONFIG_40x
  222. /*
  223. * Do an IO access in real mode
  224. */
  225. _GLOBAL(real_readb)
  226. mfmsr r7
  227. rlwinm r0,r7,0,~MSR_DR
  228. sync
  229. mtmsr r0
  230. sync
  231. isync
  232. lbz r3,0(r3)
  233. sync
  234. mtmsr r7
  235. sync
  236. isync
  237. blr
  238. /*
  239. * Do an IO access in real mode
  240. */
  241. _GLOBAL(real_writeb)
  242. mfmsr r7
  243. rlwinm r0,r7,0,~MSR_DR
  244. sync
  245. mtmsr r0
  246. sync
  247. isync
  248. stb r3,0(r4)
  249. sync
  250. mtmsr r7
  251. sync
  252. isync
  253. blr
  254. #endif /* CONFIG_40x */
  255. /*
  256. * Flush instruction cache.
  257. * This is a no-op on the 601.
  258. */
  259. #ifndef CONFIG_PPC_8xx
  260. _GLOBAL(flush_instruction_cache)
  261. #if defined(CONFIG_4xx)
  262. #ifdef CONFIG_403GCX
  263. li r3, 512
  264. mtctr r3
  265. lis r4, KERNELBASE@h
  266. 1: iccci 0, r4
  267. addi r4, r4, 16
  268. bdnz 1b
  269. #else
  270. lis r3, KERNELBASE@h
  271. iccci 0,r3
  272. #endif
  273. #elif defined(CONFIG_FSL_BOOKE)
  274. BEGIN_FTR_SECTION
  275. mfspr r3,SPRN_L1CSR0
  276. ori r3,r3,L1CSR0_CFI|L1CSR0_CLFC
  277. /* msync; isync recommended here */
  278. mtspr SPRN_L1CSR0,r3
  279. isync
  280. blr
  281. END_FTR_SECTION_IFSET(CPU_FTR_UNIFIED_ID_CACHE)
  282. mfspr r3,SPRN_L1CSR1
  283. ori r3,r3,L1CSR1_ICFI|L1CSR1_ICLFR
  284. mtspr SPRN_L1CSR1,r3
  285. #else
  286. mfspr r3,SPRN_PVR
  287. rlwinm r3,r3,16,16,31
  288. cmpwi 0,r3,1
  289. beqlr /* for 601, do nothing */
  290. /* 603/604 processor - use invalidate-all bit in HID0 */
  291. mfspr r3,SPRN_HID0
  292. ori r3,r3,HID0_ICFI
  293. mtspr SPRN_HID0,r3
  294. #endif /* CONFIG_4xx */
  295. isync
  296. blr
  297. EXPORT_SYMBOL(flush_instruction_cache)
  298. #endif /* CONFIG_PPC_8xx */
  299. /*
  300. * Write any modified data cache blocks out to memory
  301. * and invalidate the corresponding instruction cache blocks.
  302. * This is a no-op on the 601.
  303. *
  304. * flush_icache_range(unsigned long start, unsigned long stop)
  305. */
  306. _GLOBAL(flush_icache_range)
  307. BEGIN_FTR_SECTION
  308. PURGE_PREFETCHED_INS
  309. blr /* for 601, do nothing */
  310. END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
  311. rlwinm r3,r3,0,0,31 - L1_CACHE_SHIFT
  312. subf r4,r3,r4
  313. addi r4,r4,L1_CACHE_BYTES - 1
  314. srwi. r4,r4,L1_CACHE_SHIFT
  315. beqlr
  316. mtctr r4
  317. mr r6,r3
  318. 1: dcbst 0,r3
  319. addi r3,r3,L1_CACHE_BYTES
  320. bdnz 1b
  321. sync /* wait for dcbst's to get to ram */
  322. #ifndef CONFIG_44x
  323. mtctr r4
  324. 2: icbi 0,r6
  325. addi r6,r6,L1_CACHE_BYTES
  326. bdnz 2b
  327. #else
  328. /* Flash invalidate on 44x because we are passed kmapped addresses and
  329. this doesn't work for userspace pages due to the virtually tagged
  330. icache. Sigh. */
  331. iccci 0, r0
  332. #endif
  333. sync /* additional sync needed on g4 */
  334. isync
  335. blr
  336. _ASM_NOKPROBE_SYMBOL(flush_icache_range)
  337. EXPORT_SYMBOL(flush_icache_range)
  338. /*
  339. * Flush a particular page from the data cache to RAM.
  340. * Note: this is necessary because the instruction cache does *not*
  341. * snoop from the data cache.
  342. * This is a no-op on the 601 which has a unified cache.
  343. *
  344. * void __flush_dcache_icache(void *page)
  345. */
  346. _GLOBAL(__flush_dcache_icache)
  347. BEGIN_FTR_SECTION
  348. PURGE_PREFETCHED_INS
  349. blr
  350. END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
  351. rlwinm r3,r3,0,0,31-PAGE_SHIFT /* Get page base address */
  352. li r4,PAGE_SIZE/L1_CACHE_BYTES /* Number of lines in a page */
  353. mtctr r4
  354. mr r6,r3
  355. 0: dcbst 0,r3 /* Write line to ram */
  356. addi r3,r3,L1_CACHE_BYTES
  357. bdnz 0b
  358. sync
  359. #ifdef CONFIG_44x
  360. /* We don't flush the icache on 44x. Those have a virtual icache
  361. * and we don't have access to the virtual address here (it's
  362. * not the page vaddr but where it's mapped in user space). The
  363. * flushing of the icache on these is handled elsewhere, when
  364. * a change in the address space occurs, before returning to
  365. * user space
  366. */
  367. BEGIN_MMU_FTR_SECTION
  368. blr
  369. END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_44x)
  370. #endif /* CONFIG_44x */
  371. mtctr r4
  372. 1: icbi 0,r6
  373. addi r6,r6,L1_CACHE_BYTES
  374. bdnz 1b
  375. sync
  376. isync
  377. blr
  378. #ifndef CONFIG_BOOKE
  379. /*
  380. * Flush a particular page from the data cache to RAM, identified
  381. * by its physical address. We turn off the MMU so we can just use
  382. * the physical address (this may be a highmem page without a kernel
  383. * mapping).
  384. *
  385. * void __flush_dcache_icache_phys(unsigned long physaddr)
  386. */
  387. _GLOBAL(__flush_dcache_icache_phys)
  388. BEGIN_FTR_SECTION
  389. PURGE_PREFETCHED_INS
  390. blr /* for 601, do nothing */
  391. END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
  392. mfmsr r10
  393. rlwinm r0,r10,0,28,26 /* clear DR */
  394. mtmsr r0
  395. isync
  396. rlwinm r3,r3,0,0,31-PAGE_SHIFT /* Get page base address */
  397. li r4,PAGE_SIZE/L1_CACHE_BYTES /* Number of lines in a page */
  398. mtctr r4
  399. mr r6,r3
  400. 0: dcbst 0,r3 /* Write line to ram */
  401. addi r3,r3,L1_CACHE_BYTES
  402. bdnz 0b
  403. sync
  404. mtctr r4
  405. 1: icbi 0,r6
  406. addi r6,r6,L1_CACHE_BYTES
  407. bdnz 1b
  408. sync
  409. mtmsr r10 /* restore DR */
  410. isync
  411. blr
  412. #endif /* CONFIG_BOOKE */
  413. /*
  414. * Copy a whole page. We use the dcbz instruction on the destination
  415. * to reduce memory traffic (it eliminates the unnecessary reads of
  416. * the destination into cache). This requires that the destination
  417. * is cacheable.
  418. */
  419. #define COPY_16_BYTES \
  420. lwz r6,4(r4); \
  421. lwz r7,8(r4); \
  422. lwz r8,12(r4); \
  423. lwzu r9,16(r4); \
  424. stw r6,4(r3); \
  425. stw r7,8(r3); \
  426. stw r8,12(r3); \
  427. stwu r9,16(r3)
  428. _GLOBAL(copy_page)
  429. addi r3,r3,-4
  430. addi r4,r4,-4
  431. li r5,4
  432. #if MAX_COPY_PREFETCH > 1
  433. li r0,MAX_COPY_PREFETCH
  434. li r11,4
  435. mtctr r0
  436. 11: dcbt r11,r4
  437. addi r11,r11,L1_CACHE_BYTES
  438. bdnz 11b
  439. #else /* MAX_COPY_PREFETCH == 1 */
  440. dcbt r5,r4
  441. li r11,L1_CACHE_BYTES+4
  442. #endif /* MAX_COPY_PREFETCH */
  443. li r0,PAGE_SIZE/L1_CACHE_BYTES - MAX_COPY_PREFETCH
  444. crclr 4*cr0+eq
  445. 2:
  446. mtctr r0
  447. 1:
  448. dcbt r11,r4
  449. dcbz r5,r3
  450. COPY_16_BYTES
  451. #if L1_CACHE_BYTES >= 32
  452. COPY_16_BYTES
  453. #if L1_CACHE_BYTES >= 64
  454. COPY_16_BYTES
  455. COPY_16_BYTES
  456. #if L1_CACHE_BYTES >= 128
  457. COPY_16_BYTES
  458. COPY_16_BYTES
  459. COPY_16_BYTES
  460. COPY_16_BYTES
  461. #endif
  462. #endif
  463. #endif
  464. bdnz 1b
  465. beqlr
  466. crnot 4*cr0+eq,4*cr0+eq
  467. li r0,MAX_COPY_PREFETCH
  468. li r11,4
  469. b 2b
  470. EXPORT_SYMBOL(copy_page)
  471. /*
  472. * Extended precision shifts.
  473. *
  474. * Updated to be valid for shift counts from 0 to 63 inclusive.
  475. * -- Gabriel
  476. *
  477. * R3/R4 has 64 bit value
  478. * R5 has shift count
  479. * result in R3/R4
  480. *
  481. * ashrdi3: arithmetic right shift (sign propagation)
  482. * lshrdi3: logical right shift
  483. * ashldi3: left shift
  484. */
  485. _GLOBAL(__ashrdi3)
  486. subfic r6,r5,32
  487. srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count
  488. addi r7,r5,32 # could be xori, or addi with -32
  489. slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count)
  490. rlwinm r8,r7,0,32 # t3 = (count < 32) ? 32 : 0
  491. sraw r7,r3,r7 # t2 = MSW >> (count-32)
  492. or r4,r4,r6 # LSW |= t1
  493. slw r7,r7,r8 # t2 = (count < 32) ? 0 : t2
  494. sraw r3,r3,r5 # MSW = MSW >> count
  495. or r4,r4,r7 # LSW |= t2
  496. blr
  497. EXPORT_SYMBOL(__ashrdi3)
  498. _GLOBAL(__ashldi3)
  499. subfic r6,r5,32
  500. slw r3,r3,r5 # MSW = count > 31 ? 0 : MSW << count
  501. addi r7,r5,32 # could be xori, or addi with -32
  502. srw r6,r4,r6 # t1 = count > 31 ? 0 : LSW >> (32-count)
  503. slw r7,r4,r7 # t2 = count < 32 ? 0 : LSW << (count-32)
  504. or r3,r3,r6 # MSW |= t1
  505. slw r4,r4,r5 # LSW = LSW << count
  506. or r3,r3,r7 # MSW |= t2
  507. blr
  508. EXPORT_SYMBOL(__ashldi3)
  509. _GLOBAL(__lshrdi3)
  510. subfic r6,r5,32
  511. srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count
  512. addi r7,r5,32 # could be xori, or addi with -32
  513. slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count)
  514. srw r7,r3,r7 # t2 = count < 32 ? 0 : MSW >> (count-32)
  515. or r4,r4,r6 # LSW |= t1
  516. srw r3,r3,r5 # MSW = MSW >> count
  517. or r4,r4,r7 # LSW |= t2
  518. blr
  519. EXPORT_SYMBOL(__lshrdi3)
  520. /*
  521. * 64-bit comparison: __cmpdi2(s64 a, s64 b)
  522. * Returns 0 if a < b, 1 if a == b, 2 if a > b.
  523. */
  524. _GLOBAL(__cmpdi2)
  525. cmpw r3,r5
  526. li r3,1
  527. bne 1f
  528. cmplw r4,r6
  529. beqlr
  530. 1: li r3,0
  531. bltlr
  532. li r3,2
  533. blr
  534. EXPORT_SYMBOL(__cmpdi2)
  535. /*
  536. * 64-bit comparison: __ucmpdi2(u64 a, u64 b)
  537. * Returns 0 if a < b, 1 if a == b, 2 if a > b.
  538. */
  539. _GLOBAL(__ucmpdi2)
  540. cmplw r3,r5
  541. li r3,1
  542. bne 1f
  543. cmplw r4,r6
  544. beqlr
  545. 1: li r3,0
  546. bltlr
  547. li r3,2
  548. blr
  549. EXPORT_SYMBOL(__ucmpdi2)
  550. _GLOBAL(__bswapdi2)
  551. rotlwi r9,r4,8
  552. rotlwi r10,r3,8
  553. rlwimi r9,r4,24,0,7
  554. rlwimi r10,r3,24,0,7
  555. rlwimi r9,r4,24,16,23
  556. rlwimi r10,r3,24,16,23
  557. mr r3,r9
  558. mr r4,r10
  559. blr
  560. EXPORT_SYMBOL(__bswapdi2)
  561. #ifdef CONFIG_SMP
  562. _GLOBAL(start_secondary_resume)
  563. /* Reset stack */
  564. CURRENT_THREAD_INFO(r1, r1)
  565. addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
  566. li r3,0
  567. stw r3,0(r1) /* Zero the stack frame pointer */
  568. bl start_secondary
  569. b .
  570. #endif /* CONFIG_SMP */
  571. /*
  572. * This routine is just here to keep GCC happy - sigh...
  573. */
  574. _GLOBAL(__main)
  575. blr
  576. #ifdef CONFIG_KEXEC_CORE
  577. /*
  578. * Must be relocatable PIC code callable as a C function.
  579. */
  580. .globl relocate_new_kernel
  581. relocate_new_kernel:
  582. /* r3 = page_list */
  583. /* r4 = reboot_code_buffer */
  584. /* r5 = start_address */
  585. #ifdef CONFIG_FSL_BOOKE
  586. mr r29, r3
  587. mr r30, r4
  588. mr r31, r5
  589. #define ENTRY_MAPPING_KEXEC_SETUP
  590. #include "fsl_booke_entry_mapping.S"
  591. #undef ENTRY_MAPPING_KEXEC_SETUP
  592. mr r3, r29
  593. mr r4, r30
  594. mr r5, r31
  595. li r0, 0
  596. #elif defined(CONFIG_44x)
  597. /* Save our parameters */
  598. mr r29, r3
  599. mr r30, r4
  600. mr r31, r5
  601. #ifdef CONFIG_PPC_47x
  602. /* Check for 47x cores */
  603. mfspr r3,SPRN_PVR
  604. srwi r3,r3,16
  605. cmplwi cr0,r3,PVR_476FPE@h
  606. beq setup_map_47x
  607. cmplwi cr0,r3,PVR_476@h
  608. beq setup_map_47x
  609. cmplwi cr0,r3,PVR_476_ISS@h
  610. beq setup_map_47x
  611. #endif /* CONFIG_PPC_47x */
  612. /*
  613. * Code for setting up 1:1 mapping for PPC440x for KEXEC
  614. *
  615. * We cannot switch off the MMU on PPC44x.
  616. * So we:
  617. * 1) Invalidate all the mappings except the one we are running from.
  618. * 2) Create a tmp mapping for our code in the other address space(TS) and
  619. * jump to it. Invalidate the entry we started in.
  620. * 3) Create a 1:1 mapping for 0-2GiB in chunks of 256M in original TS.
  621. * 4) Jump to the 1:1 mapping in original TS.
  622. * 5) Invalidate the tmp mapping.
  623. *
  624. * - Based on the kexec support code for FSL BookE
  625. *
  626. */
  627. /*
  628. * Load the PID with kernel PID (0).
  629. * Also load our MSR_IS and TID to MMUCR for TLB search.
  630. */
  631. li r3, 0
  632. mtspr SPRN_PID, r3
  633. mfmsr r4
  634. andi. r4,r4,MSR_IS@l
  635. beq wmmucr
  636. oris r3,r3,PPC44x_MMUCR_STS@h
  637. wmmucr:
  638. mtspr SPRN_MMUCR,r3
  639. sync
  640. /*
  641. * Invalidate all the TLB entries except the current entry
  642. * where we are running from
  643. */
  644. bl 0f /* Find our address */
  645. 0: mflr r5 /* Make it accessible */
  646. tlbsx r23,0,r5 /* Find entry we are in */
  647. li r4,0 /* Start at TLB entry 0 */
  648. li r3,0 /* Set PAGEID inval value */
  649. 1: cmpw r23,r4 /* Is this our entry? */
  650. beq skip /* If so, skip the inval */
  651. tlbwe r3,r4,PPC44x_TLB_PAGEID /* If not, inval the entry */
  652. skip:
  653. addi r4,r4,1 /* Increment */
  654. cmpwi r4,64 /* Are we done? */
  655. bne 1b /* If not, repeat */
  656. isync
  657. /* Create a temp mapping and jump to it */
  658. andi. r6, r23, 1 /* Find the index to use */
  659. addi r24, r6, 1 /* r24 will contain 1 or 2 */
  660. mfmsr r9 /* get the MSR */
  661. rlwinm r5, r9, 27, 31, 31 /* Extract the MSR[IS] */
  662. xori r7, r5, 1 /* Use the other address space */
  663. /* Read the current mapping entries */
  664. tlbre r3, r23, PPC44x_TLB_PAGEID
  665. tlbre r4, r23, PPC44x_TLB_XLAT
  666. tlbre r5, r23, PPC44x_TLB_ATTRIB
  667. /* Save our current XLAT entry */
  668. mr r25, r4
  669. /* Extract the TLB PageSize */
  670. li r10, 1 /* r10 will hold PageSize */
  671. rlwinm r11, r3, 0, 24, 27 /* bits 24-27 */
  672. /* XXX: As of now we use 256M, 4K pages */
  673. cmpwi r11, PPC44x_TLB_256M
  674. bne tlb_4k
  675. rotlwi r10, r10, 28 /* r10 = 256M */
  676. b write_out
  677. tlb_4k:
  678. cmpwi r11, PPC44x_TLB_4K
  679. bne default
  680. rotlwi r10, r10, 12 /* r10 = 4K */
  681. b write_out
  682. default:
  683. rotlwi r10, r10, 10 /* r10 = 1K */
  684. write_out:
  685. /*
  686. * Write out the tmp 1:1 mapping for this code in other address space
  687. * Fixup EPN = RPN , TS=other address space
  688. */
  689. insrwi r3, r7, 1, 23 /* Bit 23 is TS for PAGEID field */
  690. /* Write out the tmp mapping entries */
  691. tlbwe r3, r24, PPC44x_TLB_PAGEID
  692. tlbwe r4, r24, PPC44x_TLB_XLAT
  693. tlbwe r5, r24, PPC44x_TLB_ATTRIB
  694. subi r11, r10, 1 /* PageOffset Mask = PageSize - 1 */
  695. not r10, r11 /* Mask for PageNum */
  696. /* Switch to other address space in MSR */
  697. insrwi r9, r7, 1, 26 /* Set MSR[IS] = r7 */
  698. bl 1f
  699. 1: mflr r8
  700. addi r8, r8, (2f-1b) /* Find the target offset */
  701. /* Jump to the tmp mapping */
  702. mtspr SPRN_SRR0, r8
  703. mtspr SPRN_SRR1, r9
  704. rfi
  705. 2:
  706. /* Invalidate the entry we were executing from */
  707. li r3, 0
  708. tlbwe r3, r23, PPC44x_TLB_PAGEID
  709. /* attribute fields. rwx for SUPERVISOR mode */
  710. li r5, 0
  711. ori r5, r5, (PPC44x_TLB_SW | PPC44x_TLB_SR | PPC44x_TLB_SX | PPC44x_TLB_G)
  712. /* Create 1:1 mapping in 256M pages */
  713. xori r7, r7, 1 /* Revert back to Original TS */
  714. li r8, 0 /* PageNumber */
  715. li r6, 3 /* TLB Index, start at 3 */
  716. next_tlb:
  717. rotlwi r3, r8, 28 /* Create EPN (bits 0-3) */
  718. mr r4, r3 /* RPN = EPN */
  719. ori r3, r3, (PPC44x_TLB_VALID | PPC44x_TLB_256M) /* SIZE = 256M, Valid */
  720. insrwi r3, r7, 1, 23 /* Set TS from r7 */
  721. tlbwe r3, r6, PPC44x_TLB_PAGEID /* PageID field : EPN, V, SIZE */
  722. tlbwe r4, r6, PPC44x_TLB_XLAT /* Address translation : RPN */
  723. tlbwe r5, r6, PPC44x_TLB_ATTRIB /* Attributes */
  724. addi r8, r8, 1 /* Increment PN */
  725. addi r6, r6, 1 /* Increment TLB Index */
  726. cmpwi r8, 8 /* Are we done ? */
  727. bne next_tlb
  728. isync
  729. /* Jump to the new mapping 1:1 */
  730. li r9,0
  731. insrwi r9, r7, 1, 26 /* Set MSR[IS] = r7 */
  732. bl 1f
  733. 1: mflr r8
  734. and r8, r8, r11 /* Get our offset within page */
  735. addi r8, r8, (2f-1b)
  736. and r5, r25, r10 /* Get our target PageNum */
  737. or r8, r8, r5 /* Target jump address */
  738. mtspr SPRN_SRR0, r8
  739. mtspr SPRN_SRR1, r9
  740. rfi
  741. 2:
  742. /* Invalidate the tmp entry we used */
  743. li r3, 0
  744. tlbwe r3, r24, PPC44x_TLB_PAGEID
  745. sync
  746. b ppc44x_map_done
  747. #ifdef CONFIG_PPC_47x
  748. /* 1:1 mapping for 47x */
  749. setup_map_47x:
  750. /*
  751. * Load the kernel pid (0) to PID and also to MMUCR[TID].
  752. * Also set the MSR IS->MMUCR STS
  753. */
  754. li r3, 0
  755. mtspr SPRN_PID, r3 /* Set PID */
  756. mfmsr r4 /* Get MSR */
  757. andi. r4, r4, MSR_IS@l /* TS=1? */
  758. beq 1f /* If not, leave STS=0 */
  759. oris r3, r3, PPC47x_MMUCR_STS@h /* Set STS=1 */
  760. 1: mtspr SPRN_MMUCR, r3 /* Put MMUCR */
  761. sync
  762. /* Find the entry we are running from */
  763. bl 2f
  764. 2: mflr r23
  765. tlbsx r23, 0, r23
  766. tlbre r24, r23, 0 /* TLB Word 0 */
  767. tlbre r25, r23, 1 /* TLB Word 1 */
  768. tlbre r26, r23, 2 /* TLB Word 2 */
  769. /*
  770. * Invalidates all the tlb entries by writing to 256 RPNs(r4)
  771. * of 4k page size in all 4 ways (0-3 in r3).
  772. * This would invalidate the entire UTLB including the one we are
  773. * running from. However the shadow TLB entries would help us
  774. * to continue the execution, until we flush them (rfi/isync).
  775. */
  776. addis r3, 0, 0x8000 /* specify the way */
  777. addi r4, 0, 0 /* TLB Word0 = (EPN=0, VALID = 0) */
  778. addi r5, 0, 0
  779. b clear_utlb_entry
  780. /* Align the loop to speed things up. from head_44x.S */
  781. .align 6
  782. clear_utlb_entry:
  783. tlbwe r4, r3, 0
  784. tlbwe r5, r3, 1
  785. tlbwe r5, r3, 2
  786. addis r3, r3, 0x2000 /* Increment the way */
  787. cmpwi r3, 0
  788. bne clear_utlb_entry
  789. addis r3, 0, 0x8000
  790. addis r4, r4, 0x100 /* Increment the EPN */
  791. cmpwi r4, 0
  792. bne clear_utlb_entry
  793. /* Create the entries in the other address space */
  794. mfmsr r5
  795. rlwinm r7, r5, 27, 31, 31 /* Get the TS (Bit 26) from MSR */
  796. xori r7, r7, 1 /* r7 = !TS */
  797. insrwi r24, r7, 1, 21 /* Change the TS in the saved TLB word 0 */
  798. /*
  799. * write out the TLB entries for the tmp mapping
  800. * Use way '0' so that we could easily invalidate it later.
  801. */
  802. lis r3, 0x8000 /* Way '0' */
  803. tlbwe r24, r3, 0
  804. tlbwe r25, r3, 1
  805. tlbwe r26, r3, 2
  806. /* Update the msr to the new TS */
  807. insrwi r5, r7, 1, 26
  808. bl 1f
  809. 1: mflr r6
  810. addi r6, r6, (2f-1b)
  811. mtspr SPRN_SRR0, r6
  812. mtspr SPRN_SRR1, r5
  813. rfi
  814. /*
  815. * Now we are in the tmp address space.
  816. * Create a 1:1 mapping for 0-2GiB in the original TS.
  817. */
  818. 2:
  819. li r3, 0
  820. li r4, 0 /* TLB Word 0 */
  821. li r5, 0 /* TLB Word 1 */
  822. li r6, 0
  823. ori r6, r6, PPC47x_TLB2_S_RWX /* TLB word 2 */
  824. li r8, 0 /* PageIndex */
  825. xori r7, r7, 1 /* revert back to original TS */
  826. write_utlb:
  827. rotlwi r5, r8, 28 /* RPN = PageIndex * 256M */
  828. /* ERPN = 0 as we don't use memory above 2G */
  829. mr r4, r5 /* EPN = RPN */
  830. ori r4, r4, (PPC47x_TLB0_VALID | PPC47x_TLB0_256M)
  831. insrwi r4, r7, 1, 21 /* Insert the TS to Word 0 */
  832. tlbwe r4, r3, 0 /* Write out the entries */
  833. tlbwe r5, r3, 1
  834. tlbwe r6, r3, 2
  835. addi r8, r8, 1
  836. cmpwi r8, 8 /* Have we completed ? */
  837. bne write_utlb
  838. /* make sure we complete the TLB write up */
  839. isync
  840. /*
  841. * Prepare to jump to the 1:1 mapping.
  842. * 1) Extract page size of the tmp mapping
  843. * DSIZ = TLB_Word0[22:27]
  844. * 2) Calculate the physical address of the address
  845. * to jump to.
  846. */
  847. rlwinm r10, r24, 0, 22, 27
  848. cmpwi r10, PPC47x_TLB0_4K
  849. bne 0f
  850. li r10, 0x1000 /* r10 = 4k */
  851. bl 1f
  852. 0:
  853. /* Defaults to 256M */
  854. lis r10, 0x1000
  855. bl 1f
  856. 1: mflr r4
  857. addi r4, r4, (2f-1b) /* virtual address of 2f */
  858. subi r11, r10, 1 /* offsetmask = Pagesize - 1 */
  859. not r10, r11 /* Pagemask = ~(offsetmask) */
  860. and r5, r25, r10 /* Physical page */
  861. and r6, r4, r11 /* offset within the current page */
  862. or r5, r5, r6 /* Physical address for 2f */
  863. /* Switch the TS in MSR to the original one */
  864. mfmsr r8
  865. insrwi r8, r7, 1, 26
  866. mtspr SPRN_SRR1, r8
  867. mtspr SPRN_SRR0, r5
  868. rfi
  869. 2:
  870. /* Invalidate the tmp mapping */
  871. lis r3, 0x8000 /* Way '0' */
  872. clrrwi r24, r24, 12 /* Clear the valid bit */
  873. tlbwe r24, r3, 0
  874. tlbwe r25, r3, 1
  875. tlbwe r26, r3, 2
  876. /* Make sure we complete the TLB write and flush the shadow TLB */
  877. isync
  878. #endif
  879. ppc44x_map_done:
  880. /* Restore the parameters */
  881. mr r3, r29
  882. mr r4, r30
  883. mr r5, r31
  884. li r0, 0
  885. #else
  886. li r0, 0
  887. /*
  888. * Set Machine Status Register to a known status,
  889. * switch the MMU off and jump to 1: in a single step.
  890. */
  891. mr r8, r0
  892. ori r8, r8, MSR_RI|MSR_ME
  893. mtspr SPRN_SRR1, r8
  894. addi r8, r4, 1f - relocate_new_kernel
  895. mtspr SPRN_SRR0, r8
  896. sync
  897. rfi
  898. 1:
  899. #endif
  900. /* from this point address translation is turned off */
  901. /* and interrupts are disabled */
  902. /* set a new stack at the bottom of our page... */
  903. /* (not really needed now) */
  904. addi r1, r4, KEXEC_CONTROL_PAGE_SIZE - 8 /* for LR Save+Back Chain */
  905. stw r0, 0(r1)
  906. /* Do the copies */
  907. li r6, 0 /* checksum */
  908. mr r0, r3
  909. b 1f
  910. 0: /* top, read another word for the indirection page */
  911. lwzu r0, 4(r3)
  912. 1:
  913. /* is it a destination page? (r8) */
  914. rlwinm. r7, r0, 0, 31, 31 /* IND_DESTINATION (1<<0) */
  915. beq 2f
  916. rlwinm r8, r0, 0, 0, 19 /* clear kexec flags, page align */
  917. b 0b
  918. 2: /* is it an indirection page? (r3) */
  919. rlwinm. r7, r0, 0, 30, 30 /* IND_INDIRECTION (1<<1) */
  920. beq 2f
  921. rlwinm r3, r0, 0, 0, 19 /* clear kexec flags, page align */
  922. subi r3, r3, 4
  923. b 0b
  924. 2: /* are we done? */
  925. rlwinm. r7, r0, 0, 29, 29 /* IND_DONE (1<<2) */
  926. beq 2f
  927. b 3f
  928. 2: /* is it a source page? (r9) */
  929. rlwinm. r7, r0, 0, 28, 28 /* IND_SOURCE (1<<3) */
  930. beq 0b
  931. rlwinm r9, r0, 0, 0, 19 /* clear kexec flags, page align */
  932. li r7, PAGE_SIZE / 4
  933. mtctr r7
  934. subi r9, r9, 4
  935. subi r8, r8, 4
  936. 9:
  937. lwzu r0, 4(r9) /* do the copy */
  938. xor r6, r6, r0
  939. stwu r0, 4(r8)
  940. dcbst 0, r8
  941. sync
  942. icbi 0, r8
  943. bdnz 9b
  944. addi r9, r9, 4
  945. addi r8, r8, 4
  946. b 0b
  947. 3:
  948. /* To be certain of avoiding problems with self-modifying code
  949. * execute a serializing instruction here.
  950. */
  951. isync
  952. sync
  953. mfspr r3, SPRN_PIR /* current core we are running on */
  954. mr r4, r5 /* load physical address of chunk called */
  955. /* jump to the entry point, usually the setup routine */
  956. mtlr r5
  957. blrl
  958. 1: b 1b
  959. relocate_new_kernel_end:
  960. .globl relocate_new_kernel_size
  961. relocate_new_kernel_size:
  962. .long relocate_new_kernel_end - relocate_new_kernel
  963. #endif