From 123021c5adc663a0d7f31c2c2a8cc99d3179d41b Mon Sep 17 00:00:00 2001 From: SeokYeon Hwang Date: Tue, 16 Apr 2013 00:39:58 +0900 Subject: [PATCH] sdcard: Prepare virtio sdcard For higher performance and mount support by Tizen system framework. Change-Id: I0c7d0538cb062139c48d00d57f80bb027a605452 Signed-off-by: SeokYeon Hwang --- hw/pci-hotplug.c | 7 +++ sysemu.h | 4 ++ tizen/src/guest_server.c | 6 ++- tizen/src/mloop_event.c | 100 +++++++++++++++++++++++++++++++++++++++ tizen/src/mloop_event.h | 2 + 5 files changed, 118 insertions(+), 1 deletion(-) diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c index 73badc15ad..33d1baceee 100644 --- a/hw/pci-hotplug.c +++ b/hw/pci-hotplug.c @@ -246,7 +246,11 @@ static PCIDevice *qemu_pci_hot_add_keyboard(Monitor *mon, } #endif /* CONFIG_MARU */ +#ifdef CONFIG_MARU +PCIDevice *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"); @@ -284,6 +288,9 @@ void pci_device_hot_add(Monitor *mon, const QDict *qdict) PCI_FUNC(dev->devfn)); } else monitor_printf(mon, "failed to add %s\n", opts); +#ifdef CONFIG_MARU + return dev; +#endif } #endif diff --git a/sysemu.h b/sysemu.h index 92107114f9..3a23fb97dc 100644 --- a/sysemu.h +++ b/sysemu.h @@ -161,7 +161,11 @@ extern const char *prom_envs[MAX_PROM_ENVS]; extern unsigned int nb_prom_envs; /* pci-hotplug */ +#ifdef CONFIG_MARU +PCIDevice *pci_device_hot_add(Monitor *mon, const QDict *qdict); +#else void pci_device_hot_add(Monitor *mon, const QDict *qdict); +#endif int pci_drive_hot_add(Monitor *mon, const QDict *qdict, DriveInfo *dinfo, int type); void do_pci_device_hot_remove(Monitor *mon, const QDict *qdict); diff --git a/tizen/src/guest_server.c b/tizen/src/guest_server.c index 452b048f54..7c0eb41172 100644 --- a/tizen/src/guest_server.c +++ b/tizen/src/guest_server.c @@ -224,7 +224,8 @@ static void* run_guest_server(void* args) if (atoi(ret) == 0) { /* umount sdcard */ mloop_evcmd_usbdisk(NULL); - + // prepare virtio sdcard... + //mloop_evcmd_sdcard(NULL); } else if (atoi(ret) == 1) { /* mount sdcard */ char sdcard_path[256]; @@ -239,6 +240,9 @@ static void* run_guest_server(void* args) INFO("%s\n", sdcard_path); mloop_evcmd_usbdisk(sdcard_path); + // prepare virtio sdcard... + //mloop_evcmd_sdcard(sdcard_path); + free(vms_path); } else { ERR("!!! unknown command : %s\n", ret); diff --git a/tizen/src/mloop_event.c b/tizen/src/mloop_event.c index d4a61eb7b3..fca63fc80d 100644 --- a/tizen/src/mloop_event.c +++ b/tizen/src/mloop_event.c @@ -85,6 +85,8 @@ struct mloop_evpack { #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}; @@ -205,6 +207,9 @@ static int mloop_evsock_send(struct mloop_evsock *ev, struct mloop_evpack *p) static USBDevice *usbkbd = NULL; static USBDevice *usbdisk = NULL; static PCIDevice *hostkbd = NULL; +#ifdef TARGET_I386 +static PCIDevice *virtio_sdcard = NULL; +#endif static void mloop_evhandle_usb_add(char *name) { @@ -372,6 +377,71 @@ static void mloop_evhandle_kbd_del(char *name) WARN("There is no %s device.\n", name); } } + +static void mloop_evhandle_sdcard_attach(char *name) +{ + char opts[PATH_MAX]; + + INFO("mloop_evhandle_sdcard_attach\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 = pci_device_hot_add(cur_mon, qdict); + + INFO("hot add virtio storage device with [%s]\n", opts); + INFO("virtio-sdcard device: domain %d, bus %d, slot %d, function %d\n", + pci_find_domain(virtio_sdcard->bus), pci_bus_num(virtio_sdcard->bus), + PCI_SLOT(virtio_sdcard->devfn), PCI_FUNC(virtio_sdcard->devfn)); + + QDECREF(qdict); +} + +static void mloop_evhandle_sdcard_detach(char *name) +{ + INFO("mloop_evhandle_sdcard_detach\n"); + + if (name == NULL) { + ERR("packet data is NULL.\n"); + return; + } + + 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", slotbuf); + 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); +} #endif @@ -470,6 +540,14 @@ static void mloop_evcb_recv(struct mloop_evsock *ev) 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(pack.data); + break; +#endif default: break; } @@ -550,6 +628,28 @@ void mloop_evcmd_usbdisk(char *img) mloop_evsock_send(&mloop, &pack); } +void mloop_evcmd_sdcard(char *img) +{ + struct mloop_evpack pack; + + if (img) { + if (strlen(img) > PACKET_LEN-5) { + // Need log + 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); +} + int mloop_evcmd_get_usbkbd_status(void) { return (usbkbd && usbkbd->attached ? 1 : 0); diff --git a/tizen/src/mloop_event.h b/tizen/src/mloop_event.h index ddfbc25ec3..1023f02985 100644 --- a/tizen/src/mloop_event.h +++ b/tizen/src/mloop_event.h @@ -56,6 +56,8 @@ void mloop_evcmd_touch(void); void mloop_evcmd_keyboard(void *data); void mloop_evcmd_ramdump(void); +void mloop_evcmd_sdcard(char* img); + #ifdef __cplusplus } #endif -- 2.34.1