TianoCore EDK2 master
Loading...
Searching...
No Matches
SsdtPcieSupportLib.c
Go to the documentation of this file.
1
18#include <Library/AcpiLib.h>
19#include <Library/BaseLib.h>
21#include <Library/DebugLib.h>
23#include <Protocol/AcpiTable.h>
24
25// Module specific include files.
26#include <AcpiTableGenerator.h>
34
36
54EFIAPI
58 IN UINT32 Uid,
60 )
61{
62 EFI_STATUS Status;
63 UINT32 Index;
64 UINT32 LastIndex;
65 UINT32 DeviceId;
66 CHAR8 AslName[AML_NAME_SEG_SIZE + 1];
67 AML_OBJECT_NODE_HANDLE DeviceNode;
68
69 ASSERT (MappingTable != NULL);
70 ASSERT (PciNode != NULL);
71
72 // Generic device name is "Dxx".
73 CopyMem (AslName, "Dxx_", AML_NAME_SEG_SIZE + 1);
74
75 LastIndex = MappingTable->LastIndex;
76
77 // There are at most 32 devices on a Pci bus.
78 if (LastIndex >= 32) {
79 ASSERT (0);
80 return EFI_INVALID_PARAMETER;
81 }
82
83 for (Index = 0; Index < LastIndex; Index++) {
84 DeviceId = MappingTable->Table[Index];
85 AslName[AML_NAME_SEG_SIZE - 3] = AsciiFromHex (DeviceId & 0xF);
86 AslName[AML_NAME_SEG_SIZE - 2] = AsciiFromHex ((DeviceId >> 4) & 0xF);
87
88 // ASL:
89 // Device (Dxx) {
90 // Name (_ADR, <address value>)
91 // }
92 Status = AmlCodeGenDevice (AslName, PciNode, &DeviceNode);
93 if (EFI_ERROR (Status)) {
94 ASSERT (0);
95 return Status;
96 }
97
98 /* ACPI 6.4 specification, Table 6.2: "ADR Object Address Encodings"
99 High word-Device #, Low word-Function #. (for example, device 3,
100 function 2 is 0x00030002). To refer to all the functions on a device #,
101 use a function number of FFFF).
102 */
103 Status = AmlCodeGenNameInteger (
104 "_ADR",
105 (DeviceId << 16) | 0xFFFF,
106 DeviceNode,
107 NULL
108 );
109 if (EFI_ERROR (Status)) {
110 ASSERT (0);
111 return Status;
112 }
113
114 // _SUN object is not generated as we don't know which slot will be used.
115 }
116
117 return Status;
118}
119
133EFIAPI
137 )
138{
139 EFI_STATUS Status;
140 EFI_STATUS Status1;
141 EFI_ACPI_DESCRIPTION_HEADER *SsdtPcieOscTemplate;
142 AML_ROOT_NODE_HANDLE OscTemplateRoot;
144
145 ASSERT (PciNode != NULL);
146
147 // Parse the Ssdt Pci Osc Template.
148 SsdtPcieOscTemplate = (EFI_ACPI_DESCRIPTION_HEADER *)
150
151 OscNode = NULL;
152 OscTemplateRoot = NULL;
153 Status = AmlParseDefinitionBlock (
154 SsdtPcieOscTemplate,
155 &OscTemplateRoot
156 );
157 if (EFI_ERROR (Status)) {
158 DEBUG ((
159 DEBUG_ERROR,
160 "ERROR: SSDT-PCI-OSC: Failed to parse SSDT PCI OSC Template."
161 " Status = %r\n",
162 Status
163 ));
164 return Status;
165 }
166
167 Status = AmlFindNode (OscTemplateRoot, "\\_OSC", &OscNode);
168 if (EFI_ERROR (Status)) {
169 goto error_handler;
170 }
171
172 Status = AmlDetachNode (OscNode);
173 if (EFI_ERROR (Status)) {
174 goto error_handler;
175 }
176
177 Status = AmlAttachNode (PciNode, OscNode);
178 if (EFI_ERROR (Status)) {
179 // Free the detached node.
180 AmlDeleteTree (OscNode);
181 goto error_handler;
182 }
183
184error_handler:
185 // Cleanup
186 Status1 = AmlDeleteTree (OscTemplateRoot);
187 if (EFI_ERROR (Status1)) {
188 DEBUG ((
189 DEBUG_ERROR,
190 "ERROR: SSDT-PCI-OSC: Failed to cleanup AML tree."
191 " Status = %r\n",
192 Status1
193 ));
194 // If Status was success but we failed to delete the AML Tree
195 // return Status1 else return the original error code, i.e. Status.
196 if (!EFI_ERROR (Status)) {
197 return Status1;
198 }
199 }
200
201 return Status;
202}
UINT8 EFIAPI AsciiFromHex(IN UINT8 Hex)
Definition: AcpiHelper.c:25
void * AML_ROOT_NODE_HANDLE
Definition: AmlLib.h:51
EFI_STATUS EFIAPI AmlCodeGenDevice(IN CONST CHAR8 *NameString, IN AML_NODE_HANDLE ParentNode OPTIONAL, OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL)
EFI_STATUS EFIAPI AmlCodeGenNameInteger(IN CONST CHAR8 *NameString, IN UINT64 Integer, IN AML_NODE_HANDLE ParentNode OPTIONAL, OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL)
EFI_STATUS EFIAPI AmlAttachNode(IN AML_NODE_HANDLE ParentNode, IN AML_NODE_HANDLE NewNode)
Definition: AmlApi.c:425
void * AML_OBJECT_NODE_HANDLE
Definition: AmlLib.h:55
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_STATUS EFIAPI GeneratePciSlots(IN CONST CM_ARCH_COMMON_PCI_CONFIG_SPACE_INFO *PciInfo, IN CONST MAPPING_TABLE *MappingTable, IN UINT32 Uid, IN OUT AML_OBJECT_NODE_HANDLE PciNode)
EFI_STATUS EFIAPI AddOscMethod(IN CONST CM_ARCH_COMMON_PCI_CONFIG_SPACE_INFO *PciInfo, IN OUT AML_OBJECT_NODE_HANDLE PciNode)
CHAR8 ssdtpcieosctemplate_aml_code[]
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
EFI_STATUS EFIAPI AmlFindNode(IN AML_NODE_HANDLE ReferenceNode, IN CONST CHAR8 *AslPath, OUT AML_NODE_HANDLE *OutNode)
EFI_STATUS EFIAPI AmlDeleteTree(IN AML_NODE_HANDLE Node)
EFI_STATUS EFIAPI AmlParseDefinitionBlock(IN CONST EFI_ACPI_DESCRIPTION_HEADER *DefinitionBlock, OUT AML_ROOT_NODE_HANDLE *RootPtr)
EFI_STATUS EFIAPI AmlDetachNode(IN AML_NODE_HANDLE Node)