X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Fpci.c;h=e7927b7d2de5e27d5bb7cede3f43bac211f45df0;hb=cad2a42f98571ec27228d6e20f5d76910dc0e4a0;hp=de3e0eaeb7f2707030226dd934dc3a7429aaa127;hpb=b5c53bc93c0daf0d03d04afbce2e874f5f39c710;p=palacios-OLD.git diff --git a/palacios/src/devices/pci.c b/palacios/src/devices/pci.c index de3e0ea..e7927b7 100644 --- a/palacios/src/devices/pci.c +++ b/palacios/src/devices/pci.c @@ -125,7 +125,7 @@ static int get_free_dev_num(struct pci_bus * bus) { // availability for (j = 0; j < 8; j++) { if (!(bus->dev_map[i] & (0x1 << j))) { - return i * 8 + j; + return ((i * 8) + j) * 8; } } } @@ -135,7 +135,7 @@ static int get_free_dev_num(struct pci_bus * bus) { } static void allocate_dev_num(struct pci_bus * bus, int dev_num) { - int major = dev_num / 8; + int major = (dev_num / 8) / 8; int minor = dev_num % 8; bus->dev_map[major] |= (0x1 << minor); @@ -381,8 +381,17 @@ static int data_port_write(ushort_t port, void * src, uint_t length, struct vm_d } } else if ((cur_reg >= 0x30) && (cur_reg < 0x34)) { pci_dev->ext_rom_update_flag = 1; - } else if ((cur_reg == 0x04) || (cur_reg == 0x05)) { - // COMMAND update + } else if (cur_reg == 0x04) { + // COMMAND update + uint8_t command = *((uint8_t *)src + i); + + pci_dev->config_space[cur_reg] = command; + + if (pci_dev->cmd_update) { + pci_dev->cmd_update(pci_dev, (command & 0x01), (command & 0x02)); + } + + } else if (cur_reg == 0x0f) { // BIST update pci_dev->config_header.BIST = 0x00; @@ -456,11 +465,22 @@ static int pci_deinit_device(struct vm_device * dev) { static int init_i440fx(struct vm_device * dev) { - /*struct pci_device * pci_dev = v3_pci_register_device(dev, 0, "i440FX", 0, - NULL, NULL, NULL); + struct pci_device * pci_dev = NULL; + struct v3_pci_bar bars[6]; + int i; + + for (i = 0; i < 6; i++) { + bars[i].type = PCI_BAR_NONE; + bars[i].mem_hook = 0; + bars[i].num_pages = 0; + bars[i].bar_update = NULL; + } + + pci_dev = v3_pci_register_device(dev, PCI_STD_DEVICE, 0, "i440FX", 0, bars, + NULL, NULL, NULL, NULL); if (!pci_dev) { - return -1; + return -1; } pci_dev->config_header.vendor_id = 0x8086; @@ -468,10 +488,8 @@ static int init_i440fx(struct vm_device * dev) { pci_dev->config_header.revision = 0x0002; pci_dev->config_header.subclass = 0x00; // SubClass: host2pci pci_dev->config_header.class = 0x06; // Class: PCI bridge - pci_dev->config_header.header_type = 0x00; pci_dev->bus_num = 0; - */ return 0; } @@ -546,9 +564,10 @@ static inline int init_bars(struct pci_device * pci_dev) { int bar_offset = 0x10 + 4 * i; if (pci_dev->bar[i].type == PCI_BAR_IO) { + pci_dev->bar[i].mask = 0x0000fffd; *(uint32_t *)(pci_dev->config_space + bar_offset) = 0x00000001; } else if (pci_dev->bar[i].type == PCI_BAR_MEM32) { - pci_dev->bar[i].mask = (pci_dev->bar[i].num_pages << 12) - 1; + pci_dev->bar[i].mask = ~((pci_dev->bar[i].num_pages << 12) - 1); pci_dev->bar[i].mask |= 0xf; // preserve the configuration flags *(uint32_t *)(pci_dev->config_space + bar_offset) = 0x00000008; @@ -576,6 +595,7 @@ static inline int init_bars(struct pci_device * pci_dev) { // if dev_num == -1, auto assign struct pci_device * v3_pci_register_device(struct vm_device * pci, + pci_device_type_t dev_type, uint_t bus_num, const char * name, int dev_num, @@ -618,6 +638,15 @@ struct pci_device * v3_pci_register_device(struct vm_device * pci, memset(pci_dev, 0, sizeof(struct pci_device)); + switch (dev_type) { + case PCI_STD_DEVICE: + pci_dev->config_header.header_type = 0x00; + break; + default: + PrintError("Unhandled PCI Device Type: %d\n", dev_type); + return NULL; + } + pci_dev->bus_num = bus_num; pci_dev->dev_num = dev_num;