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