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