Home | History | Annotate | Line # | Download | only in news68k
bus_space.c revision 1.12
      1 /*	$NetBSD: bus_space.c,v 1.11 2011/11/22 14:31:02 tsutsui Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe.
      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  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 /*
     33  * Implementation of bus_space mapping for the news68k.
     34  * Just taken from hp300.
     35  */
     36 
     37 #include <sys/cdefs.h>
     38 __KERNEL_RCSID(0, "$NetBSD: bus_space.c,v 1.11 2011/11/22 14:31:02 tsutsui Exp $");
     39 
     40 #include <sys/param.h>
     41 #include <sys/systm.h>
     42 
     43 #include <machine/bus.h>
     44 
     45 #include <uvm/uvm_extern.h>
     46 
     47 extern int *nofault;
     48 
     49 /* ARGSUSED */
     50 int
     51 bus_space_map(bus_space_tag_t t, bus_addr_t bpa, bus_size_t size, int flags,
     52     bus_space_handle_t *bshp)
     53 {
     54 
     55 	if (t == NEWS68K_BUS_SPACE_INTIO) {
     56 		/*
     57 		 * Intio space is direct-mapped in pmap_bootstrap(); just
     58 		 * do the translation.
     59 		 */
     60 		*bshp = (bus_space_handle_t)bpa;
     61 		return 0;
     62 	}
     63 
     64 	if (t == NEWS68K_BUS_SPACE_EIO)
     65 		*bshp = (bus_space_handle_t)bpa; /* XXX use tt0 mapping */
     66 		return 0;
     67 
     68 	return 1;
     69 }
     70 
     71 /* ARGSUSED */
     72 int
     73 bus_space_alloc(bus_space_tag_t t, bus_addr_t rstart, bus_addr_t rend,
     74     bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags,
     75     bus_addr_t *bpap, bus_space_handle_t *bshp)
     76 {
     77 
     78 	/*
     79 	 * Not meaningful on any currently-supported news68k bus.
     80 	 */
     81 	return EINVAL;
     82 }
     83 
     84 /* ARGSUSED */
     85 void
     86 bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh, bus_size_t size)
     87 {
     88 
     89 	/*
     90 	 * Not meaningful on any currently-supported news68k bus.
     91 	 */
     92 	panic("bus_space_free: shouldn't be here");
     93 }
     94 
     95 void
     96 bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh, bus_size_t size)
     97 {
     98 
     99 	if (t == NEWS68K_BUS_SPACE_INTIO) {
    100 		/*
    101 		 * Intio space is direct-mapped in pmap_bootstrap(); nothing
    102 		 * to do
    103 		 */
    104 		return;
    105 	}
    106 
    107 	if (t != NEWS68K_BUS_SPACE_EIO)
    108 		panic("bus_space_map: bad space tag");
    109 
    110 	return;
    111 }
    112 
    113 /* ARGSUSED */
    114 int
    115 bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh,
    116     bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp)
    117 {
    118 
    119 	*nbshp = bsh + offset;
    120 	return 0;
    121 }
    122 
    123 /* ARGSUSED */
    124 int
    125 news68k_bus_space_probe(bus_space_tag_t t, bus_space_handle_t bsh,
    126     bus_size_t offset, int sz)
    127 {
    128 	label_t faultbuf;
    129 	int i;
    130 
    131 	nofault = (int *)&faultbuf;
    132 	if (setjmp((label_t *)nofault)) {
    133 		nofault = NULL;
    134 		return 0;
    135 	}
    136 
    137 	switch (sz) {
    138 	case 1:
    139 		i = bus_space_read_1(t, bsh, offset);
    140 		break;
    141 
    142 	case 2:
    143 		i = bus_space_read_2(t, bsh, offset);
    144 		break;
    145 
    146 	case 4:
    147 		i = bus_space_read_4(t, bsh, offset);
    148 		break;
    149 
    150 	default:
    151 		panic("bus_space_probe: unupported data size %d", sz);
    152 		/* NOTREACHED */
    153 	}
    154 	__USE(i);
    155 	nofault = NULL;
    156 	return 1;
    157 }
    158