Example #1
0
Bool
xf86ParseSbusBusString(const char *busID, int *fbNum)
{
    /*
     * The format is assumed to be one of:
     * "fbN", e.g. "fb1", which means the device corresponding to /dev/fbN
     * "nameN", e.g. "cgsix0", which means Nth instance of card NAME
     * "/prompath", e.g. "/sbus@0,10001000/cgsix@3,0" which is PROM pathname
     * to the device.
     */

    const char *id;
    int i, len;

    if (StringToBusType(busID, &id) != BUS_SBUS)
	return FALSE;

    if (*id != '/') {
	if (!strncmp (id, "fb", 2)) {
	    if (!isdigit(id[2]))
		return FALSE;
	    *fbNum = atoi(id + 2);
	    return TRUE;
	} else {
	    sbusDevicePtr *psdpp;
	    int devId;

	    for (i = 0, len = 0; sbusDeviceTable[i].devId; i++) {
		len = strlen(sbusDeviceTable[i].promName);
		if (!strncmp (sbusDeviceTable[i].promName, id, len)
		    && isdigit(id[len]))
		    break;
	    }
	    devId = sbusDeviceTable[i].devId;
	    if (!devId) return FALSE;
	    i = atoi(id + len);
	    for (psdpp = xf86SbusInfo; *psdpp; ++psdpp) {
		if ((*psdpp)->devId != devId)
		    continue;
		if (!i) {
		    *fbNum = (*psdpp)->fbNum;
		    return TRUE;
		}
		i--;
	    }
	}
	return FALSE;
    }

    if (sparcPromInit() >= 0) {
	i = sparcPromPathname2Node(id);
	sparcPromClose();
	if (i) {
	    sbusDevicePtr *psdpp;
	    for (psdpp = xf86SbusInfo; *psdpp; ++psdpp) {
		if ((*psdpp)->node.node == i) {
		    *fbNum = (*psdpp)->fbNum;
		    return TRUE;
		}
	    }
	}
    }
    return FALSE;
}
Example #2
0
Bool
xf86ParsePciBusString(const char *busID, int *bus, int *device, int *func)
{
    /*
     * The format is assumed to be "bus[@domain]:device[:func]", where domain,
     * bus, device and func are decimal integers.  domain and func may be
     * omitted and assumed to be zero, although doing this isn't encouraged.
     */

    char *p, *s, *d;
    const char *id;
    int i;

    if (StringToBusType(busID, &id) != BUS_PCI)
        return FALSE;

    s = xstrdup(id);
    p = strtok(s, ":");
    if (p == NULL || *p == 0) {
        free(s);
        return FALSE;
    }
    d = strpbrk(p, "@");
    if (d != NULL) {
        *(d++) = 0;
        for (i = 0; d[i] != 0; i++) {
            if (!isdigit(d[i])) {
                free(s);
                return FALSE;
            }
        }
    }
    for (i = 0; p[i] != 0; i++) {
        if (!isdigit(p[i])) {
            free(s);
            return FALSE;
        }
    }
    *bus = atoi(p);
    if (d != NULL && *d != 0)
        *bus += atoi(d) << 8;
    p = strtok(NULL, ":");
    if (p == NULL || *p == 0) {
        free(s);
        return FALSE;
    }
    for (i = 0; p[i] != 0; i++) {
        if (!isdigit(p[i])) {
            free(s);
            return FALSE;
        }
    }
    *device = atoi(p);
    *func = 0;
    p = strtok(NULL, ":");
    if (p == NULL || *p == 0) {
        free(s);
        return TRUE;
    }
    for (i = 0; p[i] != 0; i++) {
        if (!isdigit(p[i])) {
            free(s);
            return FALSE;
        }
    }
    *func = atoi(p);
    free(s);
    return TRUE;
}