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