139f5719251505c1605034a1a2af89ed9c85dbed
[reactos.git] / boot / freeldr / freeldr / arch / i386 / machxbox.c
1 /*
2 * FreeLoader
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #include <freeldr.h>
20
21 #include <debug.h>
22
23 DBG_DEFAULT_CHANNEL(HWDETECT);
24
25
26 VOID
27 XboxGetExtendedBIOSData(PULONG ExtendedBIOSDataArea, PULONG ExtendedBIOSDataSize)
28 {
29 TRACE("XboxGetExtendedBIOSData(): UNIMPLEMENTED\n");
30 *ExtendedBIOSDataArea = 0;
31 *ExtendedBIOSDataSize = 0;
32 }
33
34 // NOTE: Similar to machpc.c!PcGetHarddiskConfigurationData(),
35 // but without extended geometry support.
36 static
37 PCM_PARTIAL_RESOURCE_LIST
38 XboxGetHarddiskConfigurationData(UCHAR DriveNumber, ULONG* pSize)
39 {
40 PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
41 PCM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry;
42 //EXTENDED_GEOMETRY ExtGeometry;
43 GEOMETRY Geometry;
44 ULONG Size;
45
46 //
47 // Initialize returned size
48 //
49 *pSize = 0;
50
51 /* Set 'Configuration Data' value */
52 Size = sizeof(CM_PARTIAL_RESOURCE_LIST) +
53 sizeof(CM_DISK_GEOMETRY_DEVICE_DATA);
54 PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
55 if (PartialResourceList == NULL)
56 {
57 ERR("Failed to allocate a full resource descriptor\n");
58 return NULL;
59 }
60
61 memset(PartialResourceList, 0, Size);
62 PartialResourceList->Version = 1;
63 PartialResourceList->Revision = 1;
64 PartialResourceList->Count = 1;
65 PartialResourceList->PartialDescriptors[0].Type =
66 CmResourceTypeDeviceSpecific;
67 // PartialResourceList->PartialDescriptors[0].ShareDisposition =
68 // PartialResourceList->PartialDescriptors[0].Flags =
69 PartialResourceList->PartialDescriptors[0].u.DeviceSpecificData.DataSize =
70 sizeof(CM_DISK_GEOMETRY_DEVICE_DATA);
71
72 /* Get pointer to geometry data */
73 DiskGeometry = (PVOID)(((ULONG_PTR)PartialResourceList) + sizeof(CM_PARTIAL_RESOURCE_LIST));
74
75 /* Get the disk geometry */
76 //ExtGeometry.Size = sizeof(EXTENDED_GEOMETRY);
77
78 if (MachDiskGetDriveGeometry(DriveNumber, &Geometry))
79 {
80 DiskGeometry->BytesPerSector = Geometry.BytesPerSector;
81 DiskGeometry->NumberOfCylinders = Geometry.Cylinders;
82 DiskGeometry->SectorsPerTrack = Geometry.Sectors;
83 DiskGeometry->NumberOfHeads = Geometry.Heads;
84 }
85 else
86 {
87 ERR("Reading disk geometry failed\n");
88 FrLdrHeapFree(PartialResourceList, TAG_HW_RESOURCE_LIST);
89 return NULL;
90 }
91 TRACE("Disk %x: %u Cylinders %u Heads %u Sectors %u Bytes\n",
92 DriveNumber,
93 DiskGeometry->NumberOfCylinders,
94 DiskGeometry->NumberOfHeads,
95 DiskGeometry->SectorsPerTrack,
96 DiskGeometry->BytesPerSector);
97
98 //
99 // Return configuration data
100 //
101 *pSize = Size;
102 return PartialResourceList;
103 }
104
105 static
106 VOID
107 DetectIsaBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
108 {
109 PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
110 PCONFIGURATION_COMPONENT_DATA BusKey;
111 ULONG Size;
112
113 /* Set 'Configuration Data' value */
114 Size = sizeof(CM_PARTIAL_RESOURCE_LIST) -
115 sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
116 PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
117 if (PartialResourceList == NULL)
118 {
119 TRACE("Failed to allocate resource descriptor\n");
120 return;
121 }
122
123 /* Initialize resource descriptor */
124 memset(PartialResourceList, 0, Size);
125 PartialResourceList->Version = 1;
126 PartialResourceList->Revision = 1;
127 PartialResourceList->Count = 0;
128
129 /* Create new bus key */
130 FldrCreateComponentKey(SystemKey,
131 AdapterClass,
132 MultiFunctionAdapter,
133 0x0,
134 0x0,
135 0xFFFFFFFF,
136 "ISA",
137 PartialResourceList,
138 Size,
139 &BusKey);
140
141 /* Increment bus number */
142 (*BusNumber)++;
143
144 /* Detect ISA/BIOS devices */
145 DetectBiosDisks(SystemKey, BusKey);
146
147 /* FIXME: Detect more ISA devices */
148 }
149
150 static
151 UCHAR
152 XboxGetFloppyCount(VOID)
153 {
154 /* On a PC we use CMOS/RTC I/O ports 0x70 and 0x71 to detect floppies.
155 * However an Xbox CMOS memory range [0x10, 0x70) and [0x80, 0x100)
156 * is filled with 0x55 0xAA 0x55 0xAA ... byte pattern which is used
157 * to validate the date/time settings by Xbox OS.
158 *
159 * Technically it's possible to connect a floppy drive to Xbox, but
160 * CMOS detection method should not be used here. */
161
162 WARN("XboxGetFloppyCount() is UNIMPLEMENTED, returning 0\n");
163 return 0;
164 }
165
166 PCONFIGURATION_COMPONENT_DATA
167 XboxHwDetect(VOID)
168 {
169 PCONFIGURATION_COMPONENT_DATA SystemKey;
170 ULONG BusNumber = 0;
171
172 TRACE("DetectHardware()\n");
173
174 /* Create the 'System' key */
175 FldrCreateSystemKey(&SystemKey);
176
177 GetHarddiskConfigurationData = XboxGetHarddiskConfigurationData;
178
179 /* TODO: Build actual xbox's hardware configuration tree */
180 DetectIsaBios(SystemKey, &BusNumber);
181
182 TRACE("DetectHardware() Done\n");
183 return SystemKey;
184 }
185
186 VOID XboxHwIdle(VOID)
187 {
188 /* UNIMPLEMENTED */
189 }
190
191
192 /******************************************************************************/
193
194 VOID
195 XboxMachInit(const char *CmdLine)
196 {
197 /* Set LEDs to red before anything is initialized */
198 XboxSetLED("rrrr");
199
200 /* Initialize our stuff */
201 XboxMemInit();
202 XboxVideoInit();
203
204 /* Setup vtbl */
205 MachVtbl.ConsPutChar = XboxConsPutChar;
206 MachVtbl.ConsKbHit = XboxConsKbHit;
207 MachVtbl.ConsGetCh = XboxConsGetCh;
208 MachVtbl.VideoClearScreen = XboxVideoClearScreen;
209 MachVtbl.VideoSetDisplayMode = XboxVideoSetDisplayMode;
210 MachVtbl.VideoGetDisplaySize = XboxVideoGetDisplaySize;
211 MachVtbl.VideoGetBufferSize = XboxVideoGetBufferSize;
212 MachVtbl.VideoGetFontsFromFirmware = XboxVideoGetFontsFromFirmware;
213 MachVtbl.VideoHideShowTextCursor = XboxVideoHideShowTextCursor;
214 MachVtbl.VideoPutChar = XboxVideoPutChar;
215 MachVtbl.VideoCopyOffScreenBufferToVRAM = XboxVideoCopyOffScreenBufferToVRAM;
216 MachVtbl.VideoIsPaletteFixed = XboxVideoIsPaletteFixed;
217 MachVtbl.VideoSetPaletteColor = XboxVideoSetPaletteColor;
218 MachVtbl.VideoGetPaletteColor = XboxVideoGetPaletteColor;
219 MachVtbl.VideoSync = XboxVideoSync;
220 MachVtbl.Beep = PcBeep;
221 MachVtbl.PrepareForReactOS = XboxPrepareForReactOS;
222 MachVtbl.GetMemoryMap = XboxMemGetMemoryMap;
223 MachVtbl.GetExtendedBIOSData = XboxGetExtendedBIOSData;
224 MachVtbl.GetFloppyCount = XboxGetFloppyCount;
225 MachVtbl.DiskGetBootPath = DiskGetBootPath;
226 MachVtbl.DiskReadLogicalSectors = XboxDiskReadLogicalSectors;
227 MachVtbl.DiskGetDriveGeometry = XboxDiskGetDriveGeometry;
228 MachVtbl.DiskGetCacheableBlockCount = XboxDiskGetCacheableBlockCount;
229 MachVtbl.GetTime = XboxGetTime;
230 MachVtbl.InitializeBootDevices = PcInitializeBootDevices;
231 MachVtbl.HwDetect = XboxHwDetect;
232 MachVtbl.HwIdle = XboxHwIdle;
233
234 /* Set LEDs to orange after init */
235 XboxSetLED("oooo");
236 }
237
238 VOID
239 XboxPrepareForReactOS(VOID)
240 {
241 /* On XBOX, prepare video and turn off the floppy motor */
242 XboxVideoPrepareForReactOS();
243 DiskStopFloppyMotor();
244 }
245
246 /* EOF */