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 DBG_DEFAULT_CHANNEL(HWDETECT);
15
16 /* GLOBALS ********************************************************************/
17
18 /* Strings corresponding to CONFIGURATION_TYPE */
19 const PCSTR ArcTypes[MaximumType + 1] = // CmTypeName
20 {
21 "System",
22 "CentralProcessor",
23 "FloatingPointProcessor",
24 "PrimaryICache",
25 "PrimaryDCache",
26 "SecondaryICache",
27 "SecondaryDCache",
28 "SecondaryCache",
29 "EisaAdapter",
30 "TcAdapter",
31 "ScsiAdapter",
32 "DtiAdapter",
33 "MultifunctionAdapter",
34 "DiskController",
35 "TapeController",
36 "CdRomController",
37 "WormController",
38 "SerialController",
39 "NetworkController",
40 "DisplayController",
41 "ParallelController",
42 "PointerController",
43 "KeyboardController",
44 "AudioController",
45 "OtherController",
46 "DiskPeripheral",
47 "FloppyDiskPeripheral",
48 "TapePeripheral",
49 "ModemPeripheral",
50 "MonitorPeripheral",
51 "PrinterPeripheral",
52 "PointerPeripheral",
53 "KeyboardPeripheral",
54 "TerminalPeripheral",
55 "OtherPeripheral",
56 "LinePeripheral",
57 "NetworkPeripheral",
58 "SystemMemory",
59 "DockingInformation",
60 "RealModeIrqRoutingTable",
61 "RealModePCIEnumeration",
62 "Undefined"
63 };
64
65 PCONFIGURATION_COMPONENT_DATA FldrArcHwTreeRoot;
66
67 // ARC Disk Information
68 ULONG reactos_disk_count = 0;
69 ARC_DISK_SIGNATURE_EX reactos_arc_disk_info[32];
70
71 /* FUNCTIONS ******************************************************************/
72
73 #define TAG_HW_COMPONENT_DATA 'DCwH'
74 #define TAG_HW_NAME 'mNwH'
75
76 VOID
AddReactOSArcDiskInfo(IN PSTR ArcName,IN ULONG Signature,IN ULONG Checksum,IN BOOLEAN ValidPartitionTable)77 AddReactOSArcDiskInfo(
78 IN PSTR ArcName,
79 IN ULONG Signature,
80 IN ULONG Checksum,
81 IN BOOLEAN ValidPartitionTable)
82 {
83 ASSERT(reactos_disk_count < sizeof(reactos_arc_disk_info)/sizeof(reactos_arc_disk_info[0]));
84
85 /* Fill out the ARC disk block */
86
87 reactos_arc_disk_info[reactos_disk_count].DiskSignature.Signature = Signature;
88 reactos_arc_disk_info[reactos_disk_count].DiskSignature.CheckSum = Checksum;
89 reactos_arc_disk_info[reactos_disk_count].DiskSignature.ValidPartitionTable = ValidPartitionTable;
90
91 strcpy(reactos_arc_disk_info[reactos_disk_count].ArcName, ArcName);
92 reactos_arc_disk_info[reactos_disk_count].DiskSignature.ArcName =
93 reactos_arc_disk_info[reactos_disk_count].ArcName;
94
95 reactos_disk_count++;
96 }
97
98 //
99 // ARC Component Configuration Routines
100 //
101
102 static VOID
FldrSetIdentifier(_In_ PCONFIGURATION_COMPONENT Component,_In_ PCSTR IdentifierString)103 FldrSetIdentifier(
104 _In_ PCONFIGURATION_COMPONENT Component,
105 _In_ PCSTR IdentifierString)
106 {
107 SIZE_T IdentifierLength;
108 PCHAR Identifier;
109
110 /* Allocate memory for the identifier */
111 IdentifierLength = strlen(IdentifierString) + 1;
112 Identifier = FrLdrHeapAlloc(IdentifierLength, TAG_HW_NAME);
113 if (!Identifier) return;
114
115 /* Copy the identifier */
116 RtlCopyMemory(Identifier, IdentifierString, IdentifierLength);
117
118 /* Set component information */
119 Component->IdentifierLength = (ULONG)IdentifierLength;
120 Component->Identifier = Identifier;
121 }
122
123 VOID
FldrSetConfigurationData(_Inout_ PCONFIGURATION_COMPONENT_DATA ComponentData,_In_ PCM_PARTIAL_RESOURCE_LIST ResourceList,_In_ ULONG Size)124 FldrSetConfigurationData(
125 _Inout_ PCONFIGURATION_COMPONENT_DATA ComponentData,
126 _In_ PCM_PARTIAL_RESOURCE_LIST ResourceList,
127 _In_ ULONG Size)
128 {
129 /* Set component information */
130 ComponentData->ConfigurationData = ResourceList;
131 ComponentData->ComponentEntry.ConfigurationDataLength = Size;
132 }
133
134 VOID
FldrCreateSystemKey(_Out_ PCONFIGURATION_COMPONENT_DATA * SystemNode,_In_ PCSTR IdentifierString)135 FldrCreateSystemKey(
136 _Out_ PCONFIGURATION_COMPONENT_DATA* SystemNode,
137 _In_ PCSTR IdentifierString)
138 {
139 PCONFIGURATION_COMPONENT Component;
140
141 /* Allocate the root */
142 FldrArcHwTreeRoot = FrLdrHeapAlloc(sizeof(CONFIGURATION_COMPONENT_DATA),
143 TAG_HW_COMPONENT_DATA);
144 if (!FldrArcHwTreeRoot) return;
145
146 /* Set it up */
147 Component = &FldrArcHwTreeRoot->ComponentEntry;
148 Component->Class = SystemClass;
149 Component->Type = MaximumType;
150 Component->ConfigurationDataLength = 0;
151 Component->Identifier = 0;
152 Component->IdentifierLength = 0;
153 Component->Flags = 0;
154 Component->Version = 0;
155 Component->Revision = 0;
156 Component->Key = 0;
157 Component->AffinityMask = 0xFFFFFFFF;
158
159 /* Set identifier */
160 if (IdentifierString)
161 FldrSetIdentifier(Component, IdentifierString);
162
163 /* Return the node */
164 *SystemNode = FldrArcHwTreeRoot;
165 }
166
167 static VOID
FldrLinkToParent(_In_ PCONFIGURATION_COMPONENT_DATA Parent,_In_ PCONFIGURATION_COMPONENT_DATA Child)168 FldrLinkToParent(
169 _In_ PCONFIGURATION_COMPONENT_DATA Parent,
170 _In_ PCONFIGURATION_COMPONENT_DATA Child)
171 {
172 PCONFIGURATION_COMPONENT_DATA Sibling;
173
174 /* Get the first sibling */
175 Sibling = Parent->Child;
176
177 /* If no sibling exists, then we are the first child */
178 if (!Sibling)
179 {
180 /* Link us in */
181 Parent->Child = Child;
182 }
183 else
184 {
185 /* Loop each sibling */
186 do
187 {
188 /* This is now the parent */
189 Parent = Sibling;
190 } while ((Sibling = Sibling->Sibling));
191
192 /* Found the lowest sibling; mark us as its sibling too */
193 Parent->Sibling = Child;
194 }
195 }
196
197 VOID
FldrCreateComponentKey(_In_ PCONFIGURATION_COMPONENT_DATA SystemNode,_In_ CONFIGURATION_CLASS Class,_In_ CONFIGURATION_TYPE Type,_In_ IDENTIFIER_FLAG Flags,_In_ ULONG Key,_In_ ULONG Affinity,_In_ PCSTR IdentifierString,_In_ PCM_PARTIAL_RESOURCE_LIST ResourceList,_In_ ULONG Size,_Out_ PCONFIGURATION_COMPONENT_DATA * ComponentKey)198 FldrCreateComponentKey(
199 _In_ PCONFIGURATION_COMPONENT_DATA SystemNode,
200 _In_ CONFIGURATION_CLASS Class,
201 _In_ CONFIGURATION_TYPE Type,
202 _In_ IDENTIFIER_FLAG Flags,
203 _In_ ULONG Key,
204 _In_ ULONG Affinity,
205 _In_ PCSTR IdentifierString,
206 _In_ PCM_PARTIAL_RESOURCE_LIST ResourceList,
207 _In_ ULONG Size,
208 _Out_ PCONFIGURATION_COMPONENT_DATA* ComponentKey)
209 {
210 PCONFIGURATION_COMPONENT_DATA ComponentData;
211 PCONFIGURATION_COMPONENT Component;
212
213 /* Allocate the node for this component */
214 ComponentData = FrLdrHeapAlloc(sizeof(CONFIGURATION_COMPONENT_DATA),
215 TAG_HW_COMPONENT_DATA);
216 if (!ComponentData) return;
217
218 /* Now save our parent */
219 ComponentData->Parent = SystemNode;
220
221 /* Link us to the parent */
222 if (SystemNode)
223 FldrLinkToParent(SystemNode, ComponentData);
224
225 /* Set us up */
226 Component = &ComponentData->ComponentEntry;
227 Component->Class = Class;
228 Component->Type = Type;
229 Component->Flags = Flags;
230 Component->Key = Key;
231 Component->AffinityMask = Affinity;
232
233 /* Set identifier */
234 if (IdentifierString)
235 FldrSetIdentifier(Component, IdentifierString);
236
237 /* Set configuration data */
238 if (ResourceList)
239 FldrSetConfigurationData(ComponentData, ResourceList, Size);
240
241 TRACE("Created key: %s\\%d\n", ArcTypes[min(Type, MaximumType)], Key);
242
243 /* Return the child */
244 *ComponentKey = ComponentData;
245 }
246