smp.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /*++
  2. Copyright (c) 2015 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. smp.c
  5. Abstract:
  6. This module implements support routines for the second core on RK3288 SoCs.
  7. Author:
  8. Evan Green 10-Jul-2015
  9. Environment:
  10. Firmware
  11. --*/
  12. //
  13. // ------------------------------------------------------------------- Includes
  14. //
  15. #include <uefifw.h>
  16. #include "veyronfw.h"
  17. //
  18. // ---------------------------------------------------------------- Definitions
  19. //
  20. //
  21. // Define the parking page locations. This is completely arbitrary, but has to
  22. // match the values in the MADT.
  23. //
  24. #define RK32_CPU_PARKING_BASE 0x00080000
  25. #define RK32_CPU_COUNT 4
  26. #define RK32_CPU_PARKED_ADDRESS_SIZE 0x1000
  27. #define RK32_CPU_TOTAL_PARKED_ADDRESS_SIZE \
  28. (RK32_CPU_COUNT * RK32_CPU_PARKED_ADDRESS_SIZE)
  29. #define ARM_PARKING_PROTOCOL_FIRMWARE_OFFSET 0x0800
  30. //
  31. // Define the physical processor ID base. This comes from core 0's MPIDR and
  32. // must match the values in the MADT.
  33. //
  34. #define RK32_PROCESSOR_ID_BASE 0x500
  35. //
  36. // ------------------------------------------------------ Data Type Definitions
  37. //
  38. //
  39. // ----------------------------------------------- Internal Function Prototypes
  40. //
  41. //
  42. // Internal assembly routines.
  43. //
  44. VOID
  45. EfipRk32SendEvent (
  46. VOID
  47. );
  48. VOID
  49. EfipRk32ProcessorStartup (
  50. VOID
  51. );
  52. //
  53. // -------------------------------------------------------------------- Globals
  54. //
  55. //
  56. // Define the variables other cores read to boot.
  57. //
  58. volatile UINT32 EfiRk32ProcessorId;
  59. VOID volatile *EfiRk32ProcessorJumpAddress;
  60. extern UINT8 EfipRk32ParkingLoop;
  61. extern UINT8 EfipRk32ParkingLoopEnd;
  62. //
  63. // ------------------------------------------------------------------ Functions
  64. //
  65. EFI_STATUS
  66. EfipSmpInitialize (
  67. VOID
  68. )
  69. /*++
  70. Routine Description:
  71. This routine initializes and parks the second core on the RK32xx.
  72. Arguments:
  73. None.
  74. Return Value:
  75. EFI status code.
  76. --*/
  77. {
  78. UINT32 Bit;
  79. UINT32 CoreMask;
  80. VOID *Cpu;
  81. UINTN CpuIndex;
  82. VOID *Cru;
  83. EFI_PHYSICAL_ADDRESS ParkedAddress;
  84. VOID *Pmu;
  85. UINT32 *Sram;
  86. EFI_STATUS Status;
  87. UINT32 Value;
  88. //
  89. // Allocate the pages for the firmware parked spaces.
  90. //
  91. Cru = (VOID *)RK32_CRU_BASE;
  92. Pmu = (VOID *)RK32_PMU_BASE;
  93. ParkedAddress = RK32_CPU_PARKING_BASE;
  94. Status = EfiAllocatePages(
  95. AllocateAddress,
  96. EfiACPIMemoryNVS,
  97. EFI_SIZE_TO_PAGES(RK32_CPU_TOTAL_PARKED_ADDRESS_SIZE),
  98. &ParkedAddress);
  99. if (EFI_ERROR(Status)) {
  100. return Status;
  101. }
  102. EfiSetMem((VOID *)(UINTN)ParkedAddress,
  103. RK32_CPU_TOTAL_PARKED_ADDRESS_SIZE,
  104. 0);
  105. Cpu = (VOID *)(UINTN)ParkedAddress;
  106. for (CpuIndex = 0; CpuIndex < RK32_CPU_COUNT; CpuIndex += 1) {
  107. //
  108. // Write -1 to the processor number location.
  109. //
  110. Cpu = (VOID *)((UINTN)ParkedAddress +
  111. (CpuIndex * RK32_CPU_PARKED_ADDRESS_SIZE));
  112. EfiWriteRegister32(Cpu, -1);
  113. //
  114. // Copy the parking protocol loops into the right places.
  115. //
  116. EfiCopyMem(
  117. Cpu + ARM_PARKING_PROTOCOL_FIRMWARE_OFFSET,
  118. &EfipRk32ParkingLoop,
  119. (UINTN)&EfipRk32ParkingLoopEnd - (UINTN)&EfipRk32ParkingLoop);
  120. }
  121. EfiCoreInvalidateInstructionCacheRange((VOID *)(UINTN)ParkedAddress,
  122. RK32_CPU_TOTAL_PARKED_ADDRESS_SIZE);
  123. //
  124. // Assert reset on cores 1 through 3 before powering them down.
  125. //
  126. CoreMask = RK32_CRU_SOFT_RESET0_CORE1 |
  127. RK32_CRU_SOFT_RESET0_CORE2 |
  128. RK32_CRU_SOFT_RESET0_CORE3;
  129. Value = (CoreMask << RK32_CRU_SOFT_RESET0_PROTECT_SHIFT) | CoreMask;
  130. EfiWriteRegister32(Cru + Rk32CruSoftReset0, Value);
  131. //
  132. // Power down the cores.
  133. //
  134. CoreMask = RK32_PMU_POWER_DOWN_CONTROL_A17_1 |
  135. RK32_PMU_POWER_DOWN_CONTROL_A17_2 |
  136. RK32_PMU_POWER_DOWN_CONTROL_A17_3;
  137. Value = EfiReadRegister32(Pmu + Rk32PmuPowerDownControl);
  138. Value |= CoreMask;
  139. EfiWriteRegister32(Pmu + Rk32PmuPowerDownControl, Value);
  140. CoreMask = RK32_PMU_POWER_DOWN_STATUS_A17_1 |
  141. RK32_PMU_POWER_DOWN_STATUS_A17_2 |
  142. RK32_PMU_POWER_DOWN_STATUS_A17_3;
  143. while (TRUE) {
  144. Value = EfiReadRegister32(Pmu + Rk32PmuPowerDownStatus);
  145. if ((Value & CoreMask) == CoreMask) {
  146. break;
  147. }
  148. }
  149. //
  150. // Start up other cores and send them to their parking places.
  151. //
  152. for (CpuIndex = 1; CpuIndex < RK32_CPU_COUNT; CpuIndex += 1) {
  153. Cpu = (VOID *)((UINTN)ParkedAddress +
  154. (CpuIndex * RK32_CPU_PARKED_ADDRESS_SIZE));
  155. EfiRk32ProcessorJumpAddress = Cpu +
  156. ARM_PARKING_PROTOCOL_FIRMWARE_OFFSET;
  157. EfiRk32ProcessorId = RK32_PROCESSOR_ID_BASE + CpuIndex;
  158. //
  159. // Power up the core by clearing the power down control for the core.
  160. //
  161. Value = EfiReadRegister32(Pmu + Rk32PmuPowerDownControl);
  162. Value &= ~(RK32_PMU_POWER_DOWN_CONTROL_A17_0 << CpuIndex);
  163. EfiWriteRegister32(Pmu + Rk32PmuPowerDownControl, Value);
  164. //
  165. // Take the core out of reset. Deasserting reset means writing a 0,
  166. // and the reset protect tells the register which bits to listen to.
  167. //
  168. Bit = RK32_CRU_SOFT_RESET0_CORE0 << CpuIndex;
  169. Value = Bit << RK32_CRU_SOFT_RESET0_PROTECT_SHIFT;
  170. EfiWriteRegister32(Cru + Rk32CruSoftReset0, Value);
  171. //
  172. // Wait for the status bit to clear.
  173. //
  174. do {
  175. Value = EfiReadRegister32(Pmu + Rk32PmuPowerDownStatus);
  176. } while ((Value & (RK32_PMU_POWER_DOWN_STATUS_A17_0 << CpuIndex)) != 0);
  177. //
  178. // The other cores are sitting in their own parking loop off in SRAM.
  179. // bring them out of that and into this parking loop.
  180. //
  181. Sram = (UINT32 *)RK32_SRAM_BASE;
  182. Sram[2] = (UINT32)EfipRk32ProcessorStartup;
  183. Sram[1] = 0xDEADBEAF;
  184. //
  185. // Send an event to wake the core up.
  186. //
  187. EfipRk32SendEvent();
  188. //
  189. // Wait for the CPU to come to life. For some reason marking the
  190. // variable as volatile doesn't seem to prevent optimization.
  191. //
  192. while (EfiReadRegister32(&EfiRk32ProcessorJumpAddress) != (UINTN)NULL) {
  193. NOTHING;
  194. }
  195. }
  196. return EFI_SUCCESS;
  197. }
  198. //
  199. // --------------------------------------------------------- Internal Functions
  200. //