Revision 113f89df hw/pci.c

b/hw/pci.c
726 726
/* -1 for devfn means auto assign */
727 727
static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
728 728
                                         const char *name, int devfn,
729
                                         PCIConfigReadFunc *config_read,
730
                                         PCIConfigWriteFunc *config_write,
731
                                         bool is_bridge)
729
                                         const PCIDeviceInfo *info)
732 730
{
731
    PCIConfigReadFunc *config_read = info->config_read;
732
    PCIConfigWriteFunc *config_write = info->config_write;
733

  
733 734
    if (devfn < 0) {
734 735
        for(devfn = bus->devfn_min ; devfn < ARRAY_SIZE(bus->devices);
735 736
            devfn += PCI_FUNC_MAX) {
......
750 751
    pci_dev->irq_state = 0;
751 752
    pci_config_alloc(pci_dev);
752 753

  
753
    if (!is_bridge) {
754
        pci_set_default_subsystem_id(pci_dev);
754
    pci_config_set_vendor_id(pci_dev->config, info->vendor_id);
755
    pci_config_set_device_id(pci_dev->config, info->device_id);
756
    pci_config_set_revision(pci_dev->config, info->revision);
757
    pci_config_set_class(pci_dev->config, info->class_id);
758

  
759
    if (!info->is_bridge) {
760
        if (info->subsystem_vendor_id || info->subsystem_id) {
761
            pci_set_word(pci_dev->config + PCI_SUBSYSTEM_VENDOR_ID,
762
                         info->subsystem_vendor_id);
763
            pci_set_word(pci_dev->config + PCI_SUBSYSTEM_ID,
764
                         info->subsystem_id);
765
        } else {
766
            pci_set_default_subsystem_id(pci_dev);
767
        }
768
    } else {
769
        /* subsystem_vendor_id/subsystem_id are only for header type 0 */
770
        assert(!info->subsystem_vendor_id);
771
        assert(!info->subsystem_id);
755 772
    }
756 773
    pci_init_cmask(pci_dev);
757 774
    pci_init_wmask(pci_dev);
758 775
    pci_init_w1cmask(pci_dev);
759
    if (is_bridge) {
776
    if (info->is_bridge) {
760 777
        pci_init_wmask_bridge(pci_dev);
761 778
    }
762 779
    if (pci_init_multifunction(bus, pci_dev)) {
......
783 800
    pci_config_free(pci_dev);
784 801
}
785 802

  
803
/* TODO: obsolete. eliminate this once all pci devices are qdevifed. */
786 804
PCIDevice *pci_register_device(PCIBus *bus, const char *name,
787 805
                               int instance_size, int devfn,
788 806
                               PCIConfigReadFunc *config_read,
789 807
                               PCIConfigWriteFunc *config_write)
790 808
{
791 809
    PCIDevice *pci_dev;
810
    PCIDeviceInfo info = {
811
        .config_read = config_read,
812
        .config_write = config_write,
813
    };
792 814

  
793 815
    pci_dev = qemu_mallocz(instance_size);
794
    pci_dev = do_pci_register_device(pci_dev, bus, name, devfn,
795
                                     config_read, config_write,
796
                                     PCI_HEADER_TYPE_NORMAL);
816
    pci_dev = do_pci_register_device(pci_dev, bus, name, devfn, &info);
797 817
    if (pci_dev == NULL) {
798 818
        hw_error("PCI: can't register device\n");
799 819
    }
......
1643 1663
    PCIDevice *pci_dev = (PCIDevice *)qdev;
1644 1664
    PCIDeviceInfo *info = container_of(base, PCIDeviceInfo, qdev);
1645 1665
    PCIBus *bus;
1646
    int devfn, rc;
1666
    int rc;
1647 1667
    bool is_default_rom;
1648 1668

  
1649 1669
    /* initialize cap_present for pci_is_express() and pci_config_size() */
......
1652 1672
    }
1653 1673

  
1654 1674
    bus = FROM_QBUS(PCIBus, qdev_get_parent_bus(qdev));
1655
    devfn = pci_dev->devfn;
1656
    pci_dev = do_pci_register_device(pci_dev, bus, base->name, devfn,
1657
                                     info->config_read, info->config_write,
1658
                                     info->is_bridge);
1675
    pci_dev = do_pci_register_device(pci_dev, bus, base->name,
1676
                                     pci_dev->devfn, info);
1659 1677
    if (pci_dev == NULL)
1660 1678
        return -1;
1661 1679
    if (qdev->hotplugged && info->no_hotplug) {

Also available in: Unified diff