head_32.S 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * Copyright 2010 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. *
  14. * TILE startup code.
  15. */
  16. #include <linux/linkage.h>
  17. #include <linux/init.h>
  18. #include <asm/page.h>
  19. #include <asm/pgtable.h>
  20. #include <asm/thread_info.h>
  21. #include <asm/processor.h>
  22. #include <asm/asm-offsets.h>
  23. #include <hv/hypervisor.h>
  24. #include <arch/chip.h>
  25. /*
  26. * This module contains the entry code for kernel images. It performs the
  27. * minimal setup needed to call the generic C routines.
  28. */
  29. __HEAD
  30. ENTRY(_start)
  31. /* Notify the hypervisor of what version of the API we want */
  32. {
  33. movei r1, TILE_CHIP
  34. movei r2, TILE_CHIP_REV
  35. }
  36. {
  37. moveli r0, _HV_VERSION
  38. jal hv_init
  39. }
  40. /* Get a reasonable default ASID in r0 */
  41. {
  42. move r0, zero
  43. jal hv_inquire_asid
  44. }
  45. /* Install the default page table */
  46. {
  47. moveli r6, lo16(swapper_pgprot - PAGE_OFFSET)
  48. move r4, r0 /* use starting ASID of range for this page table */
  49. }
  50. {
  51. moveli r0, lo16(swapper_pg_dir - PAGE_OFFSET)
  52. auli r6, r6, ha16(swapper_pgprot - PAGE_OFFSET)
  53. }
  54. {
  55. lw r2, r6
  56. addi r6, r6, 4
  57. }
  58. {
  59. lw r3, r6
  60. auli r0, r0, ha16(swapper_pg_dir - PAGE_OFFSET)
  61. }
  62. {
  63. inv r6
  64. move r1, zero /* high 32 bits of CPA is zero */
  65. }
  66. {
  67. moveli lr, lo16(1f)
  68. move r5, zero
  69. }
  70. {
  71. auli lr, lr, ha16(1f)
  72. j hv_install_context
  73. }
  74. 1:
  75. /* Get our processor number and save it away in SAVE_1_0. */
  76. jal hv_inquire_topology
  77. mulll_uu r4, r1, r2 /* r1 == y, r2 == width */
  78. add r4, r4, r0 /* r0 == x, so r4 == cpu == y*width + x */
  79. #ifdef CONFIG_SMP
  80. /*
  81. * Load up our per-cpu offset. When the first (master) tile
  82. * boots, this value is still zero, so we will load boot_pc
  83. * with start_kernel, and boot_sp with init_stack + THREAD_SIZE.
  84. * The master tile initializes the per-cpu offset array, so that
  85. * when subsequent (secondary) tiles boot, they will instead load
  86. * from their per-cpu versions of boot_sp and boot_pc.
  87. */
  88. moveli r5, lo16(__per_cpu_offset)
  89. auli r5, r5, ha16(__per_cpu_offset)
  90. s2a r5, r4, r5
  91. lw r5, r5
  92. bnz r5, 1f
  93. /*
  94. * Save the width and height to the smp_topology variable
  95. * for later use.
  96. */
  97. moveli r0, lo16(smp_topology + HV_TOPOLOGY_WIDTH_OFFSET)
  98. auli r0, r0, ha16(smp_topology + HV_TOPOLOGY_WIDTH_OFFSET)
  99. {
  100. sw r0, r2
  101. addi r0, r0, (HV_TOPOLOGY_HEIGHT_OFFSET - HV_TOPOLOGY_WIDTH_OFFSET)
  102. }
  103. sw r0, r3
  104. 1:
  105. #else
  106. move r5, zero
  107. #endif
  108. /* Load and go with the correct pc and sp. */
  109. {
  110. addli r1, r5, lo16(boot_sp)
  111. addli r0, r5, lo16(boot_pc)
  112. }
  113. {
  114. auli r1, r1, ha16(boot_sp)
  115. auli r0, r0, ha16(boot_pc)
  116. }
  117. lw r0, r0
  118. lw sp, r1
  119. or r4, sp, r4
  120. mtspr SYSTEM_SAVE_1_0, r4 /* save ksp0 + cpu */
  121. addi sp, sp, -STACK_TOP_DELTA
  122. {
  123. move lr, zero /* stop backtraces in the called function */
  124. jr r0
  125. }
  126. ENDPROC(_start)
  127. .section ".bss.page_aligned","w"
  128. .align PAGE_SIZE
  129. ENTRY(empty_zero_page)
  130. .fill PAGE_SIZE,1,0
  131. END(empty_zero_page)
  132. .macro PTE va, cpa, bits1, no_org=0
  133. .ifeq \no_org
  134. .org swapper_pg_dir + HV_L1_INDEX(\va) * HV_PTE_SIZE
  135. .endif
  136. .word HV_PTE_PAGE | HV_PTE_DIRTY | HV_PTE_PRESENT | HV_PTE_ACCESSED | \
  137. (HV_PTE_MODE_CACHE_NO_L3 << HV_PTE_INDEX_MODE)
  138. .word (\bits1) | (HV_CPA_TO_PFN(\cpa) << HV_PTE_INDEX_PFN)
  139. .endm
  140. .section ".data.page_aligned","wa"
  141. .align PAGE_SIZE
  142. ENTRY(swapper_pg_dir)
  143. /*
  144. * All data pages from PAGE_OFFSET to MEM_USER_INTRPT are mapped as
  145. * VA = PA + PAGE_OFFSET. We remap things with more precise access
  146. * permissions and more respect for size of RAM later.
  147. */
  148. .set addr, 0
  149. .rept (MEM_USER_INTRPT - PAGE_OFFSET) >> PGDIR_SHIFT
  150. PTE addr + PAGE_OFFSET, addr, HV_PTE_READABLE | HV_PTE_WRITABLE
  151. .set addr, addr + PGDIR_SIZE
  152. .endr
  153. /* The true text VAs are mapped as VA = PA + MEM_SV_INTRPT */
  154. PTE MEM_SV_INTRPT, 0, HV_PTE_READABLE | HV_PTE_EXECUTABLE
  155. .org swapper_pg_dir + HV_L1_SIZE
  156. END(swapper_pg_dir)
  157. /*
  158. * Isolate swapper_pgprot to its own cache line, since each cpu
  159. * starting up will read it using VA-is-PA and local homing.
  160. * This would otherwise likely conflict with other data on the cache
  161. * line, once we have set its permanent home in the page tables.
  162. */
  163. __INITDATA
  164. .align CHIP_L2_LINE_SIZE()
  165. ENTRY(swapper_pgprot)
  166. PTE 0, 0, HV_PTE_READABLE | HV_PTE_WRITABLE, 1
  167. .align CHIP_L2_LINE_SIZE()
  168. END(swapper_pgprot)