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