1/*
2 * Copyright (c) 1998-2002 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) 2000 Apple Computer, Inc.  All rights reserved.
24 *
25 * HISTORY
26 *
27 */
28
29
30#ifndef _IOKIT_IOFireWireLink_H
31#define _IOKIT_IOFireWireLink_H
32
33#ifndef FIREWIREPRIVATE
34#warning Please do not include this file. Include IOFireWireBus.h instead.
35#endif
36
37#import <IOKit/firewire/IOFireWireFamilyCommon.h>
38
39#import <IOKit/IOService.h>
40#import <IOKit/IOFilterInterruptEventSource.h>
41#import <IOKit/firewire/IOFireWireController.h>
42
43enum
44{
45	kIOFWAllPhysicalFilters = 64
46};
47
48// These are used by SetLinkMode, arg1 parameter
49enum
50{
51	kIOFWSetDSLimit = 0,
52	kIOFWSetForceLinkReset = 1
53};
54
55enum
56{
57	kIOFWNodeFlagRetryOnAckD	= (1 << 0)
58};
59
60struct IOFWNodeScan;
61class IOFWDCLPool ;
62class IODCLProgram ;
63
64/*! @class IOFireWireLink
65*/
66class IOFireWireLink : public IOService
67{
68    OSDeclareAbstractStructors(IOFireWireLink)
69
70	protected:
71
72		IOFireWireController *fControl;
73		IOFWWorkLoop *	fWorkLoop;
74
75	/*! @struct ExpansionData
76		@discussion This structure will be used to expand the capablilties of the class in the future.
77		*/
78		struct ExpansionData { };
79
80	/*! @var reserved
81		Reserved for future use.  (Internal use only)  */
82		ExpansionData *reserved;
83
84		// calls to protected methods of controller
85		void processBusReset()
86		{ fControl->processBusReset(); };
87		void processSelfIDs(UInt32 *IDs, int numIDs, UInt32 *ownIDs, int numOwnIDs)
88		{ fControl->processSelfIDs(IDs, numIDs, ownIDs, numOwnIDs); };
89		void processRcvPacket(UInt32 *data, int numQuads, IOFWSpeed speed )
90			{ fControl->processRcvPacket(data, numQuads, speed ); };
91		void processCycle64Int()
92		{ fControl->processCycle64Int(); };
93		virtual IOFireWireController * createController();
94		virtual IOFWWorkLoop* createWorkLoop();
95
96
97		// Public methods are usually only called from the firewire controller object.
98	public:
99
100		// Create a device nub
101		virtual IOFireWireDevice *createDeviceNub(CSRNodeUniqueID guid, const IOFWNodeScan *deviceInfo);
102
103		// Set power state
104		virtual IOReturn setLinkPowerState ( unsigned long powerStateOrdinal) = 0;
105
106		// Bus management stuff
107		virtual IOReturn 				setContender(bool state) = 0;
108		virtual IOReturn 				setRootHoldOff(bool state) = 0;
109		virtual IOReturn 				setCycleMaster(bool state) = 0;
110
111		virtual IODCLProgram*			createDCLProgram(bool talking, DCLCommand *opcodes,
112												IOFireWireController::DCLTaskInfo *info, UInt32 startEvent,
113												UInt32 startState, UInt32 startMask) = 0;
114
115		// Send a PHY packet
116		virtual IOReturn 				sendPHYPacket(UInt32 quad) = 0;
117
118		// Check for hardware interrupts (typically from a timeout call)
119		virtual void 					handleInterrupts( IOInterruptEventSource *, int count ) = 0;
120
121		virtual IOReturn 				resetBus( bool useIBR = false ) = 0;
122
123		virtual IOReturn 				asyncRead(UInt16 nodeID, UInt16 addrHi, UInt32 addrLo,
124												int speed, int label, int size, IOFWAsyncCommand *cmd,
125												IOFWReadFlags 			flags) = 0;
126
127		virtual IOReturn 				asyncReadQuadResponse(UInt16 nodeID, int speed,
128												int label, int rcode, UInt32 data) = 0;
129
130		virtual IOReturn				asyncReadResponse(UInt16 nodeID, int speed,
131											int label, int rcode, IOMemoryDescriptor *buf,
132											IOByteCount offset, int len, IODMACommand * in_dma_command ) = 0;
133
134		virtual IOReturn				asyncWrite(	UInt16 					nodeID,
135													UInt16 					addrHi,
136													UInt32 					addrLo,
137													int 					speed,
138													int 					label,
139													IOMemoryDescriptor *	buf,
140													IOByteCount 			offset,
141													int 					size,
142													IOFWAsyncCommand *		cmd,
143													IOFWWriteFlags 			flags ) = 0;
144
145		virtual IOReturn 				asyncWriteResponse(UInt16 nodeID, int speed,
146												int label, int rcode, UInt16 addrHi) = 0;
147
148		virtual IOReturn asyncLock(	UInt16					destID,
149									UInt16 					addrHi,
150									UInt32 					addrLo,
151									int 					speed,
152									int 					label,
153									int 					type,
154									IOMemoryDescriptor *	buf,
155									IOByteCount 			offset,
156									int 					length,
157									IOFWAsyncCommand *		cmd ) = 0;
158
159		virtual IOReturn 				asyncLockResponse(UInt16 nodeID, int speed,
160												int label, int rcode, int type, void *data, int len) = 0;
161
162		// Try to fix whatever might have caused the other device to not respond
163		virtual IOReturn 				handleAsyncTimeout(IOFWAsyncCommand *cmd) = 0;
164
165		// Local ConfigROM changed
166		// Bus will be reset (via resetBus()) if this returns kIOReturnSuccess
167		virtual IOReturn 				updateROM(const OSData *rom) = 0;
168
169		// Read Cycle time register. safe to call at any time.
170		virtual IOReturn 				getCycleTime(UInt32 &cycleTime) = 0;
171		virtual IOReturn 				getBusCycleTime(UInt32 &busTime, UInt32 &cycleTime) = 0;
172		virtual IOReturn 				setBusTime(UInt32 busTime) = 0;
173
174		virtual CSRNodeUniqueID 		getGUID() = 0;
175		virtual UInt32 					getBusCharacteristics() = 0;
176		virtual UInt32 					getMaxSendLog() = 0;
177		virtual UInt16 					getNodeID() = 0;
178
179		virtual IOFireWireController * 	getController() const;
180
181		// Implement IOService::getWorkLoop
182		virtual IOWorkLoop *			getWorkLoop () const;
183
184		// FireWire wants an IOFWWorkLoop
185		virtual IOFWWorkLoop *			getFireWireWorkLoop () const;
186
187		virtual void 					setNodeIDPhysicalFilter ( UInt16 nodeID, bool state ) = 0;
188		virtual void 					setNodeFlags ( UInt16 nodeID, UInt32 flags ) = 0;
189
190//		// don't forget about the isoch workloop:
191//		virtual void					closeIsochGate () ;
192//		virtual void					openIsochGate () ;
193
194		virtual	IOReturn					asyncStreamTransmit (
195															UInt32					channel,
196															int						speed,
197															UInt32					sync,
198															UInt32					tag,
199															IOMemoryDescriptor		*pmd,
200															IOByteCount				offset,
201															int						length,
202															IOFWAsyncStreamCommand	* cmd ) = 0;
203		virtual void						setSecurityMode (
204															IOFWSecurityMode mode ) = 0;
205		void								handleARxReqIntComplete ( void )							{ fControl->handleARxReqIntComplete(); };
206		virtual void						flushWaitingPackets ( void ) = 0;
207		virtual IOFWDCLPool*				createDCLPool ( UInt32 capacity ) ;
208		inline IOWorkLoop *					getIsochWorkloop ()											{ return fIsocWorkloop ; }
209		inline IOWorkLoop *					getWorkloop()											{ return (IOWorkLoop*)fWorkLoop; }
210
211		virtual IOReturn					clipMaxRec2K( bool clipMaxRec ) = 0;
212		virtual IOFWSpeed					getPhySpeed() = 0 ;
213
214		virtual void disablePHYPortOnSleep( UInt32 mask );
215
216		virtual	UInt32 *					getPingTimes ();
217
218		virtual IOReturn					handleAsyncCompletion( IOFWCommand *cmd, IOReturn status );
219
220		virtual void handleSystemShutDown( UInt32 messageType );
221
222		virtual void configureAsyncRobustness( bool enabled );
223
224		virtual bool isPhysicalAccessEnabledForNodeID( UInt16 nodeID );
225
226		virtual void notifyInvalidSelfIDs ();
227
228		virtual IOReturn asyncPHYPacket( UInt32 data, UInt32 data2, IOFWAsyncPHYCommand * cmd );
229
230		virtual bool enterLoggingMode( void );
231
232		virtual IOReturn getCycleTimeAndUpTime( UInt32 &cycleTime, UInt64 &uptime );
233
234		virtual UInt32 setLinkMode( UInt32 arg1, UInt32 arg2 );
235
236		void requestBusReset()
237			{ fControl->resetBus(); };
238
239		virtual IOReturn activateMultiIsochReceiveListener(IOFireWireMultiIsochReceiveListener *pListener) = 0;
240		virtual IOReturn deactivateMultiIsochReceiveListener(IOFireWireMultiIsochReceiveListener *pListener) = 0;
241		virtual void clientDoneWithMultiIsochReceivePacket(IOFireWireMultiIsochReceivePacket *pPacket) = 0;
242
243		inline void setMultiIsochReceiveListenerActivatedState(IOFireWireMultiIsochReceiveListener *pListener, bool active) {pListener->fActivated = active;};
244
245		virtual void enableAllInterrupts( void ) = 0;
246
247		virtual IOPMPowerState * getPowerStateTable( unsigned long * numberOfStates ) = 0;
248
249	private:
250
251		OSMetaClassDeclareReservedUnused(IOFireWireLink, 0);
252		OSMetaClassDeclareReservedUnused(IOFireWireLink, 1);
253		OSMetaClassDeclareReservedUnused(IOFireWireLink, 2);
254		OSMetaClassDeclareReservedUnused(IOFireWireLink, 3);
255		OSMetaClassDeclareReservedUnused(IOFireWireLink, 4);
256		OSMetaClassDeclareReservedUnused(IOFireWireLink, 5);
257		OSMetaClassDeclareReservedUnused(IOFireWireLink, 6);
258		OSMetaClassDeclareReservedUnused(IOFireWireLink, 7);
259		OSMetaClassDeclareReservedUnused(IOFireWireLink, 8);
260
261	protected:
262
263//		FWOHCIIsocInterruptEventSource*	fIsocInterruptEventSource;
264//		IOEventSource *
265		IOWorkLoop *					fIsocWorkloop;
266};
267
268#endif /* ! _IOKIT_IOFireWireLink_H */
269
270