X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Fpci_passthrough.c;h=18e4ef49608085f1b6e129909cfe46fc90129c63;hp=816c237fb03feb13efbeaea7cca22dbe13302aa0;hb=0121a4503305424096e2b5c5bd3b6c3af2d813e5;hpb=0f29d2c0a099fae40a86791b6d40479de235efbf diff --git a/palacios/src/devices/pci_passthrough.c b/palacios/src/devices/pci_passthrough.c index 816c237..18e4ef4 100644 --- a/palacios/src/devices/pci_passthrough.c +++ b/palacios/src/devices/pci_passthrough.c @@ -35,18 +35,18 @@ #include #include #include - +#include // must include this to avoid dependency issue +#include #include #include -#include // Hardcoded... Are these standard?? #define PCI_CFG_ADDR 0xcf8 #define PCI_CFG_DATA 0xcfc -#define PCI_BUS_MAX 4 +#define PCI_BUS_MAX 7 #define PCI_DEV_MAX 32 #define PCI_FN_MAX 7 @@ -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 @@ -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,8 +276,6 @@ 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; @@ -451,7 +450,7 @@ static int find_real_pci_dev(uint16_t vendor_id, uint16_t device_id, struct pt_d } __attribute__((packed)) pci_hdr = {0}; - + //PrintDebug("Scanning PCI busses for vendor=%x, device=%x\n", vendor_id, device_id); for (i = 0, pci_addr.bus = 0; i < PCI_BUS_MAX; i++, pci_addr.bus++) { for (j = 0, pci_addr.dev = 0; j < PCI_DEV_MAX; j++, pci_addr.dev++) { for (k = 0, pci_addr.func = 0; k < PCI_FN_MAX; k++, pci_addr.func++) { @@ -459,6 +458,8 @@ static int find_real_pci_dev(uint16_t vendor_id, uint16_t device_id, struct pt_d v3_outdw(PCI_CFG_ADDR, pci_addr.value); pci_hdr.value = v3_indw(PCI_CFG_DATA); + //PrintDebug("\bus=%d, tvendor=%x, device=%x\n", pci_addr.bus, pci_hdr.vendor, pci_hdr.device); + if ((pci_hdr.vendor == vendor_id) && (pci_hdr.device == device_id)) { uint32_t * cfg_space = (uint32_t *)&state->real_hdr; @@ -504,13 +505,16 @@ static int setup_virt_pci_dev(struct guest_info * info, struct vm_device * dev) bus_num, -1, 0, state->name, bars, pt_config_update, NULL, NULL, - dev, dev); + dev); // This will overwrite the bar registers.. but that should be ok. memcpy(pci_dev->config_space, (uint8_t *)&(state->real_hdr), sizeof(struct pci_config_header)); state->pci_dev = pci_dev; + v3_sym_map_pci_passthrough(info, pci_dev->bus_num, pci_dev->dev_num, pci_dev->fn_num); + + return 0; } @@ -528,7 +532,7 @@ static int irq_handler(struct guest_info * info, struct v3_interrupt * intr, voi 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); @@ -540,12 +544,11 @@ static int irq_handler(struct guest_info * info, struct v3_interrupt * intr, voi -static int passthrough_init(struct guest_info * info, void * cfg_data) { - struct pci_passthrough_cfg * cfg = (struct pci_passthrough_cfg *)cfg_data; +static int passthrough_init(struct guest_info * info, 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, cfg->pci_bus_name); - + struct vm_device * pci = v3_find_dev(info, v3_cfg_val(cfg, "bus")); + char * name = v3_cfg_val(cfg, "name"); memset(state, 0, sizeof(struct pt_dev_state)); @@ -555,27 +558,30 @@ static int passthrough_init(struct guest_info * info, void * cfg_data) { } state->pci_bus = pci; - strncpy(state->name, cfg->name, 32); - - + strncpy(state->name, name, 32); - dev = v3_allocate_device("PCI_PASSTHROUGH", &dev_ops, state); + dev = v3_allocate_device(name, &dev_ops, state); if (v3_attach_device(info, dev) == -1) { - PrintError("Could not attach device %s\n", "PCI_PASSTHROUGH"); + PrintError("Could not attach device %s\n", name); return -1; } - if (find_real_pci_dev(cfg->vendor_id, cfg->device_id, state) == -1) { - PrintError("Could not find PCI Device %x:%x\n", cfg->vendor_id, cfg->device_id); + if (find_real_pci_dev(atox(v3_cfg_val(cfg, "vendor_id")), + atox(v3_cfg_val(cfg, "device_id")), + state) == -1) { + PrintError("Could not find PCI Device %s:%s\n", + v3_cfg_val(cfg, "vendor_id"), + v3_cfg_val(cfg, "device_id")); return 0; } setup_virt_pci_dev(info, dev); - v3_hook_irq(info, 59, irq_handler, dev); + v3_hook_irq(info, atoi(v3_cfg_val(cfg, "irq")), irq_handler, dev); + // v3_hook_irq(info, 64, irq_handler, dev); return 0; }