promdev.c revision 1.1.8.2 1 1.1.8.2 nathanw /* $NetBSD: promdev.c,v 1.1.8.2 2002/06/20 03:42:01 nathanw Exp $ */
2 1.1.8.2 nathanw
3 1.1.8.2 nathanw /*
4 1.1.8.2 nathanw * Copyright (c) 1995 Gordon W. Ross
5 1.1.8.2 nathanw * Copyright (c) 1993 Paul Kranenburg
6 1.1.8.2 nathanw * All rights reserved.
7 1.1.8.2 nathanw *
8 1.1.8.2 nathanw * Redistribution and use in source and binary forms, with or without
9 1.1.8.2 nathanw * modification, are permitted provided that the following conditions
10 1.1.8.2 nathanw * are met:
11 1.1.8.2 nathanw * 1. Redistributions of source code must retain the above copyright
12 1.1.8.2 nathanw * notice, this list of conditions and the following disclaimer.
13 1.1.8.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
14 1.1.8.2 nathanw * notice, this list of conditions and the following disclaimer in the
15 1.1.8.2 nathanw * documentation and/or other materials provided with the distribution.
16 1.1.8.2 nathanw * 3. All advertising materials mentioning features or use of this software
17 1.1.8.2 nathanw * must display the following acknowledgement:
18 1.1.8.2 nathanw * This product includes software developed by Paul Kranenburg.
19 1.1.8.2 nathanw * 4. The name of the author may not be used to endorse or promote products
20 1.1.8.2 nathanw * derived from this software without specific prior written permission
21 1.1.8.2 nathanw *
22 1.1.8.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.1.8.2 nathanw * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1.8.2 nathanw * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1.8.2 nathanw * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.1.8.2 nathanw * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.1.8.2 nathanw * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.1.8.2 nathanw * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.1.8.2 nathanw * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.1.8.2 nathanw * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.1.8.2 nathanw * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1.8.2 nathanw */
33 1.1.8.2 nathanw
34 1.1.8.2 nathanw #include <sys/types.h>
35 1.1.8.2 nathanw #include <machine/mon.h>
36 1.1.8.2 nathanw
37 1.1.8.2 nathanw #include <stand.h>
38 1.1.8.2 nathanw
39 1.1.8.2 nathanw #include "libsa.h"
40 1.1.8.2 nathanw #include "dvma.h"
41 1.1.8.2 nathanw #include "saio.h"
42 1.1.8.2 nathanw
43 1.1.8.2 nathanw int promdev_inuse;
44 1.1.8.2 nathanw
45 1.1.8.2 nathanw /*
46 1.1.8.2 nathanw * Note: caller sets the fields:
47 1.1.8.2 nathanw * si->si_boottab
48 1.1.8.2 nathanw * si->si_ctlr
49 1.1.8.2 nathanw * si->si_unit
50 1.1.8.2 nathanw * si->si_boff
51 1.1.8.2 nathanw */
52 1.1.8.2 nathanw
53 1.1.8.2 nathanw int
54 1.1.8.2 nathanw prom_iopen(si)
55 1.1.8.2 nathanw struct saioreq *si;
56 1.1.8.2 nathanw {
57 1.1.8.2 nathanw struct boottab *ops;
58 1.1.8.2 nathanw struct devinfo *dip;
59 1.1.8.2 nathanw int i, ctlr, error;
60 1.1.8.2 nathanw
61 1.1.8.2 nathanw if (promdev_inuse)
62 1.1.8.2 nathanw return(EMFILE);
63 1.1.8.2 nathanw
64 1.1.8.2 nathanw ops = si->si_boottab;
65 1.1.8.2 nathanw dip = ops->b_devinfo;
66 1.1.8.2 nathanw ctlr = si->si_ctlr;
67 1.1.8.2 nathanw
68 1.1.8.2 nathanw #ifdef DEBUG_PROM
69 1.1.8.2 nathanw if (debug) {
70 1.1.8.2 nathanw printf("Boot device type: %s\n", ops->b_desc);
71 1.1.8.2 nathanw }
72 1.1.8.2 nathanw #endif
73 1.1.8.2 nathanw
74 1.1.8.2 nathanw if (!_is2) {
75 1.1.8.2 nathanw #ifdef DEBUG_PROM
76 1.1.8.2 nathanw if (debug) {
77 1.1.8.2 nathanw printf("d_devbytes=%d\n", dip->d_devbytes);
78 1.1.8.2 nathanw printf("d_dmabytes=%d\n", dip->d_dmabytes);
79 1.1.8.2 nathanw printf("d_localbytes=%d\n", dip->d_localbytes);
80 1.1.8.2 nathanw printf("d_devtype=%d\n", dip->d_devtype);
81 1.1.8.2 nathanw printf("d_maxiobytes=%d\n", dip->d_maxiobytes);
82 1.1.8.2 nathanw printf("d_stdcount=%d\n", dip->d_stdcount);
83 1.1.8.2 nathanw for (i = 0; i < dip->d_stdcount; i++)
84 1.1.8.2 nathanw printf("d_stdaddrs[i]=0x%x\n",
85 1.1.8.2 nathanw i, dip->d_stdaddrs[0]);
86 1.1.8.2 nathanw }
87 1.1.8.2 nathanw #endif
88 1.1.8.2 nathanw
89 1.1.8.2 nathanw if (dip->d_devbytes && dip->d_stdcount) {
90 1.1.8.2 nathanw if (ctlr >= dip->d_stdcount) {
91 1.1.8.2 nathanw putstr("Invalid controller number\n");
92 1.1.8.2 nathanw return(ENXIO);
93 1.1.8.2 nathanw }
94 1.1.8.2 nathanw si->si_devaddr = dev_mapin(dip->d_devtype,
95 1.1.8.2 nathanw dip->d_stdaddrs[ctlr], dip->d_devbytes);
96 1.1.8.2 nathanw #ifdef DEBUG_PROM
97 1.1.8.2 nathanw if (debug)
98 1.1.8.2 nathanw printf("prom_iopen: devaddr=0x%x\n", si->si_devaddr);
99 1.1.8.2 nathanw #endif
100 1.1.8.2 nathanw }
101 1.1.8.2 nathanw
102 1.1.8.2 nathanw if (dip->d_dmabytes) {
103 1.1.8.2 nathanw si->si_dmaaddr = dvma_alloc(dip->d_dmabytes);
104 1.1.8.2 nathanw #ifdef DEBUG_PROM
105 1.1.8.2 nathanw if (debug)
106 1.1.8.2 nathanw printf("prom_iopen: dmaaddr=0x%x\n", si->si_dmaaddr);
107 1.1.8.2 nathanw #endif
108 1.1.8.2 nathanw }
109 1.1.8.2 nathanw
110 1.1.8.2 nathanw if (dip->d_localbytes) {
111 1.1.8.2 nathanw si->si_devdata = alloc(dip->d_localbytes);
112 1.1.8.2 nathanw #ifdef DEBUG_PROM
113 1.1.8.2 nathanw if (debug)
114 1.1.8.2 nathanw printf("prom_iopen: devdata=0x%x\n", si->si_devdata);
115 1.1.8.2 nathanw #endif
116 1.1.8.2 nathanw }
117 1.1.8.2 nathanw }
118 1.1.8.2 nathanw
119 1.1.8.2 nathanw /* OK, call the PROM device open routine. */
120 1.1.8.2 nathanw #ifdef DEBUG_PROM
121 1.1.8.2 nathanw if (debug)
122 1.1.8.2 nathanw printf("prom_iopen: calling prom open...\n");
123 1.1.8.2 nathanw #endif
124 1.1.8.2 nathanw error = (*ops->b_open)(si);
125 1.1.8.2 nathanw #ifdef DEBUG_PROM
126 1.1.8.2 nathanw if (debug)
127 1.1.8.2 nathanw printf("prom_iopen: prom open returned %d\n", error);
128 1.1.8.2 nathanw #endif
129 1.1.8.2 nathanw if (error != 0) {
130 1.1.8.2 nathanw #if 0 /* XXX: printf is too big for bootxx */
131 1.1.8.2 nathanw printf("prom_iopen: \"%s\" error=%d\n",
132 1.1.8.2 nathanw ops->b_desc, error);
133 1.1.8.2 nathanw #else
134 1.1.8.2 nathanw putstr("prom_iopen: prom open failed");
135 1.1.8.2 nathanw #endif
136 1.1.8.2 nathanw return (ENXIO);
137 1.1.8.2 nathanw }
138 1.1.8.2 nathanw
139 1.1.8.2 nathanw promdev_inuse++;
140 1.1.8.2 nathanw return (0);
141 1.1.8.2 nathanw }
142 1.1.8.2 nathanw
143 1.1.8.2 nathanw void
144 1.1.8.2 nathanw prom_iclose(si)
145 1.1.8.2 nathanw struct saioreq *si;
146 1.1.8.2 nathanw {
147 1.1.8.2 nathanw struct boottab *ops;
148 1.1.8.2 nathanw struct devinfo *dip;
149 1.1.8.2 nathanw
150 1.1.8.2 nathanw if (promdev_inuse == 0)
151 1.1.8.2 nathanw return;
152 1.1.8.2 nathanw
153 1.1.8.2 nathanw ops = si->si_boottab;
154 1.1.8.2 nathanw dip = ops->b_devinfo;
155 1.1.8.2 nathanw
156 1.1.8.2 nathanw #ifdef DEBUG_PROM
157 1.1.8.2 nathanw if (debug)
158 1.1.8.2 nathanw printf("prom_iclose: calling prom close...\n");
159 1.1.8.2 nathanw #endif
160 1.1.8.2 nathanw (*ops->b_close)(si);
161 1.1.8.2 nathanw
162 1.1.8.2 nathanw promdev_inuse = 0;
163 1.1.8.2 nathanw }
164 1.1.8.2 nathanw
165