2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991
26 * Permission to use, copy, modify, and distribute this software and
27 * its documentation for any purpose and without fee is hereby granted,
28 * provided that the above copyright notice appears in all copies and
29 * that both the copyright notice and this permission notice appear in
30 * supporting documentation.
32 * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
33 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
34 * FOR A PARTICULAR PURPOSE.
36 * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
37 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
38 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
39 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
40 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
44 * Copyright 1996 1995 by Apple Computer, Inc. 1997 1996 1995 1994 1993 1992 1991
47 * Permission to use, copy, modify, and distribute this software and
48 * its documentation for any purpose and without fee is hereby granted,
49 * provided that the above copyright notice appears in all copies and
50 * that both the copyright notice and this permission notice appear in
51 * supporting documentation.
53 * APPLE COMPUTER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
54 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
55 * FOR A PARTICULAR PURPOSE.
57 * IN NO EVENT SHALL APPLE COMPUTER BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
58 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
59 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
60 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
61 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
67 /* 1 April 1997 Simon Douglas:
68 * Stolen wholesale from MkLinux.
69 * Added nonblocking adb poll from interrupt level for the debugger.
70 * Acknowledge before response so polled mode can work from inside the adb handler.
72 * 18 June 1998 sdouglas
73 * Start IOKit version. Fix errors from kCudaSRQAssertMask. Use ool cmd & reply buffers,
74 * not fixed len in packet. Does queueing here.
76 * 20 Nov 1998 suurballe
83 #include <mach/mach_types.h>
85 #include <IOKit/IOService.h>
88 #include <pexpert/pexpert.h>
90 #include <IOKit/IOLocks.h>
91 #include "AppleCudaCommands.h"
92 #include "AppleCudaHW.h"
93 #include <IOKit/adb/adb.h>
94 #include <IOKit/pwr_mgt/RootDomain.h>
95 #include <IOKit/IOTimerEventSource.h>
98 // CudaInterruptState - internal to CudaCore.c
101 enum CudaInterruptState
103 CUDA_STATE_INTERRUPT_LIMBO
= -1, //
104 CUDA_STATE_IDLE
= 0, //
105 CUDA_STATE_ATTN_EXPECTED
= 1, //
106 CUDA_STATE_TRANSMIT_EXPECTED
= 2, //
107 CUDA_STATE_RECEIVE_EXPECTED
= 3 //
110 typedef enum CudaInterruptState CudaInterruptState
;
113 // CudaTransactionFlag - internal to CudaCore.c
116 enum CudaTransactionFlag
118 CUDA_TS_NO_REQUEST
= 0x0000,
119 CUDA_TS_SYNC_RESPONSE
= 0x0001,
120 CUDA_TS_ASYNC_RESPONSE
= 0x0002
123 typedef enum CudaTransactionFlag CudaTransactionFlag
;
125 //typedef void (* ADB_input_func)(IOService * obj_id, UInt8 * buffer, UInt32 length, UInt8 command);
127 class IOCudaADBController
;
128 class IOInterruptEventSource
;
132 class AppleCuda
: public IOService
134 OSDeclareDefaultStructors(AppleCuda
)
138 IOService
* cudaDevice
;
139 IOWorkLoop
* workLoop
;
141 IOCudaADBController
* ourADBinterface
;
142 ADB_callback_func autopoll_handler
;
143 UInt8 _cuda_power_state
;
144 IOTimerEventSource
* timerSrc
;
145 bool _wakeup_from_sleep
;
146 // callPlatformFunction symbols
147 const OSSymbol
*cuda_check_any_interrupt
;
149 // number of autopoll buffers between interrupt and thread
150 #define NUM_AP_BUFFERS (1<<3)
151 // max adb register size for autopoll
152 #define MAX_AP_RESPONSE (8)
154 unsigned char cuda_autopoll_buffers
[ NUM_AP_BUFFERS
]
156 static void WakeupTimeoutHandler(OSObject
*object
, IOTimerEventSource
*timer
);
160 virtual void free( void );
164 VIARegisterAddress cuda_via_regs
;
165 bool cuda_polled_mode
;
166 IOSimpleLock
* cuda_request_lock
;
167 volatile cuda_request_t
* cuda_request
; // head of todo queue
168 volatile cuda_request_t
* cuda_last_request
; // tail of todo queue
169 volatile CudaInterruptState cuda_interrupt_state
;
170 volatile unsigned int inIndex
;
171 volatile unsigned int outIndex
;
172 volatile CudaTransactionFlag cuda_transaction_state
;
173 cuda_packet_t cuda_unsolicited
[ NUM_AP_BUFFERS
];
174 bool cuda_is_header_transfer
;
175 int cuda_transfer_count
;
176 IOInterruptEventSource
* eventSrc
;
177 cuda_packet_t
* cuda_current_response
;
178 bool cuda_is_packet_type
;
179 AbsoluteTime cuda_state_transition_delay
;
180 IOPMrootDomain
* _rootDomain
;
182 bool init ( OSDictionary
* properties
= 0 );
183 bool start ( IOService
* );
184 virtual IOWorkLoop
*getWorkLoop() const;
185 void serviceAutopolls ( void );
186 void registerForADBInterrupts ( ADB_callback_func handler
, IOService
* caller
);
187 IOReturn
doSyncRequest ( cuda_request_t
* request
);
188 IOReturn
powerStateWillChangeTo ( IOPMPowerFlags
, unsigned long, IOService
*);
189 IOReturn
powerStateDidChangeTo ( IOPMPowerFlags
, unsigned long, IOService
*);
190 void setWakeTime(UInt32 waketime
);
191 void setPowerOnTime(UInt32 newTime
);
192 void setFileServerMode(bool fileServerModeON
);
193 void demandSleepNow(void);
194 IOReturn
newUserClient(task_t owningTask
, void*, // Security id (?!)
195 UInt32 type
, // Magic number
196 IOUserClient
**handler
);
198 virtual IOReturn
callPlatformFunction(const OSSymbol
*functionName
,
199 bool waitForFunction
,
200 void *param1
, void *param2
,
201 void *param3
, void *param4
);
205 #endif /* APPLECUDA_H */