head_fsl_booke.S 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339
  1. /*
  2. * Kernel execution entry point code.
  3. *
  4. * Copyright (c) 1995-1996 Gary Thomas <gdt@linuxppc.org>
  5. * Initial PowerPC version.
  6. * Copyright (c) 1996 Cort Dougan <cort@cs.nmt.edu>
  7. * Rewritten for PReP
  8. * Copyright (c) 1996 Paul Mackerras <paulus@cs.anu.edu.au>
  9. * Low-level exception handers, MMU support, and rewrite.
  10. * Copyright (c) 1997 Dan Malek <dmalek@jlc.net>
  11. * PowerPC 8xx modifications.
  12. * Copyright (c) 1998-1999 TiVo, Inc.
  13. * PowerPC 403GCX modifications.
  14. * Copyright (c) 1999 Grant Erickson <grant@lcse.umn.edu>
  15. * PowerPC 403GCX/405GP modifications.
  16. * Copyright 2000 MontaVista Software Inc.
  17. * PPC405 modifications
  18. * PowerPC 403GCX/405GP modifications.
  19. * Author: MontaVista Software, Inc.
  20. * frank_rowand@mvista.com or source@mvista.com
  21. * debbie_chu@mvista.com
  22. * Copyright 2002-2004 MontaVista Software, Inc.
  23. * PowerPC 44x support, Matt Porter <mporter@kernel.crashing.org>
  24. * Copyright 2004 Freescale Semiconductor, Inc
  25. * PowerPC e500 modifications, Kumar Gala <galak@kernel.crashing.org>
  26. *
  27. * This program is free software; you can redistribute it and/or modify it
  28. * under the terms of the GNU General Public License as published by the
  29. * Free Software Foundation; either version 2 of the License, or (at your
  30. * option) any later version.
  31. */
  32. #include <linux/init.h>
  33. #include <linux/threads.h>
  34. #include <asm/processor.h>
  35. #include <asm/page.h>
  36. #include <asm/mmu.h>
  37. #include <asm/pgtable.h>
  38. #include <asm/cputable.h>
  39. #include <asm/thread_info.h>
  40. #include <asm/ppc_asm.h>
  41. #include <asm/asm-offsets.h>
  42. #include <asm/cache.h>
  43. #include <asm/ptrace.h>
  44. #include "head_booke.h"
  45. /* As with the other PowerPC ports, it is expected that when code
  46. * execution begins here, the following registers contain valid, yet
  47. * optional, information:
  48. *
  49. * r3 - Board info structure pointer (DRAM, frequency, MAC address, etc.)
  50. * r4 - Starting address of the init RAM disk
  51. * r5 - Ending address of the init RAM disk
  52. * r6 - Start of kernel command line string (e.g. "mem=128")
  53. * r7 - End of kernel command line string
  54. *
  55. */
  56. __HEAD
  57. _ENTRY(_stext);
  58. _ENTRY(_start);
  59. /*
  60. * Reserve a word at a fixed location to store the address
  61. * of abatron_pteptrs
  62. */
  63. nop
  64. /* Translate device tree address to physical, save in r30/r31 */
  65. bl get_phys_addr
  66. mr r30,r3
  67. mr r31,r4
  68. li r25,0 /* phys kernel start (low) */
  69. li r24,0 /* CPU number */
  70. li r23,0 /* phys kernel start (high) */
  71. #ifdef CONFIG_RELOCATABLE
  72. LOAD_REG_ADDR_PIC(r3, _stext) /* Get our current runtime base */
  73. /* Translate _stext address to physical, save in r23/r25 */
  74. bl get_phys_addr
  75. mr r23,r3
  76. mr r25,r4
  77. bl 0f
  78. 0: mflr r8
  79. addis r3,r8,(is_second_reloc - 0b)@ha
  80. lwz r19,(is_second_reloc - 0b)@l(r3)
  81. /* Check if this is the second relocation. */
  82. cmpwi r19,1
  83. bne 1f
  84. /*
  85. * For the second relocation, we already get the real memstart_addr
  86. * from device tree. So we will map PAGE_OFFSET to memstart_addr,
  87. * then the virtual address of start kernel should be:
  88. * PAGE_OFFSET + (kernstart_addr - memstart_addr)
  89. * Since the offset between kernstart_addr and memstart_addr should
  90. * never be beyond 1G, so we can just use the lower 32bit of them
  91. * for the calculation.
  92. */
  93. lis r3,PAGE_OFFSET@h
  94. addis r4,r8,(kernstart_addr - 0b)@ha
  95. addi r4,r4,(kernstart_addr - 0b)@l
  96. lwz r5,4(r4)
  97. addis r6,r8,(memstart_addr - 0b)@ha
  98. addi r6,r6,(memstart_addr - 0b)@l
  99. lwz r7,4(r6)
  100. subf r5,r7,r5
  101. add r3,r3,r5
  102. b 2f
  103. 1:
  104. /*
  105. * We have the runtime (virutal) address of our base.
  106. * We calculate our shift of offset from a 64M page.
  107. * We could map the 64M page we belong to at PAGE_OFFSET and
  108. * get going from there.
  109. */
  110. lis r4,KERNELBASE@h
  111. ori r4,r4,KERNELBASE@l
  112. rlwinm r6,r25,0,0x3ffffff /* r6 = PHYS_START % 64M */
  113. rlwinm r5,r4,0,0x3ffffff /* r5 = KERNELBASE % 64M */
  114. subf r3,r5,r6 /* r3 = r6 - r5 */
  115. add r3,r4,r3 /* Required Virtual Address */
  116. 2: bl relocate
  117. /*
  118. * For the second relocation, we already set the right tlb entries
  119. * for the kernel space, so skip the code in fsl_booke_entry_mapping.S
  120. */
  121. cmpwi r19,1
  122. beq set_ivor
  123. #endif
  124. /* We try to not make any assumptions about how the boot loader
  125. * setup or used the TLBs. We invalidate all mappings from the
  126. * boot loader and load a single entry in TLB1[0] to map the
  127. * first 64M of kernel memory. Any boot info passed from the
  128. * bootloader needs to live in this first 64M.
  129. *
  130. * Requirement on bootloader:
  131. * - The page we're executing in needs to reside in TLB1 and
  132. * have IPROT=1. If not an invalidate broadcast could
  133. * evict the entry we're currently executing in.
  134. *
  135. * r3 = Index of TLB1 were executing in
  136. * r4 = Current MSR[IS]
  137. * r5 = Index of TLB1 temp mapping
  138. *
  139. * Later in mapin_ram we will correctly map lowmem, and resize TLB1[0]
  140. * if needed
  141. */
  142. _ENTRY(__early_start)
  143. #define ENTRY_MAPPING_BOOT_SETUP
  144. #include "fsl_booke_entry_mapping.S"
  145. #undef ENTRY_MAPPING_BOOT_SETUP
  146. set_ivor:
  147. /* Establish the interrupt vector offsets */
  148. SET_IVOR(0, CriticalInput);
  149. SET_IVOR(1, MachineCheck);
  150. SET_IVOR(2, DataStorage);
  151. SET_IVOR(3, InstructionStorage);
  152. SET_IVOR(4, ExternalInput);
  153. SET_IVOR(5, Alignment);
  154. SET_IVOR(6, Program);
  155. SET_IVOR(7, FloatingPointUnavailable);
  156. SET_IVOR(8, SystemCall);
  157. SET_IVOR(9, AuxillaryProcessorUnavailable);
  158. SET_IVOR(10, Decrementer);
  159. SET_IVOR(11, FixedIntervalTimer);
  160. SET_IVOR(12, WatchdogTimer);
  161. SET_IVOR(13, DataTLBError);
  162. SET_IVOR(14, InstructionTLBError);
  163. SET_IVOR(15, DebugCrit);
  164. /* Establish the interrupt vector base */
  165. lis r4,interrupt_base@h /* IVPR only uses the high 16-bits */
  166. mtspr SPRN_IVPR,r4
  167. /* Setup the defaults for TLB entries */
  168. li r2,(MAS4_TSIZED(BOOK3E_PAGESZ_4K))@l
  169. #ifdef CONFIG_E200
  170. oris r2,r2,MAS4_TLBSELD(1)@h
  171. #endif
  172. mtspr SPRN_MAS4, r2
  173. #if 0
  174. /* Enable DOZE */
  175. mfspr r2,SPRN_HID0
  176. oris r2,r2,HID0_DOZE@h
  177. mtspr SPRN_HID0, r2
  178. #endif
  179. #if !defined(CONFIG_BDI_SWITCH)
  180. /*
  181. * The Abatron BDI JTAG debugger does not tolerate others
  182. * mucking with the debug registers.
  183. */
  184. lis r2,DBCR0_IDM@h
  185. mtspr SPRN_DBCR0,r2
  186. isync
  187. /* clear any residual debug events */
  188. li r2,-1
  189. mtspr SPRN_DBSR,r2
  190. #endif
  191. #ifdef CONFIG_SMP
  192. /* Check to see if we're the second processor, and jump
  193. * to the secondary_start code if so
  194. */
  195. LOAD_REG_ADDR_PIC(r24, boot_cpuid)
  196. lwz r24, 0(r24)
  197. cmpwi r24, -1
  198. mfspr r24,SPRN_PIR
  199. bne __secondary_start
  200. #endif
  201. /*
  202. * This is where the main kernel code starts.
  203. */
  204. /* ptr to current */
  205. lis r2,init_task@h
  206. ori r2,r2,init_task@l
  207. /* ptr to current thread */
  208. addi r4,r2,THREAD /* init task's THREAD */
  209. mtspr SPRN_SPRG_THREAD,r4
  210. /* stack */
  211. lis r1,init_thread_union@h
  212. ori r1,r1,init_thread_union@l
  213. li r0,0
  214. stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1)
  215. CURRENT_THREAD_INFO(r22, r1)
  216. stw r24, TI_CPU(r22)
  217. bl early_init
  218. #ifdef CONFIG_RELOCATABLE
  219. mr r3,r30
  220. mr r4,r31
  221. #ifdef CONFIG_PHYS_64BIT
  222. mr r5,r23
  223. mr r6,r25
  224. #else
  225. mr r5,r25
  226. #endif
  227. bl relocate_init
  228. #endif
  229. #ifdef CONFIG_DYNAMIC_MEMSTART
  230. lis r3,kernstart_addr@ha
  231. la r3,kernstart_addr@l(r3)
  232. #ifdef CONFIG_PHYS_64BIT
  233. stw r23,0(r3)
  234. stw r25,4(r3)
  235. #else
  236. stw r25,0(r3)
  237. #endif
  238. #endif
  239. /*
  240. * Decide what sort of machine this is and initialize the MMU.
  241. */
  242. mr r3,r30
  243. mr r4,r31
  244. bl machine_init
  245. bl MMU_init
  246. /* Setup PTE pointers for the Abatron bdiGDB */
  247. lis r6, swapper_pg_dir@h
  248. ori r6, r6, swapper_pg_dir@l
  249. lis r5, abatron_pteptrs@h
  250. ori r5, r5, abatron_pteptrs@l
  251. lis r4, KERNELBASE@h
  252. ori r4, r4, KERNELBASE@l
  253. stw r5, 0(r4) /* Save abatron_pteptrs at a fixed location */
  254. stw r6, 0(r5)
  255. /* Let's move on */
  256. lis r4,start_kernel@h
  257. ori r4,r4,start_kernel@l
  258. lis r3,MSR_KERNEL@h
  259. ori r3,r3,MSR_KERNEL@l
  260. mtspr SPRN_SRR0,r4
  261. mtspr SPRN_SRR1,r3
  262. rfi /* change context and jump to start_kernel */
  263. /* Macros to hide the PTE size differences
  264. *
  265. * FIND_PTE -- walks the page tables given EA & pgdir pointer
  266. * r10 -- EA of fault
  267. * r11 -- PGDIR pointer
  268. * r12 -- free
  269. * label 2: is the bailout case
  270. *
  271. * if we find the pte (fall through):
  272. * r11 is low pte word
  273. * r12 is pointer to the pte
  274. * r10 is the pshift from the PGD, if we're a hugepage
  275. */
  276. #ifdef CONFIG_PTE_64BIT
  277. #ifdef CONFIG_HUGETLB_PAGE
  278. #define FIND_PTE \
  279. rlwinm r12, r10, 13, 19, 29; /* Compute pgdir/pmd offset */ \
  280. lwzx r11, r12, r11; /* Get pgd/pmd entry */ \
  281. rlwinm. r12, r11, 0, 0, 20; /* Extract pt base address */ \
  282. blt 1000f; /* Normal non-huge page */ \
  283. beq 2f; /* Bail if no table */ \
  284. oris r11, r11, PD_HUGE@h; /* Put back address bit */ \
  285. andi. r10, r11, HUGEPD_SHIFT_MASK@l; /* extract size field */ \
  286. xor r12, r10, r11; /* drop size bits from pointer */ \
  287. b 1001f; \
  288. 1000: rlwimi r12, r10, 23, 20, 28; /* Compute pte address */ \
  289. li r10, 0; /* clear r10 */ \
  290. 1001: lwz r11, 4(r12); /* Get pte entry */
  291. #else
  292. #define FIND_PTE \
  293. rlwinm r12, r10, 13, 19, 29; /* Compute pgdir/pmd offset */ \
  294. lwzx r11, r12, r11; /* Get pgd/pmd entry */ \
  295. rlwinm. r12, r11, 0, 0, 20; /* Extract pt base address */ \
  296. beq 2f; /* Bail if no table */ \
  297. rlwimi r12, r10, 23, 20, 28; /* Compute pte address */ \
  298. lwz r11, 4(r12); /* Get pte entry */
  299. #endif /* HUGEPAGE */
  300. #else /* !PTE_64BIT */
  301. #define FIND_PTE \
  302. rlwimi r11, r10, 12, 20, 29; /* Create L1 (pgdir/pmd) address */ \
  303. lwz r11, 0(r11); /* Get L1 entry */ \
  304. rlwinm. r12, r11, 0, 0, 19; /* Extract L2 (pte) base address */ \
  305. beq 2f; /* Bail if no table */ \
  306. rlwimi r12, r10, 22, 20, 29; /* Compute PTE address */ \
  307. lwz r11, 0(r12); /* Get Linux PTE */
  308. #endif
  309. /*
  310. * Interrupt vector entry code
  311. *
  312. * The Book E MMUs are always on so we don't need to handle
  313. * interrupts in real mode as with previous PPC processors. In
  314. * this case we handle interrupts in the kernel virtual address
  315. * space.
  316. *
  317. * Interrupt vectors are dynamically placed relative to the
  318. * interrupt prefix as determined by the address of interrupt_base.
  319. * The interrupt vectors offsets are programmed using the labels
  320. * for each interrupt vector entry.
  321. *
  322. * Interrupt vectors must be aligned on a 16 byte boundary.
  323. * We align on a 32 byte cache line boundary for good measure.
  324. */
  325. interrupt_base:
  326. /* Critical Input Interrupt */
  327. CRITICAL_EXCEPTION(0x0100, CRITICAL, CriticalInput, unknown_exception)
  328. /* Machine Check Interrupt */
  329. #ifdef CONFIG_E200
  330. /* no RFMCI, MCSRRs on E200 */
  331. CRITICAL_EXCEPTION(0x0200, MACHINE_CHECK, MachineCheck, \
  332. machine_check_exception)
  333. #else
  334. MCHECK_EXCEPTION(0x0200, MachineCheck, machine_check_exception)
  335. #endif
  336. /* Data Storage Interrupt */
  337. START_EXCEPTION(DataStorage)
  338. NORMAL_EXCEPTION_PROLOG(DATA_STORAGE)
  339. mfspr r5,SPRN_ESR /* Grab the ESR, save it, pass arg3 */
  340. stw r5,_ESR(r11)
  341. mfspr r4,SPRN_DEAR /* Grab the DEAR, save it, pass arg2 */
  342. andis. r10,r5,(ESR_ILK|ESR_DLK)@h
  343. bne 1f
  344. EXC_XFER_LITE(0x0300, handle_page_fault)
  345. 1:
  346. addi r3,r1,STACK_FRAME_OVERHEAD
  347. EXC_XFER_EE_LITE(0x0300, CacheLockingException)
  348. /* Instruction Storage Interrupt */
  349. INSTRUCTION_STORAGE_EXCEPTION
  350. /* External Input Interrupt */
  351. EXCEPTION(0x0500, EXTERNAL, ExternalInput, do_IRQ, EXC_XFER_LITE)
  352. /* Alignment Interrupt */
  353. ALIGNMENT_EXCEPTION
  354. /* Program Interrupt */
  355. PROGRAM_EXCEPTION
  356. /* Floating Point Unavailable Interrupt */
  357. #ifdef CONFIG_PPC_FPU
  358. FP_UNAVAILABLE_EXCEPTION
  359. #else
  360. #ifdef CONFIG_E200
  361. /* E200 treats 'normal' floating point instructions as FP Unavail exception */
  362. EXCEPTION(0x0800, FP_UNAVAIL, FloatingPointUnavailable, \
  363. program_check_exception, EXC_XFER_EE)
  364. #else
  365. EXCEPTION(0x0800, FP_UNAVAIL, FloatingPointUnavailable, \
  366. unknown_exception, EXC_XFER_EE)
  367. #endif
  368. #endif
  369. /* System Call Interrupt */
  370. START_EXCEPTION(SystemCall)
  371. NORMAL_EXCEPTION_PROLOG(SYSCALL)
  372. EXC_XFER_EE_LITE(0x0c00, DoSyscall)
  373. /* Auxiliary Processor Unavailable Interrupt */
  374. EXCEPTION(0x2900, AP_UNAVAIL, AuxillaryProcessorUnavailable, \
  375. unknown_exception, EXC_XFER_EE)
  376. /* Decrementer Interrupt */
  377. DECREMENTER_EXCEPTION
  378. /* Fixed Internal Timer Interrupt */
  379. /* TODO: Add FIT support */
  380. EXCEPTION(0x3100, FIT, FixedIntervalTimer, \
  381. unknown_exception, EXC_XFER_EE)
  382. /* Watchdog Timer Interrupt */
  383. #ifdef CONFIG_BOOKE_WDT
  384. CRITICAL_EXCEPTION(0x3200, WATCHDOG, WatchdogTimer, WatchdogException)
  385. #else
  386. CRITICAL_EXCEPTION(0x3200, WATCHDOG, WatchdogTimer, unknown_exception)
  387. #endif
  388. /* Data TLB Error Interrupt */
  389. START_EXCEPTION(DataTLBError)
  390. mtspr SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */
  391. mfspr r10, SPRN_SPRG_THREAD
  392. stw r11, THREAD_NORMSAVE(0)(r10)
  393. #ifdef CONFIG_KVM_BOOKE_HV
  394. BEGIN_FTR_SECTION
  395. mfspr r11, SPRN_SRR1
  396. END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV)
  397. #endif
  398. stw r12, THREAD_NORMSAVE(1)(r10)
  399. stw r13, THREAD_NORMSAVE(2)(r10)
  400. mfcr r13
  401. stw r13, THREAD_NORMSAVE(3)(r10)
  402. DO_KVM BOOKE_INTERRUPT_DTLB_MISS SPRN_SRR1
  403. mfspr r10, SPRN_DEAR /* Get faulting address */
  404. /* If we are faulting a kernel address, we have to use the
  405. * kernel page tables.
  406. */
  407. lis r11, PAGE_OFFSET@h
  408. cmplw 5, r10, r11
  409. blt 5, 3f
  410. lis r11, swapper_pg_dir@h
  411. ori r11, r11, swapper_pg_dir@l
  412. mfspr r12,SPRN_MAS1 /* Set TID to 0 */
  413. rlwinm r12,r12,0,16,1
  414. mtspr SPRN_MAS1,r12
  415. b 4f
  416. /* Get the PGD for the current thread */
  417. 3:
  418. mfspr r11,SPRN_SPRG_THREAD
  419. lwz r11,PGDIR(r11)
  420. 4:
  421. /* Mask of required permission bits. Note that while we
  422. * do copy ESR:ST to _PAGE_RW position as trying to write
  423. * to an RO page is pretty common, we don't do it with
  424. * _PAGE_DIRTY. We could do it, but it's a fairly rare
  425. * event so I'd rather take the overhead when it happens
  426. * rather than adding an instruction here. We should measure
  427. * whether the whole thing is worth it in the first place
  428. * as we could avoid loading SPRN_ESR completely in the first
  429. * place...
  430. *
  431. * TODO: Is it worth doing that mfspr & rlwimi in the first
  432. * place or can we save a couple of instructions here ?
  433. */
  434. mfspr r12,SPRN_ESR
  435. #ifdef CONFIG_PTE_64BIT
  436. li r13,_PAGE_PRESENT
  437. oris r13,r13,_PAGE_ACCESSED@h
  438. #else
  439. li r13,_PAGE_PRESENT|_PAGE_ACCESSED
  440. #endif
  441. rlwimi r13,r12,11,29,29
  442. FIND_PTE
  443. andc. r13,r13,r11 /* Check permission */
  444. #ifdef CONFIG_PTE_64BIT
  445. #ifdef CONFIG_SMP
  446. subf r13,r11,r12 /* create false data dep */
  447. lwzx r13,r11,r13 /* Get upper pte bits */
  448. #else
  449. lwz r13,0(r12) /* Get upper pte bits */
  450. #endif
  451. #endif
  452. bne 2f /* Bail if permission/valid mismach */
  453. /* Jump to common tlb load */
  454. b finish_tlb_load
  455. 2:
  456. /* The bailout. Restore registers to pre-exception conditions
  457. * and call the heavyweights to help us out.
  458. */
  459. mfspr r10, SPRN_SPRG_THREAD
  460. lwz r11, THREAD_NORMSAVE(3)(r10)
  461. mtcr r11
  462. lwz r13, THREAD_NORMSAVE(2)(r10)
  463. lwz r12, THREAD_NORMSAVE(1)(r10)
  464. lwz r11, THREAD_NORMSAVE(0)(r10)
  465. mfspr r10, SPRN_SPRG_RSCRATCH0
  466. b DataStorage
  467. /* Instruction TLB Error Interrupt */
  468. /*
  469. * Nearly the same as above, except we get our
  470. * information from different registers and bailout
  471. * to a different point.
  472. */
  473. START_EXCEPTION(InstructionTLBError)
  474. mtspr SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */
  475. mfspr r10, SPRN_SPRG_THREAD
  476. stw r11, THREAD_NORMSAVE(0)(r10)
  477. #ifdef CONFIG_KVM_BOOKE_HV
  478. BEGIN_FTR_SECTION
  479. mfspr r11, SPRN_SRR1
  480. END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV)
  481. #endif
  482. stw r12, THREAD_NORMSAVE(1)(r10)
  483. stw r13, THREAD_NORMSAVE(2)(r10)
  484. mfcr r13
  485. stw r13, THREAD_NORMSAVE(3)(r10)
  486. DO_KVM BOOKE_INTERRUPT_ITLB_MISS SPRN_SRR1
  487. mfspr r10, SPRN_SRR0 /* Get faulting address */
  488. /* If we are faulting a kernel address, we have to use the
  489. * kernel page tables.
  490. */
  491. lis r11, PAGE_OFFSET@h
  492. cmplw 5, r10, r11
  493. blt 5, 3f
  494. lis r11, swapper_pg_dir@h
  495. ori r11, r11, swapper_pg_dir@l
  496. mfspr r12,SPRN_MAS1 /* Set TID to 0 */
  497. rlwinm r12,r12,0,16,1
  498. mtspr SPRN_MAS1,r12
  499. /* Make up the required permissions for kernel code */
  500. #ifdef CONFIG_PTE_64BIT
  501. li r13,_PAGE_PRESENT | _PAGE_BAP_SX
  502. oris r13,r13,_PAGE_ACCESSED@h
  503. #else
  504. li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC
  505. #endif
  506. b 4f
  507. /* Get the PGD for the current thread */
  508. 3:
  509. mfspr r11,SPRN_SPRG_THREAD
  510. lwz r11,PGDIR(r11)
  511. /* Make up the required permissions for user code */
  512. #ifdef CONFIG_PTE_64BIT
  513. li r13,_PAGE_PRESENT | _PAGE_BAP_UX
  514. oris r13,r13,_PAGE_ACCESSED@h
  515. #else
  516. li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC
  517. #endif
  518. 4:
  519. FIND_PTE
  520. andc. r13,r13,r11 /* Check permission */
  521. #ifdef CONFIG_PTE_64BIT
  522. #ifdef CONFIG_SMP
  523. subf r13,r11,r12 /* create false data dep */
  524. lwzx r13,r11,r13 /* Get upper pte bits */
  525. #else
  526. lwz r13,0(r12) /* Get upper pte bits */
  527. #endif
  528. #endif
  529. bne 2f /* Bail if permission mismach */
  530. /* Jump to common TLB load point */
  531. b finish_tlb_load
  532. 2:
  533. /* The bailout. Restore registers to pre-exception conditions
  534. * and call the heavyweights to help us out.
  535. */
  536. mfspr r10, SPRN_SPRG_THREAD
  537. lwz r11, THREAD_NORMSAVE(3)(r10)
  538. mtcr r11
  539. lwz r13, THREAD_NORMSAVE(2)(r10)
  540. lwz r12, THREAD_NORMSAVE(1)(r10)
  541. lwz r11, THREAD_NORMSAVE(0)(r10)
  542. mfspr r10, SPRN_SPRG_RSCRATCH0
  543. b InstructionStorage
  544. #ifdef CONFIG_SPE
  545. /* SPE Unavailable */
  546. START_EXCEPTION(SPEUnavailable)
  547. NORMAL_EXCEPTION_PROLOG(SPE_ALTIVEC_UNAVAIL)
  548. beq 1f
  549. bl load_up_spe
  550. b fast_exception_return
  551. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  552. EXC_XFER_EE_LITE(0x2010, KernelSPE)
  553. #else
  554. EXCEPTION(0x2020, SPE_ALTIVEC_UNAVAIL, SPEUnavailable, \
  555. unknown_exception, EXC_XFER_EE)
  556. #endif /* CONFIG_SPE */
  557. /* SPE Floating Point Data */
  558. #ifdef CONFIG_SPE
  559. EXCEPTION(0x2030, SPE_FP_DATA_ALTIVEC_ASSIST, SPEFloatingPointData,
  560. SPEFloatingPointException, EXC_XFER_EE)
  561. /* SPE Floating Point Round */
  562. EXCEPTION(0x2050, SPE_FP_ROUND, SPEFloatingPointRound, \
  563. SPEFloatingPointRoundException, EXC_XFER_EE)
  564. #else
  565. EXCEPTION(0x2040, SPE_FP_DATA_ALTIVEC_ASSIST, SPEFloatingPointData,
  566. unknown_exception, EXC_XFER_EE)
  567. EXCEPTION(0x2050, SPE_FP_ROUND, SPEFloatingPointRound, \
  568. unknown_exception, EXC_XFER_EE)
  569. #endif /* CONFIG_SPE */
  570. /* Performance Monitor */
  571. EXCEPTION(0x2060, PERFORMANCE_MONITOR, PerformanceMonitor, \
  572. performance_monitor_exception, EXC_XFER_STD)
  573. EXCEPTION(0x2070, DOORBELL, Doorbell, doorbell_exception, EXC_XFER_STD)
  574. CRITICAL_EXCEPTION(0x2080, DOORBELL_CRITICAL, \
  575. CriticalDoorbell, unknown_exception)
  576. /* Debug Interrupt */
  577. DEBUG_DEBUG_EXCEPTION
  578. DEBUG_CRIT_EXCEPTION
  579. GUEST_DOORBELL_EXCEPTION
  580. CRITICAL_EXCEPTION(0, GUEST_DBELL_CRIT, CriticalGuestDoorbell, \
  581. unknown_exception)
  582. /* Hypercall */
  583. EXCEPTION(0, HV_SYSCALL, Hypercall, unknown_exception, EXC_XFER_EE)
  584. /* Embedded Hypervisor Privilege */
  585. EXCEPTION(0, HV_PRIV, Ehvpriv, unknown_exception, EXC_XFER_EE)
  586. interrupt_end:
  587. /*
  588. * Local functions
  589. */
  590. /*
  591. * Both the instruction and data TLB miss get to this
  592. * point to load the TLB.
  593. * r10 - tsize encoding (if HUGETLB_PAGE) or available to use
  594. * r11 - TLB (info from Linux PTE)
  595. * r12 - available to use
  596. * r13 - upper bits of PTE (if PTE_64BIT) or available to use
  597. * CR5 - results of addr >= PAGE_OFFSET
  598. * MAS0, MAS1 - loaded with proper value when we get here
  599. * MAS2, MAS3 - will need additional info from Linux PTE
  600. * Upon exit, we reload everything and RFI.
  601. */
  602. finish_tlb_load:
  603. #ifdef CONFIG_HUGETLB_PAGE
  604. cmpwi 6, r10, 0 /* check for huge page */
  605. beq 6, finish_tlb_load_cont /* !huge */
  606. /* Alas, we need more scratch registers for hugepages */
  607. mfspr r12, SPRN_SPRG_THREAD
  608. stw r14, THREAD_NORMSAVE(4)(r12)
  609. stw r15, THREAD_NORMSAVE(5)(r12)
  610. stw r16, THREAD_NORMSAVE(6)(r12)
  611. stw r17, THREAD_NORMSAVE(7)(r12)
  612. /* Get the next_tlbcam_idx percpu var */
  613. #ifdef CONFIG_SMP
  614. lwz r12, THREAD_INFO-THREAD(r12)
  615. lwz r15, TI_CPU(r12)
  616. lis r14, __per_cpu_offset@h
  617. ori r14, r14, __per_cpu_offset@l
  618. rlwinm r15, r15, 2, 0, 29
  619. lwzx r16, r14, r15
  620. #else
  621. li r16, 0
  622. #endif
  623. lis r17, next_tlbcam_idx@h
  624. ori r17, r17, next_tlbcam_idx@l
  625. add r17, r17, r16 /* r17 = *next_tlbcam_idx */
  626. lwz r15, 0(r17) /* r15 = next_tlbcam_idx */
  627. lis r14, MAS0_TLBSEL(1)@h /* select TLB1 (TLBCAM) */
  628. rlwimi r14, r15, 16, 4, 15 /* next_tlbcam_idx entry */
  629. mtspr SPRN_MAS0, r14
  630. /* Extract TLB1CFG(NENTRY) */
  631. mfspr r16, SPRN_TLB1CFG
  632. andi. r16, r16, 0xfff
  633. /* Update next_tlbcam_idx, wrapping when necessary */
  634. addi r15, r15, 1
  635. cmpw r15, r16
  636. blt 100f
  637. lis r14, tlbcam_index@h
  638. ori r14, r14, tlbcam_index@l
  639. lwz r15, 0(r14)
  640. 100: stw r15, 0(r17)
  641. /*
  642. * Calc MAS1_TSIZE from r10 (which has pshift encoded)
  643. * tlb_enc = (pshift - 10).
  644. */
  645. subi r15, r10, 10
  646. mfspr r16, SPRN_MAS1
  647. rlwimi r16, r15, 7, 20, 24
  648. mtspr SPRN_MAS1, r16
  649. /* copy the pshift for use later */
  650. mr r14, r10
  651. /* fall through */
  652. #endif /* CONFIG_HUGETLB_PAGE */
  653. /*
  654. * We set execute, because we don't have the granularity to
  655. * properly set this at the page level (Linux problem).
  656. * Many of these bits are software only. Bits we don't set
  657. * here we (properly should) assume have the appropriate value.
  658. */
  659. finish_tlb_load_cont:
  660. #ifdef CONFIG_PTE_64BIT
  661. rlwinm r12, r11, 32-2, 26, 31 /* Move in perm bits */
  662. andi. r10, r11, _PAGE_DIRTY
  663. bne 1f
  664. li r10, MAS3_SW | MAS3_UW
  665. andc r12, r12, r10
  666. 1: rlwimi r12, r13, 20, 0, 11 /* grab RPN[32:43] */
  667. rlwimi r12, r11, 20, 12, 19 /* grab RPN[44:51] */
  668. 2: mtspr SPRN_MAS3, r12
  669. BEGIN_MMU_FTR_SECTION
  670. srwi r10, r13, 12 /* grab RPN[12:31] */
  671. mtspr SPRN_MAS7, r10
  672. END_MMU_FTR_SECTION_IFSET(MMU_FTR_BIG_PHYS)
  673. #else
  674. li r10, (_PAGE_EXEC | _PAGE_PRESENT)
  675. mr r13, r11
  676. rlwimi r10, r11, 31, 29, 29 /* extract _PAGE_DIRTY into SW */
  677. and r12, r11, r10
  678. andi. r10, r11, _PAGE_USER /* Test for _PAGE_USER */
  679. slwi r10, r12, 1
  680. or r10, r10, r12
  681. iseleq r12, r12, r10
  682. rlwimi r13, r12, 0, 20, 31 /* Get RPN from PTE, merge w/ perms */
  683. mtspr SPRN_MAS3, r13
  684. #endif
  685. mfspr r12, SPRN_MAS2
  686. #ifdef CONFIG_PTE_64BIT
  687. rlwimi r12, r11, 32-19, 27, 31 /* extract WIMGE from pte */
  688. #else
  689. rlwimi r12, r11, 26, 27, 31 /* extract WIMGE from pte */
  690. #endif
  691. #ifdef CONFIG_HUGETLB_PAGE
  692. beq 6, 3f /* don't mask if page isn't huge */
  693. li r13, 1
  694. slw r13, r13, r14
  695. subi r13, r13, 1
  696. rlwinm r13, r13, 0, 0, 19 /* bottom bits used for WIMGE/etc */
  697. andc r12, r12, r13 /* mask off ea bits within the page */
  698. #endif
  699. 3: mtspr SPRN_MAS2, r12
  700. #ifdef CONFIG_E200
  701. /* Round robin TLB1 entries assignment */
  702. mfspr r12, SPRN_MAS0
  703. /* Extract TLB1CFG(NENTRY) */
  704. mfspr r11, SPRN_TLB1CFG
  705. andi. r11, r11, 0xfff
  706. /* Extract MAS0(NV) */
  707. andi. r13, r12, 0xfff
  708. addi r13, r13, 1
  709. cmpw 0, r13, r11
  710. addi r12, r12, 1
  711. /* check if we need to wrap */
  712. blt 7f
  713. /* wrap back to first free tlbcam entry */
  714. lis r13, tlbcam_index@ha
  715. lwz r13, tlbcam_index@l(r13)
  716. rlwimi r12, r13, 0, 20, 31
  717. 7:
  718. mtspr SPRN_MAS0,r12
  719. #endif /* CONFIG_E200 */
  720. tlb_write_entry:
  721. tlbwe
  722. /* Done...restore registers and get out of here. */
  723. mfspr r10, SPRN_SPRG_THREAD
  724. #ifdef CONFIG_HUGETLB_PAGE
  725. beq 6, 8f /* skip restore for 4k page faults */
  726. lwz r14, THREAD_NORMSAVE(4)(r10)
  727. lwz r15, THREAD_NORMSAVE(5)(r10)
  728. lwz r16, THREAD_NORMSAVE(6)(r10)
  729. lwz r17, THREAD_NORMSAVE(7)(r10)
  730. #endif
  731. 8: lwz r11, THREAD_NORMSAVE(3)(r10)
  732. mtcr r11
  733. lwz r13, THREAD_NORMSAVE(2)(r10)
  734. lwz r12, THREAD_NORMSAVE(1)(r10)
  735. lwz r11, THREAD_NORMSAVE(0)(r10)
  736. mfspr r10, SPRN_SPRG_RSCRATCH0
  737. rfi /* Force context change */
  738. #ifdef CONFIG_SPE
  739. /* Note that the SPE support is closely modeled after the AltiVec
  740. * support. Changes to one are likely to be applicable to the
  741. * other! */
  742. _GLOBAL(load_up_spe)
  743. /*
  744. * Disable SPE for the task which had SPE previously,
  745. * and save its SPE registers in its thread_struct.
  746. * Enables SPE for use in the kernel on return.
  747. * On SMP we know the SPE units are free, since we give it up every
  748. * switch. -- Kumar
  749. */
  750. mfmsr r5
  751. oris r5,r5,MSR_SPE@h
  752. mtmsr r5 /* enable use of SPE now */
  753. isync
  754. /*
  755. * For SMP, we don't do lazy SPE switching because it just gets too
  756. * horrendously complex, especially when a task switches from one CPU
  757. * to another. Instead we call giveup_spe in switch_to.
  758. */
  759. #ifndef CONFIG_SMP
  760. lis r3,last_task_used_spe@ha
  761. lwz r4,last_task_used_spe@l(r3)
  762. cmpi 0,r4,0
  763. beq 1f
  764. addi r4,r4,THREAD /* want THREAD of last_task_used_spe */
  765. SAVE_32EVRS(0,r10,r4,THREAD_EVR0)
  766. evxor evr10, evr10, evr10 /* clear out evr10 */
  767. evmwumiaa evr10, evr10, evr10 /* evr10 <- ACC = 0 * 0 + ACC */
  768. li r5,THREAD_ACC
  769. evstddx evr10, r4, r5 /* save off accumulator */
  770. lwz r5,PT_REGS(r4)
  771. lwz r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  772. lis r10,MSR_SPE@h
  773. andc r4,r4,r10 /* disable SPE for previous task */
  774. stw r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  775. 1:
  776. #endif /* !CONFIG_SMP */
  777. /* enable use of SPE after return */
  778. oris r9,r9,MSR_SPE@h
  779. mfspr r5,SPRN_SPRG_THREAD /* current task's THREAD (phys) */
  780. li r4,1
  781. li r10,THREAD_ACC
  782. stw r4,THREAD_USED_SPE(r5)
  783. evlddx evr4,r10,r5
  784. evmra evr4,evr4
  785. REST_32EVRS(0,r10,r5,THREAD_EVR0)
  786. #ifndef CONFIG_SMP
  787. subi r4,r5,THREAD
  788. stw r4,last_task_used_spe@l(r3)
  789. #endif /* !CONFIG_SMP */
  790. blr
  791. /*
  792. * SPE unavailable trap from kernel - print a message, but let
  793. * the task use SPE in the kernel until it returns to user mode.
  794. */
  795. KernelSPE:
  796. lwz r3,_MSR(r1)
  797. oris r3,r3,MSR_SPE@h
  798. stw r3,_MSR(r1) /* enable use of SPE after return */
  799. #ifdef CONFIG_PRINTK
  800. lis r3,87f@h
  801. ori r3,r3,87f@l
  802. mr r4,r2 /* current */
  803. lwz r5,_NIP(r1)
  804. bl printk
  805. #endif
  806. b ret_from_except
  807. #ifdef CONFIG_PRINTK
  808. 87: .string "SPE used in kernel (task=%p, pc=%x) \n"
  809. #endif
  810. .align 4,0
  811. #endif /* CONFIG_SPE */
  812. /*
  813. * Translate the effec addr in r3 to phys addr. The phys addr will be put
  814. * into r3(higher 32bit) and r4(lower 32bit)
  815. */
  816. get_phys_addr:
  817. mfmsr r8
  818. mfspr r9,SPRN_PID
  819. rlwinm r9,r9,16,0x3fff0000 /* turn PID into MAS6[SPID] */
  820. rlwimi r9,r8,28,0x00000001 /* turn MSR[DS] into MAS6[SAS] */
  821. mtspr SPRN_MAS6,r9
  822. tlbsx 0,r3 /* must succeed */
  823. mfspr r8,SPRN_MAS1
  824. mfspr r12,SPRN_MAS3
  825. rlwinm r9,r8,25,0x1f /* r9 = log2(page size) */
  826. li r10,1024
  827. slw r10,r10,r9 /* r10 = page size */
  828. addi r10,r10,-1
  829. and r11,r3,r10 /* r11 = page offset */
  830. andc r4,r12,r10 /* r4 = page base */
  831. or r4,r4,r11 /* r4 = devtree phys addr */
  832. #ifdef CONFIG_PHYS_64BIT
  833. mfspr r3,SPRN_MAS7
  834. #endif
  835. blr
  836. /*
  837. * Global functions
  838. */
  839. /* Adjust or setup IVORs for e200 */
  840. _GLOBAL(__setup_e200_ivors)
  841. li r3,DebugDebug@l
  842. mtspr SPRN_IVOR15,r3
  843. li r3,SPEUnavailable@l
  844. mtspr SPRN_IVOR32,r3
  845. li r3,SPEFloatingPointData@l
  846. mtspr SPRN_IVOR33,r3
  847. li r3,SPEFloatingPointRound@l
  848. mtspr SPRN_IVOR34,r3
  849. sync
  850. blr
  851. /* Adjust or setup IVORs for e500v1/v2 */
  852. _GLOBAL(__setup_e500_ivors)
  853. li r3,DebugCrit@l
  854. mtspr SPRN_IVOR15,r3
  855. li r3,SPEUnavailable@l
  856. mtspr SPRN_IVOR32,r3
  857. li r3,SPEFloatingPointData@l
  858. mtspr SPRN_IVOR33,r3
  859. li r3,SPEFloatingPointRound@l
  860. mtspr SPRN_IVOR34,r3
  861. li r3,PerformanceMonitor@l
  862. mtspr SPRN_IVOR35,r3
  863. sync
  864. blr
  865. /* Adjust or setup IVORs for e500mc */
  866. _GLOBAL(__setup_e500mc_ivors)
  867. li r3,DebugDebug@l
  868. mtspr SPRN_IVOR15,r3
  869. li r3,PerformanceMonitor@l
  870. mtspr SPRN_IVOR35,r3
  871. li r3,Doorbell@l
  872. mtspr SPRN_IVOR36,r3
  873. li r3,CriticalDoorbell@l
  874. mtspr SPRN_IVOR37,r3
  875. sync
  876. blr
  877. /* setup ehv ivors for */
  878. _GLOBAL(__setup_ehv_ivors)
  879. li r3,GuestDoorbell@l
  880. mtspr SPRN_IVOR38,r3
  881. li r3,CriticalGuestDoorbell@l
  882. mtspr SPRN_IVOR39,r3
  883. li r3,Hypercall@l
  884. mtspr SPRN_IVOR40,r3
  885. li r3,Ehvpriv@l
  886. mtspr SPRN_IVOR41,r3
  887. sync
  888. blr
  889. #ifdef CONFIG_SPE
  890. /*
  891. * extern void giveup_spe(struct task_struct *prev)
  892. *
  893. */
  894. _GLOBAL(giveup_spe)
  895. mfmsr r5
  896. oris r5,r5,MSR_SPE@h
  897. mtmsr r5 /* enable use of SPE now */
  898. isync
  899. cmpi 0,r3,0
  900. beqlr- /* if no previous owner, done */
  901. addi r3,r3,THREAD /* want THREAD of task */
  902. lwz r5,PT_REGS(r3)
  903. cmpi 0,r5,0
  904. SAVE_32EVRS(0, r4, r3, THREAD_EVR0)
  905. evxor evr6, evr6, evr6 /* clear out evr6 */
  906. evmwumiaa evr6, evr6, evr6 /* evr6 <- ACC = 0 * 0 + ACC */
  907. li r4,THREAD_ACC
  908. evstddx evr6, r4, r3 /* save off accumulator */
  909. beq 1f
  910. lwz r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  911. lis r3,MSR_SPE@h
  912. andc r4,r4,r3 /* disable SPE for previous task */
  913. stw r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  914. 1:
  915. #ifndef CONFIG_SMP
  916. li r5,0
  917. lis r4,last_task_used_spe@ha
  918. stw r5,last_task_used_spe@l(r4)
  919. #endif /* !CONFIG_SMP */
  920. blr
  921. #endif /* CONFIG_SPE */
  922. /*
  923. * extern void abort(void)
  924. *
  925. * At present, this routine just applies a system reset.
  926. */
  927. _GLOBAL(abort)
  928. li r13,0
  929. mtspr SPRN_DBCR0,r13 /* disable all debug events */
  930. isync
  931. mfmsr r13
  932. ori r13,r13,MSR_DE@l /* Enable Debug Events */
  933. mtmsr r13
  934. isync
  935. mfspr r13,SPRN_DBCR0
  936. lis r13,(DBCR0_IDM|DBCR0_RST_CHIP)@h
  937. mtspr SPRN_DBCR0,r13
  938. isync
  939. _GLOBAL(set_context)
  940. #ifdef CONFIG_BDI_SWITCH
  941. /* Context switch the PTE pointer for the Abatron BDI2000.
  942. * The PGDIR is the second parameter.
  943. */
  944. lis r5, abatron_pteptrs@h
  945. ori r5, r5, abatron_pteptrs@l
  946. stw r4, 0x4(r5)
  947. #endif
  948. mtspr SPRN_PID,r3
  949. isync /* Force context change */
  950. blr
  951. _GLOBAL(flush_dcache_L1)
  952. mfspr r3,SPRN_L1CFG0
  953. rlwinm r5,r3,9,3 /* Extract cache block size */
  954. twlgti r5,1 /* Only 32 and 64 byte cache blocks
  955. * are currently defined.
  956. */
  957. li r4,32
  958. subfic r6,r5,2 /* r6 = log2(1KiB / cache block size) -
  959. * log2(number of ways)
  960. */
  961. slw r5,r4,r5 /* r5 = cache block size */
  962. rlwinm r7,r3,0,0xff /* Extract number of KiB in the cache */
  963. mulli r7,r7,13 /* An 8-way cache will require 13
  964. * loads per set.
  965. */
  966. slw r7,r7,r6
  967. /* save off HID0 and set DCFA */
  968. mfspr r8,SPRN_HID0
  969. ori r9,r8,HID0_DCFA@l
  970. mtspr SPRN_HID0,r9
  971. isync
  972. lis r4,KERNELBASE@h
  973. mtctr r7
  974. 1: lwz r3,0(r4) /* Load... */
  975. add r4,r4,r5
  976. bdnz 1b
  977. msync
  978. lis r4,KERNELBASE@h
  979. mtctr r7
  980. 1: dcbf 0,r4 /* ...and flush. */
  981. add r4,r4,r5
  982. bdnz 1b
  983. /* restore HID0 */
  984. mtspr SPRN_HID0,r8
  985. isync
  986. blr
  987. /* Flush L1 d-cache, invalidate and disable d-cache and i-cache */
  988. _GLOBAL(__flush_disable_L1)
  989. mflr r10
  990. bl flush_dcache_L1 /* Flush L1 d-cache */
  991. mtlr r10
  992. mfspr r4, SPRN_L1CSR0 /* Invalidate and disable d-cache */
  993. li r5, 2
  994. rlwimi r4, r5, 0, 3
  995. msync
  996. isync
  997. mtspr SPRN_L1CSR0, r4
  998. isync
  999. 1: mfspr r4, SPRN_L1CSR0 /* Wait for the invalidate to finish */
  1000. andi. r4, r4, 2
  1001. bne 1b
  1002. mfspr r4, SPRN_L1CSR1 /* Invalidate and disable i-cache */
  1003. li r5, 2
  1004. rlwimi r4, r5, 0, 3
  1005. mtspr SPRN_L1CSR1, r4
  1006. isync
  1007. blr
  1008. #ifdef CONFIG_SMP
  1009. /* When we get here, r24 needs to hold the CPU # */
  1010. .globl __secondary_start
  1011. __secondary_start:
  1012. LOAD_REG_ADDR_PIC(r3, tlbcam_index)
  1013. lwz r3,0(r3)
  1014. mtctr r3
  1015. li r26,0 /* r26 safe? */
  1016. bl switch_to_as1
  1017. mr r27,r3 /* tlb entry */
  1018. /* Load each CAM entry */
  1019. 1: mr r3,r26
  1020. bl loadcam_entry
  1021. addi r26,r26,1
  1022. bdnz 1b
  1023. mr r3,r27 /* tlb entry */
  1024. LOAD_REG_ADDR_PIC(r4, memstart_addr)
  1025. lwz r4,0(r4)
  1026. mr r5,r25 /* phys kernel start */
  1027. rlwinm r5,r5,0,~0x3ffffff /* aligned 64M */
  1028. subf r4,r5,r4 /* memstart_addr - phys kernel start */
  1029. li r5,0 /* no device tree */
  1030. li r6,0 /* not boot cpu */
  1031. bl restore_to_as0
  1032. lis r3,__secondary_hold_acknowledge@h
  1033. ori r3,r3,__secondary_hold_acknowledge@l
  1034. stw r24,0(r3)
  1035. li r3,0
  1036. mr r4,r24 /* Why? */
  1037. bl call_setup_cpu
  1038. /* get current_thread_info and current */
  1039. lis r1,secondary_ti@ha
  1040. lwz r1,secondary_ti@l(r1)
  1041. lwz r2,TI_TASK(r1)
  1042. /* stack */
  1043. addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
  1044. li r0,0
  1045. stw r0,0(r1)
  1046. /* ptr to current thread */
  1047. addi r4,r2,THREAD /* address of our thread_struct */
  1048. mtspr SPRN_SPRG_THREAD,r4
  1049. /* Setup the defaults for TLB entries */
  1050. li r4,(MAS4_TSIZED(BOOK3E_PAGESZ_4K))@l
  1051. mtspr SPRN_MAS4,r4
  1052. /* Jump to start_secondary */
  1053. lis r4,MSR_KERNEL@h
  1054. ori r4,r4,MSR_KERNEL@l
  1055. lis r3,start_secondary@h
  1056. ori r3,r3,start_secondary@l
  1057. mtspr SPRN_SRR0,r3
  1058. mtspr SPRN_SRR1,r4
  1059. sync
  1060. rfi
  1061. sync
  1062. .globl __secondary_hold_acknowledge
  1063. __secondary_hold_acknowledge:
  1064. .long -1
  1065. #endif
  1066. /*
  1067. * Create a tlb entry with the same effective and physical address as
  1068. * the tlb entry used by the current running code. But set the TS to 1.
  1069. * Then switch to the address space 1. It will return with the r3 set to
  1070. * the ESEL of the new created tlb.
  1071. */
  1072. _GLOBAL(switch_to_as1)
  1073. mflr r5
  1074. /* Find a entry not used */
  1075. mfspr r3,SPRN_TLB1CFG
  1076. andi. r3,r3,0xfff
  1077. mfspr r4,SPRN_PID
  1078. rlwinm r4,r4,16,0x3fff0000 /* turn PID into MAS6[SPID] */
  1079. mtspr SPRN_MAS6,r4
  1080. 1: lis r4,0x1000 /* Set MAS0(TLBSEL) = 1 */
  1081. addi r3,r3,-1
  1082. rlwimi r4,r3,16,4,15 /* Setup MAS0 = TLBSEL | ESEL(r3) */
  1083. mtspr SPRN_MAS0,r4
  1084. tlbre
  1085. mfspr r4,SPRN_MAS1
  1086. andis. r4,r4,MAS1_VALID@h
  1087. bne 1b
  1088. /* Get the tlb entry used by the current running code */
  1089. bl 0f
  1090. 0: mflr r4
  1091. tlbsx 0,r4
  1092. mfspr r4,SPRN_MAS1
  1093. ori r4,r4,MAS1_TS /* Set the TS = 1 */
  1094. mtspr SPRN_MAS1,r4
  1095. mfspr r4,SPRN_MAS0
  1096. rlwinm r4,r4,0,~MAS0_ESEL_MASK
  1097. rlwimi r4,r3,16,4,15 /* Setup MAS0 = TLBSEL | ESEL(r3) */
  1098. mtspr SPRN_MAS0,r4
  1099. tlbwe
  1100. isync
  1101. sync
  1102. mfmsr r4
  1103. ori r4,r4,MSR_IS | MSR_DS
  1104. mtspr SPRN_SRR0,r5
  1105. mtspr SPRN_SRR1,r4
  1106. sync
  1107. rfi
  1108. /*
  1109. * Restore to the address space 0 and also invalidate the tlb entry created
  1110. * by switch_to_as1.
  1111. * r3 - the tlb entry which should be invalidated
  1112. * r4 - __pa(PAGE_OFFSET in AS1) - __pa(PAGE_OFFSET in AS0)
  1113. * r5 - device tree virtual address. If r4 is 0, r5 is ignored.
  1114. * r6 - boot cpu
  1115. */
  1116. _GLOBAL(restore_to_as0)
  1117. mflr r0
  1118. bl 0f
  1119. 0: mflr r9
  1120. addi r9,r9,1f - 0b
  1121. /*
  1122. * We may map the PAGE_OFFSET in AS0 to a different physical address,
  1123. * so we need calculate the right jump and device tree address based
  1124. * on the offset passed by r4.
  1125. */
  1126. add r9,r9,r4
  1127. add r5,r5,r4
  1128. add r0,r0,r4
  1129. 2: mfmsr r7
  1130. li r8,(MSR_IS | MSR_DS)
  1131. andc r7,r7,r8
  1132. mtspr SPRN_SRR0,r9
  1133. mtspr SPRN_SRR1,r7
  1134. sync
  1135. rfi
  1136. /* Invalidate the temporary tlb entry for AS1 */
  1137. 1: lis r9,0x1000 /* Set MAS0(TLBSEL) = 1 */
  1138. rlwimi r9,r3,16,4,15 /* Setup MAS0 = TLBSEL | ESEL(r3) */
  1139. mtspr SPRN_MAS0,r9
  1140. tlbre
  1141. mfspr r9,SPRN_MAS1
  1142. rlwinm r9,r9,0,2,31 /* Clear MAS1 Valid and IPPROT */
  1143. mtspr SPRN_MAS1,r9
  1144. tlbwe
  1145. isync
  1146. cmpwi r4,0
  1147. cmpwi cr1,r6,0
  1148. cror eq,4*cr1+eq,eq
  1149. bne 3f /* offset != 0 && is_boot_cpu */
  1150. mtlr r0
  1151. blr
  1152. /*
  1153. * The PAGE_OFFSET will map to a different physical address,
  1154. * jump to _start to do another relocation again.
  1155. */
  1156. 3: mr r3,r5
  1157. bl _start
  1158. /*
  1159. * We put a few things here that have to be page-aligned. This stuff
  1160. * goes at the beginning of the data segment, which is page-aligned.
  1161. */
  1162. .data
  1163. .align 12
  1164. .globl sdata
  1165. sdata:
  1166. .globl empty_zero_page
  1167. empty_zero_page:
  1168. .space 4096
  1169. .globl swapper_pg_dir
  1170. swapper_pg_dir:
  1171. .space PGD_TABLE_SIZE
  1172. /*
  1173. * Room for two PTE pointers, usually the kernel and current user pointers
  1174. * to their respective root page table.
  1175. */
  1176. abatron_pteptrs:
  1177. .space 8