#ifndef _IOKIT_APPLEUSBHUB_H
#define _IOKIT_APPLEUSBHUB_H
#include <IOKit/IOLib.h>
#include <IOKit/IOService.h>
#include <IOKit/IOBufferMemoryDescriptor.h>
#include <IOKit/IOTimerEventSource.h>
#include <IOKit/usb/USB.h>
#include <IOKit/usb/USBHub.h>
#include <IOKit/usb/IOUSBLog.h>
#include <kern/thread_call.h>
enum{
kErrataCaptiveOKBit = 1,
kStartupDelayBit = 2,
};
class IOUSBController;
class IOUSBDevice;
class IOUSBInterface;
class IOUSBPipe;
class AppleUSBHubPort;
class AppleUSBHub : public IOService
{
OSDeclareDefaultStructors(AppleUSBHub)
friend class AppleUSBHubPort;
IOUSBController * _bus;
IOUSBDevice * _device;
IOUSBInterface * _hubInterface;
IOUSBConfigurationDescriptor *_configDescriptor;
IOUSBHubDescriptor _hubDescriptor;
USBDeviceAddress _address;
IOUSBHubPortStatus _hubStatus;
IOUSBPipe * _interruptPipe;
IOBufferMemoryDescriptor * _buffer;
IOCommandGate * _gate;
IOWorkLoop * _workLoop;
UInt32 _locationID;
UInt32 _inStartMethod;
bool _portSuspended;
bool _hubHasBeenDisconnected;
bool _hubIsDead;
bool _busPowered;
bool _selfPowered;
bool _busPowerGood;
bool _selfPowerGood;
bool _needToClose;
UInt32 _powerForCaptive;
thread_call_t _workThread;
thread_call_t _resetPortZeroThread;
thread_call_t _hubDeadCheckThread;
thread_call_t _clearFeatureEndpointHaltThread;
thread_call_t _clearDevZeroLockThread;
UInt8 _readBytes;
UInt8 _numCaptive;
AppleUSBHubPort ** _ports; bool _multiTTs; bool _hsHub; IOTimerEventSource * _timerSource;
UInt32 _timeoutFlag;
UInt32 _portTimeStamp[32];
UInt32 _portWithDevZeroLock;
UInt32 _outstandingIO;
UInt32 _errataBits;
UInt32 _startupDelay;
static void InterruptReadHandlerEntry(OSObject *target, void *param, IOReturn status, UInt32 bufferSizeRemaining);
void InterruptReadHandler(IOReturn status, UInt32 bufferSizeRemaining);
static void ProcessStatusChangedEntry(OSObject *target);
void ProcessStatusChanged(void);
static void ResetPortZeroEntry(OSObject *target);
void ResetPortZero();
static void CheckForDeadHubEntry(OSObject *target);
void CheckForDeadHub();
static void ClearFeatureEndpointHaltEntry(OSObject *target);
void ClearFeatureEndpointHalt(void);
static void TimeoutOccurred(OSObject *owner, IOTimerEventSource *sender);
static void ClearDevZeroLockForPort( OSObject *target, thread_call_param_t thePort);
IOReturn DoDeviceRequest(IOUSBDevRequest *request);
UInt32 GetHubErrataBits(void);
void DecrementOutstandingIO(void);
void IncrementOutstandingIO(void);
static IOReturn ChangeOutstandingIO(OSObject *target, void *arg0, void *arg1, void *arg2, void *arg3);
void UnpackPortFlags(void);
void CountCaptivePorts(void);
IOReturn CheckPortPowerRequirements(void);
IOReturn AllocatePortMemory(void);
IOReturn StartPorts(void);
IOReturn StopPorts(void);
IOReturn ConfigureHub(void);
bool HubStatusChanged(void);
IOReturn GetHubDescriptor(IOUSBHubDescriptor *desc);
IOReturn GetHubStatus(IOUSBHubStatus *status);
IOReturn ClearHubFeature(UInt16 feature);
IOReturn GetPortStatus(IOUSBHubPortStatus *status, UInt16 port);
IOReturn GetPortState(UInt8 *state, UInt16 port);
IOReturn SetPortFeature(UInt16 feature, UInt16 port);
IOReturn ClearPortFeature(UInt16 feature, UInt16 port);
void PrintHubDescriptor(IOUSBHubDescriptor *desc);
void FatalError(IOReturn err, char *str);
IOReturn DoPortAction(UInt32 type, UInt32 portNumber, UInt32 options );
void StartWatchdogTimer();
void StopWatchdogTimer();
IOReturn RearmInterruptRead();
void ResetMyPort();
void CallCheckForDeadHub(void);
IOUSBHubDescriptor GetCachedHubDescriptor() { return _hubDescriptor; }
bool MergeDictionaryIntoProvider(IOService * provider, OSDictionary * mergeDict);
bool MergeDictionaryIntoDictionary(OSDictionary * sourceDictionary, OSDictionary * targetDictionary);
public:
virtual bool init(OSDictionary * propTable );
virtual bool start(IOService * provider);
virtual void stop(IOService * provider);
virtual bool finalize(IOOptionBits options);
virtual IOReturn message( UInt32 type, IOService * provider, void * argument = 0 );
virtual bool willTerminate( IOService * provider, IOOptionBits options );
virtual bool didTerminate( IOService * provider, IOOptionBits options, bool * defer );
virtual bool requestTerminate( IOService * provider, IOOptionBits options );
virtual bool terminate( IOOptionBits options = 0 );
virtual void free( void );
virtual bool terminateClient( IOService * client, IOOptionBits options );
virtual IOUSBDevice * GetDevice(void) { return _device; }
};
#endif _IOKIT_APPLEUSBHUB_H