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 extern CHAR reactos_arc_hardware_data
[];
18 ULONG FldrpHwHeapLocation
;
19 PCONFIGURATION_COMPONENT_DATA FldrArcHwTreeRoot
;
21 BOOLEAN UseRealHeap
= FALSE
;
23 /* FUNCTIONS ******************************************************************/
27 FldrpHwHeapAlloc(IN ULONG Size
)
33 /* Allocate memory from generic bootloader heap */
34 Buffer
= MmHeapAlloc(Size
);
38 /* Return a block of memory from the ARC Hardware Heap */
39 Buffer
= &reactos_arc_hardware_data
[FldrpHwHeapLocation
];
41 /* Increment the heap location */
42 FldrpHwHeapLocation
+= Size
;
43 if (FldrpHwHeapLocation
> HW_MAX_ARC_HEAP_SIZE
) Buffer
= NULL
;
48 RtlZeroMemory(Buffer
, Size
);
50 /* Return the buffer */
56 FldrSetComponentInformation(IN PCONFIGURATION_COMPONENT_DATA ComponentData
,
57 IN IDENTIFIER_FLAG Flags
,
61 PCONFIGURATION_COMPONENT Component
= &ComponentData
->ComponentEntry
;
63 /* Set component information */
64 Component
->Flags
= Flags
;
65 Component
->Version
= 0;
66 Component
->Revision
= 0;
68 Component
->AffinityMask
= Affinity
;
73 FldrSetIdentifier(IN PCONFIGURATION_COMPONENT_DATA ComponentData
,
74 IN PCHAR IdentifierString
)
76 ULONG IdentifierLength
;
77 PCONFIGURATION_COMPONENT Component
= &ComponentData
->ComponentEntry
;
80 /* Allocate memory for the identifier */
81 IdentifierLength
= strlen(IdentifierString
) + 1;
82 Identifier
= FldrpHwHeapAlloc(IdentifierLength
);
83 if (!Identifier
) return;
85 /* Copy the identifier */
86 RtlCopyMemory(Identifier
, IdentifierString
, IdentifierLength
);
88 /* Set component information */
89 Component
->IdentifierLength
= IdentifierLength
;
90 Component
->Identifier
= Identifier
;
95 FldrCreateSystemKey(OUT PCONFIGURATION_COMPONENT_DATA
*SystemNode
)
97 PCONFIGURATION_COMPONENT Component
;
99 /* Allocate the root */
100 FldrArcHwTreeRoot
= FldrpHwHeapAlloc(sizeof(CONFIGURATION_COMPONENT_DATA
));
101 if (!FldrArcHwTreeRoot
) return;
104 Component
= &FldrArcHwTreeRoot
->ComponentEntry
;
105 Component
->Class
= SystemClass
;
106 Component
->Type
= MaximumType
;
107 Component
->ConfigurationDataLength
= 0;
108 Component
->Identifier
= 0;
109 Component
->IdentifierLength
= 0;
111 /* Return the node */
112 *SystemNode
= FldrArcHwTreeRoot
;
117 FldrLinkToParent(IN PCONFIGURATION_COMPONENT_DATA Parent
,
118 IN PCONFIGURATION_COMPONENT_DATA Child
)
120 PCONFIGURATION_COMPONENT_DATA Sibling
;
122 /* Get the first sibling */
123 Sibling
= Parent
->Child
;
125 /* If no sibling exists, then we are the first child */
129 Parent
->Child
= Child
;
133 /* Loop each sibling */
136 /* This is now the parent */
138 } while ((Sibling
= Sibling
->Sibling
));
140 /* Found the lowest sibling; mark us as its sibling too */
141 Parent
->Sibling
= Child
;
147 FldrCreateComponentKey(IN PCONFIGURATION_COMPONENT_DATA SystemNode
,
150 IN CONFIGURATION_CLASS Class
,
151 IN CONFIGURATION_TYPE Type
,
152 OUT PCONFIGURATION_COMPONENT_DATA
*ComponentKey
)
154 PCONFIGURATION_COMPONENT_DATA ComponentData
;
155 PCONFIGURATION_COMPONENT Component
;
157 /* Allocate the node for this component */
158 ComponentData
= FldrpHwHeapAlloc(sizeof(CONFIGURATION_COMPONENT_DATA
));
159 if (!ComponentData
) return;
161 /* Now save our parent */
162 ComponentData
->Parent
= SystemNode
;
164 /* Link us to the parent */
165 FldrLinkToParent(SystemNode
, ComponentData
);
168 Component
= &ComponentData
->ComponentEntry
;
169 Component
->Class
= Class
;
170 Component
->Type
= Type
;
172 /* Return the child */
173 *ComponentKey
= ComponentData
;
178 FldrSetConfigurationData(IN PCONFIGURATION_COMPONENT_DATA ComponentData
,
179 IN PCM_PARTIAL_RESOURCE_LIST ResourceList
,
182 PCONFIGURATION_COMPONENT Component
= &ComponentData
->ComponentEntry
;
183 PVOID ConfigurationData
;
185 /* Allocate a buffer from the hardware heap */
186 ConfigurationData
= FldrpHwHeapAlloc(Size
);
187 if (!ConfigurationData
) return;
189 /* Copy component information */
190 RtlCopyMemory(ConfigurationData
, ResourceList
, Size
);
192 /* Set component information */
193 ComponentData
->ConfigurationData
= ConfigurationData
;
194 Component
->ConfigurationDataLength
= Size
;