QuarkSocPkg: Add new package for Quark SoC X1000
[mirror_edk2.git] / QuarkSocPkg / QuarkNorthCluster / Library / QNCAccessLib / RuntimeAccess.c
CommitLineData
9b6bbcdb
MK
1/** @file\r
2Runtime Lib function for QNC internal network access.\r
3\r
4Copyright (c) 2013-2015 Intel Corporation.\r
5\r
6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16\r
17#include <PiDxe.h>\r
18\r
19#include <Guid/EventGroup.h>\r
20\r
21#include <Library/BaseLib.h>\r
22#include <Library/DebugLib.h>\r
23#include <Library/UefiBootServicesTableLib.h>\r
24#include <Library/UefiRuntimeLib.h>\r
25#include <Library/QNCAccessLib.h>\r
26\r
27///\r
28/// Set Virtual Address Map Event\r
29///\r
30EFI_EVENT mDxeRuntimeQncAccessLibVirtualNotifyEvent = NULL;\r
31\r
32///\r
33/// Module global that contains the base physical address of the PCI Express MMIO range.\r
34///\r
35UINTN mDxeRuntimeQncAccessLibPciExpressBaseAddress = 0;\r
36\r
37/**\r
38 Convert the physical PCI Express MMIO address to a virtual address.\r
39\r
40 @param[in] Event The event that is being processed.\r
41 @param[in] Context The Event Context.\r
42**/\r
43VOID\r
44EFIAPI\r
45DxeRuntimeQncAccessLibVirtualNotify (\r
46 IN EFI_EVENT Event,\r
47 IN VOID *Context\r
48 )\r
49{\r
50 EFI_STATUS Status;\r
51\r
52 //\r
53 // Convert the physical PCI Express MMIO address to a virtual address.\r
54 //\r
55 Status = EfiConvertPointer (0, (VOID **) &mDxeRuntimeQncAccessLibPciExpressBaseAddress);\r
56\r
57 ASSERT_EFI_ERROR (Status);\r
58}\r
59\r
60/**\r
61 The constructor function to setup globals and goto virtual mode notify.\r
62\r
63 @param ImageHandle The firmware allocated handle for the EFI image.\r
64 @param SystemTable A pointer to the EFI System Table.\r
65\r
66 @retval EFI_SUCCESS The constructor completed successfully.\r
67 @retval Other value The constructor did not complete successfully.\r
68\r
69**/\r
70EFI_STATUS\r
71EFIAPI\r
72DxeRuntimeQncAccessLibConstructor (\r
73 IN EFI_HANDLE ImageHandle,\r
74 IN EFI_SYSTEM_TABLE *SystemTable\r
75 )\r
76{\r
77 EFI_STATUS Status;\r
78\r
79 //\r
80 // Cache the physical address of the PCI Express MMIO range into a module global variable\r
81 //\r
82 mDxeRuntimeQncAccessLibPciExpressBaseAddress = (UINTN) PcdGet64(PcdPciExpressBaseAddress);\r
83\r
84 //\r
85 // Register SetVirtualAddressMap () notify function\r
86 //\r
87 Status = gBS->CreateEventEx (\r
88 EVT_NOTIFY_SIGNAL,\r
89 TPL_NOTIFY,\r
90 DxeRuntimeQncAccessLibVirtualNotify,\r
91 NULL,\r
92 &gEfiEventVirtualAddressChangeGuid,\r
93 &mDxeRuntimeQncAccessLibVirtualNotifyEvent\r
94 );\r
95 ASSERT_EFI_ERROR (Status);\r
96\r
97 return Status;\r
98}\r
99\r
100/**\r
101 The destructor function frees any allocated buffers and closes the Set Virtual\r
102 Address Map event.\r
103\r
104 @param ImageHandle The firmware allocated handle for the EFI image.\r
105 @param SystemTable A pointer to the EFI System Table.\r
106\r
107 @retval EFI_SUCCESS The destructor completed successfully.\r
108 @retval Other value The destructor did not complete successfully.\r
109\r
110**/\r
111EFI_STATUS\r
112EFIAPI\r
113DxeRuntimeQncAccessLibDestructor (\r
114 IN EFI_HANDLE ImageHandle,\r
115 IN EFI_SYSTEM_TABLE *SystemTable\r
116 )\r
117{\r
118 EFI_STATUS Status;\r
119\r
120 //\r
121 // Close the Set Virtual Address Map event\r
122 //\r
123 Status = gBS->CloseEvent (mDxeRuntimeQncAccessLibVirtualNotifyEvent);\r
124 ASSERT_EFI_ERROR (Status);\r
125\r
126 return Status;\r
127}\r
128\r
129/**\r
130 Gets the base address of PCI Express for Quark North Cluster.\r
131\r
132 @return The base address of PCI Express for Quark North Cluster.\r
133\r
134**/\r
135UINTN\r
136EFIAPI\r
137QncGetPciExpressBaseAddress (\r
138 VOID\r
139 )\r
140{\r
141 //\r
142 // If system goes to virtual mode then virtual notify callback will update\r
143 // mDxeRuntimeQncAccessLibPciExpressBaseAddress with virtual address of\r
144 // PCIe memory base.\r
145 //\r
146 return mDxeRuntimeQncAccessLibPciExpressBaseAddress;\r
147}\r
148\r