[FREELDR] Simplify code by using a AddReactOSArcDiskInfo() helper, and few extra...
[reactos.git] / boot / freeldr / freeldr / arch / arm / macharm.c
1 /*
2 * PROJECT: ReactOS Boot Loader
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: boot/freeldr/freeldr/arch/arm/macharm.c
5 * PURPOSE: Provides abstraction between the ARM Boot Loader and FreeLDR
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9 /* INCLUDES *******************************************************************/
10
11 #include <freeldr.h>
12 #include <internal/arm/intrin_i.h>
13
14 /* GLOBALS ********************************************************************/
15
16 PARM_BOARD_CONFIGURATION_BLOCK ArmBoardBlock;
17 ULONG gDiskReadBuffer, gFileSysBuffer;
18 BOOLEAN ArmHwDetectRan;
19 PCONFIGURATION_COMPONENT_DATA RootNode;
20
21 BOOLEAN AcpiPresent = FALSE;
22
23 ULONG FirstLevelDcacheSize;
24 ULONG FirstLevelDcacheFillSize;
25 ULONG FirstLevelIcacheSize;
26 ULONG FirstLevelIcacheFillSize;
27 ULONG SecondLevelDcacheSize;
28 ULONG SecondLevelDcacheFillSize;
29 ULONG SecondLevelIcacheSize;
30 ULONG SecondLevelIcacheFillSize;
31
32 extern ULONG reactos_disk_count;
33
34 ULONG SizeBits[] =
35 {
36 -1, // INVALID
37 -1, // INVALID
38 1 << 12, // 4KB
39 1 << 13, // 8KB
40 1 << 14, // 16KB
41 1 << 15, // 32KB
42 1 << 16, // 64KB
43 1 << 17 // 128KB
44 };
45
46 ULONG AssocBits[] =
47 {
48 -1, // INVALID
49 -1, // INVALID
50 4 // 4-way associative
51 };
52
53 ULONG LenBits[] =
54 {
55 -1, // INVALID
56 -1, // INVALID
57 8 // 8 words per line (32 bytes)
58 };
59
60 /* FUNCTIONS ******************************************************************/
61
62 VOID DiskStopFloppyMotor(VOID)
63 {
64 }
65
66 VOID
67 FrLdrCheckCpuCompatibility(VOID)
68 {
69 /* Nothing for now */
70 }
71
72 VOID
73 ArmInit(IN PARM_BOARD_CONFIGURATION_BLOCK BootContext)
74 {
75 /* Remember the pointer */
76 ArmBoardBlock = BootContext;
77
78 /* Let's make sure we understand the LLB */
79 ASSERT(ArmBoardBlock->MajorVersion == ARM_BOARD_CONFIGURATION_MAJOR_VERSION);
80 ASSERT(ArmBoardBlock->MinorVersion == ARM_BOARD_CONFIGURATION_MINOR_VERSION);
81
82 /* This should probably go away once we support more boards */
83 ASSERT((ArmBoardBlock->BoardType == MACH_TYPE_FEROCEON) ||
84 (ArmBoardBlock->BoardType == MACH_TYPE_VERSATILE_PB) ||
85 (ArmBoardBlock->BoardType == MACH_TYPE_OMAP3_BEAGLE) ||
86 (ArmBoardBlock->BoardType == MACH_TYPE_OMAP_ZOOM2));
87
88 /* Call FreeLDR's portable entrypoint with our command-line */
89 BootMain(ArmBoardBlock->CommandLine);
90 }
91
92 VOID
93 ArmPrepareForReactOS(IN BOOLEAN Setup)
94 {
95 return;
96 }
97
98 BOOLEAN
99 ArmDiskGetBootPath(OUT PCHAR BootPath, IN ULONG Size)
100 {
101 PCCH Path = "ramdisk(0)";
102
103 /* Make sure enough space exists */
104 if (Size < sizeof(Path)) return FALSE;
105
106 /* On ARM platforms, the loader is always in RAM */
107 strcpy(BootPath, Path);
108 return TRUE;
109 }
110
111 PCONFIGURATION_COMPONENT_DATA
112 ArmHwDetect(VOID)
113 {
114 ARM_CACHE_REGISTER CacheReg;
115
116 /* Create the root node */
117 if (ArmHwDetectRan++) return RootNode;
118 FldrCreateSystemKey(&RootNode);
119
120 /*
121 * TODO:
122 * There's no such thing as "PnP" on embedded hardware.
123 * The boot loader will send us a device tree, similar to ACPI
124 * or OpenFirmware device trees, and we will convert it to ARC.
125 */
126
127 /* Get cache information */
128 CacheReg = KeArmCacheRegisterGet();
129 FirstLevelDcacheSize = SizeBits[CacheReg.DSize];
130 FirstLevelDcacheFillSize = LenBits[CacheReg.DLength];
131 FirstLevelDcacheFillSize <<= 2;
132 FirstLevelIcacheSize = SizeBits[CacheReg.ISize];
133 FirstLevelIcacheFillSize = LenBits[CacheReg.ILength];
134 FirstLevelIcacheFillSize <<= 2;
135 SecondLevelDcacheSize =
136 SecondLevelDcacheFillSize =
137 SecondLevelIcacheSize =
138 SecondLevelIcacheFillSize = 0;
139
140 /* Register RAMDISK Device */
141 RamDiskInitialize();
142
143 /* Fill out the ARC disk block */
144 AddReactOSArcDiskInfo("ramdisk(0)", 0xBADAB00F, 0xDEADBABE, TRUE);
145 ASSERT(reactos_disk_count == 1);
146
147 /* Return the root node */
148 return RootNode;
149 }
150
151 BOOLEAN
152 ArmInitializeBootDevices(VOID)
153 {
154 /* Emulate old behavior */
155 return (ArmHwDetect() != NULL);
156 }
157
158 FREELDR_MEMORY_DESCRIPTOR ArmMemoryMap[32];
159
160 PFREELDR_MEMORY_DESCRIPTOR
161 ArmMemGetMemoryMap(OUT ULONG *MemoryMapSize)
162 {
163 ULONG i;
164 ASSERT(ArmBoardBlock->MemoryMapEntryCount <= 32);
165
166 /* Return whatever the board returned to us (CS0 Base + Size and FLASH0) */
167 for (i = 0; i < ArmBoardBlock->MemoryMapEntryCount; i++)
168 {
169 ArmMemoryMap[i].BasePage = ArmBoardBlock->MemoryMap[i].BaseAddress / PAGE_SIZE;
170 ArmMemoryMap[i].PageCount = ArmBoardBlock->MemoryMap[i].Length / PAGE_SIZE;
171 if (ArmBoardBlock->MemoryMap[i].Type == BiosMemoryUsable)
172 ArmMemoryMap[i].MemoryType = MemoryFree;
173 else
174 ArmMemoryMap[i].MemoryType = MemoryFirmwarePermanent;
175 }
176
177 *MemoryMapSize = ArmBoardBlock->MemoryMapEntryCount;
178
179 // FIXME
180 return NULL;
181 }
182
183 VOID
184 ArmHwIdle(VOID)
185 {
186 /* UNIMPLEMENTED */
187 }
188
189 VOID
190 MachInit(IN PCCH CommandLine)
191 {
192 /* Copy Machine Routines from Firmware Table */
193 MachVtbl.ConsPutChar = ArmBoardBlock->ConsPutChar;
194 MachVtbl.ConsKbHit = ArmBoardBlock->ConsKbHit;
195 MachVtbl.ConsGetCh = ArmBoardBlock->ConsGetCh;
196 MachVtbl.VideoClearScreen = ArmBoardBlock->VideoClearScreen;
197 MachVtbl.VideoSetDisplayMode = ArmBoardBlock->VideoSetDisplayMode;
198 MachVtbl.VideoGetDisplaySize = ArmBoardBlock->VideoGetDisplaySize;
199 MachVtbl.VideoPutChar = ArmBoardBlock->VideoPutChar;
200 MachVtbl.GetTime = ArmBoardBlock->GetTime;
201
202 /* Setup board-specific ARM routines */
203 switch (ArmBoardBlock->BoardType)
204 {
205 /* Check for Feroceon-base boards */
206 case MACH_TYPE_FEROCEON:
207 TuiPrintf("Not implemented\n");
208 while (TRUE);
209 break;
210
211 /* Check for TI OMAP3 ZOOM-II MDK */
212 case MACH_TYPE_OMAP_ZOOM2:
213
214 /* Setup the disk and file system buffers */
215 gDiskReadBuffer = 0x81094000;
216 gFileSysBuffer = 0x81094000;
217 break;
218
219 /* Check for ARM Versatile PB boards */
220 case MACH_TYPE_VERSATILE_PB:
221
222 /* Setup the disk and file system buffers */
223 gDiskReadBuffer = 0x00090000;
224 gFileSysBuffer = 0x00090000;
225 break;
226
227 /* Check for TI OMAP3 Beagleboard */
228 case MACH_TYPE_OMAP3_BEAGLE:
229 TuiPrintf("Not implemented\n");
230 while (TRUE);
231 break;
232
233 default:
234 ASSERT(FALSE);
235 }
236
237 /* Setup generic ARM routines for all boards */
238 MachVtbl.PrepareForReactOS = ArmPrepareForReactOS;
239 MachVtbl.GetMemoryMap = ArmMemGetMemoryMap;
240 MachVtbl.InitializeBootDevices = ArmInitializeBootDevices;
241 MachVtbl.HwDetect = ArmHwDetect;
242 MachVtbl.DiskGetBootPath = ArmDiskGetBootPath;
243 MachVtbl.HwIdle = ArmHwIdle;
244 }