2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * @APPLE_LICENSE_HEADER_END@
26 * Copyright (c) 1997 Apple Computer, Inc.
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.
39 #include <IOKit/IOTypes.h>
40 #include <libkern/OSByteOrder.h>
43 /* DBDMA definitions */
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*/
57 volatile unsigned long reserved1
;
58 volatile unsigned long addressHi
; /* implementation optional*/
59 volatile unsigned long reserved2
[4];
60 volatile unsigned long unimplemented
[16];
62 /* This structure must remain fully padded to 256 bytes.*/
63 volatile unsigned long undefined
[32];
65 typedef struct IODBDMAChannelRegisters IODBDMAChannelRegisters
;
67 /* These constants define the DB-DMA channel control words and status flags.*/
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,
88 #define IOSetDBDMAChannelControlBits(mask) ( ((mask) | (mask) << 16) )
89 #define IOClearDBDMAChannelControlBits(mask) ( (mask) << 16)
92 /* This structure defines the DB-DMA channel command descriptor.*/
95 *** WARNING: Endian-ness issues must be considered when performing load/store! ***
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*/
104 typedef struct IODBDMADescriptor IODBDMADescriptor
;
106 /* These constants define the DB-DMA channel command operations and modifiers.*/
110 /* Command.cmd operations*/
111 kdbdmaOutputMore
= 0,
112 kdbdmaOutputLast
= 1,
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,
132 kdbdmaIntNever
= 0, /* default modifier*/
134 kdbdmaIntIfFalse
= 2,
137 kdbdmaBranchNever
= 0, /* default modifier*/
138 kdbdmaBranchIfTrue
= 1,
139 kdbdmaBranchIfFalse
= 2,
140 kdbdmaBranchAlways
= 3,
142 kdbdmaWaitNever
= 0, /* default modifier*/
143 kdbdmaWaitIfTrue
= 1,
144 kdbdmaWaitIfFalse
= 2,
145 kdbdmaWaitAlways
= 3,
147 kdbdmaCommandMask
= (long)0xFFFF0000,
148 kdbdmaReqCountMask
= 0x0000FFFF
152 /* These constants define the DB-DMA channel command results.*/
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
176 /* These macros are are IODBDMAChannelRegisters accessor functions. */
178 #define IOSetDBDMAChannelRegister(registerSetPtr,field,value) \
179 OSWriteSwapInt32(registerSetPtr,offsetof(IODBDMAChannelRegisters,field),value)
181 #define IOGetDBDMAChannelRegister(registerSetPtr, field) \
182 OSReadSwapInt32(registerSetPtr,offsetof(IODBDMAChannelRegisters, field))
185 /* void IOSetDBDMAChannelControl (IODBDMAChannelRegisters *registerSetPtr, unsigned long ctlValue); */
187 #define IOSetDBDMAChannelControl(registerSetPtr,ctlValue) \
190 IOSetDBDMAChannelRegister(registerSetPtr,channelControl,ctlValue); \
194 /* unsigned long IOGetDBDMAChannelStatus (IODBDMAChannelRegisters *registerSetPtr); */
196 #define IOGetDBDMAChannelStatus(registerSetPtr) \
197 IOGetDBDMAChannelRegister(registerSetPtr,channelStatus)
199 /* unsigned long IOGetDBDMACommandPtr (IODBDMAChannelRegisters *registerSetPtr); */
201 #define IOGetDBDMACommandPtr(registerSetPtr) \
202 IOGetDBDMAChannelRegister(registerSetPtr,commandPtrLo)
204 /* void IOSetDBDMACommandPtr (IODBDMAChannelRegisters *registerSetPtr, unsigned long cclPtr); */
206 #define IOSetDBDMACommandPtr(registerSetPtr,cclPtr) \
208 IOSetDBDMAChannelRegister(registerSetPtr,commandPtrHi,0); \
210 IOSetDBDMAChannelRegister(registerSetPtr,commandPtrLo,cclPtr); \
215 /* unsigned long IOGetDBDMAInterruptSelect (IODBDMAChannelRegisters *registerSetPtr); */
217 #define IOGetDBDMAInterruptSelect(registerSetPtr) \
218 IOGetDBDMAChannelRegister(registerSetPtr,interruptSelect)
220 /* void IOSetDBDMAInterruptSelect (IODBDMAChannelRegisters *registerSetPtr, unsigned long intSelValue); */
222 #define IOSetDBDMAInterruptSelect(registerSetPtr,intSelValue) \
224 IOSetDBDMAChannelRegister(registerSetPtr,interruptSelect,intSelValue); \
228 /* unsigned long IOGetDBDMABranchSelect (IODBDMAChannelRegisters *registerSetPtr); */
230 #define IOGetDBDMABranchSelect(registerSetPtr) \
231 IOGetDBDMAChannelRegister(registerSetPtr,branchSelect)
233 /* void IOSetDBDMABranchSelect (IODBDMAChannelRegisters *registerSetPtr, unsigned long braSelValue); */
235 #define IOSetDBDMABranchSelect(registerSetPtr,braSelValue) \
237 IOSetDBDMAChannelRegister(registerSetPtr,branchSelect,braSelValue); \
241 /* unsigned long IOGetDBDMAWaitSelect (IODBDMAChannelRegisters *registerSetPtr); */
243 #define IOGetDBDMAWaitSelect(registerSetPtr) \
244 IOGetDBDMAChannelRegister(registerSetPtr,waitSelect)
246 /* void IOSetDBDMAWaitSelect (IODBDMAChannelRegisters *registerSetPtr, unsigned long waitSelValue); */
248 #define IOSetDBDMAWaitSelect(registerSetPtr,waitSelValue) \
250 IOSetDBDMAChannelRegister(registerSetPtr,waitSelect,waitSelValue); \
255 /* These macros are IODBDMADescriptor accessor functions. */
257 #define IOSetDBDMADescriptor(descPtr,field,value) \
258 OSWriteSwapInt32( descPtr, offsetof( IODBDMADescriptor, field), value)
260 #define IOGetDBDMADescriptor(descPtr,field) \
261 OSReadSwapInt32( descPtr, offsetof( IODBDMADescriptor, field))
263 #define IOMakeDBDMAOperation(cmd,key,interrupt,branch,wait,count) \
264 ( ((cmd) << 28) | ((key) << 24) | ((interrupt) << 20) \
265 | ((branch) << 18) | ( (wait) << 16) | (count) )
267 /* void IOMakeDBDMADescriptor (IODBDMADescriptor *descPtr,
270 unsigned long interrupt,
271 unsigned long branch,
274 unsigned long addr); */
276 #define IOMakeDBDMADescriptor(descPtr,cmd,key,interrupt,branch,wait,count,addr)\
278 IOSetDBDMADescriptor(descPtr, address, addr); \
279 IOSetDBDMADescriptor(descPtr, cmdDep, 0); \
280 IOSetDBDMADescriptor(descPtr, result, 0); \
282 IOSetDBDMADescriptor(descPtr, operation, \
283 IOMakeDBDMAOperation(cmd,key,interrupt,branch,wait,count)); \
287 /* void IOMakeDBDMADescriptorDep (IODBDMADescriptor *descPtr,
290 unsigned long interrupt,
291 unsigned long branch,
295 unsigned long dep); */
297 #define IOMakeDBDMADescriptorDep(descPtr,cmd,key,interrupt,branch,wait,count,addr,dep) \
299 IOSetDBDMADescriptor(descPtr, address, addr); \
300 IOSetDBDMADescriptor(descPtr, cmdDep, dep); \
301 IOSetDBDMADescriptor(descPtr, result, 0); \
303 IOSetDBDMADescriptor(descPtr, operation, \
304 IOMakeDBDMAOperation(cmd, key, interrupt, branch, wait, count)); \
308 /* Field accessors - NOTE: unsynchronized */
310 /* unsigned long IOGetDBDMAOperation (IODBDMADescriptor *descPtr) */
312 #define IOGetCCOperation(descPtr) \
313 IOGetDBDMADescriptor(descPtr,operation)
315 /* void IOSetCCOperation (IODBDMADescriptor *descPtr, unsigned long operationValue) */
317 #define IOSetCCOperation(descPtr,operationValue) \
318 IOSetDBDMADescriptor(descPtr,operation,operationValue)
320 /* unsigned long IOGetCCAddress (IODBDMADescriptor *descPtr) */
322 #define IOGetCCAddress(descPtr) \
323 IOGetDBDMADescriptor(descPtr,address)
325 /* void IOSetCCAddress (IODBDMADescriptor *descPtr, unsigned long addressValue) */
327 #define IOSetCCAddress(descPtr,addressValue) \
328 IOSetDBDMADescriptor(descPtr,address, addressValue)
330 /* unsigned long IOGetCCCmdDep (IODBDMADescriptor *descPtr) */
332 #define IOGetCCCmdDep(descPtr) \
333 IOGetDBDMADescriptor(descPtr,cmdDep)
335 /* void IOSetCCCmdDep (IODBDMADescriptor *descPtr, unsigned long cmdDepValue) */
337 #define IOSetCCCmdDep(descPtr,cmdDepValue) \
338 IOSetDBDMADescriptor(descPtr,cmdDep,cmdDepValue)
340 /* unsigned long IOGetCCResult (IODBDMADescriptor *descPtr) */
342 #define IOGetCCResult(descPtr) \
343 IOGetDBDMADescriptor(descPtr,result)
345 /* void IOSetCCResult (IODBDMADescriptor *descPtr, unsigned long resultValue) */
347 #define IOSetCCResult(descPtr,resultValue) \
348 IOSetDBDMADescriptor(descPtr,result,resultValue)
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
);
360 extern IOReturn
IOAllocatePhysicallyContiguousMemory( unsigned int size
, unsigned int options
,
361 IOVirtualAddress
* logical
, IOPhysicalAddress
* physical
);
362 extern IOReturn
IOFreePhysicallyContiguousMemory( IOVirtualAddress
* logical
, unsigned int size
);
364 #endif /* !defined(_IODBDMA_H_) */