xref: /netbsd-src/sys/arch/cobalt/include/bus_defs.h (revision 6a493d6bc668897c91594964a732d38505b70cbb)
1 /*	$NetBSD: bus_defs.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_DEFS_H_
34 #define _COBALT_BUS_DEFS_H_
35 
36 /*
37  * Bus address and size types
38  */
39 typedef u_long bus_addr_t;
40 typedef u_long bus_size_t;
41 
42 #include <mips/locore.h>
43 
44 /*
45  * Access methods for bus resources and address space.
46  */
47 typedef int	bus_space_tag_t;
48 typedef u_long	bus_space_handle_t;
49 
50 #define	BUS_SPACE_MAP_CACHEABLE		0x01
51 #define	BUS_SPACE_MAP_LINEAR		0x02
52 #define BUS_SPACE_MAP_PREFETCHABLE	0x04
53 
54 #define __BUS_SPACE_HAS_STREAM_METHODS
55 
56 #define	BUS_SPACE_BARRIER_READ	0x01		/* force read barrier */
57 #define	BUS_SPACE_BARRIER_WRITE	0x02		/* force write barrier */
58 
59 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
60 
61 /*
62  * Flags used in various bus DMA methods.
63  */
64 #define	BUS_DMA_WAITOK		0x000	/* safe to sleep (pseudo-flag) */
65 #define	BUS_DMA_NOWAIT		0x001	/* not safe to sleep */
66 #define	BUS_DMA_ALLOCNOW	0x002	/* perform resource allocation now */
67 #define	BUS_DMA_COHERENT	0x004	/* hint: map memory DMA coherent */
68 #define	BUS_DMA_STREAMING	0x008	/* hint: sequential, unidirectional */
69 #define	BUS_DMA_BUS1		0x010	/* placeholders for bus functions... */
70 #define	BUS_DMA_BUS2		0x020
71 #define	BUS_DMA_BUS3		0x040
72 #define	BUS_DMA_BUS4		0x080
73 #define	BUS_DMA_READ		0x100	/* mapping is device -> memory only */
74 #define	BUS_DMA_WRITE		0x200	/* mapping is memory -> device only */
75 #define	BUS_DMA_NOCACHE		0x400	/* hint: map non-cached memory */
76 
77 #define	COBALT_DMAMAP_COHERENT	0x10000	/* no cache flush necessary on sync */
78 
79 /* Forwards needed by prototypes below. */
80 struct mbuf;
81 struct uio;
82 
83 /*
84  * Operations performed by bus_dmamap_sync().
85  */
86 #define	BUS_DMASYNC_PREREAD	0x01	/* pre-read synchronization */
87 #define	BUS_DMASYNC_POSTREAD	0x02	/* post-read synchronization */
88 #define	BUS_DMASYNC_PREWRITE	0x04	/* pre-write synchronization */
89 #define	BUS_DMASYNC_POSTWRITE	0x08	/* post-write synchronization */
90 
91 typedef struct cobalt_bus_dma_tag		*bus_dma_tag_t;
92 typedef struct cobalt_bus_dmamap		*bus_dmamap_t;
93 
94 #define BUS_DMA_TAG_VALID(t)    ((t) != (bus_dma_tag_t)0)
95 
96 /*
97  *	bus_dma_segment_t
98  *
99  *	Describes a single contiguous DMA transaction.  Values
100  *	are suitable for programming into DMA registers.
101  */
102 struct cobalt_bus_dma_segment {
103 	bus_addr_t	ds_addr;	/* DMA address */
104 	bus_size_t	ds_len;		/* length of transfer */
105 	vaddr_t		_ds_vaddr;	/* virtual address, 0 if invalid */
106 };
107 typedef struct cobalt_bus_dma_segment	bus_dma_segment_t;
108 
109 /*
110  *	bus_dma_tag_t
111  *
112  *	A machine-dependent opaque type describing the implementation of
113  *	DMA for a given bus.
114  */
115 
116 struct cobalt_bus_dma_tag {
117 	/*
118 	 * DMA mapping methods.
119 	 */
120 	int	(*_dmamap_create)(bus_dma_tag_t, bus_size_t, int,
121 		    bus_size_t, bus_size_t, int, bus_dmamap_t *);
122 	void	(*_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t);
123 	int	(*_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *,
124 		    bus_size_t, struct proc *, int);
125 	int	(*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t,
126 		    struct mbuf *, int);
127 	int	(*_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t,
128 		    struct uio *, int);
129 	int	(*_dmamap_load_raw)(bus_dma_tag_t, bus_dmamap_t,
130 		    bus_dma_segment_t *, int, bus_size_t, int);
131 	void	(*_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t);
132 	void	(*_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t,
133 		    bus_addr_t, bus_size_t, int);
134 
135 	/*
136 	 * DMA memory utility functions.
137 	 */
138 	int	(*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t,
139 		    bus_size_t, bus_dma_segment_t *, int, int *, int);
140 	void	(*_dmamem_free)(bus_dma_tag_t,
141 		    bus_dma_segment_t *, int);
142 	int	(*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *,
143 		    int, size_t, void **, int);
144 	void	(*_dmamem_unmap)(bus_dma_tag_t, void *, size_t);
145 	paddr_t	(*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *,
146 		    int, off_t, int, int);
147 };
148 
149 /*
150  *	bus_dmamap_t
151  *
152  *	Describes a DMA mapping.
153  */
154 struct cobalt_bus_dmamap {
155 	/*
156 	 * PRIVATE MEMBERS: not for use my machine-independent code.
157 	 */
158 	bus_size_t	_dm_size;	/* largest DMA transfer mappable */
159 	int		_dm_segcnt;	/* number of segs this map can map */
160 	bus_size_t	_dm_maxmaxsegsz; /* fixed largest possible segment */
161 	bus_size_t	_dm_boundary;	/* don't cross this */
162 	int		_dm_flags;	/* misc. flags */
163 	struct vmspace	*_dm_vmspace;	/* vmspace that owns this mapping */
164 
165 	/*
166 	 * PUBLIC MEMBERS: these are used by machine-independent code.
167 	 */
168 	bus_size_t	dm_maxsegsz;	/* largest possible segment */
169 	bus_size_t	dm_mapsize;	/* size of the mapping */
170 	int		dm_nsegs;	/* # valid segments in mapping */
171 	bus_dma_segment_t dm_segs[1];	/* segments; variable length */
172 };
173 
174 #endif /* _COBALT_BUS_DEFS_H_ */
175