apbus_subr.c revision 1.3 1 /* $NetBSD: apbus_subr.c,v 1.3 2000/12/03 01:42:29 matt 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/param.h>
30 #include <sys/systm.h>
31
32 #include <newsmips/apbus/apbusvar.h>
33
34 static void apctl_dump (struct apbus_ctl *);
35
36 void *
37 apbus_device_to_hwaddr(apbus_dev)
38 struct apbus_dev *apbus_dev;
39 {
40 struct apbus_ctl *ctl;
41
42 if (apbus_dev == NULL)
43 return NULL;
44
45 ctl = apbus_dev->apbd_ctl;
46 if (ctl == NULL)
47 return NULL;
48
49 return (void *)ctl->apbc_hwbase;
50 }
51
52 struct apbus_dev *
53 apbus_lookupdev(devname)
54 char *devname;
55 {
56 struct apbus_dev *dp;
57
58 dp = _sip->apbsi_dev;
59 if (devname == NULL || *devname == '\0')
60 return dp;
61
62 /* search apbus_dev named 'devname' */
63 while (dp) {
64 if (strcmp(devname,dp->apbd_name) == 0)
65 return dp;
66
67 dp = dp->apbd_link;
68 }
69
70 return NULL;
71 }
72
73 static void
74 apctl_dump(apctl)
75 struct apbus_ctl *apctl;
76 {
77 unsigned int *p;
78
79 if (!apctl)
80 return;
81
82 printf(" apbus_ctl dump (%p)\n", apctl);
83
84 p = (void *)apctl;
85
86 printf(" Num: %d\n", apctl->apbc_ctlno);
87 printf(" HWaddr: 0x%08x\n", apctl->apbc_hwbase);
88 printf(" softc: %p\n", apctl->apbc_softc);
89 printf(" Slot: %d\n", apctl->apbc_sl);
90 printf("\n");
91
92 if (apctl->apbc_link)
93 apctl_dump(apctl->apbc_link);
94 }
95
96 void
97 apdevice_dump(apdev)
98 struct apbus_dev *apdev;
99 {
100 struct apbus_ctl *apctl;
101
102 if (apdev == NULL)
103 return;
104
105 /* only no pseudo device */
106 apctl = apdev->apbd_ctl;
107 if (apctl == NULL || apctl->apbc_hwbase == 0)
108 return;
109
110 printf("apbus_dev dump (%p)\n", apdev);
111 printf("name: %s\n", apdev->apbd_name);
112 printf("vendor: %s\n", apdev->apbd_vendor);
113 printf("atr: %08x\n", apdev->apbd_atr);
114 printf("rev: %d\n", apdev->apbd_rev);
115 printf("driver: 0x%08x\n", (unsigned int)apdev->apbd_driver);
116 printf("ctl: 0x%08x\n", (unsigned int)apdev->apbd_ctl);
117 printf("link: 0x%08x\n", (unsigned int)apdev->apbd_link);
118 printf("\n");
119
120 apctl_dump(apctl);
121 }
122