-static int pci_free(struct vm_device * dev) {
-
- return 0;
-}
-
static void init_pci_busses(struct pci_internal * pci_state) {
}
+static int pci_free(struct pci_internal * pci_state) {
+ int i;
+
+
+ // cleanup devices
+ for (i = 0; i < PCI_BUS_COUNT; i++) {
+ struct pci_bus * bus = &(pci_state->bus_list[i]);
+ struct rb_node * node = v3_rb_first(&(bus->devices));
+ struct pci_device * dev = NULL;
+
+ while (node) {
+ dev = rb_entry(node, struct pci_device, dev_tree_node);
+ node = v3_rb_next(node);
+
+ v3_rb_erase(&(dev->dev_tree_node), &(bus->devices));
+ V3_Free(dev);
+ }
+
+ }
+
+ V3_Free(pci_state);
+ return 0;
+}
static struct v3_device_ops dev_ops = {
- .free = pci_free,
+ .free = (int (*)(void *))pci_free,
};
struct pci_internal * pci_state = V3_Malloc(sizeof(struct pci_internal));
int i = 0;
char * dev_id = v3_cfg_val(cfg, "ID");
+ int ret = 0;
PrintDebug("PCI internal at %p\n",(void *)pci_state);
- struct vm_device * dev = v3_allocate_device(dev_id, &dev_ops, pci_state);
+ struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, pci_state);
- if (v3_attach_device(vm, dev) == -1) {
+ if (dev == NULL) {
PrintError("Could not attach device %s\n", dev_id);
+ V3_Free(pci_state);
return -1;
}
PrintDebug("Sizeof config header=%d\n", (int)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);
- v3_dev_hook_io(dev, CONFIG_DATA_PORT + i, &data_port_read, &data_port_write);
+ ret |= v3_dev_hook_io(dev, CONFIG_ADDR_PORT + i, &addr_port_read, &addr_port_write);
+ ret |= v3_dev_hook_io(dev, CONFIG_DATA_PORT + i, &data_port_read, &data_port_write);
+ }
+
+ if (ret != 0) {
+ PrintError("Error hooking PCI IO ports\n");
+ v3_remove_device(dev);
+ return -1;
}
return 0;
struct pci_internal * pci_state = (struct pci_internal *)pci_bus->private_data;
struct pci_bus * bus = &(pci_state->bus_list[bus_num]);
- return bus->raise_pci_irq(bus->irq_dev_data, dev);
+ return bus->raise_pci_irq(dev, bus->irq_dev_data);
}
int v3_pci_lower_irq(struct vm_device * pci_bus, int bus_num, struct pci_device * dev) {
struct pci_internal * pci_state = (struct pci_internal *)pci_bus->private_data;
struct pci_bus * bus = &(pci_state->bus_list[bus_num]);
- return bus->lower_pci_irq(bus->irq_dev_data, dev);
+ return bus->lower_pci_irq(dev, bus->irq_dev_data);
}
// if dev_num == -1, auto assign