[SETUPLIB] Add two hacks in partlist.c for temporarily setting consistently the disk...
[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 AddReactOSArcDiskInfo(
30 IN PSTR ArcName,
31 IN ULONG Signature,
32 IN ULONG Checksum,
33 IN BOOLEAN ValidPartitionTable)
34 {
35 ASSERT(reactos_disk_count < sizeof(reactos_arc_disk_info)/sizeof(reactos_arc_disk_info[0]));
36
37 /* Fill out the ARC disk block */
38
39 reactos_arc_disk_info[reactos_disk_count].DiskSignature.Signature = Signature;
40 reactos_arc_disk_info[reactos_disk_count].DiskSignature.CheckSum = Checksum;
41 reactos_arc_disk_info[reactos_disk_count].DiskSignature.ValidPartitionTable = ValidPartitionTable;
42
43 strcpy(reactos_arc_disk_info[reactos_disk_count].ArcName, ArcName);
44 reactos_arc_disk_info[reactos_disk_count].DiskSignature.ArcName =
45 reactos_arc_disk_info[reactos_disk_count].ArcName;
46
47 reactos_disk_count++;
48 }
49
50 //
51 // ARC Component Configuration Routines
52 //
53
54 VOID
55 NTAPI
56 FldrSetIdentifier(IN PCONFIGURATION_COMPONENT_DATA ComponentData,
57 IN PCHAR IdentifierString)
58 {
59 PCONFIGURATION_COMPONENT Component = &ComponentData->ComponentEntry;
60 SIZE_T IdentifierLength;
61 PCHAR Identifier;
62
63 /* Allocate memory for the identifier */
64 IdentifierLength = strlen(IdentifierString) + 1;
65 Identifier = FrLdrHeapAlloc(IdentifierLength, TAG_HW_NAME);
66 if (!Identifier) return;
67
68 /* Copy the identifier */
69 RtlCopyMemory(Identifier, IdentifierString, IdentifierLength);
70
71 /* Set component information */
72 Component->IdentifierLength = (ULONG)IdentifierLength;
73 Component->Identifier = Identifier;
74 }
75
76 VOID
77 NTAPI
78 FldrSetConfigurationData(IN PCONFIGURATION_COMPONENT_DATA ComponentData,
79 IN PCM_PARTIAL_RESOURCE_LIST ResourceList,
80 IN ULONG Size)
81 {
82 /* Set component information */
83 ComponentData->ConfigurationData = ResourceList;
84 ComponentData->ComponentEntry.ConfigurationDataLength = Size;
85 }
86
87 VOID
88 NTAPI
89 FldrCreateSystemKey(OUT PCONFIGURATION_COMPONENT_DATA *SystemNode)
90 {
91 PCONFIGURATION_COMPONENT Component;
92
93 /* Allocate the root */
94 FldrArcHwTreeRoot = FrLdrHeapAlloc(sizeof(CONFIGURATION_COMPONENT_DATA),
95 TAG_HW_COMPONENT_DATA);
96 if (!FldrArcHwTreeRoot) return;
97
98 /* Set it up */
99 Component = &FldrArcHwTreeRoot->ComponentEntry;
100 Component->Class = SystemClass;
101 Component->Type = MaximumType;
102 Component->ConfigurationDataLength = 0;
103 Component->Identifier = 0;
104 Component->IdentifierLength = 0;
105 Component->Flags = 0;
106 Component->Version = 0;
107 Component->Revision = 0;
108 Component->Key = 0;
109 Component->AffinityMask = 0xFFFFFFFF;
110
111 /* Return the node */
112 *SystemNode = FldrArcHwTreeRoot;
113 }
114
115 static VOID
116 NTAPI
117 FldrLinkToParent(IN PCONFIGURATION_COMPONENT_DATA Parent,
118 IN PCONFIGURATION_COMPONENT_DATA Child)
119 {
120 PCONFIGURATION_COMPONENT_DATA Sibling;
121
122 /* Get the first sibling */
123 Sibling = Parent->Child;
124
125 /* If no sibling exists, then we are the first child */
126 if (!Sibling)
127 {
128 /* Link us in */
129 Parent->Child = Child;
130 }
131 else
132 {
133 /* Loop each sibling */
134 do
135 {
136 /* This is now the parent */
137 Parent = Sibling;
138 } while ((Sibling = Sibling->Sibling));
139
140 /* Found the lowest sibling; mark us as its sibling too */
141 Parent->Sibling = Child;
142 }
143 }
144
145 VOID
146 NTAPI
147 FldrCreateComponentKey(IN PCONFIGURATION_COMPONENT_DATA SystemNode,
148 IN CONFIGURATION_CLASS Class,
149 IN CONFIGURATION_TYPE Type,
150 IN IDENTIFIER_FLAG Flags,
151 IN ULONG Key,
152 IN ULONG Affinity,
153 IN PCHAR IdentifierString,
154 IN PCM_PARTIAL_RESOURCE_LIST ResourceList,
155 IN ULONG Size,
156 OUT PCONFIGURATION_COMPONENT_DATA *ComponentKey)
157 {
158 PCONFIGURATION_COMPONENT_DATA ComponentData;
159 PCONFIGURATION_COMPONENT Component;
160
161 /* Allocate the node for this component */
162 ComponentData = FrLdrHeapAlloc(sizeof(CONFIGURATION_COMPONENT_DATA),
163 TAG_HW_COMPONENT_DATA);
164 if (!ComponentData) return;
165
166 /* Now save our parent */
167 ComponentData->Parent = SystemNode;
168
169 /* Link us to the parent */
170 if (SystemNode)
171 FldrLinkToParent(SystemNode, ComponentData);
172
173 /* Set us up */
174 Component = &ComponentData->ComponentEntry;
175 Component->Class = Class;
176 Component->Type = Type;
177 Component->Flags = Flags;
178 Component->Key = Key;
179 Component->AffinityMask = Affinity;
180
181 /* Set identifier */
182 if (IdentifierString)
183 FldrSetIdentifier(ComponentData, IdentifierString);
184
185 /* Set configuration data */
186 if (ResourceList)
187 FldrSetConfigurationData(ComponentData, ResourceList, Size);
188
189 /* Return the child */
190 *ComponentKey = ComponentData;
191 }