Home | History | Annotate | Line # | Download | only in isa
isa_machdep.c revision 1.4
      1 /* $NetBSD: isa_machdep.c,v 1.4 2008/01/17 23:42:58 garbled Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2007 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Tim Rightnour
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include <sys/cdefs.h>
     40 __KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.4 2008/01/17 23:42:58 garbled Exp $");
     41 
     42 #include <sys/param.h>
     43 
     44 #include <machine/bus.h>
     45 #include <machine/pio.h>
     46 
     47 #include <sys/extent.h>
     48 
     49 #include <dev/isa/isavar.h>
     50 #include <dev/isa/isareg.h>
     51 
     52 #define IO_ELCR1        0x4d0
     53 #define IO_ELCR2        0x4d1
     54 
     55 struct powerpc_isa_chipset genppc_ict;
     56 bus_space_handle_t io_icu1h, io_icu2h, io_elcrh;
     57 
     58 /*
     59  * These functions can *ONLY* be used to talk to the i8259.  Leave them
     60  * alone.  I know they are greusome.
     61  */
     62 
     63 int
     64 map_isa_ioregs(void)
     65 {
     66 	int err, noerr;
     67 
     68 	err = bus_space_map(&genppc_isa_io_space_tag, IO_ICU1, 2, 0,
     69 	    &io_icu1h);
     70 	if (err != 0)
     71 		panic("Can't map IO_ICU1 error %d\n", err);
     72 
     73 	err = bus_space_map(&genppc_isa_io_space_tag, IO_ICU2, 2, 0,
     74 	    &io_icu2h);
     75 	if (err != 0)
     76 		panic("Can't map IO_ICU2 error %d\n", err);
     77 
     78 	noerr = bus_space_map(&genppc_isa_io_space_tag, IO_ELCR1, 2, 0,
     79 	    &io_elcrh);
     80 	if (noerr != 0)
     81 		aprint_error("Can't map IO_ELCR error %d\n", noerr);
     82 
     83 	return err;
     84 }
     85 
     86 uint8_t
     87 isa_inb(uint32_t addr)
     88 {
     89 	if (addr == IO_ICU1 || addr == IO_ICU1+1)
     90 		return bus_space_read_1(&genppc_isa_io_space_tag, io_icu1h,
     91 		    addr-IO_ICU1);
     92 	if (addr == IO_ICU2 || addr == IO_ICU2+1)
     93 		return bus_space_read_1(&genppc_isa_io_space_tag, io_icu2h,
     94 		    addr-IO_ICU2);
     95 	if (addr == IO_ELCR1 || addr == IO_ELCR2)
     96 		return bus_space_read_1(&genppc_isa_io_space_tag, io_elcrh,
     97 		    addr-IO_ELCR1);
     98 	return 0;
     99 }
    100 
    101 void
    102 isa_outb(uint32_t addr, uint8_t val)
    103 {
    104 	if (addr == IO_ICU1 || addr == IO_ICU1+1)
    105 		bus_space_write_1(&genppc_isa_io_space_tag, io_icu1h,
    106 		    addr-IO_ICU1, val);
    107 	if (addr == IO_ICU2 || addr == IO_ICU2+1)
    108 		bus_space_write_1(&genppc_isa_io_space_tag, io_icu2h,
    109 		    addr-IO_ICU2, val);
    110 	if (addr == IO_ELCR1 || addr == IO_ELCR2)
    111 		bus_space_write_1(&genppc_isa_io_space_tag, io_elcrh,
    112 		    addr-IO_ELCR1, val);
    113 }
    114