lowlevel_init.S 3.6 KB

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