xref: /openbsd/sys/arch/alpha/isa/isapnp_machdep.c (revision d874cce4)
1 /*	$OpenBSD: isapnp_machdep.c,v 1.4 2008/06/26 05:42:08 ray Exp $	*/
2 /*	$NetBSD: isapnp_machdep.c,v 1.3 1998/09/05 15:28:04 christos Exp $	*/
3 
4 /*-
5  * Copyright (c) 1996, 1997, 1998 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 and by Christos Zoulas.
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  * Machine-dependent portions of ISA PnP bus autoconfiguration.
36  *
37  * N.B. This file exists mostly to get around some lameness surrounding
38  * the PnP spec.  ISA PnP registers live where some `normal' ISA
39  * devices do, but are e.g. write-only registers where the normal
40  * device has a read-only register.  This breaks in the presence of
41  * i/o port accounting.  This file takes care of mapping ISA PnP
42  * registers without actually allocating them in extent maps.
43  *
44  * Since this is a machine-dependent file, we make all sorts of
45  * assumptions about bus.h's guts.  Beware!
46  */
47 
48 #include <sys/param.h>
49 #include <sys/systm.h>
50 #include <sys/device.h>
51 #include <sys/malloc.h>
52 
53 #include <machine/bus.h>
54 
55 #include <dev/isa/isavar.h>
56 
57 #include <dev/isa/isapnpreg.h>
58 /* #include <dev/isapnp/isapnpvar.h> */
59 
60 /* isapnp_map():
61  *	Map I/O regions used by PnP
62  */
63 int
isapnp_map(sc)64 isapnp_map(sc)
65 	struct isapnp_softc *sc;
66 {
67 	int error;
68 
69 	error = alpha_bus_space_map_noacct(sc->sc_iot, ISAPNP_ADDR, 1, 0,
70 	    &sc->sc_addr_ioh);
71 	if (error)
72 		return (error);
73 
74 	error = alpha_bus_space_map_noacct(sc->sc_iot, ISAPNP_WRDATA, 1, 0,
75 	    &sc->sc_wrdata_ioh);
76 	if (error) {
77 		alpha_bus_space_unmap_noacct(sc->sc_iot, sc->sc_addr_ioh, 1);
78 		return (error);
79 	}
80 
81 	return (0);
82 }
83 
84 /* isapnp_unmap():
85  *	Unmap I/O regions used by PnP
86  */
87 void
isapnp_unmap(sc)88 isapnp_unmap(sc)
89 	struct isapnp_softc *sc;
90 {
91 
92 	alpha_bus_space_unmap_noacct(sc->sc_iot, sc->sc_addr_ioh, 1);
93 	alpha_bus_space_unmap_noacct(sc->sc_iot, sc->sc_wrdata_ioh, 1);
94 }
95 
96 /* isapnp_map_readport():
97  *	Called to map the PnP `read port', which is mapped independently
98  *	of the `write' and `addr' ports.
99  *
100  *	NOTE: assumes the caller has filled in sc->sc_read_port!
101  */
102 int
isapnp_map_readport(sc)103 isapnp_map_readport(sc)
104 	struct isapnp_softc *sc;
105 {
106 #ifdef _KERNEL
107 	int error;
108 #endif
109 
110 #ifdef _KERNEL
111 	/* Check if some other device has already claimed this port. */
112 	if ((error = bus_space_map(sc->sc_iot, sc->sc_read_port, 1, 0,
113 	    &sc->sc_read_ioh)) != 0)
114 		return error;
115 
116 	/*
117 	 * XXX: We unmap the port because it can and will be used by other
118 	 *	devices such as a joystick. We need a better port accounting
119 	 *	scheme with read and write ports.
120 	 */
121 	bus_space_unmap(sc->sc_iot, sc->sc_read_ioh, 1);
122 #endif
123 	return 0;
124 }
125 
126 /* isapnp_unmap_readport():
127  *	Pretend to unmap a previously mapped `read port'.
128  */
129 void
isapnp_unmap_readport(sc)130 isapnp_unmap_readport(sc)
131 	struct isapnp_softc *sc;
132 {
133 	/* Do nothing */
134 }
135