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