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