TianoCore EDK2 master
Loading...
Searching...
No Matches
SsdtSerialPortGenerator.c
Go to the documentation of this file.
1
9#include <Library/AcpiLib.h>
10#include <Library/BaseLib.h>
12#include <Library/DebugLib.h>
14#include <Protocol/AcpiTable.h>
15
16// Module specific include files.
17#include <AcpiTableGenerator.h>
23
42 );
43
49#define SERIAL_PORT_START_UID 2
50
60#define MAX_SERIAL_PORTS_SUPPORTED 14
61
77EFIAPI
83 IN CONST UINTN TableCount
84 )
85{
86 EFI_STATUS Status;
88 UINTN Index;
89
90 ASSERT (This != NULL);
91 ASSERT (AcpiTableInfo != NULL);
92 ASSERT (CfgMgrProtocol != NULL);
93 ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID);
94 ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature);
95
96 if ((Table == NULL) ||
97 (*Table == NULL) ||
98 (TableCount == 0))
99 {
100 DEBUG ((DEBUG_ERROR, "ERROR: SSDT-SERIAL-PORT: Invalid Table Pointer\n"));
101 return EFI_INVALID_PARAMETER;
102 }
103
104 TableList = *Table;
105
106 for (Index = 0; Index < TableCount; Index++) {
107 if ((TableList[Index] != NULL) &&
108 (TableList[Index]->Signature ==
110 {
111 Status = FreeSsdtSerialPortTable (TableList[Index]);
112 } else {
113 Status = EFI_INVALID_PARAMETER;
114 }
115
116 if (EFI_ERROR (Status)) {
117 DEBUG ((
118 DEBUG_ERROR,
119 "ERROR: SSDT-SERIAL-PORT: Could not free SSDT table at index %d."
120 " Status = %r\n",
121 Index,
122 Status
123 ));
124 return Status;
125 }
126 } // for
127
128 // Free the table list.
129 FreePool (*Table);
130
131 return EFI_SUCCESS;
132}
133
159STATIC
161EFIAPI
167 OUT UINTN *CONST TableCount
168 )
169{
170 EFI_STATUS Status;
171 CM_ARCH_COMMON_SERIAL_PORT_INFO *SerialPortInfo;
172 UINT32 SerialPortCount;
173 UINTN Index;
174 CHAR8 NewName[AML_NAME_SEG_SIZE + 1];
175 UINT64 Uid;
176 EFI_ACPI_DESCRIPTION_HEADER **TableList;
177
178 ASSERT (This != NULL);
179 ASSERT (AcpiTableInfo != NULL);
180 ASSERT (CfgMgrProtocol != NULL);
181 ASSERT (Table != NULL);
182 ASSERT (TableCount != NULL);
183 ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID);
184 ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature);
185
186 *Table = NULL;
187
188 Status = GetEArchCommonObjSerialPortInfo (
189 CfgMgrProtocol,
191 &SerialPortInfo,
192 &SerialPortCount
193 );
194 if (EFI_ERROR (Status)) {
195 DEBUG ((
196 DEBUG_ERROR,
197 "ERROR: SSDT-SERIAL-PORT: Failed to get serial port information."
198 " Status = %r\n",
199 Status
200 ));
201 return Status;
202 }
203
204 if (SerialPortCount > MAX_SERIAL_PORTS_SUPPORTED) {
205 DEBUG ((
206 DEBUG_ERROR,
207 "ERROR: SSDT-SERIAL-PORT: Too many serial ports: %d."
208 " Maximum serial ports supported = %d.\n",
209 SerialPortCount,
211 ));
212 return EFI_INVALID_PARAMETER;
213 }
214
215 // Validate the SerialPort info.
216 Status = ValidateSerialPortInfo (SerialPortInfo, SerialPortCount);
217 if (EFI_ERROR (Status)) {
218 DEBUG ((
219 DEBUG_ERROR,
220 "ERROR: SSDT-SERIAL-PORT: Invalid serial port information. Status = %r\n",
221 Status
222 ));
223 return Status;
224 }
225
226 // Allocate a table to store pointers to the SSDT tables.
227 TableList = (EFI_ACPI_DESCRIPTION_HEADER **)
229 (sizeof (EFI_ACPI_DESCRIPTION_HEADER *) * SerialPortCount)
230 );
231 if (TableList == NULL) {
232 Status = EFI_OUT_OF_RESOURCES;
233 DEBUG ((
234 DEBUG_ERROR,
235 "ERROR: SSDT-SERIAL-PORT: Failed to allocate memory for Table List."
236 " Status = %r\n",
237 Status
238 ));
239 return Status;
240 }
241
242 // Setup the table list early so that appropriate cleanup
243 // can be done in case of failure.
244 *Table = TableList;
245
246 NewName[0] = 'C';
247 NewName[1] = 'O';
248 NewName[2] = 'M';
249 NewName[4] = '\0';
250 for (Index = 0; Index < SerialPortCount; Index++) {
251 Uid = SERIAL_PORT_START_UID + Index;
252 NewName[3] = AsciiFromHex ((UINT8)(Uid));
253
254 // Build a SSDT table describing the serial port.
255 Status = BuildSsdtSerialPortTable (
256 AcpiTableInfo,
257 &SerialPortInfo[Index],
258 NewName,
259 Uid,
260 &TableList[Index]
261 );
262 if (EFI_ERROR (Status)) {
263 DEBUG ((
264 DEBUG_ERROR,
265 "ERROR: SSDT-SERIAL-PORT: Failed to build associated SSDT table."
266 " Status = %r\n",
267 Status
268 ));
269 goto error_handler;
270 }
271
272 // Increment the table count here so that appropriate cleanup
273 // can be done in case of failure.
274 *TableCount += 1;
275 } // for
276
277error_handler:
278 // Note: Table list and Serial port count has been setup. The
279 // error handler does nothing here as the framework will invoke
280 // FreeSsdtSerialPortTableEx() even on failure.
281 return Status;
282}
283
286#define SSDT_SERIAL_GENERATOR_REVISION CREATE_REVISION (1, 0)
287
290STATIC
291CONST
293 // Generator ID
295 // Generator Description
296 L"ACPI.STD.SSDT.SERIAL.PORT.GENERATOR",
297 // ACPI Table Signature
299 // ACPI Table Revision - Unused
300 0,
301 // Minimum ACPI Table Revision - Unused
302 0,
303 // Creator ID
305 // Creator Revision
307 // Build table function. Use the extended version instead.
308 NULL,
309 // Free table function. Use the extended version instead.
310 NULL,
311 // Extended Build table function.
313 // Extended free function.
315};
316
328EFIAPI
330 IN EFI_HANDLE ImageHandle,
331 IN EFI_SYSTEM_TABLE *SystemTable
332 )
333{
334 EFI_STATUS Status;
335
337 DEBUG ((
338 DEBUG_INFO,
339 "SSDT-SERIAL-PORT: Register Generator. Status = %r\n",
340 Status
341 ));
342 ASSERT_EFI_ERROR (Status);
343
344 return Status;
345}
346
357EFIAPI
359 IN EFI_HANDLE ImageHandle,
360 IN EFI_SYSTEM_TABLE *SystemTable
361 )
362{
363 EFI_STATUS Status;
364
366 DEBUG ((
367 DEBUG_INFO,
368 "SSDT-SERIAL-PORT: Deregister Generator. Status = %r\n",
369 Status
370 ));
371 ASSERT_EFI_ERROR (Status);
372 return Status;
373}
UINT64 UINTN
#define EFI_ACPI_6_3_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
Definition: Acpi63.h:2831
UINT8 EFIAPI AsciiFromHex(IN UINT8 Hex)
Definition: AcpiHelper.c:25
EFI_STATUS EFIAPI RegisterAcpiTableGenerator(IN CONST ACPI_TABLE_GENERATOR *CONST Generator)
EFI_STATUS EFIAPI DeregisterAcpiTableGenerator(IN CONST ACPI_TABLE_GENERATOR *CONST Generator)
#define CREATE_STD_ACPI_TABLE_GEN_ID(TableId)
#define TABLE_GENERATOR_CREATOR_ID
@ EStdAcpiTableIdSsdtSerialPort
SSDT Serial-Port Generator.
@ EArchCommonObjSerialPortInfo
2 - Generic Serial Port Info
#define GET_OBJECT_LIST(CmObjectNameSpace, CmObjectId, Type)
@ EObjNameSpaceArchCommon
Arch Common Objects Namespace.
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_STATUS EFIAPI ValidateSerialPortInfo(IN CONST CM_ARCH_COMMON_SERIAL_PORT_INFO *SerialPortInfoTable, IN UINT32 SerialPortCount)
EFI_STATUS EFIAPI FreeSsdtSerialPortTable(IN EFI_ACPI_DESCRIPTION_HEADER *Table)
EFI_STATUS EFIAPI BuildSsdtSerialPortTable(IN CONST CM_STD_OBJ_ACPI_TABLE_INFO *AcpiTableInfo, IN CONST CM_ARCH_COMMON_SERIAL_PORT_INFO *SerialPortInfo, IN CONST CHAR8 *Name, IN CONST UINT64 Uid, OUT EFI_ACPI_DESCRIPTION_HEADER **Table)
STATIC CONST ACPI_TABLE_GENERATOR SsdtSerialPortGenerator
STATIC EFI_STATUS EFIAPI FreeSsdtSerialPortTableEx(IN CONST ACPI_TABLE_GENERATOR *CONST This, IN CONST CM_STD_OBJ_ACPI_TABLE_INFO *CONST AcpiTableInfo, IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, IN OUT EFI_ACPI_DESCRIPTION_HEADER ***CONST Table, IN CONST UINTN TableCount)
#define SERIAL_PORT_START_UID
EFI_STATUS EFIAPI AcpiSsdtSerialPortLibConstructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS EFIAPI AcpiSsdtSerialPortLibDestructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
#define MAX_SERIAL_PORTS_SUPPORTED
STATIC EFI_STATUS EFIAPI BuildSsdtSerialPortTableEx(IN CONST ACPI_TABLE_GENERATOR *This, IN CONST CM_STD_OBJ_ACPI_TABLE_INFO *CONST AcpiTableInfo, IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, OUT EFI_ACPI_DESCRIPTION_HEADER ***Table, OUT UINTN *CONST TableCount)
#define SSDT_SERIAL_GENERATOR_REVISION
#define CM_NULL_TOKEN
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112