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
35 changes: 29 additions & 6 deletions hw/xbox/smbus_xbox_smc.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@
*/

#include "qemu/osdep.h"
#include "qemu/option.h"
#include "hw/hw.h"
#include "hw/acpi/acpi.h"
#include "hw/hw.h"
#include "hw/i2c/i2c.h"
#include "hw/i2c/smbus_slave.h"
#include "qemu/config-file.h"
#include "hw/qdev-properties.h"
#include "qapi/error.h"
#include "qemu/config-file.h"
#include "qemu/option.h"
#include "sysemu/block-backend.h"
#include "sysemu/blockdev.h"
#include "sysemu/runstate.h"
#include "sysemu/sysemu.h"
#include "ui/xemu-settings.h"
BiatuAutMiahn marked this conversation as resolved.
Show resolved Hide resolved
#include "smbus.h"
#include "sysemu/runstate.h"
#include "hw/qdev-properties.h"

#define TYPE_XBOX_SMC "smbus-xbox-smc"
#define XBOX_SMC(obj) OBJECT_CHECK(SMBusSMCDevice, (obj), TYPE_XBOX_SMC)
Expand Down Expand Up @@ -91,7 +92,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,6 +118,7 @@ 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];
Expand All @@ -140,6 +145,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,8 +282,13 @@ 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;
}

if (object_property_get_bool(qdev_get_machine(), "short-animation", NULL)) {
smc->scratch_reg = SMC_REG_SCRATCH_SHORT_ANIMATION;
smc->scratch_reg |= SMC_REG_SCRATCH_SHORT_ANIMATION;
}

avpack = object_property_get_str(qdev_get_machine(), "avpack", NULL);
Expand Down
19 changes: 19 additions & 0 deletions hw/xbox/xbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,18 @@ 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 +516,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
18 changes: 13 additions & 5 deletions softmmu/vl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2782,12 +2782,20 @@ 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",
(bootrom_arg != NULL) ? bootrom_arg : "",
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
);
",kernel-irqchip=off", avpack_str);

if (bootrom_arg != NULL) {
g_free(bootrom_arg);
Expand Down
3 changes: 2 additions & 1 deletion ui/xui/main-menu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,8 @@ void MainMenuSystemView::Draw()
}

if ((int)g_config.sys.avpack == CONFIG_SYS_AVPACK_NONE) {
ImGui::TextColored(ImVec4(1,0,0,1), "Setting AV Pack to NONE disables video output.");
ImGui::TextColored(ImVec4(1, 0, 0, 1),
"Setting AV Pack to NONE disables video output.");
}

SectionTitle("System Configuration");
Expand Down
Loading