isapnp_machdep.c revision 1.1.2.2 1 1.1.2.2 eeh /* $NetBSD: isapnp_machdep.c,v 1.1.2.2 1998/08/08 03:06:35 eeh Exp $ */
2 1.1.2.2 eeh
3 1.1.2.2 eeh /*-
4 1.1.2.2 eeh * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
5 1.1.2.2 eeh * All rights reserved.
6 1.1.2.2 eeh *
7 1.1.2.2 eeh * This code is derived from software contributed to The NetBSD Foundation
8 1.1.2.2 eeh * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 1.1.2.2 eeh * NASA Ames Research Center.
10 1.1.2.2 eeh *
11 1.1.2.2 eeh * Redistribution and use in source and binary forms, with or without
12 1.1.2.2 eeh * modification, are permitted provided that the following conditions
13 1.1.2.2 eeh * are met:
14 1.1.2.2 eeh * 1. Redistributions of source code must retain the above copyright
15 1.1.2.2 eeh * notice, this list of conditions and the following disclaimer.
16 1.1.2.2 eeh * 2. Redistributions in binary form must reproduce the above copyright
17 1.1.2.2 eeh * notice, this list of conditions and the following disclaimer in the
18 1.1.2.2 eeh * documentation and/or other materials provided with the distribution.
19 1.1.2.2 eeh * 3. All advertising materials mentioning features or use of this software
20 1.1.2.2 eeh * must display the following acknowledgement:
21 1.1.2.2 eeh * This product includes software developed by the NetBSD
22 1.1.2.2 eeh * Foundation, Inc. and its contributors.
23 1.1.2.2 eeh * 4. Neither the name of The NetBSD Foundation nor the names of its
24 1.1.2.2 eeh * contributors may be used to endorse or promote products derived
25 1.1.2.2 eeh * from this software without specific prior written permission.
26 1.1.2.2 eeh *
27 1.1.2.2 eeh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.1.2.2 eeh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.1.2.2 eeh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.1.2.2 eeh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.1.2.2 eeh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.1.2.2 eeh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.1.2.2 eeh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.1.2.2 eeh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.1.2.2 eeh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.1.2.2 eeh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.1.2.2 eeh * POSSIBILITY OF SUCH DAMAGE.
38 1.1.2.2 eeh */
39 1.1.2.2 eeh
40 1.1.2.2 eeh /*
41 1.1.2.2 eeh * Copyright (c) 1996 Christos Zoulas. All rights reserved.
42 1.1.2.2 eeh *
43 1.1.2.2 eeh * Redistribution and use in source and binary forms, with or without
44 1.1.2.2 eeh * modification, are permitted provided that the following conditions
45 1.1.2.2 eeh * are met:
46 1.1.2.2 eeh * 1. Redistributions of source code must retain the above copyright
47 1.1.2.2 eeh * notice, this list of conditions and the following disclaimer.
48 1.1.2.2 eeh * 2. Redistributions in binary form must reproduce the above copyright
49 1.1.2.2 eeh * notice, this list of conditions and the following disclaimer in the
50 1.1.2.2 eeh * documentation and/or other materials provided with the distribution.
51 1.1.2.2 eeh * 3. All advertising materials mentioning features or use of this software
52 1.1.2.2 eeh * must display the following acknowledgement:
53 1.1.2.2 eeh * This product includes software developed by Christos Zoulas.
54 1.1.2.2 eeh * 4. The name of the author may not be used to endorse or promote products
55 1.1.2.2 eeh * derived from this software without specific prior written permission.
56 1.1.2.2 eeh *
57 1.1.2.2 eeh * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
58 1.1.2.2 eeh * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
59 1.1.2.2 eeh * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
60 1.1.2.2 eeh * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
61 1.1.2.2 eeh * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
62 1.1.2.2 eeh * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
63 1.1.2.2 eeh * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
64 1.1.2.2 eeh * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
65 1.1.2.2 eeh * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
66 1.1.2.2 eeh * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 1.1.2.2 eeh */
68 1.1.2.2 eeh
69 1.1.2.2 eeh /*
70 1.1.2.2 eeh * Machine-dependent portions of ISA PnP bus autoconfiguration.
71 1.1.2.2 eeh *
72 1.1.2.2 eeh * N.B. This file exists mostly to get around some lameness surrounding
73 1.1.2.2 eeh * the PnP spec. ISA PnP registers live where some `normal' ISA
74 1.1.2.2 eeh * devices do, but are e.g. write-only registers where the normal
75 1.1.2.2 eeh * device has a read-only register. This breaks in the presence of
76 1.1.2.2 eeh * i/o port accounting. This file takes care of mapping ISA PnP
77 1.1.2.2 eeh * registers without actually allocating them in extent maps.
78 1.1.2.2 eeh *
79 1.1.2.2 eeh * Since this is a machine-dependent file, we make all sorts of
80 1.1.2.2 eeh * assumptions about bus.h's guts. Beware!
81 1.1.2.2 eeh */
82 1.1.2.2 eeh
83 1.1.2.2 eeh #include <sys/param.h>
84 1.1.2.2 eeh #include <sys/systm.h>
85 1.1.2.2 eeh #include <sys/device.h>
86 1.1.2.2 eeh #include <sys/malloc.h>
87 1.1.2.2 eeh
88 1.1.2.2 eeh #include <machine/bus.h>
89 1.1.2.2 eeh
90 1.1.2.2 eeh #include <dev/isa/isavar.h>
91 1.1.2.2 eeh
92 1.1.2.2 eeh #include <dev/isapnp/isapnpreg.h>
93 1.1.2.2 eeh #include <dev/isapnp/isapnpvar.h>
94 1.1.2.2 eeh
95 1.1.2.2 eeh /* isapnp_map():
96 1.1.2.2 eeh * Map I/O regions used by PnP
97 1.1.2.2 eeh */
98 1.1.2.2 eeh int
99 1.1.2.2 eeh isapnp_map(sc)
100 1.1.2.2 eeh struct isapnp_softc *sc;
101 1.1.2.2 eeh {
102 1.1.2.2 eeh int error;
103 1.1.2.2 eeh
104 1.1.2.2 eeh error = alpha_bus_space_map_noacct(sc->sc_iot, ISAPNP_ADDR, 1, 0,
105 1.1.2.2 eeh &sc->sc_addr_ioh);
106 1.1.2.2 eeh if (error)
107 1.1.2.2 eeh return (error);
108 1.1.2.2 eeh
109 1.1.2.2 eeh error = alpha_bus_space_map_noacct(sc->sc_iot, ISAPNP_WRDATA, 1, 0,
110 1.1.2.2 eeh &sc->sc_wrdata_ioh);
111 1.1.2.2 eeh if (error) {
112 1.1.2.2 eeh alpha_bus_space_unmap_noacct(sc->sc_iot, sc->sc_addr_ioh, 1);
113 1.1.2.2 eeh return (error);
114 1.1.2.2 eeh }
115 1.1.2.2 eeh
116 1.1.2.2 eeh return (0);
117 1.1.2.2 eeh }
118 1.1.2.2 eeh
119 1.1.2.2 eeh /* isapnp_unmap():
120 1.1.2.2 eeh * Unmap I/O regions used by PnP
121 1.1.2.2 eeh */
122 1.1.2.2 eeh void
123 1.1.2.2 eeh isapnp_unmap(sc)
124 1.1.2.2 eeh struct isapnp_softc *sc;
125 1.1.2.2 eeh {
126 1.1.2.2 eeh
127 1.1.2.2 eeh alpha_bus_space_unmap_noacct(sc->sc_iot, sc->sc_addr_ioh, 1);
128 1.1.2.2 eeh alpha_bus_space_unmap_noacct(sc->sc_iot, sc->sc_wrdata_ioh, 1);
129 1.1.2.2 eeh }
130 1.1.2.2 eeh
131 1.1.2.2 eeh /* isapnp_map_readport():
132 1.1.2.2 eeh * Called to map the PnP `read port', which is mapped independently
133 1.1.2.2 eeh * of the `write' and `addr' ports.
134 1.1.2.2 eeh *
135 1.1.2.2 eeh * NOTE: assumes the caller has filled in sc->sc_read_port!
136 1.1.2.2 eeh */
137 1.1.2.2 eeh int
138 1.1.2.2 eeh isapnp_map_readport(sc)
139 1.1.2.2 eeh struct isapnp_softc *sc;
140 1.1.2.2 eeh {
141 1.1.2.2 eeh #ifdef _KERNEL
142 1.1.2.2 eeh int error;
143 1.1.2.2 eeh #endif
144 1.1.2.2 eeh
145 1.1.2.2 eeh #ifdef _KERNEL
146 1.1.2.2 eeh /* Check if some other device has already claimed this port. */
147 1.1.2.2 eeh if ((error = bus_space_map(sc->sc_iot, sc->sc_read_port, 1, 0,
148 1.1.2.2 eeh &sc->sc_read_ioh)) != 0)
149 1.1.2.2 eeh return error;
150 1.1.2.2 eeh
151 1.1.2.2 eeh /*
152 1.1.2.2 eeh * XXX: We unmap the port because it can and will be used by other
153 1.1.2.2 eeh * devices such as a joystick. We need a better port accounting
154 1.1.2.2 eeh * scheme with read and write ports.
155 1.1.2.2 eeh */
156 1.1.2.2 eeh bus_space_unmap(sc->sc_iot, sc->sc_read_ioh, 1);
157 1.1.2.2 eeh #endif
158 1.1.2.2 eeh return 0;
159 1.1.2.2 eeh }
160 1.1.2.2 eeh
161 1.1.2.2 eeh /* isapnp_unmap_readport():
162 1.1.2.2 eeh * Pretend to unmap a previously mapped `read port'.
163 1.1.2.2 eeh */
164 1.1.2.2 eeh void
165 1.1.2.2 eeh isapnp_unmap_readport(sc)
166 1.1.2.2 eeh struct isapnp_softc *sc;
167 1.1.2.2 eeh {
168 1.1.2.2 eeh
169 1.1.2.2 eeh /* Do nothing */
170 1.1.2.2 eeh }
171