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