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