From: Lei Xia Date: Mon, 16 Mar 2009 18:10:35 +0000 (-0500) Subject: Merge branch 'devel' of /home/palacios/palacios into devel X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=commitdiff_plain;h=95ca28a23f949b13c857ba0b061a2ca465683e8e;hp=-c;p=palacios.git Merge branch 'devel' of /home/palacios/palacios into devel Conflicts: palacios/src/devices/pci.c --- 95ca28a23f949b13c857ba0b061a2ca465683e8e diff --combined palacios/include/devices/pci.h index 01ce86a,23f459c..090ac62 --- a/palacios/include/devices/pci.h +++ b/palacios/include/devices/pci.h @@@ -33,7 -33,7 +33,7 @@@ typedef enum {PCI_BAR_IO, PCI_BAR_MEM32, PCI_BAR_MEM64_LOW, PCI_BAR_MEM64_HIGH, PCI_BAR_NONE} pci_bar_type_t; -struct bar_reg { +struct v3_bar_reg { int updated; pci_bar_type_t type; int num_resources; @@@ -52,7 -52,7 +52,7 @@@ struct pci_device - struct bar_reg bar[6]; + struct v3_bar_reg bar[6]; uint_t bus_num; struct rb_node dev_tree_node; @@@ -64,10 -64,10 +64,13 @@@ int (*config_update)(struct pci_device * pci_dev, uint_t reg_num, int length); + int (*cmd_update)(struct pci_dev *pci_dev, uchar_t io_enabled, uchar_t mem_enabled); + int (*ext_rom_update)(struct pci_dev *pci_dev); + + int ext_rom_update_flag; + int bar_update_flag; + void * priv_data; }; diff --combined palacios/src/devices/pci.c index 9162384,e86af94..42077e9 --- a/palacios/src/devices/pci.c +++ b/palacios/src/devices/pci.c @@@ -333,7 -333,7 +333,7 @@@ static inline int is_cfg_reg_writable(u static int data_port_write(ushort_t port, void * src, uint_t length, struct vm_device * vmdev) { - struct pci_internal * pci_state = (struct pci_internal *)vmdev->private_data;; + struct pci_internal * pci_state = (struct pci_internal *)vmdev->private_data; struct pci_device * pci_dev = NULL; uint_t reg_num = pci_state->addr_reg.reg_num + (port & 0x3); int i; @@@ -355,15 -355,50 +355,50 @@@ for (i = 0; i < length; i++) { - if (is_cfg_reg_writable(pci_dev->config_header.header_type, reg_num)) { - pci_dev->config_space[reg_num + i] = *((uint8_t *)src + i); + uint_t cur_reg = reg_num + i; + + if (is_cfg_reg_writable(pci_dev->config_header.header_type, cur_reg)) { + pci_dev->config_space[cur_reg] = *((uint8_t *)src + i); + + if ((cur_reg >= 0x10) && (cur_reg < 0x28)) { + // BAR Reg + int bar_reg = (cur_reg & ~0x3) - 0x10; + + if (pci_dev->bar[bar_reg].bar_update) { + pci_dev->bar_update_flag = 1; + pci_dev->bar[bar_reg].updated = 1; + } + } else if ((cur_reg >= 0x30) && (cur_reg < 0x34)) { + pci_dev->ext_rom_updated = 1; + } else if ((cur_reg == 0x04) || (cur_reg == 0x05)) { + // COMMAND update + } else if (cur_reg == 0x0f) { + // BIST update + } } } if (pci_dev->config_update) { pci_dev->config_update(pci_dev, reg_num, length); } - + + // Scan for BAR updated + if (pci_dev->bar_update_flag) { + for (i = 0; i < 6; i++) { + if ((pci_dev->bar[i].updated) && (pci_dev->bar[i].bar_update)) { + pci_dev->bar[i].bar_update(pci_dev, i); + } + pci_dev->bar[i].updated = 0; + } + pci_dev->bar_update_flag = 0; + } + + if ((pci_dev->ext_rom_update_flag) && (pci_dev->ext_rom_update)) { + pci_dev->ext_rom_update(pci_dev); + pci_dev->ext_rom_update_flag = 0; + } + + return length; } @@@ -404,7 -439,7 +439,7 @@@ static int pci_deinit_device(struct vm_ static int init_i440fx(struct vm_device * dev) { struct pci_device * pci_dev = v3_pci_register_device(dev, 0, "i440FX", 0, - NULL, NULL); + NULL, NULL, NULL); if (!pci_dev) { return -1; @@@ -453,6 -488,8 +488,8 @@@ static int pci_init_device(struct vm_de PrintError("Could not intialize i440fx\n"); return -1; } + + PrintDebug("Sizeof config header=%d\n", sizeof(struct pci_config_header)); for (i = 0; i < 4; i++) { v3_dev_hook_io(dev, CONFIG_ADDR_PORT + i, &addr_port_read, &addr_port_write); @@@ -491,15 -528,13 +528,16 @@@ struct pci_device * v3_pci_register_dev uint_t bus_num, const char * name, int dev_num, + struct v3_pci_bar * bars, int (*config_update)(struct pci_device * pci_dev, uint_t reg_num, int length), + int (*cmd_update)(struct pci_dev *pci_dev, uchar_t io_enabled, uchar_t mem_enabled), + int (*bar_update)(struct pci_device * pci_dev, uint_t bar), void * private_data) { struct pci_internal * pci_state = (struct pci_internal *)pci->private_data; struct pci_bus * bus = &(pci_state->bus_list[bus_num]); struct pci_device * pci_dev = NULL; + int i; if (dev_num > MAX_BUS_DEVICES) { PrintError("Requested Invalid device number (%d)\n", dev_num); @@@ -535,25 -570,14 +573,27 @@@ strncpy(pci_dev->name, name, sizeof(pci_dev->name)); pci_dev->vm_dev = pci; + // register update callbacks pci_dev->config_update = config_update; + pci_dev->bar_update = bar_update; pci_dev->priv_data = private_data; + + //copy bars + for (i = 0; i < 6; i ++){ + pci_dev->bar[i].updated = bars[i].updated; + pci_dev->bar[i].type = bars[i].type; + pci_dev->bar[i].num_resources = bars[i].num_resources; + pci_dev->bar[i].bar_update = bars[i].bar_update; + } + + pci_dev->cmd_update = cmd_update; + pci_dev->ext_rom_update = ext_rom_update; + // add the device add_device_to_bus(bus, pci_dev); + #ifdef DEBUG_PCI pci_dump_state(pci_state);