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.
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.
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.
20 #include <drivers/xbox/superio.h>
23 DBG_DEFAULT_CHANNEL(HWDETECT
);
25 #define MAX_XBOX_COM_PORTS 2
27 extern PVOID FrameBuffer
;
28 extern ULONG FrameBufferSize
;
31 XboxFindPciBios(PPCI_REGISTRY_INFO BusData
)
33 /* We emulate PCI BIOS here, there are 2 known working PCI buses on an original Xbox */
36 BusData
->MajorRevision
= 1;
37 BusData
->MinorRevision
= 0;
38 BusData
->HardwareMechanism
= 1;
44 DetectSerialPointerPeripheral(PCONFIGURATION_COMPONENT_DATA ControllerKey
, PUCHAR Base
);
48 XboxGetSerialPort(ULONG Index
, PULONG Irq
)
51 * Xbox may have maximum two Serial COM ports
52 * if the Super I/O chip is connected via LPC
54 static const UCHAR Device
[MAX_XBOX_COM_PORTS
] = {LPC_DEVICE_SERIAL_PORT_1
, LPC_DEVICE_SERIAL_PORT_2
};
59 // Select serial device
60 LpcWriteRegister(LPC_CONFIG_DEVICE_NUMBER
, Device
[Index
]);
62 // Check if selected device is active
63 if (LpcReadRegister(LPC_CONFIG_DEVICE_ACTIVATE
) == 1)
65 ComBase
= LpcGetIoBase();
66 *Irq
= LpcGetIrqPrimary();
76 DetectSerialPorts(PCONFIGURATION_COMPONENT_DATA BusKey
, GET_SERIAL_PORT MachGetSerialPort
, ULONG Count
);
79 XboxGetExtendedBIOSData(PULONG ExtendedBIOSDataArea
, PULONG ExtendedBIOSDataSize
)
81 TRACE("XboxGetExtendedBIOSData(): UNIMPLEMENTED\n");
82 *ExtendedBIOSDataArea
= 0;
83 *ExtendedBIOSDataSize
= 0;
86 // NOTE: Similar to machpc.c!PcGetHarddiskConfigurationData(),
87 // but without extended geometry support.
89 PCM_PARTIAL_RESOURCE_LIST
90 XboxGetHarddiskConfigurationData(UCHAR DriveNumber
, ULONG
* pSize
)
92 PCM_PARTIAL_RESOURCE_LIST PartialResourceList
;
93 PCM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry
;
94 //EXTENDED_GEOMETRY ExtGeometry;
99 // Initialize returned size
103 /* Set 'Configuration Data' value */
104 Size
= sizeof(CM_PARTIAL_RESOURCE_LIST
) +
105 sizeof(CM_DISK_GEOMETRY_DEVICE_DATA
);
106 PartialResourceList
= FrLdrHeapAlloc(Size
, TAG_HW_RESOURCE_LIST
);
107 if (PartialResourceList
== NULL
)
109 ERR("Failed to allocate a full resource descriptor\n");
113 memset(PartialResourceList
, 0, Size
);
114 PartialResourceList
->Version
= 1;
115 PartialResourceList
->Revision
= 1;
116 PartialResourceList
->Count
= 1;
117 PartialResourceList
->PartialDescriptors
[0].Type
=
118 CmResourceTypeDeviceSpecific
;
119 // PartialResourceList->PartialDescriptors[0].ShareDisposition =
120 // PartialResourceList->PartialDescriptors[0].Flags =
121 PartialResourceList
->PartialDescriptors
[0].u
.DeviceSpecificData
.DataSize
=
122 sizeof(CM_DISK_GEOMETRY_DEVICE_DATA
);
124 /* Get pointer to geometry data */
125 DiskGeometry
= (PVOID
)(((ULONG_PTR
)PartialResourceList
) + sizeof(CM_PARTIAL_RESOURCE_LIST
));
127 /* Get the disk geometry */
128 //ExtGeometry.Size = sizeof(EXTENDED_GEOMETRY);
130 if (XboxDiskGetDriveGeometry(DriveNumber
, &Geometry
))
132 DiskGeometry
->BytesPerSector
= Geometry
.BytesPerSector
;
133 DiskGeometry
->NumberOfCylinders
= Geometry
.Cylinders
;
134 DiskGeometry
->SectorsPerTrack
= Geometry
.Sectors
;
135 DiskGeometry
->NumberOfHeads
= Geometry
.Heads
;
139 ERR("Reading disk geometry failed\n");
140 FrLdrHeapFree(PartialResourceList
, TAG_HW_RESOURCE_LIST
);
143 TRACE("Disk %x: %u Cylinders %u Heads %u Sectors %u Bytes\n",
145 DiskGeometry
->NumberOfCylinders
,
146 DiskGeometry
->NumberOfHeads
,
147 DiskGeometry
->SectorsPerTrack
,
148 DiskGeometry
->BytesPerSector
);
151 // Return configuration data
154 return PartialResourceList
;
158 DetectDisplayController(PCONFIGURATION_COMPONENT_DATA BusKey
)
161 PCONFIGURATION_COMPONENT_DATA ControllerKey
;
162 PCM_PARTIAL_RESOURCE_LIST PartialResourceList
;
163 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor
;
166 if (FrameBufferSize
== 0)
169 strcpy(Buffer
, "NV2A Framebuffer");
171 Size
= sizeof(CM_PARTIAL_RESOURCE_LIST
);
172 PartialResourceList
= FrLdrHeapAlloc(Size
, TAG_HW_RESOURCE_LIST
);
173 if (PartialResourceList
== NULL
)
175 ERR("Failed to allocate resource descriptor\n");
178 memset(PartialResourceList
, 0, Size
);
180 /* Initialize resource descriptor */
181 PartialResourceList
->Version
= 1;
182 PartialResourceList
->Revision
= 1;
183 PartialResourceList
->Count
= 1;
186 PartialDescriptor
= &PartialResourceList
->PartialDescriptors
[0];
187 PartialDescriptor
->Type
= CmResourceTypeMemory
;
188 PartialDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
189 PartialDescriptor
->Flags
= CM_RESOURCE_MEMORY_READ_WRITE
;
190 PartialDescriptor
->u
.Memory
.Start
.LowPart
= (ULONG_PTR
)FrameBuffer
& 0x0FFFFFFF;
191 PartialDescriptor
->u
.Memory
.Length
= FrameBufferSize
;
193 FldrCreateComponentKey(BusKey
,
204 TRACE("Created key: DisplayController\\0\n");
209 DetectIsaBios(PCONFIGURATION_COMPONENT_DATA SystemKey
, ULONG
*BusNumber
)
211 PCM_PARTIAL_RESOURCE_LIST PartialResourceList
;
212 PCONFIGURATION_COMPONENT_DATA BusKey
;
215 /* Set 'Configuration Data' value */
216 Size
= sizeof(CM_PARTIAL_RESOURCE_LIST
) -
217 sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR
);
218 PartialResourceList
= FrLdrHeapAlloc(Size
, TAG_HW_RESOURCE_LIST
);
219 if (PartialResourceList
== NULL
)
221 TRACE("Failed to allocate resource descriptor\n");
225 /* Initialize resource descriptor */
226 memset(PartialResourceList
, 0, Size
);
227 PartialResourceList
->Version
= 1;
228 PartialResourceList
->Revision
= 1;
229 PartialResourceList
->Count
= 0;
231 /* Create new bus key */
232 FldrCreateComponentKey(SystemKey
,
234 MultiFunctionAdapter
,
243 /* Increment bus number */
246 /* Detect ISA/BIOS devices */
247 DetectBiosDisks(SystemKey
, BusKey
);
248 DetectSerialPorts(BusKey
, XboxGetSerialPort
, MAX_XBOX_COM_PORTS
);
249 DetectDisplayController(BusKey
);
251 /* FIXME: Detect more ISA devices */
256 XboxGetFloppyCount(VOID
)
258 /* On a PC we use CMOS/RTC I/O ports 0x70 and 0x71 to detect floppies.
259 * However an Xbox CMOS memory range [0x10, 0x70) and [0x80, 0x100)
260 * is filled with 0x55 0xAA 0x55 0xAA ... byte pattern which is used
261 * to validate the date/time settings by Xbox OS.
263 * Technically it's possible to connect a floppy drive to Xbox, but
264 * CMOS detection method should not be used here. */
266 WARN("XboxGetFloppyCount() is UNIMPLEMENTED, returning 0\n");
270 PCONFIGURATION_COMPONENT_DATA
273 PCONFIGURATION_COMPONENT_DATA SystemKey
;
276 TRACE("DetectHardware()\n");
278 /* Create the 'System' key */
279 FldrCreateSystemKey(&SystemKey
);
280 FldrSetIdentifier(SystemKey
, "Original Xbox (PC/AT like)");
282 GetHarddiskConfigurationData
= XboxGetHarddiskConfigurationData
;
283 FindPciBios
= XboxFindPciBios
;
285 /* TODO: Build actual xbox's hardware configuration tree */
286 DetectPciBios(SystemKey
, &BusNumber
);
287 DetectIsaBios(SystemKey
, &BusNumber
);
289 TRACE("DetectHardware() Done\n");
293 VOID
XboxHwIdle(VOID
)
299 /******************************************************************************/
302 MachInit(const char *CmdLine
)
306 memset(&MachVtbl
, 0, sizeof(MACHVTBL
));
308 /* Check for Xbox by identifying device at PCI 0:0:0, if it's
309 * 0x10DE/0x02A5 then we're running on an Xbox */
310 WRITE_PORT_ULONG((PULONG
)0xCF8, CONFIG_CMD(0, 0, 0));
311 PciId
= READ_PORT_ULONG((PULONG
)0xCFC);
312 if (PciId
!= 0x02A510DE)
314 ERR("This is not original Xbox!\n");
316 /* Disable and halt the CPU */
323 /* Set LEDs to red before anything is initialized */
327 MachVtbl
.ConsPutChar
= XboxConsPutChar
;
328 MachVtbl
.ConsKbHit
= XboxConsKbHit
;
329 MachVtbl
.ConsGetCh
= XboxConsGetCh
;
330 MachVtbl
.VideoClearScreen
= XboxVideoClearScreen
;
331 MachVtbl
.VideoSetDisplayMode
= XboxVideoSetDisplayMode
;
332 MachVtbl
.VideoGetDisplaySize
= XboxVideoGetDisplaySize
;
333 MachVtbl
.VideoGetBufferSize
= XboxVideoGetBufferSize
;
334 MachVtbl
.VideoGetFontsFromFirmware
= XboxVideoGetFontsFromFirmware
;
335 MachVtbl
.VideoSetTextCursorPosition
= XboxVideoSetTextCursorPosition
;
336 MachVtbl
.VideoHideShowTextCursor
= XboxVideoHideShowTextCursor
;
337 MachVtbl
.VideoPutChar
= XboxVideoPutChar
;
338 MachVtbl
.VideoCopyOffScreenBufferToVRAM
= XboxVideoCopyOffScreenBufferToVRAM
;
339 MachVtbl
.VideoIsPaletteFixed
= XboxVideoIsPaletteFixed
;
340 MachVtbl
.VideoSetPaletteColor
= XboxVideoSetPaletteColor
;
341 MachVtbl
.VideoGetPaletteColor
= XboxVideoGetPaletteColor
;
342 MachVtbl
.VideoSync
= XboxVideoSync
;
343 MachVtbl
.Beep
= PcBeep
;
344 MachVtbl
.PrepareForReactOS
= XboxPrepareForReactOS
;
345 MachVtbl
.GetMemoryMap
= XboxMemGetMemoryMap
;
346 MachVtbl
.GetExtendedBIOSData
= XboxGetExtendedBIOSData
;
347 MachVtbl
.GetFloppyCount
= XboxGetFloppyCount
;
348 MachVtbl
.DiskReadLogicalSectors
= XboxDiskReadLogicalSectors
;
349 MachVtbl
.DiskGetDriveGeometry
= XboxDiskGetDriveGeometry
;
350 MachVtbl
.DiskGetCacheableBlockCount
= XboxDiskGetCacheableBlockCount
;
351 MachVtbl
.GetTime
= XboxGetTime
;
352 MachVtbl
.InitializeBootDevices
= PcInitializeBootDevices
;
353 MachVtbl
.HwDetect
= XboxHwDetect
;
354 MachVtbl
.HwIdle
= XboxHwIdle
;
356 /* Initialize our stuff */
360 /* Set LEDs to orange after init */
363 HalpCalibrateStallExecution();
367 XboxPrepareForReactOS(VOID
)
369 /* On Xbox, prepare video and disk support */
370 XboxVideoPrepareForReactOS();
372 DiskStopFloppyMotor();
374 /* Turn off debug messages to screen */
375 DebugDisableScreenPort();