kvm tools: define marcros for virtio device io space size and pci device number
PATCH 1/3 kvm tools: define marcros for virtio device io space size and pci device number
--- tools/kvm/blk-virtio.c | 6 ++++-- tools/kvm/include/kvm/ioport.h | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-)
tools/kvm/blk-virtio.c +4 -2
@@ -278,6 +278,8 @@ static struct pci_device_header blk_virtio_pci_device = { .irq_line = VIRTIO_BLK_IRQ, }; +#define PCI_VIRTIO_BLK_DEVNUM 1 +void blk_virtio__init (struct kvm *self) {if (!self->disk_image)
@@ -285,7 +287,7 @@ void blk_virtio__init(struct kvm *self) device.blk_config.capacity = self->disk_image->size /SECTOR_SIZE ; -pci__register (&blk_virtio_pci_device,1 ); +pci__register (&blk_virtio_pci_device,PCI_VIRTIO_BLK_DEVNUM ); -ioport__register (IOPORT_VIRTIO_BLK , &blk_virtio_io_ops,256 ); +ioport__register (IOPORT_VIRTIO_BLK , &blk_virtio_io_ops,IOPORT_VIRTIO_BLK_SIZE ); }
tools/kvm/include/kvm/ioport.h +5 -2
@@ -5,8 +5,11 @@#include <stdint.h> /* some ports we reserve for own use */ -#define IOPORT_DBG 0xe0 -#define IOPORT_VIRTIO_BLK 0xc200/* Virtio block device */ +#define IOPORT_DBG 0xe0 +#define IOPORT_VIRTIO_BLK 0xc200/* Virtio block device */ +#define IOPORT_VIRTIO_BLK_SIZE 256 +#define IOPORT_VIRTIO_CONSOLE 0xd200/* Virtio console device */ +#define IOPORT_VIRTIO_CONSOLE_SIZE 256struct kvm ;
Signature · 1 line
1.7.4.1
PATCH 2/3 kvm tools: add some helper functions for virt_queue
--- tools/kvm/include/kvm/virtqueue.h | 42 +++++++++++++++++++++++++++++++++++++ 1 files changed, 42 insertions(+), 0 deletions(-)
tools/kvm/include/kvm/virtqueue.h +42 -0
@@ -4,6 +4,9 @@#include <linux/virtio_ring.h> #include <stdint.h> +#include <sys/uio.h> + +#include "kvm/kvm.h" struct virt_queue {struct vring vring;
@@ -28,4 +31,43 @@ static inline struct vring_used_elem *virt_queue__get_used_elem(struct virt_queureturn &queue->vring.used->ring[queue->vring.used->idx++ % queue->vring.num]; } +static inline struct vring_used_elem *virt_queue__set_used_elem (struct virt_queue *queue,uint32_t head,uint32_t len) +{ +struct vring_used_elem *used_elem; + used_elem = &queue->vring.used->ring[queue->vring.used->idx++ % queue->vring.num]; + used_elem->id = head; + used_elem->len = len; +return used_elem; +} + +static inline bool virt_queue__available (struct virt_queue *vq) +{ +return vq->vring.avail->idx != vq->last_avail_idx; +} + +static inline uint16_t virt_queue__get_iov (struct virt_queue *queue,struct iovec iov[],uint16_t *out,uint16_t *in,struct kvm *kvm) +{ +struct vring_desc *desc; +uint16_t head, idx; + + idx = head =virt_queue__pop (queue); + *out = *in =0 ; + +do { + desc =virt_queue__get_desc (queue, idx); + iov[*out + *in].iov_base =guest_flat_to_host (kvm, desc->addr); + iov[*out + *in].iov_len = desc->len; +if (desc->flags &VRING_DESC_F_WRITE ) + (*in)++; +else + (*out)++; +if (desc->flags &VRING_DESC_F_NEXT ) + idx = desc->next; +else +break ; + }while (1 ); + +return head; +} +#endif /* KVM__VIRTQUEUE_H */
Signature · 1 line
1.7.4.1
PATCH 3/3 kvm tools: add virtio console support v2
In reply to Asias He- Consolidate all console related code to term.c
- Use timer based approach instead of thread to deal with user input
- Introduce --enable-virtio-console option, this option disables serial console output
NOTE:
Please add something like this:
T2:23:respawn:/sbin/getty -L hvc0 9600 vt100
to your /etc/inittab file to get a virtio console login.
--- tools/kvm/8250-serial.c | 40 +----- tools/kvm/Makefile | 2 + tools/kvm/console-virtio.c | 218 ++++++++++++++++++++++++++++++++ tools/kvm/include/kvm/8250-serial.h | 2 +- tools/kvm/include/kvm/console-virtio.h | 9 ++ tools/kvm/include/kvm/term.h | 17 +++ tools/kvm/main.c | 48 ++----- tools/kvm/term.c | 89 +++++++++++++ 8 files changed, 357 insertions(+), 68 deletions(-) create mode 100644 tools/kvm/console-virtio.c create mode 100644 tools/kvm/include/kvm/console-virtio.h create mode 100644 tools/kvm/include/kvm/term.h create mode 100644 tools/kvm/term.c
tools/kvm/8250-serial.c +7 -33
@@ -3,12 +3,11 @@#include "kvm/read-write.h" #include "kvm/ioport.h" #include "kvm/util.h" +#include "kvm/term.h" #include "kvm/kvm.h" #include <linux/serial_reg.h> -#include <stdbool.h> -#include <poll.h> struct serial8250_device {uint16_t iobase;
@@ -54,26 +53,6 @@ static struct serial8250_device devices[] = { }, }; -static int read_char (int fd) -{ -char c; - -if (read_in_full (fd, &c,1 ) ==0 ) -return -1 ; - -return c; -} - -static bool is_readable (int fd) -{ -struct pollfd pollfd = (struct pollfd ) { - .fd = fd, - .events =POLLIN , - }; - -return poll (&pollfd,1 ,0 ) >0 ; -} -static void serial8250__receive (struct kvm *self,struct serial8250_device *dev) {int c;
@@ -81,10 +60,11 @@ static void serial8250__receive(struct kvm *self, struct serial8250_device *dev)if (dev->lsr &UART_LSR_DR )return ; -if (!is_readable (STDIN_FILENO )) +if (!term_readable (CONSOLE_8250 ))return ; - c =read_char (STDIN_FILENO ); + c =term_getc (CONSOLE_8250 ); +if (c <0 )return ;
@@ -95,7 +75,7 @@ static void serial8250__receive(struct kvm *self, struct serial8250_device *dev)/* * Interrupts are injected for ttyS0 only. */ -void serial8250__interrupt (struct kvm *self) +void serial8250__inject_interrupt (struct kvm *self) {struct serial8250_device *dev = &devices[0 ];
@@ -170,15 +150,9 @@ static bool serial8250_out(struct kvm *self, uint16_t port, void *data, int size }else {switch (offset) {case UART_TX : { -char *p = data; -int i; - +char *addr = data;if (!(dev->mcr &UART_MCR_LOOP )) { -while (count--) { -for (i =0 ; i < size; i++) -fprintf (stdout,"%c" , *p++); - } -fflush (stdout); +term_putc (CONSOLE_8250 , addr, size * count); } dev->iir =UART_IIR_NO_INT ;break ;
tools/kvm/Makefile +2 -0
@@ -14,6 +14,7 @@ TAGS = ctags OBJS += 8250-serial.o OBJS += blk-virtio.o +OBJS += console-virtio.o OBJS += cpuid.o OBJS += read-write.o OBJS += disk-image.o
@@ -24,6 +25,7 @@ OBJS += main.o OBJS += mmio.o OBJS += pci.o OBJS += util.o +OBJS += term.o DEPS := $(patsubst %.o,%.d,$(OBJS))
tools/kvm/console-virtio.c new file +218 -0
218 lines not on this page · raw message
tools/kvm/include/kvm/8250-serial.h +1 -1
@@ -4,6 +4,6 @@struct kvm ;void serial8250__init (struct kvm *kvm); -void serial8250__interrupt (struct kvm *kvm); +void serial8250__inject_interrupt (struct kvm *kvm);#endif /* KVM__8250_SERIAL_H */
tools/kvm/include/kvm/console-virtio.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef KVM__CONSOLE_VIRTIO_H +#define KVM__CONSOLE_VIRTIO_H + +struct kvm ; + +void virtio_console__init (struct kvm *self); +void virtio_console__inject_interrupt (struct kvm *self); + +#endif /* KVM__CONSOLE_VIRTIO_H */
tools/kvm/include/kvm/term.h new file +17 -0
@@ -0,0 +1,17 @@ +#ifndef KVM__TERM_H +#define KVM__TERM_H + +#include <sys/uio.h> + +#define CONSOLE_8250 1 +#define CONSOLE_VIRTIO 2 + +int term_putc_iov (int who,struct iovec *iov,int iovcnt); +int term_getc_iov (int who,struct iovec *iov,int iovcnt); +int term_putc (int who,char *addr,int cnt); +int term_getc (int who); + +bool term_readable (int who); +void term_init (void ); + +#endif /* KVM__TERM_H */
tools/kvm/main.c +14 -34
115 lines not on this page · raw message
tools/kvm/term.c new file +89 -0
89 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Re: [PATCH 3/3] kvm tools: add virtio console support v2
Hi Asias,
Quoted 11 lines · Asias He
- Consolidate all console related code to
term.c
- Use timer based approach instead of thread to deal with user input
- Introduce --enable-virtio-console option, this option disables serial console outputNOTE:
Please add something like this:
T2:23:respawn:/sbin/getty -L hvc0 9600 vt100
to your/etc/inittabfile to get a virtio console login.Signed-off-by Asias He<[email protected]>
Quoted 9 lines
--- tools/kvm/8250-serial.c | 40 +----- tools/kvm/Makefile | 2 + tools/kvm/console-virtio.c | 218 ++++++++++++++++++++++++++++++++ tools/kvm/include/kvm/8250-serial.h | 2 +- tools/kvm/include/kvm/console-virtio.h | 9 ++ tools/kvm/include/kvm/term.h | 17 +++ tools/kvm/main.c | 48 ++----- tools/kvm/term.c | 89 +++++++++++++
Is it too much trouble to ask you to split this patch into two: (1) the term.c refactoring and (2) virtio console implementation? That would make the series much easier to review.
Pekka
Re: [PATCH 3/3] kvm tools: add virtio console support v2
Quoted 25 lines · Pekka Enberg
Hi Asias,
Quoted 11 lines · Asias He
- Consolidate all console related code to
term.c
- Use timer based approach instead of thread to deal with user input
- Introduce --enable-virtio-console option, this option disables serial console outputNOTE:
Please add something like this:
T2:23:respawn:/sbin/getty -L hvc0 9600 vt100
to your/etc/inittabfile to get a virtio console login.Signed-off-by Asias He<[email protected]>Quoted 10 lines
--- tools/kvm/8250-serial.c | 40 +----- tools/kvm/Makefile | 2 + tools/kvm/console-virtio.c | 218 ++++++++++++++++++++++++++++++++ tools/kvm/include/kvm/8250-serial.h | 2 +- tools/kvm/include/kvm/console-virtio.h | 9 ++ tools/kvm/include/kvm/term.h | 17 +++ tools/kvm/main.c | 48 ++----- tools/kvm/term.c | 89 +++++++++++++
Quoted 4 lines
Is it too much trouble to ask you to split this patch into two: (1) the
term.crefactoring and (2) virtio console implementation? That would make the series much easier to review.
Hi, Pekka
I have split the patch and sent it out.
Signature · 2 lines
Best Regards, Asias He
Interesting overload of the kvm mailing list. Intended for changes to the 'native kvm' (ie., tools/kvm)?
David
Quoted 47 lines · Asias He
Signed-off-by Asias He <[email protected]>--- tools/kvm/blk-virtio.c | 6 ++++-- tools/kvm/include/kvm/ioport.h | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-)tools/kvm/blk-virtio.c +4
-2@@ -278,6 +278,8 @@ static struct pci_device_header blk_virtio_pci_device = { .irq_line = VIRTIO_BLK_IRQ, }; +#define PCI_VIRTIO_BLK_DEVNUM 1 +void blk_virtio__init (struct kvm *self) {if (!self->disk_image)@@ -285,7 +287,7 @@ void blk_virtio__init(struct kvm *self) device.blk_config.capacity = self->disk_image->size /SECTOR_SIZE ; -pci__register (&blk_virtio_pci_device,1 ); +pci__register (&blk_virtio_pci_device,PCI_VIRTIO_BLK_DEVNUM ); -ioport__register (IOPORT_VIRTIO_BLK , &blk_virtio_io_ops,256 ); +ioport__register (IOPORT_VIRTIO_BLK , &blk_virtio_io_ops,IOPORT_VIRTIO_BLK_SIZE ); }tools/kvm/include/kvm/ioport.h +5
-2@@ -5,8 +5,11 @@#include <stdint.h> /* some ports we reserve for own use */ -#define IOPORT_DBG 0xe0 -#define IOPORT_VIRTIO_BLK 0xc200/* Virtio block device */ +#define IOPORT_DBG 0xe0 +#define IOPORT_VIRTIO_BLK 0xc200/* Virtio block device */ +#define IOPORT_VIRTIO_BLK_SIZE 256 +#define IOPORT_VIRTIO_CONSOLE 0xd200/* Virtio console device */ +#define IOPORT_VIRTIO_CONSOLE_SIZE 256struct kvm ;
Quoted 2 lines · David Ahern
Interesting overload of the kvm mailing list. Intended for changes to the 'native kvm' (ie.,
tools/kvm)?
Yup, we're starting to use kvm@ for our patches and discussion as suggested by Avi.
Quoted 6 lines · Pekka Enberg
Quoted 2 lines · David Ahern
Interesting overload of the kvm mailing list. Intended for changes to the 'native kvm' (ie.,
tools/kvm)?Yup, we're starting to use kvm@ for our patches and discussion as suggested by Avi.
Right, if the load becomes too high we can split it off to a separate list.
Signature · 1 line
error compiling committee.c: too many arguments to function