X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Fpci_passthrough.c;h=2506d77db172fe6105f03621b0845d6dbd340bac;hb=1423d1b79cde22d1967efb0465a9ca88a2b8a199;hp=ce4b334f6d1d46e9e780b513eb5435c1803604b9;hpb=123a1ba27ea09c8fa77a1b36ce625b43d7c48b14;p=palacios.git diff --git a/palacios/src/devices/pci_passthrough.c b/palacios/src/devices/pci_passthrough.c index ce4b334..2506d77 100644 --- a/palacios/src/devices/pci_passthrough.c +++ b/palacios/src/devices/pci_passthrough.c @@ -36,7 +36,7 @@ #include #include #include // must include this to avoid dependency issue -#include +#include #include #include @@ -147,7 +147,7 @@ static inline void pci_cfg_write8(uint32_t addr, uint8_t val) { // We initialize this -static int pci_bar_init(int bar_num, uint32_t * dst,void * private_data) { +static int pci_bar_init(int bar_num, uint32_t * dst, void * private_data) { struct vm_device * dev = (struct vm_device *)private_data; struct pt_dev_state * state = (struct pt_dev_state *)dev->private_data; const uint32_t bar_base_reg = 4; @@ -187,9 +187,12 @@ static int pci_bar_init(int bar_num, uint32_t * dst,void * private_data) { //v3_irq_restore(irq_state); - pbar->size = ~PCI_IO_BASE(max_val) + 1; + V3_Print("max_val = %x\n", max_val); + + pbar->size = (uint16_t)~PCI_IO_BASE(max_val) + 1; + V3_Print("IO Bar with %d (%x) ports %x->%x\n", pbar->size, pbar->size, pbar->addr, pbar->addr + pbar->size); // setup a set of null io hooks // This allows the guest to do passthrough IO to these ports // While still reserving them in the IO map @@ -231,7 +234,7 @@ static int pci_bar_init(int bar_num, uint32_t * dst,void * private_data) { PrintDebug("Adding 32 bit PCI mem region: start=0x%x, end=0x%x\n", pbar->addr, pbar->addr + pbar->size); - v3_add_shadow_mem(dev->vm, + v3_add_shadow_mem(dev->vm, V3_MEM_CORE_ANY, pbar->addr, pbar->addr + pbar->size - 1, pbar->addr); @@ -242,7 +245,7 @@ static int pci_bar_init(int bar_num, uint32_t * dst,void * private_data) { pbar->addr = PCI_MEM24_BASE(bar_val); pbar->size = ~PCI_MEM24_BASE(max_val) + 1; - v3_add_shadow_mem(dev->vm, + v3_add_shadow_mem(dev->vm, V3_MEM_CORE_ANY, pbar->addr, pbar->addr + pbar->size - 1, pbar->addr); @@ -258,8 +261,6 @@ static int pci_bar_init(int bar_num, uint32_t * dst,void * private_data) { } } - - // Initially the virtual bars match the physical ones @@ -275,15 +276,13 @@ static int pci_bar_init(int bar_num, uint32_t * dst,void * private_data) { state->virt_bars[bar_num].type, state->virt_bars[bar_num].addr, state->virt_bars[bar_num].size); - - // Update the pci subsystem versions *dst = bar_val; return 0; } -static int pt_io_read(uint16_t port, void * dst, uint_t length, void * priv_data) { +static int pt_io_read(struct guest_info * core, uint16_t port, void * dst, uint_t length, void * priv_data) { struct pt_bar * pbar = (struct pt_bar *)priv_data; int port_offset = port % pbar->size; @@ -302,7 +301,7 @@ static int pt_io_read(uint16_t port, void * dst, uint_t length, void * priv_data } -static int pt_io_write(uint16_t port, void * src, uint_t length, void * priv_data) { +static int pt_io_write(struct guest_info * core, uint16_t port, void * src, uint_t length, void * priv_data) { struct pt_bar * pbar = (struct pt_bar *)priv_data; int port_offset = port % pbar->size; @@ -332,7 +331,11 @@ static int pci_bar_write(int bar_num, uint32_t * src, void * private_data) { struct pt_bar * pbar = &(state->phys_bars[bar_num]); struct pt_bar * vbar = &(state->virt_bars[bar_num]); - PrintDebug("Bar update src=0x%x\n", *src); + PrintDebug("Bar update: bar_num=%d, src=0x%x\n", bar_num,*src); + PrintDebug("vbar is size=%u, type=%d, addr=0x%x, val=0x%x\n",vbar->size, vbar->type, vbar->addr, vbar->val); + PrintDebug("pbar is size=%u, type=%d, addr=0x%x, val=0x%x\n",pbar->size, pbar->type, pbar->addr, pbar->val); + + if (vbar->type == PT_BAR_NONE) { return 0; @@ -376,7 +379,7 @@ static int pci_bar_write(int bar_num, uint32_t * src, void * private_data) { } } else if (vbar->type == PT_BAR_MEM32) { // remove old mapping - struct v3_shadow_region * old_reg = v3_get_shadow_region(dev->vm, vbar->addr); + struct v3_shadow_region * old_reg = v3_get_shadow_region(dev->vm, V3_MEM_CORE_ANY, vbar->addr); if (old_reg == NULL) { // uh oh... @@ -399,7 +402,7 @@ static int pci_bar_write(int bar_num, uint32_t * src, void * private_data) { PrintDebug("Adding pci Passthrough remapping: start=0x%x, size=%d, end=0x%x\n", vbar->addr, vbar->size, vbar->addr + vbar->size); - v3_add_shadow_mem(dev->vm, + v3_add_shadow_mem(dev->vm, V3_MEM_CORE_ANY, vbar->addr, vbar->addr + vbar->size - 1, pbar->addr); @@ -487,7 +490,7 @@ static int find_real_pci_dev(uint16_t vendor_id, uint16_t device_id, struct pt_d -static int setup_virt_pci_dev(struct guest_info * info, struct vm_device * dev) { +static int setup_virt_pci_dev(struct v3_vm_info * vm_info, struct vm_device * dev) { struct pt_dev_state * state = (struct pt_dev_state *)dev->private_data; struct pci_device * pci_dev = NULL; struct v3_pci_bar bars[6]; @@ -513,7 +516,7 @@ static int setup_virt_pci_dev(struct guest_info * info, struct vm_device * dev) state->pci_dev = pci_dev; - v3_sym_map_pci_passthrough(info, pci_dev->bus_num, pci_dev->dev_num, pci_dev->fn_num); + v3_sym_map_pci_passthrough(vm_info, pci_dev->bus_num, pci_dev->dev_num, pci_dev->fn_num); return 0; @@ -529,11 +532,11 @@ static struct v3_device_ops dev_ops = { -static int irq_handler(struct guest_info * info, struct v3_interrupt * intr, void * private_data) { +static int irq_handler(struct v3_vm_info * vm, struct v3_interrupt * intr, void * private_data) { struct vm_device * dev = (struct vm_device *)private_data; struct pt_dev_state * state = (struct pt_dev_state *)dev->private_data; - // PrintDebug("Handling E1000 IRQ %d\n", intr->irq); +// PrintDebug("Handling E1000 IRQ %d\n", intr->irq); v3_pci_raise_irq(state->pci_bus, 0, state->pci_dev); @@ -545,10 +548,10 @@ static int irq_handler(struct guest_info * info, struct v3_interrupt * intr, voi -static int passthrough_init(struct guest_info * info, v3_cfg_tree_t * cfg) { +static int passthrough_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { struct pt_dev_state * state = V3_Malloc(sizeof(struct pt_dev_state)); struct vm_device * dev = NULL; - struct vm_device * pci = v3_find_dev(info, v3_cfg_val(cfg, "bus")); + struct vm_device * pci = v3_find_dev(vm, v3_cfg_val(cfg, "bus")); char * name = v3_cfg_val(cfg, "name"); memset(state, 0, sizeof(struct pt_dev_state)); @@ -564,7 +567,7 @@ static int passthrough_init(struct guest_info * info, v3_cfg_tree_t * cfg) { dev = v3_allocate_device(name, &dev_ops, state); - if (v3_attach_device(info, dev) == -1) { + if (v3_attach_device(vm, dev) == -1) { PrintError("Could not attach device %s\n", name); return -1; } @@ -579,9 +582,9 @@ static int passthrough_init(struct guest_info * info, v3_cfg_tree_t * cfg) { return 0; } - setup_virt_pci_dev(info, dev); + setup_virt_pci_dev(vm, dev); - v3_hook_irq(info, atoi(v3_cfg_val(cfg, "irq")), irq_handler, dev); + v3_hook_irq(vm, atoi(v3_cfg_val(cfg, "irq")), irq_handler, dev); // v3_hook_irq(info, 64, irq_handler, dev); return 0;