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