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