1 /** @file 2 Do a generic Cold Reset for OMAP3550 and BeagleBoard specific Warm reset 3 4 Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR> 5 6 This program and the accompanying materials 7 are licensed and made available under the terms and conditions of the BSD License 8 which accompanies this distribution. The full text of the license may be found at 9 http://opensource.org/licenses/bsd-license.php 10 11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 13 14 **/ 15 16 17 #include <Uefi.h> 18 19 #include <Library/ArmLib.h> 20 #include <Library/CacheMaintenanceLib.h> 21 #include <Library/MemoryAllocationLib.h> 22 #include <Library/IoLib.h> 23 #include <Library/PcdLib.h> 24 #include <Library/DebugLib.h> 25 #include <Library/UefiBootServicesTableLib.h> 26 27 #include <Omap3530/Omap3530.h> 28 29 30 VOID 31 ShutdownEfi ( 32 VOID 33 ) 34 { 35 EFI_STATUS Status; 36 UINTN MemoryMapSize; 37 EFI_MEMORY_DESCRIPTOR *MemoryMap; 38 UINTN MapKey; 39 UINTN DescriptorSize; 40 UINTN DescriptorVersion; 41 UINTN Pages; 42 43 MemoryMap = NULL; 44 MemoryMapSize = 0; 45 do { 46 Status = gBS->GetMemoryMap ( 47 &MemoryMapSize, 48 MemoryMap, 49 &MapKey, 50 &DescriptorSize, 51 &DescriptorVersion 52 ); 53 if (Status == EFI_BUFFER_TOO_SMALL) { 54 55 Pages = EFI_SIZE_TO_PAGES (MemoryMapSize) + 1; 56 MemoryMap = AllocatePages (Pages); 57 58 // 59 // Get System MemoryMap 60 // 61 Status = gBS->GetMemoryMap ( 62 &MemoryMapSize, 63 MemoryMap, 64 &MapKey, 65 &DescriptorSize, 66 &DescriptorVersion 67 ); 68 // Don't do anything between the GetMemoryMap() and ExitBootServices() 69 if (!EFI_ERROR (Status)) { 70 Status = gBS->ExitBootServices (gImageHandle, MapKey); 71 if (EFI_ERROR (Status)) { 72 FreePages (MemoryMap, Pages); 73 MemoryMap = NULL; 74 MemoryMapSize = 0; 75 } 76 } 77 } 78 } while (EFI_ERROR (Status)); 79 80 //Clean and invalidate caches. 81 WriteBackInvalidateDataCache(); 82 InvalidateInstructionCache(); 83 84 //Turning off Caches and MMU 85 ArmDisableDataCache (); 86 ArmDisableInstructionCache (); 87 ArmDisableMmu (); 88 } 89 90 typedef 91 VOID 92 (EFIAPI *CALL_STUB)( 93 VOID 94 ); 95 96 97 /** 98 Resets the entire platform. 99 100 @param ResetType The type of reset to perform. 101 @param ResetStatus The status code for the reset. 102 @param DataSize The size, in bytes, of WatchdogData. 103 @param ResetData For a ResetType of EfiResetCold, EfiResetWarm, or 104 EfiResetShutdown the data buffer starts with a Null-terminated 105 Unicode string, optionally followed by additional binary data. 106 107 **/ 108 EFI_STATUS 109 EFIAPI 110 LibResetSystem ( 111 IN EFI_RESET_TYPE ResetType, 112 IN EFI_STATUS ResetStatus, 113 IN UINTN DataSize, 114 IN CHAR16 *ResetData OPTIONAL 115 ) 116 { 117 CALL_STUB StartOfFv; 118 119 if (ResetData != NULL) { 120 DEBUG((EFI_D_ERROR, "%s", ResetData)); 121 } 122 123 ShutdownEfi (); 124 125 switch (ResetType) { 126 case EfiResetWarm: 127 //Perform warm reset of the system by jumping to the begining of the FV 128 StartOfFv = (CALL_STUB)(UINTN)PcdGet64 (PcdFvBaseAddress); 129 StartOfFv (); 130 break; 131 case EfiResetCold: 132 case EfiResetShutdown: 133 default: 134 //Perform cold reset of the system. 135 MmioOr32 (PRM_RSTCTRL, RST_DPLL3); 136 while ((MmioRead32(PRM_RSTST) & GLOBAL_COLD_RST) != 0x1); 137 break; 138 } 139 140 // If the reset didn't work, return an error. 141 ASSERT (FALSE); 142 return EFI_DEVICE_ERROR; 143 } 144 145 146 147 /** 148 Initialize any infrastructure required for LibResetSystem () to function. 149 150 @param ImageHandle The firmware allocated handle for the EFI image. 151 @param SystemTable A pointer to the EFI System Table. 152 153 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. 154 155 **/ 156 EFI_STATUS 157 EFIAPI 158 LibInitializeResetSystem ( 159 IN EFI_HANDLE ImageHandle, 160 IN EFI_SYSTEM_TABLE *SystemTable 161 ) 162 { 163 return EFI_SUCCESS; 164 } 165 166