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