Do not use old hotplug logic anymore.
"Hotplug logic" becomes independent of legacy mloop.
"mloop" will be removed.
Change-Id: Ib1c40cb9bb65e6f2d8a2310ad5a0c761184b6321
Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
return dev;
}
-#ifdef CONFIG_MARU
-static PCIDevice *qemu_pci_hot_add_keyboard(Monitor *mon,
- const char *devaddr,
- const char *opts)
-{
- PCIDevice *dev;
- PCIBus *root = pci_find_primary_bus();
- PCIBus *bus;
- int devfn;
-
- if (!root) {
- monitor_printf(mon, "no primary PCI bus (if there are multiple"
- " PCI roots, you must use device_add instead)");
- return NULL;
- }
-
- bus = pci_get_bus_devfn(&devfn, root, devaddr);
- if (!bus) {
- monitor_printf(mon, "Invalid PCI device address %s\n", devaddr);
- return NULL;
- }
-
- if (!((BusState*)bus)->allow_hotplug) {
- monitor_printf(mon, "PCI bus doesn't support hotplug\n");
- return NULL;
- }
-
- dev = pci_create(bus, devfn, "virtio-keyboard-pci");
- if (qdev_init(&dev->qdev) < 0) {
- dev = NULL;
- }
-
- return dev;
-}
-#endif /* CONFIG_MARU */
-
-#ifdef CONFIG_MARU
-void pci_device_hot_add(Monitor *mon, const QDict *qdict)
-{
- do_pci_device_hot_add(mon, qdict);
-}
-
-PCIDevice *do_pci_device_hot_add(Monitor *mon, const QDict *qdict)
-#else
void pci_device_hot_add(Monitor *mon, const QDict *qdict)
-#endif
{
PCIDevice *dev = NULL;
const char *pci_addr = qdict_get_str(qdict, "pci_addr");
dev = qemu_pci_hot_add_nic(mon, pci_addr, opts);
} else if (strcmp(type, "storage") == 0) {
dev = qemu_pci_hot_add_storage(mon, pci_addr, opts);
-#ifdef CONFIG_MARU
- } else if (strcmp(type, "keyboard") == 0) {
- dev = qemu_pci_hot_add_keyboard(mon, pci_addr, opts);
-#endif
} else {
monitor_printf(mon, "invalid type: %s\n", type);
}
PCI_FUNC(dev->devfn));
} else
monitor_printf(mon, "failed to add %s\n", opts);
-#ifdef CONFIG_MARU
- return dev;
-#endif
}
static int pci_device_hot_remove(Monitor *mon, const char *pci_addr)
#include "hw/maru_virtio_vmodem.h"
#include "skin/maruskin_operation.h"
#include "skin/maruskin_server.h"
+#include "util/maru_device_hotplug.h"
#include "emulator.h"
#include "emul_state.h"
}
} else if (!strncmp(cmd, "HKeyboard", 8)) {
if (group == MSG_GROUP_STATUS) {
- send_host_keyboard_ntf(mloop_evcmd_get_hostkbd_status());
+ send_host_keyboard_ntf(is_host_keyboard_attached());
} else {
if (data == NULL) {
ERR("HKeyboard data is NULL\n");
return true;
}
+
static void handle_sdcard(char* dataBuf, size_t dataLen)
{
if (ret == '0' ) {
/* umount sdcard */
- //mloop_evcmd_usbdisk(NULL);
- mloop_evcmd_sdcard(NULL);
+ do_hotplug(DETACH_SDCARD, NULL, 0);
} else if (ret == '1') {
/* mount sdcard */
char sdcard_img_path[256];
g_strlcat(sdcard_img_path, sdcard_img_name, sizeof(sdcard_img_path));
TRACE("sdcard path: [%s]\n", sdcard_img_path);
- //mloop_evcmd_usbdisk(sdcard_img_path);
- mloop_evcmd_sdcard(sdcard_img_path);
+ do_hotplug(ATTACH_SDCARD, sdcard_img_path, strlen(sdcard_img_path) + 1);
/*if using strndup than free string*/
if(pLinechange != NULL && sdcard_img_name!= NULL){
#include "skin/maruskin_server.h"
#include "debug_ch.h"
#include "ecs/ecs.h"
+#include "util/maru_device_hotplug.h"
#ifdef CONFIG_SDL
#include <SDL.h>
check_vm_lock();
make_vm_lock();
+ maru_device_hotplug_init();
+
qemu_add_opts(&qemu_ecs_opts);
start_ecs();
#define MLOOP_EVTYPE_INTR_UP 3
#define MLOOP_EVTYPE_INTR_DOWN 4
#define MLOOP_EVTYPE_TOUCH 6
-#define MLOOP_EVTYPE_KBD_ADD 8
-#define MLOOP_EVTYPE_KBD_DEL 9
#define MLOOP_EVTYPE_RAMDUMP 10
-#define MLOOP_EVTYPE_SDCARD_ATTACH 11
-#define MLOOP_EVTYPE_SDCARD_DETACH 12
-
static struct mloop_evsock mloop = {-1, 0, 0};
}
static USBDevice *usbdisk = NULL;
-#ifdef TARGET_I386
-static PCIDevice *hostkbd = NULL;
-static PCIDevice *virtio_sdcard = NULL;
-#endif
static void mloop_evhandle_usb_add(char *name)
{
maru_virtio_touchscreen_notify();
}
-#ifdef TARGET_I386
-static void mloop_evhandle_kbd_add(char *name)
-{
- QDict *qdict;
-
- TRACE("try to add a keyboard device.\n");
-
- if (name == NULL) {
- ERR("packet data is NULL.\n");
- return;
- }
-
- if (hostkbd) {
- INFO("virtio-keyboard has already been added.\n");
- return;
- }
-
- qdict = qdict_new();
- qdict_put(qdict, "pci_addr", qstring_from_str("auto"));
- qdict_put(qdict, "type", qstring_from_str(name));
-
- hostkbd = do_pci_device_hot_add(cur_mon, qdict);
- if (hostkbd) {
- TRACE("virtio-keyboard device: root_bus_path %s, bus %d, slot %d, function %d\n",
- pci_root_bus_path(hostkbd), pci_bus_num(hostkbd->bus),
- PCI_SLOT(hostkbd->devfn), PCI_FUNC(hostkbd->devfn));
- } else {
- ERR("failed to hot_add keyboard device.\n");
- }
-
- QDECREF(qdict);
-}
-
-static void mloop_evhandle_kbd_del(void)
-{
- QDict *qdict;
- int slot = 0;
- char slotbuf[4] = {0,};
-
- TRACE("try to remove a keyboard device.\n");
-
- if (!hostkbd) {
- ERR("Failed to remove a keyboard device "
- "because the device has not been created yet.\n");
- return;
- }
-
- slot = PCI_SLOT(hostkbd->devfn);
- snprintf(slotbuf, sizeof(slotbuf), "%x", slot);
- TRACE("virtio-keyboard slot %s.\n", slotbuf);
-
- qdict = qdict_new();
- qdict_put(qdict, "pci_addr", qstring_from_str(slotbuf));
-
- do_pci_device_hot_remove(cur_mon, qdict);
- INFO("hot_remove keyboard.\n");
-
- hostkbd = NULL;
-
- QDECREF(qdict);
-}
-
-static void mloop_evhandle_sdcard_attach(char *name)
-{
- char opts[PATH_MAX];
-
- INFO("try to attach sdcard.\n");
-
- if (name == NULL) {
- ERR("Packet data is NULL.\n");
- return;
- }
-
- if (virtio_sdcard) {
- ERR("sdcard is already attached.\n");
- return;
- }
-
- QDict *qdict = qdict_new();
-
- qdict_put(qdict, "pci_addr", qstring_from_str("auto"));
- qdict_put(qdict, "type", qstring_from_str("storage"));
- snprintf(opts, sizeof(opts), "file=%s,if=virtio", name);
- qdict_put(qdict, "opts", qstring_from_str(opts));
-
- virtio_sdcard = do_pci_device_hot_add(cur_mon, qdict);
- if (virtio_sdcard) {
- INFO("hot add virtio storage device with [%s]\n", opts);
- INFO("virtio-sdcard device: root_bus_path %s, bus %d, slot %d, function %d\n",
- pci_root_bus_path(virtio_sdcard), pci_bus_num(virtio_sdcard->bus),
- PCI_SLOT(virtio_sdcard->devfn), PCI_FUNC(virtio_sdcard->devfn));
- } else {
- ERR("failed to create a sdcard device.\n");
- }
-
- QDECREF(qdict);
-}
-
-static void mloop_evhandle_sdcard_detach(void)
-{
- INFO("try to detach sdcard.\n");
-
- if (!virtio_sdcard) {
- ERR("sdcard is not attached yet.\n");
- return;
- }
-
- QDict *qdict = qdict_new();
- int slot = 0;
- char slotbuf[4] = {0,};
-
- slot = PCI_SLOT(virtio_sdcard->devfn);
- snprintf(slotbuf, sizeof(slotbuf), "%x", slot);
- INFO("virtio-sdcard slot [%d].\n", slot);
- qdict_put(qdict, "pci_addr", qstring_from_str(slotbuf));
-
- do_pci_device_hot_remove(cur_mon, qdict);
-
- virtio_sdcard = NULL;
-
- INFO("hot remove virtio storage device.\n");
-
- QDECREF(qdict);
-}
-
-int mloop_evcmd_get_hostkbd_status(void)
-{
- return hostkbd ? 1 : 0;
-}
-#endif
-
static void mloop_evhandle_ramdump(struct mloop_evpack* pack)
{
#define MAX_PATH 256
case MLOOP_EVTYPE_TOUCH:
mloop_evhandle_touch(&pack);
break;
-#ifdef TARGET_I386
- case MLOOP_EVTYPE_KBD_ADD:
- mloop_evhandle_kbd_add(pack.data);
- break;
- case MLOOP_EVTYPE_KBD_DEL:
- mloop_evhandle_kbd_del();
- break;
-#endif
case MLOOP_EVTYPE_RAMDUMP:
mloop_evhandle_ramdump(&pack);
break;
-#ifdef TARGET_I386
- case MLOOP_EVTYPE_SDCARD_ATTACH:
- mloop_evhandle_sdcard_attach(pack.data);
- break;
- case MLOOP_EVTYPE_SDCARD_DETACH:
- mloop_evhandle_sdcard_detach();
- break;
-#endif
default:
break;
}
mloop_evsock_send(&mloop, &pack);
}
-void mloop_evcmd_hostkbd(int on)
-{
- struct mloop_evpack pack
- = {MLOOP_EVTYPE_KBD_ADD, 13, "keyboard"};
- if (on == 0) {
- pack.type = MLOOP_EVTYPE_KBD_DEL;
- }
- mloop_evsock_send(&mloop, &pack);
-}
-
void mloop_evcmd_usbdisk(char *img)
{
struct mloop_evpack pack;
mloop_evsock_send(&mloop, &pack);
}
-void mloop_evcmd_sdcard(char *img)
-{
- struct mloop_evpack pack;
-
- if (img) {
- if (strlen(img) > PACKET_LEN-5) {
- ERR("The length of disk image path is greater than "
- "lenth of maximum packet.\n");
- return;
- }
-
- pack.type = MLOOP_EVTYPE_SDCARD_ATTACH;
- pack.size = 5 + sprintf(pack.data, "%s", img);
- } else {
- pack.type = MLOOP_EVTYPE_SDCARD_DETACH;
- pack.size = 5;
- }
-
- mloop_evsock_send(&mloop, &pack);
-}
-
void mloop_evcmd_set_usbdisk(void *dev)
{
usbdisk = (USBDevice *)dev;
#include "maruskin_server.h"
#include "display/maru_display.h"
#include "hw/maru_pm.h"
+#include "util/maru_device_hotplug.h"
#include "ecs/ecs.h"
#ifdef CONFIG_HAX
#endif
#if defined(TARGET_I386)
- if (!mloop_evcmd_get_hostkbd_status()) {
+ if (!is_host_keyboard_attached()) {
TRACE("ignore keyboard input because usb keyboard is dettached.\n");
return;
}
#if defined(TARGET_ARM)
mloop_evcmd_usbkbd(on);
#elif defined(TARGET_I386)
- mloop_evcmd_hostkbd(on);
+ if (on) {
+ do_hotplug(ATTACH_HOST_KEYBOARD, NULL, 0);
+ } else {
+ do_hotplug(DETACH_HOST_KEYBOARD, NULL, 0);
+ }
#endif
}
obj-$(CONFIG_WIN32) += check_gl_wgl.o
obj-$(CONFIG_DARWIN) += check_gl_cgl.o
+# hotplug
+obj-y += maru_device_hotplug.o
+
$(obj)/osutil.o: QEMU_CFLAGS += $(CURL_CFLAGS)
--- /dev/null
+/*
+ * Maru device hotplug
+ *
+ * Copyright (C) 2014 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+#include "qemu/main-loop.h"
+#include "qemu/config-file.h"
+#include "hw/qdev.h"
+#include "monitor/qdev.h"
+#include "qmp-commands.h"
+#include "sysemu/blockdev.h"
+#include "qemu/event_notifier.h"
+
+#include "maru_common.h"
+#include "emulator.h"
+#include "maru_device_hotplug.h"
+
+#define HOST_KEYBOARD_DRIVER "virtio-keyboard-pci"
+#define HOST_KEYBOARD_DEFAULT_ID "HOSTKBD0"
+
+#define SDCARD_DRIVE_DEFAULT_ID "SDCARD_DRIVE0"
+#define SDCARD_DRIVER "virtio-blk-pci"
+#define SDCARD_DEFAULT_ID "SDCARD0"
+
+struct maru_device_hotplug {
+ EventNotifier notifier;
+
+ char *opaque;
+ int command;
+
+ // FIXME: Should we query device every time ??
+ bool host_keyboard_attached;
+ bool sdcard_attached;
+};
+
+static struct maru_device_hotplug *state;
+
+static bool do_host_keyboard_attach(void)
+{
+ QDict *qdict = qdict_new();
+ qdict_put(qdict, "driver", qstring_from_str(HOST_KEYBOARD_DRIVER));
+ qdict_put(qdict, "id", qstring_from_str(HOST_KEYBOARD_DEFAULT_ID));
+
+ if (do_device_add(default_mon, qdict, NULL)) {
+ QDECREF(qdict);
+ // TODO error reporting
+ return false;
+ }
+
+ QDECREF(qdict);
+
+ state->host_keyboard_attached = true;
+
+ return true;
+}
+
+static bool do_host_keyboard_detach(void)
+{
+ QDict *qdict = qdict_new();
+ qdict_put(qdict, "id", qstring_from_str(HOST_KEYBOARD_DEFAULT_ID));
+
+ if (qmp_marshal_input_device_del(default_mon, qdict, NULL)) {
+ QDECREF(qdict);
+ // TODO error reporting
+ return false;
+ }
+
+ QDECREF(qdict);
+
+ state->host_keyboard_attached = false;
+
+ return true;
+}
+
+static bool do_sdcard_attach(const char * const file)
+{
+ QDict *qdict = qdict_new();
+ QDict *qdict_file = qdict_new();
+ QDict *qdict_options = qdict_new();
+
+ qdict_put(qdict_file, "driver", qstring_from_str("file"));
+ qdict_put(qdict_file, "filename", qstring_from_str(file));
+ qdict_put(qdict_options, "file", qdict_file);
+ qdict_put(qdict_options, "driver", qstring_from_str("qcow2"));
+ qdict_put(qdict_options, "id", qstring_from_str(SDCARD_DRIVE_DEFAULT_ID));
+ qdict_put(qdict, "options", qdict_options);
+
+ if (qmp_marshal_input_blockdev_add(default_mon, qdict, NULL)) {
+ QDECREF(qdict);
+ }
+
+ QDECREF(qdict);
+
+ qdict = qdict_new();
+ qdict_put(qdict, "driver", qstring_from_str(SDCARD_DRIVER));
+ qdict_put(qdict, "drive", qstring_from_str(SDCARD_DRIVE_DEFAULT_ID));
+ qdict_put(qdict, "id", qstring_from_str(SDCARD_DEFAULT_ID));
+
+ if (do_device_add(default_mon, qdict, NULL)) {
+ QDECREF(qdict);
+ // TODO error reporting
+ return false;
+ }
+
+ QDECREF(qdict);
+
+ state->sdcard_attached = true;
+
+ return true;
+}
+
+static bool do_sdcard_detach(void) {
+ QDict *qdict = qdict_new();
+ qdict_put(qdict, "id", qstring_from_str(SDCARD_DEFAULT_ID));
+
+ if (qmp_marshal_input_device_del(cur_mon, qdict, NULL)) {
+ QDECREF(qdict);
+ // TODO error reporting
+ return false;
+ }
+
+ QDECREF(qdict);
+
+ state->sdcard_attached = false;
+
+ return true;
+}
+
+void do_hotplug(int command, void *opaque, size_t size)
+{
+ if (command == ATTACH_SDCARD) {
+ state->opaque = g_malloc(size);
+ memcpy(state->opaque, opaque, size);
+ }
+ state->command = command;
+
+ event_notifier_set(&state->notifier);
+}
+
+static void device_hotplug_handler(EventNotifier *e)
+{
+ event_notifier_test_and_clear(e);
+
+ switch(state->command) {
+ case ATTACH_HOST_KEYBOARD:
+ do_host_keyboard_attach();
+ break;
+ case DETACH_HOST_KEYBOARD:
+ do_host_keyboard_detach();
+ break;
+ case ATTACH_SDCARD:
+ do_sdcard_attach(state->opaque);
+ g_free(state->opaque);
+ break;
+ case DETACH_SDCARD:
+ do_sdcard_detach();
+ break;
+ default:
+ break;
+ }
+}
+
+static void maru_device_hotplug_deinit(Notifier *notifier, void *data)
+{
+ event_notifier_cleanup(&state->notifier);
+
+ g_free(state);
+}
+
+static Notifier maru_device_hotplug_exit = { .notify = maru_device_hotplug_deinit };
+
+void maru_device_hotplug_init(void)
+{
+ state = g_malloc0(sizeof(struct maru_device_hotplug));
+
+ event_notifier_init(&state->notifier, 0);
+ event_notifier_set_handler(&state->notifier, device_hotplug_handler);
+
+ emulator_add_exit_notifier(&maru_device_hotplug_exit);
+}
+
+bool is_host_keyboard_attached(void)
+{
+ return state->host_keyboard_attached;
+}
+
+bool is_sdcard_attached(void)
+{
+ return state->sdcard_attached;
+}
+
--- /dev/null
+/*
+ * Maru device hotplug
+ *
+ * Copyright (C) 2014 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+#ifndef _MARU_DEVICE_HOTPLUG_H_
+#define _MARU_DEVICE_HOTPLUG_H_
+
+enum command {
+ ATTACH_HOST_KEYBOARD,
+ DETACH_HOST_KEYBOARD,
+ ATTACH_SDCARD,
+ DETACH_SDCARD,
+};
+
+void maru_device_hotplug_init(void);
+
+void do_hotplug(int command, void *opaque, size_t size);
+
+bool is_host_keyboard_attached(void);
+bool is_sdcard_attached(void);
+
+#endif // _MARU_DEVICE_HOTPLUG_H_