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 FldrSetIdentifier(IN PCONFIGURATION_COMPONENT_DATA ComponentData
,
57 IN PCHAR IdentifierString
)
59 ULONG IdentifierLength
;
60 PCONFIGURATION_COMPONENT Component
= &ComponentData
->ComponentEntry
;
63 /* Allocate memory for the identifier */
64 IdentifierLength
= strlen(IdentifierString
) + 1;
65 Identifier
= FldrpHwHeapAlloc(IdentifierLength
);
66 if (!Identifier
) return;
68 /* Copy the identifier */
69 RtlCopyMemory(Identifier
, IdentifierString
, IdentifierLength
);
71 /* Set component information */
72 Component
->IdentifierLength
= IdentifierLength
;
73 Component
->Identifier
= Identifier
;
78 FldrCreateSystemKey(OUT PCONFIGURATION_COMPONENT_DATA
*SystemNode
)
80 PCONFIGURATION_COMPONENT Component
;
82 /* Allocate the root */
83 FldrArcHwTreeRoot
= FldrpHwHeapAlloc(sizeof(CONFIGURATION_COMPONENT_DATA
));
84 if (!FldrArcHwTreeRoot
) return;
87 Component
= &FldrArcHwTreeRoot
->ComponentEntry
;
88 Component
->Class
= SystemClass
;
89 Component
->Type
= MaximumType
;
90 Component
->ConfigurationDataLength
= 0;
91 Component
->Identifier
= 0;
92 Component
->IdentifierLength
= 0;
94 Component
->Version
= 0;
95 Component
->Revision
= 0;
97 Component
->AffinityMask
= 0xFFFFFFFF;
100 *SystemNode
= FldrArcHwTreeRoot
;
105 FldrLinkToParent(IN PCONFIGURATION_COMPONENT_DATA Parent
,
106 IN PCONFIGURATION_COMPONENT_DATA Child
)
108 PCONFIGURATION_COMPONENT_DATA Sibling
;
110 /* Get the first sibling */
111 Sibling
= Parent
->Child
;
113 /* If no sibling exists, then we are the first child */
117 Parent
->Child
= Child
;
121 /* Loop each sibling */
124 /* This is now the parent */
126 } while ((Sibling
= Sibling
->Sibling
));
128 /* Found the lowest sibling; mark us as its sibling too */
129 Parent
->Sibling
= Child
;
135 FldrCreateComponentKey(IN PCONFIGURATION_COMPONENT_DATA SystemNode
,
136 IN CONFIGURATION_CLASS Class
,
137 IN CONFIGURATION_TYPE Type
,
138 IN IDENTIFIER_FLAG Flags
,
141 OUT PCONFIGURATION_COMPONENT_DATA
*ComponentKey
)
143 PCONFIGURATION_COMPONENT_DATA ComponentData
;
144 PCONFIGURATION_COMPONENT Component
;
146 /* Allocate the node for this component */
147 ComponentData
= FldrpHwHeapAlloc(sizeof(CONFIGURATION_COMPONENT_DATA
));
148 if (!ComponentData
) return;
150 /* Now save our parent */
151 ComponentData
->Parent
= SystemNode
;
153 /* Link us to the parent */
154 FldrLinkToParent(SystemNode
, ComponentData
);
157 Component
= &ComponentData
->ComponentEntry
;
158 Component
->Class
= Class
;
159 Component
->Type
= Type
;
161 /* Return the child */
162 *ComponentKey
= ComponentData
;
167 FldrSetConfigurationData(IN PCONFIGURATION_COMPONENT_DATA ComponentData
,
168 IN PCM_PARTIAL_RESOURCE_LIST ResourceList
,
171 PCONFIGURATION_COMPONENT Component
= &ComponentData
->ComponentEntry
;
172 PVOID ConfigurationData
;
174 /* Allocate a buffer from the hardware heap */
175 ConfigurationData
= FldrpHwHeapAlloc(Size
);
176 if (!ConfigurationData
) return;
178 /* Copy component information */
179 RtlCopyMemory(ConfigurationData
, ResourceList
, Size
);
181 /* Set component information */
182 ComponentData
->ConfigurationData
= ConfigurationData
;
183 Component
->ConfigurationDataLength
= Size
;