xref: /netbsd/sys/arch/hppa/include/bus_defs.h (revision 8a06b90d)
1 /*	$NetBSD: bus_defs.h,v 1.2 2019/09/23 16:17:56 skrll Exp $	*/
2 
3 /*	$OpenBSD: bus.h,v 1.13 2001/07/30 14:15:59 art Exp $	*/
4 
5 /*
6  * Copyright (c) 1998-2004 Michael Shalayeff
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
22  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28  * THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 
32 #ifndef _MACHINE_BUS_DEFS_H_
33 #define _MACHINE_BUS_DEFS_H_
34 
35 #include <machine/cpufunc.h>
36 
37 /*
38  * Bus address and size types.
39  */
40 typedef u_long bus_addr_t;
41 typedef u_long bus_size_t;
42 
43 #define PRIxBUSADDR	"lx"
44 #define PRIxBUSSIZE	"lx"
45 #define PRIuBUSSIZE	"lu"
46 
47 typedef u_long bus_space_handle_t;
48 
49 #define PRIxBSH		"lx"
50 
51 struct hppa_bus_space_tag {
52 	void *hbt_cookie;
53 
54 	int  (*hbt_map)(void *v, bus_addr_t addr, bus_size_t size,
55 			     int flags, bus_space_handle_t *bshp);
56 	void (*hbt_unmap)(void *v, bus_space_handle_t bsh,
57 			       bus_size_t size);
58 	int  (*hbt_subregion)(void *v, bus_space_handle_t bsh,
59 				   bus_size_t offset, bus_size_t size,
60 				   bus_space_handle_t *nbshp);
61 	int  (*hbt_alloc)(void *v, bus_addr_t rstart, bus_addr_t rend,
62 			       bus_size_t size, bus_size_t align,
63 			       bus_size_t boundary, int flags,
64 			       bus_addr_t *addrp, bus_space_handle_t *bshp);
65 	void (*hbt_free)(void *, bus_space_handle_t, bus_size_t);
66 	void (*hbt_barrier)(void *v, bus_space_handle_t h,
67 				 bus_size_t o, bus_size_t l, int op);
68 	void *(*hbt_vaddr)(void *, bus_space_handle_t);
69 	paddr_t (*hbt_mmap)(void *, bus_addr_t, off_t, int, int);
70 
71 	uint8_t  (*hbt_r1)(void *, bus_space_handle_t, bus_size_t);
72 	uint16_t (*hbt_r2)(void *, bus_space_handle_t, bus_size_t);
73 	uint32_t (*hbt_r4)(void *, bus_space_handle_t, bus_size_t);
74 	uint64_t (*hbt_r8)(void *, bus_space_handle_t, bus_size_t);
75 
76 	void (*hbt_w1)(void *, bus_space_handle_t, bus_size_t, uint8_t);
77 	void (*hbt_w2)(void *, bus_space_handle_t, bus_size_t, uint16_t);
78 	void (*hbt_w4)(void *, bus_space_handle_t, bus_size_t, uint32_t);
79 	void (*hbt_w8)(void *, bus_space_handle_t, bus_size_t, uint64_t);
80 
81 	void (*hbt_rm_1)(void *v, bus_space_handle_t h,
82 			      bus_size_t o, uint8_t *a, bus_size_t c);
83 	void (*hbt_rm_2)(void *v, bus_space_handle_t h,
84 			      bus_size_t o, uint16_t *a, bus_size_t c);
85 	void (*hbt_rm_4)(void *v, bus_space_handle_t h,
86 			      bus_size_t o, uint32_t *a, bus_size_t c);
87 	void (*hbt_rm_8)(void *v, bus_space_handle_t h,
88 			      bus_size_t o, uint64_t *a, bus_size_t c);
89 
90 	void (*hbt_wm_1)(void *v, bus_space_handle_t h, bus_size_t o,
91 			      const uint8_t *a, bus_size_t c);
92 	void (*hbt_wm_2)(void *v, bus_space_handle_t h, bus_size_t o,
93 			      const uint16_t *a, bus_size_t c);
94 	void (*hbt_wm_4)(void *v, bus_space_handle_t h, bus_size_t o,
95 			      const uint32_t *a, bus_size_t c);
96 	void (*hbt_wm_8)(void *v, bus_space_handle_t h, bus_size_t o,
97 			      const uint64_t *a, bus_size_t c);
98 
99 	void (*hbt_sm_1)(void *v, bus_space_handle_t h, bus_size_t o,
100 			      uint8_t  vv, bus_size_t c);
101 	void (*hbt_sm_2)(void *v, bus_space_handle_t h, bus_size_t o,
102 			      uint16_t vv, bus_size_t c);
103 	void (*hbt_sm_4)(void *v, bus_space_handle_t h, bus_size_t o,
104 			      uint32_t vv, bus_size_t c);
105 	void (*hbt_sm_8)(void *v, bus_space_handle_t h, bus_size_t o,
106 			      uint64_t vv, bus_size_t c);
107 
108 	void (*hbt_rrm_2)(void *v, bus_space_handle_t h,
109 			       bus_size_t o, uint16_t *a, bus_size_t c);
110 	void (*hbt_rrm_4)(void *v, bus_space_handle_t h,
111 			       bus_size_t o, uint32_t *a, bus_size_t c);
112 	void (*hbt_rrm_8)(void *v, bus_space_handle_t h,
113 			       bus_size_t o, uint64_t *a, bus_size_t c);
114 
115 	void (*hbt_wrm_2)(void *v, bus_space_handle_t h,
116 			       bus_size_t o, const uint16_t *a, bus_size_t c);
117 	void (*hbt_wrm_4)(void *v, bus_space_handle_t h,
118 			       bus_size_t o, const uint32_t *a, bus_size_t c);
119 	void (*hbt_wrm_8)(void *v, bus_space_handle_t h,
120 			       bus_size_t o, const uint64_t *a, bus_size_t c);
121 
122 	void (*hbt_rr_1)(void *v, bus_space_handle_t h,
123 			      bus_size_t o, uint8_t *a, bus_size_t c);
124 	void (*hbt_rr_2)(void *v, bus_space_handle_t h,
125 			      bus_size_t o, uint16_t *a, bus_size_t c);
126 	void (*hbt_rr_4)(void *v, bus_space_handle_t h,
127 			      bus_size_t o, uint32_t *a, bus_size_t c);
128 	void (*hbt_rr_8)(void *v, bus_space_handle_t h,
129 			      bus_size_t o, uint64_t *a, bus_size_t c);
130 
131 	void (*hbt_wr_1)(void *v, bus_space_handle_t h,
132 			      bus_size_t o, const uint8_t *a, bus_size_t c);
133 	void (*hbt_wr_2)(void *v, bus_space_handle_t h,
134 			      bus_size_t o, const uint16_t *a, bus_size_t c);
135 	void (*hbt_wr_4)(void *v, bus_space_handle_t h,
136 			      bus_size_t o, const uint32_t *a, bus_size_t c);
137 	void (*hbt_wr_8)(void *v, bus_space_handle_t h,
138 			      bus_size_t o, const uint64_t *a, bus_size_t c);
139 
140 	void (*hbt_rrr_2)(void *v, bus_space_handle_t h,
141 			       bus_size_t o, uint16_t *a, bus_size_t c);
142 	void (*hbt_rrr_4)(void *v, bus_space_handle_t h,
143 			       bus_size_t o, uint32_t *a, bus_size_t c);
144 	void (*hbt_rrr_8)(void *v, bus_space_handle_t h,
145 			       bus_size_t o, uint64_t *a, bus_size_t c);
146 
147 	void (*hbt_wrr_2)(void *v, bus_space_handle_t h,
148 			       bus_size_t o, const uint16_t *a, bus_size_t c);
149 	void (*hbt_wrr_4)(void *v, bus_space_handle_t h,
150 			       bus_size_t o, const uint32_t *a, bus_size_t c);
151 	void (*hbt_wrr_8)(void *v, bus_space_handle_t h,
152 			       bus_size_t o, const uint64_t *a, bus_size_t c);
153 
154 	void (*hbt_sr_1)(void *v, bus_space_handle_t h,
155 			       bus_size_t o, uint8_t vv, bus_size_t c);
156 	void (*hbt_sr_2)(void *v, bus_space_handle_t h,
157 			       bus_size_t o, uint16_t vv, bus_size_t c);
158 	void (*hbt_sr_4)(void *v, bus_space_handle_t h,
159 			       bus_size_t o, uint32_t vv, bus_size_t c);
160 	void (*hbt_sr_8)(void *v, bus_space_handle_t h,
161 			       bus_size_t o, uint64_t vv, bus_size_t c);
162 
163 	void (*hbt_cp_1)(void *v, bus_space_handle_t h1, bus_size_t o1,
164 			      bus_space_handle_t h2, bus_size_t o2, bus_size_t c);
165 	void (*hbt_cp_2)(void *v, bus_space_handle_t h1, bus_size_t o1,
166 			      bus_space_handle_t h2, bus_size_t o2, bus_size_t c);
167 	void (*hbt_cp_4)(void *v, bus_space_handle_t h1, bus_size_t o1,
168 			      bus_space_handle_t h2, bus_size_t o2, bus_size_t c);
169 	void (*hbt_cp_8)(void *v, bus_space_handle_t h1, bus_size_t o1,
170 			      bus_space_handle_t h2, bus_size_t o2, bus_size_t c);
171 };
172 typedef const struct hppa_bus_space_tag *bus_space_tag_t;
173 
174 /* flags for bus space map functions */
175 #define BUS_SPACE_MAP_READONLY		0x0008
176 #define BUS_SPACE_MAP_NOEXTENT		0x8000  /* no extent ops */
177 
178 
179 /* bus access routines */
180 #define	BUS_SPACE_ALIGNED_POINTER(p, t)	ALIGNED_POINTER(p, t)
181 
182 /* XXX fredette */
183 #define	__BUS_SPACE_HAS_STREAM_METHODS
184 
185 #define	BUS_DMA_WAITOK		0x000	/* safe to sleep (pseudo-flag) */
186 #define	BUS_DMA_NOWAIT		0x001	/* not safe to sleep */
187 #define	BUS_DMA_ALLOCNOW	0x002	/* perform resource allocation now */
188 #define	BUS_DMA_COHERENT	0x004	/* hint: map memory DMA coherent */
189 #define	BUS_DMA_STREAMING	0x008	/* hint: sequential, unidirectional */
190 #define	BUS_DMA_BUS1		0x010	/* placeholders for bus functions... */
191 #define	BUS_DMA_BUS2		0x020
192 #define	BUS_DMA_BUS3		0x040
193 #define	BUS_DMA_BUS4		0x080
194 #define	BUS_DMA_READ		0x100	/* mapping is device -> memory only */
195 #define	BUS_DMA_WRITE		0x200	/* mapping is memory -> device only */
196 #define	BUS_DMA_NOCACHE		0x400	/* hint: map non-cached memory */
197 
198 /* For devices that have a 24-bit address space */
199 #define	BUS_DMA_24BIT		BUS_DMA_BUS1
200 
201 /* Forwards needed by prototypes below. */
202 struct mbuf;
203 struct proc;
204 struct uio;
205 
206 typedef const struct hppa_bus_dma_tag	*bus_dma_tag_t;
207 typedef struct hppa_bus_dmamap	*bus_dmamap_t;
208 
209 #define BUS_DMA_TAG_VALID(t)    ((t) != (bus_dma_tag_t)0)
210 
211 /*
212  *	bus_dma_segment_t
213  *
214  *	Describes a single contiguous DMA transaction.  Values
215  *	are suitable for programming into DMA registers.
216  */
217 struct hppa_bus_dma_segment {
218 	bus_addr_t	ds_addr;	/* DMA address */
219 	bus_size_t	ds_len;		/* length of transfer */
220 	void		*_ds_mlist;	/* page list when dmamem_alloc'ed */
221 	vaddr_t		_ds_va;		/* VA when dmamem_map'ed */
222 };
223 typedef struct hppa_bus_dma_segment	bus_dma_segment_t;
224 
225 /*
226  *	bus_dma_tag_t
227  *
228  *	A machine-dependent opaque type describing the implementation of
229  *	DMA for a given bus.
230  */
231 
232 struct hppa_bus_dma_tag {
233 	void	*_cookie;		/* cookie used in the guts */
234 
235 	/*
236 	 * DMA mapping methods.
237 	 */
238 	int	(*_dmamap_create)(void *, bus_size_t, int,
239 		    bus_size_t, bus_size_t, int, bus_dmamap_t *);
240 	void	(*_dmamap_destroy)(void *, bus_dmamap_t);
241 	int	(*_dmamap_load)(void *, bus_dmamap_t, void *,
242 		    bus_size_t, struct proc *, int);
243 	int	(*_dmamap_load_mbuf)(void *, bus_dmamap_t,
244 		    struct mbuf *, int);
245 	int	(*_dmamap_load_uio)(void *, bus_dmamap_t,
246 		    struct uio *, int);
247 	int	(*_dmamap_load_raw)(void *, bus_dmamap_t,
248 		    bus_dma_segment_t *, int, bus_size_t, int);
249 	void	(*_dmamap_unload)(void *, bus_dmamap_t);
250 	void	(*_dmamap_sync)(void *, bus_dmamap_t, bus_addr_t, bus_size_t, int);
251 
252 	/*
253 	 * DMA memory utility functions.
254 	 */
255 	int	(*_dmamem_alloc)(void *, bus_size_t, bus_size_t,
256 		    bus_size_t, bus_dma_segment_t *, int, int *, int);
257 	void	(*_dmamem_free)(void *, bus_dma_segment_t *, int);
258 	int	(*_dmamem_map)(void *, bus_dma_segment_t *,
259 		    int, size_t, void **, int);
260 	void	(*_dmamem_unmap)(void *, void *, size_t);
261 	paddr_t	(*_dmamem_mmap)(void *, bus_dma_segment_t *,
262 		    int, off_t, int, int);
263 };
264 
265 /*
266  *	bus_dmamap_t
267  *
268  *	Describes a DMA mapping.
269  */
270 struct hppa_bus_dmamap {
271 	/*
272 	 * PRIVATE MEMBERS: not for use by machine-independent code.
273 	 */
274 	bus_size_t	_dm_size;	/* largest DMA transfer mappable */
275 	int		_dm_segcnt;	/* number of segs this map can map */
276 	bus_size_t	_dm_maxsegsz;	/* fixed largest possible segment */
277 	bus_size_t	_dm_boundary;	/* don't cross this */
278 	int		_dm_flags;	/* misc. flags */
279 
280 	void		*_dm_cookie;	/* cookie for bus-specific functions */
281 
282 	/*
283 	 * PUBLIC MEMBERS: these are used by machine-independent code.
284 	 */
285 	bus_size_t	dm_maxsegsz;	/* largest possible segment */
286 	bus_size_t	dm_mapsize;	/* size of the mapping */
287 	int		dm_nsegs;	/* # valid segments in mapping */
288 	bus_dma_segment_t dm_segs[1];	/* segments; variable length */
289 };
290 
291 #endif /* _MACHINE_BUS_DEFS_H_ */
292