head_fsl_booke.S 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347
  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. /* Define SPE handlers for e200 and e500v2 */
  545. #ifdef CONFIG_SPE
  546. /* SPE Unavailable */
  547. START_EXCEPTION(SPEUnavailable)
  548. NORMAL_EXCEPTION_PROLOG(SPE_UNAVAIL)
  549. beq 1f
  550. bl load_up_spe
  551. b fast_exception_return
  552. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  553. EXC_XFER_EE_LITE(0x2010, KernelSPE)
  554. #elif defined(CONFIG_SPE_POSSIBLE)
  555. EXCEPTION(0x2020, SPE_UNAVAIL, SPEUnavailable, \
  556. unknown_exception, EXC_XFER_EE)
  557. #endif /* CONFIG_SPE_POSSIBLE */
  558. /* SPE Floating Point Data */
  559. #ifdef CONFIG_SPE
  560. EXCEPTION(0x2030, SPE_FP_DATA, SPEFloatingPointData,
  561. SPEFloatingPointException, EXC_XFER_EE)
  562. /* SPE Floating Point Round */
  563. EXCEPTION(0x2050, SPE_FP_ROUND, SPEFloatingPointRound, \
  564. SPEFloatingPointRoundException, EXC_XFER_EE)
  565. #elif defined(CONFIG_SPE_POSSIBLE)
  566. EXCEPTION(0x2040, SPE_FP_DATA, SPEFloatingPointData,
  567. unknown_exception, EXC_XFER_EE)
  568. EXCEPTION(0x2050, SPE_FP_ROUND, SPEFloatingPointRound, \
  569. unknown_exception, EXC_XFER_EE)
  570. #endif /* CONFIG_SPE_POSSIBLE */
  571. /* Performance Monitor */
  572. EXCEPTION(0x2060, PERFORMANCE_MONITOR, PerformanceMonitor, \
  573. performance_monitor_exception, EXC_XFER_STD)
  574. EXCEPTION(0x2070, DOORBELL, Doorbell, doorbell_exception, EXC_XFER_STD)
  575. CRITICAL_EXCEPTION(0x2080, DOORBELL_CRITICAL, \
  576. CriticalDoorbell, unknown_exception)
  577. /* Debug Interrupt */
  578. DEBUG_DEBUG_EXCEPTION
  579. DEBUG_CRIT_EXCEPTION
  580. GUEST_DOORBELL_EXCEPTION
  581. CRITICAL_EXCEPTION(0, GUEST_DBELL_CRIT, CriticalGuestDoorbell, \
  582. unknown_exception)
  583. /* Hypercall */
  584. EXCEPTION(0, HV_SYSCALL, Hypercall, unknown_exception, EXC_XFER_EE)
  585. /* Embedded Hypervisor Privilege */
  586. EXCEPTION(0, HV_PRIV, Ehvpriv, unknown_exception, EXC_XFER_EE)
  587. interrupt_end:
  588. /*
  589. * Local functions
  590. */
  591. /*
  592. * Both the instruction and data TLB miss get to this
  593. * point to load the TLB.
  594. * r10 - tsize encoding (if HUGETLB_PAGE) or available to use
  595. * r11 - TLB (info from Linux PTE)
  596. * r12 - available to use
  597. * r13 - upper bits of PTE (if PTE_64BIT) or available to use
  598. * CR5 - results of addr >= PAGE_OFFSET
  599. * MAS0, MAS1 - loaded with proper value when we get here
  600. * MAS2, MAS3 - will need additional info from Linux PTE
  601. * Upon exit, we reload everything and RFI.
  602. */
  603. finish_tlb_load:
  604. #ifdef CONFIG_HUGETLB_PAGE
  605. cmpwi 6, r10, 0 /* check for huge page */
  606. beq 6, finish_tlb_load_cont /* !huge */
  607. /* Alas, we need more scratch registers for hugepages */
  608. mfspr r12, SPRN_SPRG_THREAD
  609. stw r14, THREAD_NORMSAVE(4)(r12)
  610. stw r15, THREAD_NORMSAVE(5)(r12)
  611. stw r16, THREAD_NORMSAVE(6)(r12)
  612. stw r17, THREAD_NORMSAVE(7)(r12)
  613. /* Get the next_tlbcam_idx percpu var */
  614. #ifdef CONFIG_SMP
  615. lwz r12, THREAD_INFO-THREAD(r12)
  616. lwz r15, TI_CPU(r12)
  617. lis r14, __per_cpu_offset@h
  618. ori r14, r14, __per_cpu_offset@l
  619. rlwinm r15, r15, 2, 0, 29
  620. lwzx r16, r14, r15
  621. #else
  622. li r16, 0
  623. #endif
  624. lis r17, next_tlbcam_idx@h
  625. ori r17, r17, next_tlbcam_idx@l
  626. add r17, r17, r16 /* r17 = *next_tlbcam_idx */
  627. lwz r15, 0(r17) /* r15 = next_tlbcam_idx */
  628. lis r14, MAS0_TLBSEL(1)@h /* select TLB1 (TLBCAM) */
  629. rlwimi r14, r15, 16, 4, 15 /* next_tlbcam_idx entry */
  630. mtspr SPRN_MAS0, r14
  631. /* Extract TLB1CFG(NENTRY) */
  632. mfspr r16, SPRN_TLB1CFG
  633. andi. r16, r16, 0xfff
  634. /* Update next_tlbcam_idx, wrapping when necessary */
  635. addi r15, r15, 1
  636. cmpw r15, r16
  637. blt 100f
  638. lis r14, tlbcam_index@h
  639. ori r14, r14, tlbcam_index@l
  640. lwz r15, 0(r14)
  641. 100: stw r15, 0(r17)
  642. /*
  643. * Calc MAS1_TSIZE from r10 (which has pshift encoded)
  644. * tlb_enc = (pshift - 10).
  645. */
  646. subi r15, r10, 10
  647. mfspr r16, SPRN_MAS1
  648. rlwimi r16, r15, 7, 20, 24
  649. mtspr SPRN_MAS1, r16
  650. /* copy the pshift for use later */
  651. mr r14, r10
  652. /* fall through */
  653. #endif /* CONFIG_HUGETLB_PAGE */
  654. /*
  655. * We set execute, because we don't have the granularity to
  656. * properly set this at the page level (Linux problem).
  657. * Many of these bits are software only. Bits we don't set
  658. * here we (properly should) assume have the appropriate value.
  659. */
  660. finish_tlb_load_cont:
  661. #ifdef CONFIG_PTE_64BIT
  662. rlwinm r12, r11, 32-2, 26, 31 /* Move in perm bits */
  663. andi. r10, r11, _PAGE_DIRTY
  664. bne 1f
  665. li r10, MAS3_SW | MAS3_UW
  666. andc r12, r12, r10
  667. 1: rlwimi r12, r13, 20, 0, 11 /* grab RPN[32:43] */
  668. rlwimi r12, r11, 20, 12, 19 /* grab RPN[44:51] */
  669. 2: mtspr SPRN_MAS3, r12
  670. BEGIN_MMU_FTR_SECTION
  671. srwi r10, r13, 12 /* grab RPN[12:31] */
  672. mtspr SPRN_MAS7, r10
  673. END_MMU_FTR_SECTION_IFSET(MMU_FTR_BIG_PHYS)
  674. #else
  675. li r10, (_PAGE_EXEC | _PAGE_PRESENT)
  676. mr r13, r11
  677. rlwimi r10, r11, 31, 29, 29 /* extract _PAGE_DIRTY into SW */
  678. and r12, r11, r10
  679. andi. r10, r11, _PAGE_USER /* Test for _PAGE_USER */
  680. slwi r10, r12, 1
  681. or r10, r10, r12
  682. iseleq r12, r12, r10
  683. rlwimi r13, r12, 0, 20, 31 /* Get RPN from PTE, merge w/ perms */
  684. mtspr SPRN_MAS3, r13
  685. #endif
  686. mfspr r12, SPRN_MAS2
  687. #ifdef CONFIG_PTE_64BIT
  688. rlwimi r12, r11, 32-19, 27, 31 /* extract WIMGE from pte */
  689. #else
  690. rlwimi r12, r11, 26, 27, 31 /* extract WIMGE from pte */
  691. #endif
  692. #ifdef CONFIG_HUGETLB_PAGE
  693. beq 6, 3f /* don't mask if page isn't huge */
  694. li r13, 1
  695. slw r13, r13, r14
  696. subi r13, r13, 1
  697. rlwinm r13, r13, 0, 0, 19 /* bottom bits used for WIMGE/etc */
  698. andc r12, r12, r13 /* mask off ea bits within the page */
  699. #endif
  700. 3: mtspr SPRN_MAS2, r12
  701. #ifdef CONFIG_E200
  702. /* Round robin TLB1 entries assignment */
  703. mfspr r12, SPRN_MAS0
  704. /* Extract TLB1CFG(NENTRY) */
  705. mfspr r11, SPRN_TLB1CFG
  706. andi. r11, r11, 0xfff
  707. /* Extract MAS0(NV) */
  708. andi. r13, r12, 0xfff
  709. addi r13, r13, 1
  710. cmpw 0, r13, r11
  711. addi r12, r12, 1
  712. /* check if we need to wrap */
  713. blt 7f
  714. /* wrap back to first free tlbcam entry */
  715. lis r13, tlbcam_index@ha
  716. lwz r13, tlbcam_index@l(r13)
  717. rlwimi r12, r13, 0, 20, 31
  718. 7:
  719. mtspr SPRN_MAS0,r12
  720. #endif /* CONFIG_E200 */
  721. tlb_write_entry:
  722. tlbwe
  723. /* Done...restore registers and get out of here. */
  724. mfspr r10, SPRN_SPRG_THREAD
  725. #ifdef CONFIG_HUGETLB_PAGE
  726. beq 6, 8f /* skip restore for 4k page faults */
  727. lwz r14, THREAD_NORMSAVE(4)(r10)
  728. lwz r15, THREAD_NORMSAVE(5)(r10)
  729. lwz r16, THREAD_NORMSAVE(6)(r10)
  730. lwz r17, THREAD_NORMSAVE(7)(r10)
  731. #endif
  732. 8: lwz r11, THREAD_NORMSAVE(3)(r10)
  733. mtcr r11
  734. lwz r13, THREAD_NORMSAVE(2)(r10)
  735. lwz r12, THREAD_NORMSAVE(1)(r10)
  736. lwz r11, THREAD_NORMSAVE(0)(r10)
  737. mfspr r10, SPRN_SPRG_RSCRATCH0
  738. rfi /* Force context change */
  739. #ifdef CONFIG_SPE
  740. /* Note that the SPE support is closely modeled after the AltiVec
  741. * support. Changes to one are likely to be applicable to the
  742. * other! */
  743. _GLOBAL(load_up_spe)
  744. /*
  745. * Disable SPE for the task which had SPE previously,
  746. * and save its SPE registers in its thread_struct.
  747. * Enables SPE for use in the kernel on return.
  748. * On SMP we know the SPE units are free, since we give it up every
  749. * switch. -- Kumar
  750. */
  751. mfmsr r5
  752. oris r5,r5,MSR_SPE@h
  753. mtmsr r5 /* enable use of SPE now */
  754. isync
  755. /*
  756. * For SMP, we don't do lazy SPE switching because it just gets too
  757. * horrendously complex, especially when a task switches from one CPU
  758. * to another. Instead we call giveup_spe in switch_to.
  759. */
  760. #ifndef CONFIG_SMP
  761. lis r3,last_task_used_spe@ha
  762. lwz r4,last_task_used_spe@l(r3)
  763. cmpi 0,r4,0
  764. beq 1f
  765. addi r4,r4,THREAD /* want THREAD of last_task_used_spe */
  766. SAVE_32EVRS(0,r10,r4,THREAD_EVR0)
  767. evxor evr10, evr10, evr10 /* clear out evr10 */
  768. evmwumiaa evr10, evr10, evr10 /* evr10 <- ACC = 0 * 0 + ACC */
  769. li r5,THREAD_ACC
  770. evstddx evr10, r4, r5 /* save off accumulator */
  771. lwz r5,PT_REGS(r4)
  772. lwz r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  773. lis r10,MSR_SPE@h
  774. andc r4,r4,r10 /* disable SPE for previous task */
  775. stw r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  776. 1:
  777. #endif /* !CONFIG_SMP */
  778. /* enable use of SPE after return */
  779. oris r9,r9,MSR_SPE@h
  780. mfspr r5,SPRN_SPRG_THREAD /* current task's THREAD (phys) */
  781. li r4,1
  782. li r10,THREAD_ACC
  783. stw r4,THREAD_USED_SPE(r5)
  784. evlddx evr4,r10,r5
  785. evmra evr4,evr4
  786. REST_32EVRS(0,r10,r5,THREAD_EVR0)
  787. #ifndef CONFIG_SMP
  788. subi r4,r5,THREAD
  789. stw r4,last_task_used_spe@l(r3)
  790. #endif /* !CONFIG_SMP */
  791. blr
  792. /*
  793. * SPE unavailable trap from kernel - print a message, but let
  794. * the task use SPE in the kernel until it returns to user mode.
  795. */
  796. KernelSPE:
  797. lwz r3,_MSR(r1)
  798. oris r3,r3,MSR_SPE@h
  799. stw r3,_MSR(r1) /* enable use of SPE after return */
  800. #ifdef CONFIG_PRINTK
  801. lis r3,87f@h
  802. ori r3,r3,87f@l
  803. mr r4,r2 /* current */
  804. lwz r5,_NIP(r1)
  805. bl printk
  806. #endif
  807. b ret_from_except
  808. #ifdef CONFIG_PRINTK
  809. 87: .string "SPE used in kernel (task=%p, pc=%x) \n"
  810. #endif
  811. .align 4,0
  812. #endif /* CONFIG_SPE */
  813. /*
  814. * Translate the effec addr in r3 to phys addr. The phys addr will be put
  815. * into r3(higher 32bit) and r4(lower 32bit)
  816. */
  817. get_phys_addr:
  818. mfmsr r8
  819. mfspr r9,SPRN_PID
  820. rlwinm r9,r9,16,0x3fff0000 /* turn PID into MAS6[SPID] */
  821. rlwimi r9,r8,28,0x00000001 /* turn MSR[DS] into MAS6[SAS] */
  822. mtspr SPRN_MAS6,r9
  823. tlbsx 0,r3 /* must succeed */
  824. mfspr r8,SPRN_MAS1
  825. mfspr r12,SPRN_MAS3
  826. rlwinm r9,r8,25,0x1f /* r9 = log2(page size) */
  827. li r10,1024
  828. slw r10,r10,r9 /* r10 = page size */
  829. addi r10,r10,-1
  830. and r11,r3,r10 /* r11 = page offset */
  831. andc r4,r12,r10 /* r4 = page base */
  832. or r4,r4,r11 /* r4 = devtree phys addr */
  833. #ifdef CONFIG_PHYS_64BIT
  834. mfspr r3,SPRN_MAS7
  835. #endif
  836. blr
  837. /*
  838. * Global functions
  839. */
  840. #ifdef CONFIG_E200
  841. /* Adjust or setup IVORs for e200 */
  842. _GLOBAL(__setup_e200_ivors)
  843. li r3,DebugDebug@l
  844. mtspr SPRN_IVOR15,r3
  845. li r3,SPEUnavailable@l
  846. mtspr SPRN_IVOR32,r3
  847. li r3,SPEFloatingPointData@l
  848. mtspr SPRN_IVOR33,r3
  849. li r3,SPEFloatingPointRound@l
  850. mtspr SPRN_IVOR34,r3
  851. sync
  852. blr
  853. #endif
  854. #ifdef CONFIG_E500
  855. #ifndef CONFIG_PPC_E500MC
  856. /* Adjust or setup IVORs for e500v1/v2 */
  857. _GLOBAL(__setup_e500_ivors)
  858. li r3,DebugCrit@l
  859. mtspr SPRN_IVOR15,r3
  860. li r3,SPEUnavailable@l
  861. mtspr SPRN_IVOR32,r3
  862. li r3,SPEFloatingPointData@l
  863. mtspr SPRN_IVOR33,r3
  864. li r3,SPEFloatingPointRound@l
  865. mtspr SPRN_IVOR34,r3
  866. li r3,PerformanceMonitor@l
  867. mtspr SPRN_IVOR35,r3
  868. sync
  869. blr
  870. #else
  871. /* Adjust or setup IVORs for e500mc */
  872. _GLOBAL(__setup_e500mc_ivors)
  873. li r3,DebugDebug@l
  874. mtspr SPRN_IVOR15,r3
  875. li r3,PerformanceMonitor@l
  876. mtspr SPRN_IVOR35,r3
  877. li r3,Doorbell@l
  878. mtspr SPRN_IVOR36,r3
  879. li r3,CriticalDoorbell@l
  880. mtspr SPRN_IVOR37,r3
  881. sync
  882. blr
  883. /* setup ehv ivors for */
  884. _GLOBAL(__setup_ehv_ivors)
  885. li r3,GuestDoorbell@l
  886. mtspr SPRN_IVOR38,r3
  887. li r3,CriticalGuestDoorbell@l
  888. mtspr SPRN_IVOR39,r3
  889. li r3,Hypercall@l
  890. mtspr SPRN_IVOR40,r3
  891. li r3,Ehvpriv@l
  892. mtspr SPRN_IVOR41,r3
  893. sync
  894. blr
  895. #endif /* CONFIG_PPC_E500MC */
  896. #endif /* CONFIG_E500 */
  897. #ifdef CONFIG_SPE
  898. /*
  899. * extern void giveup_spe(struct task_struct *prev)
  900. *
  901. */
  902. _GLOBAL(giveup_spe)
  903. mfmsr r5
  904. oris r5,r5,MSR_SPE@h
  905. mtmsr r5 /* enable use of SPE now */
  906. isync
  907. cmpi 0,r3,0
  908. beqlr- /* if no previous owner, done */
  909. addi r3,r3,THREAD /* want THREAD of task */
  910. lwz r5,PT_REGS(r3)
  911. cmpi 0,r5,0
  912. SAVE_32EVRS(0, r4, r3, THREAD_EVR0)
  913. evxor evr6, evr6, evr6 /* clear out evr6 */
  914. evmwumiaa evr6, evr6, evr6 /* evr6 <- ACC = 0 * 0 + ACC */
  915. li r4,THREAD_ACC
  916. evstddx evr6, r4, r3 /* save off accumulator */
  917. beq 1f
  918. lwz r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  919. lis r3,MSR_SPE@h
  920. andc r4,r4,r3 /* disable SPE for previous task */
  921. stw r4,_MSR-STACK_FRAME_OVERHEAD(r5)
  922. 1:
  923. #ifndef CONFIG_SMP
  924. li r5,0
  925. lis r4,last_task_used_spe@ha
  926. stw r5,last_task_used_spe@l(r4)
  927. #endif /* !CONFIG_SMP */
  928. blr
  929. #endif /* CONFIG_SPE */
  930. /*
  931. * extern void abort(void)
  932. *
  933. * At present, this routine just applies a system reset.
  934. */
  935. _GLOBAL(abort)
  936. li r13,0
  937. mtspr SPRN_DBCR0,r13 /* disable all debug events */
  938. isync
  939. mfmsr r13
  940. ori r13,r13,MSR_DE@l /* Enable Debug Events */
  941. mtmsr r13
  942. isync
  943. mfspr r13,SPRN_DBCR0
  944. lis r13,(DBCR0_IDM|DBCR0_RST_CHIP)@h
  945. mtspr SPRN_DBCR0,r13
  946. isync
  947. _GLOBAL(set_context)
  948. #ifdef CONFIG_BDI_SWITCH
  949. /* Context switch the PTE pointer for the Abatron BDI2000.
  950. * The PGDIR is the second parameter.
  951. */
  952. lis r5, abatron_pteptrs@h
  953. ori r5, r5, abatron_pteptrs@l
  954. stw r4, 0x4(r5)
  955. #endif
  956. mtspr SPRN_PID,r3
  957. isync /* Force context change */
  958. blr
  959. _GLOBAL(flush_dcache_L1)
  960. mfspr r3,SPRN_L1CFG0
  961. rlwinm r5,r3,9,3 /* Extract cache block size */
  962. twlgti r5,1 /* Only 32 and 64 byte cache blocks
  963. * are currently defined.
  964. */
  965. li r4,32
  966. subfic r6,r5,2 /* r6 = log2(1KiB / cache block size) -
  967. * log2(number of ways)
  968. */
  969. slw r5,r4,r5 /* r5 = cache block size */
  970. rlwinm r7,r3,0,0xff /* Extract number of KiB in the cache */
  971. mulli r7,r7,13 /* An 8-way cache will require 13
  972. * loads per set.
  973. */
  974. slw r7,r7,r6
  975. /* save off HID0 and set DCFA */
  976. mfspr r8,SPRN_HID0
  977. ori r9,r8,HID0_DCFA@l
  978. mtspr SPRN_HID0,r9
  979. isync
  980. lis r4,KERNELBASE@h
  981. mtctr r7
  982. 1: lwz r3,0(r4) /* Load... */
  983. add r4,r4,r5
  984. bdnz 1b
  985. msync
  986. lis r4,KERNELBASE@h
  987. mtctr r7
  988. 1: dcbf 0,r4 /* ...and flush. */
  989. add r4,r4,r5
  990. bdnz 1b
  991. /* restore HID0 */
  992. mtspr SPRN_HID0,r8
  993. isync
  994. blr
  995. /* Flush L1 d-cache, invalidate and disable d-cache and i-cache */
  996. _GLOBAL(__flush_disable_L1)
  997. mflr r10
  998. bl flush_dcache_L1 /* Flush L1 d-cache */
  999. mtlr r10
  1000. mfspr r4, SPRN_L1CSR0 /* Invalidate and disable d-cache */
  1001. li r5, 2
  1002. rlwimi r4, r5, 0, 3
  1003. msync
  1004. isync
  1005. mtspr SPRN_L1CSR0, r4
  1006. isync
  1007. 1: mfspr r4, SPRN_L1CSR0 /* Wait for the invalidate to finish */
  1008. andi. r4, r4, 2
  1009. bne 1b
  1010. mfspr r4, SPRN_L1CSR1 /* Invalidate and disable i-cache */
  1011. li r5, 2
  1012. rlwimi r4, r5, 0, 3
  1013. mtspr SPRN_L1CSR1, r4
  1014. isync
  1015. blr
  1016. #ifdef CONFIG_SMP
  1017. /* When we get here, r24 needs to hold the CPU # */
  1018. .globl __secondary_start
  1019. __secondary_start:
  1020. LOAD_REG_ADDR_PIC(r3, tlbcam_index)
  1021. lwz r3,0(r3)
  1022. mtctr r3
  1023. li r26,0 /* r26 safe? */
  1024. bl switch_to_as1
  1025. mr r27,r3 /* tlb entry */
  1026. /* Load each CAM entry */
  1027. 1: mr r3,r26
  1028. bl loadcam_entry
  1029. addi r26,r26,1
  1030. bdnz 1b
  1031. mr r3,r27 /* tlb entry */
  1032. LOAD_REG_ADDR_PIC(r4, memstart_addr)
  1033. lwz r4,0(r4)
  1034. mr r5,r25 /* phys kernel start */
  1035. rlwinm r5,r5,0,~0x3ffffff /* aligned 64M */
  1036. subf r4,r5,r4 /* memstart_addr - phys kernel start */
  1037. li r5,0 /* no device tree */
  1038. li r6,0 /* not boot cpu */
  1039. bl restore_to_as0
  1040. lis r3,__secondary_hold_acknowledge@h
  1041. ori r3,r3,__secondary_hold_acknowledge@l
  1042. stw r24,0(r3)
  1043. li r3,0
  1044. mr r4,r24 /* Why? */
  1045. bl call_setup_cpu
  1046. /* get current_thread_info and current */
  1047. lis r1,secondary_ti@ha
  1048. lwz r1,secondary_ti@l(r1)
  1049. lwz r2,TI_TASK(r1)
  1050. /* stack */
  1051. addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
  1052. li r0,0
  1053. stw r0,0(r1)
  1054. /* ptr to current thread */
  1055. addi r4,r2,THREAD /* address of our thread_struct */
  1056. mtspr SPRN_SPRG_THREAD,r4
  1057. /* Setup the defaults for TLB entries */
  1058. li r4,(MAS4_TSIZED(BOOK3E_PAGESZ_4K))@l
  1059. mtspr SPRN_MAS4,r4
  1060. /* Jump to start_secondary */
  1061. lis r4,MSR_KERNEL@h
  1062. ori r4,r4,MSR_KERNEL@l
  1063. lis r3,start_secondary@h
  1064. ori r3,r3,start_secondary@l
  1065. mtspr SPRN_SRR0,r3
  1066. mtspr SPRN_SRR1,r4
  1067. sync
  1068. rfi
  1069. sync
  1070. .globl __secondary_hold_acknowledge
  1071. __secondary_hold_acknowledge:
  1072. .long -1
  1073. #endif
  1074. /*
  1075. * Create a tlb entry with the same effective and physical address as
  1076. * the tlb entry used by the current running code. But set the TS to 1.
  1077. * Then switch to the address space 1. It will return with the r3 set to
  1078. * the ESEL of the new created tlb.
  1079. */
  1080. _GLOBAL(switch_to_as1)
  1081. mflr r5
  1082. /* Find a entry not used */
  1083. mfspr r3,SPRN_TLB1CFG
  1084. andi. r3,r3,0xfff
  1085. mfspr r4,SPRN_PID
  1086. rlwinm r4,r4,16,0x3fff0000 /* turn PID into MAS6[SPID] */
  1087. mtspr SPRN_MAS6,r4
  1088. 1: lis r4,0x1000 /* Set MAS0(TLBSEL) = 1 */
  1089. addi r3,r3,-1
  1090. rlwimi r4,r3,16,4,15 /* Setup MAS0 = TLBSEL | ESEL(r3) */
  1091. mtspr SPRN_MAS0,r4
  1092. tlbre
  1093. mfspr r4,SPRN_MAS1
  1094. andis. r4,r4,MAS1_VALID@h
  1095. bne 1b
  1096. /* Get the tlb entry used by the current running code */
  1097. bl 0f
  1098. 0: mflr r4
  1099. tlbsx 0,r4
  1100. mfspr r4,SPRN_MAS1
  1101. ori r4,r4,MAS1_TS /* Set the TS = 1 */
  1102. mtspr SPRN_MAS1,r4
  1103. mfspr r4,SPRN_MAS0
  1104. rlwinm r4,r4,0,~MAS0_ESEL_MASK
  1105. rlwimi r4,r3,16,4,15 /* Setup MAS0 = TLBSEL | ESEL(r3) */
  1106. mtspr SPRN_MAS0,r4
  1107. tlbwe
  1108. isync
  1109. sync
  1110. mfmsr r4
  1111. ori r4,r4,MSR_IS | MSR_DS
  1112. mtspr SPRN_SRR0,r5
  1113. mtspr SPRN_SRR1,r4
  1114. sync
  1115. rfi
  1116. /*
  1117. * Restore to the address space 0 and also invalidate the tlb entry created
  1118. * by switch_to_as1.
  1119. * r3 - the tlb entry which should be invalidated
  1120. * r4 - __pa(PAGE_OFFSET in AS1) - __pa(PAGE_OFFSET in AS0)
  1121. * r5 - device tree virtual address. If r4 is 0, r5 is ignored.
  1122. * r6 - boot cpu
  1123. */
  1124. _GLOBAL(restore_to_as0)
  1125. mflr r0
  1126. bl 0f
  1127. 0: mflr r9
  1128. addi r9,r9,1f - 0b
  1129. /*
  1130. * We may map the PAGE_OFFSET in AS0 to a different physical address,
  1131. * so we need calculate the right jump and device tree address based
  1132. * on the offset passed by r4.
  1133. */
  1134. add r9,r9,r4
  1135. add r5,r5,r4
  1136. add r0,r0,r4
  1137. 2: mfmsr r7
  1138. li r8,(MSR_IS | MSR_DS)
  1139. andc r7,r7,r8
  1140. mtspr SPRN_SRR0,r9
  1141. mtspr SPRN_SRR1,r7
  1142. sync
  1143. rfi
  1144. /* Invalidate the temporary tlb entry for AS1 */
  1145. 1: lis r9,0x1000 /* Set MAS0(TLBSEL) = 1 */
  1146. rlwimi r9,r3,16,4,15 /* Setup MAS0 = TLBSEL | ESEL(r3) */
  1147. mtspr SPRN_MAS0,r9
  1148. tlbre
  1149. mfspr r9,SPRN_MAS1
  1150. rlwinm r9,r9,0,2,31 /* Clear MAS1 Valid and IPPROT */
  1151. mtspr SPRN_MAS1,r9
  1152. tlbwe
  1153. isync
  1154. cmpwi r4,0
  1155. cmpwi cr1,r6,0
  1156. cror eq,4*cr1+eq,eq
  1157. bne 3f /* offset != 0 && is_boot_cpu */
  1158. mtlr r0
  1159. blr
  1160. /*
  1161. * The PAGE_OFFSET will map to a different physical address,
  1162. * jump to _start to do another relocation again.
  1163. */
  1164. 3: mr r3,r5
  1165. bl _start
  1166. /*
  1167. * We put a few things here that have to be page-aligned. This stuff
  1168. * goes at the beginning of the data segment, which is page-aligned.
  1169. */
  1170. .data
  1171. .align 12
  1172. .globl sdata
  1173. sdata:
  1174. .globl empty_zero_page
  1175. empty_zero_page:
  1176. .space 4096
  1177. .globl swapper_pg_dir
  1178. swapper_pg_dir:
  1179. .space PGD_TABLE_SIZE
  1180. /*
  1181. * Room for two PTE pointers, usually the kernel and current user pointers
  1182. * to their respective root page table.
  1183. */
  1184. abatron_pteptrs:
  1185. .space 8