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