Skip to content

Commit d4ede03

Browse files
binarymasterHBelusca
authored andcommitted
[HALXBOX] Implement shutdown, reboot, and power cycle routines
CORE-16216
1 parent c360509 commit d4ede03

File tree

3 files changed

+139
-6
lines changed

3 files changed

+139
-6
lines changed

hal/halx86/xbox.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ list(APPEND HAL_XBOX_SOURCE
1515
generic/memory.c
1616
generic/misc.c
1717
generic/pic.c
18-
generic/reboot.c
1918
generic/sysinfo.c
2019
generic/usage.c
2120
generic/bios.c
@@ -34,6 +33,7 @@ list(APPEND HAL_XBOX_SOURCE
3433
generic/timer.c
3534
xbox/part_xbox.c
3635
xbox/halinit_xbox.c
36+
xbox/reboot.c
3737
up/pic.c)
3838

3939
add_asm_files(lib_hal_xbox_asm ${HAL_XBOX_ASM_SOURCE})

hal/halx86/xbox/halxbox.h

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
/*
2-
* COPYRIGHT: See COPYING in the top level directory
32
* PROJECT: Xbox HAL
4-
* FILE: hal/halx86/xbox/halxbox.h
3+
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
54
* PURPOSE: Xbox specific routines
6-
* PROGRAMMER: Ge van Geldorp ([email protected])
7-
* UPDATE HISTORY:
8-
* Created 2004/12/02
5+
* COPYRIGHT: Copyright 2004 Gé van Geldorp ([email protected])
6+
* Copyright 2019 Stanislav Motylkov ([email protected])
7+
*
8+
* REFERENCES: https://xboxdevwiki.net/SMBus
9+
* https://github.com/XboxDev/cromwell/blob/master/drivers/pci/i2cio.c
10+
* https://github.com/torvalds/linux/blob/master/drivers/i2c/busses/i2c-amd756.c
11+
* https://github.com/xqemu/xqemu/blob/master/hw/xbox/smbus_xbox_smc.c
912
*/
1013

1114
#ifndef HALXBOX_H_INCLUDED
@@ -14,6 +17,21 @@
1417
#include <hal.h>
1518
#include <ntdddisk.h>
1619

20+
#define SMB_IO_BASE 0xC000
21+
22+
#define SMB_GLOBAL_STATUS (0 + SMB_IO_BASE)
23+
#define SMB_GLOBAL_ENABLE (2 + SMB_IO_BASE)
24+
#define SMB_HOST_ADDRESS (4 + SMB_IO_BASE)
25+
#define SMB_HOST_DATA (6 + SMB_IO_BASE)
26+
#define SMB_HOST_COMMAND (8 + SMB_IO_BASE)
27+
28+
#define SMB_DEVICE_SMC_PIC16LC 0x10
29+
30+
#define SMC_REG_POWER 0x02
31+
#define SMC_REG_POWER_RESET 0x01
32+
#define SMC_REG_POWER_CYCLE 0x40
33+
#define SMC_REG_POWER_SHUTDOWN 0x80
34+
1735
VOID HalpXboxInitPciBus(PBUS_HANDLER BusHandler);
1836
VOID HalpXboxInitPartIo(VOID);
1937

hal/halx86/xbox/reboot.c

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* PROJECT: Xbox HAL
3+
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4+
* PURPOSE: Xbox reboot functions
5+
* COPYRIGHT: Copyright 2004 Lehner Franz ([email protected])
6+
* Copyright 2019 Stanislav Motylkov ([email protected])
7+
*
8+
* REFERENCES: https://xboxdevwiki.net/SMBus
9+
* https://github.com/XboxDev/cromwell/blob/master/drivers/pci/i2cio.c
10+
* https://github.com/torvalds/linux/blob/master/drivers/i2c/busses/i2c-amd756.c
11+
* https://github.com/xqemu/xqemu/blob/master/hw/xbox/smbus_xbox_smc.c
12+
*/
13+
14+
/* INCLUDES ******************************************************************/
15+
16+
#include "halxbox.h"
17+
18+
#define NDEBUG
19+
#include <debug.h>
20+
21+
/* PRIVATE FUNCTIONS *********************************************************/
22+
23+
VOID
24+
NTAPI
25+
SMBusWriteByte(UCHAR Address, UCHAR Register, UCHAR Data)
26+
{
27+
INT Retries = 50;
28+
29+
/* Wait while bus is busy with any master traffic */
30+
while (READ_PORT_USHORT((PUSHORT)SMB_GLOBAL_STATUS) & 0x800)
31+
{
32+
NOTHING;
33+
}
34+
35+
while (Retries--)
36+
{
37+
UCHAR b;
38+
39+
WRITE_PORT_UCHAR((PUCHAR)SMB_HOST_ADDRESS, Address << 1);
40+
WRITE_PORT_UCHAR((PUCHAR)SMB_HOST_COMMAND, Register);
41+
42+
WRITE_PORT_UCHAR((PUCHAR)SMB_HOST_DATA, Data);
43+
44+
/* Clear down all preexisting errors */
45+
WRITE_PORT_USHORT((PUSHORT)SMB_GLOBAL_STATUS, READ_PORT_USHORT((PUSHORT)SMB_GLOBAL_STATUS));
46+
47+
/* Let I2C SMBus know we're sending a single byte here */
48+
WRITE_PORT_UCHAR((PUCHAR)SMB_GLOBAL_ENABLE, 0x1A);
49+
50+
b = 0;
51+
52+
while (!(b & 0x36))
53+
{
54+
b = READ_PORT_UCHAR((PUCHAR)SMB_GLOBAL_STATUS);
55+
}
56+
57+
if (b & 0x10)
58+
{
59+
return;
60+
}
61+
62+
KeStallExecutionProcessor(1);
63+
}
64+
}
65+
66+
VOID
67+
DECLSPEC_NORETURN
68+
NTAPI
69+
HalpXboxPowerAction(IN UCHAR Action)
70+
{
71+
SMBusWriteByte(SMB_DEVICE_SMC_PIC16LC, SMC_REG_POWER, Action);
72+
73+
/* Halt the CPU */
74+
__halt();
75+
76+
while (TRUE); /* 'noreturn' function */
77+
}
78+
79+
/* PUBLIC FUNCTIONS **********************************************************/
80+
81+
/*
82+
* @implemented
83+
*/
84+
VOID
85+
NTAPI
86+
HalReturnToFirmware(IN FIRMWARE_REENTRY Action)
87+
{
88+
/* Check what kind of action this is */
89+
switch (Action)
90+
{
91+
/* All recognized actions */
92+
case HalPowerDownRoutine:
93+
{
94+
/* Call the internal power function */
95+
HalpXboxPowerAction(SMC_REG_POWER_SHUTDOWN);
96+
}
97+
case HalRestartRoutine:
98+
{
99+
HalpXboxPowerAction(SMC_REG_POWER_CYCLE);
100+
}
101+
case HalRebootRoutine:
102+
{
103+
HalpXboxPowerAction(SMC_REG_POWER_RESET);
104+
}
105+
/* Anything else */
106+
default:
107+
{
108+
/* Print message and break */
109+
DbgPrint("HalReturnToFirmware(%d) called!\n", Action);
110+
DbgBreakPoint();
111+
}
112+
}
113+
}
114+
115+
/* EOF */

0 commit comments

Comments
 (0)