]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/SmmControl2OnSmmControlThunk/SmmControl2OnSmmControlThunk.c
PI 1.2 Errata C: A new return condition is added for the returned status code EFI_INV...
[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 - 2011, Intel Corporation. All rights reserved.<BR>
5 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_INVALID_PARAMETER The last periodic activation has not been cleared.
42 @retval EFI_NOT_STARTED The SMM base service has not been initialized.
43 **/
44 EFI_STATUS
45 EFIAPI
46 SmmControl2Trigger (
47 IN CONST EFI_SMM_CONTROL2_PROTOCOL *This,
48 IN OUT UINT8 *CommandPort OPTIONAL,
49 IN OUT UINT8 *DataPort OPTIONAL,
50 IN BOOLEAN Periodic OPTIONAL,
51 IN UINTN ActivationInterval OPTIONAL
52 )
53 {
54 UINTN ArgumentBufferSize;
55
56 ArgumentBufferSize = 0;
57 if (CommandPort != NULL) {
58 ArgumentBufferSize = 1;
59 }
60 if (DataPort != NULL) {
61 IoWrite8 (mDataPort, *DataPort);
62 }
63 return mSmmControl->Trigger (mSmmControl, (INT8 *)CommandPort, &ArgumentBufferSize, Periodic, ActivationInterval);
64 }
65
66 /**
67 Clears any system state that was created in response to the Trigger() call.
68
69 This function acknowledges and causes the deassertion of the SMI activation source.
70
71 @param[in] This The EFI_SMM_CONTROL2_PROTOCOL instance.
72 @param[in] Periodic Optional parameter to repeat at this period one time
73
74 @retval EFI_SUCCESS The SMI/PMI has been engendered.
75 @retval EFI_DEVICE_ERROR The source could not be cleared.
76 @retval EFI_INVALID_PARAMETER The service did not support the Periodic input argument.
77 **/
78 EFI_STATUS
79 EFIAPI
80 SmmControl2Clear (
81 IN CONST EFI_SMM_CONTROL2_PROTOCOL *This,
82 IN BOOLEAN Periodic OPTIONAL
83 )
84 {
85 return mSmmControl->Clear (mSmmControl, Periodic);
86 }
87
88 /**
89 Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
90
91 This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
92 It convers pointer to new virtual address.
93
94 @param[in] Event Event whose notification function is being invoked.
95 @param[in] Context Pointer to the notification function's context.
96
97 **/
98 VOID
99 EFIAPI
100 SetVirtualAddressNotify (
101 IN EFI_EVENT Event,
102 IN VOID *Context
103 )
104 {
105 EfiConvertPointer (0x0, (VOID **)&mSmmControl);
106 }
107
108 /**
109 Entry Point for this thunk driver.
110
111 @param[in] ImageHandle Image handle of this driver.
112 @param[in] SystemTable A Pointer to the EFI System Table.
113
114 @retval EFI_SUCCESS The entry point is executed successfully.
115 @retval other Some error occurred when executing this entry point.
116 **/
117 EFI_STATUS
118 EFIAPI
119 SmmControl2ThunkMain (
120 IN EFI_HANDLE ImageHandle,
121 IN EFI_SYSTEM_TABLE *SystemTable
122 )
123 {
124 EFI_STATUS Status;
125 EFI_EVENT Event;
126 EFI_SMM_CONTROL_REGISTER RegisterInfo;
127
128 ///
129 /// Locate Framework SMM Control Protocol
130 ///
131 Status = gBS->LocateProtocol (&gEfiSmmControlProtocolGuid, NULL, (VOID **)&mSmmControl);
132 ASSERT_EFI_ERROR (Status);
133
134 gSmmControl2.MinimumTriggerPeriod = mSmmControl->MinimumTriggerPeriod;
135
136 Status = mSmmControl->GetRegisterInfo (mSmmControl, &RegisterInfo);
137 ASSERT_EFI_ERROR (Status);
138 mDataPort = RegisterInfo.SmiDataRegister;
139
140 ///
141 /// Create event on SetVirtualAddressMap() to convert mSmmControl from a physical address to a virtual address
142 ///
143 Status = gBS->CreateEventEx (
144 EVT_NOTIFY_SIGNAL,
145 TPL_NOTIFY,
146 SetVirtualAddressNotify,
147 NULL,
148 &gEfiEventVirtualAddressChangeGuid,
149 &Event
150 );
151
152 ASSERT_EFI_ERROR (Status);
153
154 ///
155 /// Publish framework SMM Control Protocol
156 ///
157 Status = gBS->InstallProtocolInterface (
158 &ImageHandle,
159 &gEfiSmmControl2ProtocolGuid,
160 EFI_NATIVE_INTERFACE,
161 &gSmmControl2
162 );
163 return Status;
164 }
165