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
81 #include <mach/mach_types.h>
83 #include <IOKit/IOService.h>
86 #include <pexpert/pexpert.h>
88 #include <IOKit/IOLocks.h>
89 #include "AppleCudaCommands.h"
90 #include "AppleCudaHW.h"
91 #include <IOKit/adb/adb.h>
92 #include <IOKit/pwr_mgt/RootDomain.h>
95 // CudaInterruptState - internal to CudaCore.c
98 enum CudaInterruptState
100 CUDA_STATE_INTERRUPT_LIMBO
= -1, //
101 CUDA_STATE_IDLE
= 0, //
102 CUDA_STATE_ATTN_EXPECTED
= 1, //
103 CUDA_STATE_TRANSMIT_EXPECTED
= 2, //
104 CUDA_STATE_RECEIVE_EXPECTED
= 3 //
107 typedef enum CudaInterruptState CudaInterruptState
;
110 // CudaTransactionFlag - internal to CudaCore.c
113 enum CudaTransactionFlag
115 CUDA_TS_NO_REQUEST
= 0x0000,
116 CUDA_TS_SYNC_RESPONSE
= 0x0001,
117 CUDA_TS_ASYNC_RESPONSE
= 0x0002
120 typedef enum CudaTransactionFlag CudaTransactionFlag
;
122 //typedef void (* ADB_input_func)(IOService * obj_id, UInt8 * buffer, UInt32 length, UInt8 command);
124 class IOCudaADBController
;
125 class IOInterruptEventSource
;
129 class AppleCuda
: public IOService
131 OSDeclareDefaultStructors(AppleCuda
)
135 IOService
* cudaDevice
;
136 IOWorkLoop
* workLoop
;
138 IOCudaADBController
* ourADBinterface
;
139 ADB_callback_func autopoll_handler
;
140 UInt8 _cuda_power_state
;
141 // callPlatformFunction symbols
142 const OSSymbol
*cuda_check_any_interrupt
;
144 // number of autopoll buffers between interrupt and thread
145 #define NUM_AP_BUFFERS (1<<3)
146 // max adb register size for autopoll
147 #define MAX_AP_RESPONSE (8)
149 unsigned char cuda_autopoll_buffers
[ NUM_AP_BUFFERS
]
154 virtual void free( void );
158 VIARegisterAddress cuda_via_regs
;
159 bool cuda_polled_mode
;
160 IOSimpleLock
* cuda_request_lock
;
161 volatile cuda_request_t
* cuda_request
; // head of todo queue
162 volatile cuda_request_t
* cuda_last_request
; // tail of todo queue
163 volatile CudaInterruptState cuda_interrupt_state
;
164 volatile unsigned int inIndex
;
165 volatile unsigned int outIndex
;
166 volatile CudaTransactionFlag cuda_transaction_state
;
167 cuda_packet_t cuda_unsolicited
[ NUM_AP_BUFFERS
];
168 bool cuda_is_header_transfer
;
169 int cuda_transfer_count
;
170 IOInterruptEventSource
* eventSrc
;
171 cuda_packet_t
* cuda_current_response
;
172 bool cuda_is_packet_type
;
173 AbsoluteTime cuda_state_transition_delay
;
174 IOPMrootDomain
* _rootDomain
;
176 bool init ( OSDictionary
* properties
= 0 );
177 bool start ( IOService
* );
178 virtual IOWorkLoop
*getWorkLoop() const;
179 void serviceAutopolls ( void );
180 void registerForADBInterrupts ( ADB_callback_func handler
, IOService
* caller
);
181 IOReturn
doSyncRequest ( cuda_request_t
* request
);
182 IOReturn
powerStateWillChangeTo ( IOPMPowerFlags
, unsigned long, IOService
*);
183 IOReturn
powerStateDidChangeTo ( IOPMPowerFlags
, unsigned long, IOService
*);
184 virtual IOReturn
callPlatformFunction(const OSSymbol
*functionName
,
185 bool waitForFunction
,
186 void *param1
, void *param2
,
187 void *param3
, void *param4
);