Home | History | Annotate | Line # | Download | only in ddb
      1  1.3  riastrad /*	$NetBSD: db_autoconf.c,v 1.3 2022/03/28 12:38:58 riastradh 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.3  riastrad __KERNEL_RCSID(0, "$NetBSD: db_autoconf.c,v 1.3 2022/03/28 12:38:58 riastradh 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.3  riastrad #include <sys/device_impl.h>
     39  1.1   mlelstv 
     40  1.1   mlelstv #include <ddb/ddb.h>
     41  1.1   mlelstv 
     42  1.1   mlelstv static const char *classnames[] = {
     43  1.1   mlelstv 	"dull", "cpu", "disk", "ifnet", "tape", "tty",
     44  1.1   mlelstv 	"audiodev", "displaydev", "bus", "virtual"
     45  1.1   mlelstv };
     46  1.1   mlelstv 
     47  1.1   mlelstv struct device *
     48  1.1   mlelstv db_device_first(void)
     49  1.1   mlelstv {
     50  1.1   mlelstv 
     51  1.1   mlelstv 	return db_read_ptr("alldevs");
     52  1.1   mlelstv }
     53  1.1   mlelstv 
     54  1.1   mlelstv struct device *
     55  1.1   mlelstv db_device_next(struct device *dv)
     56  1.1   mlelstv {
     57  1.1   mlelstv 
     58  1.1   mlelstv 	db_read_bytes((db_addr_t)&dv->dv_list.tqe_next, sizeof(dv),
     59  1.1   mlelstv 	    (char *)&dv);
     60  1.1   mlelstv 	return dv;
     61  1.1   mlelstv }
     62  1.1   mlelstv 
     63  1.1   mlelstv void
     64  1.1   mlelstv db_show_all_devices(db_expr_t addr, bool haddr, db_expr_t count,
     65  1.1   mlelstv 		  const char *modif)
     66  1.1   mlelstv {
     67  1.1   mlelstv 	struct device buf;
     68  1.1   mlelstv 	struct device *dv;
     69  1.1   mlelstv 	const char *cl;
     70  1.1   mlelstv 
     71  1.1   mlelstv 	db_printf("%-16s %10s %4s %18s %18s\n",
     72  1.1   mlelstv 		"NAME","CLASS","UNIT","DEVICE_T","PRIVATE");
     73  1.1   mlelstv 
     74  1.1   mlelstv 	for (dv = db_device_first(); dv != NULL; dv = db_device_next(dv)) {
     75  1.1   mlelstv 		db_read_bytes((db_addr_t)dv, sizeof(buf), (char *)&buf);
     76  1.1   mlelstv 
     77  1.2   mlelstv 		unsigned i = buf.dv_class;
     78  1.2   mlelstv 
     79  1.2   mlelstv 		if (i >= __arraycount(classnames))
     80  1.1   mlelstv 			cl = "????";
     81  1.1   mlelstv 		else
     82  1.2   mlelstv 			cl = classnames[i];
     83  1.1   mlelstv 
     84  1.1   mlelstv 		db_printf("%-16.16s", buf.dv_xname);
     85  1.1   mlelstv 		db_printf(" %10s", cl);
     86  1.1   mlelstv 		db_printf(" %4u", buf.dv_unit);
     87  1.1   mlelstv 		db_printf(" %18" PRIxPTR, (uintptr_t)dv);
     88  1.1   mlelstv 		db_printf(" %18" PRIxPTR, (uintptr_t)buf.dv_private);
     89  1.1   mlelstv 		db_printf("\n");
     90  1.1   mlelstv 	}
     91  1.1   mlelstv }
     92