]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/ppc/IODBDMA.h
xnu-344.49.tar.gz
[apple/xnu.git] / iokit / IOKit / ppc / IODBDMA.h
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * Copyright (c) 1997 Apple Computer, Inc.
27 *
28 *
29 * HISTORY
30 *
31 * Simon Douglas 10 Nov 97
32 * - first checked in, mostly from MacOS DBDMA.i, machdep/ppc/dbdma.h
33 * but use byte reverse ops.
34 */
35
36 #ifndef _IODBDMA_H_
37 #define _IODBDMA_H_
38
39 #include <IOKit/IOTypes.h>
40 #include <libkern/OSByteOrder.h>
41
42
43 /* DBDMA definitions */
44
45 struct IODBDMAChannelRegisters {
46 volatile unsigned long channelControl;
47 volatile unsigned long channelStatus;
48 volatile unsigned long commandPtrHi; /* implementation optional*/
49 volatile unsigned long commandPtrLo;
50 volatile unsigned long interruptSelect; /* implementation optional*/
51 volatile unsigned long branchSelect; /* implementation optional*/
52 volatile unsigned long waitSelect; /* implementation optional*/
53 volatile unsigned long transferModes; /* implementation optional*/
54 volatile unsigned long data2PtrHi; /* implementation optional*/
55 volatile unsigned long data2PtrLo; /* implementation optional*/
56
57 volatile unsigned long reserved1;
58 volatile unsigned long addressHi; /* implementation optional*/
59 volatile unsigned long reserved2[4];
60 volatile unsigned long unimplemented[16];
61
62 /* This structure must remain fully padded to 256 bytes.*/
63 volatile unsigned long undefined[32];
64 };
65 typedef struct IODBDMAChannelRegisters IODBDMAChannelRegisters;
66
67 /* These constants define the DB-DMA channel control words and status flags.*/
68
69 enum {
70 kdbdmaRun = 0x00008000,
71 kdbdmaPause = 0x00004000,
72 kdbdmaFlush = 0x00002000,
73 kdbdmaWake = 0x00001000,
74 kdbdmaDead = 0x00000800,
75 kdbdmaActive = 0x00000400,
76 kdbdmaBt = 0x00000100,
77 kdbdmaS7 = 0x00000080,
78 kdbdmaS6 = 0x00000040,
79 kdbdmaS5 = 0x00000020,
80 kdbdmaS4 = 0x00000010,
81 kdbdmaS3 = 0x00000008,
82 kdbdmaS2 = 0x00000004,
83 kdbdmaS1 = 0x00000002,
84 kdbdmaS0 = 0x00000001
85 };
86
87
88 #define IOSetDBDMAChannelControlBits(mask) ( ((mask) | (mask) << 16) )
89 #define IOClearDBDMAChannelControlBits(mask) ( (mask) << 16)
90
91
92 /* This structure defines the DB-DMA channel command descriptor.*/
93
94 /*
95 *** WARNING: Endian-ness issues must be considered when performing load/store! ***
96 */
97
98 struct IODBDMADescriptor {
99 unsigned long operation; /* cmd || key || i || b || w || reqCount*/
100 unsigned long address;
101 volatile unsigned long cmdDep;
102 volatile unsigned long result; /* xferStatus || resCount*/
103 };
104 typedef struct IODBDMADescriptor IODBDMADescriptor;
105
106 /* These constants define the DB-DMA channel command operations and modifiers.*/
107
108
109 enum {
110 /* Command.cmd operations*/
111 kdbdmaOutputMore = 0,
112 kdbdmaOutputLast = 1,
113 kdbdmaInputMore = 2,
114 kdbdmaInputLast = 3,
115 kdbdmaStoreQuad = 4,
116 kdbdmaLoadQuad = 5,
117 kdbdmaNop = 6,
118 kdbdmaStop = 7,
119 };
120
121
122 enum {
123 /* Command.key modifiers (choose one for INPUT, OUTPUT, LOAD, and STORE)*/
124 kdbdmaKeyStream0 = 0, /* default modifier*/
125 kdbdmaKeyStream1 = 1,
126 kdbdmaKeyStream2 = 2,
127 kdbdmaKeyStream3 = 3,
128 kdbdmaKeyRegs = 5,
129 kdbdmaKeySystem = 6,
130 kdbdmaKeyDevice = 7,
131
132 kdbdmaIntNever = 0, /* default modifier*/
133 kdbdmaIntIfTrue = 1,
134 kdbdmaIntIfFalse = 2,
135 kdbdmaIntAlways = 3,
136
137 kdbdmaBranchNever = 0, /* default modifier*/
138 kdbdmaBranchIfTrue = 1,
139 kdbdmaBranchIfFalse = 2,
140 kdbdmaBranchAlways = 3,
141
142 kdbdmaWaitNever = 0, /* default modifier*/
143 kdbdmaWaitIfTrue = 1,
144 kdbdmaWaitIfFalse = 2,
145 kdbdmaWaitAlways = 3,
146
147 kdbdmaCommandMask = (long)0xFFFF0000,
148 kdbdmaReqCountMask = 0x0000FFFF
149 };
150
151
152 /* These constants define the DB-DMA channel command results.*/
153
154 enum {
155 /* result masks*/
156 kdbdmaStatusRun = kdbdmaRun << 16,
157 kdbdmaStatusPause = kdbdmaPause << 16,
158 kdbdmaStatusFlush = kdbdmaFlush << 16,
159 kdbdmaStatusWake = kdbdmaWake << 16,
160 kdbdmaStatusDead = kdbdmaDead << 16,
161 kdbdmaStatusActive = kdbdmaActive << 16,
162 kdbdmaStatusBt = kdbdmaBt << 16,
163 kdbdmaStatusS7 = kdbdmaS7 << 16,
164 kdbdmaStatusS6 = kdbdmaS6 << 16,
165 kdbdmaStatusS5 = kdbdmaS5 << 16,
166 kdbdmaStatusS4 = kdbdmaS4 << 16,
167 kdbdmaStatusS3 = kdbdmaS3 << 16,
168 kdbdmaStatusS2 = kdbdmaS2 << 16,
169 kdbdmaStatusS1 = kdbdmaS1 << 16,
170 kdbdmaStatusS0 = kdbdmaS0 << 16,
171 kdbdmaResCountMask = 0x0000FFFF,
172 kdbdmaXferStatusMask = 0xFFFF0000
173 };
174
175
176 /* These macros are are IODBDMAChannelRegisters accessor functions. */
177
178 #define IOSetDBDMAChannelRegister(registerSetPtr,field,value) \
179 OSWriteSwapInt32(registerSetPtr,offsetof(IODBDMAChannelRegisters,field),value)
180
181 #define IOGetDBDMAChannelRegister(registerSetPtr, field) \
182 OSReadSwapInt32(registerSetPtr,offsetof(IODBDMAChannelRegisters, field))
183
184
185 /* void IOSetDBDMAChannelControl (IODBDMAChannelRegisters *registerSetPtr, unsigned long ctlValue); */
186
187 #define IOSetDBDMAChannelControl(registerSetPtr,ctlValue) \
188 do { \
189 eieio(); \
190 IOSetDBDMAChannelRegister(registerSetPtr,channelControl,ctlValue); \
191 eieio(); \
192 } while(0)
193
194 /* unsigned long IOGetDBDMAChannelStatus (IODBDMAChannelRegisters *registerSetPtr); */
195
196 #define IOGetDBDMAChannelStatus(registerSetPtr) \
197 IOGetDBDMAChannelRegister(registerSetPtr,channelStatus)
198
199 /* unsigned long IOGetDBDMACommandPtr (IODBDMAChannelRegisters *registerSetPtr); */
200
201 #define IOGetDBDMACommandPtr(registerSetPtr) \
202 IOGetDBDMAChannelRegister(registerSetPtr,commandPtrLo)
203
204 /* void IOSetDBDMACommandPtr (IODBDMAChannelRegisters *registerSetPtr, unsigned long cclPtr); */
205
206 #define IOSetDBDMACommandPtr(registerSetPtr,cclPtr) \
207 do { \
208 IOSetDBDMAChannelRegister(registerSetPtr,commandPtrHi,0); \
209 eieio(); \
210 IOSetDBDMAChannelRegister(registerSetPtr,commandPtrLo,cclPtr); \
211 eieio(); \
212 } while(0)
213
214
215 /* unsigned long IOGetDBDMAInterruptSelect (IODBDMAChannelRegisters *registerSetPtr); */
216
217 #define IOGetDBDMAInterruptSelect(registerSetPtr) \
218 IOGetDBDMAChannelRegister(registerSetPtr,interruptSelect)
219
220 /* void IOSetDBDMAInterruptSelect (IODBDMAChannelRegisters *registerSetPtr, unsigned long intSelValue); */
221
222 #define IOSetDBDMAInterruptSelect(registerSetPtr,intSelValue) \
223 do { \
224 IOSetDBDMAChannelRegister(registerSetPtr,interruptSelect,intSelValue); \
225 eieio(); \
226 } while(0)
227
228 /* unsigned long IOGetDBDMABranchSelect (IODBDMAChannelRegisters *registerSetPtr); */
229
230 #define IOGetDBDMABranchSelect(registerSetPtr) \
231 IOGetDBDMAChannelRegister(registerSetPtr,branchSelect)
232
233 /* void IOSetDBDMABranchSelect (IODBDMAChannelRegisters *registerSetPtr, unsigned long braSelValue); */
234
235 #define IOSetDBDMABranchSelect(registerSetPtr,braSelValue) \
236 do { \
237 IOSetDBDMAChannelRegister(registerSetPtr,branchSelect,braSelValue); \
238 eieio(); \
239 } while(0)
240
241 /* unsigned long IOGetDBDMAWaitSelect (IODBDMAChannelRegisters *registerSetPtr); */
242
243 #define IOGetDBDMAWaitSelect(registerSetPtr) \
244 IOGetDBDMAChannelRegister(registerSetPtr,waitSelect)
245
246 /* void IOSetDBDMAWaitSelect (IODBDMAChannelRegisters *registerSetPtr, unsigned long waitSelValue); */
247
248 #define IOSetDBDMAWaitSelect(registerSetPtr,waitSelValue) \
249 do { \
250 IOSetDBDMAChannelRegister(registerSetPtr,waitSelect,waitSelValue); \
251 eieio(); \
252 } while(0)
253
254
255 /* These macros are IODBDMADescriptor accessor functions. */
256
257 #define IOSetDBDMADescriptor(descPtr,field,value) \
258 OSWriteSwapInt32( descPtr, offsetof( IODBDMADescriptor, field), value)
259
260 #define IOGetDBDMADescriptor(descPtr,field) \
261 OSReadSwapInt32( descPtr, offsetof( IODBDMADescriptor, field))
262
263 #define IOMakeDBDMAOperation(cmd,key,interrupt,branch,wait,count) \
264 ( ((cmd) << 28) | ((key) << 24) | ((interrupt) << 20) \
265 | ((branch) << 18) | ( (wait) << 16) | (count) )
266
267 /* void IOMakeDBDMADescriptor (IODBDMADescriptor *descPtr,
268 unsigned long cmd,
269 unsigned long key,
270 unsigned long interrupt,
271 unsigned long branch,
272 unsigned long wait,
273 unsigned long count,
274 unsigned long addr); */
275
276 #define IOMakeDBDMADescriptor(descPtr,cmd,key,interrupt,branch,wait,count,addr)\
277 do { \
278 IOSetDBDMADescriptor(descPtr, address, addr); \
279 IOSetDBDMADescriptor(descPtr, cmdDep, 0); \
280 IOSetDBDMADescriptor(descPtr, result, 0); \
281 eieio(); \
282 IOSetDBDMADescriptor(descPtr, operation, \
283 IOMakeDBDMAOperation(cmd,key,interrupt,branch,wait,count)); \
284 eieio(); \
285 } while(0)
286
287 /* void IOMakeDBDMADescriptorDep (IODBDMADescriptor *descPtr,
288 unsigned long cmd,
289 unsigned long key,
290 unsigned long interrupt,
291 unsigned long branch,
292 unsigned long wait,
293 unsigned long count,
294 unsigned long addr,
295 unsigned long dep); */
296
297 #define IOMakeDBDMADescriptorDep(descPtr,cmd,key,interrupt,branch,wait,count,addr,dep) \
298 do { \
299 IOSetDBDMADescriptor(descPtr, address, addr); \
300 IOSetDBDMADescriptor(descPtr, cmdDep, dep); \
301 IOSetDBDMADescriptor(descPtr, result, 0); \
302 eieio(); \
303 IOSetDBDMADescriptor(descPtr, operation, \
304 IOMakeDBDMAOperation(cmd, key, interrupt, branch, wait, count)); \
305 eieio(); \
306 } while(0)
307
308 /* Field accessors - NOTE: unsynchronized */
309
310 /* unsigned long IOGetDBDMAOperation (IODBDMADescriptor *descPtr) */
311
312 #define IOGetCCOperation(descPtr) \
313 IOGetDBDMADescriptor(descPtr,operation)
314
315 /* void IOSetCCOperation (IODBDMADescriptor *descPtr, unsigned long operationValue) */
316
317 #define IOSetCCOperation(descPtr,operationValue) \
318 IOSetDBDMADescriptor(descPtr,operation,operationValue)
319
320 /* unsigned long IOGetCCAddress (IODBDMADescriptor *descPtr) */
321
322 #define IOGetCCAddress(descPtr) \
323 IOGetDBDMADescriptor(descPtr,address)
324
325 /* void IOSetCCAddress (IODBDMADescriptor *descPtr, unsigned long addressValue) */
326
327 #define IOSetCCAddress(descPtr,addressValue) \
328 IOSetDBDMADescriptor(descPtr,address, addressValue)
329
330 /* unsigned long IOGetCCCmdDep (IODBDMADescriptor *descPtr) */
331
332 #define IOGetCCCmdDep(descPtr) \
333 IOGetDBDMADescriptor(descPtr,cmdDep)
334
335 /* void IOSetCCCmdDep (IODBDMADescriptor *descPtr, unsigned long cmdDepValue) */
336
337 #define IOSetCCCmdDep(descPtr,cmdDepValue) \
338 IOSetDBDMADescriptor(descPtr,cmdDep,cmdDepValue)
339
340 /* unsigned long IOGetCCResult (IODBDMADescriptor *descPtr) */
341
342 #define IOGetCCResult(descPtr) \
343 IOGetDBDMADescriptor(descPtr,result)
344
345 /* void IOSetCCResult (IODBDMADescriptor *descPtr, unsigned long resultValue) */
346
347 #define IOSetCCResult(descPtr,resultValue) \
348 IOSetDBDMADescriptor(descPtr,result,resultValue)
349
350
351 /* DBDMA routines */
352
353 extern void IODBDMAStart( volatile IODBDMAChannelRegisters *registerSetPtr, volatile IODBDMADescriptor *physicalDescPtr);
354 extern void IODBDMAStop( volatile IODBDMAChannelRegisters *registerSetPtr);
355 extern void IODBDMAFlush( volatile IODBDMAChannelRegisters *registerSetPtr);
356 extern void IODBDMAReset( volatile IODBDMAChannelRegisters *registerSetPtr);
357 extern void IODBDMAContinue( volatile IODBDMAChannelRegisters *registerSetPtr);
358 extern void IODBDMAPause( volatile IODBDMAChannelRegisters *registerSetPtr);
359
360 extern IOReturn IOAllocatePhysicallyContiguousMemory( unsigned int size, unsigned int options,
361 IOVirtualAddress * logical, IOPhysicalAddress * physical );
362 extern IOReturn IOFreePhysicallyContiguousMemory( IOVirtualAddress * logical, unsigned int size);
363
364 #endif /* !defined(_IODBDMA_H_) */