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