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