1/*
2 * Copyright (c) 1998-2001 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#ifndef _IOKIT_IOFIREWIREAVCUSERCLIENT_H
24#define _IOKIT_IOFIREWIREAVCUSERCLIENT_H
25
26#include <IOKit/IOUserClient.h>
27
28//#include <IOKit/firewire/IOFireWireController.h>
29
30#include <IOKit/avc/IOFireWireAVCUnit.h>
31#include <IOKit/avc/IOFireWireAVCUserClientCommon.h>
32
33#include <IOKit/firewire/IOFWUserObjectExporter.h>
34
35class IOFireWireAVCUserClient;
36
37// A little class to put into the connections set
38class IOFireWireAVCConnection : public OSObject
39{
40    OSDeclareDefaultStructors(IOFireWireAVCConnection)
41
42public:
43
44    UInt32 fPlugAddr;
45	UInt32 fChannel;
46};
47
48// A wrapper class for async AVC commands created by this user client
49class IOFireWireAVCUserClientAsyncCommand : public OSObject
50{
51    OSDeclareDefaultStructors(IOFireWireAVCUserClientAsyncCommand)
52public:
53	IOFireWireAVCAsynchronousCommand *pAsyncCommand;
54	IOMemoryDescriptor *fMem;
55	IOFireWireAVCUserClient *pUserClient;
56	UInt32 commandIdentifierHandle;
57};
58
59
60class IOFireWireAVCUserClient : public IOUserClient
61{
62    OSDeclareDefaultStructors(IOFireWireAVCUserClient)
63
64protected:
65
66    bool					fOpened;
67	bool					fStarted;
68    task_t					fTask;
69
70    IOFireWireAVCNub *		fUnit;
71	OSArray *				fConnections;
72
73	IOLock *				fAsyncAVCCmdLock;
74	OSArray *				fUCAsyncCommands;
75	UInt32					fNextAVCAsyncCommandHandle;
76    OSAsyncReference64		fAsyncAVCCmdCallbackInfo;
77
78#ifdef kUseAsyncAVCCommandForBlockingAVCCommand
79	IOLock *avcCmdLock;
80	IOFireWireAVCAsynchronousCommand *pCommandObject;
81#endif
82
83	IOFireWireLib::UserObjectHandle		fSessionRef;
84
85    static void remakeConnections(void *arg);
86    virtual IOReturn updateP2PCount(UInt32 addr, SInt32 inc, bool failOnBusReset, UInt32 chan, IOFWSpeed speed);
87    virtual IOReturn makeConnection(UInt32 addr, UInt32 chan, IOFWSpeed speed);
88    virtual void breakConnection(UInt32 addr);
89	virtual IOFireWireAVCUserClientAsyncCommand *FindUCAsyncCommandWithHandle(UInt32 commandHandle);
90
91	virtual IOReturn externalMethod( uint32_t selector,
92									IOExternalMethodArguments * arguments,
93									IOExternalMethodDispatch * dispatch,
94									OSObject * target,
95									void * reference);
96
97public:
98	virtual bool initWithTask(task_t owningTask, void * securityToken, UInt32 type,OSDictionary * properties);
99	virtual void free();
100    virtual bool start( IOService * provider );
101    virtual void stop( IOService * provider );
102
103    virtual IOReturn message(UInt32 type, IOService *provider, void *argument);
104
105    virtual IOReturn clientClose( void );
106    virtual IOReturn clientDied( void );
107
108    virtual IOReturn open( void *, void *, void *, void *, void *, void * );
109	virtual IOReturn openWithSessionRef( IOFireWireLib::UserObjectHandle sessionRef, void *, void *, void *, void *, void * );
110	virtual IOReturn getSessionRef( uint64_t * sessionRef, void *, void *, void *, void *, void * );
111    virtual IOReturn close( void * = 0, void * = 0, void * = 0, void * = 0, void * = 0, void * = 0);
112
113    virtual IOReturn AVCCommand(UInt8 * cmd, UInt8 * response, UInt32 len, UInt32 *size);
114    virtual IOReturn AVCCommandInGen(UInt8 * cmd, UInt8 * response, UInt32 len, UInt32 *size);
115
116    virtual IOReturn updateAVCCommandTimeout( void * = 0, void * = 0, void * = 0, void * = 0, void * = 0, void * = 0);
117
118    virtual IOReturn makeP2PInputConnection( UInt32 plugNo, UInt32 chan, void * = 0, void * = 0, void * = 0, void * = 0);
119    virtual IOReturn breakP2PInputConnection( UInt32 plugNo, void * = 0, void * = 0, void * = 0, void * = 0, void * = 0);
120    virtual IOReturn makeP2POutputConnection( UInt32 plugNo, UInt32 chan, IOFWSpeed speed, void * = 0, void * = 0, void * = 0);
121    virtual IOReturn breakP2POutputConnection( UInt32 plugNo, void * = 0, void * = 0, void * = 0, void * = 0, void * = 0);
122
123    virtual IOReturn installUserLibAsyncAVCCommandCallback(io_user_reference_t *asyncRef, uint64_t userRefcon, uint64_t *returnParam);
124
125	virtual IOReturn CreateAVCAsyncCommand(UInt8 * cmd, UInt8 * asyncAVCCommandHandle, UInt32 len, UInt32 *refSize);
126	virtual IOReturn SubmitAVCAsyncCommand(UInt32 commandHandle);
127	virtual IOReturn CancelAVCAsyncCommand(UInt32 commandHandle);
128	virtual IOReturn ReleaseAVCAsyncCommand(UInt32 commandHandle);
129	virtual void HandleUCAsyncCommandCallback(IOFireWireAVCUserClientAsyncCommand *pUCAsyncCommand);
130	virtual IOReturn ReinitAVCAsyncCommand(UInt32 commandHandle, const UInt8 *pCommandBytes, UInt32 len);
131
132	virtual bool requestTerminate( IOService * provider, IOOptionBits options );
133};
134
135#endif // _IOKIT_IOFIREWIREAVCUSERCLIENT_H