コード例 #1
0
ファイル: xf86Configure.c プロジェクト: L3oV1nc3/VMGL
static void
bus_pci_newdev_configure(void *busData, int i, int *chipset)
{
	const char *VendorName;
	const char *CardName;
	char busnum[8];
    struct pci_device * pVideo = NULL;

    pVideo = (struct pci_device *) busData;

	DevToConfig[i].pVideo = pVideo;

	VendorName = pci_device_get_vendor_name( pVideo );
	CardName = pci_device_get_device_name( pVideo );

	if (!VendorName) {
	    VendorName = xnfalloc(15);
	    sprintf((char*)VendorName, "Unknown Vendor");
	}

	if (!CardName) {
	    CardName = xnfalloc(14);
	    sprintf((char*)CardName, "Unknown Board");
	}

	DevToConfig[i].GDev.identifier =
	    xnfalloc(strlen(VendorName) + strlen(CardName) + 2);
	sprintf(DevToConfig[i].GDev.identifier, "%s %s", VendorName, CardName);

	DevToConfig[i].GDev.vendor = (char *)VendorName;
	DevToConfig[i].GDev.board = (char *)CardName;

	DevToConfig[i].GDev.busID = xnfalloc(16);
	xf86FormatPciBusNumber(pVideo->bus, busnum);
	sprintf(DevToConfig[i].GDev.busID, "PCI:%s:%d:%d",
	    busnum, pVideo->dev, pVideo->func);

	DevToConfig[i].GDev.chipID = pVideo->device_id;
	DevToConfig[i].GDev.chipRev = pVideo->revision;

	if (*chipset < 0) {
	    *chipset = (pVideo->vendor_id << 16) | pVideo->device_id;
	}
}
コード例 #2
0
/*
 * This is called by the driver, either through xf86Match???Instances() or
 * directly.  We allocate a GDevRec and fill it in as much as we can, letting
 * the caller fill in the rest and/or change it as it sees fit.
 */
GDevPtr
xf86AddBusDeviceToConfigure(const char *driver, BusType bus, void *busData, int chipset)
{
    int i, j;
    pciVideoPtr pVideo = NULL;
    Bool isPrimary = FALSE;

    if (xf86DoProbe || !xf86DoConfigure || !xf86DoConfigurePass1)
        return NULL;

    /* Check for duplicates */
    switch (bus) {
    case BUS_PCI:
        pVideo = (pciVideoPtr) busData;
        for (i = 0;  i < nDevToConfig;  i++)
            if (DevToConfig[i].pVideo &&
                    (DevToConfig[i].pVideo->bus == pVideo->bus) &&
                    (DevToConfig[i].pVideo->device == pVideo->device) &&
                    (DevToConfig[i].pVideo->func == pVideo->func))
                return NULL;
        isPrimary = xf86IsPrimaryPci(pVideo);
        break;
    case BUS_ISA:
        /*
         * This needs to be revisited as it doesn't allow for non-PCI
         * multihead.
         */
        if (!xf86IsPrimaryIsa())
            return NULL;
        isPrimary = TRUE;
        for (i = 0;  i < nDevToConfig;  i++)
            if (!DevToConfig[i].pVideo)
                return NULL;
        break;
#if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__)
    case BUS_SBUS:
        for (i = 0;  i < nDevToConfig;  i++)
            if (DevToConfig[i].sVideo &&
                    DevToConfig[i].sVideo->fbNum == ((sbusDevicePtr) busData)->fbNum)
                return NULL;
        break;
#endif
    default:
        return NULL;
    }

    /* Allocate new structure occurrence */
    i = nDevToConfig++;
    DevToConfig =
        xnfrealloc(DevToConfig, nDevToConfig * sizeof(DevToConfigRec));
#if 1   /* Doesn't work when a driver detects more than one adapter */
    if ((i > 0) && isPrimary) {
        memmove(DevToConfig + 1,DevToConfig,
                (nDevToConfig - 1) * sizeof(DevToConfigRec));
        i = 0;
    }
#endif
    memset(DevToConfig + i, 0, sizeof(DevToConfigRec));

#   define NewDevice DevToConfig[i]

    NewDevice.GDev.chipID = NewDevice.GDev.chipRev = NewDevice.GDev.irq = -1;

    NewDevice.iDriver = CurrentDriver;

    /* Fill in what we know, converting the driver name to lower case */
    NewDevice.GDev.driver = xnfalloc(strlen(driver) + 1);
    for (j = 0;  (NewDevice.GDev.driver[j] = tolower(driver[j]));  j++);

    switch (bus) {
    case BUS_PCI: {
        const char *VendorName;
        const char *CardName;
        char busnum[8];

        NewDevice.pVideo = pVideo;
        xf86FindPciNamesByDevice(pVideo->vendor, pVideo->chipType,
                                 NOVENDOR, NOSUBSYS,
                                 &VendorName, &CardName, NULL, NULL);

        if (!VendorName) {
            VendorName = xnfalloc(15);
            sprintf((char*)VendorName, "Unknown Vendor");
        }

        if (!CardName) {
            CardName = xnfalloc(14);
            sprintf((char*)CardName, "Unknown Board");
        }

        NewDevice.GDev.identifier =
            xnfalloc(strlen(VendorName) + strlen(CardName) + 2);
        sprintf(NewDevice.GDev.identifier, "%s %s", VendorName, CardName);

        NewDevice.GDev.vendor = (char *)VendorName;
        NewDevice.GDev.board = (char *)CardName;

        NewDevice.GDev.busID = xnfalloc(16);
        xf86FormatPciBusNumber(pVideo->bus, busnum);
        sprintf(NewDevice.GDev.busID, "PCI:%s:%d:%d",
                busnum, pVideo->device, pVideo->func);

        NewDevice.GDev.chipID = pVideo->chipType;
        NewDevice.GDev.chipRev = pVideo->chipRev;

        if (chipset < 0)
            chipset = (pVideo->vendor << 16) | pVideo->chipType;
    }
    break;
    case BUS_ISA:
        NewDevice.GDev.identifier = "ISA Adapter";
        NewDevice.GDev.busID = "ISA";
        break;
#if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__)
    case BUS_SBUS: {
        char *promPath = NULL;
        NewDevice.sVideo = (sbusDevicePtr) busData;
        NewDevice.GDev.identifier = NewDevice.sVideo->descr;
        if (sparcPromInit() >= 0) {
            promPath = sparcPromNode2Pathname(&NewDevice.sVideo->node);
            sparcPromClose();
        }
        if (promPath) {
            NewDevice.GDev.busID = xnfalloc(strlen(promPath) + 6);
            sprintf(NewDevice.GDev.busID, "SBUS:%s", promPath);
            xfree(promPath);
        } else {
            NewDevice.GDev.busID = xnfalloc(12);
            sprintf(NewDevice.GDev.busID, "SBUS:fb%d", NewDevice.sVideo->fbNum);
        }
    }
    break;
#endif
    default:
        break;
    }

    /* Get driver's available options */
    if (xf86DriverList[CurrentDriver]->AvailableOptions)
        NewDevice.GDev.options = (OptionInfoPtr)
                                 (*xf86DriverList[CurrentDriver]->AvailableOptions)(chipset,
                                         bus);

    return &NewDevice.GDev;

#   undef NewDevice
}