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