Home | History | Annotate | Line # | Download | only in isa
isapnp_machdep.c revision 1.6
      1 /*	$NetBSD: isapnp_machdep.c,v 1.6 2008/04/28 20:23:11 martin Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1996, 1997, 1998 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  *
     20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  * POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 /*
     34  * Machine-dependent portions of ISA PnP bus autoconfiguration.
     35  *
     36  * N.B. This file exists mostly to get around some lameness surrounding
     37  * the PnP spec.  ISA PnP registers live where some `normal' ISA
     38  * devices do, but are e.g. write-only registers where the normal
     39  * device has a read-only register.  This breaks in the presence of
     40  * i/o port accounting.  This file takes care of mapping ISA PnP
     41  * registers without actually allocating them in extent maps.
     42  *
     43  * Since this is a machine-dependent file, we make all sorts of
     44  * assumptions about bus.h's guts.  Beware!
     45  */
     46 
     47 #include <sys/cdefs.h>
     48 __KERNEL_RCSID(0, "$NetBSD: isapnp_machdep.c,v 1.6 2008/04/28 20:23:11 martin Exp $");
     49 
     50 #include <sys/param.h>
     51 #include <sys/systm.h>
     52 #include <sys/device.h>
     53 #include <sys/malloc.h>
     54 
     55 #include <machine/bus.h>
     56 
     57 #include <dev/isa/isavar.h>
     58 
     59 #include <dev/isapnp/isapnpreg.h>
     60 #include <dev/isapnp/isapnpvar.h>
     61 
     62 /* isapnp_map():
     63  *	Map I/O regions used by PnP
     64  */
     65 int
     66 isapnp_map(sc)
     67 	struct isapnp_softc *sc;
     68 {
     69 	int error;
     70 
     71 	error = alpha_bus_space_map_noacct(sc->sc_iot, ISAPNP_ADDR, 1, 0,
     72 	    &sc->sc_addr_ioh);
     73 	if (error)
     74 		return (error);
     75 
     76 	error = alpha_bus_space_map_noacct(sc->sc_iot, ISAPNP_WRDATA, 1, 0,
     77 	    &sc->sc_wrdata_ioh);
     78 	if (error) {
     79 		alpha_bus_space_unmap_noacct(sc->sc_iot, sc->sc_addr_ioh, 1);
     80 		return (error);
     81 	}
     82 
     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 	alpha_bus_space_unmap_noacct(sc->sc_iot, sc->sc_addr_ioh, 1);
     95 	alpha_bus_space_unmap_noacct(sc->sc_iot, sc->sc_wrdata_ioh, 1);
     96 }
     97 
     98 /* isapnp_map_readport():
     99  *	Called to map the PnP `read port', which is mapped independently
    100  *	of the `write' and `addr' ports.
    101  *
    102  *	NOTE: assumes the caller has filled in sc->sc_read_port!
    103  */
    104 int
    105 isapnp_map_readport(sc)
    106 	struct isapnp_softc *sc;
    107 {
    108 #ifdef _KERNEL
    109 	int error;
    110 #endif
    111 
    112 #ifdef _KERNEL
    113 	/* Check if some other device has already claimed this port. */
    114 	if ((error = bus_space_map(sc->sc_iot, sc->sc_read_port, 1, 0,
    115 	    &sc->sc_read_ioh)) != 0)
    116 		return error;
    117 
    118 	/*
    119 	 * XXX: We unmap the port because it can and will be used by other
    120 	 *	devices such as a joystick. We need a better port accounting
    121 	 *	scheme with read and write ports.
    122 	 */
    123 	bus_space_unmap(sc->sc_iot, sc->sc_read_ioh, 1);
    124 #endif
    125 	return 0;
    126 }
    127 
    128 /* isapnp_unmap_readport():
    129  *	Pretend to unmap a previously mapped `read port'.
    130  */
    131 void
    132 isapnp_unmap_readport(sc)
    133 	struct isapnp_softc *sc;
    134 {
    135 
    136 	/* Do nothing */
    137 }
    138