From f0c3f57d698801d05805c0da53b30570c2fc53b6 Mon Sep 17 00:00:00 2001 From: SeokYeon Hwang Date: Mon, 21 Jan 2013 22:36:56 +0900 Subject: [PATCH] emulator: Massive refactoring on vl.c, emulator.c Code cleans up and refactor massively (vl.c, emulator.c) Signed-off-by: SeokYeon Hwang --- tizen/src/emulator.c | 179 +++++++++++++++++++++++++++++++++++++++- tizen/src/emulator.h | 8 +- tizen/src/hw/gloffscreen_test.c | 2 +- tizen/src/hw/gloffscreen_test.h | 34 ++++++++ tizen/src/maru_common.h | 5 +- vl.c | 163 +++--------------------------------- 6 files changed, 233 insertions(+), 158 deletions(-) create mode 100644 tizen/src/hw/gloffscreen_test.h diff --git a/tizen/src/emulator.c b/tizen/src/emulator.c index 794d5c5..e67b69f 100644 --- a/tizen/src/emulator.c +++ b/tizen/src/emulator.c @@ -49,8 +49,8 @@ #include "qemu_socket.h" #include "build_info.h" #include "maru_err_table.h" -#include #include +#include "qemu-config.h" #if defined(CONFIG_WIN32) #include @@ -72,6 +72,8 @@ #endif #include "mloop_event.h" +#include "hw/maru_camera_common.h" +#include "hw/gloffscreen_test.h" MULTI_DEBUG_CHANNEL(qemu, main); @@ -84,6 +86,7 @@ MULTI_DEBUG_CHANNEL(qemu, main); #define LOGFILE "emulator.log" #define LCD_WIDTH_PREFIX "width=" #define LCD_HEIGHT_PREFIX "height=" + #define MIDBUF 128 int tizen_base_port; @@ -91,6 +94,14 @@ char tizen_target_path[MAXLEN]; char tizen_target_img_path[MAXLEN]; char logpath[MAXLEN]; +int enable_gl = 0; +int enable_yagl = 0; + +int is_webcam_enabled; + +#define LEN_MARU_KERNEL_CMDLINE 512 +gchar maru_kernel_cmdline[LEN_MARU_KERNEL_CMDLINE]; + static int _skin_argc; static char **_skin_argv; static int _qemu_argc; @@ -260,7 +271,7 @@ void make_shdmem(void) ERR("shmat failed\n"); return; } - sprintf(shared_memory, "%d", get_sdb_base_port() + 2); + sprintf(shared_memory, "%d", tizen_base_port + 2); INFO("shared memory key: %d, value: %s\n", SHMKEY, (char *)shared_memory); shmdt(shared_memory); #endif @@ -402,8 +413,10 @@ void set_image_and_log_path(char *qemu_argv) } else { strcpy(tizen_target_path, g_path_get_dirname(path)); } + strcpy(tizen_target_img_path, path); free(path); + strcpy(logpath, tizen_target_path); strcat(logpath, LOGS_SUFFIX); #ifdef CONFIG_WIN32 @@ -559,7 +572,7 @@ static void system_info(void) sys_info.freeram * (unsigned long long)sys_info.mem_unit / DIV); } - /* get linux distribution */ + /* get linux distribution information */ INFO("* Linux distribution infomation :\n"); char lsb_release_cmd[MAXLEN] = "lsb_release -d -r -c >> "; strcat(lsb_release_cmd, logpath); @@ -632,6 +645,166 @@ static void system_info(void) INFO("\n"); } +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) +{ + char http_proxy[MIDBUF] ={0}, https_proxy[MIDBUF] = {0,}, + ftp_proxy[MIDBUF] = {0,}, socks_proxy[MIDBUF] = {0,}, + dns1[MIDBUF] = {0}, dns2[MIDBUF] = {0}; + + tizen_base_port = get_sdb_base_port(); + + gethostproxy(http_proxy, https_proxy, ftp_proxy, socks_proxy); + gethostDNS(dns1, dns2); + + check_shdmem(); + socket_init(); + make_shdmem(); + + sdb_setup(); + + gchar * const tmp_str = g_strdup_printf(" sdb_port=%d," + " http_proxy=%s https_proxy=%s ftp_proxy=%s socks_proxy=%s" + " dns1=%s", tizen_base_port, + http_proxy, https_proxy, ftp_proxy, socks_proxy, + dns1, dns2); + + g_strlcat(maru_kernel_cmdline, tmp_str, LEN_MARU_KERNEL_CMDLINE); + + g_free(tmp_str); +} + +#define VIRTIOGL_DEV_NAME "virtio-gl-pci" +#ifdef CONFIG_GL_BACKEND +static void prepare_opengl_acceleration(void) +{ + int capability_check_gl = 0; + + if (enable_gl && enable_yagl) { + ERR("Error: only one openGL passthrough device can be used at one time!\n"); + exit(1); + } + + + if (enable_gl || enable_yagl) { + capability_check_gl = gl_acceleration_capability_check(); + + if (capability_check_gl != 0) { + enable_gl = enable_yagl = 0; + WARN("Warn: 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); + } + } + } + + gchar * const tmp_str = g_strdup_printf(" gles=%d yagl=%d", enable_gl, enable_yagl); + + g_strlcat(maru_kernel_cmdline, tmp_str, LEN_MARU_KERNEL_CMDLINE); + + g_free(tmp_str); +} +#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] 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"); + + g_strlcpy(maru_kernel_cmdline, kernel_cmdline, LEN_MARU_KERNEL_CMDLINE); + + // Prepare basic features + prepare_basic_features(); + + // Prepare GL acceleration +#ifdef CONFIG_GL_BACKEND + prepare_opengl_acceleration(); +#endif + + // 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"); diff --git a/tizen/src/emulator.h b/tizen/src/emulator.h index f5e93d8..69da953 100644 --- a/tizen/src/emulator.h +++ b/tizen/src/emulator.h @@ -31,12 +31,14 @@ /** * @file emulator.h - * @brief - header of file these are config struecture and defines in emulator + * @brief - header file for emulator.c */ #ifndef __EMULATOR_H__ #define __EMULATOR_H__ +#include "maru_common.h" + #define MAXLEN 512 #define MAXPACKETLEN 60 #define SHMKEY 26099 @@ -50,4 +52,8 @@ void extract_skin_info(int skin_argc, char **skin_argv); void prepare_maru(void); void check_shdmem(void); void make_shdmem(void); + +const gchar * prepare_maru_devices(const gchar * kernel_cmdline); +// FIXME: Necessary declaration of functions but produces error difficult to solve now +//int maru_device_check(QemuOpts *opts); #endif /* __EMULATOR_H__ */ diff --git a/tizen/src/hw/gloffscreen_test.c b/tizen/src/hw/gloffscreen_test.c index 99005a0..525447a 100644 --- a/tizen/src/hw/gloffscreen_test.c +++ b/tizen/src/hw/gloffscreen_test.c @@ -24,7 +24,7 @@ * THE SOFTWARE. */ -#include "gloffscreen.h" +#include "gloffscreen_test.h" #include #include diff --git a/tizen/src/hw/gloffscreen_test.h b/tizen/src/hw/gloffscreen_test.h new file mode 100644 index 0000000..4527043 --- /dev/null +++ b/tizen/src/hw/gloffscreen_test.h @@ -0,0 +1,34 @@ +/* + * Offscreen OpenGL abstraction layer + * + * Copyright (c) 2010 Intel Corporation + * Written by: + * Gordon Williams + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef __GLOFFSCREEN_TEST_H__ +#define __GLOFFSCREEN_TEST_H__ + +#include "gloffscreen.h" + +int gl_acceleration_capability_check(void); + +#endif /* __GLOFFSCREEN_TEST_H__ */ diff --git a/tizen/src/maru_common.h b/tizen/src/maru_common.h index caddfdb..e40fd69 100644 --- a/tizen/src/maru_common.h +++ b/tizen/src/maru_common.h @@ -31,8 +31,8 @@ */ /** - * @file emulator.h - * @brief - header of file these are config structures and defines in emulator + * @file maru_common.h + * @brief - header file that covers maru common features */ #ifndef __MARU_COMMON_H__ @@ -42,6 +42,7 @@ #include #include #include +#include // W/A for preserve larger continuous heap for RAM. extern void *preallocated_ptr; diff --git a/vl.c b/vl.c index 2640e41..98817ff 100644 --- a/vl.c +++ b/vl.c @@ -199,8 +199,10 @@ int qemu_main(int argc, char **argv, char **envp); #define MAX_VIRTIO_CONSOLES 1 #ifdef CONFIG_MARU -#define MARUCAM_DEV_NAME "maru_camera_pci" int skin_disabled = 0; +//virtio-gl +extern int enable_gl; +extern int enable_yagl; #endif static const char *data_dir; @@ -261,21 +263,6 @@ uint8_t *boot_splash_filedata; int boot_splash_filedata_size; uint8_t qemu_extra_params_fw[2]; -//virtio-gl -#define VIRTIOGL_DEV_NAME "virtio-gl-pci" -#if defined(CONFIG_MARU) -extern int gl_acceleration_capability_check(void); -int enable_gl = 0; -int enable_yagl = 0; -int capability_check_gl = 0; -#endif -#if defined(CONFIG_MARU) -#define WEBCAM_INFO_IGNORE 0x00 -#define WEBCAM_INFO_WRITE 0x04 -extern int marucam_device_check(int log_flag); -int is_webcam_enabled = 0; -#endif - typedef struct FWBootEntry FWBootEntry; @@ -1976,24 +1963,9 @@ static int device_init_func(QemuOpts *opts, void *opaque) { DeviceState *dev; -#ifdef CONFIG_GL_BACKEND -#if defined(CONFIG_MARU) - // 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 0; - } - } -#endif -#endif -#if defined(CONFIG_MARU) - if (!is_webcam_enabled) { - const char *driver = qemu_opt_get(opts, "driver"); - if (driver && (strcmp (driver, MARUCAM_DEV_NAME) == 0)) { - return 0; - } +#ifdef CONFIG_MARU + if(maru_device_check(opts) == -1) { + return 0; } #endif @@ -2434,34 +2406,13 @@ static void free_and_trace(gpointer mem) free(mem); } -// virtio-gl pci device lookup -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; -} - -int use_qemu_display = 0; //0:use tizen qemu sdl, 1:use original qemu sdl - int qemu_init_main_loop(void) { return main_loop_init(); } #ifdef CONFIG_MARU +int use_qemu_display = 0; //0:use tizen qemu sdl, 1:use original qemu sdl // W/A for preserve larger continuous heap for RAM. void *preallocated_ptr = 0; #endif @@ -2473,7 +2424,6 @@ int main(int argc, char **argv, char **envp) const char *icount_option = NULL; const char *initrd_filename; const char *kernel_filename, *kernel_cmdline; - char* tmp_cmdline = NULL; char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */ DisplayState *ds; DisplayChangeListener *dcl; @@ -2503,13 +2453,6 @@ int main(int argc, char **argv, char **envp) const char *trace_events = NULL; const char *trace_file = NULL; -#ifdef CONFIG_MARU - #define MIDBUF 128 - char http_proxy[MIDBUF] ={0},https_proxy[MIDBUF] = {0,}, - ftp_proxy[MIDBUF] = {0,}, socks_proxy[MIDBUF] = {0,}, - dns1[MIDBUF] = {0}, dns2[MIDBUF] = {0}; -#endif - atexit(qemu_run_exit_notifiers); error_set_progname(argv[0]); @@ -2742,32 +2685,7 @@ int main(int argc, char **argv, char **envp) qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg); break; case QEMU_OPTION_append: -#ifdef CONFIG_MARU - gethostproxy(http_proxy, https_proxy, ftp_proxy, socks_proxy); - gethostDNS(dns1, dns2); - - check_shdmem(); - socket_init(); - tizen_base_port = get_sdb_base_port(); - make_shdmem(); - - sdb_setup(); - - tmp_cmdline = g_strdup_printf("%s sdb_port=%d," - " http_proxy=%s https_proxy=%s ftp_proxy=%s socks_proxy=%s" - " dns1=%s dns2=%s", optarg, tizen_base_port, - http_proxy, https_proxy, ftp_proxy, socks_proxy, - dns1, dns2); - qemu_opts_set(qemu_find_opts("machine"), 0, "append", - tmp_cmdline); -#if 0 - fprintf(stdout, "kernel command: =========================================\n"); - fprintf(stdout, "%s\n", tmp_cmdline); - fprintf(stdout, "kernel command: =========================================\n"); -#endif -#else qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg); -#endif break; case QEMU_OPTION_dtb: qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg); @@ -3517,41 +3435,6 @@ int main(int argc, char **argv, char **envp) exit(0); } -#if defined(CONFIG_MARU) - if (enable_gl && enable_yagl) { - fprintf (stderr, "Error: only one openGL passthrough device can be used at one time!\n"); - exit(1); - } - - if (enable_gl || enable_yagl) { - capability_check_gl = gl_acceleration_capability_check(); - - if (capability_check_gl != 0) { - enable_gl = enable_yagl = 0; - fprintf (stderr, "Warn: GL acceleration was disabled due to the fail of GL check!\n"); - } - - // To check host gl driver capability and notify to guest. - gchar *tmp = tmp_cmdline; - tmp_cmdline = g_strdup_printf("%s gles=%d yagl=%d", tmp, enable_gl, enable_yagl); - qemu_opts_set(qemu_find_opts("machine"), 0, "append", tmp_cmdline); - fprintf(stdout, "kernel command: =========================================\n"); - fprintf(stdout, "%s\n", tmp_cmdline); - fprintf(stdout, "kernel command: =========================================\n"); - g_free(tmp); - - 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); - } - } - } - } -#endif - /* Open the logfile at this point, if necessary. We can't open the logfile * when encountering either of the logging options (-d or -D) because the * other one may be encountered later on the command line, changing the @@ -3703,30 +3586,6 @@ int main(int argc, char **argv, char **envp) kernel_cmdline = ""; } -#if defined(CONFIG_MARU) - is_webcam_enabled = marucam_device_check(WEBCAM_INFO_WRITE); - if (!is_webcam_enabled) { - fprintf (stderr, "[Webcam] Webcam support was disabled " - "due to the fail of webcam capability check!\n"); - } - - gchar const *tmp_cam_kcmd = kernel_cmdline; - kernel_cmdline = g_strdup_printf("%s enable_cam=%d", tmp_cam_kcmd, is_webcam_enabled); -// g_free(tmp_cam_kcmd); - - if (is_webcam_enabled) { - 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)) { - fprintf(stderr, "Failed to initialize the marucam device.\n"); - exit(1); - } - } - fprintf(stdout, "[Webcam] Webcam support was enabled.\n"); - } -#endif - linux_boot = (kernel_filename != NULL); if (!linux_boot && *kernel_cmdline != '\0') { @@ -3874,12 +3733,14 @@ int main(int argc, char **argv, char **envp) qdev_machine_init(); - machine->init(ram_size, boot_devices, - kernel_filename, kernel_cmdline, initrd_filename, cpu_model); #ifdef CONFIG_MARU - g_free((gchar *)tmp_cmdline); + // return variable points different address from input variable. + kernel_cmdline = prepare_maru_devices(kernel_cmdline); #endif + machine->init(ram_size, boot_devices, + kernel_filename, kernel_cmdline, initrd_filename, cpu_model); + cpu_synchronize_all_post_init(); set_numa_modes(); -- 2.7.4