Moving OMAP 3530 code out of BeagleBoard package into its own package
[mirror_edk2.git] / Omap35xxPkg / Library / BeagleBoardSystemLib / BeagleBoardSystemLib.c
1 /** @file
2
3 Copyright (c) 2008-2009, Apple Inc. All rights reserved.
4
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include <Uefi.h>
16
17 #include <Library/ArmLib.h>
18 #include <Library/CacheMaintenanceLib.h>
19 #include <Library/MemoryAllocationLib.h>
20 #include <Library/IoLib.h>
21 #include <Library/PcdLib.h>
22 #include <Library/DebugLib.h>
23 #include <Library/UefiBootServicesTableLib.h>
24 #include <Library/BeagleBoardSystemLib.h>
25
26 #include <Omap3530/Omap3530.h>
27
28 VOID
29 ResetSystem (
30 IN EFI_RESET_TYPE ResetType
31 )
32 {
33 switch (ResetType) {
34 case EfiResetWarm:
35 //Perform warm reset of the system.
36 GoLittleEndian(PcdGet32(PcdFlashFvMainBase));
37 break;
38 case EfiResetCold:
39 case EfiResetShutdown:
40 default:
41 //Perform cold reset of the system.
42 MmioOr32(PRM_RSTCTRL, RST_DPLL3);
43 while ((MmioRead32(PRM_RSTST) & GLOBAL_COLD_RST) != 0x1);
44 break;
45 }
46
47 //Should never come here.
48 ASSERT(FALSE);
49 }
50
51 VOID
52 ShutdownEfi (
53 VOID
54 )
55 {
56 EFI_STATUS Status;
57 UINTN MemoryMapSize;
58 EFI_MEMORY_DESCRIPTOR *MemoryMap;
59 UINTN MapKey;
60 UINTN DescriptorSize;
61 UINTN DescriptorVersion;
62 UINTN Pages;
63
64 MemoryMap = NULL;
65 MemoryMapSize = 0;
66 do {
67 Status = gBS->GetMemoryMap (
68 &MemoryMapSize,
69 MemoryMap,
70 &MapKey,
71 &DescriptorSize,
72 &DescriptorVersion
73 );
74 if (Status == EFI_BUFFER_TOO_SMALL) {
75
76 Pages = EFI_SIZE_TO_PAGES (MemoryMapSize) + 1;
77 MemoryMap = AllocatePages (Pages);
78
79 //
80 // Get System MemoryMap
81 //
82 Status = gBS->GetMemoryMap (
83 &MemoryMapSize,
84 MemoryMap,
85 &MapKey,
86 &DescriptorSize,
87 &DescriptorVersion
88 );
89 // Don't do anything between the GetMemoryMap() and ExitBootServices()
90 if (!EFI_ERROR (Status)) {
91 Status = gBS->ExitBootServices (gImageHandle, MapKey);
92 if (EFI_ERROR (Status)) {
93 FreePages (MemoryMap, Pages);
94 MemoryMap = NULL;
95 MemoryMapSize = 0;
96 }
97 }
98 }
99 } while (EFI_ERROR (Status));
100
101 //Clean and invalidate caches.
102 WriteBackInvalidateDataCache();
103 InvalidateInstructionCache();
104
105 //Turning off Caches and MMU
106 ArmDisableDataCache();
107 ArmDisableInstructionCache();
108 ArmDisableMmu();
109 }
110