kvm tools: Add optional parameter used in ioport callbacks
PATCH v3 1/8 kvm tools: Add optional parameter used in ioport callbacks
Allow specifying an optional parameter when registering an ioport range. The callback functions provided by the registering module will be called with the same parameter.
This may be used to keep context during callbacks on IO operations.
--- tools/kvm/hw/rtc.c | 10 +++--- tools/kvm/hw/serial.c | 6 ++-- tools/kvm/hw/vesa.c | 6 ++-- tools/kvm/include/kvm/ioport.h | 14 ++++++-- tools/kvm/ioport.c | 71 +++++++++++++++++---------------------- tools/kvm/pci.c | 12 +++--- tools/kvm/virtio/9p.c | 6 ++-- tools/kvm/virtio/blk.c | 6 ++-- tools/kvm/virtio/console.c | 6 ++-- tools/kvm/virtio/net.c | 6 ++-- tools/kvm/virtio/rng.c | 6 ++-- 11 files changed, 74 insertions(+), 75 deletions(-)
tools/kvm/hw/rtc.c +5 -5
@@ -19,7 +19,7 @@ static inline unsigned char bin2bcd(unsigned val)return ((val /10 ) <<4 ) + val %10 ; } -static bool cmos_ram_data_in (struct kvm *kvm,u16 port,void *data,int size,u32 count) +static bool cmos_ram_data_in (struct ioport *ioport,struct kvm *kvm,u16 port,void *data,int size,u32 count) {struct tm *tm;time_t ti;
@@ -52,7 +52,7 @@ static bool cmos_ram_data_in(struct kvm *kvm, u16 port, void *data, int size, u3return true; } -static bool cmos_ram_data_out (struct kvm *kvm,u16 port,void *data,int size,u32 count) +static bool cmos_ram_data_out (struct ioport *ioport,struct kvm *kvm,u16 port,void *data,int size,u32 count) {return true; }
@@ -62,7 +62,7 @@ static struct ioport_operations cmos_ram_data_ioport_ops = { .io_in = cmos_ram_data_in, }; -static bool cmos_ram_index_out (struct kvm *kvm,u16 port,void *data,int size,u32 count) +static bool cmos_ram_index_out (struct ioport *ioport,struct kvm *kvm,u16 port,void *data,int size,u32 count) {u8 value;
@@ -82,6 +82,6 @@ static struct ioport_operations cmos_ram_index_ioport_ops = {void rtc__init (void ) {/* PORT 0070-007F - CMOS RAM/RTC (REAL TIME CLOCK) */ -ioport__register (0x0070 , &cmos_ram_index_ioport_ops,1 ); -ioport__register (0x0071 , &cmos_ram_data_ioport_ops,1 ); +ioport__register (0x0070 , &cmos_ram_index_ioport_ops,1 ,NULL ); +ioport__register (0x0071 , &cmos_ram_data_ioport_ops,1 ,NULL ); }
tools/kvm/hw/serial.c +3 -3
@@ -164,7 +164,7 @@ static struct serial8250_device *find_device(u16 port)return NULL ; } -static bool serial8250_out (struct kvm *kvm,u16 port,void *data,int size,u32 count) +static bool serial8250_out (struct ioport *ioport,struct kvm *kvm,u16 port,void *data,int size,u32 count) {struct serial8250_device *dev;u16 offset;
@@ -252,7 +252,7 @@ out_unlock:return ret; } -static bool serial8250_in (struct kvm *kvm,u16 port,void *data,int size,u32 count) +static bool serial8250_in (struct ioport *ioport,struct kvm *kvm,u16 port,void *data,int size,u32 count) {struct serial8250_device *dev;u16 offset;
@@ -339,7 +339,7 @@ static struct ioport_operations serial8250_ops = {static void serial8250__device_init (struct kvm *kvm,struct serial8250_device *dev) { -ioport__register (dev->iobase, &serial8250_ops,8 ); +ioport__register (dev->iobase, &serial8250_ops,8 ,NULL );kvm__irq_line (kvm, dev->irq,0 ); }
tools/kvm/hw/vesa.c +3 -3
@@ -26,12 +26,12 @@static char videomem[VESA_MEM_SIZE ]; -static bool vesa_pci_io_in (struct kvm *kvm,u16 port,void *data,int size,u32 count) +static bool vesa_pci_io_in (struct ioport *ioport,struct kvm *kvm,u16 port,void *data,int size,u32 count) {return true; } -static bool vesa_pci_io_out (struct kvm *kvm,u16 port,void *data,int size,u32 count) +static bool vesa_pci_io_out (struct ioport *ioport,struct kvm *kvm,u16 port,void *data,int size,u32 count) {return true; }
@@ -75,7 +75,7 @@ void vesa__init(struct kvm *kvm)pci__register (&vesa_pci_device, dev); -ioport__register (IOPORT_VESA , &vesa_io_ops,IOPORT_VESA_SIZE ); +ioport__register (IOPORT_VESA , &vesa_io_ops,IOPORT_VESA_SIZE ,NULL );kvm__register_mmio (VESA_MEM_ADDR ,VESA_MEM_SIZE , &vesa_mmio_callback);
tools/kvm/include/kvm/ioport.h +11 -3
@@ -1,6 +1,8 @@#ifndef KVM__IOPORT_H #define KVM__IOPORT_H +#include "kvm/rbtree-interval.h" +#include <stdbool.h> #include <asm/types.h> #include <linux/types.h>
@@ -22,14 +24,20 @@struct kvm ; +struct ioport { +struct rb_int_node node; +struct ioport_operations *ops; +void *priv; +}; +struct ioport_operations { -bool (*io_in)(struct kvm *kvm,u16 port,void *data,int size,u32 count); -bool (*io_out)(struct kvm *kvm,u16 port,void *data,int size,u32 count); +bool (*io_in)(struct ioport *ioport,struct kvm *kvm,u16 port,void *data,int size,u32 count); +bool (*io_out)(struct ioport *ioport,struct kvm *kvm,u16 port,void *data,int size,u32 count); };void ioport__setup_legacy (void ); -void ioport__register (u16 port,struct ioport_operations *ops,int count); +void ioport__register (u16 port,struct ioport_operations *ops,int count,void *param);static inline u8 ioport__read8 (u8 *data) {
tools/kvm/ioport.c +31 -40
156 lines not on this page · raw message
tools/kvm/pci.c +6 -6
@@ -21,7 +21,7 @@ static void *pci_config_address_ptr(u16 port)return base + offset; } -static bool pci_config_address_out (struct kvm *kvm,u16 port,void *data,int size,u32 count) +static bool pci_config_address_out (struct ioport *ioport,struct kvm *kvm,u16 port,void *data,int size,u32 count) {void *p =pci_config_address_ptr (port);
@@ -30,7 +30,7 @@ static bool pci_config_address_out(struct kvm *kvm, u16 port, void *data, int sireturn true; } -static bool pci_config_address_in (struct kvm *kvm,u16 port,void *data,int size,u32 count) +static bool pci_config_address_in (struct ioport *ioport,struct kvm *kvm,u16 port,void *data,int size,u32 count) {void *p =pci_config_address_ptr (port);
@@ -44,7 +44,7 @@ static struct ioport_operations pci_config_address_ops = { .io_out = pci_config_address_out, }; -static bool pci_config_data_out (struct kvm *kvm,u16 port,void *data,int size,u32 count) +static bool pci_config_data_out (struct ioport *ioport,struct kvm *kvm,u16 port,void *data,int size,u32 count) {return true; }
@@ -67,7 +67,7 @@ static bool pci_device_exists(u8 bus_number, u8 device_number, u8 function_numbereturn dev !=NULL ; } -static bool pci_config_data_in (struct kvm *kvm,u16 port,void *data,int size,u32 count) +static bool pci_config_data_in (struct ioport *ioport,struct kvm *kvm,u16 port,void *data,int size,u32 count) {unsigned long start;u8 dev_num;
@@ -110,6 +110,6 @@ void pci__register(struct pci_device_header *dev, u8 dev_num)void pci__init (void ) { -ioport__register (PCI_CONFIG_DATA +0 , &pci_config_data_ops,4 ); -ioport__register (PCI_CONFIG_ADDRESS +0 , &pci_config_address_ops,4 ); +ioport__register (PCI_CONFIG_DATA +0 , &pci_config_data_ops,4 ,NULL ); +ioport__register (PCI_CONFIG_ADDRESS +0 , &pci_config_address_ops,4 ,NULL ); }
tools/kvm/virtio/9p.c +3 -3
@@ -91,7 +91,7 @@ static bool virtio_p9_dev_in(void *data, unsigned long offset, int size, u32 coureturn true; } -static bool virtio_p9_pci_io_in (struct kvm *kvm,u16 port,void *data,int size,u32 count) +static bool virtio_p9_pci_io_in (struct ioport *ioport,struct kvm *kvm,u16 port,void *data,int size,u32 count) {unsigned long offset;bool ret = true;
@@ -579,7 +579,7 @@ static void virtio_p9_do_io(struct kvm *kvm, void *param) } } -static bool virtio_p9_pci_io_out (struct kvm *kvm,u16 port,void *data,int size,u32 count) +static bool virtio_p9_pci_io_out (struct ioport *ioport,struct kvm *kvm,u16 port,void *data,int size,u32 count) {unsigned long offset;bool ret = true;
@@ -664,5 +664,5 @@ void virtio_9p__init(struct kvm *kvm, const char *root) virtio_p9_pci_device.irq_line = line;pci__register (&virtio_p9_pci_device, dev); -ioport__register (IOPORT_VIRTIO_P9 , &virtio_p9_io_ops,IOPORT_VIRTIO_P9_SIZE ); +ioport__register (IOPORT_VIRTIO_P9 , &virtio_p9_io_ops,IOPORT_VIRTIO_P9_SIZE ,NULL ); }
tools/kvm/virtio/blk.c +3 -3
@@ -73,7 +73,7 @@ static void virtio_blk_port2dev(u16 port, u16 base, u16 size, u16 *dev_idx, u16 *offset = port - (base + *dev_idx * size); } -static bool virtio_blk_pci_io_in (struct kvm *kvm,u16 port,void *data,int size,u32 count) +static bool virtio_blk_pci_io_in (struct ioport *ioport,struct kvm *kvm,u16 port,void *data,int size,u32 count) {struct blk_dev *bdev;u16 offset, dev_idx;
@@ -178,7 +178,7 @@ static void virtio_blk_do_io(struct kvm *kvm, void *param)virt_queue__trigger_irq (vq, bdev->pci_hdr.irq_line, &bdev->isr, kvm); } -static bool virtio_blk_pci_io_out (struct kvm *kvm,u16 port,void *data,int size,u32 count) +static bool virtio_blk_pci_io_out (struct ioport *ioport,struct kvm *kvm,u16 port,void *data,int size,u32 count) {struct blk_dev *bdev;u16 offset, dev_idx;
@@ -318,7 +318,7 @@ void virtio_blk__init(struct kvm *kvm, struct disk_image *disk)pci__register (&bdev->pci_hdr, dev); -ioport__register (blk_dev_base_addr, &virtio_blk_io_ops,IOPORT_VIRTIO_BLK_SIZE ); +ioport__register (blk_dev_base_addr, &virtio_blk_io_ops,IOPORT_VIRTIO_BLK_SIZE ,NULL ); }void virtio_blk__init_all (struct kvm *kvm)
tools/kvm/virtio/console.c +3 -3
@@ -111,7 +111,7 @@ static bool virtio_console_pci_io_device_specific_in(void *data, unsigned long oreturn true; } -static bool virtio_console_pci_io_in (struct kvm *kvm,u16 port,void *data,int size,u32 count) +static bool virtio_console_pci_io_in (struct ioport *ioport,struct kvm *kvm,u16 port,void *data,int size,u32 count) {unsigned long offset = port -IOPORT_VIRTIO_CONSOLE ;bool ret = true;
@@ -179,7 +179,7 @@ static void virtio_console_handle_callback(struct kvm *kvm, void *param) } -static bool virtio_console_pci_io_out (struct kvm *kvm,u16 port,void *data,int size,u32 count) +static bool virtio_console_pci_io_out (struct ioport *ioport,struct kvm *kvm,u16 port,void *data,int size,u32 count) {unsigned long offset = port -IOPORT_VIRTIO_CONSOLE ;bool ret = true;
@@ -250,5 +250,5 @@ void virtio_console__init(struct kvm *kvm) virtio_console_pci_device.irq_pin = pin; virtio_console_pci_device.irq_line = line;pci__register (&virtio_console_pci_device, dev); -ioport__register (IOPORT_VIRTIO_CONSOLE , &virtio_console_io_ops,IOPORT_VIRTIO_CONSOLE_SIZE ); +ioport__register (IOPORT_VIRTIO_CONSOLE , &virtio_console_io_ops,IOPORT_VIRTIO_CONSOLE_SIZE ,NULL ); }
tools/kvm/virtio/net.c +3 -3
@@ -164,7 +164,7 @@ static bool virtio_net_pci_io_device_specific_in(void *data, unsigned long offsereturn true; } -static bool virtio_net_pci_io_in (struct kvm *kvm,u16 port,void *data,int size,u32 count) +static bool virtio_net_pci_io_in (struct ioport *ioport,struct kvm *kvm,u16 port,void *data,int size,u32 count) {unsigned long offset = port -IOPORT_VIRTIO_NET ;bool ret = true;
@@ -228,7 +228,7 @@ static void virtio_net_handle_callback(struct kvm *kvm, u16 queue_index) } } -static bool virtio_net_pci_io_out (struct kvm *kvm,u16 port,void *data,int size,u32 count) +static bool virtio_net_pci_io_out (struct ioport *ioport,struct kvm *kvm,u16 port,void *data,int size,u32 count) {unsigned long offset = port -IOPORT_VIRTIO_NET ;bool ret = true;
@@ -394,7 +394,7 @@ void virtio_net__init(const struct virtio_net_parameters *params) pci_header.irq_pin = pin; pci_header.irq_line = line;pci__register (&pci_header, dev); -ioport__register (IOPORT_VIRTIO_NET , &virtio_net_io_ops,IOPORT_VIRTIO_NET_SIZE ); +ioport__register (IOPORT_VIRTIO_NET , &virtio_net_io_ops,IOPORT_VIRTIO_NET_SIZE ,NULL );virtio_net__io_thread_init (params->kvm); }
tools/kvm/virtio/rng.c +3 -3
@@ -48,7 +48,7 @@ struct rng_dev {static struct rng_dev rdev; -static bool virtio_rng_pci_io_in (struct kvm *kvm,u16 port,void *data,int size,u32 count) +static bool virtio_rng_pci_io_in (struct ioport *ioport,struct kvm *kvm,u16 port,void *data,int size,u32 count) {unsigned long offset;bool ret = true;
@@ -111,7 +111,7 @@ static void virtio_rng_do_io(struct kvm *kvm, void *param) } } -static bool virtio_rng_pci_io_out (struct kvm *kvm,u16 port,void *data,int size,u32 count) +static bool virtio_rng_pci_io_out (struct ioport *ioport,struct kvm *kvm,u16 port,void *data,int size,u32 count) {unsigned long offset;bool ret = true;
@@ -179,5 +179,5 @@ void virtio_rng__init(struct kvm *kvm) virtio_rng_pci_device.irq_line = line;pci__register (&virtio_rng_pci_device, dev); -ioport__register (IOPORT_VIRTIO_RNG , &virtio_rng_io_ops,IOPORT_VIRTIO_RNG_SIZE ); +ioport__register (IOPORT_VIRTIO_RNG , &virtio_rng_io_ops,IOPORT_VIRTIO_RNG_SIZE ,NULL ); }
Signature · 1 line
1.7.5.rc3
PATCH v3 2/8 kvm tools: Add basic ioport dynamic allocation
Add a very simple allocation of ioports.
This prevents the need to coordinate ioports between different modules.
--- tools/kvm/include/kvm/ioport.h | 7 ++++++- tools/kvm/ioport.c | 24 +++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-)
tools/kvm/include/kvm/ioport.h +6 -1
@@ -9,6 +9,9 @@/* some ports we reserve for own use */ #define IOPORT_DBG 0xe0 +#define IOPORT_START 0x6200 +#define IOPORT_SIZE 0x400 +#define IOPORT_VESA 0xa200#define IOPORT_VESA_SIZE 256#define IOPORT_VIRTIO_P9 0xb200/* Virtio 9P device */
@@ -22,6 +25,8 @@#define IOPORT_VIRTIO_RNG 0xf200/* Virtio network device */ #define IOPORT_VIRTIO_RNG_SIZE 256 +#define IOPORT_EMPTY USHRT_MAX +struct kvm ;struct ioport {
@@ -37,7 +42,7 @@ struct ioport_operations {void ioport__setup_legacy (void ); -void ioport__register (u16 port,struct ioport_operations *ops,int count,void *param); +u16 ioport__register (u16 port,struct ioport_operations *ops,int count,void *param);static inline u8 ioport__read8 (u8 *data) {
tools/kvm/ioport.c +23 -1
@@ -3,6 +3,9 @@#include "kvm/kvm.h" #include "kvm/util.h" +#include "kvm/rbtree-interval.h" +#include "kvm/mutex.h" +#include <linux/kvm.h> /* for KVM_EXIT_* */ #include <linux/types.h>
@@ -14,9 +17,23 @@#define ioport_node (n) rb_entry(n, struct ioport, node) +static u16 free_io_port_idx; +DEFINE_MUTEX (free_io_port_idx_lock);static struct rb_root ioport_tree =RB_ROOT ;bool ioport_debug; +static u16 ioport__find_free_port (void ) +{ +u16 free_port; + +mutex_lock (&free_io_port_idx_lock); + free_port =IOPORT_START + free_io_port_idx *IOPORT_SIZE ; + free_io_port_idx++; +mutex_unlock (&free_io_port_idx_lock); + +return free_port; +} +static struct ioport *ioport_search (struct rb_root *root,u64 addr) {struct rb_int_node *node;
@@ -61,10 +78,13 @@ static struct ioport_operations dummy_write_only_ioport_ops = { .io_out = dummy_io_out, }; -void ioport__register (u16 port,struct ioport_operations *ops,int count,void *param) +u16 ioport__register (u16 port,struct ioport_operations *ops,int count,void *param) {struct ioport *entry; +if (port ==IOPORT_EMPTY ) + port =ioport__find_free_port (); + entry =ioport_search (&ioport_tree, port);if (entry) {pr_warning ("ioport re-registered: %x" , port);
@@ -82,6 +102,8 @@ void ioport__register(u16 port, struct ioport_operations *ops, int count, void * };ioport_insert (&ioport_tree, entry); + +return port; }static const char *to_direction (int direction)
Signature · 1 line
1.7.5.rc3
PATCH v3 3/8 kvm tools: Use ioport context to control blk devices
In reply to Sasha LevinSince ioports now has the ability to pass context to its callbacks, we can implement multiple blk devices more efficiently.
We can get a ptr to the 'current' blk dev on each ioport call, which means that we don't need to keep track of the blk device allocation and ioport distribution within the module.
The advantages are easier management of multiple blk devices and removal of any hardcoded limits to the amount of possible blk devices.
--- tools/kvm/include/kvm/ioport.h | 2 - tools/kvm/virtio/blk.c | 71 +++++++++++++-------------------------- 2 files changed, 24 insertions(+), 49 deletions(-)
tools/kvm/include/kvm/ioport.h +0 -2
@@ -16,8 +16,6 @@#define IOPORT_VESA_SIZE 256#define IOPORT_VIRTIO_P9 0xb200/* Virtio 9P device */ #define IOPORT_VIRTIO_P9_SIZE 256 -#define IOPORT_VIRTIO_BLK 0xc200/* Virtio block device */ -#define IOPORT_VIRTIO_BLK_SIZE 0x200#define IOPORT_VIRTIO_CONSOLE 0xd200/* Virtio console device */ #define IOPORT_VIRTIO_CONSOLE_SIZE 256#define IOPORT_VIRTIO_NET 0xe200/* Virtio network device */
tools/kvm/virtio/blk.c +24 -47
156 lines not on this page · raw message
Signature · 1 line
1.7.5.rc3
PATCH v3 4/8 kvm tools: Add support for multiple virtio-rng devices
In reply to Sasha LevinSince multiple hardware rng devices of the same type are currently unsupported by the kernel, this serves more as an example of a basic virtio driver under kvm tools and can be used to debug the PCI layer.
--- tools/kvm/include/kvm/ioport.h | 2 - tools/kvm/include/kvm/parse-options.h | 9 +++ tools/kvm/include/kvm/virtio-rng.h | 1 + tools/kvm/kvm-run.c | 8 ++- tools/kvm/virtio/rng.c | 118 ++++++++++++++++++++++---------- 5 files changed, 96 insertions(+), 42 deletions(-)
tools/kvm/include/kvm/ioport.h +0 -2
@@ -20,8 +20,6 @@#define IOPORT_VIRTIO_CONSOLE_SIZE 256#define IOPORT_VIRTIO_NET 0xe200/* Virtio network device */ #define IOPORT_VIRTIO_NET_SIZE 256 -#define IOPORT_VIRTIO_RNG 0xf200/* Virtio network device */ -#define IOPORT_VIRTIO_RNG_SIZE 256#define IOPORT_EMPTY USHRT_MAX
tools/kvm/include/kvm/parse-options.h +9 -0
@@ -132,6 +132,15 @@ intptr_t defval; .help = (h) \ } +#define OPT_INCR (s, l, v, h) \ +{ \ + .type = OPTION_INCR, \ + .short_name = (s), \ + .long_name = (l), \ + .value = check_vtype(v, int *), \ + .help = (h) \ +} +#define OPT_GROUP (h) \ { \ .type = OPTION_GROUP, \
tools/kvm/include/kvm/virtio-rng.h +1 -0
@@ -4,5 +4,6 @@struct kvm ;void virtio_rng__init (struct kvm *kvm); +void virtio_rng__delete_all (struct kvm *kvm);#endif /* KVM__RNG_VIRTIO_H */
tools/kvm/kvm-run.c +5 -3
@@ -52,6 +52,7 @@ static __thread struct kvm_cpu *current_kvm_cpu;static u64 ram_size;static u8 image_count; +static int virtio_rng;static const char *kernel_cmdline;static const char *kernel_filename;static const char *vmlinux_filename;
@@ -66,7 +67,6 @@ static const char *script;static const char *virtio_9p_dir;static bool single_step;static bool readonly_image[MAX_DISK_IMAGES ]; -static bool virtio_rng;static bool vnc;extern bool ioport_debug;extern int active_console;
@@ -107,7 +107,7 @@ static const struct option options[] = {OPT_CALLBACK ('d' ,"disk" ,NULL ,"image" ,"Disk image" , img_name_parser),OPT_STRING ('\0' ,"console" , &console,"serial or virtio" ,"Console to use" ), -OPT_BOOLEAN ('\0' ,"rng" , &virtio_rng, +OPT_INCR ('\0' ,"rng" , &virtio_rng,"Enable virtio Random Number Generator" ),OPT_STRING ('\0' ,"kvm-dev" , &kvm_dev,"kvm-dev" ,"KVM device file" ), OPT_STRING('\0', "virtio-9p", &virtio_9p_dir, "root dir",
@@ -570,7 +570,8 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)virtio_console__init (kvm);if (virtio_rng) -virtio_rng__init (kvm); +while (virtio_rng--) +virtio_rng__init (kvm);if (!network) network =DEFAULT_NETWORK ;
@@ -631,6 +632,7 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix) }virtio_blk__delete_all (kvm); +virtio_rng__delete_all (kvm);disk_image__close_all (kvm->disks, image_count);kvm__delete (kvm);
tools/kvm/virtio/rng.c +81 -37
232 lines not on this page · raw message
Signature · 1 line
1.7.5.rc3
PATCH v3 5/8 kvm tools: Use dynamic IO port allocation in vesa driver
In reply to Sasha Levin--- tools/kvm/hw/vesa.c | 7 +++---- tools/kvm/include/kvm/ioport.h | 2 -- 2 files changed, 3 insertions(+), 6 deletions(-)
tools/kvm/hw/vesa.c +3 -4
@@ -49,7 +49,6 @@ static struct pci_device_header vesa_pci_device = { .class = 0x030000, .subsys_vendor_id = PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET, .subsys_id = PCI_SUBSYSTEM_ID_VESA, - .bar[0] = IOPORT_VESA | PCI_BASE_ADDRESS_SPACE_IO, .bar[1] = VESA_MEM_ADDR | PCI_BASE_ADDRESS_SPACE_MEMORY, };
@@ -66,17 +65,17 @@ void vesa__init(struct kvm *kvm) {u8 dev, line, pin;pthread_t thread; +u16 vesa_base_addr;if (irq__register_device (PCI_DEVICE_ID_VESA , &dev, &pin, &line) <0 )return ; vesa_pci_device.irq_pin = pin; vesa_pci_device.irq_line = line; - + vesa_base_addr =ioport__register (IOPORT_EMPTY , &vesa_io_ops,IOPORT_SIZE ,NULL ); + vesa_pci_device.bar[0 ] = vesa_base_addr |PCI_BASE_ADDRESS_SPACE_IO ;pci__register (&vesa_pci_device, dev); -ioport__register (IOPORT_VESA , &vesa_io_ops,IOPORT_VESA_SIZE ,NULL ); -kvm__register_mmio (VESA_MEM_ADDR ,VESA_MEM_SIZE , &vesa_mmio_callback);pthread_create (&thread,NULL , vesa__dovnc, kvm);
tools/kvm/include/kvm/ioport.h +0 -2
@@ -12,8 +12,6 @@#define IOPORT_START 0x6200#define IOPORT_SIZE 0x400 -#define IOPORT_VESA 0xa200 -#define IOPORT_VESA_SIZE 256#define IOPORT_VIRTIO_P9 0xb200/* Virtio 9P device */ #define IOPORT_VIRTIO_P9_SIZE 256#define IOPORT_VIRTIO_CONSOLE 0xd200/* Virtio console device */
Signature · 1 line
1.7.5.rc3
PATCH v3 6/8 kvm tools: Use dynamic IO port allocation in 9p driver
In reply to Sasha Levin--- tools/kvm/include/kvm/ioport.h | 2 -- tools/kvm/virtio/9p.c | 12 +++++++----- 2 files changed, 7 insertions(+), 7 deletions(-)
tools/kvm/include/kvm/ioport.h +0 -2
@@ -12,8 +12,6 @@#define IOPORT_START 0x6200#define IOPORT_SIZE 0x400 -#define IOPORT_VIRTIO_P9 0xb200/* Virtio 9P device */ -#define IOPORT_VIRTIO_P9_SIZE 256#define IOPORT_VIRTIO_CONSOLE 0xd200/* Virtio console device */ #define IOPORT_VIRTIO_CONSOLE_SIZE 256#define IOPORT_VIRTIO_NET 0xe200/* Virtio network device */
tools/kvm/virtio/9p.c +7 -5
@@ -50,7 +50,6 @@ static struct pci_device_header virtio_p9_pci_device = { .class = 0x010000, .subsys_vendor_id = PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET, .subsys_id = VIRTIO_ID_9P, - .bar[0] = IOPORT_VIRTIO_P9 | PCI_BASE_ADDRESS_SPACE_IO, };struct p9_dev {
@@ -59,6 +58,7 @@ struct p9_dev {u16 config_vector;u32 features;struct virtio_9p_config *config; +u16 base_addr;/* virtio queue */ u16 queue_selector;
@@ -96,7 +96,7 @@ static bool virtio_p9_pci_io_in(struct ioport *ioport, struct kvm *kvm, u16 portunsigned long offset;bool ret = true; - offset = port -IOPORT_VIRTIO_P9 ; + offset = port - p9dev.base_addr;switch (offset) {case VIRTIO_PCI_HOST_FEATURES :
@@ -584,7 +584,7 @@ static bool virtio_p9_pci_io_out(struct ioport *ioport, struct kvm *kvm, u16 porunsigned long offset;bool ret = true; - offset = port -IOPORT_VIRTIO_P9 ; + offset = port - p9dev.base_addr;switch (offset) {case VIRTIO_MSI_QUEUE_VECTOR :
@@ -636,6 +636,7 @@ void virtio_9p__init(struct kvm *kvm, const char *root) {u8 pin, line, dev;u32 i, root_len; +u16 p9_base_addr; p9dev.config =calloc (1 ,sizeof (*p9dev.config) +sizeof (VIRTIO_P9_TAG ));if (p9dev.config ==NULL )
@@ -662,7 +663,8 @@ void virtio_9p__init(struct kvm *kvm, const char *root) virtio_p9_pci_device.irq_pin = pin; virtio_p9_pci_device.irq_line = line; + p9_base_addr =ioport__register (IOPORT_EMPTY , &virtio_p9_io_ops,IOPORT_SIZE ,NULL ); + virtio_p9_pci_device.bar[0 ] = p9_base_addr |PCI_BASE_ADDRESS_SPACE_IO ; + p9dev.base_addr = p9_base_addr;pci__register (&virtio_p9_pci_device, dev); - -ioport__register (IOPORT_VIRTIO_P9 , &virtio_p9_io_ops,IOPORT_VIRTIO_P9_SIZE ,NULL ); }
Signature · 1 line
1.7.5.rc3
PATCH v3 7/8 kvm tools: Use dynamic IO port allocation in virtio-console
In reply to Sasha Levin--- tools/kvm/include/kvm/ioport.h | 2 -- tools/kvm/virtio/console.c | 11 +++++++---- 2 files changed, 7 insertions(+), 6 deletions(-)
tools/kvm/include/kvm/ioport.h +0 -2
@@ -12,8 +12,6 @@#define IOPORT_START 0x6200#define IOPORT_SIZE 0x400 -#define IOPORT_VIRTIO_CONSOLE 0xd200/* Virtio console device */ -#define IOPORT_VIRTIO_CONSOLE_SIZE 256#define IOPORT_VIRTIO_NET 0xe200/* Virtio network device */ #define IOPORT_VIRTIO_NET_SIZE 256
tools/kvm/virtio/console.c +7 -4
@@ -36,7 +36,6 @@ static struct pci_device_header virtio_console_pci_device = { .class = 0x078000, .subsys_vendor_id = PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET, .subsys_id = VIRTIO_ID_CONSOLE, - .bar[0] = IOPORT_VIRTIO_CONSOLE | PCI_BASE_ADDRESS_SPACE_IO, };struct con_dev {
@@ -50,6 +49,7 @@ struct con_dev {u8 status;u8 isr;u16 queue_selector; +u16 base_addr;void *jobs[VIRTIO_CONSOLE_NUM_QUEUES ]; };
@@ -113,7 +113,7 @@ static bool virtio_console_pci_io_device_specific_in(void *data, unsigned long ostatic bool virtio_console_pci_io_in (struct ioport *ioport,struct kvm *kvm,u16 port,void *data,int size,u32 count) { -unsigned long offset = port -IOPORT_VIRTIO_CONSOLE ; +unsigned long offset = port - cdev.base_addr;bool ret = true;mutex_lock (&cdev.mutex);
@@ -181,7 +181,7 @@ static void virtio_console_handle_callback(struct kvm *kvm, void *param)static bool virtio_console_pci_io_out (struct ioport *ioport,struct kvm *kvm,u16 port,void *data,int size,u32 count) { -unsigned long offset = port -IOPORT_VIRTIO_CONSOLE ; +unsigned long offset = port - cdev.base_addr;bool ret = true;mutex_lock (&cdev.mutex);
@@ -243,12 +243,15 @@ static struct ioport_operations virtio_console_io_ops = {void virtio_console__init (struct kvm *kvm) {u8 dev, line, pin; +u16 console_base_addr;if (irq__register_device (VIRTIO_ID_CONSOLE , &dev, &pin, &line) <0 )return ; virtio_console_pci_device.irq_pin = pin; virtio_console_pci_device.irq_line = line; + console_base_addr =ioport__register (IOPORT_EMPTY , &virtio_console_io_ops,IOPORT_SIZE ,NULL ); + virtio_console_pci_device.bar[0 ] = console_base_addr |PCI_BASE_ADDRESS_SPACE_IO ; + cdev.base_addr = console_base_addr;pci__register (&virtio_console_pci_device, dev); -ioport__register (IOPORT_VIRTIO_CONSOLE , &virtio_console_io_ops,IOPORT_VIRTIO_CONSOLE_SIZE ,NULL ); }
Signature · 1 line
1.7.5.rc3
PATCH v3 8/8 kvm tools: Use dynamic IO port allocation in virtio-net
In reply to Sasha Levin--- tools/kvm/include/kvm/ioport.h | 3 --- tools/kvm/virtio/net.c | 12 ++++++++---- 2 files changed, 8 insertions(+), 7 deletions(-)
tools/kvm/include/kvm/ioport.h +0 -3
@@ -12,9 +12,6 @@#define IOPORT_START 0x6200#define IOPORT_SIZE 0x400 -#define IOPORT_VIRTIO_NET 0xe200/* Virtio network device */ -#define IOPORT_VIRTIO_NET_SIZE 256 -#define IOPORT_EMPTY USHRT_MAXstruct kvm ;
tools/kvm/virtio/net.c +8 -4
@@ -37,7 +37,6 @@ static struct pci_device_header pci_header = { .class = 0x020000, .subsys_vendor_id = PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET, .subsys_id = VIRTIO_ID_NET, - .bar[0] = IOPORT_VIRTIO_NET | PCI_BASE_ADDRESS_SPACE_IO, };struct net_device {
@@ -51,6 +50,7 @@ struct net_device {u8 status;u8 isr;u16 queue_selector; +u16 base_addr;pthread_t io_rx_thread;pthread_mutex_t io_rx_lock;
@@ -166,7 +166,7 @@ static bool virtio_net_pci_io_device_specific_in(void *data, unsigned long offsestatic bool virtio_net_pci_io_in (struct ioport *ioport,struct kvm *kvm,u16 port,void *data,int size,u32 count) { -unsigned long offset = port -IOPORT_VIRTIO_NET ; +unsigned long offset = port - ndev.base_addr;bool ret = true;mutex_lock (&ndev.mutex);
@@ -230,7 +230,7 @@ static void virtio_net_handle_callback(struct kvm *kvm, u16 queue_index)static bool virtio_net_pci_io_out (struct ioport *ioport,struct kvm *kvm,u16 port,void *data,int size,u32 count) { -unsigned long offset = port -IOPORT_VIRTIO_NET ; +unsigned long offset = port - ndev.base_addr;bool ret = true;mutex_lock (&ndev.mutex);
@@ -387,14 +387,18 @@ void virtio_net__init(const struct virtio_net_parameters *params) {if (virtio_net__tap_init (params)) {u8 dev, line, pin; +u16 net_base_addr;if (irq__register_device (VIRTIO_ID_NET , &dev, &pin, &line) <0 )return ; pci_header.irq_pin = pin; pci_header.irq_line = line; + net_base_addr =ioport__register (IOPORT_EMPTY , &virtio_net_io_ops,IOPORT_SIZE ,NULL ); + pci_header.bar[0 ] = net_base_addr |PCI_BASE_ADDRESS_SPACE_IO ; + ndev.base_addr = net_base_addr; +pci__register (&pci_header, dev); -ioport__register (IOPORT_VIRTIO_NET , &virtio_net_io_ops,IOPORT_VIRTIO_NET_SIZE ,NULL );virtio_net__io_thread_init (params->kvm); }
Signature · 1 line
1.7.5.rc3