2001-04-21 00:13:25 +00:00
|
|
|
/*-
|
2017-11-27 15:37:16 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2001-04-21 00:13:25 +00:00
|
|
|
* Copyright (c) 2000, 2001 Michael Smith
|
|
|
|
* Copyright (c) 2000 BSDi
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print information about system device configuration.
|
|
|
|
*/
|
|
|
|
|
2004-01-04 15:51:32 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2001-04-21 00:13:25 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <stdio.h>
|
2006-09-29 16:46:01 +00:00
|
|
|
#include <stdlib.h>
|
2017-12-21 18:51:47 +00:00
|
|
|
#include <string.h>
|
2001-04-21 00:13:25 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include "devinfo.h"
|
|
|
|
|
2011-11-06 19:01:48 +00:00
|
|
|
static int rflag;
|
|
|
|
static int vflag;
|
2001-04-21 00:13:25 +00:00
|
|
|
|
2001-12-09 07:32:55 +00:00
|
|
|
static void print_resource(struct devinfo_res *);
|
|
|
|
static int print_device_matching_resource(struct devinfo_res *, void *);
|
|
|
|
static int print_device_rman_resources(struct devinfo_rman *, void *);
|
|
|
|
static int print_device(struct devinfo_dev *, void *);
|
|
|
|
static int print_rman_resource(struct devinfo_res *, void *);
|
|
|
|
static int print_rman(struct devinfo_rman *, void *);
|
|
|
|
|
2001-04-21 00:13:25 +00:00
|
|
|
struct indent_arg
|
|
|
|
{
|
|
|
|
int indent;
|
|
|
|
void *arg;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print a resource.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
print_resource(struct devinfo_res *res)
|
|
|
|
{
|
|
|
|
struct devinfo_rman *rman;
|
|
|
|
int hexmode;
|
|
|
|
|
|
|
|
rman = devinfo_handle_to_rman(res->dr_rman);
|
2007-10-27 13:06:15 +00:00
|
|
|
hexmode = (rman->dm_size > 1000) || (rman->dm_size == 0);
|
Use uintmax_t (typedef'd to rman_res_t type) for rman ranges.
On some architectures, u_long isn't large enough for resource definitions.
Particularly, powerpc and arm allow 36-bit (or larger) physical addresses, but
type `long' is only 32-bit. This extends rman's resources to uintmax_t. With
this change, any resource can feasibly be placed anywhere in physical memory
(within the constraints of the driver).
Why uintmax_t and not something machine dependent, or uint64_t? Though it's
possible for uintmax_t to grow, it's highly unlikely it will become 128-bit on
32-bit architectures. 64-bit architectures should have plenty of RAM to absorb
the increase on resource sizes if and when this occurs, and the number of
resources on memory-constrained systems should be sufficiently small as to not
pose a drastic overhead. That being said, uintmax_t was chosen for source
clarity. If it's specified as uint64_t, all printf()-like calls would either
need casts to uintmax_t, or be littered with PRI*64 macros. Casts to uintmax_t
aren't horrible, but it would also bake into the API for
resource_list_print_type() either a hidden assumption that entries get cast to
uintmax_t for printing, or these calls would need the PRI*64 macros. Since
source code is meant to be read more often than written, I chose the clearest
path of simply using uintmax_t.
Tested on a PowerPC p5020-based board, which places all device resources in
0xfxxxxxxxx, and has 8GB RAM.
Regression tested on qemu-system-i386
Regression tested on qemu-system-mips (malta profile)
Tested PAE and devinfo on virtualbox (live CD)
Special thanks to bz for his testing on ARM.
Reviewed By: bz, jhb (previous)
Relnotes: Yes
Sponsored by: Alex Perez/Inertial Computing
Differential Revision: https://reviews.freebsd.org/D4544
2016-03-18 01:28:41 +00:00
|
|
|
printf(hexmode ? "0x%jx" : "%ju", res->dr_start);
|
2001-04-21 00:13:25 +00:00
|
|
|
if (res->dr_size > 1)
|
Use uintmax_t (typedef'd to rman_res_t type) for rman ranges.
On some architectures, u_long isn't large enough for resource definitions.
Particularly, powerpc and arm allow 36-bit (or larger) physical addresses, but
type `long' is only 32-bit. This extends rman's resources to uintmax_t. With
this change, any resource can feasibly be placed anywhere in physical memory
(within the constraints of the driver).
Why uintmax_t and not something machine dependent, or uint64_t? Though it's
possible for uintmax_t to grow, it's highly unlikely it will become 128-bit on
32-bit architectures. 64-bit architectures should have plenty of RAM to absorb
the increase on resource sizes if and when this occurs, and the number of
resources on memory-constrained systems should be sufficiently small as to not
pose a drastic overhead. That being said, uintmax_t was chosen for source
clarity. If it's specified as uint64_t, all printf()-like calls would either
need casts to uintmax_t, or be littered with PRI*64 macros. Casts to uintmax_t
aren't horrible, but it would also bake into the API for
resource_list_print_type() either a hidden assumption that entries get cast to
uintmax_t for printing, or these calls would need the PRI*64 macros. Since
source code is meant to be read more often than written, I chose the clearest
path of simply using uintmax_t.
Tested on a PowerPC p5020-based board, which places all device resources in
0xfxxxxxxxx, and has 8GB RAM.
Regression tested on qemu-system-i386
Regression tested on qemu-system-mips (malta profile)
Tested PAE and devinfo on virtualbox (live CD)
Special thanks to bz for his testing on ARM.
Reviewed By: bz, jhb (previous)
Relnotes: Yes
Sponsored by: Alex Perez/Inertial Computing
Differential Revision: https://reviews.freebsd.org/D4544
2016-03-18 01:28:41 +00:00
|
|
|
printf(hexmode ? "-0x%jx" : "-%ju",
|
2001-04-21 00:13:25 +00:00
|
|
|
res->dr_start + res->dr_size - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print resource information if this resource matches the
|
|
|
|
* given device.
|
|
|
|
*
|
|
|
|
* If the given indent is 0, return an indicator that a matching
|
|
|
|
* resource exists.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
print_device_matching_resource(struct devinfo_res *res, void *arg)
|
|
|
|
{
|
|
|
|
struct indent_arg *ia = (struct indent_arg *)arg;
|
|
|
|
struct devinfo_dev *dev = (struct devinfo_dev *)ia->arg;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (devinfo_handle_to_device(res->dr_device) == dev) {
|
|
|
|
/* in 'detect' mode, found a match */
|
|
|
|
if (ia->indent == 0)
|
|
|
|
return(1);
|
|
|
|
for (i = 0; i < ia->indent; i++)
|
|
|
|
printf(" ");
|
|
|
|
print_resource(res);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print resource information for this device and resource manager.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
print_device_rman_resources(struct devinfo_rman *rman, void *arg)
|
|
|
|
{
|
|
|
|
struct indent_arg *ia = (struct indent_arg *)arg;
|
|
|
|
int indent, i;
|
|
|
|
|
|
|
|
indent = ia->indent;
|
|
|
|
|
|
|
|
/* check whether there are any resources matching this device */
|
|
|
|
ia->indent = 0;
|
|
|
|
if (devinfo_foreach_rman_resource(rman,
|
|
|
|
print_device_matching_resource, ia) != 0) {
|
|
|
|
|
|
|
|
/* there are, print header */
|
|
|
|
for (i = 0; i < indent; i++)
|
|
|
|
printf(" ");
|
|
|
|
printf("%s:\n", rman->dm_desc);
|
|
|
|
|
|
|
|
/* print resources */
|
|
|
|
ia->indent = indent + 4;
|
|
|
|
devinfo_foreach_rman_resource(rman,
|
|
|
|
print_device_matching_resource, ia);
|
|
|
|
}
|
|
|
|
ia->indent = indent;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2017-12-21 19:19:43 +00:00
|
|
|
static void
|
|
|
|
print_dev(struct devinfo_dev *dev)
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("%s", dev->dd_name[0] ? dev->dd_name : "unknown");
|
|
|
|
if (vflag && *dev->dd_pnpinfo)
|
|
|
|
printf(" pnpinfo %s", dev->dd_pnpinfo);
|
|
|
|
if (vflag && *dev->dd_location)
|
|
|
|
printf(" at %s", dev->dd_location);
|
|
|
|
if (!(dev->dd_flags & DF_ENABLED))
|
|
|
|
printf(" (disabled)");
|
|
|
|
else if (dev->dd_flags & DF_SUSPENDED)
|
|
|
|
printf(" (suspended)");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-21 00:13:25 +00:00
|
|
|
/*
|
|
|
|
* Print information about a device.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
print_device(struct devinfo_dev *dev, void *arg)
|
|
|
|
{
|
|
|
|
struct indent_arg ia;
|
|
|
|
int i, indent;
|
|
|
|
|
2009-11-15 16:44:43 +00:00
|
|
|
if (vflag || (dev->dd_name[0] != 0 && dev->dd_state >= DS_ATTACHED)) {
|
2001-12-09 07:32:55 +00:00
|
|
|
indent = (int)(intptr_t)arg;
|
2001-04-21 00:13:25 +00:00
|
|
|
for (i = 0; i < indent; i++)
|
|
|
|
printf(" ");
|
2017-12-21 19:19:43 +00:00
|
|
|
print_dev(dev);
|
2003-02-17 18:56:54 +00:00
|
|
|
printf("\n");
|
2001-04-21 00:13:25 +00:00
|
|
|
if (rflag) {
|
|
|
|
ia.indent = indent + 4;
|
|
|
|
ia.arg = dev;
|
|
|
|
devinfo_foreach_rman(print_device_rman_resources,
|
|
|
|
(void *)&ia);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(devinfo_foreach_device_child(dev, print_device,
|
2001-12-09 07:32:55 +00:00
|
|
|
(void *)((char *)arg + 2)));
|
2001-04-21 00:13:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print information about a resource under a resource manager.
|
|
|
|
*/
|
|
|
|
int
|
2001-12-09 07:32:55 +00:00
|
|
|
print_rman_resource(struct devinfo_res *res, void *arg __unused)
|
2001-04-21 00:13:25 +00:00
|
|
|
{
|
|
|
|
struct devinfo_dev *dev;
|
|
|
|
|
|
|
|
printf(" ");
|
|
|
|
print_resource(res);
|
|
|
|
dev = devinfo_handle_to_device(res->dr_device);
|
|
|
|
if ((dev != NULL) && (dev->dd_name[0] != 0)) {
|
|
|
|
printf(" (%s)", dev->dd_name);
|
|
|
|
} else {
|
|
|
|
printf(" ----");
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print information about a resource manager.
|
|
|
|
*/
|
|
|
|
int
|
2001-12-09 07:32:55 +00:00
|
|
|
print_rman(struct devinfo_rman *rman, void *arg __unused)
|
2001-04-21 00:13:25 +00:00
|
|
|
{
|
|
|
|
printf("%s:\n", rman->dm_desc);
|
|
|
|
devinfo_foreach_rman_resource(rman, print_rman_resource, 0);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2017-12-21 18:51:47 +00:00
|
|
|
static int
|
|
|
|
print_path(struct devinfo_dev *dev, void *xname)
|
|
|
|
{
|
|
|
|
const char *name = xname;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
if (strcmp(dev->dd_name, name) == 0) {
|
2017-12-21 19:19:43 +00:00
|
|
|
print_dev(dev);
|
|
|
|
if (vflag)
|
|
|
|
printf("\n");
|
2017-12-21 18:51:47 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = devinfo_foreach_device_child(dev, print_path, xname);
|
2017-12-21 19:19:43 +00:00
|
|
|
if (rv == 1) {
|
|
|
|
printf(" ");
|
|
|
|
print_dev(dev);
|
|
|
|
if (vflag)
|
|
|
|
printf("\n");
|
|
|
|
}
|
2017-12-21 18:51:47 +00:00
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
2017-12-21 19:19:43 +00:00
|
|
|
static void __dead2
|
|
|
|
usage(void)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s\n%s\n%s\n",
|
|
|
|
"usage: devinfo [-rv]",
|
|
|
|
" devinfo -u",
|
|
|
|
" devifno -p dev [-v]");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2001-04-21 00:13:25 +00:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct devinfo_dev *root;
|
|
|
|
int c, uflag;
|
2017-12-21 19:19:43 +00:00
|
|
|
char *path = NULL;
|
2001-04-21 00:13:25 +00:00
|
|
|
|
|
|
|
uflag = 0;
|
2017-12-21 18:51:47 +00:00
|
|
|
while ((c = getopt(argc, argv, "p:ruv")) != -1) {
|
2001-04-21 00:13:25 +00:00
|
|
|
switch(c) {
|
2017-12-21 18:51:47 +00:00
|
|
|
case 'p':
|
|
|
|
path = optarg;
|
|
|
|
break;
|
2001-04-21 00:13:25 +00:00
|
|
|
case 'r':
|
|
|
|
rflag++;
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
uflag++;
|
|
|
|
break;
|
2002-09-20 02:26:58 +00:00
|
|
|
case 'v':
|
|
|
|
vflag++;
|
|
|
|
break;
|
2001-04-21 00:13:25 +00:00
|
|
|
default:
|
2017-12-21 18:51:47 +00:00
|
|
|
usage();
|
2001-04-21 00:13:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-21 18:51:47 +00:00
|
|
|
if (path && (rflag || uflag))
|
|
|
|
usage();
|
|
|
|
|
2001-04-21 00:13:25 +00:00
|
|
|
if (devinfo_init())
|
|
|
|
err(1, "devinfo_init");
|
|
|
|
|
|
|
|
if ((root = devinfo_handle_to_device(DEVINFO_ROOT_DEVICE)) == NULL)
|
|
|
|
errx(1, "can't find root device");
|
|
|
|
|
2017-12-21 18:51:47 +00:00
|
|
|
if (path) {
|
|
|
|
if (devinfo_foreach_device_child(root, print_path, (void *)path) == 0)
|
|
|
|
errx(1, "%s: Not found", path);
|
2017-12-21 19:19:43 +00:00
|
|
|
if (!vflag)
|
|
|
|
printf("\n");
|
2017-12-21 18:51:47 +00:00
|
|
|
} else if (uflag) {
|
|
|
|
/* print resource usage? */
|
2001-04-21 00:13:25 +00:00
|
|
|
devinfo_foreach_rman(print_rman, NULL);
|
|
|
|
} else {
|
|
|
|
/* print device hierarchy */
|
|
|
|
devinfo_foreach_device_child(root, print_device, (void *)0);
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|