1*a29b8a92Smrg /* $NetBSD: pcictl.c,v 1.22 2016/09/24 23:12:54 mrg Exp $ */
20c91ac68Sthorpej
30c91ac68Sthorpej /*
40c91ac68Sthorpej * Copyright 2001 Wasabi Systems, Inc.
50c91ac68Sthorpej * All rights reserved.
60c91ac68Sthorpej *
70c91ac68Sthorpej * Written by Jason R. Thorpe for Wasabi Systems, Inc.
80c91ac68Sthorpej *
90c91ac68Sthorpej * Redistribution and use in source and binary forms, with or without
100c91ac68Sthorpej * modification, are permitted provided that the following conditions
110c91ac68Sthorpej * are met:
120c91ac68Sthorpej * 1. Redistributions of source code must retain the above copyright
130c91ac68Sthorpej * notice, this list of conditions and the following disclaimer.
140c91ac68Sthorpej * 2. Redistributions in binary form must reproduce the above copyright
150c91ac68Sthorpej * notice, this list of conditions and the following disclaimer in the
160c91ac68Sthorpej * documentation and/or other materials provided with the distribution.
170c91ac68Sthorpej * 3. All advertising materials mentioning features or use of this software
180c91ac68Sthorpej * must display the following acknowledgement:
190c91ac68Sthorpej * This product includes software developed for the NetBSD Project by
200c91ac68Sthorpej * Wasabi Systems, Inc.
210c91ac68Sthorpej * 4. The name of Wasabi Systems, Inc. may not be used to endorse
220c91ac68Sthorpej * or promote products derived from this software without specific prior
230c91ac68Sthorpej * written permission.
240c91ac68Sthorpej *
250c91ac68Sthorpej * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
260c91ac68Sthorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
270c91ac68Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
280c91ac68Sthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
290c91ac68Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
300c91ac68Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
310c91ac68Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
320c91ac68Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
330c91ac68Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
340c91ac68Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
350c91ac68Sthorpej * POSSIBILITY OF SUCH DAMAGE.
360c91ac68Sthorpej */
370c91ac68Sthorpej
380c91ac68Sthorpej /*
390c91ac68Sthorpej * pcictl(8) -- a program to manipulate the PCI bus
400c91ac68Sthorpej */
410c91ac68Sthorpej
420c91ac68Sthorpej #include <sys/param.h>
430c91ac68Sthorpej #include <sys/ioctl.h>
440c91ac68Sthorpej #include <err.h>
450c91ac68Sthorpej #include <errno.h>
460c91ac68Sthorpej #include <fcntl.h>
474c61cd90Stron #include <paths.h>
480c91ac68Sthorpej #include <pci.h>
490c91ac68Sthorpej #include <stdio.h>
500c91ac68Sthorpej #include <stdlib.h>
510c91ac68Sthorpej #include <string.h>
520c91ac68Sthorpej #include <unistd.h>
530c91ac68Sthorpej #include <util.h>
540c91ac68Sthorpej
550c91ac68Sthorpej #include <dev/pci/pcireg.h>
560c91ac68Sthorpej #include <dev/pci/pcidevs.h>
570c91ac68Sthorpej #include <dev/pci/pciio.h>
580c91ac68Sthorpej
590c91ac68Sthorpej struct command {
600c91ac68Sthorpej const char *cmd_name;
610c91ac68Sthorpej const char *arg_names;
620c91ac68Sthorpej void (*cmd_func)(int, char *[]);
630c91ac68Sthorpej int open_flags;
640c91ac68Sthorpej };
650c91ac68Sthorpej
66e7664345Sjoerg __dead static void usage(void);
670c91ac68Sthorpej
68e7664345Sjoerg static int pcifd;
690c91ac68Sthorpej
70e7664345Sjoerg static struct pciio_businfo pci_businfo;
710c91ac68Sthorpej
72e7664345Sjoerg static const char *dvname;
73e7664345Sjoerg static char dvname_store[MAXPATHLEN];
74e7664345Sjoerg static const char *cmdname;
75e7664345Sjoerg static int print_numbers = 0;
767ef7291eSmrg static int print_names = 0;
770c91ac68Sthorpej
7849fc067aScegger static void cmd_list(int, char *[]);
7949fc067aScegger static void cmd_dump(int, char *[]);
80d92cacd8Smanu static void cmd_read(int, char *[]);
81d92cacd8Smanu static void cmd_write(int, char *[]);
820c91ac68Sthorpej
83e7664345Sjoerg static const struct command commands[] = {
840c91ac68Sthorpej { "list",
851447fe10Swiz "[-Nn] [-b bus] [-d device] [-f function]",
860c91ac68Sthorpej cmd_list,
870c91ac68Sthorpej O_RDONLY },
880c91ac68Sthorpej
890c91ac68Sthorpej { "dump",
900c91ac68Sthorpej "[-b bus] -d device [-f function]",
910c91ac68Sthorpej cmd_dump,
920c91ac68Sthorpej O_RDONLY },
930c91ac68Sthorpej
94d92cacd8Smanu { "read",
95d92cacd8Smanu "[-b bus] -d device [-f function] reg",
96d92cacd8Smanu cmd_read,
97d92cacd8Smanu O_RDONLY },
98d92cacd8Smanu
99d92cacd8Smanu { "write",
100d92cacd8Smanu "[-b bus] -d device [-f function] reg value",
101d92cacd8Smanu cmd_write,
102d92cacd8Smanu O_WRONLY },
103d92cacd8Smanu
10495596468Slukem { 0, 0, 0, 0 },
1050c91ac68Sthorpej };
1060c91ac68Sthorpej
10749fc067aScegger static int parse_bdf(const char *);
108d92cacd8Smanu static u_int parse_reg(const char *);
1090c91ac68Sthorpej
11049fc067aScegger static void scan_pci(int, int, int, void (*)(u_int, u_int, u_int));
1110c91ac68Sthorpej
11249fc067aScegger static void scan_pci_list(u_int, u_int, u_int);
11349fc067aScegger static void scan_pci_dump(u_int, u_int, u_int);
1140c91ac68Sthorpej
1150c91ac68Sthorpej int
main(int argc,char * argv[])1160c91ac68Sthorpej main(int argc, char *argv[])
1170c91ac68Sthorpej {
1180c91ac68Sthorpej int i;
1190c91ac68Sthorpej
1200c91ac68Sthorpej /* Must have at least: device command */
1210c91ac68Sthorpej if (argc < 3)
1220c91ac68Sthorpej usage();
1230c91ac68Sthorpej
1240c91ac68Sthorpej /* Skip program name, get and skip device name, get command. */
1250c91ac68Sthorpej dvname = argv[1];
1260c91ac68Sthorpej cmdname = argv[2];
1270c91ac68Sthorpej argv += 2;
1280c91ac68Sthorpej argc -= 2;
1290c91ac68Sthorpej
1300c91ac68Sthorpej /* Look up and call the command. */
1310c91ac68Sthorpej for (i = 0; commands[i].cmd_name != NULL; i++)
1320c91ac68Sthorpej if (strcmp(cmdname, commands[i].cmd_name) == 0)
1330c91ac68Sthorpej break;
1340c91ac68Sthorpej if (commands[i].cmd_name == NULL)
1356face9fcScegger errx(EXIT_FAILURE, "unknown command: %s", cmdname);
1360c91ac68Sthorpej
1370c91ac68Sthorpej /* Open the device. */
1384c61cd90Stron if ((strchr(dvname, '/') == NULL) &&
1394c61cd90Stron (snprintf(dvname_store, sizeof(dvname_store), _PATH_DEV "%s",
14095596468Slukem dvname) < (int)sizeof(dvname_store)))
1410c91ac68Sthorpej dvname = dvname_store;
1424c61cd90Stron pcifd = open(dvname, commands[i].open_flags);
1434c61cd90Stron if (pcifd < 0)
1446face9fcScegger err(EXIT_FAILURE, "%s", dvname);
1450c91ac68Sthorpej
1460c91ac68Sthorpej /* Make sure the device is a PCI bus. */
1470c91ac68Sthorpej if (ioctl(pcifd, PCI_IOC_BUSINFO, &pci_businfo) != 0)
1486face9fcScegger errx(EXIT_FAILURE, "%s: not a PCI bus device", dvname);
1490c91ac68Sthorpej
1500c91ac68Sthorpej (*commands[i].cmd_func)(argc, argv);
1516face9fcScegger exit(EXIT_SUCCESS);
1520c91ac68Sthorpej }
1530c91ac68Sthorpej
15449fc067aScegger static void
usage(void)1556face9fcScegger usage(void)
1560c91ac68Sthorpej {
1570c91ac68Sthorpej int i;
1580c91ac68Sthorpej
159b635f565Sjmmv fprintf(stderr, "usage: %s device command [arg [...]]\n",
1600c91ac68Sthorpej getprogname());
1610c91ac68Sthorpej
1620c91ac68Sthorpej fprintf(stderr, " Available commands:\n");
1630c91ac68Sthorpej for (i = 0; commands[i].cmd_name != NULL; i++)
1640c91ac68Sthorpej fprintf(stderr, "\t%s %s\n", commands[i].cmd_name,
1650c91ac68Sthorpej commands[i].arg_names);
1660c91ac68Sthorpej
1676face9fcScegger exit(EXIT_FAILURE);
1680c91ac68Sthorpej }
1690c91ac68Sthorpej
17049fc067aScegger static void
cmd_list(int argc,char * argv[])1710c91ac68Sthorpej cmd_list(int argc, char *argv[])
1720c91ac68Sthorpej {
1730c91ac68Sthorpej int bus, dev, func;
1740c91ac68Sthorpej int ch;
1750c91ac68Sthorpej
17626b5a191Sjmcneill bus = -1;
1778b531ac9Sthorpej dev = func = -1;
1780c91ac68Sthorpej
1791447fe10Swiz while ((ch = getopt(argc, argv, "b:d:f:Nn")) != -1) {
1800c91ac68Sthorpej switch (ch) {
1810c91ac68Sthorpej case 'b':
1820c91ac68Sthorpej bus = parse_bdf(optarg);
1830c91ac68Sthorpej break;
1840c91ac68Sthorpej case 'd':
1850c91ac68Sthorpej dev = parse_bdf(optarg);
1860c91ac68Sthorpej break;
1870c91ac68Sthorpej case 'f':
1880c91ac68Sthorpej func = parse_bdf(optarg);
1890c91ac68Sthorpej break;
190fe81bd2fShubertf case 'n':
191fe81bd2fShubertf print_numbers = 1;
192fe81bd2fShubertf break;
1937ef7291eSmrg case 'N':
1947ef7291eSmrg print_names = 1;
1957ef7291eSmrg break;
1960c91ac68Sthorpej default:
1970c91ac68Sthorpej usage();
1980c91ac68Sthorpej }
1990c91ac68Sthorpej }
2000c91ac68Sthorpej argv += optind;
2010c91ac68Sthorpej argc -= optind;
2020c91ac68Sthorpej
2030c91ac68Sthorpej if (argc != 0)
2040c91ac68Sthorpej usage();
2050c91ac68Sthorpej
2060c91ac68Sthorpej scan_pci(bus, dev, func, scan_pci_list);
2070c91ac68Sthorpej }
2080c91ac68Sthorpej
20949fc067aScegger static void
cmd_dump(int argc,char * argv[])2100c91ac68Sthorpej cmd_dump(int argc, char *argv[])
2110c91ac68Sthorpej {
2120c91ac68Sthorpej int bus, dev, func;
2130c91ac68Sthorpej int ch;
2140c91ac68Sthorpej
2150c91ac68Sthorpej bus = pci_businfo.busno;
2160c91ac68Sthorpej func = 0;
2170c91ac68Sthorpej dev = -1;
2180c91ac68Sthorpej
219477798fcSthorpej while ((ch = getopt(argc, argv, "b:d:f:")) != -1) {
2200c91ac68Sthorpej switch (ch) {
2210c91ac68Sthorpej case 'b':
2220c91ac68Sthorpej bus = parse_bdf(optarg);
2230c91ac68Sthorpej break;
2240c91ac68Sthorpej case 'd':
2250c91ac68Sthorpej dev = parse_bdf(optarg);
2260c91ac68Sthorpej break;
2270c91ac68Sthorpej case 'f':
2280c91ac68Sthorpej func = parse_bdf(optarg);
2290c91ac68Sthorpej break;
2300c91ac68Sthorpej default:
2310c91ac68Sthorpej usage();
2320c91ac68Sthorpej }
2330c91ac68Sthorpej }
2340c91ac68Sthorpej argv += optind;
2350c91ac68Sthorpej argc -= optind;
2360c91ac68Sthorpej
2370c91ac68Sthorpej if (argc != 0)
2380c91ac68Sthorpej usage();
2390c91ac68Sthorpej
2400c91ac68Sthorpej if (bus == -1)
241efe84895Scegger errx(EXIT_FAILURE, "dump: wildcard bus number not permitted");
2420c91ac68Sthorpej if (dev == -1)
243efe84895Scegger errx(EXIT_FAILURE, "dump: must specify a device number");
2440c91ac68Sthorpej if (func == -1)
245efe84895Scegger errx(EXIT_FAILURE, "dump: wildcard function number not permitted");
2460c91ac68Sthorpej
2470c91ac68Sthorpej scan_pci(bus, dev, func, scan_pci_dump);
2480c91ac68Sthorpej }
2490c91ac68Sthorpej
250d92cacd8Smanu static void
cmd_read(int argc,char * argv[])251d92cacd8Smanu cmd_read(int argc, char *argv[])
252d92cacd8Smanu {
253d92cacd8Smanu int bus, dev, func;
254d92cacd8Smanu u_int reg;
255d92cacd8Smanu pcireg_t value;
256d92cacd8Smanu int ch;
257d92cacd8Smanu
258d92cacd8Smanu bus = pci_businfo.busno;
259d92cacd8Smanu func = 0;
260d92cacd8Smanu dev = -1;
261d92cacd8Smanu
262d92cacd8Smanu while ((ch = getopt(argc, argv, "b:d:f:")) != -1) {
263d92cacd8Smanu switch (ch) {
264d92cacd8Smanu case 'b':
265d92cacd8Smanu bus = parse_bdf(optarg);
266d92cacd8Smanu break;
267d92cacd8Smanu case 'd':
268d92cacd8Smanu dev = parse_bdf(optarg);
269d92cacd8Smanu break;
270d92cacd8Smanu case 'f':
271d92cacd8Smanu func = parse_bdf(optarg);
272d92cacd8Smanu break;
273d92cacd8Smanu default:
274d92cacd8Smanu usage();
275d92cacd8Smanu }
276d92cacd8Smanu }
277d92cacd8Smanu argv += optind;
278d92cacd8Smanu argc -= optind;
279d92cacd8Smanu
280d92cacd8Smanu if (argc != 1)
281d92cacd8Smanu usage();
282d92cacd8Smanu reg = parse_reg(argv[0]);
283d92cacd8Smanu if (pcibus_conf_read(pcifd, bus, dev, func, reg, &value) == -1)
284d92cacd8Smanu err(EXIT_FAILURE, "pcibus_conf_read"
285d92cacd8Smanu "(bus %d dev %d func %d reg %u)", bus, dev, func, reg);
286d92cacd8Smanu if (printf("%08x\n", value) < 0)
287d92cacd8Smanu err(EXIT_FAILURE, "printf");
288d92cacd8Smanu }
289d92cacd8Smanu
290d92cacd8Smanu static void
cmd_write(int argc,char * argv[])291d92cacd8Smanu cmd_write(int argc, char *argv[])
292d92cacd8Smanu {
293d92cacd8Smanu int bus, dev, func;
294d92cacd8Smanu u_int reg;
295d92cacd8Smanu pcireg_t value;
296d92cacd8Smanu int ch;
297d92cacd8Smanu
298d92cacd8Smanu bus = pci_businfo.busno;
299d92cacd8Smanu func = 0;
300d92cacd8Smanu dev = -1;
301d92cacd8Smanu
302d92cacd8Smanu while ((ch = getopt(argc, argv, "b:d:f:")) != -1) {
303d92cacd8Smanu switch (ch) {
304d92cacd8Smanu case 'b':
305d92cacd8Smanu bus = parse_bdf(optarg);
306d92cacd8Smanu break;
307d92cacd8Smanu case 'd':
308d92cacd8Smanu dev = parse_bdf(optarg);
309d92cacd8Smanu break;
310d92cacd8Smanu case 'f':
311d92cacd8Smanu func = parse_bdf(optarg);
312d92cacd8Smanu break;
313d92cacd8Smanu default:
314d92cacd8Smanu usage();
315d92cacd8Smanu }
316d92cacd8Smanu }
317d92cacd8Smanu argv += optind;
318d92cacd8Smanu argc -= optind;
319d92cacd8Smanu
320d92cacd8Smanu if (argc != 2)
321d92cacd8Smanu usage();
322d92cacd8Smanu reg = parse_reg(argv[0]);
323d92cacd8Smanu __CTASSERT(sizeof(value) == sizeof(u_int));
324d92cacd8Smanu value = parse_reg(argv[1]);
325d92cacd8Smanu if (pcibus_conf_write(pcifd, bus, dev, func, reg, value) == -1)
326d92cacd8Smanu err(EXIT_FAILURE, "pcibus_conf_write"
327d92cacd8Smanu "(bus %d dev %d func %d reg %u value 0x%x)",
328d92cacd8Smanu bus, dev, func, reg, value);
329d92cacd8Smanu }
330d92cacd8Smanu
33149fc067aScegger static int
parse_bdf(const char * str)3320c91ac68Sthorpej parse_bdf(const char *str)
3330c91ac68Sthorpej {
334f51bc9e6Sjoda long value;
335f51bc9e6Sjoda char *end;
3360c91ac68Sthorpej
3370c91ac68Sthorpej if (strcmp(str, "all") == 0 ||
3380c91ac68Sthorpej strcmp(str, "any") == 0)
3390c91ac68Sthorpej return (-1);
3400c91ac68Sthorpej
341d92cacd8Smanu errno = 0;
342f51bc9e6Sjoda value = strtol(str, &end, 0);
343d92cacd8Smanu if ((str[0] == '\0') || (*end != '\0'))
344d92cacd8Smanu errx(EXIT_FAILURE, "\"%s\" is not a number", str);
345d92cacd8Smanu if ((errno == ERANGE) && ((value == LONG_MIN) || (value == LONG_MAX)))
346d92cacd8Smanu errx(EXIT_FAILURE, "out of range: %s", str);
347d92cacd8Smanu if ((value < INT_MIN) || (INT_MAX < value))
348d92cacd8Smanu errx(EXIT_FAILURE, "out of range: %lu", value);
349d92cacd8Smanu
350d92cacd8Smanu return value;
351d92cacd8Smanu }
352d92cacd8Smanu
353d92cacd8Smanu static u_int
parse_reg(const char * str)354d92cacd8Smanu parse_reg(const char *str)
355d92cacd8Smanu {
356d92cacd8Smanu unsigned long value;
357d92cacd8Smanu char *end;
358d92cacd8Smanu
359d92cacd8Smanu errno = 0;
360d92cacd8Smanu value = strtoul(str, &end, 0);
361f51bc9e6Sjoda if (*end != '\0')
362efe84895Scegger errx(EXIT_FAILURE, "\"%s\" is not a number", str);
363d92cacd8Smanu if ((errno == ERANGE) && (value == ULONG_MAX))
364d92cacd8Smanu errx(EXIT_FAILURE, "out of range: %s", str);
365d92cacd8Smanu if (UINT_MAX < value)
366d92cacd8Smanu errx(EXIT_FAILURE, "out of range: %lu", value);
367f51bc9e6Sjoda
368f51bc9e6Sjoda return value;
3690c91ac68Sthorpej }
3700c91ac68Sthorpej
37149fc067aScegger static void
scan_pci(int busarg,int devarg,int funcarg,void (* cb)(u_int,u_int,u_int))3720c91ac68Sthorpej scan_pci(int busarg, int devarg, int funcarg, void (*cb)(u_int, u_int, u_int))
3730c91ac68Sthorpej {
3740c91ac68Sthorpej u_int busmin, busmax;
3750c91ac68Sthorpej u_int devmin, devmax;
3760c91ac68Sthorpej u_int funcmin, funcmax;
3770c91ac68Sthorpej u_int bus, dev, func;
3780c91ac68Sthorpej pcireg_t id, bhlcr;
3790c91ac68Sthorpej
3800c91ac68Sthorpej if (busarg == -1) {
3810c91ac68Sthorpej busmin = 0;
3820c91ac68Sthorpej busmax = 255;
3830c91ac68Sthorpej } else
3840c91ac68Sthorpej busmin = busmax = busarg;
3850c91ac68Sthorpej
3860c91ac68Sthorpej if (devarg == -1) {
3870c91ac68Sthorpej devmin = 0;
3882abd1dd1Sbsh if (pci_businfo.maxdevs <= 0)
3892abd1dd1Sbsh devmax = 0;
3902abd1dd1Sbsh else
3910c91ac68Sthorpej devmax = pci_businfo.maxdevs - 1;
3920c91ac68Sthorpej } else
3930c91ac68Sthorpej devmin = devmax = devarg;
3940c91ac68Sthorpej
3950c91ac68Sthorpej for (bus = busmin; bus <= busmax; bus++) {
3960c91ac68Sthorpej for (dev = devmin; dev <= devmax; dev++) {
3970c91ac68Sthorpej if (pcibus_conf_read(pcifd, bus, dev, 0,
3980c91ac68Sthorpej PCI_BHLC_REG, &bhlcr) != 0)
3990c91ac68Sthorpej continue;
4000c91ac68Sthorpej if (funcarg == -1) {
4010c91ac68Sthorpej funcmin = 0;
4020c91ac68Sthorpej if (PCI_HDRTYPE_MULTIFN(bhlcr))
4030c91ac68Sthorpej funcmax = 7;
4040c91ac68Sthorpej else
4050c91ac68Sthorpej funcmax = 0;
4060c91ac68Sthorpej } else
4070c91ac68Sthorpej funcmin = funcmax = funcarg;
4080c91ac68Sthorpej for (func = funcmin; func <= funcmax; func++) {
4090c91ac68Sthorpej if (pcibus_conf_read(pcifd, bus, dev,
4100c91ac68Sthorpej func, PCI_ID_REG, &id) != 0)
4110c91ac68Sthorpej continue;
4120c91ac68Sthorpej
4130c91ac68Sthorpej /* Invalid vendor ID value? */
4140c91ac68Sthorpej if (PCI_VENDOR(id) == PCI_VENDOR_INVALID)
4150c91ac68Sthorpej continue;
4160c91ac68Sthorpej /*
4170c91ac68Sthorpej * XXX Not invalid, but we've done this
4180c91ac68Sthorpej * ~forever.
4190c91ac68Sthorpej */
4200c91ac68Sthorpej if (PCI_VENDOR(id) == 0)
4210c91ac68Sthorpej continue;
4220c91ac68Sthorpej
4230c91ac68Sthorpej (*cb)(bus, dev, func);
4240c91ac68Sthorpej }
4250c91ac68Sthorpej }
4260c91ac68Sthorpej }
4270c91ac68Sthorpej }
4280c91ac68Sthorpej
42949fc067aScegger static void
scan_pci_list(u_int bus,u_int dev,u_int func)4300c91ac68Sthorpej scan_pci_list(u_int bus, u_int dev, u_int func)
4310c91ac68Sthorpej {
4320c91ac68Sthorpej pcireg_t id, class;
4330c91ac68Sthorpej char devinfo[256];
4340c91ac68Sthorpej
4350c91ac68Sthorpej if (pcibus_conf_read(pcifd, bus, dev, func, PCI_ID_REG, &id) != 0)
4360c91ac68Sthorpej return;
4370c91ac68Sthorpej if (pcibus_conf_read(pcifd, bus, dev, func, PCI_CLASS_REG, &class) != 0)
4380c91ac68Sthorpej return;
4390c91ac68Sthorpej
440fe81bd2fShubertf printf("%03u:%02u:%01u: ", bus, dev, func);
441fe81bd2fShubertf if (print_numbers) {
4427ef7291eSmrg printf("0x%08x (0x%08x)", id, class);
443fe81bd2fShubertf } else {
4449ef6a94eSkleink pci_devinfo(id, class, 1, devinfo, sizeof(devinfo));
4457ef7291eSmrg printf("%s", devinfo);
446fe81bd2fShubertf }
4477ef7291eSmrg if (print_names) {
4487ef7291eSmrg char drvname[16];
449*a29b8a92Smrg if (pci_drvnameonbus(pcifd, bus, dev, func, drvname,
450*a29b8a92Smrg sizeof drvname) == 0)
4517ef7291eSmrg printf(" [%s]", drvname);
4527ef7291eSmrg }
4537ef7291eSmrg printf("\n");
4540c91ac68Sthorpej }
4550c91ac68Sthorpej
45649fc067aScegger static void
scan_pci_dump(u_int bus,u_int dev,u_int func)4570c91ac68Sthorpej scan_pci_dump(u_int bus, u_int dev, u_int func)
4580c91ac68Sthorpej {
4590c91ac68Sthorpej
4600c91ac68Sthorpej pci_conf_print(pcifd, bus, dev, func);
4610c91ac68Sthorpej }
462