int intr_pin = pci_dev->config_header.intr_pin - 1;
int irq_index = (intr_pin + pci_dev->dev_num - 1) & 0x3;
- // PrintError("Raising PCI IRQ %d\n", piix3_cfg->pirq_rc[irq_index]);
+ //PrintError("Raising PCI IRQ %d, %p\n", piix3_cfg->pirq_rc[irq_index], piix3->vm);
v3_raise_irq(piix3->vm, piix3_cfg->pirq_rc[irq_index]);
-static int piix_free(struct vm_device * dev) {
+static int piix_free(struct v3_southbridge * piix3) {
+
+ // unregister pci
+
+ V3_Free(piix3);
return 0;
}
static struct v3_device_ops dev_ops = {
- .free = piix_free,
+ .free = (int (*)(void *))piix_free,
};
piix3->pci_bus = pci;
piix3->type = V3_SB_PIIX3;
+ piix3->vm = vm;
- dev = v3_allocate_device(dev_id, &dev_ops, piix3);
+ dev = v3_add_device(vm, dev_id, &dev_ops, piix3);
- if (v3_attach_device(vm, dev) == -1) {
+ if (dev == NULL) {
PrintError("Could not attach device %s\n", dev_id);
+ V3_Free(piix3);
return -1;
}
PrintDebug("Created PIIX3\n");
- return setup_pci(piix3);
+ if (setup_pci(piix3) == -1) {
+ v3_remove_device(dev);
+ return -1;
+ }
+
+ return 0;
}