xref: /netbsd-src/sys/arch/sparc/include/bus_defs.h (revision bf158e33f8ddb4806758d116c5263901660763ff)
1*bf158e33Sskrll /*	$NetBSD: bus_defs.h,v 1.2 2019/09/23 16:17:57 skrll Exp $	*/
259adf08eSdyoung 
359adf08eSdyoung /*-
459adf08eSdyoung  * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
559adf08eSdyoung  * All rights reserved.
659adf08eSdyoung  *
759adf08eSdyoung  * This code is derived from software contributed to The NetBSD Foundation
859adf08eSdyoung  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
959adf08eSdyoung  * NASA Ames Research Center.
1059adf08eSdyoung  *
1159adf08eSdyoung  * Redistribution and use in source and binary forms, with or without
1259adf08eSdyoung  * modification, are permitted provided that the following conditions
1359adf08eSdyoung  * are met:
1459adf08eSdyoung  * 1. Redistributions of source code must retain the above copyright
1559adf08eSdyoung  *    notice, this list of conditions and the following disclaimer.
1659adf08eSdyoung  * 2. Redistributions in binary form must reproduce the above copyright
1759adf08eSdyoung  *    notice, this list of conditions and the following disclaimer in the
1859adf08eSdyoung  *    documentation and/or other materials provided with the distribution.
1959adf08eSdyoung  *
2059adf08eSdyoung  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2159adf08eSdyoung  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2259adf08eSdyoung  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2359adf08eSdyoung  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2459adf08eSdyoung  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2559adf08eSdyoung  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2659adf08eSdyoung  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2759adf08eSdyoung  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2859adf08eSdyoung  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2959adf08eSdyoung  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3059adf08eSdyoung  * POSSIBILITY OF SUCH DAMAGE.
3159adf08eSdyoung  */
3259adf08eSdyoung 
3359adf08eSdyoung /*
3459adf08eSdyoung  * Copyright (c) 1996 Charles M. Hannum.  All rights reserved.
3559adf08eSdyoung  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
3659adf08eSdyoung  *
3759adf08eSdyoung  * Redistribution and use in source and binary forms, with or without
3859adf08eSdyoung  * modification, are permitted provided that the following conditions
3959adf08eSdyoung  * are met:
4059adf08eSdyoung  * 1. Redistributions of source code must retain the above copyright
4159adf08eSdyoung  *    notice, this list of conditions and the following disclaimer.
4259adf08eSdyoung  * 2. Redistributions in binary form must reproduce the above copyright
4359adf08eSdyoung  *    notice, this list of conditions and the following disclaimer in the
4459adf08eSdyoung  *    documentation and/or other materials provided with the distribution.
4559adf08eSdyoung  * 3. All advertising materials mentioning features or use of this software
4659adf08eSdyoung  *    must display the following acknowledgement:
4759adf08eSdyoung  *      This product includes software developed by Christopher G. Demetriou
4859adf08eSdyoung  *	for the NetBSD Project.
4959adf08eSdyoung  * 4. The name of the author may not be used to endorse or promote products
5059adf08eSdyoung  *    derived from this software without specific prior written permission
5159adf08eSdyoung  *
5259adf08eSdyoung  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
5359adf08eSdyoung  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
5459adf08eSdyoung  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
5559adf08eSdyoung  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
5659adf08eSdyoung  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
5759adf08eSdyoung  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
5859adf08eSdyoung  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
5959adf08eSdyoung  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
6059adf08eSdyoung  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
6159adf08eSdyoung  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6259adf08eSdyoung  */
6359adf08eSdyoung 
6459adf08eSdyoung #ifndef _SPARC_BUS_DEFS_H_
6559adf08eSdyoung #define _SPARC_BUS_DEFS_H_
6659adf08eSdyoung 
6759adf08eSdyoung /*
6859adf08eSdyoung  * Bus address and size types
6959adf08eSdyoung  */
7059adf08eSdyoung typedef	u_long		bus_space_handle_t;
71*bf158e33Sskrll 
72*bf158e33Sskrll #define PRIxBSH		"lx"
73*bf158e33Sskrll 
7459adf08eSdyoung typedef uint64_t	bus_addr_t;
7559adf08eSdyoung typedef u_long		bus_size_t;
7659adf08eSdyoung 
77*bf158e33Sskrll #define PRIxBUSADDR	PRIx64
78*bf158e33Sskrll #define PRIxBUSSIZE	"lx"
79*bf158e33Sskrll #define PRIuBUSSIZE	"lu"
80*bf158e33Sskrll 
8159adf08eSdyoung #define	SPARC_BUS_SPACE	0
8259adf08eSdyoung 
8359adf08eSdyoung /* bus_addr_t is extended to 64-bits and has the iospace encoded in it */
8459adf08eSdyoung #define	BUS_ADDR_IOSPACE(x)	((x)>>32)
8559adf08eSdyoung #define	BUS_ADDR_PADDR(x)	((x)&0xffffffff)
8659adf08eSdyoung #define	BUS_ADDR(io, pa)	\
8759adf08eSdyoung 	((((uint64_t)(uint32_t)(io))<<32) | (uint32_t)(pa))
8859adf08eSdyoung 
8959adf08eSdyoung #define __BUS_SPACE_HAS_STREAM_METHODS	1
9059adf08eSdyoung 
9159adf08eSdyoung /*
9259adf08eSdyoung  * Access methods for bus resources and address space.
9359adf08eSdyoung  */
9459adf08eSdyoung typedef struct sparc_bus_space_tag	*bus_space_tag_t;
9559adf08eSdyoung 
9659adf08eSdyoung struct sparc_bus_space_tag {
9759adf08eSdyoung 	void		*cookie;
9859adf08eSdyoung 	bus_space_tag_t	parent;
9959adf08eSdyoung 
10059adf08eSdyoung 	/*
10159adf08eSdyoung 	 * Windows onto the parent bus that this tag maps.  If ranges
10259adf08eSdyoung 	 * is non-NULL, the address will be translated, and recursively
10359adf08eSdyoung 	 * mapped via the parent tag.
10459adf08eSdyoung 	 */
10559adf08eSdyoung 	struct openprom_range *ranges;
10659adf08eSdyoung 	int nranges;
10759adf08eSdyoung 
10859adf08eSdyoung 	int	(*sparc_bus_map)(
10959adf08eSdyoung 				bus_space_tag_t,
11059adf08eSdyoung 				bus_addr_t,
11159adf08eSdyoung 				bus_size_t,
11259adf08eSdyoung 				int,			/*flags*/
11359adf08eSdyoung 				vaddr_t,		/*preferred vaddr*/
11459adf08eSdyoung 				bus_space_handle_t *);
11559adf08eSdyoung 	int	(*sparc_bus_unmap)(
11659adf08eSdyoung 				bus_space_tag_t,
11759adf08eSdyoung 				bus_space_handle_t,
11859adf08eSdyoung 				bus_size_t);
11959adf08eSdyoung 	int	(*sparc_bus_subregion)(
12059adf08eSdyoung 				bus_space_tag_t,
12159adf08eSdyoung 				bus_space_handle_t,
12259adf08eSdyoung 				bus_size_t,		/*offset*/
12359adf08eSdyoung 				bus_size_t,		/*size*/
12459adf08eSdyoung 				bus_space_handle_t *);
12559adf08eSdyoung 
12659adf08eSdyoung 	void	(*sparc_bus_barrier)(
12759adf08eSdyoung 				bus_space_tag_t,
12859adf08eSdyoung 				bus_space_handle_t,
12959adf08eSdyoung 				bus_size_t,		/*offset*/
13059adf08eSdyoung 				bus_size_t,		/*size*/
13159adf08eSdyoung 				int);			/*flags*/
13259adf08eSdyoung 
13359adf08eSdyoung 	paddr_t	(*sparc_bus_mmap)(
13459adf08eSdyoung 				bus_space_tag_t,
13559adf08eSdyoung 				bus_addr_t,
13659adf08eSdyoung 				off_t,
13759adf08eSdyoung 				int,			/*prot*/
13859adf08eSdyoung 				int);			/*flags*/
13959adf08eSdyoung 
14059adf08eSdyoung 	void	*(*sparc_intr_establish)(
14159adf08eSdyoung 				bus_space_tag_t,
14259adf08eSdyoung 				int,			/*bus-specific intr*/
14359adf08eSdyoung 				int,			/*device class level,
14459adf08eSdyoung 							  see machine/intr.h*/
14559adf08eSdyoung 				int (*)(void *),	/*handler*/
14659adf08eSdyoung 				void *,			/*handler arg*/
14759adf08eSdyoung 				void (*)(void));	/*optional fast vector*/
14859adf08eSdyoung 
14959adf08eSdyoung 	uint8_t (*sparc_read_1)(
15059adf08eSdyoung 				bus_space_tag_t space,
15159adf08eSdyoung 				bus_space_handle_t handle,
15259adf08eSdyoung 				bus_size_t offset);
15359adf08eSdyoung 
15459adf08eSdyoung 	uint16_t (*sparc_read_2)(
15559adf08eSdyoung 				bus_space_tag_t space,
15659adf08eSdyoung 				bus_space_handle_t handle,
15759adf08eSdyoung 				bus_size_t offset);
15859adf08eSdyoung 
15959adf08eSdyoung 	uint32_t (*sparc_read_4)(
16059adf08eSdyoung 				bus_space_tag_t space,
16159adf08eSdyoung 				bus_space_handle_t handle,
16259adf08eSdyoung 				bus_size_t offset);
16359adf08eSdyoung 
16459adf08eSdyoung 	uint64_t (*sparc_read_8)(
16559adf08eSdyoung 				bus_space_tag_t space,
16659adf08eSdyoung 				bus_space_handle_t handle,
16759adf08eSdyoung 				bus_size_t offset);
16859adf08eSdyoung 
16959adf08eSdyoung 	void	(*sparc_write_1)(
17059adf08eSdyoung 				bus_space_tag_t space,
17159adf08eSdyoung 				bus_space_handle_t handle,
17259adf08eSdyoung 				bus_size_t offset,
17359adf08eSdyoung 				uint8_t value);
17459adf08eSdyoung 
17559adf08eSdyoung 	void	(*sparc_write_2)(
17659adf08eSdyoung 				bus_space_tag_t space,
17759adf08eSdyoung 				bus_space_handle_t handle,
17859adf08eSdyoung 				bus_size_t offset,
17959adf08eSdyoung 				uint16_t value);
18059adf08eSdyoung 
18159adf08eSdyoung 	void	(*sparc_write_4)(
18259adf08eSdyoung 				bus_space_tag_t space,
18359adf08eSdyoung 				bus_space_handle_t handle,
18459adf08eSdyoung 				bus_size_t offset,
18559adf08eSdyoung 				uint32_t value);
18659adf08eSdyoung 
18759adf08eSdyoung 	void	(*sparc_write_8)(
18859adf08eSdyoung 				bus_space_tag_t space,
18959adf08eSdyoung 				bus_space_handle_t handle,
19059adf08eSdyoung 				bus_size_t offset,
19159adf08eSdyoung 				uint64_t value);
19259adf08eSdyoung };
19359adf08eSdyoung 
19459adf08eSdyoung /* flags for bus space map functions */
19559adf08eSdyoung #define BUS_SPACE_MAP_BUS1	0x0100	/* placeholders for bus functions... */
19659adf08eSdyoung #define BUS_SPACE_MAP_BUS2	0x0200
19759adf08eSdyoung #define BUS_SPACE_MAP_BUS3	0x0400
19859adf08eSdyoung #define BUS_SPACE_MAP_LARGE	0x0800	/* map outside IODEV range */
19959adf08eSdyoung 
20059adf08eSdyoung 
20159adf08eSdyoung /* flags for bus_space_barrier() */
20259adf08eSdyoung #define	BUS_SPACE_BARRIER_READ	0x01		/* force read barrier */
20359adf08eSdyoung #define	BUS_SPACE_BARRIER_WRITE	0x02		/* force write barrier */
20459adf08eSdyoung 
20559adf08eSdyoung #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
20659adf08eSdyoung 
20759adf08eSdyoung /*
20859adf08eSdyoung  * Flags used in various bus DMA methods.
20959adf08eSdyoung  */
21059adf08eSdyoung #define	BUS_DMA_WAITOK		0x000	/* safe to sleep (pseudo-flag) */
21159adf08eSdyoung #define	BUS_DMA_NOWAIT		0x001	/* not safe to sleep */
21259adf08eSdyoung #define	BUS_DMA_ALLOCNOW	0x002	/* perform resource allocation now */
21359adf08eSdyoung #define	BUS_DMA_COHERENT	0x004	/* hint: map memory DMA coherent */
21459adf08eSdyoung #define	BUS_DMA_STREAMING	0x008	/* hint: sequential, unidirectional */
21559adf08eSdyoung #define	BUS_DMA_BUS1		0x010	/* placeholders for bus functions... */
21659adf08eSdyoung #define	BUS_DMA_BUS2		0x020
21759adf08eSdyoung #define	BUS_DMA_BUS3		0x040
21859adf08eSdyoung #define	BUS_DMA_BUS4		0x080
21959adf08eSdyoung #define	BUS_DMA_READ		0x100	/* mapping is device -> memory only */
22059adf08eSdyoung #define	BUS_DMA_WRITE		0x200	/* mapping is memory -> device only */
22159adf08eSdyoung #define	BUS_DMA_NOCACHE		0x400	/* hint: map non-cached memory */
22259adf08eSdyoung 
22359adf08eSdyoung /* For devices that have a 24-bit address space */
22459adf08eSdyoung #define BUS_DMA_24BIT		BUS_DMA_BUS1
22559adf08eSdyoung 
22659adf08eSdyoung /* Internal flag: current DVMA address is equal to the KVA buffer address */
22759adf08eSdyoung #define _BUS_DMA_DIRECTMAP	BUS_DMA_BUS2
22859adf08eSdyoung 
22959adf08eSdyoung /* Forwards needed by prototypes below. */
23059adf08eSdyoung struct mbuf;
23159adf08eSdyoung struct uio;
23259adf08eSdyoung 
23359adf08eSdyoung /*
23459adf08eSdyoung  * Operations performed by bus_dmamap_sync().
23559adf08eSdyoung  */
23659adf08eSdyoung #define	BUS_DMASYNC_PREREAD	0x01	/* pre-read synchronization */
23759adf08eSdyoung #define	BUS_DMASYNC_POSTREAD	0x02	/* post-read synchronization */
23859adf08eSdyoung #define	BUS_DMASYNC_PREWRITE	0x04	/* pre-write synchronization */
23959adf08eSdyoung #define	BUS_DMASYNC_POSTWRITE	0x08	/* post-write synchronization */
24059adf08eSdyoung 
24159adf08eSdyoung typedef struct sparc_bus_dma_tag	*bus_dma_tag_t;
24259adf08eSdyoung typedef struct sparc_bus_dmamap		*bus_dmamap_t;
24359adf08eSdyoung 
24459adf08eSdyoung #define BUS_DMA_TAG_VALID(t)    ((t) != (bus_dma_tag_t)0)
24559adf08eSdyoung 
24659adf08eSdyoung /*
24759adf08eSdyoung  *	bus_dma_segment_t
24859adf08eSdyoung  *
24959adf08eSdyoung  *	Describes a single contiguous DMA transaction.  Values
25059adf08eSdyoung  *	are suitable for programming into DMA registers.
25159adf08eSdyoung  */
25259adf08eSdyoung struct sparc_bus_dma_segment {
25359adf08eSdyoung 	bus_addr_t	ds_addr;	/* DVMA address */
25459adf08eSdyoung 	bus_size_t	ds_len;		/* length of transfer */
25559adf08eSdyoung 	bus_size_t	_ds_sgsize;	/* size of allocated DVMA segment */
25659adf08eSdyoung 	void		*_ds_mlist;	/* page list when dmamem_alloc'ed */
25759adf08eSdyoung 	vaddr_t		_ds_va;		/* VA when dmamem_map'ed */
25859adf08eSdyoung };
25959adf08eSdyoung typedef struct sparc_bus_dma_segment	bus_dma_segment_t;
26059adf08eSdyoung 
26159adf08eSdyoung 
26259adf08eSdyoung /*
26359adf08eSdyoung  *	bus_dma_tag_t
26459adf08eSdyoung  *
26559adf08eSdyoung  *	A machine-dependent opaque type describing the implementation of
26659adf08eSdyoung  *	DMA for a given bus.
26759adf08eSdyoung  */
26859adf08eSdyoung struct sparc_bus_dma_tag {
26959adf08eSdyoung 	void	*_cookie;		/* cookie used in the guts */
27059adf08eSdyoung 
27159adf08eSdyoung 	/*
27259adf08eSdyoung 	 * DMA mapping methods.
27359adf08eSdyoung 	 */
27459adf08eSdyoung 	int	(*_dmamap_create)(bus_dma_tag_t, bus_size_t, int,
27559adf08eSdyoung 		    bus_size_t, bus_size_t, int, bus_dmamap_t *);
27659adf08eSdyoung 	void	(*_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t);
27759adf08eSdyoung 	int	(*_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *,
27859adf08eSdyoung 		    bus_size_t, struct proc *, int);
27959adf08eSdyoung 	int	(*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t,
28059adf08eSdyoung 		    struct mbuf *, int);
28159adf08eSdyoung 	int	(*_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t,
28259adf08eSdyoung 		    struct uio *, int);
28359adf08eSdyoung 	int	(*_dmamap_load_raw)(bus_dma_tag_t, bus_dmamap_t,
28459adf08eSdyoung 		    bus_dma_segment_t *, int, bus_size_t, int);
28559adf08eSdyoung 	void	(*_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t);
28659adf08eSdyoung 	void	(*_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t,
28759adf08eSdyoung 		    bus_addr_t, bus_size_t, int);
28859adf08eSdyoung 
28959adf08eSdyoung 	/*
29059adf08eSdyoung 	 * DMA memory utility functions.
29159adf08eSdyoung 	 */
29259adf08eSdyoung 	int	(*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t,
29359adf08eSdyoung 		    bus_size_t, bus_dma_segment_t *, int, int *, int);
29459adf08eSdyoung 	void	(*_dmamem_free)(bus_dma_tag_t,
29559adf08eSdyoung 		    bus_dma_segment_t *, int);
29659adf08eSdyoung 	int	(*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *,
29759adf08eSdyoung 		    int, size_t, void **, int);
29859adf08eSdyoung 	void	(*_dmamem_unmap)(bus_dma_tag_t, void *, size_t);
29959adf08eSdyoung 	paddr_t	(*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *,
30059adf08eSdyoung 		    int, off_t, int, int);
30159adf08eSdyoung };
30259adf08eSdyoung 
30359adf08eSdyoung /*
30459adf08eSdyoung  *	bus_dmamap_t
30559adf08eSdyoung  *
30659adf08eSdyoung  *	Describes a DMA mapping.
30759adf08eSdyoung  */
30859adf08eSdyoung struct sparc_bus_dmamap {
30959adf08eSdyoung 	/*
31059adf08eSdyoung 	 * PRIVATE MEMBERS: not for use by machine-independent code.
31159adf08eSdyoung 	 */
31259adf08eSdyoung 	bus_size_t	_dm_size;	/* largest DMA transfer mappable */
31359adf08eSdyoung 	int		_dm_segcnt;	/* number of segs this map can map */
31459adf08eSdyoung 	bus_size_t	_dm_maxmaxsegsz; /* fixed largest possible segment */
31559adf08eSdyoung 	bus_size_t	_dm_boundary;	/* don't cross this */
31659adf08eSdyoung 	int		_dm_flags;	/* misc. flags */
31759adf08eSdyoung 
31859adf08eSdyoung 	void		*_dm_cookie;	/* cookie for bus-specific functions */
31959adf08eSdyoung 
32059adf08eSdyoung 	u_long		_dm_align;	/* DVMA alignment; must be a
32159adf08eSdyoung 					   multiple of the page size */
32259adf08eSdyoung 	u_long		_dm_ex_start;	/* constraints on DVMA map */
32359adf08eSdyoung 	u_long		_dm_ex_end;	/* allocations; used by the VME bus
32459adf08eSdyoung 					   driver and by the IOMMU driver
32559adf08eSdyoung 					   when mapping 24-bit devices */
32659adf08eSdyoung 
32759adf08eSdyoung 	/*
32859adf08eSdyoung 	 * PUBLIC MEMBERS: these are used by machine-independent code.
32959adf08eSdyoung 	 */
33059adf08eSdyoung 	bus_size_t	dm_maxsegsz;	/* largest possible segment */
33159adf08eSdyoung 	bus_size_t	dm_mapsize;	/* size of the mapping */
33259adf08eSdyoung 	int		dm_nsegs;	/* # valid segments in mapping */
33359adf08eSdyoung 	bus_dma_segment_t dm_segs[1];	/* segments; variable length */
33459adf08eSdyoung };
33559adf08eSdyoung 
33659adf08eSdyoung #endif /* _SPARC_BUS_DEFS_H_ */
337