]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/UefiRuntimeLib/RuntimeLib.c
Implement Read() and Poll()
[mirror_edk2.git] / MdePkg / Library / UefiRuntimeLib / RuntimeLib.c
CommitLineData
42eedea9 1/** @file\r
60c93673 2 UEFI Runtime Library implementation for non IPF processor types.\r
ebcc8fb7 3\r
60c93673 4Copyright (c) 2006 - 2008 Intel Corporation. <BR>\r
ebcc8fb7 5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <RuntimeLibInternal.h>\r
16\r
17///\r
18/// Driver Lib Module Globals\r
19///\r
20\r
21STATIC EFI_EVENT mEfiVirtualNotifyEvent;\r
21998b67 22STATIC EFI_EVENT mEfiExitBootServicesEvent;\r
ebcc8fb7 23STATIC BOOLEAN mEfiGoneVirtual = FALSE;\r
24STATIC BOOLEAN mEfiAtRuntime = FALSE;\r
25EFI_RUNTIME_SERVICES *mRT;\r
26\r
27/**\r
42eedea9 28 Set AtRuntime flag as TRUE after ExitBootServices.\r
ebcc8fb7 29\r
30 @param[in] Event The Event that is being processed\r
31 @param[in] Context Event Context\r
32**/\r
33VOID\r
34EFIAPI\r
21998b67 35RuntimeLibExitBootServicesEvent (\r
ebcc8fb7 36 IN EFI_EVENT Event,\r
37 IN VOID *Context\r
38 )\r
39{\r
40 //\r
41 // Clear out BootService globals\r
42 //\r
43 gBS = NULL;\r
44\r
45 mEfiAtRuntime = TRUE;\r
46}\r
47\r
48/**\r
49 Fixup internal data so that EFI can be call in virtual mode.\r
50 Call the passed in Child Notify event and convert any pointers in\r
51 lib to virtual mode.\r
52\r
53 @param[in] Event The Event that is being processed\r
54 @param[in] Context Event Context\r
55**/\r
ebcc8fb7 56VOID\r
57EFIAPI\r
58RuntimeLibVirtualNotifyEvent (\r
59 IN EFI_EVENT Event,\r
60 IN VOID *Context\r
61 )\r
62{\r
ebcc8fb7 63 //\r
64 // Update global for Runtime Services Table and IO\r
65 //\r
66 EfiConvertPointer (0, (VOID **) &mRT);\r
67\r
68 mEfiGoneVirtual = TRUE;\r
69}\r
70\r
71/**\r
72 Intialize runtime Driver Lib if it has not yet been initialized.\r
60c93673
LG
73 It will ASSERT() if gRT is NULL or gBS is NULL.\r
74 It will ASSERT() if that operation fails.\r
ebcc8fb7 75\r
76 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
77 @param[in] SystemTable A pointer to the EFI System Table.\r
78\r
79 @return EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.\r
80**/\r
81EFI_STATUS\r
82EFIAPI\r
83RuntimeDriverLibConstruct (\r
84 IN EFI_HANDLE ImageHandle,\r
85 IN EFI_SYSTEM_TABLE *SystemTable\r
86 )\r
87{\r
88 EFI_STATUS Status;\r
89\r
60c93673
LG
90 ASSERT (gRT != NULL);\r
91 ASSERT (gBS != NULL);\r
92\r
ad9e507a 93 mRT = gRT;\r
ebcc8fb7 94 //\r
95 // Register SetVirtualAddressMap () notify function\r
96 //\r
ebcc8fb7 97 Status = gBS->CreateEvent (\r
98 EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,\r
99 TPL_NOTIFY,\r
100 RuntimeLibVirtualNotifyEvent,\r
101 NULL,\r
102 &mEfiVirtualNotifyEvent\r
103 );\r
104\r
105 ASSERT_EFI_ERROR (Status);\r
106\r
21998b67 107 Status = gBS->CreateEvent (\r
108 EVT_SIGNAL_EXIT_BOOT_SERVICES,\r
109 TPL_NOTIFY,\r
110 RuntimeLibExitBootServicesEvent,\r
111 NULL,\r
112 &mEfiExitBootServicesEvent\r
113 );\r
114\r
115 ASSERT_EFI_ERROR (Status);\r
116\r
ebcc8fb7 117 return Status;\r
118}\r
119\r
120/**\r
60c93673
LG
121 If a runtime driver exits with an error, it must call this routine \r
122 to free the allocated resource before the exiting.\r
123 It will ASSERT() if gBS is NULL.\r
124 It will ASSERT() if that operation fails.\r
ebcc8fb7 125\r
42eedea9 126 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
127 @param[in] SystemTable A pointer to the EFI System Table.\r
128\r
ebcc8fb7 129 @retval EFI_SUCCESS Shutdown the Runtime Driver Lib successfully\r
130 @retval EFI_UNSUPPORTED Runtime Driver lib was not initialized at all\r
131**/\r
132EFI_STATUS\r
133EFIAPI\r
134RuntimeDriverLibDeconstruct (\r
135 IN EFI_HANDLE ImageHandle,\r
136 IN EFI_SYSTEM_TABLE *SystemTable\r
137 )\r
138{\r
139 EFI_STATUS Status;\r
140\r
141 //\r
142 // Close SetVirtualAddressMap () notify function\r
143 //\r
144 ASSERT (gBS != NULL);\r
145 Status = gBS->CloseEvent (mEfiVirtualNotifyEvent);\r
146 ASSERT_EFI_ERROR (Status);\r
147\r
21998b67 148 Status = gBS->CloseEvent (mEfiExitBootServicesEvent);\r
149 ASSERT_EFI_ERROR (Status);\r
150\r
ebcc8fb7 151 return Status;\r
152}\r
153\r
154/**\r
42eedea9 155 Return TRUE if ExitBootServices () has been called.\r
ebcc8fb7 156\r
157 @retval TRUE If ExitBootServices () has been called\r
158**/\r
159BOOLEAN\r
160EFIAPI\r
161EfiAtRuntime (\r
162 VOID\r
163 )\r
164{\r
165 return mEfiAtRuntime;\r
166}\r
167\r
168/**\r
42eedea9 169 Return TRUE if SetVirtualAddressMap () has been called.\r
ebcc8fb7 170\r
171 @retval TRUE If SetVirtualAddressMap () has been called\r
172**/\r
173BOOLEAN\r
174EFIAPI\r
175EfiGoneVirtual (\r
176 VOID\r
177 )\r
178{\r
179 return mEfiGoneVirtual;\r
180}\r
181\r