From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LKrb3-0005ed-Jg for qemu-devel@nongnu.org; Thu, 08 Jan 2009 04:54:37 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LKrb2-0005e5-Lg for qemu-devel@nongnu.org; Thu, 08 Jan 2009 04:54:37 -0500 Received: from [199.232.76.173] (port=36619 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LKrb2-0005dt-Cy for qemu-devel@nongnu.org; Thu, 08 Jan 2009 04:54:36 -0500 Received: from mx2.redhat.com ([66.187.237.31]:36486) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LKrb1-0007Wf-K2 for qemu-devel@nongnu.org; Thu, 08 Jan 2009 04:54:36 -0500 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n089sWJC003176 for ; Thu, 8 Jan 2009 04:54:32 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n089sWnT030097 for ; Thu, 8 Jan 2009 04:54:32 -0500 Received: from dhcp-1-237.tlv.redhat.com (dhcp-1-237.tlv.redhat.com [10.35.1.237]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n089sVj7011534 for ; Thu, 8 Jan 2009 04:54:31 -0500 Received: from dhcp-1-237.tlv.redhat.com (localhost [127.0.0.1]) by dhcp-1-237.tlv.redhat.com (Postfix) with ESMTP id 2E5FB18D43A for ; Thu, 8 Jan 2009 11:55:44 +0200 (IST) From: Gleb Natapov Date: Thu, 08 Jan 2009 11:55:44 +0200 Message-ID: <20090108095544.12548.21251.stgit@dhcp-1-237.tlv.redhat.com> In-Reply-To: <20090108095533.12548.8211.stgit@dhcp-1-237.tlv.redhat.com> References: <20090108095533.12548.8211.stgit@dhcp-1-237.tlv.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH v3 2/5] Add vmchannel command line option. Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Signed-off-by: Gleb Natapov --- vl.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 74 insertions(+), 1 deletions(-) diff --git a/vl.c b/vl.c index 959be62..c076375 100644 --- a/vl.c +++ b/vl.c @@ -207,6 +207,13 @@ static int full_screen = 0; static int no_frame = 0; #endif int no_quit = 0; +#if defined(CONFIG_SLIRP) +#define MAX_VMCHANNEL_DEVICES 4 +struct VMChannel { + CharDriverState *hd; + int port; +} vmchannel_hds[MAX_VMCHANNEL_DEVICES]; +#endif CharDriverState *serial_hds[MAX_SERIAL_PORTS]; CharDriverState *parallel_hds[MAX_PARALLEL_PORTS]; #ifdef TARGET_I386 @@ -3948,6 +3955,9 @@ static void help(int exitcode) "-monitor dev redirect the monitor to char device 'dev'\n" "-serial dev redirect the serial port to char device 'dev'\n" "-parallel dev redirect the parallel port to char device 'dev'\n" +#if defined(CONFIG_SLIRP) + "-vmchannel di:DI,dev redirect the vmchannel device with device id DI, to char device 'dev'\n" +#endif "-pidfile file Write PID to 'file'\n" "-S freeze CPU at startup (use 'c' to start execution)\n" "-s wait gdb connection to port\n" @@ -4062,6 +4072,9 @@ enum { QEMU_OPTION_monitor, QEMU_OPTION_serial, QEMU_OPTION_parallel, +#if defined(CONFIG_SLIRP) + QEMU_OPTION_vmchannel, +#endif QEMU_OPTION_loadvm, QEMU_OPTION_full_screen, QEMU_OPTION_no_frame, @@ -4171,6 +4184,9 @@ static const QEMUOption qemu_options[] = { { "monitor", HAS_ARG, QEMU_OPTION_monitor }, { "serial", HAS_ARG, QEMU_OPTION_serial }, { "parallel", HAS_ARG, QEMU_OPTION_parallel }, +#if defined(CONFIG_SLIRP) + { "vmchannel", 1, QEMU_OPTION_vmchannel }, +#endif { "loadvm", HAS_ARG, QEMU_OPTION_loadvm }, { "full-screen", 0, QEMU_OPTION_full_screen }, #ifdef CONFIG_SDL @@ -4469,6 +4485,20 @@ static void termsig_setup(void) #endif +#if defined(CONFIG_SLIRP) +static int vmchannel_can_read(void *opaque) +{ + struct VMChannel *vmc = (struct VMChannel*)opaque; + return slirp_socket_can_recv(4, vmc->port); +} + +static void vmchannel_read(void *opaque, const uint8_t *buf, int size) +{ + struct VMChannel *vmc = (struct VMChannel*)opaque; + slirp_socket_recv(4, vmc->port, buf, size); +} +#endif + int main(int argc, char **argv, char **envp) { #ifdef CONFIG_GDBSTUB @@ -4496,6 +4526,8 @@ int main(int argc, char **argv, char **envp) int serial_device_index; const char *parallel_devices[MAX_PARALLEL_PORTS]; int parallel_device_index; + char *vmchannel_devices[MAX_VMCHANNEL_DEVICES]; + int vmchannel_device_index; const char *loadvm = NULL; QEMUMachine *machine; const char *cpu_model; @@ -4569,6 +4601,10 @@ int main(int argc, char **argv, char **envp) parallel_devices[i] = NULL; parallel_device_index = 0; + for(i = 0; i < MAX_VMCHANNEL_DEVICES; i++) + vmchannel_devices[i] = NULL; + vmchannel_device_index = 0; + usb_devices_index = 0; nb_net_clients = 0; @@ -4963,7 +4999,15 @@ int main(int argc, char **argv, char **envp) parallel_devices[parallel_device_index] = optarg; parallel_device_index++; break; - case QEMU_OPTION_loadvm: +#if defined(CONFIG_SLIRP) + case QEMU_OPTION_vmchannel: + if (vmchannel_device_index >= MAX_VMCHANNEL_DEVICES) { + fprintf(stderr, "qemu: too many vmchannel devices\n"); + exit(1); + } + vmchannel_devices[vmchannel_device_index++] = optarg; +#endif + case QEMU_OPTION_loadvm: loadvm = optarg; break; case QEMU_OPTION_full_screen: @@ -5468,6 +5512,35 @@ int main(int argc, char **argv, char **envp) } } +#if defined(CONFIG_SLIRP) + for(i = 0; i < vmchannel_device_index; i++) { + char *devname = vmchannel_devices[i]; + long port; + char name[20]; + + if (!devname) + continue; + + port = strtol(devname, &devname, 10); + devname++; + if (port < 1 || port > 65535) { + fprintf(stderr, "vmchannel: wrong port number\n"); + exit(1); + } + snprintf(name, 20, "vmchannel%ld\n", port); + vmchannel_hds[i].hd = qemu_chr_open(name, devname); + if (!vmchannel_hds[i].hd) { + fprintf(stderr, "qemu: could not open vmchannel device '%s'\n", + devname); + exit(1); + } + vmchannel_hds[i].port = port; + slirp_add_exec(3, vmchannel_hds[i].hd, 4, port); + qemu_chr_add_handlers(vmchannel_hds[i].hd, vmchannel_can_read, + vmchannel_read, NULL, &vmchannel_hds[i]); + } +#endif + machine->init(ram_size, vga_ram_size, boot_devices, ds, kernel_filename, kernel_cmdline, initrd_filename, cpu_model);