lowlevel_init.S 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Copyright (C) 2012-2015 Panasonic Corporation
  3. * Copyright (C) 2015-2016 Socionext Inc.
  4. * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <config.h>
  9. #include <linux/linkage.h>
  10. #include <linux/sizes.h>
  11. #include <asm/system.h>
  12. #include "ssc-regs.h"
  13. ENTRY(lowlevel_init)
  14. mov r8, lr @ persevere link reg across call
  15. /*
  16. * The UniPhier Boot ROM loads SPL code to the L2 cache.
  17. * But CPUs can only do instruction fetch now because start.S has
  18. * cleared C and M bits.
  19. * First we need to turn on MMU and Dcache again to get back
  20. * data access to L2.
  21. */
  22. mrc p15, 0, r0, c1, c0, 0 @ SCTLR (System Control Register)
  23. orr r0, r0, #(CR_C | CR_M) @ enable MMU and Dcache
  24. mcr p15, 0, r0, c1, c0, 0
  25. #ifdef CONFIG_DEBUG_LL
  26. bl debug_ll_init
  27. #endif
  28. bl setup_init_ram @ RAM area for stack and page table
  29. /*
  30. * Now we are using the page table embedded in the Boot ROM.
  31. * It is not handy since it is not a straight mapped table for sLD3.
  32. * Also, the access to the external bus is prohibited. What we need
  33. * to do next is to create a page table and switch over to it.
  34. */
  35. bl create_page_table
  36. bl __v7_flush_dcache_all
  37. /* Disable MMU and Dcache before switching Page Table */
  38. mrc p15, 0, r0, c1, c0, 0 @ SCTLR (System Control Register)
  39. bic r0, r0, #(CR_C | CR_M) @ disable MMU and Dcache
  40. mcr p15, 0, r0, c1, c0, 0
  41. bl enable_mmu
  42. mov lr, r8 @ restore link
  43. mov pc, lr @ back to my caller
  44. ENDPROC(lowlevel_init)
  45. ENTRY(enable_mmu)
  46. mrc p15, 0, r0, c2, c0, 2 @ TTBCR (Translation Table Base Control Register)
  47. bic r0, r0, #0x37
  48. orr r0, r0, #0x20 @ disable TTBR1
  49. mcr p15, 0, r0, c2, c0, 2
  50. orr r0, r12, #0x8 @ Outer Cacheability for table walks: WBWA
  51. mcr p15, 0, r0, c2, c0, 0 @ TTBR0
  52. mov r0, #0
  53. mcr p15, 0, r0, c8, c7, 0 @ invalidate TLBs
  54. mov r0, #-1 @ manager for all domains (No permission check)
  55. mcr p15, 0, r0, c3, c0, 0 @ DACR (Domain Access Control Register)
  56. dsb
  57. isb
  58. /*
  59. * MMU on:
  60. * TLBs was already invalidated in "../start.S"
  61. * So, we don't need to invalidate it here.
  62. */
  63. mrc p15, 0, r0, c1, c0, 0 @ SCTLR (System Control Register)
  64. orr r0, r0, #(CR_C | CR_M) @ MMU and Dcache enable
  65. mcr p15, 0, r0, c1, c0, 0
  66. mov pc, lr
  67. ENDPROC(enable_mmu)
  68. /*
  69. * For PH1-Pro4 or older SoCs, the size of WAY is 32KB.
  70. * It is large enough for tmp RAM.
  71. */
  72. #define BOOT_RAM_SIZE (SZ_32K)
  73. #define BOOT_RAM_BASE ((CONFIG_SPL_STACK) - (BOOT_RAM_SIZE))
  74. #define BOOT_WAY_BITS (0x00000100) /* way 8 */
  75. ENTRY(setup_init_ram)
  76. /*
  77. * Touch to zero for the boot way
  78. */
  79. 0:
  80. /*
  81. * set UNIPHIER_SSCOQM, UNIPHIER_SSCOQAD, UNIPHIER_SSCOQSZ, UNIPHIER_SSCOQWN in this order
  82. */
  83. ldr r0, = 0x00408006 @ touch to zero with address range
  84. ldr r1, = UNIPHIER_SSCOQM
  85. str r0, [r1]
  86. ldr r0, = BOOT_RAM_BASE
  87. ldr r1, = UNIPHIER_SSCOQAD
  88. str r0, [r1]
  89. ldr r0, = BOOT_RAM_SIZE
  90. ldr r1, = UNIPHIER_SSCOQSZ
  91. str r0, [r1]
  92. ldr r0, = BOOT_WAY_BITS
  93. ldr r1, = UNIPHIER_SSCOQWN
  94. str r0, [r1]
  95. ldr r1, = UNIPHIER_SSCOPPQSEF
  96. ldr r0, [r1]
  97. cmp r0, #0 @ check if the command is successfully set
  98. bne 0b @ try again if an error occurs
  99. ldr r1, = UNIPHIER_SSCOLPQS
  100. 1:
  101. ldr r0, [r1]
  102. cmp r0, #0x4
  103. bne 1b @ wait until the operation is completed
  104. str r0, [r1] @ clear the complete notification flag
  105. mov pc, lr
  106. ENDPROC(setup_init_ram)
  107. #define DEVICE 0x00002002 /* Non-shareable Device */
  108. #define NORMAL 0x0000000e /* Normal Memory Write-Back, No Write-Allocate */
  109. ENTRY(create_page_table)
  110. ldr r0, = DEVICE
  111. ldr r1, = BOOT_RAM_BASE
  112. mov r12, r1 @ r12 is preserved during D-cache flush
  113. 0: str r0, [r1], #4 @ specify all the sections as Device
  114. adds r0, r0, #0x00100000
  115. bcc 0b
  116. ldr r0, = NORMAL
  117. str r0, [r12] @ mark the first section as Normal
  118. add r0, r0, #0x00100000
  119. str r0, [r12, #4] @ mark the second section as Normal
  120. mov pc, lr
  121. ENDPROC(create_page_table)