maru: Change the device initialization routine. 31/19931/1
authorjinhyung.jo <jinhyung.jo@samsung.com>
Wed, 16 Apr 2014 06:50:26 +0000 (15:50 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Wed, 23 Apr 2014 06:13:39 +0000 (15:13 +0900)
Brightness, overlay and camera device can be added by option instead of forced initializing.
Remove unneccessary code, used to check devices(virtgl & camera)

Change-Id: Ie5cd5520ca17b7920342f6b2ae21e4c1f685c5e1
Signed-off-by: Jinhyung Jo <jinhyung.jo@samsung.com>
tizen/src/emulator.c
tizen/src/hw/maru_board.c
tizen/src/hw/maru_brightness.c
tizen/src/hw/maru_brightness.h
tizen/src/hw/maru_camera_common.h
tizen/src/hw/maru_camera_common_pci.c
tizen/src/hw/maru_overlay.c
tizen/src/hw/maru_overlay.h
vl.c

index 0bd636c..6fb8dfc 100644 (file)
@@ -96,7 +96,6 @@ char tizen_target_img_path[PATH_MAX];
 int enable_gl = 0;
 int enable_yagl = 0;
 int enable_spice = 0;
-int is_webcam_enabled;
 
 static int _skin_argc;
 static char **_skin_argv;
@@ -340,25 +339,6 @@ static void print_system_info(void)
     print_system_info_os();
 }
 
-typedef struct {
-    const char *device_name;
-    int found;
-} device_opt_finding_t;
-
-static int find_device_opt (QemuOpts *opts, void *opaque)
-{
-    device_opt_finding_t *devp = (device_opt_finding_t *) opaque;
-    if (devp->found == 1) {
-        return 0;
-    }
-
-    const char *str = qemu_opt_get (opts, "driver");
-    if (strcmp (str, devp->device_name) == 0) {
-        devp->found = 1;
-    }
-    return 0;
-}
-
 #define DEFAULT_QEMU_DNS_IP "10.0.2.3"
 static void prepare_basic_features(void)
 {
@@ -409,16 +389,13 @@ static void prepare_opengl_acceleration(void)
 
         if (capability_check_gl != 0) {
             enable_gl = enable_yagl = 0;
-            WARN("Warn: GL acceleration was disabled due to the fail of GL check!\n");
+            INFO("<WARNING> GL acceleration was disabled due to the fail of GL check!\n");
         }
     }
     if (enable_gl) {
-        device_opt_finding_t devp = {VIRTIOGL_DEV_NAME, 0};
-        qemu_opts_foreach(qemu_find_opts("device"), find_device_opt, &devp, 0);
-        if (devp.found == 0) {
-            if (!qemu_opts_parse(qemu_find_opts("device"), VIRTIOGL_DEV_NAME, 1)) {
-                exit(1);
-            }
+        if (!qemu_opts_parse(qemu_find_opts("device"), VIRTIOGL_DEV_NAME, 1)) {
+            ERR("Failed to initialize the virtio-gl device.\n");
+            exit(1);
         }
     }
 
@@ -430,36 +407,6 @@ static void prepare_opengl_acceleration(void)
 }
 #endif
 
-#define MARUCAM_DEV_NAME "maru_camera_pci"
-#define WEBCAM_INFO_IGNORE 0x00
-#define WEBCAM_INFO_WRITE 0x04
-static void prepare_host_webcam(void)
-{
-    is_webcam_enabled = marucam_device_check(WEBCAM_INFO_WRITE);
-
-    if (!is_webcam_enabled) {
-        INFO("[Webcam] <WARNING> Webcam support was disabled "
-                         "due to the fail of webcam capability check!\n");
-    }
-    else {
-        device_opt_finding_t devp = {MARUCAM_DEV_NAME, 0};
-        qemu_opts_foreach(qemu_find_opts("device"), find_device_opt, &devp, 0);
-        if (devp.found == 0) {
-            if (!qemu_opts_parse(qemu_find_opts("device"), MARUCAM_DEV_NAME, 1)) {
-                INFO("Failed to initialize the marucam device.\n");
-                exit(1);
-            }
-        }
-        INFO("[Webcam] Webcam support was enabled.\n");
-    }
-
-    gchar * const tmp_str = g_strdup_printf(" enable_cam=%d", is_webcam_enabled);
-
-    g_strlcat(maru_kernel_cmdline, tmp_str, LEN_MARU_KERNEL_CMDLINE);
-
-    g_free(tmp_str);
-}
-
 const gchar *prepare_maru_devices(const gchar *kernel_cmdline)
 {
     INFO("Prepare maru specified kernel command line\n");
@@ -474,36 +421,11 @@ const gchar *prepare_maru_devices(const gchar *kernel_cmdline)
     // Prepare basic features
     prepare_basic_features();
 
-    // Prepare host webcam
-    prepare_host_webcam();
-
     INFO("kernel command : %s\n", maru_kernel_cmdline);
 
     return maru_kernel_cmdline;
 }
 
-int maru_device_check(QemuOpts *opts)
-{
-#if defined(CONFIG_GL_BACKEND)
-    // virtio-gl pci device
-    if (!enable_gl) {
-        // ignore virtio-gl-pci device, even if users set it in option.
-        const char *driver = qemu_opt_get(opts, "driver");
-        if (driver && (strcmp (driver, VIRTIOGL_DEV_NAME) == 0)) {
-            return -1;
-        }
-    }
-#endif
-    if (!is_webcam_enabled) {
-        const char *driver = qemu_opt_get(opts, "driver");
-        if (driver && (strcmp (driver, MARUCAM_DEV_NAME) == 0)) {
-            return -1;
-        }
-    }
-
-    return 0;
-}
-
 void prepare_maru(void)
 {
     INFO("Prepare maru specified feature\n");
index c555731..e8bb5f1 100644 (file)
@@ -69,8 +69,6 @@
 #include "maru_common.h"
 #include "guest_debug.h"
 #include "maru_pm.h"
-#include "maru_brightness.h"
-#include "maru_overlay.h"
 #if defined(__linux__)
 #include <X11/Xlib.h>
 #endif
@@ -115,9 +113,6 @@ static void maru_device_init(void)
     struct work_queue *render_queue = NULL;
     struct winsys_interface *vigs_wsi = NULL;
 
-    pci_maru_overlay_init(pci_bus);
-    pci_maru_brightness_init(pci_bus);
-
     if (enable_vigs || enable_yagl) {
         render_queue = work_queue_create();
     }
index b65e15d..f4066c7 100644 (file)
@@ -41,7 +41,7 @@
 
 MULTI_DEBUG_CHANNEL(qemu, maru_brightness);
 
-#define QEMU_DEV_NAME           "MARU_BRIGHTNESS"
+#define QEMU_DEV_NAME           "maru_brightness"
 
 #define BRIGHTNESS_MEM_SIZE    (4 * 1024)    /* 4KB */
 #define BRIGHTNESS_REG_SIZE    256
@@ -56,7 +56,7 @@ enum {
     BRIGHTNESS_OFF = 0x04,
 };
 
-uint32_t brightness_level;
+uint32_t brightness_level = BRIGHTNESS_MAX;
 uint32_t brightness_off;
 pixman_color_t level_color;
 pixman_image_t *brightness_image;
@@ -206,12 +206,6 @@ static int brightness_initfn(PCIDevice *dev)
     return 0;
 }
 
-/* external interface */
-DeviceState *pci_maru_brightness_init(PCIBus *bus)
-{
-    return &pci_create_simple(bus, -1, QEMU_DEV_NAME)->qdev;
-}
-
 static void brightness_classinit(ObjectClass *klass, void *data)
 {
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
index 9ecaccb..2c0449f 100644 (file)
@@ -43,6 +43,4 @@ extern uint32_t brightness_off;
 extern uint8_t brightness_tbl[];
 extern pixman_image_t *brightness_image;
 
-DeviceState *pci_maru_brightness_init(PCIBus *bus);
-
 #endif /* MARU_BRIGHTNESS_H_ */
index e3a052d..45b1a38 100644 (file)
@@ -77,6 +77,7 @@ struct MaruCamState {
     QemuCond            thread_cond;
     QEMUBH              *tx_bh;
 
+    bool                initialized;
     bool                destroying;
     void                *vaddr;     /* vram ptr */
     uint32_t            isr;
index 0c40ffe..8f892c0 100644 (file)
@@ -200,11 +200,22 @@ static void marucam_tx_bh(void *opaque)
 /*
  *  Initialization function
  */
+
 static int marucam_initfn(PCIDevice *dev)
 {
     MaruCamState *s = DO_UPCAST(MaruCamState, dev, dev);
     uint8_t *pci_conf = s->dev.config;
 
+    /* Check available webcam
+     * If there is not one, we don't init this device
+     */
+    if (!marucam_device_check(1)) {
+        s->initialized = false;
+        ERR("Failed to check the camera device, "
+            "stop the camera initialization. You can *not* use the camera\n");
+        return 1;
+    }
+
     pci_config_set_interrupt_pin(pci_conf, 0x03);
 
     memory_region_init_ram(&s->vram, OBJECT(s), "marucamera.ram", MARUCAM_MEM_SIZE);
@@ -228,6 +239,7 @@ static int marucam_initfn(PCIDevice *dev)
     marucam_device_init(s);
 
     s->tx_bh = qemu_bh_new(marucam_tx_bh, s);
+    s->initialized = true;
     INFO("[%s] camera device was initialized.\n", __func__);
 
     return 0;
@@ -241,14 +253,15 @@ static void marucam_exitfn(PCIDevice *pci_dev)
     MaruCamState *s =
         OBJECT_CHECK(MaruCamState, pci_dev, MARU_PCI_CAMERA_DEVICE_NAME);
 
-    marucam_device_exit(s);
-    g_free(s->param);
-    qemu_cond_destroy(&s->thread_cond);
-    qemu_mutex_destroy(&s->thread_mutex);
-
-    memory_region_destroy(&s->vram);
-    memory_region_destroy(&s->mmio);
+    if (s->initialized) {
+        marucam_device_exit(s);
+        g_free(s->param);
+        qemu_cond_destroy(&s->thread_cond);
+        qemu_mutex_destroy(&s->thread_mutex);
 
+        memory_region_destroy(&s->vram);
+        memory_region_destroy(&s->mmio);
+    }
 
     INFO("[%s] camera device was released.\n", __func__);
 }
index 960b0cf..e21685e 100644 (file)
@@ -38,7 +38,7 @@
 
 MULTI_DEBUG_CHANNEL(qemu, maru_overlay);
 
-#define QEMU_DEV_NAME       "MARU_OVERLAY"
+#define QEMU_DEV_NAME       "maru_overlay"
 
 #define OVERLAY_MEM_SIZE    (8192 * 1024)   /* 4MB(overlay0) + 4MB(overlay1) */
 #define OVERLAY_REG_SIZE    256
@@ -253,12 +253,6 @@ static void overlay_exitfn(PCIDevice *dev)
     INFO("<%s>\n", __func__);
 }
 
-DeviceState *pci_maru_overlay_init(PCIBus *bus)
-{
-    INFO("Maru overlay was initailized!\n");
-    return &pci_create_simple(bus, -1, QEMU_DEV_NAME)->qdev;
-}
-
 static void overlay_classinit(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
index 06ea812..1f40885 100644 (file)
@@ -52,6 +52,4 @@ extern uint16_t overlay1_height;
 extern pixman_image_t *overlay0_image;
 extern pixman_image_t *overlay1_image;
 
-DeviceState *pci_maru_overlay_init(PCIBus *bus);
-
 #endif /* MARU_OVERLAY_H_ */
diff --git a/vl.c b/vl.c
index 6cf5fe3..b34f75a 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -2370,12 +2370,6 @@ static int device_init_func(QemuOpts *opts, void *opaque)
 {
     DeviceState *dev;
 
-#ifdef CONFIG_MARU
-    if(maru_device_check(opts) == -1) {
-        return 0;
-    }
-#endif
-       
     dev = qdev_device_add(opts);
     if (!dev)
         return -1;