• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /********************************************************************************
2 Copyright (C) 2016 Marvell International Ltd.
3 
4 Marvell BSD License Option
5 
6 If you received this File from Marvell, you may opt to use, redistribute and/or
7 modify this File under the following licensing terms.
8 Redistribution and use in source and binary forms, with or without modification,
9 are permitted provided that the following conditions are met:
10 
11   * Redistributions of source code must retain the above copyright notice,
12     this list of conditions and the following disclaimer.
13 
14   * Redistributions in binary form must reproduce the above copyright
15     notice, this list of conditions and the following disclaimer in the
16     documentation and/or other materials provided with the distribution.
17 
18   * Neither the name of Marvell nor the names of its contributors may be
19     used to endorse or promote products derived from this software without
20     specific prior written permission.
21 
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
26 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33 *******************************************************************************/
34 
35 
36 #include <PiDxe.h>
37 #include <Uefi.h>
38 
39 #include <Library/BaseLib.h>
40 #include <Library/DebugLib.h>
41 #include <Library/DxeServicesTableLib.h>
42 #include <Library/IoLib.h>
43 #include <Library/UefiLib.h>
44 #include <Library/UefiBootServicesTableLib.h>
45 #include <Library/UefiRuntimeLib.h>
46 #include <Library/UefiRuntimeServicesTableLib.h>
47 
48 #include <Guid/EventGroup.h>
49 
50 STATIC EFI_EVENT mResetSystemVirtualAddrChangeEvent;
51 STATIC UINT64    mAddress;
52 
53 STATIC
54 VOID
55 EFIAPI
LibResetSystemVirtualNotifyEvent(IN EFI_EVENT Event,IN VOID * Context)56 LibResetSystemVirtualNotifyEvent (
57   IN EFI_EVENT        Event,
58   IN VOID             *Context
59   )
60 {
61   //
62   // Convert physical address to virtual address.
63   //
64   EfiConvertPointer (0x0, (VOID**)&mAddress);
65   return;
66 }
67 
68 /**
69   Resets the entire platform.
70 
71   @param  ResetType             The type of reset to perform.
72   @param  ResetStatus           The status code for the reset.
73   @param  DataSize              The size, in bytes, of WatchdogData.
74   @param  ResetData             For a ResetType of EfiResetCold, EfiResetWarm,
75                                 or EfiResetShutdown the data buffer starts with
76                                 a Null-terminated Unicode string, optionally
77                                 followed by additional binary data.
78 **/
79 EFI_STATUS
80 EFIAPI
LibResetSystem(IN EFI_RESET_TYPE ResetType,IN EFI_STATUS ResetStatus,IN UINTN DataSize,IN VOID * ResetData OPTIONAL)81 LibResetSystem (
82   IN EFI_RESET_TYPE   ResetType,
83   IN EFI_STATUS       ResetStatus,
84   IN UINTN            DataSize,
85   IN VOID             *ResetData OPTIONAL
86   )
87 {
88   UINT32   Data;
89 
90   switch (ResetType) {
91   case EfiResetCold:
92   case EfiResetWarm:
93     Data = MmioRead32 (mAddress);
94     Data &= ~PcdGet32 (PcdResetRegMask);
95     MmioWrite32 (mAddress, Data);
96     break;
97   case EfiResetShutdown:
98   //
99   // Currently there is no support for power-off platform
100   //
101     break;
102   default:
103     break;
104   }
105 
106   return EFI_DEVICE_ERROR;
107 }
108 
109 EFI_STATUS
110 EFIAPI
LibInitializeResetSystem(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)111 LibInitializeResetSystem (
112   IN EFI_HANDLE        ImageHandle,
113   IN EFI_SYSTEM_TABLE  *SystemTable
114   )
115 {
116   UINT64 Alignment;
117   EFI_STATUS  Status;
118 
119   mAddress = PcdGet64 (PcdResetRegAddress);
120 
121   Alignment = ~(SIZE_64KB - 1);
122   //
123   // Add 64KB aligned and 64KB long memory space
124   //
125   Status = gDS->AddMemorySpace (
126                   EfiGcdMemoryTypeMemoryMappedIo,
127                   mAddress & Alignment, SIZE_64KB,
128                   EFI_MEMORY_UC | EFI_MEMORY_RUNTIME
129                   );
130   if (EFI_ERROR (Status)) {
131     ASSERT_EFI_ERROR (Status);
132     return Status;
133   }
134 
135   //
136   // Mark 64KB aligned and 64KB long memory space as runtime
137   //
138   Status = gDS->SetMemorySpaceAttributes (mAddress & Alignment, SIZE_64KB,
139     EFI_MEMORY_UC | EFI_MEMORY_RUNTIME);
140   if (EFI_ERROR (Status)) {
141     ASSERT_EFI_ERROR (Status);
142     return Status;
143   }
144 
145   //
146   // Register for the virtual address change event
147   //
148   Status = gBS->CreateEventEx (
149                   EVT_NOTIFY_SIGNAL,
150                   TPL_NOTIFY,
151                   LibResetSystemVirtualNotifyEvent,
152                   NULL,
153                   &gEfiEventVirtualAddressChangeGuid,
154                   &mResetSystemVirtualAddrChangeEvent
155                   );
156   ASSERT_EFI_ERROR (Status);
157 
158   return Status;
159 }
160