zs_any.c revision 1.4.8.2 1 1.4.8.2 nathanw /* $NetBSD: zs_any.c,v 1.4.8.2 2002/01/08 00:28:08 nathanw Exp $ */
2 1.4.8.2 nathanw
3 1.4.8.2 nathanw /*-
4 1.4.8.2 nathanw * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 1.4.8.2 nathanw * All rights reserved.
6 1.4.8.2 nathanw *
7 1.4.8.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.4.8.2 nathanw * by Gordon W. Ross and Matthew Fredette.
9 1.4.8.2 nathanw *
10 1.4.8.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.4.8.2 nathanw * modification, are permitted provided that the following conditions
12 1.4.8.2 nathanw * are met:
13 1.4.8.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.4.8.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.4.8.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.4.8.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.4.8.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.4.8.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.4.8.2 nathanw * must display the following acknowledgement:
20 1.4.8.2 nathanw * This product includes software developed by the NetBSD
21 1.4.8.2 nathanw * Foundation, Inc. and its contributors.
22 1.4.8.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.4.8.2 nathanw * contributors may be used to endorse or promote products derived
24 1.4.8.2 nathanw * from this software without specific prior written permission.
25 1.4.8.2 nathanw *
26 1.4.8.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.4.8.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.4.8.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.4.8.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.4.8.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.4.8.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.4.8.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.4.8.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.4.8.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.4.8.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.4.8.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.4.8.2 nathanw */
38 1.4.8.2 nathanw
39 1.4.8.2 nathanw /*
40 1.4.8.2 nathanw * Zilog Z8530 Dual UART driver (machine-dependent part)
41 1.4.8.2 nathanw *
42 1.4.8.2 nathanw * Runs two serial lines per chip using slave drivers.
43 1.4.8.2 nathanw * Plain tty/async lines use the zs_async slave.
44 1.4.8.2 nathanw * Sun keyboard/mouse uses the zs_kbd/zs_ms slaves.
45 1.4.8.2 nathanw */
46 1.4.8.2 nathanw
47 1.4.8.2 nathanw #include "opt_kgdb.h"
48 1.4.8.2 nathanw
49 1.4.8.2 nathanw #include <sys/param.h>
50 1.4.8.2 nathanw #include <sys/systm.h>
51 1.4.8.2 nathanw #include <sys/conf.h>
52 1.4.8.2 nathanw #include <sys/device.h>
53 1.4.8.2 nathanw #include <sys/file.h>
54 1.4.8.2 nathanw #include <sys/ioctl.h>
55 1.4.8.2 nathanw #include <sys/kernel.h>
56 1.4.8.2 nathanw #include <sys/proc.h>
57 1.4.8.2 nathanw #include <sys/tty.h>
58 1.4.8.2 nathanw #include <sys/time.h>
59 1.4.8.2 nathanw #include <sys/syslog.h>
60 1.4.8.2 nathanw
61 1.4.8.2 nathanw #include <machine/autoconf.h>
62 1.4.8.2 nathanw #include <machine/bus.h>
63 1.4.8.2 nathanw #include <machine/z8530var.h>
64 1.4.8.2 nathanw
65 1.4.8.2 nathanw #ifdef KGDB
66 1.4.8.2 nathanw #include <uvm/uvm_extern.h>
67 1.4.8.2 nathanw
68 1.4.8.2 nathanw #include <machine/idprom.h>
69 1.4.8.2 nathanw #include <machine/pmap.h>
70 1.4.8.2 nathanw #include <dev/sun/cons.h>
71 1.4.8.2 nathanw #endif
72 1.4.8.2 nathanw
73 1.4.8.2 nathanw #include <sun2/sun2/machdep.h>
74 1.4.8.2 nathanw #include <dev/ic/z8530reg.h>
75 1.4.8.2 nathanw #include <dev/sun/kbd_reg.h>
76 1.4.8.2 nathanw
77 1.4.8.2 nathanw /****************************************************************
78 1.4.8.2 nathanw * Autoconfig
79 1.4.8.2 nathanw ****************************************************************/
80 1.4.8.2 nathanw
81 1.4.8.2 nathanw /* Definition of the driver for autoconfig. */
82 1.4.8.2 nathanw static int zs_any_match __P((struct device *, struct cfdata *, void *));
83 1.4.8.2 nathanw static void zs_any_attach __P((struct device *, struct device *, void *));
84 1.4.8.2 nathanw
85 1.4.8.2 nathanw struct cfattach zs_obio_ca = {
86 1.4.8.2 nathanw sizeof(struct zsc_softc), zs_any_match, zs_any_attach
87 1.4.8.2 nathanw };
88 1.4.8.2 nathanw
89 1.4.8.2 nathanw struct cfattach zs_obmem_ca = {
90 1.4.8.2 nathanw sizeof(struct zsc_softc), zs_any_match, zs_any_attach
91 1.4.8.2 nathanw };
92 1.4.8.2 nathanw
93 1.4.8.2 nathanw struct cfattach zs_mbmem_ca = {
94 1.4.8.2 nathanw sizeof(struct zsc_softc), zs_any_match, zs_any_attach
95 1.4.8.2 nathanw };
96 1.4.8.2 nathanw
97 1.4.8.2 nathanw /*
98 1.4.8.2 nathanw * Is the zs chip present?
99 1.4.8.2 nathanw */
100 1.4.8.2 nathanw static int
101 1.4.8.2 nathanw zs_any_match(parent, cf, aux)
102 1.4.8.2 nathanw struct device *parent;
103 1.4.8.2 nathanw struct cfdata *cf;
104 1.4.8.2 nathanw void *aux;
105 1.4.8.2 nathanw {
106 1.4.8.2 nathanw struct mainbus_attach_args *ma = aux;
107 1.4.8.2 nathanw bus_space_handle_t bh;
108 1.4.8.2 nathanw int matched;
109 1.4.8.2 nathanw
110 1.4.8.2 nathanw /* Make sure there is something there... */
111 1.4.8.2 nathanw if (bus_space_map(ma->ma_bustag, ma->ma_paddr, sizeof(struct zsdevice),
112 1.4.8.2 nathanw 0, &bh))
113 1.4.8.2 nathanw return (0);
114 1.4.8.2 nathanw matched = (bus_space_peek_1(ma->ma_bustag, bh, 0, NULL) == 0);
115 1.4.8.2 nathanw bus_space_unmap(ma->ma_bustag, bh, sizeof(struct zsdevice));
116 1.4.8.2 nathanw if (!matched)
117 1.4.8.2 nathanw return (0);
118 1.4.8.2 nathanw
119 1.4.8.2 nathanw /* Default interrupt priority (always splbio==2) */
120 1.4.8.2 nathanw if (ma->ma_pri == -1)
121 1.4.8.2 nathanw ma->ma_pri = ZSHARD_PRI;
122 1.4.8.2 nathanw
123 1.4.8.2 nathanw return (1);
124 1.4.8.2 nathanw }
125 1.4.8.2 nathanw
126 1.4.8.2 nathanw /*
127 1.4.8.2 nathanw * Attach a found zs.
128 1.4.8.2 nathanw */
129 1.4.8.2 nathanw static void
130 1.4.8.2 nathanw zs_any_attach(parent, self, aux)
131 1.4.8.2 nathanw struct device *parent;
132 1.4.8.2 nathanw struct device *self;
133 1.4.8.2 nathanw void *aux;
134 1.4.8.2 nathanw {
135 1.4.8.2 nathanw struct zsc_softc *zsc = (void *) self;
136 1.4.8.2 nathanw struct mainbus_attach_args *ma = aux;
137 1.4.8.2 nathanw bus_space_handle_t bh;
138 1.4.8.2 nathanw
139 1.4.8.2 nathanw zsc->zsc_bustag = ma->ma_bustag;
140 1.4.8.2 nathanw zsc->zsc_dmatag = ma->ma_dmatag;
141 1.4.8.2 nathanw zsc->zsc_promunit = self->dv_unit;
142 1.4.8.2 nathanw zsc->zsc_node = 0;
143 1.4.8.2 nathanw
144 1.4.8.2 nathanw /* Map in the device. */
145 1.4.8.2 nathanw if (bus_space_map(ma->ma_bustag, ma->ma_paddr, sizeof(struct zsdevice),
146 1.4.8.2 nathanw BUS_SPACE_MAP_LINEAR, &bh))
147 1.4.8.2 nathanw panic("zs_any_attach: can't map");
148 1.4.8.2 nathanw
149 1.4.8.2 nathanw /* This is where we break the bus_space(9) abstraction: */
150 1.4.8.2 nathanw zs_attach(zsc, (void *)bh, ma->ma_pri);
151 1.4.8.2 nathanw }
152 1.4.8.2 nathanw
153 1.4.8.2 nathanw int
154 1.4.8.2 nathanw zs_console_flags(promunit, node, channel)
155 1.4.8.2 nathanw int promunit;
156 1.4.8.2 nathanw int node;
157 1.4.8.2 nathanw int channel;
158 1.4.8.2 nathanw {
159 1.4.8.2 nathanw int cookie, flags = 0;
160 1.4.8.2 nathanw
161 1.4.8.2 nathanw /*
162 1.4.8.2 nathanw * Use `promunit' and `channel' to derive the PROM
163 1.4.8.2 nathanw * stdio handles that correspond to this device.
164 1.4.8.2 nathanw */
165 1.4.8.2 nathanw if (promunit == 0)
166 1.4.8.2 nathanw cookie = PROMDEV_TTYA + channel;
167 1.4.8.2 nathanw else if (promunit == 1 && channel == 0)
168 1.4.8.2 nathanw cookie = PROMDEV_KBD;
169 1.4.8.2 nathanw else
170 1.4.8.2 nathanw cookie = -1;
171 1.4.8.2 nathanw
172 1.4.8.2 nathanw /*
173 1.4.8.2 nathanw * We have the console keyboard only if it's a Sun-2
174 1.4.8.2 nathanw * keyboard or better. (i.e., not a Sun-1 parallel kbd).
175 1.4.8.2 nathanw */
176 1.4.8.2 nathanw if (cookie == prom_stdin() &&
177 1.4.8.2 nathanw (cookie != PROMDEV_KBD || prom_kbdid() >= KB_SUN2))
178 1.4.8.2 nathanw flags |= ZS_HWFLAG_CONSOLE_INPUT;
179 1.4.8.2 nathanw
180 1.4.8.2 nathanw /*
181 1.4.8.2 nathanw * Prevent the keyboard from matching the output device
182 1.4.8.2 nathanw * (note that PROMDEV_KBD == PROMDEV_SCREEN == 0!).
183 1.4.8.2 nathanw */
184 1.4.8.2 nathanw if (cookie != PROMDEV_KBD && cookie == prom_stdout())
185 1.4.8.2 nathanw flags |= ZS_HWFLAG_CONSOLE_OUTPUT;
186 1.4.8.2 nathanw
187 1.4.8.2 nathanw return (flags);
188 1.4.8.2 nathanw }
189 1.4.8.2 nathanw
190 1.4.8.2 nathanw #ifdef KGDB
191 1.4.8.2 nathanw /*
192 1.4.8.2 nathanw * Find a zs mapped by the PROM. Currently this only works to find
193 1.4.8.2 nathanw * zs0 on obio.
194 1.4.8.2 nathanw */
195 1.4.8.2 nathanw void *
196 1.4.8.2 nathanw zs_find_prom(unit)
197 1.4.8.2 nathanw int unit;
198 1.4.8.2 nathanw {
199 1.4.8.2 nathanw bus_addr_t zs0_phys;
200 1.4.8.2 nathanw bus_space_handle_t bh;
201 1.4.8.2 nathanw extern int sun68k_find_prom_map __P((bus_addr_t, bus_type_t,
202 1.4.8.2 nathanw int, bus_space_handle_t *));
203 1.4.8.2 nathanw
204 1.4.8.2 nathanw if (unit != 0)
205 1.4.8.2 nathanw return (NULL);
206 1.4.8.2 nathanw
207 1.4.8.2 nathanw /*
208 1.4.8.2 nathanw * The physical address of zs0 is model-dependent.
209 1.4.8.2 nathanw */
210 1.4.8.2 nathanw zs0_phys = (cpu_machine_id == SUN2_MACH_120 ?
211 1.4.8.2 nathanw 0x002000 : 0x7f2000);
212 1.4.8.2 nathanw
213 1.4.8.2 nathanw if (sun68k_find_prom_map(zs0_phys, PMAP_OBIO, sizeof(struct zsdevice), &bh))
214 1.4.8.2 nathanw return (NULL);
215 1.4.8.2 nathanw
216 1.4.8.2 nathanw return ((void*) bh);
217 1.4.8.2 nathanw }
218 1.4.8.2 nathanw #endif /* KGDB */
219