Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle tray eject/load via smc #1564

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
38 changes: 36 additions & 2 deletions hw/xbox/smbus_xbox_smc.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,24 @@
#include "smbus.h"
#include "sysemu/runstate.h"
#include "hw/qdev-properties.h"
#include "ui/xemu-settings.h"

#define TYPE_XBOX_SMC "smbus-xbox-smc"
#define XBOX_SMC(obj) OBJECT_CHECK(SMBusSMCDevice, (obj), TYPE_XBOX_SMC)

// #define DEBUG
#ifdef __cplusplus
BiatuAutMiahn marked this conversation as resolved.
Show resolved Hide resolved
extern "C" {
#endif

#include "../../xemu-config.h"

extern struct config g_config;
antangelo marked this conversation as resolved.
Show resolved Hide resolved

#ifdef __cplusplus
}
#endif

#define DEBUG
BiatuAutMiahn marked this conversation as resolved.
Show resolved Hide resolved
#ifdef DEBUG
# define DPRINTF(format, ...) printf(format, ## __VA_ARGS__)
#else
Expand Down Expand Up @@ -91,7 +104,10 @@
#define SMC_REG_RESETONEJECT 0x19
#define SMC_REG_INTEN 0x1a
#define SMC_REG_SCRATCH 0x1b
#define SMC_REG_SCRATCH_EJECT_AFTER_BOOT 0x01
#define SMC_REG_SCRATCH_ERROR_AFTER_BOOT 0x02
#define SMC_REG_SCRATCH_SHORT_ANIMATION 0x04
#define SMC_REG_SCRATCH_FORCE_DASH_BOOT 0x08

#define SMC_VERSION_LENGTH 3

Expand All @@ -114,8 +130,9 @@ static void smc_quick_cmd(SMBusDevice *dev, uint8_t read)

static int smc_write_data(SMBusDevice *dev, uint8_t *buf, uint8_t len)
{
Error *error = NULL;
SMBusSMCDevice *smc = XBOX_SMC(dev);

smc->cmd = buf[0];
uint8_t cmd = smc->cmd;
buf++;
Expand All @@ -140,6 +157,19 @@ static int smc_write_data(SMBusDevice *dev, uint8_t *buf, uint8_t len)
}
break;

case SMC_REG_TRAYEJECT:
if (buf[0]) {
BiatuAutMiahn marked this conversation as resolved.
Show resolved Hide resolved
const char *path = g_config.sys.files.dvd_path;
qmp_blockdev_change_medium(true, "ide0-cd1", false, NULL, path,
false, "", false, false, false, 0,
&error);
} else {
xemu_settings_set_string(&g_config.sys.files.dvd_path, "");
BiatuAutMiahn marked this conversation as resolved.
Show resolved Hide resolved
qmp_eject(true, "ide0-cd1", false, NULL, true, false, &error);
}
xbox_smc_update_tray_state();
break;

case SMC_REG_ERROR_WRITE:
smc->error_reg = buf[0];
break;
Expand Down Expand Up @@ -264,6 +294,10 @@ static void smbus_smc_realize(DeviceState *dev, Error **errp)
smc->cmd = 0;
smc->error_reg = 0;

if (object_property_get_bool(qdev_get_machine(), "eject-after-boot", NULL)) {
smc->scratch_reg = SMC_REG_SCRATCH_EJECT_AFTER_BOOT;
BiatuAutMiahn marked this conversation as resolved.
Show resolved Hide resolved
}

if (object_property_get_bool(qdev_get_machine(), "short-animation", NULL)) {
smc->scratch_reg = SMC_REG_SCRATCH_SHORT_ANIMATION;
}
Expand Down
20 changes: 20 additions & 0 deletions hw/xbox/xbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,19 @@ static bool machine_get_short_animation(Object *obj, Error **errp)
return ms->short_animation;
}

static void machine_set_eject_after_boot(Object *obj, bool value,
Error **errp)
{
XboxMachineState *ms = XBOX_MACHINE(obj);
ms->eject_after_boot = value;
}

static bool machine_get_eject_after_boot(Object *obj, Error **errp)
{
XboxMachineState *ms = XBOX_MACHINE(obj);
return ms->eject_after_boot;
}

static char *machine_get_smc_version(Object *obj, Error **errp)
{
XboxMachineState *ms = XBOX_MACHINE(obj);
Expand Down Expand Up @@ -504,6 +517,13 @@ static inline void xbox_machine_initfn(Object *obj)
"Skip Xbox boot animation");
object_property_set_bool(obj, "short-animation", false, &error_fatal);

object_property_add_bool(obj, "eject-after-boot",
machine_get_eject_after_boot,
machine_set_eject_after_boot);
object_property_set_description(obj, "eject-after-boot",
"Eject disc tray after boot");
object_property_set_bool(obj, "eject-after-boot", false, &error_fatal);

object_property_add_str(obj, "smc-version", machine_get_smc_version,
machine_set_smc_version);
object_property_set_description(obj, "smc-version",
Expand Down
1 change: 1 addition & 0 deletions hw/xbox/xbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ typedef struct XboxMachineState {
char *bootrom;
char *avpack;
bool short_animation;
bool eject_after_boot;
char *smc_version;
char *video_encoder;
} XboxMachineState;
Expand Down
12 changes: 11 additions & 1 deletion softmmu/vl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2782,8 +2782,18 @@ void qemu_init(int argc, char **argv)
"none",
}[g_config.sys.avpack];

fake_argv[fake_argc++] = g_strdup_printf("xbox%s%s%s,avpack=%s",
bool eject_after_boot = false;
for (int i = 1; i < argc; i++) {
if (argv[i] && strcmp(argv[i], "-eject_after_boot") == 0) {
argv[i] = NULL;
eject_after_boot = true;
break;
}
}

fake_argv[fake_argc++] = g_strdup_printf("xbox%s%s%s%s,avpack=%s",
(bootrom_arg != NULL) ? bootrom_arg : "",
eject_after_boot ? ",eject-after-boot=on" : "",
g_config.general.skip_boot_anim ? ",short-animation=on" : "",
",kernel-irqchip=off",
avpack_str
Expand Down
Loading