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