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.
22 DBG_DEFAULT_CHANNEL(HWDETECT
);
26 XboxFindPciBios(PPCI_REGISTRY_INFO BusData
)
28 /* We emulate PCI BIOS here, there are 2 known working PCI buses on an original Xbox */
31 BusData
->MajorRevision
= 1;
32 BusData
->MinorRevision
= 0;
33 BusData
->HardwareMechanism
= 1;
39 DetectSerialPointerPeripheral(PCONFIGURATION_COMPONENT_DATA ControllerKey
, PUCHAR Base
);
43 XboxGetSerialPort(ULONG Index
, PULONG Irq
)
46 * Xbox may have maximum two Serial COM ports
47 * if the Super I/O chip is connected via LPC
49 static const UCHAR Device
[MAX_XBOX_COM_PORTS
] = {LPC_DEVICE_SERIAL_PORT_1
, LPC_DEVICE_SERIAL_PORT_2
};
52 // Enter Configuration
53 WRITE_PORT_UCHAR(LPC_IO_BASE
, LPC_ENTER_CONFIG_KEY
);
55 // Select serial device
56 WRITE_PORT_UCHAR(LPC_IO_BASE
, LPC_CONFIG_DEVICE_NUMBER
);
57 WRITE_PORT_UCHAR(LPC_IO_BASE
+ 1, Device
[Index
]);
59 // Check if selected device is active
60 WRITE_PORT_UCHAR(LPC_IO_BASE
, LPC_CONFIG_DEVICE_ACTIVATE
);
61 if (READ_PORT_UCHAR(LPC_IO_BASE
+ 1) == 1)
64 WRITE_PORT_UCHAR(LPC_IO_BASE
, LPC_CONFIG_DEVICE_BASE_ADDRESS_LOW
);
65 ComBase
= READ_PORT_UCHAR(LPC_IO_BASE
+ 1);
67 WRITE_PORT_UCHAR(LPC_IO_BASE
, LPC_CONFIG_DEVICE_BASE_ADDRESS_HIGH
);
68 ComBase
|= (READ_PORT_UCHAR(LPC_IO_BASE
+ 1) << 8);
70 WRITE_PORT_UCHAR(LPC_IO_BASE
, LPC_CONFIG_DEVICE_INTERRUPT
);
71 *Irq
= READ_PORT_UCHAR(LPC_IO_BASE
+ 1);
75 WRITE_PORT_UCHAR(LPC_IO_BASE
, LPC_EXIT_CONFIG_KEY
);
82 DetectSerialPorts(PCONFIGURATION_COMPONENT_DATA BusKey
, GET_SERIAL_PORT MachGetSerialPort
, ULONG Count
);
85 XboxGetExtendedBIOSData(PULONG ExtendedBIOSDataArea
, PULONG ExtendedBIOSDataSize
)
87 TRACE("XboxGetExtendedBIOSData(): UNIMPLEMENTED\n");
88 *ExtendedBIOSDataArea
= 0;
89 *ExtendedBIOSDataSize
= 0;
92 // NOTE: Similar to machpc.c!PcGetHarddiskConfigurationData(),
93 // but without extended geometry support.
95 PCM_PARTIAL_RESOURCE_LIST
96 XboxGetHarddiskConfigurationData(UCHAR DriveNumber
, ULONG
* pSize
)
98 PCM_PARTIAL_RESOURCE_LIST PartialResourceList
;
99 PCM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry
;
100 //EXTENDED_GEOMETRY ExtGeometry;
105 // Initialize returned size
109 /* Set 'Configuration Data' value */
110 Size
= sizeof(CM_PARTIAL_RESOURCE_LIST
) +
111 sizeof(CM_DISK_GEOMETRY_DEVICE_DATA
);
112 PartialResourceList
= FrLdrHeapAlloc(Size
, TAG_HW_RESOURCE_LIST
);
113 if (PartialResourceList
== NULL
)
115 ERR("Failed to allocate a full resource descriptor\n");
119 memset(PartialResourceList
, 0, Size
);
120 PartialResourceList
->Version
= 1;
121 PartialResourceList
->Revision
= 1;
122 PartialResourceList
->Count
= 1;
123 PartialResourceList
->PartialDescriptors
[0].Type
=
124 CmResourceTypeDeviceSpecific
;
125 // PartialResourceList->PartialDescriptors[0].ShareDisposition =
126 // PartialResourceList->PartialDescriptors[0].Flags =
127 PartialResourceList
->PartialDescriptors
[0].u
.DeviceSpecificData
.DataSize
=
128 sizeof(CM_DISK_GEOMETRY_DEVICE_DATA
);
130 /* Get pointer to geometry data */
131 DiskGeometry
= (PVOID
)(((ULONG_PTR
)PartialResourceList
) + sizeof(CM_PARTIAL_RESOURCE_LIST
));
133 /* Get the disk geometry */
134 //ExtGeometry.Size = sizeof(EXTENDED_GEOMETRY);
136 if (XboxDiskGetDriveGeometry(DriveNumber
, &Geometry
))
138 DiskGeometry
->BytesPerSector
= Geometry
.BytesPerSector
;
139 DiskGeometry
->NumberOfCylinders
= Geometry
.Cylinders
;
140 DiskGeometry
->SectorsPerTrack
= Geometry
.Sectors
;
141 DiskGeometry
->NumberOfHeads
= Geometry
.Heads
;
145 ERR("Reading disk geometry failed\n");
146 FrLdrHeapFree(PartialResourceList
, TAG_HW_RESOURCE_LIST
);
149 TRACE("Disk %x: %u Cylinders %u Heads %u Sectors %u Bytes\n",
151 DiskGeometry
->NumberOfCylinders
,
152 DiskGeometry
->NumberOfHeads
,
153 DiskGeometry
->SectorsPerTrack
,
154 DiskGeometry
->BytesPerSector
);
157 // Return configuration data
160 return PartialResourceList
;
165 DetectIsaBios(PCONFIGURATION_COMPONENT_DATA SystemKey
, ULONG
*BusNumber
)
167 PCM_PARTIAL_RESOURCE_LIST PartialResourceList
;
168 PCONFIGURATION_COMPONENT_DATA BusKey
;
171 /* Set 'Configuration Data' value */
172 Size
= sizeof(CM_PARTIAL_RESOURCE_LIST
) -
173 sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR
);
174 PartialResourceList
= FrLdrHeapAlloc(Size
, TAG_HW_RESOURCE_LIST
);
175 if (PartialResourceList
== NULL
)
177 TRACE("Failed to allocate resource descriptor\n");
181 /* Initialize resource descriptor */
182 memset(PartialResourceList
, 0, Size
);
183 PartialResourceList
->Version
= 1;
184 PartialResourceList
->Revision
= 1;
185 PartialResourceList
->Count
= 0;
187 /* Create new bus key */
188 FldrCreateComponentKey(SystemKey
,
190 MultiFunctionAdapter
,
199 /* Increment bus number */
202 /* Detect ISA/BIOS devices */
203 DetectBiosDisks(SystemKey
, BusKey
);
204 DetectSerialPorts(BusKey
, XboxGetSerialPort
, MAX_XBOX_COM_PORTS
);
206 /* FIXME: Detect more ISA devices */
211 XboxGetFloppyCount(VOID
)
213 /* On a PC we use CMOS/RTC I/O ports 0x70 and 0x71 to detect floppies.
214 * However an Xbox CMOS memory range [0x10, 0x70) and [0x80, 0x100)
215 * is filled with 0x55 0xAA 0x55 0xAA ... byte pattern which is used
216 * to validate the date/time settings by Xbox OS.
218 * Technically it's possible to connect a floppy drive to Xbox, but
219 * CMOS detection method should not be used here. */
221 WARN("XboxGetFloppyCount() is UNIMPLEMENTED, returning 0\n");
225 PCONFIGURATION_COMPONENT_DATA
228 PCONFIGURATION_COMPONENT_DATA SystemKey
;
231 TRACE("DetectHardware()\n");
233 /* Create the 'System' key */
234 FldrCreateSystemKey(&SystemKey
);
236 GetHarddiskConfigurationData
= XboxGetHarddiskConfigurationData
;
237 FindPciBios
= XboxFindPciBios
;
239 /* TODO: Build actual xbox's hardware configuration tree */
240 DetectPciBios(SystemKey
, &BusNumber
);
241 DetectIsaBios(SystemKey
, &BusNumber
);
243 TRACE("DetectHardware() Done\n");
247 VOID
XboxHwIdle(VOID
)
253 /******************************************************************************/
256 XboxMachInit(const char *CmdLine
)
258 /* Set LEDs to red before anything is initialized */
261 /* Initialize our stuff */
266 MachVtbl
.ConsPutChar
= XboxConsPutChar
;
267 MachVtbl
.ConsKbHit
= XboxConsKbHit
;
268 MachVtbl
.ConsGetCh
= XboxConsGetCh
;
269 MachVtbl
.VideoClearScreen
= XboxVideoClearScreen
;
270 MachVtbl
.VideoSetDisplayMode
= XboxVideoSetDisplayMode
;
271 MachVtbl
.VideoGetDisplaySize
= XboxVideoGetDisplaySize
;
272 MachVtbl
.VideoGetBufferSize
= XboxVideoGetBufferSize
;
273 MachVtbl
.VideoGetFontsFromFirmware
= XboxVideoGetFontsFromFirmware
;
274 MachVtbl
.VideoSetTextCursorPosition
= XboxVideoSetTextCursorPosition
;
275 MachVtbl
.VideoHideShowTextCursor
= XboxVideoHideShowTextCursor
;
276 MachVtbl
.VideoPutChar
= XboxVideoPutChar
;
277 MachVtbl
.VideoCopyOffScreenBufferToVRAM
= XboxVideoCopyOffScreenBufferToVRAM
;
278 MachVtbl
.VideoIsPaletteFixed
= XboxVideoIsPaletteFixed
;
279 MachVtbl
.VideoSetPaletteColor
= XboxVideoSetPaletteColor
;
280 MachVtbl
.VideoGetPaletteColor
= XboxVideoGetPaletteColor
;
281 MachVtbl
.VideoSync
= XboxVideoSync
;
282 MachVtbl
.Beep
= PcBeep
;
283 MachVtbl
.PrepareForReactOS
= XboxPrepareForReactOS
;
284 MachVtbl
.GetMemoryMap
= XboxMemGetMemoryMap
;
285 MachVtbl
.GetExtendedBIOSData
= XboxGetExtendedBIOSData
;
286 MachVtbl
.GetFloppyCount
= XboxGetFloppyCount
;
287 MachVtbl
.DiskReadLogicalSectors
= XboxDiskReadLogicalSectors
;
288 MachVtbl
.DiskGetDriveGeometry
= XboxDiskGetDriveGeometry
;
289 MachVtbl
.DiskGetCacheableBlockCount
= XboxDiskGetCacheableBlockCount
;
290 MachVtbl
.GetTime
= XboxGetTime
;
291 MachVtbl
.InitializeBootDevices
= PcInitializeBootDevices
;
292 MachVtbl
.HwDetect
= XboxHwDetect
;
293 MachVtbl
.HwIdle
= XboxHwIdle
;
295 /* Set LEDs to orange after init */
300 XboxPrepareForReactOS(VOID
)
302 /* On Xbox, prepare video and disk support */
303 XboxVideoPrepareForReactOS();
305 DiskStopFloppyMotor();