Home | History | Annotate | Line # | Download | only in jensenio
jensenio_bus_intio.c revision 1.1.2.2
      1  1.1.2.2  thorpej /* $NetBSD: jensenio_bus_intio.c,v 1.1.2.2 2000/07/12 20:59:11 thorpej Exp $ */
      2  1.1.2.2  thorpej 
      3  1.1.2.2  thorpej /*-
      4  1.1.2.2  thorpej  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5  1.1.2.2  thorpej  * All rights reserved.
      6  1.1.2.2  thorpej  *
      7  1.1.2.2  thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1.2.2  thorpej  * by Jason R. Thorpe.
      9  1.1.2.2  thorpej  *
     10  1.1.2.2  thorpej  * Redistribution and use in source and binary forms, with or without
     11  1.1.2.2  thorpej  * modification, are permitted provided that the following conditions
     12  1.1.2.2  thorpej  * are met:
     13  1.1.2.2  thorpej  * 1. Redistributions of source code must retain the above copyright
     14  1.1.2.2  thorpej  *    notice, this list of conditions and the following disclaimer.
     15  1.1.2.2  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1.2.2  thorpej  *    notice, this list of conditions and the following disclaimer in the
     17  1.1.2.2  thorpej  *    documentation and/or other materials provided with the distribution.
     18  1.1.2.2  thorpej  * 3. All advertising materials mentioning features or use of this software
     19  1.1.2.2  thorpej  *    must display the following acknowledgement:
     20  1.1.2.2  thorpej  *	This product includes software developed by the NetBSD
     21  1.1.2.2  thorpej  *	Foundation, Inc. and its contributors.
     22  1.1.2.2  thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1.2.2  thorpej  *    contributors may be used to endorse or promote products derived
     24  1.1.2.2  thorpej  *    from this software without specific prior written permission.
     25  1.1.2.2  thorpej  *
     26  1.1.2.2  thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1.2.2  thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1.2.2  thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1.2.2  thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1.2.2  thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1.2.2  thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1.2.2  thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1.2.2  thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1.2.2  thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1.2.2  thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1.2.2  thorpej  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1.2.2  thorpej  */
     38  1.1.2.2  thorpej 
     39  1.1.2.2  thorpej #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     40  1.1.2.2  thorpej 
     41  1.1.2.2  thorpej __KERNEL_RCSID(0, "$NetBSD: jensenio_bus_intio.c,v 1.1.2.2 2000/07/12 20:59:11 thorpej Exp $");
     42  1.1.2.2  thorpej 
     43  1.1.2.2  thorpej #include <sys/param.h>
     44  1.1.2.2  thorpej #include <sys/systm.h>
     45  1.1.2.2  thorpej #include <sys/malloc.h>
     46  1.1.2.2  thorpej #include <sys/device.h>
     47  1.1.2.2  thorpej #include <sys/extent.h>
     48  1.1.2.2  thorpej 
     49  1.1.2.2  thorpej #include <machine/bus.h>
     50  1.1.2.2  thorpej 
     51  1.1.2.2  thorpej #include <dev/eisa/eisavar.h>
     52  1.1.2.2  thorpej 
     53  1.1.2.2  thorpej #include <dev/isa/isavar.h>
     54  1.1.2.2  thorpej 
     55  1.1.2.2  thorpej #include <alpha/jensenio/jensenioreg.h>
     56  1.1.2.2  thorpej #include <alpha/jensenio/jenseniovar.h>
     57  1.1.2.2  thorpej 
     58  1.1.2.2  thorpej /* mapping/unmapping */
     59  1.1.2.2  thorpej int		jensenio_intio_map(void *, bus_addr_t, bus_size_t, int,
     60  1.1.2.2  thorpej 		    bus_space_handle_t *, int);
     61  1.1.2.2  thorpej void		jensenio_intio_unmap(void *, bus_space_handle_t,
     62  1.1.2.2  thorpej 		    bus_size_t, int);
     63  1.1.2.2  thorpej int		jensenio_intio_subregion(void *, bus_space_handle_t,
     64  1.1.2.2  thorpej 		    bus_size_t, bus_size_t, bus_space_handle_t *);
     65  1.1.2.2  thorpej 
     66  1.1.2.2  thorpej /* allocation/deallocation */
     67  1.1.2.2  thorpej 	/* Not supported for Internal space */
     68  1.1.2.2  thorpej 
     69  1.1.2.2  thorpej /* barrier */
     70  1.1.2.2  thorpej inline void	jensenio_intio_barrier(void *, bus_space_handle_t,
     71  1.1.2.2  thorpej 		    bus_size_t, bus_size_t, int);
     72  1.1.2.2  thorpej 
     73  1.1.2.2  thorpej /* read (single) */
     74  1.1.2.2  thorpej inline u_int8_t	jensenio_intio_read_1(void *, bus_space_handle_t, bus_size_t);
     75  1.1.2.2  thorpej 
     76  1.1.2.2  thorpej /* read multiple */
     77  1.1.2.2  thorpej void		jensenio_intio_read_multi_1(void *, bus_space_handle_t,
     78  1.1.2.2  thorpej 		    bus_size_t, u_int8_t *, bus_size_t);
     79  1.1.2.2  thorpej 
     80  1.1.2.2  thorpej /* read region */
     81  1.1.2.2  thorpej 	/* Not supported for Internal space */
     82  1.1.2.2  thorpej 
     83  1.1.2.2  thorpej /* write (single) */
     84  1.1.2.2  thorpej inline void	jensenio_intio_write_1(void *, bus_space_handle_t,
     85  1.1.2.2  thorpej 		    bus_size_t, u_int8_t);
     86  1.1.2.2  thorpej 
     87  1.1.2.2  thorpej /* write multiple */
     88  1.1.2.2  thorpej void		jensenio_intio_write_multi_1(void *, bus_space_handle_t,
     89  1.1.2.2  thorpej 		    bus_size_t, const u_int8_t *, bus_size_t);
     90  1.1.2.2  thorpej 
     91  1.1.2.2  thorpej /* write region */
     92  1.1.2.2  thorpej 	/* Not supported for Internal space */
     93  1.1.2.2  thorpej 
     94  1.1.2.2  thorpej /* set multiple */
     95  1.1.2.2  thorpej void		jensenio_intio_set_multi_1(void *, bus_space_handle_t,
     96  1.1.2.2  thorpej 		    bus_size_t, u_int8_t, bus_size_t);
     97  1.1.2.2  thorpej 
     98  1.1.2.2  thorpej /* set region */
     99  1.1.2.2  thorpej 	/* Not supported for Internal space */
    100  1.1.2.2  thorpej 
    101  1.1.2.2  thorpej /* copy */
    102  1.1.2.2  thorpej 	/* Not supported for Internal space */
    103  1.1.2.2  thorpej 
    104  1.1.2.2  thorpej void
    105  1.1.2.2  thorpej jensenio_bus_intio_init(bus_space_tag_t t, void *v)
    106  1.1.2.2  thorpej {
    107  1.1.2.2  thorpej 
    108  1.1.2.2  thorpej 	/*
    109  1.1.2.2  thorpej 	 * Initialize the bus space tag.
    110  1.1.2.2  thorpej 	 */
    111  1.1.2.2  thorpej 
    112  1.1.2.2  thorpej 	memset(t, 0, sizeof(*t));
    113  1.1.2.2  thorpej 
    114  1.1.2.2  thorpej 	/* cookie */
    115  1.1.2.2  thorpej 	t->abs_cookie =		v;
    116  1.1.2.2  thorpej 
    117  1.1.2.2  thorpej 	/* mapping/unmapping */
    118  1.1.2.2  thorpej 	t->abs_map =		jensenio_intio_map;
    119  1.1.2.2  thorpej 	t->abs_unmap =		jensenio_intio_unmap;
    120  1.1.2.2  thorpej 	t->abs_subregion =	jensenio_intio_subregion;
    121  1.1.2.2  thorpej 
    122  1.1.2.2  thorpej 	/* barrier */
    123  1.1.2.2  thorpej 	t->abs_barrier =	jensenio_intio_barrier;
    124  1.1.2.2  thorpej 
    125  1.1.2.2  thorpej 	/* read (single) */
    126  1.1.2.2  thorpej 	t->abs_r_1 =		jensenio_intio_read_1;
    127  1.1.2.2  thorpej 
    128  1.1.2.2  thorpej 	/* read multiple */
    129  1.1.2.2  thorpej 	t->abs_rm_1 =		jensenio_intio_read_multi_1;
    130  1.1.2.2  thorpej 
    131  1.1.2.2  thorpej 	/* write (single) */
    132  1.1.2.2  thorpej 	t->abs_w_1 =		jensenio_intio_write_1;
    133  1.1.2.2  thorpej 
    134  1.1.2.2  thorpej 	/* write multiple */
    135  1.1.2.2  thorpej 	t->abs_wm_1 =		jensenio_intio_write_multi_1;
    136  1.1.2.2  thorpej 
    137  1.1.2.2  thorpej 	/* set multiple */
    138  1.1.2.2  thorpej 	t->abs_sm_1 =		jensenio_intio_set_multi_1;
    139  1.1.2.2  thorpej 
    140  1.1.2.2  thorpej 	/*
    141  1.1.2.2  thorpej 	 * Extent map is already set up.
    142  1.1.2.2  thorpej 	 */
    143  1.1.2.2  thorpej }
    144  1.1.2.2  thorpej 
    145  1.1.2.2  thorpej int
    146  1.1.2.2  thorpej jensenio_intio_map(void *v, bus_addr_t ioaddr, bus_size_t iosize, int flags,
    147  1.1.2.2  thorpej     bus_space_handle_t *iohp, int acct)
    148  1.1.2.2  thorpej {
    149  1.1.2.2  thorpej 	struct jensenio_config *jcp = v;
    150  1.1.2.2  thorpej 	int linear = flags & BUS_SPACE_MAP_LINEAR;
    151  1.1.2.2  thorpej 	int error;
    152  1.1.2.2  thorpej 
    153  1.1.2.2  thorpej 	/*
    154  1.1.2.2  thorpej 	 * Can't map i/o space linearly.
    155  1.1.2.2  thorpej 	 */
    156  1.1.2.2  thorpej 	if (linear)
    157  1.1.2.2  thorpej 		return (EOPNOTSUPP);
    158  1.1.2.2  thorpej 
    159  1.1.2.2  thorpej 	if (acct) {
    160  1.1.2.2  thorpej #ifdef EXTENT_DEBUG
    161  1.1.2.2  thorpej 		printf("intio: allocating 0x%lx to 0x%lx\n", ioaddr,
    162  1.1.2.2  thorpej 		    ioaddr + iosize - 1);
    163  1.1.2.2  thorpej #endif
    164  1.1.2.2  thorpej 		error = extent_alloc_region(jcp->jc_io_ex, ioaddr, iosize,
    165  1.1.2.2  thorpej 		    EX_NOWAIT | (jcp->jc_mallocsafe ? EX_MALLOCOK : 0));
    166  1.1.2.2  thorpej 		if (error) {
    167  1.1.2.2  thorpej #ifdef EXTENT_DEBUG
    168  1.1.2.2  thorpej 			printf("intio: allocation failed (%d)\n", error);
    169  1.1.2.2  thorpej 			extent_print(jcp->jc_io_ex);
    170  1.1.2.2  thorpej #endif
    171  1.1.2.2  thorpej 			return (error);
    172  1.1.2.2  thorpej 		}
    173  1.1.2.2  thorpej 	}
    174  1.1.2.2  thorpej 
    175  1.1.2.2  thorpej 	*iohp = ALPHA_PHYS_TO_K0SEG((ioaddr << 9) + JENSEN_VL82C106);
    176  1.1.2.2  thorpej 	return (0);
    177  1.1.2.2  thorpej }
    178  1.1.2.2  thorpej 
    179  1.1.2.2  thorpej void
    180  1.1.2.2  thorpej jensenio_intio_unmap(void *v, bus_space_handle_t ioh, bus_size_t iosize,
    181  1.1.2.2  thorpej     int acct)
    182  1.1.2.2  thorpej {
    183  1.1.2.2  thorpej 	struct jensenio_config *jcp = v;
    184  1.1.2.2  thorpej 	bus_addr_t ioaddr;
    185  1.1.2.2  thorpej 	int error;
    186  1.1.2.2  thorpej 
    187  1.1.2.2  thorpej 	if (acct == 0)
    188  1.1.2.2  thorpej 		return;
    189  1.1.2.2  thorpej 
    190  1.1.2.2  thorpej #ifdef EXTENT_DEBUG
    191  1.1.2.2  thorpej 	printf("intio: freeing handle 0x%lx for 0x%lx\n", ioh, iosize);
    192  1.1.2.2  thorpej #endif
    193  1.1.2.2  thorpej 
    194  1.1.2.2  thorpej 	ioh = ALPHA_K0SEG_TO_PHYS(ioh);
    195  1.1.2.2  thorpej 
    196  1.1.2.2  thorpej 	ioaddr = (ioh - JENSEN_VL82C106) >> 9;
    197  1.1.2.2  thorpej 
    198  1.1.2.2  thorpej #ifdef EXTENT_DEBUG
    199  1.1.2.2  thorpej 	printf("intio: freeing 0x%lx to 0x%lx\n", ioaddr, ioaddr + iosize - 1);
    200  1.1.2.2  thorpej #endif
    201  1.1.2.2  thorpej 	error = extent_free(jcp->jc_io_ex, ioaddr, iosize,
    202  1.1.2.2  thorpej 	    EX_NOWAIT | (jcp->jc_mallocsafe ? EX_MALLOCOK : 0));
    203  1.1.2.2  thorpej 	if (error) {
    204  1.1.2.2  thorpej 		printf("WARNING: could not unmap 0x%lx-0x%lx (error %d)\n",
    205  1.1.2.2  thorpej 		    ioaddr, ioaddr + iosize - 1, error);
    206  1.1.2.2  thorpej #ifdef EXTENT_DEBUG
    207  1.1.2.2  thorpej 		extent_print(jcp->jc_io_ex);
    208  1.1.2.2  thorpej #endif
    209  1.1.2.2  thorpej 	}
    210  1.1.2.2  thorpej }
    211  1.1.2.2  thorpej 
    212  1.1.2.2  thorpej int
    213  1.1.2.2  thorpej jensenio_intio_subregion(void *v, bus_space_handle_t ioh, bus_size_t offset,
    214  1.1.2.2  thorpej     bus_size_t size, bus_space_handle_t *nioh)
    215  1.1.2.2  thorpej {
    216  1.1.2.2  thorpej 
    217  1.1.2.2  thorpej 	*nioh = ioh + (offset << 9);
    218  1.1.2.2  thorpej 	return (0);
    219  1.1.2.2  thorpej }
    220  1.1.2.2  thorpej 
    221  1.1.2.2  thorpej inline void
    222  1.1.2.2  thorpej jensenio_intio_barrier(void *v, bus_space_handle_t h, bus_size_t o,
    223  1.1.2.2  thorpej     bus_size_t l, int f)
    224  1.1.2.2  thorpej {
    225  1.1.2.2  thorpej 
    226  1.1.2.2  thorpej 	if ((f & BUS_SPACE_BARRIER_READ) != 0)
    227  1.1.2.2  thorpej 		alpha_mb();
    228  1.1.2.2  thorpej 	else if ((f & BUS_SPACE_BARRIER_WRITE) != 0)
    229  1.1.2.2  thorpej 		alpha_wmb();
    230  1.1.2.2  thorpej }
    231  1.1.2.2  thorpej 
    232  1.1.2.2  thorpej inline u_int8_t
    233  1.1.2.2  thorpej jensenio_intio_read_1(void *v, bus_space_handle_t ioh, bus_size_t off)
    234  1.1.2.2  thorpej {
    235  1.1.2.2  thorpej 	register u_int32_t *port;
    236  1.1.2.2  thorpej 
    237  1.1.2.2  thorpej 	alpha_mb();
    238  1.1.2.2  thorpej 
    239  1.1.2.2  thorpej 	port = (u_int32_t *)(ioh + (off << 9));
    240  1.1.2.2  thorpej 	return (*port & 0xff);
    241  1.1.2.2  thorpej }
    242  1.1.2.2  thorpej 
    243  1.1.2.2  thorpej void
    244  1.1.2.2  thorpej jensenio_intio_read_multi_1(void *v, bus_space_handle_t h, bus_size_t o,
    245  1.1.2.2  thorpej     u_int8_t *a, bus_size_t c)
    246  1.1.2.2  thorpej {
    247  1.1.2.2  thorpej 
    248  1.1.2.2  thorpej 	while (c-- > 0) {
    249  1.1.2.2  thorpej 		jensenio_intio_barrier(v, h, o, sizeof *a,
    250  1.1.2.2  thorpej 		    BUS_SPACE_BARRIER_READ);
    251  1.1.2.2  thorpej 		*a++ = jensenio_intio_read_1(v, h, o);
    252  1.1.2.2  thorpej 	}
    253  1.1.2.2  thorpej }
    254  1.1.2.2  thorpej 
    255  1.1.2.2  thorpej inline void
    256  1.1.2.2  thorpej jensenio_intio_write_1(void *v, bus_space_handle_t ioh, bus_size_t off,
    257  1.1.2.2  thorpej     u_int8_t val)
    258  1.1.2.2  thorpej {
    259  1.1.2.2  thorpej 	register u_int32_t *port;
    260  1.1.2.2  thorpej 
    261  1.1.2.2  thorpej 	port = (u_int32_t *)(ioh + (off << 9));
    262  1.1.2.2  thorpej 	*port = val;
    263  1.1.2.2  thorpej 	alpha_mb();
    264  1.1.2.2  thorpej }
    265  1.1.2.2  thorpej 
    266  1.1.2.2  thorpej void
    267  1.1.2.2  thorpej jensenio_intio_write_multi_1(void *v, bus_space_handle_t h, bus_size_t o,
    268  1.1.2.2  thorpej     const u_int8_t *a, bus_size_t c)
    269  1.1.2.2  thorpej {
    270  1.1.2.2  thorpej 
    271  1.1.2.2  thorpej 	while (c-- > 0) {
    272  1.1.2.2  thorpej 		jensenio_intio_write_1(v, h, o, *a++);
    273  1.1.2.2  thorpej 		jensenio_intio_barrier(v, h, o, sizeof *a,
    274  1.1.2.2  thorpej 		    BUS_SPACE_BARRIER_WRITE);
    275  1.1.2.2  thorpej 	}
    276  1.1.2.2  thorpej }
    277  1.1.2.2  thorpej 
    278  1.1.2.2  thorpej void
    279  1.1.2.2  thorpej jensenio_intio_set_multi_1(void *v, bus_space_handle_t h, bus_size_t o,
    280  1.1.2.2  thorpej     u_int8_t val, bus_size_t c)
    281  1.1.2.2  thorpej {
    282  1.1.2.2  thorpej 
    283  1.1.2.2  thorpej 	while (c-- > 0) {
    284  1.1.2.2  thorpej 		jensenio_intio_write_1(v, h, o, val);
    285  1.1.2.2  thorpej 		jensenio_intio_barrier(v, h, o, sizeof val,
    286  1.1.2.2  thorpej 		    BUS_SPACE_BARRIER_WRITE);
    287  1.1.2.2  thorpej 	}
    288  1.1.2.2  thorpej }
    289