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