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