Synchronize with trunk r58457.
[reactos.git] / boot / freeldr / freeldr / reactos / archwsup.c
1 /*
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)
7 */
8
9 /* INCLUDES *******************************************************************/
10
11 #include <freeldr.h>
12 #define NDEBUG
13 #include <debug.h>
14
15 /* GLOBALS ********************************************************************/
16
17 PCONFIGURATION_COMPONENT_DATA FldrArcHwTreeRoot;
18
19 /* FUNCTIONS ******************************************************************/
20
21 PVOID
22 NTAPI
23 FldrpHwHeapAlloc(IN SIZE_T Size)
24 {
25 PVOID Buffer;
26
27 /* Allocate memory from generic bootloader heap */
28 Buffer = MmHeapAlloc(Size);
29 return Buffer;
30 }
31
32 VOID
33 NTAPI
34 FldrSetIdentifier(IN PCONFIGURATION_COMPONENT_DATA ComponentData,
35 IN PCHAR IdentifierString)
36 {
37 SIZE_T IdentifierLength;
38 PCONFIGURATION_COMPONENT Component = &ComponentData->ComponentEntry;
39 PCHAR Identifier;
40
41 /* Allocate memory for the identifier */
42 IdentifierLength = strlen(IdentifierString) + 1;
43 Identifier = MmHeapAlloc(IdentifierLength);
44 if (!Identifier) return;
45
46 /* Copy the identifier */
47 RtlCopyMemory(Identifier, IdentifierString, IdentifierLength);
48
49 /* Set component information */
50 Component->IdentifierLength = (ULONG)IdentifierLength;
51 Component->Identifier = Identifier;
52 }
53
54 VOID
55 NTAPI
56 FldrCreateSystemKey(OUT PCONFIGURATION_COMPONENT_DATA *SystemNode)
57 {
58 PCONFIGURATION_COMPONENT Component;
59
60 /* Allocate the root */
61 FldrArcHwTreeRoot = MmHeapAlloc(sizeof(CONFIGURATION_COMPONENT_DATA));
62 if (!FldrArcHwTreeRoot) return;
63
64 /* Set it up */
65 Component = &FldrArcHwTreeRoot->ComponentEntry;
66 Component->Class = SystemClass;
67 Component->Type = MaximumType;
68 Component->ConfigurationDataLength = 0;
69 Component->Identifier = 0;
70 Component->IdentifierLength = 0;
71 Component->Flags = 0;
72 Component->Version = 0;
73 Component->Revision = 0;
74 Component->Key = 0;
75 Component->AffinityMask = 0xFFFFFFFF;
76
77 /* Return the node */
78 *SystemNode = FldrArcHwTreeRoot;
79 }
80
81 VOID
82 NTAPI
83 FldrLinkToParent(IN PCONFIGURATION_COMPONENT_DATA Parent,
84 IN PCONFIGURATION_COMPONENT_DATA Child)
85 {
86 PCONFIGURATION_COMPONENT_DATA Sibling;
87
88 /* Get the first sibling */
89 Sibling = Parent->Child;
90
91 /* If no sibling exists, then we are the first child */
92 if (!Sibling)
93 {
94 /* Link us in */
95 Parent->Child = Child;
96 }
97 else
98 {
99 /* Loop each sibling */
100 do
101 {
102 /* This is now the parent */
103 Parent = Sibling;
104 } while ((Sibling = Sibling->Sibling));
105
106 /* Found the lowest sibling; mark us as its sibling too */
107 Parent->Sibling = Child;
108 }
109 }
110
111 VOID
112 NTAPI
113 FldrCreateComponentKey(IN PCONFIGURATION_COMPONENT_DATA SystemNode,
114 IN CONFIGURATION_CLASS Class,
115 IN CONFIGURATION_TYPE Type,
116 IN IDENTIFIER_FLAG Flags,
117 IN ULONG Key,
118 IN ULONG Affinity,
119 IN PCHAR IdentifierString,
120 IN PCM_PARTIAL_RESOURCE_LIST ResourceList,
121 IN ULONG Size,
122 OUT PCONFIGURATION_COMPONENT_DATA *ComponentKey)
123 {
124 PCONFIGURATION_COMPONENT_DATA ComponentData;
125 PCONFIGURATION_COMPONENT Component;
126
127 /* Allocate the node for this component */
128 ComponentData = MmHeapAlloc(sizeof(CONFIGURATION_COMPONENT_DATA));
129 if (!ComponentData) return;
130
131 /* Now save our parent */
132 ComponentData->Parent = SystemNode;
133
134 /* Link us to the parent */
135 if (SystemNode)
136 FldrLinkToParent(SystemNode, ComponentData);
137
138 /* Set us up */
139 Component = &ComponentData->ComponentEntry;
140 Component->Class = Class;
141 Component->Type = Type;
142 Component->Flags = Flags;
143 Component->Key = Key;
144 Component->AffinityMask = Affinity;
145
146 /* Set identifier */
147 if (IdentifierString)
148 FldrSetIdentifier(ComponentData, IdentifierString);
149
150 /* Set configuration data */
151 if (ResourceList)
152 {
153 ComponentData->ConfigurationData = ResourceList;
154 ComponentData->ComponentEntry.ConfigurationDataLength = Size;
155 }
156
157 /* Return the child */
158 *ComponentKey = ComponentData;
159 }
160