runtime.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. /*++
  2. Copyright (c) 2014 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. runtime.c
  5. Abstract:
  6. This module implements platform-specific runtime code for the Raspberry Pi
  7. system.
  8. Author:
  9. Chris Stevens 5-Jan-2015
  10. Environment:
  11. Firmware
  12. --*/
  13. //
  14. // ------------------------------------------------------------------- Includes
  15. //
  16. #include <uefifw.h>
  17. #include "../rpifw.h"
  18. //
  19. // ---------------------------------------------------------------- Definitions
  20. //
  21. //
  22. // Define the Raspberry Pi specific reset status value to indicate that the
  23. // firmware should not proceed with the next boot. The reset status register
  24. // stores the partition to boot in every other of the first 12 bits. The value
  25. // 0x3F (spaced out to 0x555) indicates that the firmware should halt.
  26. //
  27. #define RPI_BCM2709_PRM_RESET_STATUS_HALT 0x00000555
  28. //
  29. // ------------------------------------------------------ Data Type Definitions
  30. //
  31. //
  32. // ----------------------------------------------- Internal Function Prototypes
  33. //
  34. EFIAPI
  35. VOID
  36. EfipBcm2835ResetSystem (
  37. EFI_RESET_TYPE ResetType,
  38. EFI_STATUS ResetStatus,
  39. UINTN DataSize,
  40. VOID *ResetData
  41. );
  42. EFIAPI
  43. EFI_STATUS
  44. EfipBcm2835GetTime (
  45. EFI_TIME *Time,
  46. EFI_TIME_CAPABILITIES *Capabilities
  47. );
  48. EFIAPI
  49. EFI_STATUS
  50. EfipBcm2835SetTime (
  51. EFI_TIME *Time
  52. );
  53. EFIAPI
  54. EFI_STATUS
  55. EfipBcm2835GetWakeupTime (
  56. BOOLEAN *Enabled,
  57. BOOLEAN *Pending,
  58. EFI_TIME *Time
  59. );
  60. EFIAPI
  61. EFI_STATUS
  62. EfipBcm2835SetWakeupTime (
  63. BOOLEAN Enable,
  64. EFI_TIME *Time
  65. );
  66. //
  67. // -------------------------------------------------------------------- Globals
  68. //
  69. VOID *EfiBcm2835PrmBase = (VOID *)BCM2835_BASE + BCM2709_PRM_OFFSET;
  70. //
  71. // ------------------------------------------------------------------ Functions
  72. //
  73. EFI_STATUS
  74. EfiPlatformRuntimeInitialize (
  75. VOID
  76. )
  77. /*++
  78. Routine Description:
  79. This routine performs platform-specific firmware initialization in the
  80. runtime core driver. The runtime routines are in a separate binary from the
  81. firmware core routines as they need to be relocated for runtime. This
  82. routine should perform platform-specific initialization needed to provide
  83. the core runtime services.
  84. Arguments:
  85. None.
  86. Return Value:
  87. EFI status code.
  88. --*/
  89. {
  90. //
  91. // Take over the runtime services. The runtime library recomputes the
  92. // CRC so there's no need to do it here.
  93. //
  94. EfiRuntimeServices->GetTime = EfipBcm2835GetTime;
  95. EfiRuntimeServices->SetTime = EfipBcm2835SetTime;
  96. EfiRuntimeServices->GetWakeupTime = EfipBcm2835GetWakeupTime;
  97. EfiRuntimeServices->SetWakeupTime = EfipBcm2835SetWakeupTime;
  98. EfiRuntimeServices->ResetSystem = EfipBcm2835ResetSystem;
  99. return EFI_SUCCESS;
  100. }
  101. EFI_STATUS
  102. EfiPlatformReadNonVolatileData (
  103. VOID *Data,
  104. UINTN DataSize
  105. )
  106. /*++
  107. Routine Description:
  108. This routine reads the EFI variable data from non-volatile storage.
  109. Arguments:
  110. Data - Supplies a pointer where the platform returns the non-volatile
  111. data.
  112. DataSize - Supplies the size of the data to return.
  113. Return Value:
  114. EFI_SUCCESS if some data was successfully loaded.
  115. EFI_UNSUPPORTED if the platform does not have non-volatile storage. In this
  116. case the firmware core saves the non-volatile variables to a file on the
  117. EFI system partition, and the variable library hopes to catch the same
  118. variable buffer on reboots to see variable writes that happened at
  119. runtime.
  120. EFI_DEVICE_IO_ERROR if a device error occurred during the operation.
  121. Other error codes on other failures.
  122. --*/
  123. {
  124. return EFI_UNSUPPORTED;
  125. }
  126. EFI_STATUS
  127. EfiPlatformWriteNonVolatileData (
  128. VOID *Data,
  129. UINTN DataSize
  130. )
  131. /*++
  132. Routine Description:
  133. This routine writes the EFI variable data to non-volatile storage.
  134. Arguments:
  135. Data - Supplies a pointer to the data to write.
  136. DataSize - Supplies the size of the data to write, in bytes.
  137. Return Value:
  138. EFI_SUCCESS if some data was successfully loaded.
  139. EFI_UNSUPPORTED if the platform does not have non-volatile storage. In this
  140. case the firmware core saves the non-volatile variables to a file on the
  141. EFI system partition, and the variable library hopes to catch the same
  142. variable buffer on reboots to see variable writes that happened at
  143. runtime.
  144. EFI_DEVICE_IO_ERROR if a device error occurred during the operation.
  145. Other error codes on other failures.
  146. --*/
  147. {
  148. return EFI_UNSUPPORTED;
  149. }
  150. VOID
  151. EfiPlatformRuntimeExitBootServices (
  152. VOID
  153. )
  154. /*++
  155. Routine Description:
  156. This routine is called in the runtime core driver when the firmware is in
  157. the process of terminating boot services. The platform can do any work it
  158. needs to prepare for the imminent termination of boot services.
  159. Arguments:
  160. None.
  161. Return Value:
  162. None.
  163. --*/
  164. {
  165. return;
  166. }
  167. VOID
  168. EfiPlatformRuntimeVirtualAddressChange (
  169. VOID
  170. )
  171. /*++
  172. Routine Description:
  173. This routine is called in the runtime core driver when the firmware is
  174. converting to virtual address mode. It should convert any pointers it's
  175. got. This routine is called after ExitBootServices, so no EFI boot services
  176. are available.
  177. Arguments:
  178. None.
  179. Return Value:
  180. None.
  181. --*/
  182. {
  183. //
  184. // Convert the PRM base for ResetSystem.
  185. //
  186. EfiConvertPointer(0, &EfiBcm2835PrmBase);
  187. return;
  188. }
  189. //
  190. // --------------------------------------------------------- Internal Functions
  191. //
  192. EFIAPI
  193. VOID
  194. EfipBcm2835ResetSystem (
  195. EFI_RESET_TYPE ResetType,
  196. EFI_STATUS ResetStatus,
  197. UINTN DataSize,
  198. VOID *ResetData
  199. )
  200. /*++
  201. Routine Description:
  202. This routine resets the entire platform.
  203. Arguments:
  204. ResetType - Supplies the type of reset to perform.
  205. ResetStatus - Supplies the status code for this reset.
  206. DataSize - Supplies the size of the reset data.
  207. ResetData - Supplies an optional pointer for reset types of cold, warm, or
  208. shutdown to a null-terminated string, optionally followed by additional
  209. binary data.
  210. Return Value:
  211. None. This routine does not return.
  212. --*/
  213. {
  214. volatile UINT32 *PrmResetStatus;
  215. volatile UINT32 *ResetControl;
  216. UINT32 Value;
  217. volatile UINT32 *Watchdog;
  218. //
  219. // Attempt to flush non-volatile variable data out to storage.
  220. //
  221. EfiCoreFlushVariableData();
  222. //
  223. // There is no official way to shutdown the BCM2835. The Raspberry Pi
  224. // firmware, however, stores the boot partition information in the PRM
  225. // reset status register. A special partition value is reserved to indicate
  226. // that the firmware should not proceed with the boot process.
  227. //
  228. if (ResetType == EfiResetShutdown) {
  229. PrmResetStatus = EfiBcm2835PrmBase + Bcm2709PrmResetStatus;
  230. *PrmResetStatus |= BCM2709_PRM_PASSWORD |
  231. RPI_BCM2709_PRM_RESET_STATUS_HALT;
  232. }
  233. Watchdog = EfiBcm2835PrmBase + Bcm2709PrmWatchdog;
  234. *Watchdog = BCM2709_PRM_WATCHDOG_RESET_TICKS | BCM2709_PRM_PASSWORD;
  235. ResetControl = EfiBcm2835PrmBase + Bcm2709PrmResetControl;
  236. Value = *ResetControl;
  237. Value &= ~BCM2709_PRM_RESET_CONTROL_TYPE_MASK;
  238. Value |= BCM2709_PRM_PASSWORD |
  239. BCM2709_PRM_RESET_CONTROL_TYPE_FULL;
  240. *ResetControl = Value;
  241. return;
  242. }
  243. EFIAPI
  244. EFI_STATUS
  245. EfipBcm2835GetTime (
  246. EFI_TIME *Time,
  247. EFI_TIME_CAPABILITIES *Capabilities
  248. )
  249. /*++
  250. Routine Description:
  251. This routine returns the current time and dat information, and
  252. timekeeping capabilities of the hardware platform.
  253. Arguments:
  254. Time - Supplies a pointer where the current time will be returned.
  255. Capabilities - Supplies an optional pointer where the capabilities will be
  256. returned on success.
  257. Return Value:
  258. EFI_SUCCESS on success.
  259. EFI_INVALID_PARAMETER if the time parameter was NULL.
  260. EFI_DEVICE_ERROR if there was a hardware error accessing the device.
  261. --*/
  262. {
  263. return EFI_SUCCESS;
  264. }
  265. EFIAPI
  266. EFI_STATUS
  267. EfipBcm2835SetTime (
  268. EFI_TIME *Time
  269. )
  270. /*++
  271. Routine Description:
  272. This routine sets the current local time and date information.
  273. Arguments:
  274. Time - Supplies a pointer to the time to set.
  275. Return Value:
  276. EFI_SUCCESS on success.
  277. EFI_INVALID_PARAMETER if a time field is out of range.
  278. EFI_DEVICE_ERROR if there was a hardware error accessing the device.
  279. --*/
  280. {
  281. return EFI_SUCCESS;
  282. }
  283. EFIAPI
  284. EFI_STATUS
  285. EfipBcm2835GetWakeupTime (
  286. BOOLEAN *Enabled,
  287. BOOLEAN *Pending,
  288. EFI_TIME *Time
  289. )
  290. /*++
  291. Routine Description:
  292. This routine gets the current wake alarm setting.
  293. Arguments:
  294. Enabled - Supplies a pointer that receives a boolean indicating if the
  295. alarm is currently enabled or disabled.
  296. Pending - Supplies a pointer that receives a boolean indicating if the
  297. alarm signal is pending and requires acknowledgement.
  298. Time - Supplies a pointer that receives the current wake time.
  299. Return Value:
  300. EFI_SUCCESS on success.
  301. EFI_INVALID_PARAMETER if any parameter is NULL.
  302. EFI_DEVICE_ERROR if there was a hardware error accessing the device.
  303. EFI_UNSUPPORTED if the wakeup timer is not supported on this platform.
  304. --*/
  305. {
  306. return EFI_SUCCESS;
  307. }
  308. EFIAPI
  309. EFI_STATUS
  310. EfipBcm2835SetWakeupTime (
  311. BOOLEAN Enable,
  312. EFI_TIME *Time
  313. )
  314. /*++
  315. Routine Description:
  316. This routine sets the current wake alarm setting.
  317. Arguments:
  318. Enable - Supplies a boolean enabling or disabling the wakeup timer.
  319. Time - Supplies an optional pointer to the time to set. This parameter is
  320. only optional if the enable parameter is FALSE.
  321. Return Value:
  322. EFI_SUCCESS on success.
  323. EFI_INVALID_PARAMETER if a time field is out of range.
  324. EFI_DEVICE_ERROR if there was a hardware error accessing the device.
  325. EFI_UNSUPPORTED if the wakeup timer is not supported on this platform.
  326. --*/
  327. {
  328. return EFI_SUCCESS;
  329. }