xref: /netbsd-src/sys/arch/newsmips/apbus/apbus_subr.c (revision b7b7574d3bf8eeb51a1fa3977b59142ec6434a55)
1 /*	$NetBSD: apbus_subr.c,v 1.9 2014/03/24 20:05:20 christos Exp $	*/
2 
3 /*-
4  * Copyright (C) 1999 SHIMIZU Ryo.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: apbus_subr.c,v 1.9 2014/03/24 20:05:20 christos Exp $");
31 
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 
35 #include <newsmips/apbus/apbusvar.h>
36 
37 static void apctl_dump(struct apbus_ctl *);
38 
39 void *
40 apbus_device_to_hwaddr(struct apbus_dev *apbus_dev)
41 {
42 	struct apbus_ctl *ctl;
43 
44 	if (apbus_dev == NULL)
45 		return NULL;
46 
47 	ctl = apbus_dev->apbd_ctl;
48 	if (ctl == NULL)
49 		return NULL;
50 
51 	return (void *)ctl->apbc_hwbase;
52 }
53 
54 struct apbus_dev *
55 apbus_lookupdev(char *devname)
56 {
57 	struct apbus_dev *dp;
58 
59 	dp = _sip->apbsi_dev;
60 	if (devname == NULL || *devname == '\0')
61 		return dp;
62 
63 	/* search apbus_dev named 'devname' */
64 	while (dp) {
65 		if (strcmp(devname, dp->apbd_name) == 0)
66 			return dp;
67 
68 		dp = dp->apbd_link;
69 	}
70 
71 	return NULL;
72 }
73 
74 static void
75 apctl_dump(struct apbus_ctl *apctl)
76 {
77 	if (!apctl)
78 		return;
79 
80 	printf("	apbus_ctl dump (%p)\n", apctl);
81 
82 	printf("	Num:		%d\n", apctl->apbc_ctlno);
83 	printf("	HWaddr:		0x%08x\n", apctl->apbc_hwbase);
84 	printf("	softc:		%p\n", apctl->apbc_softc);
85 	printf("	Slot:		%d\n", apctl->apbc_sl);
86 	printf("\n");
87 
88 	if (apctl->apbc_link)
89 		apctl_dump(apctl->apbc_link);
90 }
91 
92 void
93 apdevice_dump(struct apbus_dev *apdev)
94 {
95 	struct apbus_ctl *apctl;
96 
97 	if (apdev == NULL)
98 		return;
99 
100 	/* only no pseudo device */
101 	apctl = apdev->apbd_ctl;
102 	if (apctl == NULL || apctl->apbc_hwbase == 0)
103 		return;
104 
105 	printf("apbus_dev dump (%p)\n", apdev);
106 	printf("name:		%s\n", apdev->apbd_name);
107 	printf("vendor:		%s\n", apdev->apbd_vendor);
108 	printf("atr:		%08x\n", apdev->apbd_atr);
109 	printf("rev:		%d\n", apdev->apbd_rev);
110 	printf("driver:		0x%08x\n", (unsigned int)apdev->apbd_driver);
111 	printf("ctl:		0x%08x\n", (unsigned int)apdev->apbd_ctl);
112 	printf("link:		0x%08x\n", (unsigned int)apdev->apbd_link);
113 	printf("\n");
114 
115 	apctl_dump(apctl);
116 }
117