2 * PROJECT: ReactOS Boot Loader (FreeLDR)
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: boot/freeldr/freeldr/reactos/archwsup.c
5 * PURPOSE: Routines for ARC Hardware Tree and Configuration Data
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
9 /* INCLUDES *******************************************************************/
15 /* GLOBALS ********************************************************************/
17 PCONFIGURATION_COMPONENT_DATA FldrArcHwTreeRoot
;
19 /* FUNCTIONS ******************************************************************/
21 #define TAG_HW_COMPONENT_DATA 'DCwH'
22 #define TAG_HW_NAME 'mNwH'
26 FldrpHwHeapAlloc(IN SIZE_T Size
)
30 /* Allocate memory from generic bootloader heap */
31 Buffer
= FrLdrHeapAlloc(Size
, 'pHwH');
37 FldrSetIdentifier(IN PCONFIGURATION_COMPONENT_DATA ComponentData
,
38 IN PCHAR IdentifierString
)
40 SIZE_T IdentifierLength
;
41 PCONFIGURATION_COMPONENT Component
= &ComponentData
->ComponentEntry
;
44 /* Allocate memory for the identifier */
45 IdentifierLength
= strlen(IdentifierString
) + 1;
46 Identifier
= FrLdrHeapAlloc(IdentifierLength
, TAG_HW_NAME
);
47 if (!Identifier
) return;
49 /* Copy the identifier */
50 RtlCopyMemory(Identifier
, IdentifierString
, IdentifierLength
);
52 /* Set component information */
53 Component
->IdentifierLength
= (ULONG
)IdentifierLength
;
54 Component
->Identifier
= Identifier
;
59 FldrCreateSystemKey(OUT PCONFIGURATION_COMPONENT_DATA
*SystemNode
)
61 PCONFIGURATION_COMPONENT Component
;
63 /* Allocate the root */
64 FldrArcHwTreeRoot
= FrLdrHeapAlloc(sizeof(CONFIGURATION_COMPONENT_DATA
),
65 TAG_HW_COMPONENT_DATA
);
66 if (!FldrArcHwTreeRoot
) return;
69 Component
= &FldrArcHwTreeRoot
->ComponentEntry
;
70 Component
->Class
= SystemClass
;
71 Component
->Type
= MaximumType
;
72 Component
->ConfigurationDataLength
= 0;
73 Component
->Identifier
= 0;
74 Component
->IdentifierLength
= 0;
76 Component
->Version
= 0;
77 Component
->Revision
= 0;
79 Component
->AffinityMask
= 0xFFFFFFFF;
82 *SystemNode
= FldrArcHwTreeRoot
;
87 FldrLinkToParent(IN PCONFIGURATION_COMPONENT_DATA Parent
,
88 IN PCONFIGURATION_COMPONENT_DATA Child
)
90 PCONFIGURATION_COMPONENT_DATA Sibling
;
92 /* Get the first sibling */
93 Sibling
= Parent
->Child
;
95 /* If no sibling exists, then we are the first child */
99 Parent
->Child
= Child
;
103 /* Loop each sibling */
106 /* This is now the parent */
108 } while ((Sibling
= Sibling
->Sibling
));
110 /* Found the lowest sibling; mark us as its sibling too */
111 Parent
->Sibling
= Child
;
117 FldrCreateComponentKey(IN PCONFIGURATION_COMPONENT_DATA SystemNode
,
118 IN CONFIGURATION_CLASS Class
,
119 IN CONFIGURATION_TYPE Type
,
120 IN IDENTIFIER_FLAG Flags
,
123 IN PCHAR IdentifierString
,
124 IN PCM_PARTIAL_RESOURCE_LIST ResourceList
,
126 OUT PCONFIGURATION_COMPONENT_DATA
*ComponentKey
)
128 PCONFIGURATION_COMPONENT_DATA ComponentData
;
129 PCONFIGURATION_COMPONENT Component
;
131 /* Allocate the node for this component */
132 ComponentData
= FrLdrHeapAlloc(sizeof(CONFIGURATION_COMPONENT_DATA
),
133 TAG_HW_COMPONENT_DATA
);
134 if (!ComponentData
) return;
136 /* Now save our parent */
137 ComponentData
->Parent
= SystemNode
;
139 /* Link us to the parent */
141 FldrLinkToParent(SystemNode
, ComponentData
);
144 Component
= &ComponentData
->ComponentEntry
;
145 Component
->Class
= Class
;
146 Component
->Type
= Type
;
147 Component
->Flags
= Flags
;
148 Component
->Key
= Key
;
149 Component
->AffinityMask
= Affinity
;
152 if (IdentifierString
)
153 FldrSetIdentifier(ComponentData
, IdentifierString
);
155 /* Set configuration data */
158 ComponentData
->ConfigurationData
= ResourceList
;
159 ComponentData
->ComponentEntry
.ConfigurationDataLength
= Size
;
162 /* Return the child */
163 *ComponentKey
= ComponentData
;