Home | History | Annotate | Line # | Download | only in podulebus
      1  1.9      ryo /*	$NetBSD: podulebus_io.c,v 1.9 2018/03/16 17:56:31 ryo Exp $	*/
      2  1.1  reinoud 
      3  1.1  reinoud /*
      4  1.1  reinoud  * Copyright (c) 1997 Mark Brinicombe.
      5  1.1  reinoud  * All rights reserved.
      6  1.1  reinoud  *
      7  1.1  reinoud  * Redistribution and use in source and binary forms, with or without
      8  1.1  reinoud  * modification, are permitted provided that the following conditions
      9  1.1  reinoud  * are met:
     10  1.1  reinoud  * 1. Redistributions of source code must retain the above copyright
     11  1.1  reinoud  *    notice, this list of conditions and the following disclaimer.
     12  1.1  reinoud  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  reinoud  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  reinoud  *    documentation and/or other materials provided with the distribution.
     15  1.1  reinoud  * 3. All advertising materials mentioning features or use of this software
     16  1.1  reinoud  *    must display the following acknowledgement:
     17  1.1  reinoud  *	This product includes software developed by Mark Brinicombe.
     18  1.1  reinoud  * 4. The name of the company nor the name of the author may be used to
     19  1.1  reinoud  *    endorse or promote products derived from this software without specific
     20  1.1  reinoud  *    prior written permission.
     21  1.1  reinoud  *
     22  1.1  reinoud  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     23  1.1  reinoud  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     24  1.1  reinoud  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.1  reinoud  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     26  1.1  reinoud  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     27  1.1  reinoud  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     28  1.1  reinoud  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  1.1  reinoud  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  1.1  reinoud  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  1.1  reinoud  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  1.1  reinoud  * SUCH DAMAGE.
     33  1.1  reinoud  */
     34  1.1  reinoud 
     35  1.1  reinoud /*
     36  1.1  reinoud  * bus_space I/O functions for podulebus
     37  1.1  reinoud  */
     38  1.3    lukem 
     39  1.3    lukem #include <sys/cdefs.h>
     40  1.9      ryo __KERNEL_RCSID(0, "$NetBSD: podulebus_io.c,v 1.9 2018/03/16 17:56:31 ryo Exp $");
     41  1.1  reinoud 
     42  1.1  reinoud #include <sys/param.h>
     43  1.1  reinoud #include <sys/systm.h>
     44  1.7   dyoung #include <sys/bus.h>
     45  1.1  reinoud 
     46  1.1  reinoud /* Proto types for all the bus_space structure functions */
     47  1.1  reinoud 
     48  1.1  reinoud bs_protos(podulebus);
     49  1.1  reinoud bs_protos(bs_notimpl);
     50  1.1  reinoud 
     51  1.1  reinoud /* Declare the podulebus bus space tag */
     52  1.1  reinoud 
     53  1.1  reinoud struct bus_space podulebus_bs_tag = {
     54  1.1  reinoud 	/* cookie */
     55  1.9      ryo 	.bs_cookie = (void *) 2,	/* Shift to apply to registers */
     56  1.1  reinoud 
     57  1.1  reinoud 	/* mapping/unmapping */
     58  1.9      ryo 	.bs_map = podulebus_bs_map,
     59  1.9      ryo 	.bs_unmap = podulebus_bs_unmap,
     60  1.9      ryo 	.bs_subregion = podulebus_bs_subregion,
     61  1.1  reinoud 
     62  1.1  reinoud 	/* allocation/deallocation */
     63  1.9      ryo 	.bs_alloc = podulebus_bs_alloc,
     64  1.9      ryo 	.bs_free = podulebus_bs_free,
     65  1.1  reinoud 
     66  1.1  reinoud 	/* get kernel virtual address */
     67  1.9      ryo 	.bs_vaddr = 0, /* there is no linear mapping */
     68  1.1  reinoud 
     69  1.1  reinoud 	/* mmap bus space for userland */
     70  1.9      ryo 	.bs_mmap = bs_notimpl_bs_mmap, /* there is no bus mapping ... well maybe EASI space? */
     71  1.1  reinoud 
     72  1.1  reinoud 	/* barrier */
     73  1.9      ryo 	.bs_barrier = podulebus_bs_barrier,
     74  1.1  reinoud 
     75  1.1  reinoud 	/* read (single) */
     76  1.9      ryo 	.bs_r_1 = podulebus_bs_r_1,
     77  1.9      ryo 	.bs_r_2 = podulebus_bs_r_2,
     78  1.9      ryo 	.bs_r_4 = podulebus_bs_r_4,
     79  1.9      ryo 	.bs_r_8 = bs_notimpl_bs_r_8,
     80  1.1  reinoud 
     81  1.1  reinoud 	/* read multiple */
     82  1.9      ryo 	.bs_rm_1 = podulebus_bs_rm_1,
     83  1.9      ryo 	.bs_rm_2 = podulebus_bs_rm_2,
     84  1.9      ryo 	.bs_rm_4 = bs_notimpl_bs_rm_4,
     85  1.9      ryo 	.bs_rm_8 = bs_notimpl_bs_rm_8,
     86  1.1  reinoud 
     87  1.1  reinoud 	/* read region */
     88  1.9      ryo 	.bs_rr_1 = podulebus_bs_rr_1,
     89  1.9      ryo 	.bs_rr_2 = podulebus_bs_rr_2,
     90  1.9      ryo 	.bs_rr_4 = bs_notimpl_bs_rr_4,
     91  1.9      ryo 	.bs_rr_8 = bs_notimpl_bs_rr_8,
     92  1.1  reinoud 
     93  1.1  reinoud 	/* write (single) */
     94  1.9      ryo 	.bs_w_1 = podulebus_bs_w_1,
     95  1.9      ryo 	.bs_w_2 = podulebus_bs_w_2,
     96  1.9      ryo 	.bs_w_4 = podulebus_bs_w_4,
     97  1.9      ryo 	.bs_w_8 = bs_notimpl_bs_w_8,
     98  1.1  reinoud 
     99  1.1  reinoud 	/* write multiple */
    100  1.9      ryo 	.bs_wm_1 = podulebus_bs_wm_1,
    101  1.9      ryo 	.bs_wm_2 = podulebus_bs_wm_2,
    102  1.9      ryo 	.bs_wm_4 = bs_notimpl_bs_wm_4,
    103  1.9      ryo 	.bs_wm_8 = bs_notimpl_bs_wm_8,
    104  1.1  reinoud 
    105  1.1  reinoud 	/* write region */
    106  1.9      ryo 	.bs_wr_1 = podulebus_bs_wr_1,
    107  1.9      ryo 	.bs_wr_2 = podulebus_bs_wr_2,
    108  1.9      ryo 	.bs_wr_4 = bs_notimpl_bs_wr_4,
    109  1.9      ryo 	.bs_wr_8 = bs_notimpl_bs_wr_8,
    110  1.1  reinoud 
    111  1.1  reinoud 	/* set multiple */
    112  1.9      ryo 	.bs_sm_1 = bs_notimpl_bs_sm_1,
    113  1.9      ryo 	.bs_sm_2 = bs_notimpl_bs_sm_2,
    114  1.9      ryo 	.bs_sm_4 = bs_notimpl_bs_sm_4,
    115  1.9      ryo 	.bs_sm_8 = bs_notimpl_bs_sm_8,
    116  1.1  reinoud 
    117  1.1  reinoud 	/* set region */
    118  1.9      ryo 	.bs_sr_1 = podulebus_bs_sr_1,
    119  1.9      ryo 	.bs_sr_2 = podulebus_bs_sr_2,
    120  1.9      ryo 	.bs_sr_4 = bs_notimpl_bs_sr_4,
    121  1.9      ryo 	.bs_sr_8 = bs_notimpl_bs_sr_8,
    122  1.1  reinoud 
    123  1.1  reinoud 	/* copy */
    124  1.9      ryo 	.bs_c_1 = bs_notimpl_bs_c_1,
    125  1.9      ryo 	.bs_c_2 = bs_notimpl_bs_c_2,
    126  1.9      ryo 	.bs_c_4 = bs_notimpl_bs_c_4,
    127  1.9      ryo 	.bs_c_8 = bs_notimpl_bs_c_8,
    128  1.1  reinoud };
    129  1.1  reinoud 
    130  1.1  reinoud /* bus space functions */
    131  1.1  reinoud 
    132  1.1  reinoud int
    133  1.5      dsl podulebus_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int cacheable, bus_space_handle_t *bshp)
    134  1.1  reinoud {
    135  1.1  reinoud 	/*
    136  1.1  reinoud 	 * Temporary implementation as all I/O is already mapped etc.
    137  1.1  reinoud 	 *
    138  1.1  reinoud 	 * Eventually this function will do the mapping check for multiple maps
    139  1.1  reinoud 	 */
    140  1.1  reinoud 	*bshp = bpa;
    141  1.1  reinoud 	return(0);
    142  1.1  reinoud 	}
    143  1.1  reinoud 
    144  1.1  reinoud int
    145  1.6   cegger podulebus_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend,
    146  1.6   cegger     bus_size_t size, bus_size_t alignment, bus_size_t boundary,
    147  1.6   cegger     int cacheable, bus_addr_t *bpap, bus_space_handle_t *bshp)
    148  1.1  reinoud {
    149  1.2   provos 	panic("podulebus_bs_alloc(): Help!");
    150  1.1  reinoud }
    151  1.1  reinoud 
    152  1.1  reinoud 
    153  1.1  reinoud void
    154  1.5      dsl podulebus_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
    155  1.1  reinoud {
    156  1.1  reinoud 	/*
    157  1.1  reinoud 	 * Temporary implementation
    158  1.1  reinoud 	 */
    159  1.1  reinoud }
    160  1.1  reinoud 
    161  1.1  reinoud void
    162  1.5      dsl podulebus_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
    163  1.1  reinoud {
    164  1.1  reinoud 
    165  1.2   provos 	panic("podulebus_bs_free(): Help!");
    166  1.1  reinoud 	/* podulebus_bs_unmap() does all that we need to do. */
    167  1.1  reinoud /*	podulebus_bs_unmap(t, bsh, size);*/
    168  1.1  reinoud }
    169  1.1  reinoud 
    170  1.1  reinoud int
    171  1.5      dsl podulebus_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp)
    172  1.1  reinoud {
    173  1.1  reinoud 
    174  1.1  reinoud 	*nbshp = bsh + (offset << ((int)t));
    175  1.1  reinoud 	return (0);
    176  1.1  reinoud }
    177  1.1  reinoud 
    178  1.1  reinoud void
    179  1.5      dsl podulebus_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t len, int flags)
    180  1.1  reinoud {
    181  1.1  reinoud }
    182  1.1  reinoud 
    183  1.1  reinoud /* Rough-and-ready implementations from arm26 */
    184  1.1  reinoud 
    185  1.1  reinoud void
    186  1.1  reinoud podulebus_bs_rr_1(void *cookie, bus_space_handle_t bsh,
    187  1.8    skrll 			bus_size_t offset, uint8_t *datap, bus_size_t count)
    188  1.1  reinoud {
    189  1.1  reinoud 	int i;
    190  1.1  reinoud 
    191  1.1  reinoud 	for (i = 0; i < count; i++)
    192  1.1  reinoud 		datap[i] = podulebus_bs_r_1(cookie, bsh, offset + i);
    193  1.1  reinoud }
    194  1.1  reinoud 
    195  1.1  reinoud void
    196  1.1  reinoud podulebus_bs_rr_2(void *cookie, bus_space_handle_t bsh,
    197  1.8    skrll 			bus_size_t offset, uint16_t *datap, bus_size_t count)
    198  1.1  reinoud {
    199  1.1  reinoud 	int i;
    200  1.1  reinoud 
    201  1.1  reinoud 	for (i = 0; i < count; i++)
    202  1.1  reinoud 		datap[i] = podulebus_bs_r_2(cookie, bsh, offset + i);
    203  1.1  reinoud }
    204  1.1  reinoud 
    205  1.1  reinoud void
    206  1.1  reinoud podulebus_bs_wr_1(void *cookie, bus_space_handle_t bsh,
    207  1.8    skrll 			 bus_size_t offset, uint8_t const *datap,
    208  1.1  reinoud 			 bus_size_t count)
    209  1.1  reinoud {
    210  1.1  reinoud 	int i;
    211  1.1  reinoud 
    212  1.1  reinoud 	for (i = 0; i < count; i++)
    213  1.1  reinoud 		podulebus_bs_w_1(cookie, bsh, offset + i, datap[i]);
    214  1.1  reinoud }
    215  1.1  reinoud 
    216  1.1  reinoud void
    217  1.1  reinoud podulebus_bs_wr_2(void *cookie, bus_space_handle_t bsh,
    218  1.8    skrll 			 bus_size_t offset, uint16_t const *datap,
    219  1.1  reinoud 			 bus_size_t count)
    220  1.1  reinoud {
    221  1.1  reinoud 	int i;
    222  1.1  reinoud 
    223  1.1  reinoud 	for (i = 0; i < count; i++)
    224  1.1  reinoud 		podulebus_bs_w_2(cookie, bsh, offset + i, datap[i]);
    225  1.1  reinoud }
    226  1.1  reinoud 
    227  1.1  reinoud void
    228  1.1  reinoud podulebus_bs_sr_1(void *cookie, bus_space_handle_t bsh,
    229  1.8    skrll 		       bus_size_t offset, uint8_t value, bus_size_t count)
    230  1.1  reinoud {
    231  1.1  reinoud 	int i;
    232  1.1  reinoud 
    233  1.1  reinoud 	for (i = 0; i < count; i++)
    234  1.1  reinoud 		podulebus_bs_w_1(cookie, bsh, offset + i, value);
    235  1.1  reinoud }
    236  1.1  reinoud 
    237  1.1  reinoud void
    238  1.1  reinoud podulebus_bs_sr_2(void *cookie, bus_space_handle_t bsh,
    239  1.8    skrll 		       bus_size_t offset, uint16_t value, bus_size_t count)
    240  1.1  reinoud {
    241  1.1  reinoud 	int i;
    242  1.1  reinoud 
    243  1.1  reinoud 	for (i = 0; i < count; i++)
    244  1.1  reinoud 		podulebus_bs_w_2(cookie, bsh, offset + i, value);
    245  1.1  reinoud }
    246