Home | History | Annotate | Line # | Download | only in ddb
db_autoconf.c revision 1.2
      1  1.2  mlelstv /*	$NetBSD: db_autoconf.c,v 1.2 2018/03/05 07:47:21 mlelstv Exp $	*/
      2  1.1  mlelstv 
      3  1.1  mlelstv /*-
      4  1.1  mlelstv  * Copyright (c) 2016 The NetBSD Foundation, Inc.
      5  1.1  mlelstv  * All rights reserved.
      6  1.1  mlelstv  *
      7  1.1  mlelstv  * Redistribution and use in source and binary forms, with or without
      8  1.1  mlelstv  * modification, are permitted provided that the following conditions
      9  1.1  mlelstv  * are met:
     10  1.1  mlelstv  * 1. Redistributions of source code must retain the above copyright
     11  1.1  mlelstv  *    notice, this list of conditions and the following disclaimer.
     12  1.1  mlelstv  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  mlelstv  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  mlelstv  *    documentation and/or other materials provided with the distribution.
     15  1.1  mlelstv  *
     16  1.1  mlelstv  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  1.1  mlelstv  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  1.1  mlelstv  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  1.1  mlelstv  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  1.1  mlelstv  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  1.1  mlelstv  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  1.1  mlelstv  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  1.1  mlelstv  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  1.1  mlelstv  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  1.1  mlelstv  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  1.1  mlelstv  * POSSIBILITY OF SUCH DAMAGE.
     27  1.1  mlelstv  */
     28  1.1  mlelstv 
     29  1.1  mlelstv #include <sys/cdefs.h>
     30  1.2  mlelstv __KERNEL_RCSID(0, "$NetBSD: db_autoconf.c,v 1.2 2018/03/05 07:47:21 mlelstv Exp $");
     31  1.1  mlelstv 
     32  1.1  mlelstv #ifndef _KERNEL
     33  1.1  mlelstv #include <stdbool.h>
     34  1.1  mlelstv #endif
     35  1.1  mlelstv 
     36  1.1  mlelstv #include <sys/param.h>
     37  1.1  mlelstv #include <sys/device.h>
     38  1.1  mlelstv 
     39  1.1  mlelstv #include <ddb/ddb.h>
     40  1.1  mlelstv 
     41  1.1  mlelstv static const char *classnames[] = {
     42  1.1  mlelstv 	"dull", "cpu", "disk", "ifnet", "tape", "tty",
     43  1.1  mlelstv 	"audiodev", "displaydev", "bus", "virtual"
     44  1.1  mlelstv };
     45  1.1  mlelstv 
     46  1.1  mlelstv struct device *
     47  1.1  mlelstv db_device_first(void)
     48  1.1  mlelstv {
     49  1.1  mlelstv 
     50  1.1  mlelstv 	return db_read_ptr("alldevs");
     51  1.1  mlelstv }
     52  1.1  mlelstv 
     53  1.1  mlelstv struct device *
     54  1.1  mlelstv db_device_next(struct device *dv)
     55  1.1  mlelstv {
     56  1.1  mlelstv 
     57  1.1  mlelstv 	db_read_bytes((db_addr_t)&dv->dv_list.tqe_next, sizeof(dv),
     58  1.1  mlelstv 	    (char *)&dv);
     59  1.1  mlelstv 	return dv;
     60  1.1  mlelstv }
     61  1.1  mlelstv 
     62  1.1  mlelstv void
     63  1.1  mlelstv db_show_all_devices(db_expr_t addr, bool haddr, db_expr_t count,
     64  1.1  mlelstv 		  const char *modif)
     65  1.1  mlelstv {
     66  1.1  mlelstv 	struct device buf;
     67  1.1  mlelstv 	struct device *dv;
     68  1.1  mlelstv 	const char *cl;
     69  1.1  mlelstv 
     70  1.1  mlelstv 	db_printf("%-16s %10s %4s %18s %18s\n",
     71  1.1  mlelstv 		"NAME","CLASS","UNIT","DEVICE_T","PRIVATE");
     72  1.1  mlelstv 
     73  1.1  mlelstv 	for (dv = db_device_first(); dv != NULL; dv = db_device_next(dv)) {
     74  1.1  mlelstv 		db_read_bytes((db_addr_t)dv, sizeof(buf), (char *)&buf);
     75  1.1  mlelstv 
     76  1.2  mlelstv 		unsigned i = buf.dv_class;
     77  1.2  mlelstv 
     78  1.2  mlelstv 		if (i >= __arraycount(classnames))
     79  1.1  mlelstv 			cl = "????";
     80  1.1  mlelstv 		else
     81  1.2  mlelstv 			cl = classnames[i];
     82  1.1  mlelstv 
     83  1.1  mlelstv 		db_printf("%-16.16s", buf.dv_xname);
     84  1.1  mlelstv 		db_printf(" %10s", cl);
     85  1.1  mlelstv 		db_printf(" %4u", buf.dv_unit);
     86  1.1  mlelstv 		db_printf(" %18" PRIxPTR, (uintptr_t)dv);
     87  1.1  mlelstv 		db_printf(" %18" PRIxPTR, (uintptr_t)buf.dv_private);
     88  1.1  mlelstv 		db_printf("\n");
     89  1.1  mlelstv 	}
     90  1.1  mlelstv }
     91