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