コード例 #1
0
ファイル: prt_xxx.c プロジェクト: AlainODea/illumos-gate
/*
 * Print vendor ID and device ID for PCI devices
 */
int
print_pciid(di_node_t node, di_prom_handle_t ph, pcidb_hdl_t *pci)
{
	pcidb_vendor_t *vend;
	pcidb_device_t *dev;
	di_node_t pnode = di_parent_node(node);
	char *s = NULL;
	int *i, type = di_nodeid(node);

	if (LOOKUP_PROP(strings, ph, type, DDI_DEV_T_ANY, pnode,
	    "device_type", &s) <= 0)
		return (0);

	if (!ISPCI(s))
		return (0);	/* not a pci device */

	(void) printf(" (%s", s);
	if (LOOKUP_PROP(ints, ph, type, DDI_DEV_T_ANY, node,
	    "vendor-id", &i) > 0)
		(void) printf("%x", i[0]);

	if (pci != NULL)
		vend = pcidb_lookup_vendor(pci, i[0]);

	if (LOOKUP_PROP(ints, ph, type, DDI_DEV_T_ANY, node,
	    "device-id", &i) > 0)
		(void) printf(",%x", i[0]);

	if (pci != NULL)
		dev = pcidb_lookup_device_by_vendor(vend, i[0]);

	(void) printf(") [");

	if (vend != NULL)
		(void) printf("%s ", pcidb_vendor_name(vend));
	else
		(void) printf("unknown vendor, ");

	if (dev != NULL)
		(void) printf("%s", pcidb_device_name(dev));
	else
		(void) printf("unknown device");

	(void) printf("]");
	return (1);
}
コード例 #2
0
ファイル: pcilookup.c プロジェクト: jclulow/illumos-hcl
static void
print_arg(void)
{
	pcidb_vendor_t *v;
	pcidb_device_t *d;
	pcidb_subvd_t *s;
	const char *vend, *dev, *sub;
	vend = NULL;
	dev = NULL;
	sub = NULL;

	assert(g_case != L_INVALID);
	v = pcidb_lookup_vendor(g_hdl, g_vid);
	if (v == NULL)
		fatal("unknown vendor id: %04x\n", g_vid);

	vend = pcidb_vendor_name(v);
	if (g_case == L_VENDOR)
		goto print;

	d = pcidb_lookup_device_by_vendor(v, g_did);
	if (d == NULL)
		fatal("unknown device id: %04x\n", g_did);

	dev = pcidb_device_name(d);
	if (g_case == L_DEVICE)
		goto print;

	s = pcidb_lookup_subvd_by_device(d, g_svid, g_sdid);
	if (s == NULL)
		fatal("uknown sub-vendor and sub-device id: %04x.%04x\n",
		    g_svid, g_sdid);
	sub = pcidb_subvd_name(s);
print:
	if (vend != NULL)
		printf("%s", vend);

	if (dev != NULL)
		printf("|%s", dev);

	if (sub != NULL)
		printf("|%s", sub);

	printf("\n");
}
コード例 #3
0
ファイル: smbios.c プロジェクト: bahamas10/openzfs
/*ARGSUSED*/
static int
do_slot_mapping_cb(topo_hdl_t *thp, tnode_t *node, void *arg)
{
	int err, ret;
	nvlist_t *rsrc = NULL;
	const char *match = arg;
	char *s, *fmri = NULL;
	char *didstr = NULL, *driver = NULL, *vidstr = NULL;
	boolean_t printed = B_FALSE;

	ret = TOPO_WALK_NEXT;
	if (topo_node_resource(node, &rsrc, &err) < 0)
		goto next;
	if (topo_fmri_nvl2str(thp, rsrc, &fmri, &err) < 0)
		goto next;

	if ((s = strstr(fmri, match)) == NULL)
		goto next;
	if (s[strlen(match)] != '\0')
		goto next;

	/* At this point we think we've found a match */
	ret = TOPO_WALK_TERMINATE;
	if (topo_prop_get_string(node, TOPO_PGROUP_IO, TOPO_IO_DRIVER, &driver,
	    &err) != 0)
		driver = NULL;

	if (topo_prop_get_string(node, TOPO_PGROUP_PCI, TOPO_PCI_VENDID,
	    &vidstr, &err) != 0)
		goto next;

	if (topo_prop_get_string(node, TOPO_PGROUP_PCI, TOPO_PCI_DEVID,
	    &didstr, &err) != 0)
		goto next;

	if (prt_php != NULL) {
		long vid, did;

		vid = strtol(vidstr, NULL, 16);
		did = strtol(didstr, NULL, 16);
		if (vid >= 0 && vid <= UINT16_MAX &&
		    did >= 0 && did <= UINT16_MAX) {
			pcidb_device_t *pdev;

			pdev = pcidb_lookup_device(prt_php, vid, did);
			if (pdev != NULL) {
				pcidb_vendor_t *pvend;
				pvend = pcidb_device_vendor(pdev);
				(void) printf(gettext(", %s %s (%s)"),
				    pcidb_vendor_name(pvend),
				    pcidb_device_name(pdev),
				    driver != NULL ? driver : "<unknown>");
				printed = B_TRUE;
			}
		}
	}

	if (printed == B_FALSE) {
		(void) printf(gettext(", pci%s,%s (%s)"), vidstr, didstr,
		    driver != NULL ? driver : "<unknown>");
	}
next:
	topo_hdl_strfree(thp, didstr);
	topo_hdl_strfree(thp, driver);
	topo_hdl_strfree(thp, vidstr);
	topo_hdl_strfree(thp, fmri);
	nvlist_free(rsrc);
	return (ret);
}
コード例 #4
0
ファイル: did_props.c プロジェクト: drscream/illumos-joyent
/*ARGSUSED*/
static int
maybe_pcidb_set(tnode_t *tn, did_t *pd, const char *dpnm, const char *tpgrp,
    const char *tpnm)
{
	const char *vname, *dname = NULL, *ssname = NULL;
	uint_t vid, pid, svid, ssid;
	pcidb_vendor_t *pciv;
	pcidb_device_t *pcid;
	pcidb_subvd_t *pcis = NULL;
	pcidb_hdl_t *pcih;
	topo_mod_t *mod = did_mod(pd);
	int err;

	/*
	 * At a minimum, we need the vid/devid of the device to be able to
	 * lookup anything in the PCI database.  So if we fail to look either
	 * of those up, bail out.
	 */
	if (di_uintprop_get(did_mod(pd), did_dinode(pd), DI_VENDIDPROP, &vid) <
	    0 || di_uintprop_get(did_mod(pd), did_dinode(pd), DI_DEVIDPROP,
	    &pid) < 0) {
		return (0);
	}
	/*
	 * If we fail to lookup the vendor, by the vid that's also a
	 * deal-breaker.
	 */
	if ((pcih = topo_mod_pcidb(mod)) == NULL ||
	    (pciv = pcidb_lookup_vendor(pcih, vid)) == NULL) {
		return (0);
	}

	/* lookup vendor-name and set the topo property, if found */
	vname = pcidb_vendor_name(pciv);
	if (vname != NULL &&
	    topo_prop_set_string(tn, tpgrp, TOPO_PCI_VENDNM,
	    TOPO_PROP_IMMUTABLE, vname, &err) != 0) {
		return (topo_mod_seterrno(mod, err));
	}

	/* lookup device-name and set the topo property, if found */
	if ((pcid = pcidb_lookup_device_by_vendor(pciv, pid)) != NULL) {
		dname = pcidb_device_name(pcid);
	}
	if (dname != NULL &&
	    topo_prop_set_string(tn, tpgrp, TOPO_PCI_DEVNM,
	    TOPO_PROP_IMMUTABLE, dname, &err) != 0) {
		return (topo_mod_seterrno(mod, err));
	}

	/*
	 * Not all devices will have a subsystem-name that we can lookup,
	 * but if both subsystem-vendorid and subsystem-id exist in devinfo and
	 * if we were previously able to find the device by devid then we can
	 * at least attempt a lookup.  If found, set the topo property.
	 */
	if (pcid != NULL &&
	    di_uintprop_get(did_mod(pd), did_dinode(pd), DI_SUBVENDIDPROP,
	    &svid) == 0 &&
	    di_uintprop_get(did_mod(pd), did_dinode(pd), DI_SUBSYSTEMID,
	    &ssid) == 0) {
		pcis = pcidb_lookup_subvd_by_device(pcid, svid, ssid);
	}
	if (pcis != NULL) {
		ssname = pcidb_subvd_name(pcis);
	}
	if (ssname != NULL && strlen(ssname) > 0 &&
	    topo_prop_set_string(tn, tpgrp, TOPO_PCI_SUBSYSNM,
	    TOPO_PROP_IMMUTABLE, ssname, &err) != 0) {
		return (topo_mod_seterrno(mod, err));
	}
	return (0);
}