123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499 |
- /*++
- Copyright (c) 2014 Minoca Corp. All Rights Reserved
- Module Name:
- runtime.c
- Abstract:
- This module implements platform-specific runtime code for the Raspberry Pi
- system.
- Author:
- Chris Stevens 5-Jan-2015
- Environment:
- Firmware
- --*/
- //
- // ------------------------------------------------------------------- Includes
- //
- #include <uefifw.h>
- #include "../rpifw.h"
- //
- // ---------------------------------------------------------------- Definitions
- //
- //
- // Define the Raspberry Pi specific reset status value to indicate that the
- // firmware should not proceed with the next boot. The reset status register
- // stores the partition to boot in every other of the first 12 bits. The value
- // 0x3F (spaced out to 0x555) indicates that the firmware should halt.
- //
- #define RPI_BCM2709_PRM_RESET_STATUS_HALT 0x00000555
- //
- // ------------------------------------------------------ Data Type Definitions
- //
- //
- // ----------------------------------------------- Internal Function Prototypes
- //
- EFIAPI
- VOID
- EfipBcm2835ResetSystem (
- EFI_RESET_TYPE ResetType,
- EFI_STATUS ResetStatus,
- UINTN DataSize,
- VOID *ResetData
- );
- EFIAPI
- EFI_STATUS
- EfipBcm2835GetTime (
- EFI_TIME *Time,
- EFI_TIME_CAPABILITIES *Capabilities
- );
- EFIAPI
- EFI_STATUS
- EfipBcm2835SetTime (
- EFI_TIME *Time
- );
- EFIAPI
- EFI_STATUS
- EfipBcm2835GetWakeupTime (
- BOOLEAN *Enabled,
- BOOLEAN *Pending,
- EFI_TIME *Time
- );
- EFIAPI
- EFI_STATUS
- EfipBcm2835SetWakeupTime (
- BOOLEAN Enable,
- EFI_TIME *Time
- );
- //
- // -------------------------------------------------------------------- Globals
- //
- VOID *EfiBcm2835PrmBase = (VOID *)BCM2835_BASE + BCM2709_PRM_OFFSET;
- //
- // ------------------------------------------------------------------ Functions
- //
- EFI_STATUS
- EfiPlatformRuntimeInitialize (
- VOID
- )
- /*++
- Routine Description:
- This routine performs platform-specific firmware initialization in the
- runtime core driver. The runtime routines are in a separate binary from the
- firmware core routines as they need to be relocated for runtime. This
- routine should perform platform-specific initialization needed to provide
- the core runtime services.
- Arguments:
- None.
- Return Value:
- EFI status code.
- --*/
- {
- //
- // Take over the runtime services. The runtime library recomputes the
- // CRC so there's no need to do it here.
- //
- EfiRuntimeServices->GetTime = EfipBcm2835GetTime;
- EfiRuntimeServices->SetTime = EfipBcm2835SetTime;
- EfiRuntimeServices->GetWakeupTime = EfipBcm2835GetWakeupTime;
- EfiRuntimeServices->SetWakeupTime = EfipBcm2835SetWakeupTime;
- EfiRuntimeServices->ResetSystem = EfipBcm2835ResetSystem;
- return EFI_SUCCESS;
- }
- EFI_STATUS
- EfiPlatformReadNonVolatileData (
- VOID *Data,
- UINTN DataSize
- )
- /*++
- Routine Description:
- This routine reads the EFI variable data from non-volatile storage.
- Arguments:
- Data - Supplies a pointer where the platform returns the non-volatile
- data.
- DataSize - Supplies the size of the data to return.
- Return Value:
- EFI_SUCCESS if some data was successfully loaded.
- EFI_UNSUPPORTED if the platform does not have non-volatile storage. In this
- case the firmware core saves the non-volatile variables to a file on the
- EFI system partition, and the variable library hopes to catch the same
- variable buffer on reboots to see variable writes that happened at
- runtime.
- EFI_DEVICE_IO_ERROR if a device error occurred during the operation.
- Other error codes on other failures.
- --*/
- {
- return EFI_UNSUPPORTED;
- }
- EFI_STATUS
- EfiPlatformWriteNonVolatileData (
- VOID *Data,
- UINTN DataSize
- )
- /*++
- Routine Description:
- This routine writes the EFI variable data to non-volatile storage.
- Arguments:
- Data - Supplies a pointer to the data to write.
- DataSize - Supplies the size of the data to write, in bytes.
- Return Value:
- EFI_SUCCESS if some data was successfully loaded.
- EFI_UNSUPPORTED if the platform does not have non-volatile storage. In this
- case the firmware core saves the non-volatile variables to a file on the
- EFI system partition, and the variable library hopes to catch the same
- variable buffer on reboots to see variable writes that happened at
- runtime.
- EFI_DEVICE_IO_ERROR if a device error occurred during the operation.
- Other error codes on other failures.
- --*/
- {
- return EFI_UNSUPPORTED;
- }
- VOID
- EfiPlatformRuntimeExitBootServices (
- VOID
- )
- /*++
- Routine Description:
- This routine is called in the runtime core driver when the firmware is in
- the process of terminating boot services. The platform can do any work it
- needs to prepare for the imminent termination of boot services.
- Arguments:
- None.
- Return Value:
- None.
- --*/
- {
- return;
- }
- VOID
- EfiPlatformRuntimeVirtualAddressChange (
- VOID
- )
- /*++
- Routine Description:
- This routine is called in the runtime core driver when the firmware is
- converting to virtual address mode. It should convert any pointers it's
- got. This routine is called after ExitBootServices, so no EFI boot services
- are available.
- Arguments:
- None.
- Return Value:
- None.
- --*/
- {
- //
- // Convert the PRM base for ResetSystem.
- //
- EfiConvertPointer(0, &EfiBcm2835PrmBase);
- return;
- }
- //
- // --------------------------------------------------------- Internal Functions
- //
- EFIAPI
- VOID
- EfipBcm2835ResetSystem (
- EFI_RESET_TYPE ResetType,
- EFI_STATUS ResetStatus,
- UINTN DataSize,
- VOID *ResetData
- )
- /*++
- Routine Description:
- This routine resets the entire platform.
- Arguments:
- ResetType - Supplies the type of reset to perform.
- ResetStatus - Supplies the status code for this reset.
- DataSize - Supplies the size of the reset data.
- ResetData - Supplies an optional pointer for reset types of cold, warm, or
- shutdown to a null-terminated string, optionally followed by additional
- binary data.
- Return Value:
- None. This routine does not return.
- --*/
- {
- volatile UINT32 *PrmResetStatus;
- volatile UINT32 *ResetControl;
- UINT32 Value;
- volatile UINT32 *Watchdog;
- //
- // Attempt to flush non-volatile variable data out to storage.
- //
- EfiCoreFlushVariableData();
- //
- // There is no official way to shutdown the BCM2835. The Raspberry Pi
- // firmware, however, stores the boot partition information in the PRM
- // reset status register. A special partition value is reserved to indicate
- // that the firmware should not proceed with the boot process.
- //
- if (ResetType == EfiResetShutdown) {
- PrmResetStatus = EfiBcm2835PrmBase + Bcm2709PrmResetStatus;
- *PrmResetStatus |= BCM2709_PRM_PASSWORD |
- RPI_BCM2709_PRM_RESET_STATUS_HALT;
- }
- Watchdog = EfiBcm2835PrmBase + Bcm2709PrmWatchdog;
- *Watchdog = BCM2709_PRM_WATCHDOG_RESET_TICKS | BCM2709_PRM_PASSWORD;
- ResetControl = EfiBcm2835PrmBase + Bcm2709PrmResetControl;
- Value = *ResetControl;
- Value &= ~BCM2709_PRM_RESET_CONTROL_TYPE_MASK;
- Value |= BCM2709_PRM_PASSWORD |
- BCM2709_PRM_RESET_CONTROL_TYPE_FULL;
- *ResetControl = Value;
- return;
- }
- EFIAPI
- EFI_STATUS
- EfipBcm2835GetTime (
- EFI_TIME *Time,
- EFI_TIME_CAPABILITIES *Capabilities
- )
- /*++
- Routine Description:
- This routine returns the current time and dat information, and
- timekeeping capabilities of the hardware platform.
- Arguments:
- Time - Supplies a pointer where the current time will be returned.
- Capabilities - Supplies an optional pointer where the capabilities will be
- returned on success.
- Return Value:
- EFI_SUCCESS on success.
- EFI_INVALID_PARAMETER if the time parameter was NULL.
- EFI_DEVICE_ERROR if there was a hardware error accessing the device.
- --*/
- {
- return EFI_SUCCESS;
- }
- EFIAPI
- EFI_STATUS
- EfipBcm2835SetTime (
- EFI_TIME *Time
- )
- /*++
- Routine Description:
- This routine sets the current local time and date information.
- Arguments:
- Time - Supplies a pointer to the time to set.
- Return Value:
- EFI_SUCCESS on success.
- EFI_INVALID_PARAMETER if a time field is out of range.
- EFI_DEVICE_ERROR if there was a hardware error accessing the device.
- --*/
- {
- return EFI_SUCCESS;
- }
- EFIAPI
- EFI_STATUS
- EfipBcm2835GetWakeupTime (
- BOOLEAN *Enabled,
- BOOLEAN *Pending,
- EFI_TIME *Time
- )
- /*++
- Routine Description:
- This routine gets the current wake alarm setting.
- Arguments:
- Enabled - Supplies a pointer that receives a boolean indicating if the
- alarm is currently enabled or disabled.
- Pending - Supplies a pointer that receives a boolean indicating if the
- alarm signal is pending and requires acknowledgement.
- Time - Supplies a pointer that receives the current wake time.
- Return Value:
- EFI_SUCCESS on success.
- EFI_INVALID_PARAMETER if any parameter is NULL.
- EFI_DEVICE_ERROR if there was a hardware error accessing the device.
- EFI_UNSUPPORTED if the wakeup timer is not supported on this platform.
- --*/
- {
- return EFI_SUCCESS;
- }
- EFIAPI
- EFI_STATUS
- EfipBcm2835SetWakeupTime (
- BOOLEAN Enable,
- EFI_TIME *Time
- )
- /*++
- Routine Description:
- This routine sets the current wake alarm setting.
- Arguments:
- Enable - Supplies a boolean enabling or disabling the wakeup timer.
- Time - Supplies an optional pointer to the time to set. This parameter is
- only optional if the enable parameter is FALSE.
- Return Value:
- EFI_SUCCESS on success.
- EFI_INVALID_PARAMETER if a time field is out of range.
- EFI_DEVICE_ERROR if there was a hardware error accessing the device.
- EFI_UNSUPPORTED if the wakeup timer is not supported on this platform.
- --*/
- {
- return EFI_SUCCESS;
- }
|