]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/SmmControl2OnSmmControlThunk/SmmControl2OnSmmControlThunk.c
Update this module from DXE_DRIVER to DXE_RUNTIME_DRIVER and convert mSmmControl...
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / SmmControl2OnSmmControlThunk / SmmControl2OnSmmControlThunk.c
1 /** @file
2 SMM Control2 Protocol on SMM Control Protocol Thunk driver.
3
4 Copyright (c) 2009 - 2010, Intel Corporation
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 "SmmControl2OnSmmControlThunk.h"
16
17 EFI_SMM_CONTROL2_PROTOCOL gSmmControl2 = {
18 SmmControl2Trigger,
19 SmmControl2Clear,
20 0
21 };
22
23 EFI_SMM_CONTROL_PROTOCOL *mSmmControl;
24 UINT8 mDataPort;
25
26 /**
27 Invokes SMI activation from either the preboot or runtime environment.
28
29 This function generates an SMI.
30
31 @param[in] This The EFI_SMM_CONTROL2_PROTOCOL instance.
32 @param[in, out] CommandPort The value written to the command port.
33 @param[in, out] DataPort The value written to the data port.
34 @param[in] Periodic Optional mechanism to engender a periodic stream.
35 @param[in] ActivationInterval Optional parameter to repeat at this period one
36 time or, if the Periodic Boolean is set, periodically.
37
38 @retval EFI_SUCCESS The SMI/PMI has been engendered.
39 @retval EFI_DEVICE_ERROR The timing is unsupported.
40 @retval EFI_INVALID_PARAMETER The activation period is unsupported.
41 @retval EFI_NOT_STARTED The SMM base service has not been initialized.
42 **/
43 EFI_STATUS
44 EFIAPI
45 SmmControl2Trigger (
46 IN CONST EFI_SMM_CONTROL2_PROTOCOL *This,
47 IN OUT UINT8 *CommandPort OPTIONAL,
48 IN OUT UINT8 *DataPort OPTIONAL,
49 IN BOOLEAN Periodic OPTIONAL,
50 IN UINTN ActivationInterval OPTIONAL
51 )
52 {
53 UINTN ArgumentBufferSize;
54
55 ArgumentBufferSize = 0;
56 if (CommandPort != NULL) {
57 ArgumentBufferSize = 1;
58 }
59 if (DataPort != NULL) {
60 IoWrite8 (mDataPort, *DataPort);
61 }
62 return mSmmControl->Trigger (mSmmControl, (INT8 *)CommandPort, &ArgumentBufferSize, Periodic, ActivationInterval);
63 }
64
65 /**
66 Clears any system state that was created in response to the Trigger() call.
67
68 This function acknowledges and causes the deassertion of the SMI activation source.
69
70 @param[in] This The EFI_SMM_CONTROL2_PROTOCOL instance.
71 @param[in] Periodic Optional parameter to repeat at this period one time
72
73 @retval EFI_SUCCESS The SMI/PMI has been engendered.
74 @retval EFI_DEVICE_ERROR The source could not be cleared.
75 @retval EFI_INVALID_PARAMETER The service did not support the Periodic input argument.
76 **/
77 EFI_STATUS
78 EFIAPI
79 SmmControl2Clear (
80 IN CONST EFI_SMM_CONTROL2_PROTOCOL *This,
81 IN BOOLEAN Periodic OPTIONAL
82 )
83 {
84 return mSmmControl->Clear (mSmmControl, Periodic);
85 }
86
87 /**
88 Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
89
90 This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
91 It convers pointer to new virtual address.
92
93 @param[in] Event Event whose notification function is being invoked.
94 @param[in] Context Pointer to the notification function's context.
95
96 **/
97 VOID
98 EFIAPI
99 SetVirtualAddressNotify (
100 IN EFI_EVENT Event,
101 IN VOID *Context
102 )
103 {
104 EfiConvertPointer (0x0, (VOID **)&mSmmControl);
105 }
106
107 /**
108 Entry Point for this thunk driver.
109
110 @param[in] ImageHandle Image handle of this driver.
111 @param[in] SystemTable A Pointer to the EFI System Table.
112
113 @retval EFI_SUCCESS The entry point is executed successfully.
114 @retval other Some error occurred when executing this entry point.
115 **/
116 EFI_STATUS
117 EFIAPI
118 SmmControl2ThunkMain (
119 IN EFI_HANDLE ImageHandle,
120 IN EFI_SYSTEM_TABLE *SystemTable
121 )
122 {
123 EFI_STATUS Status;
124 EFI_EVENT Event;
125 EFI_SMM_CONTROL_REGISTER RegisterInfo;
126
127 ///
128 /// Locate Framework SMM Control Protocol
129 ///
130 Status = gBS->LocateProtocol (&gEfiSmmControlProtocolGuid, NULL, (VOID **)&mSmmControl);
131 ASSERT_EFI_ERROR (Status);
132
133 gSmmControl2.MinimumTriggerPeriod = mSmmControl->MinimumTriggerPeriod;
134
135 Status = mSmmControl->GetRegisterInfo (mSmmControl, &RegisterInfo);
136 ASSERT_EFI_ERROR (Status);
137 mDataPort = RegisterInfo.SmiDataRegister;
138
139 ///
140 /// Create event on SetVirtualAddressMap() to convert mSmmControl from a physical address to a virtual address
141 ///
142 Status = gBS->CreateEventEx (
143 EVT_NOTIFY_SIGNAL,
144 TPL_NOTIFY,
145 SetVirtualAddressNotify,
146 NULL,
147 &gEfiEventVirtualAddressChangeGuid,
148 &Event
149 );
150
151 ASSERT_EFI_ERROR (Status);
152
153 ///
154 /// Publish framework SMM Control Protocol
155 ///
156 Status = gBS->InstallProtocolInterface (
157 &ImageHandle,
158 &gEfiSmmControl2ProtocolGuid,
159 EFI_NATIVE_INTERFACE,
160 &gSmmControl2
161 );
162 return Status;
163 }
164