summaryrefslogtreecommitdiff
path: root/sys/arch/alpha/include/bus.h
blob: 61cd8cbcbe52ed2f468bfc132c17aecdd5d00b40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*	$OpenBSD: bus.h,v 1.2 1996/07/29 22:58:29 niklas Exp $	*/
/*	$NetBSD: bus.h,v 1.2.4.2 1996/06/13 17:44:45 cgd Exp $	*/

/*
 * Copyright (c) 1996 Carnegie-Mellon University.
 * All rights reserved.
 *
 * Author: Chris G. Demetriou
 *
 * Permission to use, copy, modify and distribute this software and
 * its documentation is hereby granted, provided that both the copyright
 * notice and this permission notice appear in all copies of the
 * software, derivative works or modified versions, and any portions
 * thereof, and that both notices appear in supporting documentation.
 *
 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
 * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
 *
 * Carnegie Mellon requests users of this software to return to
 *
 *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
 *  School of Computer Science
 *  Carnegie Mellon University
 *  Pittsburgh PA 15213-3890
 *
 * any improvements or extensions that they make and grant Carnegie the
 * rights to redistribute these changes.
 */

#ifndef _ALPHA_BUS_H_
#define _ALPHA_BUS_H_

/*
 * I/O addresses (in bus space)
 */
typedef u_long bus_io_addr_t;
typedef u_long bus_io_size_t;

/*
 * Memory addresses (in bus space)
 */
typedef u_long bus_mem_addr_t;
typedef u_long bus_mem_size_t;

/*
 * Access methods for bus resources, I/O space, and memory space.
 */
typedef struct alpha_bus_chipset *bus_chipset_tag_t;
typedef u_long bus_io_handle_t;
typedef u_long bus_mem_handle_t;

struct alpha_bus_chipset {
	/* I/O-space cookie */
	void		*bc_i_v;

	/* I/O-space control functions */
	int		(*bc_i_map) __P((void *v, bus_io_addr_t port,
			    bus_io_size_t size, bus_io_handle_t *iohp));
	void		(*bc_i_unmap) __P((void *v, bus_io_handle_t ioh,
			    bus_io_size_t size));
	int		(*bc_i_subregion) __P((void *v, bus_io_handle_t ioh,
			    bus_io_size_t offset, bus_io_size_t size,
			    bus_io_handle_t *nioh));

	/* I/O-space read functions */
	u_int8_t	(*bc_ir1) __P((void *v, bus_io_handle_t ioh,
			    bus_io_size_t off));
	u_int16_t	(*bc_ir2) __P((void *v, bus_io_handle_t ioh,
			    bus_io_size_t off));
	u_int32_t	(*bc_ir4) __P((void *v, bus_io_handle_t ioh,
			    bus_io_size_t off));
	u_int64_t	(*bc_ir8) __P((void *v, bus_io_handle_t ioh,
			    bus_io_size_t off));

	/* I/O-space read-multiple functions */
	void		(*bc_irm1) __P((void *v, bus_io_handle_t ioh,
			    bus_io_size_t off, u_int8_t *addr,
			    bus_io_size_t count));
	void		(*bc_irm2) __P((void *v, bus_io_handle_t ioh,
			    bus_io_size_t off, u_int16_t *addr,
			    bus_io_size_t count));
	void		(*bc_irm4) __P((void *v, bus_io_handle_t ioh,
			    bus_io_size_t off, u_int32_t *addr,
			    bus_io_size_t count));
	void		(*bc_irm8) __P((void *v, bus_io_handle_t ioh,
			    bus_io_size_t off, u_int64_t *addr,
			    bus_io_size_t count));

	/* I/O-space write functions */
	void		(*bc_iw1) __P((void *v, bus_io_handle_t ioh,
			    bus_io_size_t off, u_int8_t val));
	void		(*bc_iw2) __P((void *v, bus_io_handle_t ioh,
			    bus_io_size_t off, u_int16_t val));
	void		(*bc_iw4) __P((void *v, bus_io_handle_t ioh,
			    bus_io_size_t off, u_int32_t val));
	void		(*bc_iw8) __P((void *v, bus_io_handle_t ioh,
			    bus_io_size_t off, u_int64_t val));

	/* I/O-space write-multiple functions */
	void		(*bc_iwm1) __P((void *v, bus_io_handle_t ioh,
			    bus_io_size_t off, const u_int8_t *addr,
			    bus_io_size_t count));
	void		(*bc_iwm2) __P((void *v, bus_io_handle_t ioh,
			    bus_io_size_t off, const u_int16_t *addr,
			    bus_io_size_t count));
	void		(*bc_iwm4) __P((void *v, bus_io_handle_t ioh,
			    bus_io_size_t off, const u_int32_t *addr,
			    bus_io_size_t count));
	void		(*bc_iwm8) __P((void *v, bus_io_handle_t ioh,
			    bus_io_size_t off, const u_int64_t *addr,
			    bus_io_size_t count));

	/* Mem-space cookie */
	void		*bc_m_v;

	/* Mem-space control functions */
	int		(*bc_m_map) __P((void *v, bus_mem_addr_t buspa,
			    bus_mem_size_t size, int cacheable,
			    bus_mem_handle_t *mhp));
	void		(*bc_m_unmap) __P((void *v, bus_mem_handle_t mh,
			    bus_mem_size_t size));
	int		(*bc_m_subregion) __P((void *v, bus_mem_handle_t memh,
			    bus_mem_size_t offset, bus_mem_size_t size,
			    bus_mem_handle_t *nmemh));

	/* Mem-space read functions */
	u_int8_t	(*bc_mr1) __P((void *v, bus_mem_handle_t memh,
			    bus_mem_size_t off));
	u_int16_t	(*bc_mr2) __P((void *v, bus_mem_handle_t memh,
			    bus_mem_size_t off));
	u_int32_t	(*bc_mr4) __P((void *v, bus_mem_handle_t memh,
			    bus_mem_size_t off));
	u_int64_t	(*bc_mr8) __P((void *v, bus_mem_handle_t memh,
			    bus_mem_size_t off));

	/* Mem-space write functions */
	void		(*bc_mw1) __P((void *v, bus_mem_handle_t memh,
			    bus_mem_size_t off, u_int8_t val));
	void		(*bc_mw2) __P((void *v, bus_mem_handle_t memh,
			    bus_mem_size_t off, u_int16_t val));
	void		(*bc_mw4) __P((void *v, bus_mem_handle_t memh,
			    bus_mem_size_t off, u_int32_t val));
	void		(*bc_mw8) __P((void *v, bus_mem_handle_t memh,
			    bus_mem_size_t off, u_int64_t val));

	/* XXX THIS DOES NOT YET BELONG HERE */
	vm_offset_t	(*bc_XXX_dmamap) __P((void *addr));
};

#define __bc_CONCAT(A,B)	__CONCAT(A,B)
#define __bc_ABC(A,B,C)		__bc_CONCAT(A,__bc_CONCAT(B,C))
#define __bc_ABCD(A,B,C,D)	__bc_CONCAT(__bc_ABC(A,B,C),D)

#define __bc_rd(t, h, o, sz, sp)					\
    (*(t)->__bc_ABCD(bc_,sp,r,sz))((t)->__bc_ABC(bc_,sp,_v), h, o)

#define __bc_wr(t, h, o, v, sz, sp)					\
    (*(t)->__bc_ABCD(bc_,sp,w,sz))((t)->__bc_ABC(bc_,sp,_v), h, o, v)

#define bus_io_map(t, port, size, iohp)					\
    (*(t)->bc_i_map)((t)->bc_i_v, (port), (size), (iohp))
#define bus_io_unmap(t, ioh, size)					\
    (*(t)->bc_i_unmap)((t)->bc_i_v, (ioh), (size))
#define bus_io_subregion(t, ioh, offset, size, nioh)			\
    (*(t)->bc_i_unmap)((t)->bc_i_v, (ioh), (offset), (size), (nioh))

#define	__bc_io_multi(t, h, o, a, s, dir, sz)				\
    (*(t)->__bc_ABCD(bc_i,dir,m,sz))((t)->bc_i_v, h, o, a, s)

#define	bus_io_read_1(t, h, o)		__bc_rd((t),(h),(o),1,i)
#define	bus_io_read_2(t, h, o)		__bc_rd((t),(h),(o),2,i)
#define	bus_io_read_4(t, h, o)		__bc_rd((t),(h),(o),4,i)
#define	bus_io_read_8(t, h, o)		__bc_rd((t),(h),(o),8,i)

#define	bus_io_read_multi_1(t, h, o, a, s)				\
    __bc_io_multi((t),(h),(o),(a),(s),r,1)
#define	bus_io_read_multi_2(t, h, o, a, s)				\
    __bc_io_multi((t),(h),(o),(a),(s),r,2)
#define	bus_io_read_multi_4(t, h, o, a, s)				\
    __bc_io_multi((t),(h),(o),(a),(s),r,4)
#define	bus_io_read_multi_8(t, h, o, a, s)				\
    __bc_io_multi((t),(h),(o),(a),(s),r,8)

#define	bus_io_write_1(t, h, o, v)	__bc_wr((t),(h),(o),(v),1,i)
#define	bus_io_write_2(t, h, o, v)	__bc_wr((t),(h),(o),(v),2,i)
#define	bus_io_write_4(t, h, o, v)	__bc_wr((t),(h),(o),(v),4,i)
#define	bus_io_write_8(t, h, o, v)	__bc_wr((t),(h),(o),(v),8,i)

#define	bus_io_write_multi_1(t, h, o, a, s)				\
    __bc_io_multi((t),(h),(o),(a),(s),w,1)
#define	bus_io_write_multi_2(t, h, o, a, s)				\
    __bc_io_multi((t),(h),(o),(a),(s),w,2)
#define	bus_io_write_multi_4(t, h, o, a, s)				\
    __bc_io_multi((t),(h),(o),(a),(s),w,4)
#define	bus_io_write_multi_8(t, h, o, a, s)				\
    __bc_io_multi((t),(h),(o),(a),(s),w,8)

#define bus_mem_map(t, bpa, size, cacheable, mhp)			\
    (*(t)->bc_m_map)((t)->bc_m_v, (bpa), (size), (cacheable), (mhp))
#define bus_mem_unmap(t, memh, size)					\
    (*(t)->bc_m_unmap)((t)->bc_m_v, (memh), (size))
#define bus_mem_subregion(t, memh, offset, size, nmemh)			\
    (*(t)->bc_m_unmap)((t)->bc_i_v, (memh), (offset), (size), (nmemh))

#define	bus_mem_read_1(t, h, o)		__bc_rd((t),(h),(o),1,m)
#define	bus_mem_read_2(t, h, o)		__bc_rd((t),(h),(o),2,m)
#define	bus_mem_read_4(t, h, o)		__bc_rd((t),(h),(o),4,m)
#define	bus_mem_read_8(t, h, o)		__bc_rd((t),(h),(o),8,m)

#define	bus_mem_write_1(t, h, o, v)	__bc_wr((t),(h),(o),(v),1,m)
#define	bus_mem_write_2(t, h, o, v)	__bc_wr((t),(h),(o),(v),2,m)
#define	bus_mem_write_4(t, h, o, v)	__bc_wr((t),(h),(o),(v),4,m)
#define	bus_mem_write_8(t, h, o, v)	__bc_wr((t),(h),(o),(v),8,m)

/* XXX THIS DOES NOT BELONG HERE YET. */
#define	__alpha_bus_XXX_dmamap(t, va) (*(t)->bc_XXX_dmamap)((va))

#endif /* _ALPHA_BUS_H_ */