From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HNhYE-0008HF-1t for qemu-devel@nongnu.org; Sat, 03 Mar 2007 22:38:22 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HNhYB-0008H3-Jf for qemu-devel@nongnu.org; Sat, 03 Mar 2007 22:38:20 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HNhYB-0008H0-DM for qemu-devel@nongnu.org; Sat, 03 Mar 2007 22:38:19 -0500 Received: from wx-out-0506.google.com ([66.249.82.235]) by monty-python.gnu.org with esmtp (Exim 4.52) id 1HNhYA-0006Jb-T8 for qemu-devel@nongnu.org; Sat, 03 Mar 2007 22:38:19 -0500 Received: by wx-out-0506.google.com with SMTP id i30so1899780wxd for ; Sat, 03 Mar 2007 19:38:18 -0800 (PST) Message-ID: <45EA3F28.5030807@codemonkey.ws> Date: Sat, 03 Mar 2007 21:38:16 -0600 From: Anthony Liguori MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------030703040407020702060405" Subject: [Qemu-devel] [PATCH] Add info commands for serial/parallel devices 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 This is a multi-part message in MIME format. --------------030703040407020702060405 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Howdy, The following patch adds an info serial and an info parallel command. Besides providing useful information (especially for the serial port), it provides a method for management tools to connect to a running VM and what character devices the serial/parallel ports have been redirected to. The format of the info is similar to that of info block. Regards, Anthony Liguori --------------030703040407020702060405 Content-Type: text/x-patch; name="info-serial-parallel.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="info-serial-parallel.diff" diff -r 18e99d1e8814 hw/parallel.c --- a/hw/parallel.c Sat Mar 03 21:18:48 2007 -0600 +++ b/hw/parallel.c Sat Mar 03 21:33:07 2007 -0600 @@ -73,6 +73,11 @@ struct ParallelState { uint32_t last_read_offset; /* For debugging */ }; +void do_info_parallel_device(ParallelState *s) +{ + term_printf(" filename=%s", s->chr->filename); +} + static void parallel_update_irq(ParallelState *s) { if (s->irq_pending) diff -r 18e99d1e8814 hw/pc.c --- a/hw/pc.c Sat Mar 03 21:18:48 2007 -0600 +++ b/hw/pc.c Sat Mar 03 21:33:07 2007 -0600 @@ -442,6 +442,34 @@ static void pc_init_ne2k_isa(NICInfo *nd nb_ne2k++; } +static SerialState *serial_devices[MAX_SERIAL_PORTS]; + +void do_info_serial(void) +{ + int i; + for (i = 0; i < MAX_SERIAL_PORTS; i++) { + if (serial_devices[i]) { + term_printf("serial%d:", i); + do_info_serial_device(serial_devices[i]); + term_printf("\n"); + } + } +} + +static ParallelState *parallel_devices[MAX_PARALLEL_PORTS]; + +void do_info_parallel(void) +{ + int i; + for (i = 0; i < MAX_PARALLEL_PORTS; i++) { + if (parallel_devices[i]) { + term_printf("parallel%d:", i); + do_info_parallel_device(parallel_devices[i]); + term_printf("\n"); + } + } +} + /* PC hardware initialisation */ static void pc_init1(int ram_size, int vga_ram_size, int boot_device, DisplayState *ds, const char **fd_filename, int snapshot, @@ -668,14 +696,14 @@ static void pc_init1(int ram_size, int v for(i = 0; i < MAX_SERIAL_PORTS; i++) { if (serial_hds[i]) { - serial_init(&pic_set_irq_new, isa_pic, - serial_io[i], serial_irq[i], serial_hds[i]); + serial_devices[i] = serial_init(&pic_set_irq_new, isa_pic, + serial_io[i], serial_irq[i], serial_hds[i]); } } for(i = 0; i < MAX_PARALLEL_PORTS; i++) { if (parallel_hds[i]) { - parallel_init(parallel_io[i], parallel_irq[i], parallel_hds[i]); + parallel_devices[i] = parallel_init(parallel_io[i], parallel_irq[i], parallel_hds[i]); } } diff -r 18e99d1e8814 hw/serial.c --- a/hw/serial.c Sat Mar 03 21:18:48 2007 -0600 +++ b/hw/serial.c Sat Mar 03 21:33:07 2007 -0600 @@ -92,6 +92,31 @@ struct SerialState { int it_shift; }; +void do_info_serial_device(SerialState *s) +{ + int parity; + + if (!s) + return; + + term_printf(" filename="); + term_print_filename(s->chr->filename); + + if (s->lcr & 0x08) { + if (s->lcr & 0x10) + parity = 'E'; + else + parity = 'O'; + } else + parity = 'N'; + + if (s->divider) + term_printf(" speed=%d", 115200 / s->divider); + term_printf(" parity=%c", parity); + term_printf(" data bits=%d", (s->lcr & 0x03) + 5); + term_printf(" stop bits=%d", (s->lcr & 0x04) ? 2 : 1); +} + static void serial_update_irq(SerialState *s) { if ((s->lsr & UART_LSR_DR) && (s->ier & UART_IER_RDI)) { diff -r 18e99d1e8814 monitor.c --- a/monitor.c Sat Mar 03 21:18:48 2007 -0600 +++ b/monitor.c Sat Mar 03 21:33:07 2007 -0600 @@ -1311,6 +1311,10 @@ static term_cmd_t info_cmds[] = { "", "show the vnc server status"}, { "name", "", do_info_name, "", "show the current VM name" }, + { "serial", "", do_info_serial, + "", "show serial device information" }, + { "parallel", "", do_info_parallel, + "", "show parallel device information" }, { NULL, NULL, }, }; diff -r 18e99d1e8814 vl.c --- a/vl.c Sat Mar 03 21:18:48 2007 -0600 +++ b/vl.c Sat Mar 03 21:33:07 2007 -0600 @@ -2884,66 +2884,73 @@ CharDriverState *qemu_chr_open(const cha CharDriverState *qemu_chr_open(const char *filename) { const char *p; + CharDriverState *chr; if (!strcmp(filename, "vc")) { - return text_console_init(&display_state); + chr = text_console_init(&display_state); } else if (!strcmp(filename, "null")) { - return qemu_chr_open_null(); + chr = qemu_chr_open_null(); } else if (strstart(filename, "tcp:", &p)) { - return qemu_chr_open_tcp(p, 0, 0); + chr = qemu_chr_open_tcp(p, 0, 0); } else if (strstart(filename, "telnet:", &p)) { - return qemu_chr_open_tcp(p, 1, 0); + chr = qemu_chr_open_tcp(p, 1, 0); } else if (strstart(filename, "udp:", &p)) { - return qemu_chr_open_udp(p); + chr = qemu_chr_open_udp(p); } else if (strstart(filename, "mon:", &p)) { CharDriverState *drv = qemu_chr_open(p); if (drv) { drv = qemu_chr_open_mux(drv); monitor_init(drv, !nographic); - return drv; - } - printf("Unable to open driver: %s\n", p); - return 0; + chr = drv; + } else { + printf("Unable to open driver: %s\n", p); + return 0; + } } else #ifndef _WIN32 if (strstart(filename, "unix:", &p)) { - return qemu_chr_open_tcp(p, 0, 1); + chr = qemu_chr_open_tcp(p, 0, 1); } else if (strstart(filename, "file:", &p)) { - return qemu_chr_open_file_out(p); + chr = qemu_chr_open_file_out(p); } else if (strstart(filename, "pipe:", &p)) { - return qemu_chr_open_pipe(p); + chr = qemu_chr_open_pipe(p); } else if (!strcmp(filename, "pty")) { - return qemu_chr_open_pty(); + chr = qemu_chr_open_pty(); } else if (!strcmp(filename, "stdio")) { - return qemu_chr_open_stdio(); + chr = qemu_chr_open_stdio(); } else #endif #if defined(__linux__) if (strstart(filename, "/dev/parport", NULL)) { - return qemu_chr_open_pp(filename); + chr = qemu_chr_open_pp(filename); } else if (strstart(filename, "/dev/", NULL)) { - return qemu_chr_open_tty(filename); + chr = qemu_chr_open_tty(filename); } else #endif #ifdef _WIN32 if (strstart(filename, "COM", NULL)) { - return qemu_chr_open_win(filename); + chr = qemu_chr_open_win(filename); } else if (strstart(filename, "pipe:", &p)) { - return qemu_chr_open_win_pipe(p); + chr = qemu_chr_open_win_pipe(p); } else if (strstart(filename, "file:", &p)) { - return qemu_chr_open_win_file_out(p); - } + chr = qemu_chr_open_win_file_out(p); + } else #endif { return NULL; } + + if (chr) + chr->filename = strdup(filename); + + return chr; } void qemu_chr_close(CharDriverState *chr) diff -r 18e99d1e8814 vl.h --- a/vl.h Sat Mar 03 21:18:48 2007 -0600 +++ b/vl.h Sat Mar 03 21:33:07 2007 -0600 @@ -307,6 +307,7 @@ typedef struct CharDriverState { void *opaque; int focus; QEMUBH *bh; + char *filename; } CharDriverState; CharDriverState *qemu_chr_open(const char *filename); @@ -1019,10 +1020,16 @@ SerialState *serial_mm_init (SetIRQFunc target_ulong base, int it_shift, int irq, CharDriverState *chr); +void do_info_serial_device(SerialState *s); +void do_info_serial(void); + /* parallel.c */ typedef struct ParallelState ParallelState; ParallelState *parallel_init(int base, int irq, CharDriverState *chr); + +void do_info_parallel_device(ParallelState *s); +void do_info_parallel(void); /* i8259.c */ --------------030703040407020702060405--