Home | History | Annotate | Line # | Download | only in isa
isapnp_machdep.c revision 1.2.4.1
      1 /*	$NetBSD: isapnp_machdep.c,v 1.2.4.1 1997/08/23 07:09:07 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1996 Jason R. Thorpe.  All rights reserved.
      5  * Copyright (c) 1996 Christos Zoulas.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by Christos Zoulas
     18  *	and Jason R. Thorpe.
     19  * 4. The name of the author may not be used to endorse or promote products
     20  *    derived from this software without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  * THIS SOFTWARE, EVEN IF ADVISED OF THE 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/isapnp/isapnpreg.h>
     58 #include <dev/isapnp/isapnpvar.h>
     59 
     60 /* isapnp_map():
     61  *	Map I/O regions used by PnP
     62  */
     63 int
     64 isapnp_map(sc)
     65 	struct isapnp_softc *sc;
     66 {
     67 
     68 #ifdef DIAGNOSTIC
     69 	if (sc->sc_iot != I386_BUS_SPACE_IO)
     70 		panic("isapnp_map: bogus bus space tag");
     71 #endif
     72 
     73 	sc->sc_addr_ioh = ISAPNP_ADDR;
     74 	sc->sc_wrdata_ioh = ISAPNP_WRDATA;
     75 	return (0);
     76 }
     77 
     78 /* isapnp_unmap():
     79  *	Unmap I/O regions used by PnP
     80  */
     81 void
     82 isapnp_unmap(sc)
     83 	struct isapnp_softc *sc;
     84 {
     85 
     86 	/* Do nothing. */
     87 }
     88 
     89 /* isapnp_map_readport():
     90  *	Called to map the PnP `read port', which is mapped independently
     91  *	of the `write' and `addr' ports.
     92  *
     93  *	NOTE: assumes the caller has filled in sc->sc_read_port!
     94  */
     95 int
     96 isapnp_map_readport(sc)
     97 	struct isapnp_softc *sc;
     98 {
     99 #ifdef _KERNEL
    100 	int error;
    101 #endif
    102 
    103 #ifdef DIAGNOSTIC
    104 	if (sc->sc_iot != I386_BUS_SPACE_IO)
    105 		panic("isapnp_map_readport: bogus bus space tag");
    106 #endif
    107 
    108 #ifdef _KERNEL
    109 	/* Check if some other device has already claimed this port. */
    110 	if ((error = bus_space_map(sc->sc_iot, sc->sc_read_port, 1, 0,
    111 	    &sc->sc_read_ioh)) != 0)
    112 		return error;
    113 
    114 	/*
    115 	 * XXX: We unmap the port because it can and will be used by other
    116 	 *	devices such as a joystick. We need a better port accounting
    117 	 *	scheme with read and write ports.
    118 	 */
    119 	bus_space_unmap(sc->sc_iot, sc->sc_read_ioh, 1);
    120 #endif
    121 	return 0;
    122 }
    123 
    124 /* isapnp_unmap_readport():
    125  *	Pretend to unmap a previously mapped `read port'.
    126  */
    127 void
    128 isapnp_unmap_readport(sc)
    129 	struct isapnp_softc *sc;
    130 {
    131 
    132 	/* Do nothing */
    133 }
    134