Home | History | Annotate | Line # | Download | only in include
bus_funcs.h revision 1.1
      1 /*	$NetBSD: bus_funcs.h,v 1.1 2011/07/01 17:09:59 dyoung Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1996, 1997, 1998, 2001 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 of the Numerical Aerospace Simulation Facility,
      9  * NASA Ames Research Center.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  * POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 #ifndef _COBALT_BUS_FUNCS_H_
     34 #define _COBALT_BUS_FUNCS_H_
     35 
     36 /*
     37  *	uintN_t bus_space_read_N(bus_space_tag_t tag,
     38  *	    bus_space_handle_t bsh, bus_size_t offset);
     39  *
     40  * Read a 1, 2, 4, or 8 byte quantity from bus space
     41  * described by tag/handle/offset.
     42  */
     43 
     44 #define	bus_space_read_1(t, h, o)					\
     45      ((void) t, (*(volatile uint8_t *)((h) + (o))))
     46 
     47 #define	bus_space_read_2(t, h, o)					\
     48      ((void) t, (*(volatile uint16_t *)((h) + (o))))
     49 
     50 #define	bus_space_read_4(t, h, o)					\
     51      ((void) t, (*(volatile uint32_t *)((h) + (o))))
     52 
     53 #if 0	/* Cause a link error for bus_space_read_8 */
     54 #define	bus_space_read_8(t, h, o)	!!! bus_space_read_8 unimplemented !!!
     55 #endif
     56 
     57 /*
     58  *	void bus_space_write_N(bus_space_tag_t tag,
     59  *	    bus_space_handle_t bsh, bus_size_t offset,
     60  *	    uintN_t value);
     61  *
     62  * Write the 1, 2, 4, or 8 byte value `value' to bus space
     63  * described by tag/handle/offset.
     64  */
     65 
     66 #define	bus_space_write_1(t, h, o, v)					\
     67 do {									\
     68 	(void) t;							\
     69 	*(volatile uint8_t *)((h) + (o)) = (v);			\
     70 } while (0)
     71 
     72 #define	bus_space_write_2(t, h, o, v)					\
     73 do {									\
     74 	(void) t;							\
     75 	*(volatile uint16_t *)((h) + (o)) = (v);			\
     76 } while (0)
     77 
     78 #define	bus_space_write_4(t, h, o, v)					\
     79 do {									\
     80 	(void) t;							\
     81 	*(volatile uint32_t *)((h) + (o)) = (v);			\
     82 } while (0)
     83 
     84 #if 0	/* Cause a link error for bus_space_write_8 */
     85 #define	bus_space_write_8	!!! bus_space_write_8 not implemented !!!
     86 #endif
     87 
     88 /*
     89  * Operations which handle byte stream data on word access.
     90  *
     91  * These functions are defined to resolve endian mismatch, by either
     92  * - When normal (i.e. stream-less) operations perform byte swap
     93  *   to resolve endian mismatch, these functions bypass the byte swap.
     94  * or
     95  * - When bus bridge performs automatic byte swap, these functions
     96  *   perform byte swap once more, to cancel the bridge's behavior.
     97  *
     98  * Currently these are just same as normal operations, since all
     99  * supported buses are same endian with CPU (i.e. little-endian).
    100  *
    101  */
    102 #define bus_space_read_stream_2(tag, bsh, offset)			\
    103 	bus_space_read_2(tag, bsh, offset)
    104 #define bus_space_read_stream_4(tag, bsh, offset)			\
    105 	bus_space_read_4(tag, bsh, offset)
    106 #define bus_space_read_stream_8(tag, bsh, offset)			\
    107 	bus_space_read_8(tag, bsh, offset)
    108 #define bus_space_read_multi_stream_2(tag, bsh, offset, datap, count)	\
    109 	bus_space_read_multi_2(tag, bsh, offset, datap, count)
    110 #define bus_space_read_multi_stream_4(tag, bsh, offset, datap, count)	\
    111 	bus_space_read_multi_4(tag, bsh, offset, datap, count)
    112 #define bus_space_read_multi_stream_8(tag, bsh, offset, datap, count)	\
    113 	bus_space_read_multi_8(tag, bsh, offset, datap, count)
    114 #define bus_space_read_region_stream_2(tag, bsh, offset, datap, count)	\
    115 	bus_space_read_region_2(tag, bsh, offset, datap, count)
    116 #define bus_space_read_region_stream_4(tag, bsh, offset, datap, count)	\
    117 	bus_space_read_region_4(tag, bsh, offset, datap, count)
    118 #define bus_space_read_region_stream_8(tag, bsh, offset, datap, count)	\
    119 	bus_space_read_region_8(tag, bsh, offset, datap, count)
    120 #define bus_space_write_stream_2(tag, bsh, offset, data)		\
    121 	bus_space_write_2(tag, bsh, offset, data)
    122 #define bus_space_write_stream_4(tag, bsh, offset, data)		\
    123 	bus_space_write_4(tag, bsh, offset, data)
    124 #define bus_space_write_stream_8(tag, bsh, offset, data)		\
    125 	bus_space_write_8(tag, bsh, offset, data)
    126 #define bus_space_write_multi_stream_2(tag, bsh, offset, datap, count)	\
    127 	bus_space_write_multi_2(tag, bsh, offset, datap, count)
    128 #define bus_space_write_multi_stream_4(tag, bsh, offset, datap, count)	\
    129 	bus_space_write_multi_4(tag, bsh, offset, datap, count)
    130 #define bus_space_write_multi_stream_8(tag, bsh, offset, datap, count)	\
    131 	bus_space_write_multi_8(tag, bsh, offset, datap, count)
    132 #define bus_space_write_region_stream_2(tag, bsh, offset, datap, count)	\
    133 	bus_space_write_region_2(tag, bsh, offset, datap, count)
    134 #define bus_space_write_region_stream_4(tag, bsh, offset, datap, count)	\
    135 	bus_space_write_region_4(tag, bsh, offset, datap, count)
    136 #define bus_space_write_region_stream_8(tag, bsh, offset, datap, count)	\
    137 	bus_space_write_region_8(tag, bsh, offset, datap, count)
    138 #define bus_space_write_region_stream_2(tag, bsh, offset, datap, count)	\
    139 	bus_space_write_region_2(tag, bsh, offset, datap, count)
    140 #define bus_space_write_region_stream_4(tag, bsh, offset, datap, count)	\
    141 	bus_space_write_region_4(tag, bsh, offset, datap, count)
    142 #define bus_space_write_region_stream_8(tag, bsh, offset, datap, count)	\
    143 	bus_space_write_region_8(tag, bsh, offset, datap, count)
    144 #define bus_space_set_multi_stream_2(tag, bsh, offset, data, count)	\
    145 	bus_space_set_multi_2(tag, bsh, offset, data, count)
    146 #define bus_space_set_multi_stream_4(tag, bsh, offset, data, count)	\
    147 	bus_space_set_multi_4(tag, bsh, offset, data, count)
    148 #define bus_space_set_multi_stream_8(tag, bsh, offset, data, count)	\
    149 	bus_space_set_multi_8(tag, bsh, offset, data, count)
    150 #define bus_space_set_region_stream_2(tag, bsh, offset, data, count)	\
    151 	bus_space_set_region_2(tag, bsh, offset, data, count)
    152 #define bus_space_set_region_stream_4(tag, bsh, offset, data, count)	\
    153 	bus_space_set_region_4(tag, bsh, offset, data, count)
    154 #define bus_space_set_region_stream_8(tag, bsh, offset, data, count)	\
    155 	bus_space_set_region_8(tag, bsh, offset, data, count)
    156 
    157 /*
    158  * Bus read/write barrier methods.
    159  *
    160  *	void bus_space_barrier(bus_space_tag_t tag,
    161  *	    bus_space_handle_t bsh, bus_size_t offset,
    162  *	    bus_size_t len, int flags);
    163  *
    164  * On the MIPS, we just flush the write buffer.
    165  */
    166 #define	bus_space_barrier(t, h, o, l, f)	\
    167 	((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f),	\
    168 	 wbflush()))
    169 
    170 /* Forwards needed by prototypes below. */
    171 struct mbuf;
    172 struct uio;
    173 
    174 #define	bus_dmamap_create(t, s, n, m, b, f, p)			\
    175 	(*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
    176 #define	bus_dmamap_destroy(t, p)				\
    177 	(*(t)->_dmamap_destroy)((t), (p))
    178 #define	bus_dmamap_load(t, m, b, s, p, f)			\
    179 	(*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
    180 #define	bus_dmamap_load_mbuf(t, m, b, f)			\
    181 	(*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
    182 #define	bus_dmamap_load_uio(t, m, u, f)				\
    183 	(*(t)->_dmamap_load_uio)((t), (m), (u), (f))
    184 #define	bus_dmamap_load_raw(t, m, sg, n, s, f)			\
    185 	(*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
    186 #define	bus_dmamap_unload(t, p)					\
    187 	(*(t)->_dmamap_unload)((t), (p))
    188 #define	bus_dmamap_sync(t, p, o, l, ops)			\
    189 	(*(t)->_dmamap_sync)((t), (p), (o), (l), (ops))
    190 
    191 #define	bus_dmamem_alloc(t, s, a, b, sg, n, r, f)		\
    192 	(*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
    193 #define	bus_dmamem_free(t, sg, n)				\
    194 	(*(t)->_dmamem_free)((t), (sg), (n))
    195 #define	bus_dmamem_map(t, sg, n, s, k, f)			\
    196 	(*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
    197 #define	bus_dmamem_unmap(t, k, s)				\
    198 	(*(t)->_dmamem_unmap)((t), (k), (s))
    199 #define	bus_dmamem_mmap(t, sg, n, o, p, f)			\
    200 	(*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
    201 
    202 #define bus_dmatag_subregion(t, mna, mxa, nt, f) EOPNOTSUPP
    203 #define bus_dmatag_destroy(t)
    204 
    205 #ifdef _COBALT_BUS_DMA_PRIVATE
    206 int	_bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t,
    207 	    bus_size_t, int, bus_dmamap_t *);
    208 void	_bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
    209 int	_bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *,
    210 	    bus_size_t, struct proc *, int);
    211 int	_bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t,
    212 	    struct mbuf *, int);
    213 int	_bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t,
    214 	    struct uio *, int);
    215 int	_bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t,
    216 	    bus_dma_segment_t *, int, bus_size_t, int);
    217 void	_bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
    218 void	_bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
    219 	    bus_size_t, int);
    220 
    221 int	_bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size,
    222 	    bus_size_t alignment, bus_size_t boundary,
    223 	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags);
    224 void	_bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs,
    225 	    int nsegs);
    226 int	_bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs,
    227 	    int nsegs, size_t size, void **kvap, int flags);
    228 void	_bus_dmamem_unmap(bus_dma_tag_t tag, void *kva,
    229 	    size_t size);
    230 paddr_t	_bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs,
    231 	    int nsegs, off_t off, int prot, int flags);
    232 
    233 int	_bus_dmamem_alloc_range(bus_dma_tag_t tag, bus_size_t size,
    234 	    bus_size_t alignment, bus_size_t boundary,
    235 	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
    236 	    vaddr_t low, vaddr_t high);
    237 
    238 extern struct cobalt_bus_dma_tag cobalt_default_bus_dma_tag;
    239 #endif /* _COBALT_BUS_DMA_PRIVATE */
    240 
    241 #endif /* _COBALT_BUS_FUNCS_H_ */
    242