From: Jack Lange Date: Wed, 9 Sep 2009 22:35:26 +0000 (-0500) Subject: modified pci io hooks to not use the dev_io hooks, which are too constrictive X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=8a441df14ef65bb559ce090249343ec1dac1a7fc modified pci io hooks to not use the dev_io hooks, which are too constrictive --- diff --git a/palacios/include/devices/pci.h b/palacios/include/devices/pci.h index 31e09ad..68ac2dc 100644 --- a/palacios/include/devices/pci.h +++ b/palacios/include/devices/pci.h @@ -63,10 +63,12 @@ struct v3_pci_bar { struct { int num_ports; uint16_t default_base_port; - int (*io_read)(ushort_t port, void * dst, uint_t length, struct vm_device * dev); - int (*io_write)(ushort_t port, void * src, uint_t length, struct vm_device * dev); + int (*io_read)(ushort_t port, void * dst, uint_t length, void * private_data); + int (*io_write)(ushort_t port, void * src, uint_t length, void * private_data); }; }; + + void * private_data; // Internal PCI data uint32_t val; @@ -75,8 +77,11 @@ struct v3_pci_bar { }; -#define PCI_IO_BASE(bar_val) (bar_val & 0xfffffffc) -#define PCI_MEM32_BASE(bar_val) (bar_val & 0xfffffff0) +#define PCI_IO_MASK 0xfffffffc +#define PCI_MEM32_MASK 0xfffffff0 + +#define PCI_IO_BASE(bar_val) (bar_val & PCI_IO_MASK) +#define PCI_MEM32_BASE(bar_val) (bar_val & PCI_MEM32_MASK) struct pci_device { diff --git a/palacios/src/devices/ide.c b/palacios/src/devices/ide.c index 363641a..1776e9c 100644 --- a/palacios/src/devices/ide.c +++ b/palacios/src/devices/ide.c @@ -626,7 +626,8 @@ static int dma_write(struct vm_device * dev, struct ide_channel * channel) { #define DMA_CHANNEL_FLAG 0x08 -static int write_dma_port(ushort_t port, void * src, uint_t length, struct vm_device * dev) { +static int write_dma_port(ushort_t port, void * src, uint_t length, void * private_data) { + struct vm_device * dev = (struct vm_device *)private_data; struct ide_internal * ide = (struct ide_internal *)(dev->private_data); uint16_t port_offset = port & (DMA_CHANNEL_FLAG - 1); uint_t channel_flag = (port & DMA_CHANNEL_FLAG) >> 3; @@ -708,7 +709,8 @@ static int write_dma_port(ushort_t port, void * src, uint_t length, struct vm_de } -static int read_dma_port(ushort_t port, void * dst, uint_t length, struct vm_device * dev) { +static int read_dma_port(ushort_t port, void * dst, uint_t length, void * private_data) { + struct vm_device * dev = (struct vm_device *)private_data; struct ide_internal * ide = (struct ide_internal *)(dev->private_data); uint16_t port_offset = port & (DMA_CHANNEL_FLAG - 1); uint_t channel_flag = (port & DMA_CHANNEL_FLAG) >> 3; @@ -1560,7 +1562,8 @@ static int ide_init(struct guest_info * vm, void * cfg_data) { bars[4].io_read = read_dma_port; bars[4].io_write = write_dma_port; - + bars[4].private_data = dev; + pci_dev = v3_pci_register_device(ide->pci_bus, PCI_STD_DEVICE, 0, sb_pci->dev_num, 1, "PIIX3_IDE", bars, pci_config_update, NULL, NULL, dev); diff --git a/palacios/src/devices/lnx_virtio_balloon.c b/palacios/src/devices/lnx_virtio_balloon.c index c29d900..fed0c83 100644 --- a/palacios/src/devices/lnx_virtio_balloon.c +++ b/palacios/src/devices/lnx_virtio_balloon.c @@ -184,7 +184,8 @@ static int handle_kick(struct vm_device * dev) { return 0; } -static int virtio_io_write(uint16_t port, void * src, uint_t length, struct vm_device * dev) { +static int virtio_io_write(uint16_t port, void * src, uint_t length, void * private_data) { + struct vm_device * dev = (struct vm_device *)private_data; struct virtio_balloon_state * virtio = (struct virtio_balloon_state *)dev->private_data; int port_idx = port % virtio->io_range_size; @@ -292,7 +293,8 @@ static int virtio_io_write(uint16_t port, void * src, uint_t length, struct vm_d } -static int virtio_io_read(uint16_t port, void * dst, uint_t length, struct vm_device * dev) { +static int virtio_io_read(uint16_t port, void * dst, uint_t length, void * private_data) { + struct vm_device * dev = (struct vm_device *)private_data; struct virtio_balloon_state * virtio = (struct virtio_balloon_state *)dev->private_data; int port_idx = port % virtio->io_range_size; @@ -473,6 +475,8 @@ static int virtio_init(struct guest_info * vm, void * cfg_data) { bars[0].io_read = virtio_io_read; bars[0].io_write = virtio_io_write; + bars[0].private_data = dev; + pci_dev = v3_pci_register_device(pci_bus, PCI_STD_DEVICE, 0, PCI_AUTO_DEV_NUM, 0, diff --git a/palacios/src/devices/lnx_virtio_blk.c b/palacios/src/devices/lnx_virtio_blk.c index e58ec10..f71b559 100644 --- a/palacios/src/devices/lnx_virtio_blk.c +++ b/palacios/src/devices/lnx_virtio_blk.c @@ -340,7 +340,8 @@ static int handle_kick(struct vm_device * dev) { return 0; } -static int virtio_io_write(uint16_t port, void * src, uint_t length, struct vm_device * dev) { +static int virtio_io_write(uint16_t port, void * src, uint_t length, void * private_data) { + struct vm_device * dev = (struct vm_device *)private_data; struct virtio_blk_state * virtio = (struct virtio_blk_state *)dev->private_data; int port_idx = port % virtio->io_range_size; @@ -447,7 +448,8 @@ static int virtio_io_write(uint16_t port, void * src, uint_t length, struct vm_d } -static int virtio_io_read(uint16_t port, void * dst, uint_t length, struct vm_device * dev) { +static int virtio_io_read(uint16_t port, void * dst, uint_t length, void * private_data) { + struct vm_device * dev = (struct vm_device *)private_data; struct virtio_blk_state * virtio = (struct virtio_blk_state *)dev->private_data; int port_idx = port % virtio->io_range_size; @@ -621,6 +623,7 @@ static int virtio_init(struct guest_info * vm, void * cfg_data) { bars[0].io_read = virtio_io_read; bars[0].io_write = virtio_io_write; + bars[0].private_data = dev; pci_dev = v3_pci_register_device(pci_bus, PCI_STD_DEVICE, 0, PCI_AUTO_DEV_NUM, 0, diff --git a/palacios/src/devices/lnx_virtio_sym.c b/palacios/src/devices/lnx_virtio_sym.c index e7fa1f0..8f4401e 100644 --- a/palacios/src/devices/lnx_virtio_sym.c +++ b/palacios/src/devices/lnx_virtio_sym.c @@ -156,7 +156,8 @@ static int handle_kick(struct vm_device * dev) { } -static int virtio_io_write(uint16_t port, void * src, uint_t length, struct vm_device * dev) { +static int virtio_io_write(uint16_t port, void * src, uint_t length, void * private_data) { + struct vm_device * dev = (struct vm_device *)private_data; struct virtio_sym_state * virtio = (struct virtio_sym_state *)dev->private_data; int port_idx = port % virtio->io_range_size; @@ -264,7 +265,8 @@ static int virtio_io_write(uint16_t port, void * src, uint_t length, struct vm_d } -static int virtio_io_read(uint16_t port, void * dst, uint_t length, struct vm_device * dev) { +static int virtio_io_read(uint16_t port, void * dst, uint_t length, void * private_data) { + struct vm_device * dev = (struct vm_device *)private_data; struct virtio_sym_state * virtio = (struct virtio_sym_state *)dev->private_data; int port_idx = port % virtio->io_range_size; @@ -407,6 +409,7 @@ static int virtio_init(struct guest_info * vm, void * cfg_data) { bars[0].io_read = virtio_io_read; bars[0].io_write = virtio_io_write; + bars[0].private_data = dev; pci_dev = v3_pci_register_device(pci_bus, PCI_STD_DEVICE, 0, PCI_AUTO_DEV_NUM, 0, diff --git a/palacios/src/devices/pci.c b/palacios/src/devices/pci.c index 0d11ed5..b65aefc 100644 --- a/palacios/src/devices/pci.c +++ b/palacios/src/devices/pci.c @@ -406,10 +406,11 @@ static int bar_update(struct pci_device * pci, int bar_num, uint32_t new_val) { PrintDebug("Rehooking PCI IO port (old port=%u) (new port=%u)\n", PCI_IO_BASE(bar->val) + i, PCI_IO_BASE(new_val) + i); - v3_dev_unhook_io(pci->vm_dev, PCI_IO_BASE(bar->val) + i); + v3_unhook_io_port(pci->vm_dev->vm, PCI_IO_BASE(bar->val) + i); - if (v3_dev_hook_io(pci->vm_dev, PCI_IO_BASE(new_val) + i, - bar->io_read, bar->io_write) == -1) { + if (v3_hook_io_port(pci->vm_dev->vm, PCI_IO_BASE(new_val) + i, + bar->io_read, bar->io_write, + bar->private_data) == -1) { PrintError("Could not hook PCI IO port (old port=%u) (new port=%u)\n", PCI_IO_BASE(bar->val) + i, PCI_IO_BASE(new_val) + i); @@ -673,8 +674,9 @@ static inline int init_bars(struct pci_device * pci_dev) { for (j = 0; j < pci_dev->bar[i].num_ports; j++) { // hook IO if (pci_dev->bar[i].default_base_port != 0xffff) { - if (v3_dev_hook_io(pci_dev->vm_dev, pci_dev->bar[i].default_base_port + j, - pci_dev->bar[i].io_read, pci_dev->bar[i].io_write) == -1) { + if (v3_hook_io_port(pci_dev->vm_dev->vm, pci_dev->bar[i].default_base_port + j, + pci_dev->bar[i].io_read, pci_dev->bar[i].io_write, + pci_dev->bar[i].private_data) == -1) { PrintError("Could not hook default io port %x\n", pci_dev->bar[i].default_base_port + j); return -1; } @@ -839,6 +841,7 @@ struct pci_device * v3_pci_register_device(struct vm_device * pci, //copy bars for (i = 0; i < 6; i ++) { pci_dev->bar[i].type = bars[i].type; + pci_dev->bar[i].private_data = bars[i].private_data; if (pci_dev->bar[i].type == PCI_BAR_IO) { pci_dev->bar[i].num_ports = bars[i].num_ports;