ReactOS 0.4.15-dev-7958-gcd0bb1a
rscreate.c File Reference
#include "acpi.h"
#include "accommon.h"
#include "acresrc.h"
#include "acnamesp.h"
Include dependency graph for rscreate.c:

Go to the source code of this file.

Macros

#define _COMPONENT   ACPI_RESOURCES
 

Functions

ACPI_STATUS AcpiBufferToResource (UINT8 *AmlBuffer, UINT16 AmlBufferLength, ACPI_RESOURCE **ResourcePtr)
 
ACPI_STATUS AcpiRsCreateResourceList (ACPI_OPERAND_OBJECT *AmlBuffer, ACPI_BUFFER *OutputBuffer)
 
ACPI_STATUS AcpiRsCreatePciRoutingTable (ACPI_OPERAND_OBJECT *PackageObject, ACPI_BUFFER *OutputBuffer)
 
ACPI_STATUS AcpiRsCreateAmlResources (ACPI_BUFFER *ResourceList, ACPI_BUFFER *OutputBuffer)
 

Macro Definition Documentation

◆ _COMPONENT

#define _COMPONENT   ACPI_RESOURCES

Definition at line 49 of file rscreate.c.

Function Documentation

◆ AcpiBufferToResource()

ACPI_STATUS AcpiBufferToResource ( UINT8 AmlBuffer,
UINT16  AmlBufferLength,
ACPI_RESOURCE **  ResourcePtr 
)

Definition at line 68 of file rscreate.c.

72{
74 ACPI_SIZE ListSizeNeeded;
75 void *Resource;
76 void *CurrentResourcePtr;
77
78
80
81
82 /*
83 * Note: we allow AE_AML_NO_RESOURCE_END_TAG, since an end tag
84 * is not required here.
85 */
86
87 /* Get the required length for the converted resource */
88
90 AmlBuffer, AmlBufferLength, &ListSizeNeeded);
92 {
93 Status = AE_OK;
94 }
95 if (ACPI_FAILURE (Status))
96 {
98 }
99
100 /* Allocate a buffer for the converted resource */
101
102 Resource = ACPI_ALLOCATE_ZEROED (ListSizeNeeded);
103 CurrentResourcePtr = Resource;
104 if (!Resource)
105 {
107 }
108
109 /* Perform the AML-to-Resource conversion */
110
112 AcpiRsConvertAmlToResources, &CurrentResourcePtr);
114 {
115 Status = AE_OK;
116 }
117 if (ACPI_FAILURE (Status))
118 {
120 }
121 else
122 {
123 *ResourcePtr = Resource;
124 }
125
127}
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
#define AE_AML_NO_RESOURCE_END_TAG
Definition: acexcep.h:207
#define AE_NO_MEMORY
Definition: acexcep.h:112
#define AE_OK
Definition: acexcep.h:97
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
#define ACPI_FUNCTION_TRACE(a)
Definition: acoutput.h:480
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 AmlBufferLength
Definition: acpixf.h:1103
ACPI_STATUS AcpiRsGetListLength(UINT8 *AmlBuffer, UINT32 AmlBufferLength, ACPI_SIZE *SizeNeeded)
Definition: rscalc.c:460
ACPI_STATUS AcpiRsConvertAmlToResources(UINT8 *Aml, UINT32 Length, UINT32 Offset, UINT8 ResourceIndex, void **Context)
Definition: rslist.c:68
#define ACPI_FREE(a)
Definition: actypes.h:386
UINT32 ACPI_STATUS
Definition: actypes.h:460
#define ACPI_ALLOCATE_ZEROED(a)
Definition: actypes.h:385
ACPI_STATUS AcpiUtWalkAmlResources(ACPI_WALK_STATE *WalkState, UINT8 *Aml, ACPI_SIZE AmlLength, ACPI_WALK_AML_CALLBACK UserFunction, void **Context)
Definition: utresrc.c:181
_Acquires_exclusive_lock_ Resource _Acquires_shared_lock_ Resource _Inout_ PERESOURCE Resource
Definition: cdprocs.h:843
#define NULL
Definition: types.h:112
Status
Definition: gdiplustypes.h:25
ACPI_STATUS AcpiBufferToResource(UINT8 *AmlBuffer, UINT16 AmlBufferLength, ACPI_RESOURCE **ResourcePtr)
Definition: rscreate.c:68

Referenced by AcpiBufferToResource().

◆ AcpiRsCreateAmlResources()

ACPI_STATUS AcpiRsCreateAmlResources ( ACPI_BUFFER ResourceList,
ACPI_BUFFER OutputBuffer 
)

Definition at line 462 of file rscreate.c.

465{
467 ACPI_SIZE AmlSizeNeeded = 0;
468
469
470 ACPI_FUNCTION_TRACE (RsCreateAmlResources);
471
472
473 /* Params already validated, no need to re-validate here */
474
475 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ResourceList Buffer = %p\n",
476 ResourceList->Pointer));
477
478 /* Get the buffer size needed for the AML byte stream */
479
481 ResourceList->Pointer, ResourceList->Length, &AmlSizeNeeded);
482
483 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "AmlSizeNeeded=%X, %s\n",
484 (UINT32) AmlSizeNeeded, AcpiFormatException (Status)));
485 if (ACPI_FAILURE (Status))
486 {
488 }
489
490 /* Validate/Allocate/Clear caller buffer */
491
492 Status = AcpiUtInitializeBuffer (OutputBuffer, AmlSizeNeeded);
493 if (ACPI_FAILURE (Status))
494 {
496 }
497
498 /* Do the conversion */
499
501 AmlSizeNeeded, OutputBuffer->Pointer);
502 if (ACPI_FAILURE (Status))
503 {
505 }
506
507 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
508 OutputBuffer->Pointer, (UINT32) OutputBuffer->Length));
510}
unsigned int UINT32
#define ACPI_DEBUG_PRINT(pl)
Definition: acoutput.h:475
#define ACPI_DB_INFO
Definition: acoutput.h:153
ACPI_STATUS AcpiRsConvertResourcesToAml(ACPI_RESOURCE *Resource, ACPI_SIZE AmlSizeNeeded, UINT8 *OutputBuffer)
Definition: rslist.c:179
ACPI_STATUS AcpiRsGetAmlLength(ACPI_RESOURCE *ResourceList, ACPI_SIZE ResourceListSize, ACPI_SIZE *SizeNeeded)
Definition: rscalc.c:211
ACPI_STATUS AcpiUtInitializeBuffer(ACPI_BUFFER *Buffer, ACPI_SIZE RequiredLength)
Definition: utalloc.c:336
const char * AcpiFormatException(ACPI_STATUS Status)
Definition: utexcep.c:70
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR OutputBuffer
Definition: wdfiotarget.h:863
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
Definition: wdfresource.h:309

Referenced by AcpiRsSetSrsMethodData().

◆ AcpiRsCreatePciRoutingTable()

ACPI_STATUS AcpiRsCreatePciRoutingTable ( ACPI_OPERAND_OBJECT PackageObject,
ACPI_BUFFER OutputBuffer 
)

Definition at line 234 of file rscreate.c.

237{
238 UINT8 *Buffer;
239 ACPI_OPERAND_OBJECT **TopObjectList;
240 ACPI_OPERAND_OBJECT **SubObjectList;
241 ACPI_OPERAND_OBJECT *ObjDesc;
242 ACPI_SIZE BufferSizeNeeded = 0;
243 UINT32 NumberOfElements;
245 ACPI_PCI_ROUTING_TABLE *UserPrt;
248 ACPI_BUFFER PathBuffer;
249
250
251 ACPI_FUNCTION_TRACE (RsCreatePciRoutingTable);
252
253
254 /* Params already validated, so we don't re-validate here */
255
256 /* Get the required buffer length */
257
259 PackageObject,&BufferSizeNeeded);
260 if (ACPI_FAILURE (Status))
261 {
263 }
264
265 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "BufferSizeNeeded = %X\n",
267
268 /* Validate/Allocate/Clear caller buffer */
269
271 if (ACPI_FAILURE (Status))
272 {
274 }
275
276 /*
277 * Loop through the ACPI_INTERNAL_OBJECTS - Each object should be a
278 * package that in turn contains an UINT64 Address, a UINT8 Pin,
279 * a Name, and a UINT8 SourceIndex.
280 */
281 TopObjectList = PackageObject->Package.Elements;
282 NumberOfElements = PackageObject->Package.Count;
283 Buffer = OutputBuffer->Pointer;
285
286 for (Index = 0; Index < NumberOfElements; Index++)
287 {
288 /*
289 * Point UserPrt past this current structure
290 *
291 * NOTE: On the first iteration, UserPrt->Length will
292 * be zero because we cleared the return buffer earlier
293 */
294 Buffer += UserPrt->Length;
296
297 /*
298 * Fill in the Length field with the information we have at this
299 * point. The minus four is to subtract the size of the UINT8
300 * Source[4] member because it is added below.
301 */
302 UserPrt->Length = (sizeof (ACPI_PCI_ROUTING_TABLE) - 4);
303
304 /* Each subpackage must be of length 4 */
305
306 if ((*TopObjectList)->Package.Count != 4)
307 {
309 "(PRT[%u]) Need package of length 4, found length %u",
310 Index, (*TopObjectList)->Package.Count));
312 }
313
314 /*
315 * Dereference the subpackage.
316 * The SubObjectList will now point to an array of the four IRQ
317 * elements: [Address, Pin, Source, SourceIndex]
318 */
319 SubObjectList = (*TopObjectList)->Package.Elements;
320
321 /* 1) First subobject: Dereference the PRT.Address */
322
323 ObjDesc = SubObjectList[0];
324 if (!ObjDesc || ObjDesc->Common.Type != ACPI_TYPE_INTEGER)
325 {
327 "(PRT[%u].Address) Need Integer, found %s",
328 Index, AcpiUtGetObjectTypeName (ObjDesc)));
330 }
331
332 UserPrt->Address = ObjDesc->Integer.Value;
333
334 /* 2) Second subobject: Dereference the PRT.Pin */
335
336 ObjDesc = SubObjectList[1];
337 if (!ObjDesc || ObjDesc->Common.Type != ACPI_TYPE_INTEGER)
338 {
339 ACPI_ERROR ((AE_INFO, "(PRT[%u].Pin) Need Integer, found %s",
340 Index, AcpiUtGetObjectTypeName (ObjDesc)));
342 }
343
344 UserPrt->Pin = (UINT32) ObjDesc->Integer.Value;
345
346 /*
347 * 3) Third subobject: Dereference the PRT.SourceName
348 * The name may be unresolved (slack mode), so allow a null object
349 */
350 ObjDesc = SubObjectList[2];
351 if (ObjDesc)
352 {
353 switch (ObjDesc->Common.Type)
354 {
356
357 if (ObjDesc->Reference.Class != ACPI_REFCLASS_NAME)
358 {
360 "(PRT[%u].Source) Need name, found Reference Class 0x%X",
361 Index, ObjDesc->Reference.Class));
363 }
364
365 Node = ObjDesc->Reference.Node;
366
367 /* Use *remaining* length of the buffer as max for pathname */
368
369 PathBuffer.Length = OutputBuffer->Length -
370 (UINT32) ((UINT8 *) UserPrt->Source -
371 (UINT8 *) OutputBuffer->Pointer);
372 PathBuffer.Pointer = UserPrt->Source;
373
375 (ACPI_HANDLE) Node, &PathBuffer, FALSE);
376 if (ACPI_FAILURE (Status))
377 {
379 }
380
381 /* +1 to include null terminator */
382
383 UserPrt->Length += (UINT32) strlen (UserPrt->Source) + 1;
384 break;
385
386 case ACPI_TYPE_STRING:
387
388 strcpy (UserPrt->Source, ObjDesc->String.Pointer);
389
390 /*
391 * Add to the Length field the length of the string
392 * (add 1 for terminator)
393 */
394 UserPrt->Length += ObjDesc->String.Length + 1;
395 break;
396
398 /*
399 * If this is a number, then the Source Name is NULL, since
400 * the entire buffer was zeroed out, we can leave this alone.
401 *
402 * Add to the Length field the length of the UINT32 NULL
403 */
404 UserPrt->Length += sizeof (UINT32);
405 break;
406
407 default:
408
410 "(PRT[%u].Source) Need Ref/String/Integer, found %s",
411 Index, AcpiUtGetObjectTypeName (ObjDesc)));
413 }
414 }
415
416 /* Now align the current length */
417
418 UserPrt->Length = (UINT32) ACPI_ROUND_UP_TO_64BIT (UserPrt->Length);
419
420 /* 4) Fourth subobject: Dereference the PRT.SourceIndex */
421
422 ObjDesc = SubObjectList[3];
423 if (!ObjDesc || ObjDesc->Common.Type != ACPI_TYPE_INTEGER)
424 {
426 "(PRT[%u].SourceIndex) Need Integer, found %s",
427 Index, AcpiUtGetObjectTypeName (ObjDesc)));
429 }
430
431 UserPrt->SourceIndex = (UINT32) ObjDesc->Integer.Value;
432
433 /* Point to the next ACPI_OPERAND_OBJECT in the top level package */
434
435 TopObjectList++;
436 }
437
438 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
439 OutputBuffer->Pointer, (UINT32) OutputBuffer->Length));
441}
unsigned char UINT8
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define AE_BAD_DATA
Definition: acexcep.h:154
#define AE_AML_PACKAGE_LIMIT
Definition: acexcep.h:190
#define ACPI_ROUND_UP_TO_64BIT(a)
Definition: acmacros.h:253
ACPI_STATUS AcpiNsHandleToPathname(ACPI_HANDLE TargetHandle, ACPI_BUFFER *Buffer, BOOLEAN NoTrailing)
Definition: nsnames.c:187
@ ACPI_REFCLASS_NAME
Definition: acobject.h:464
#define ACPI_ERROR(plist)
Definition: acoutput.h:240
#define AE_INFO
Definition: acoutput.h:230
ACPI_STATUS AcpiRsGetPciRoutingTableLength(ACPI_OPERAND_OBJECT *PackageObject, ACPI_SIZE *BufferSizeNeeded)
Definition: rscalc.c:746
struct acpi_pci_routing_table ACPI_PCI_ROUTING_TABLE
#define ACPI_TYPE_LOCAL_REFERENCE
Definition: actypes.h:719
#define ACPI_TYPE_STRING
Definition: actypes.h:689
#define ACPI_TYPE_INTEGER
Definition: actypes.h:688
#define ACPI_CAST_PTR(t, p)
Definition: actypes.h:544
const char * AcpiUtGetObjectTypeName(ACPI_OPERAND_OBJECT *ObjDesc)
Definition: utdecode.c:264
Definition: bufpool.h:45
#define FALSE
Definition: types.h:117
union node Node
Definition: types.h:1255
_Must_inspect_result_ _Inout_opt_ PUNICODE_STRING _Out_opt_ PULONG BufferSizeNeeded
Definition: fltkernel.h:1118
if(dx< 0)
Definition: linetemp.h:194
void * Pointer
Definition: actypes.h:1054
ACPI_SIZE Length
Definition: actypes.h:1053
union acpi_operand_object ** Elements
Definition: acobject.h:161
ACPI_NAMESPACE_NODE * Node
Definition: acobject.h:447
ACPI_OBJECT_COMMON_HEADER UINT8 Class
Definition: acobject.h:443
ACPI_OBJECT_INTEGER Integer
Definition: acobject.h:520
ACPI_OBJECT_REFERENCE Reference
Definition: acobject.h:540
ACPI_OBJECT_COMMON Common
Definition: acobject.h:519
ACPI_OBJECT_PACKAGE Package
Definition: acobject.h:523
ACPI_OBJECT_STRING String
Definition: acobject.h:521
Definition: dlist.c:348
_In_ WDFCOLLECTION _In_ ULONG Index

Referenced by AcpiRsGetPrtMethodData().

◆ AcpiRsCreateResourceList()

ACPI_STATUS AcpiRsCreateResourceList ( ACPI_OPERAND_OBJECT AmlBuffer,
ACPI_BUFFER OutputBuffer 
)

Definition at line 151 of file rscreate.c.

154{
155
157 UINT8 *AmlStart;
158 ACPI_SIZE ListSizeNeeded = 0;
160 void *Resource;
161
162
163 ACPI_FUNCTION_TRACE (RsCreateResourceList);
164
165
166 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "AmlBuffer = %p\n",
167 AmlBuffer));
168
169 /* Params already validated, so we don't re-validate here */
170
171 AmlBufferLength = AmlBuffer->Buffer.Length;
172 AmlStart = AmlBuffer->Buffer.Pointer;
173
174 /*
175 * Pass the AmlBuffer into a module that can calculate
176 * the buffer size needed for the linked list
177 */
179 &ListSizeNeeded);
180
181 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Status=%X ListSizeNeeded=%X\n",
182 Status, (UINT32) ListSizeNeeded));
183 if (ACPI_FAILURE (Status))
184 {
186 }
187
188 /* Validate/Allocate/Clear caller buffer */
189
190 Status = AcpiUtInitializeBuffer (OutputBuffer, ListSizeNeeded);
191 if (ACPI_FAILURE (Status))
192 {
194 }
195
196 /* Do the conversion */
197
198 Resource = OutputBuffer->Pointer;
201 if (ACPI_FAILURE (Status))
202 {
204 }
205
206 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n",
207 OutputBuffer->Pointer, (UINT32) OutputBuffer->Length));
209}
ACPI_OBJECT_BUFFER Buffer
Definition: acobject.h:522

Referenced by AcpiRsGetAeiMethodData(), AcpiRsGetCrsMethodData(), AcpiRsGetMethodData(), and AcpiRsGetPrsMethodData().