xref: /netbsd/sys/arch/x68k/dev/intiovar.h (revision 5fbbc8cb)
1 /*	$NetBSD: intiovar.h,v 1.15 2019/12/15 16:48:26 tsutsui Exp $	*/
2 
3 /*
4  *
5  * Copyright (c) 1998 NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 /*
31  * NetBSD/x68k internal I/O virtual bus.
32  */
33 
34 #ifndef _INTIOVAR_H_
35 #define _INTIOVAR_H_
36 
37 #include <machine/frame.h>
38 #include <sys/malloc.h>
39 #include <sys/extent.h>
40 #include "locators.h"
41 
42 #define cf_addr		cf_loc[INTIOCF_ADDR]
43 #define cf_intr		cf_loc[INTIOCF_INTR]
44 #define cf_dma		cf_loc[INTIOCF_DMA]
45 #define cf_dmaintr	cf_loc[INTIOCF_DMAINTR]
46 
47 
48 struct intio_attach_args {
49 	bus_space_tag_t	ia_bst;	/* bus_space tag */
50 	bus_dma_tag_t	ia_dmat; /* bus_dma tag */
51 
52 	const char	*ia_name; /* device name */
53 	int		ia_addr; /* addr */
54 	int		ia_size;
55 	int		ia_intr; /* interrupt vector */
56 	int		ia_dma;	/* dma channel */
57 	int		ia_dmaintr; /* interrupt vector for dmac */
58 };
59 
60 struct intio_softc {
61 	bus_space_tag_t	sc_bst;
62 	bus_dma_tag_t	sc_dmat;
63 	struct extent	*sc_map;
64 	device_t	sc_dmac;
65 };
66 
67 enum intio_map_flag {
68 	INTIO_MAP_ALLOCATE = 0,
69 	INTIO_MAP_TESTONLY = 1
70 };
71 int intio_map_allocate_region(device_t, struct intio_attach_args *,
72 	enum intio_map_flag);
73 int intio_map_free_region(device_t, struct intio_attach_args *);
74 
75 typedef int (*intio_intr_handler_t)(void *);
76 
77 int intio_intr_establish(int, const char *, intio_intr_handler_t, void *);
78 int intio_intr_establish_ext(int, const char *, const char *,
79 	intio_intr_handler_t, void *);
80 int intio_intr_disestablish(int, void *);
81 int intio_intr(struct frame *);
82 
83 
84 #define INTIO_SYSPORT		(0x00e8e000)
85 #define intio_sysport		((volatile uint8_t *)IIOV(INTIO_SYSPORT))
86 #define sysport_contrast	1
87 #define sysport_tvctrl		3
88 #define sysport_imageunit	5
89 #define sysport_keyctrl		7
90 #define sysport_waitctrl	9
91 #define sysport_mpustat		11
92 #define sysport_sramwp		13
93 #define sysport_powoff		15
94 
95 #define intio_set_sysport_contrast(a) \
96 	intio_sysport[sysport_contrast] = (a) /* 0-15 */
97 #define intio_set_sysport_tvctrl(a) \
98 	intio_sysport[sysport_tvctrl] = (a)
99 #define INTIO_SYSPORT_TVCTRL	0x08
100 #define intio_set_sysport_imageunit(a) \
101 	intio_sysport[sysport_imageunit] = (a)
102 #define intio_set_sysport_keyctrl(a) \
103 	intio_sysport[sysport_keyctrl] = (a)
104 #define INTIO_SYSPORT_KBENABLE	0x08
105 #define intio_set_sysport_waitctrl(a) \
106 	intio_sysport[sysport_waitctrl] = (a) /* X68030 only */
107 #define intio_set_sysport_sramwp(a) \
108 	intio_sysport[sysport_sramwp] = (a)
109 #define INTIO_SYSPORT_SRAMWP	0x31
110 #define intio_set_sysport_powoff(a) \
111 	intio_sysport[sysport_powoff] = (a)
112 
113 #define intio_get_sysport_contrast() \
114 	(intio_sysport[sysport_contrast])
115 #define intio_get_sysport_tvctrl() \
116 	(intio_sysport[sysport_tvctrl])
117 #define INTIO_SYSPORT_TVSTAT	0x08
118 #define intio_get_sysport_keyctrl() \
119 	(intio_sysport[sysport_keyctrl])
120 #define INTIO_SYSPORT_KBEXIST	0x08
121 #define intio_get_sysport_waitctrl() \
122 	(intio_sysport[sysport_waitctrl])
123 #define intio_get_sysport_sramwp() \
124 	(intio_sysport[sysport_sramwp])
125 #define intio_get_sysport_mpustat() \
126 	(intio_sysport[sysport_mpustat])
127 
128 /* I/O controller (sicilian/pluto) */
129 #define INTIO_SICILIAN		(0x00e9c000)
130 #define intio_sicilian		((volatile uint8_t *)IIOV(INTIO_SICILIAN))
131 #define sicilian_intr		1
132 #define sicilian_ivec		3
133 
134 #define intio_get_sicilian_intr() \
135 	(intio_sicilian[sicilian_intr])
136 #define intio_set_sicilian_intr(a) \
137 	intio_sicilian[sicilian_intr] = (a)
138 #define SICILIAN_INTR_PAR 0x01
139 #define SICILIAN_INTR_FDD 0x02
140 #define SICILIAN_INTR_FDC 0x04
141 #define SICILIAN_INTR_HDD 0x08
142 #define SICILIAN_STAT_HDD 0x10
143 #define SICILIAN_STAT_PAR 0x20
144 #define SICILIAN_STAT_FDD 0x40
145 #define SICILIAN_STAT_FDC 0x80
146 
147 #define intio_enable_intr(a) \
148 	intio_sicilian[sicilian_intr] = ((a) | intio_sicilian[sicilian_intr])
149 #define intio_disable_intr(a) \
150 	intio_sicilian[sicilian_intr] = (~(a) & intio_sicilian[sicilian_intr])
151 
152 #define intio_set_sicilian_ivec(a) \
153 	intio_sicilian[sicilian_ivec] = (a)
154 void intio_set_ivec(int);
155 
156 struct intio_dma_cookie {
157 	int	id_flags;		/* flags; see below */
158 
159 	/*
160 	 * Information about the original buffer used during
161 	 * DMA map syncs.  Note that origibuflen is only used
162 	 * for ID_BUFTYPE_LINEAR.
163 	 */
164 	void	*id_origbuf;		/* pointer to orig buffer if
165 					   bouncing */
166 	bus_size_t id_origbuflen;	/* ...and size */
167 	int	id_buftype;		/* type of buffer */
168 
169 	void	*id_bouncebuf;		/* pointer to the bounce buffer */
170 	bus_size_t id_bouncebuflen;	/* ...and size */
171 	int	id_nbouncesegs;		/* number of valid bounce segs */
172 	bus_dma_segment_t id_bouncesegs[0]; /* array of bounce buffer
173 					       physical memory segments */
174 };
175 
176 /* id_flags */
177 #define	ID_MIGHT_NEED_BOUNCE	0x01	/* map could need bounce buffers */
178 #define	ID_HAS_BOUNCE		0x02	/* map currently has bounce buffers */
179 #define	ID_IS_BOUNCING		0x04	/* map is bouncing current xfer */
180 
181 /* id_buftype */
182 #define	ID_BUFTYPE_INVALID	0
183 #define	ID_BUFTYPE_LINEAR	1
184 #define	ID_BUFTYPE_MBUF		2
185 #define	ID_BUFTYPE_UIO		3
186 #define	ID_BUFTYPE_RAW		4
187 
188 #endif
189