dbdma.h revision 1.1 1 /*
2 * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991
3 * All Rights Reserved
4 *
5 * Permission to use, copy, modify, and distribute this software and
6 * its documentation for any purpose and without fee is hereby granted,
7 * provided that the above copyright notice appears in all copies and
8 * that both the copyright notice and this permission notice appear in
9 * supporting documentation.
10 *
11 * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
12 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13 * FOR A PARTICULAR PURPOSE.
14 *
15 * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
16 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
18 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
19 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 *
21 */
22
23 #ifndef _POWERMAC_DBDMA_H_
24 #define _POWERMAC_DBDMA_H_
25
26 #define DBDMA_CMD_OUT_MORE 0
27 #define DBDMA_CMD_OUT_LAST 1
28 #define DBDMA_CMD_IN_MORE 2
29 #define DBDMA_CMD_IN_LAST 3
30 #define DBDMA_CMD_STORE_QUAD 4
31 #define DBDMA_CMD_LOAD_QUAD 5
32 #define DBDMA_CMD_NOP 6
33 #define DBDMA_CMD_STOP 7
34
35 /* Keys */
36
37 #define DBDMA_KEY_STREAM0 0
38 #define DBDMA_KEY_STREAM1 1
39 #define DBDMA_KEY_STREAM2 2
40 #define DBDMA_KEY_STREAM3 3
41
42 /* value 4 is reserved */
43 #define DBDMA_KEY_REGS 5
44 #define DBDMA_KEY_SYSTEM 6
45 #define DBDMA_KEY_DEVICE 7
46
47 #define DBDMA_INT_NEVER 0
48 #define DBDMA_INT_IF_TRUE 1
49 #define DBDMA_INT_IF_FALSE 2
50 #define DBDMA_INT_ALWAYS 3
51
52 #define DBDMA_BRANCH_NEVER 0
53 #define DBDMA_BRANCH_IF_TRUE 1
54 #define DBDMA_BRANCH_IF_FALSE 2
55 #define DBDMA_BRANCH_ALWAYS 3
56
57 #define DBDMA_WAIT_NEVER 0
58 #define DBDMA_WAIT_IF_TRUE 1
59 #define DBDMA_WAIT_IF_FALSE 2
60 #define DBDMA_WAIT_ALWAYS 3
61
62
63 /* Channels */
64
65 #define DBDMA_SCSI0 0x0
66 #define DBDMA_CURIO_SCSI DBDMA_SCSI0
67 #define DBDMA_FLOPPY 0x1
68 #define DBDMA_ETHERNET_TX 0x2
69 #define DBDMA_ETHERNET_RV 0x3
70 #define DBDMA_SCC_XMIT_A 0x4
71 #define DBDMA_SCC_RECV_A 0x5
72 #define DBDMA_SCC_XMIT_B 0x6
73 #define DBDMA_SCC_RECV_B 0x7
74 #define DBDMA_AUDIO_OUT 0x8
75 #define DBDMA_AUDIO_IN 0x9
76 #define DBDMA_SCSI1 0xA
77
78 /* Control register values (in little endian) */
79
80 #define DBDMA_STATUS_MASK 0x000000ff /* Status Mask */
81 #define DBDMA_CNTRL_BRANCH 0x00000100
82 /* 0x200 reserved */
83 #define DBDMA_CNTRL_ACTIVE 0x00000400
84 #define DBDMA_CNTRL_DEAD 0x00000800
85 #define DBDMA_CNTRL_WAKE 0x00001000
86 #define DBDMA_CNTRL_FLUSH 0x00002000
87 #define DBDMA_CNTRL_PAUSE 0x00004000
88 #define DBDMA_CNTRL_RUN 0x00008000
89
90 #define DBDMA_SET_CNTRL(x) ( ((x) | (x) << 16) )
91 #define DBDMA_CLEAR_CNTRL(x) ( (x) << 16)
92
93
94 #define DBDMA_REGMAP(channel) \
95 (dbdma_regmap_t *)((v_u_char *) POWERMAC_IO(PCI_DMA_BASE_PHYS) \
96 + (channel << 8))
97
98 /* This struct is layout in little endian format */
99
100 struct dbdma_command {
101 u_int16_t d_count;
102 u_int16_t d_command;
103 u_int32_t d_address;
104 u_int32_t d_cmddep;
105 u_int16_t d_resid;
106 u_int16_t d_status;
107 };
108
109 typedef struct dbdma_command dbdma_command_t;
110
111 #define DBDMA_BUILD_CMD(d, cmd, key, interrupt, wait, branch) { \
112 dbdma_st16(&(d)->d_command, \
113 ((cmd) << 12) | ((key) << 8) | \
114 ((interrupt) << 4) | \
115 ((branch) << 2) | (wait)); \
116 }
117
118 #define DBDMA_BUILD(d, cmd, key, count, address, interrupt, wait, branch) { \
119 dbdma_st16(&(d)->d_command, \
120 ((cmd) << 12) | ((key) << 8) | \
121 ((interrupt) << 4) | \
122 ((branch) << 2) | (wait)); \
123 dbdma_st16(&(d)->d_count, count); \
124 dbdma_st32(&(d)->d_address, address); \
125 (d)->d_resid = 0; \
126 (d)->d_status = 0; \
127 (d)->d_cmddep = 0; \
128 }
129
130 static __inline__ void
131 dbdma_st32(a, x)
132 volatile u_int32_t *a;
133 u_int32_t x;
134 {
135 __asm__ volatile
136 ("stwbrx %0,0,%1" : : "r" (x), "r" (a) : "memory");
137 }
138
139 static __inline__ void
140 dbdma_st16(a, x)
141 volatile u_int16_t *a;
142 u_int16_t x;
143 {
144 __asm__ volatile
145 ("sthbrx %0,0,%1" : : "r" (x), "r" (a) : "memory");
146 }
147
148 static __inline__ u_int32_t
149 dbdma_ld32(a)
150 volatile u_int32_t *a;
151 {
152 u_int32_t swap;
153
154 __asm__ volatile
155 ("lwbrx %0,0,%1" : "=r" (swap) : "r" (a));
156
157 return swap;
158 }
159
160 static __inline__ u_int16_t
161 dbdma_ld16(a)
162 volatile u_int16_t *a;
163 {
164 u_int16_t swap;
165
166 __asm__ volatile
167 ("lhbrx %0,0,%1" : "=r" (swap) : "r" (a));
168
169 return swap;
170 }
171
172 #define DBDMA_LD4_ENDIAN(a) dbdma_ld32(a)
173 #define DBDMA_ST4_ENDIAN(a, x) dbdma_st32(a, x)
174
175 /*
176 * DBDMA Channel layout
177 *
178 * NOTE - This structure is in little-endian format.
179 */
180
181 struct dbdma_regmap {
182 unsigned long d_control; /* Control Register */
183 unsigned long d_status; /* DBDMA Status Register */
184 unsigned long d_cmdptrhi; /* MSB of command pointer (not used yet) */
185 unsigned long d_cmdptrlo; /* LSB of command pointer */
186 unsigned long d_intselect; /* Interrupt Select */
187 unsigned long d_branch; /* Branch selection */
188 unsigned long d_wait; /* Wait selection */
189 unsigned long d_transmode; /* Transfer modes */
190 unsigned long d_dataptrhi; /* MSB of Data Pointer */
191 unsigned long d_dataptrlo; /* LSB of Data Pointer */
192 unsigned long d_reserved; /* Reserved for the moment */
193 unsigned long d_branchptrhi; /* MSB of Branch Pointer */
194 unsigned long d_branchptrlo; /* LSB of Branch Pointer */
195 /* The remaining fields are undefinied and unimplemented */
196 };
197
198 typedef volatile struct dbdma_regmap dbdma_regmap_t;
199
200 /* DBDMA routines */
201
202 void dbdma_start(dbdma_regmap_t *channel, dbdma_command_t *commands);
203 void dbdma_stop(dbdma_regmap_t *channel);
204 void dbdma_flush(dbdma_regmap_t *channel);
205 void dbdma_reset(dbdma_regmap_t *channel);
206 void dbdma_continue(dbdma_regmap_t *channel);
207 void dbdma_pause(dbdma_regmap_t *channel);
208
209 dbdma_command_t *dbdma_alloc(int); /* Allocate command structures */
210
211 #endif /* !defined(_POWERMAC_DBDMA_H_) */
212