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