xref: /openbsd-src/sys/arch/i386/isa/isapnp_machdep.c (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1 /*	$OpenBSD: isapnp_machdep.c,v 1.4 2008/06/26 05:42:11 ray 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 #include <sys/device.h>
80 #include <sys/malloc.h>
81 
82 #include <machine/bus.h>
83 
84 #include <dev/isa/isapnpreg.h>
85 
86 #include <dev/isa/isavar.h>
87 
88 /* isapnp_map():
89  *	Map I/O regions used by PnP
90  */
91 int
92 isapnp_map(struct isapnp_softc *sc)
93 {
94 
95 #ifdef DIAGNOSTIC
96 	if (sc->sc_iot != I386_BUS_SPACE_IO)
97 		panic("isapnp_map: bogus bus space tag");
98 #endif
99 
100 	sc->sc_addr_ioh = ISAPNP_ADDR;
101 	sc->sc_wrdata_ioh = ISAPNP_WRDATA;
102 	return (0);
103 }
104 
105 /* isapnp_unmap():
106  *	Unmap I/O regions used by PnP
107  */
108 void
109 isapnp_unmap(struct isapnp_softc *sc)
110 {
111 
112 	/* Do nothing. */
113 }
114 
115 /* isapnp_map_readport():
116  *	Called to map the PnP `read port', which is mapped independently
117  *	of the `write' and `addr' ports.
118  *
119  *	NOTE: assumes the caller has filled in sc->sc_read_port!
120  */
121 int
122 isapnp_map_readport(struct isapnp_softc *sc)
123 {
124 #ifdef _KERNEL
125 	int error;
126 #endif
127 
128 #ifdef DIAGNOSTIC
129 	if (sc->sc_iot != I386_BUS_SPACE_IO)
130 		panic("isapnp_map_readport: bogus bus space tag");
131 #endif
132 
133 #ifdef _KERNEL
134 	/* Check if some other device has already claimed this port. */
135 	if ((error = bus_space_map(sc->sc_iot, sc->sc_read_port, 1, 0,
136 	    &sc->sc_read_ioh)) != 0)
137 		return error;
138 
139 	/*
140 	 * XXX: We unmap the port because it can and will be used by other
141 	 *	devices such as a joystick. We need a better port accounting
142 	 *	scheme with read and write ports.
143 	 */
144 	bus_space_unmap(sc->sc_iot, sc->sc_read_ioh, 1);
145 #endif
146 	return 0;
147 }
148 
149 /* isapnp_unmap_readport():
150  *	Pretend to unmap a previously mapped `read port'.
151  */
152 void
153 isapnp_unmap_readport(struct isapnp_softc *sc)
154 {
155 
156 	/* Do nothing */
157 }
158