#ifndef _IOHIDSYSTEM_H
#define _IOHIDSYSTEM_H
#include <TargetConditionals.h>
#include <IOKit/IOTimerEventSource.h>
#include <IOKit/IOInterruptEventSource.h>
#include <IOKit/IOService.h>
#include <IOKit/IOMessage.h>
#include <IOKit/IOUserClient.h>
#include <IOKit/IOCommandGate.h>
#include <IOKit/IOBufferMemoryDescriptor.h>
#include <IOKit/pwr_mgt/IOPM.h>
#include "IOHIDWorkLoop.h"
#include <IOKit/graphics/IOGraphicsDevice.h>
#include <IOKit/hidsystem/IOHIDevice.h>
#include <IOKit/hidsystem/IOHIDShared.h>
#include <IOKit/hidsystem/IOHIDTypes.h>
#include <IOKit/hidsystem/IOLLEvent.h>
#include <IOKit/IOSharedDataQueue.h>
#include <IOKit/hidsystem/ev_keymap.h>
#ifndef sub_iokit_hidsystem
#define sub_iokit_hidsystem err_sub(14)
#endif
#define kIOHIDSystem508MouseClickMessage iokit_family_msg(sub_iokit_hidsystem, 1)
#define kIOHIDSystemDeviceSeizeRequestMessage iokit_family_msg(sub_iokit_hidsystem, 2)
#define kIOHIDSystem508SpecialKeyDownMessage iokit_family_msg(sub_iokit_hidsystem, 3)
#define kIOHIDSystemActivityTickle iokit_family_msg(sub_iokit_hidsystem, 5)
#define kIOHIDSystemUserHidActivity iokit_family_msg(sub_iokit_hidsystem, 6)
class IOHistogramReporter;
class IOHIDKeyboardDevice;
class IOHIDPointingDevice;
class IOHIDEvent;
class IOFixedPoint64;
#if defined(KERNEL) && !defined(KERNEL_PRIVATE)
class __deprecated_msg("Use DriverKit") IOHIDSystem : public IOService
#else
class IOHIDSystem : public IOService
#endif
{
OSDeclareDefaultStructors(IOHIDSystem);
friend class IOHIDUserClient;
friend class IOHIDParamUserClient;
friend class IOHIDEventSystemUserClient;
private:
IOHIDWorkLoop *workLoop;
IOInterruptEventSource *keyboardEQES;
IOCommandGate *cmdGate;
IONotifier *publishNotify;
void *eventMsg; void *stackShotMsg;
IOBufferMemoryDescriptor * globalMemory;
uintptr_t shmem_addr; vm_size_t shmem_size;
volatile EvGlobals *evg; int lleqSize;
vm_size_t evScreenSize; void *evScreen; int screens; UInt32 cursorScreens; UInt32 cursorPinScreen; IOGBounds cursorPin; IOGBounds workSpace; struct ExpansionData;
ExpansionData *_privateData;
IOGPoint clickLoc; IOGPoint clickSpaceThresh;
bool evOpenCalled; bool evInitialized; bool eventsOpen; bool cursorStarted; bool cursorEnabled; bool cursorCoupled; bool cursorPinned;
uint64_t lastUndimEvent;
struct SetFixedMouseLocData {
uint64_t origTs;
uint64_t callTs;
int32_t x;
int32_t y;
int32_t pid;
} __attribute__((packed));
struct Diags {
static const uint32_t SLOW_CURSOR_MS = 20;
typedef enum {
kCursorActionShow = 0,
kCursorActionHide,
kCursorActionMove,
kCursorActionCount
} CursorAction;
static const char * cursorStrings[kCursorActionCount];
uint64_t cursorWorkloopTime;
uint64_t lastActionTimes[kCursorActionCount];
uint8_t lastCursorActionsMask;
IOHistogramReporter * cursorTotalHistReporter;
IOHistogramReporter * cursorGraphicsHistReporter;
} _diags;
IOPMrootDomain * rootDomain;
UInt32 powerState;
OSDictionary * savedParameters;
UInt32 maxWaitCursorFrame; UInt32 firstWaitCursorFrame;
IOHIDPointingDevice * _hidPointingDevice;
IOHIDKeyboardDevice * _hidKeyboardDevice;
OSObject * lastSender;
bool setParamPropertiesInProgress;
OSSet * dataQueueSet;
private:
static IOReturn powerStateHandler( void *target, void *refCon,
UInt32 messageType, IOService *service, void *messageArgument, vm_size_t argSize );
void updatePowerState(UInt32 messageType);
void _setScrollCountParameters(OSDictionary *newSettings = NULL);
void initShmem(bool clean);
void postEvent( int what,
IOFixedPoint64 * location,
AbsoluteTime ts,
NXEventData * myData,
OSObject * sender = 0,
UInt32 extPID = 0,
bool processKEQ = true,
UInt32 options = 0
);
void evDispatch(
EvCmd evcmd);
OSDictionary * createFilteredParamPropertiesForService(IOService * service, OSDictionary * dict);
static void _periodicEvents(IOHIDSystem * self,
IOTimerEventSource *timer);
static void doProcessKeyboardEQ(IOHIDSystem * self);
static void processKeyboardEQ(IOHIDSystem * self, AbsoluteTime * deadline = 0);
void doProcessNotifications();
bool genericNotificationHandler(void * ref, IOService * newService, IONotifier * notifier );
static bool handlePublishNotification( void * target, IOService * newService );
static bool handleTerminationNotification( void * target, IOService * newService );
static void makeNumberParamProperty( OSDictionary * dict, const char * key,
unsigned long long number, unsigned int bits );
static void makeInt32ArrayParamProperty( OSDictionary * dict, const char * key,
UInt32 * array, unsigned int count );
private:
void scheduleNextPeriodicEvent();
void periodicEvents(IOTimerEventSource *timer);
bool startCursor();
bool resetCursor();
void showWaitCursor();
void hideWaitCursor();
void animateWaitCursor();
void changeCursor(int frame);
int pointToScreen(IOGPoint * p);
inline void showCursor();
inline void hideCursor();
inline void moveCursor();
void enableContinuousCursor();
void disableContinuousCursor();
void _onScreenCursorPin();
bool registerEventSource(IOService * source);
void setCursorPosition(IOGPoint * newLoc, bool external, OSObject * sender=0);
void _setCursorPosition(bool external = false, bool proximityChange = false, OSObject * sender=0);
static bool _idleTimeSerializerCallback(void * target, void * ref, OSSerialize *s);
static bool _cursorStateSerializerCallback(void * target, void * ref, OSSerialize *s);
static bool _displaySerializerCallback(void * target, void * ref, OSSerialize *s);
IOReturn _recordCursorAction(uint64_t origTS, uint64_t entryTS);
virtual IOReturn configureReport(IOReportChannelList *channels,
IOReportConfigureAction action,
void *result,
void *destination) APPLE_KEXT_OVERRIDE;
virtual IOReturn updateReport(IOReportChannelList *channels,
IOReportUpdateAction action,
void *result,
void *destination) APPLE_KEXT_OVERRIDE;
void createParameters( void );
public:
static IOHIDSystem * instance();
virtual bool init(OSDictionary * properties = 0) APPLE_KEXT_OVERRIDE;
virtual IOHIDSystem * probe(IOService * provider,
SInt32 * score) APPLE_KEXT_OVERRIDE;
virtual bool start(IOService * provider) APPLE_KEXT_OVERRIDE;
virtual IOReturn message(UInt32 type, IOService * provider,
void * argument) APPLE_KEXT_OVERRIDE;
virtual void free(void) APPLE_KEXT_OVERRIDE;
virtual bool attach( IOService * provider ) APPLE_KEXT_OVERRIDE;
virtual void detach( IOService * provider ) APPLE_KEXT_OVERRIDE;
virtual IOWorkLoop *getWorkLoop(void) const APPLE_KEXT_OVERRIDE;
virtual IOReturn evOpen(void);
virtual IOReturn evClose(void);
virtual IOReturn setProperties( OSObject * properties ) APPLE_KEXT_OVERRIDE;
virtual IOReturn setParamProperties(OSDictionary * dict);
virtual IOReturn createShmem(void*,void*,void*,void*,void*,void*);
virtual IOReturn registerEventQueue(IOSharedDataQueue * queue);
virtual IOReturn unregisterEventQueue(IOSharedDataQueue * queue);
public:
virtual IOReturn newUserClient(task_t owningTask,
void * security_id,
UInt32 type,
OSDictionary * properties,
IOUserClient ** handler) APPLE_KEXT_OVERRIDE;
public:
public:
virtual void keyboardEvent(unsigned eventType,
unsigned flags,
unsigned key,
unsigned charCode,
unsigned charSet,
unsigned origCharCode,
unsigned origCharSet,
unsigned keyboardType,
bool repeat,
AbsoluteTime ts);
virtual void keyboardSpecialEvent( unsigned eventType,
unsigned flags,
unsigned key,
unsigned flavor,
UInt64 guid,
bool repeat,
AbsoluteTime ts);
virtual void updateEventFlags(unsigned flags);
private:
static void _keyboardEvent( IOHIDSystem * self,
unsigned eventType,
unsigned flags,
unsigned key,
unsigned charCode,
unsigned charSet,
unsigned origCharCode,
unsigned origCharSet,
unsigned keyboardType,
bool repeat,
AbsoluteTime ts,
OSObject * sender,
void * refcon);
static void _keyboardSpecialEvent(IOHIDSystem * self,
unsigned eventType,
unsigned flags,
unsigned key,
unsigned flavor,
UInt64 guid,
bool repeat,
AbsoluteTime ts,
OSObject * sender,
void * refcon);
static void _updateEventFlags( IOHIDSystem * self,
unsigned flags,
OSObject * sender,
void * refcon);
public:
virtual IOReturn setEventsEnable(void*,void*,void*,void*,void*,void*);
virtual IOReturn setCursorEnable(void*,void*,void*,void*,void*,void*);
virtual IOReturn extPostEvent(void*,void*,void*,void*,void*,void*);
virtual IOReturn extSetMouseLocation(void*,void*,void*,void*,void*,void*);
virtual IOReturn extGetButtonEventNum(void*,void*,void*,void*,void*,void*);
IOReturn extSetBounds(void*,void*,void*,void*,void*,void*);
IOReturn extSetOnScreenBounds(void*,void*,void*,void*,void*,void*);
IOReturn setBounds(IOGBounds * bounds, IOGPoint * screenPoint, bool onScreen);
IOReturn extGetStateForSelector(void*,void*,void*,void*,void*,void*);
IOReturn extSetStateForSelector(void*,void*,void*,void*,void*,void*);
IOReturn extRegisterVirtualDisplay(void*,void*,void*,void*,void*,void*);
IOReturn extUnregisterVirtualDisplay(void*,void*,void*,void*,void*,void*);
IOReturn extSetVirtualDisplayBounds(void*,void*,void*,void*,void*,void*);
IOReturn extGetUserHidActivityState(void*,void*,void*,void*,void*,void*);
IOReturn setContinuousCursorEnable(void*,void*,void*,void*,void*,void*);
public:
virtual int registerScreen(IOGraphicsDevice * instance,
IOGBounds * bp,
IOGBounds * vbp);
private:
static IOReturn doRegisterScreen(IOHIDSystem *self, IOGraphicsDevice *io_gd, IOGBounds *bp, IOGBounds * vbp, void *arg3);
IOReturn registerScreenGated(IOGraphicsDevice *io_gd, IOGBounds *bp, IOGBounds * vbp, SInt32 *index);
public:
virtual void unregisterScreen(int index);
public:
virtual IOGBounds * workspaceBounds();
private:
void keyboardEvent(unsigned eventType,
unsigned flags,
unsigned key,
unsigned charCode,
unsigned charSet,
unsigned origCharCode,
unsigned origCharSet,
unsigned keyboardType,
bool repeat,
AbsoluteTime ts,
OSObject * sender);
void keyboardSpecialEvent( unsigned eventType,
unsigned flags,
unsigned key,
unsigned flavor,
UInt64 guid,
bool repeat,
AbsoluteTime ts,
OSObject * sender);
void updateEventFlags(unsigned flags, OSObject * sender);
static IOReturn doEvClose (IOHIDSystem *self);
IOReturn evCloseGated (void);
static IOReturn doUnregisterScreen (IOHIDSystem *self, void * arg0);
IOReturn unregisterScreenGated (int index);
static IOReturn doSetDisplayBounds (IOHIDSystem *self, void * arg0, void * arg1);
IOReturn setDisplayBoundsGated (UInt32 index, IOGBounds *bounds);
static IOReturn doCreateShmem (IOHIDSystem *self, void * arg0);
IOReturn createShmemGated (void * p1);
static IOReturn doRegisterEventQueue (IOHIDSystem *self, void * arg0);
IOReturn registerEventQueueGated (void * p1);
static IOReturn doUnregisterEventQueue (IOHIDSystem *self, void * arg0);
IOReturn unregisterEventQueueGated (void * p1);
static IOReturn doKeyboardEvent (IOHIDSystem *self, void * args);
void keyboardEventGated (unsigned eventType,
unsigned flags,
unsigned key,
unsigned charCode,
unsigned charSet,
unsigned origCharCode,
unsigned origCharSet,
unsigned keyboardType,
bool repeat,
AbsoluteTime ts,
OSObject * sender);
static IOReturn doKeyboardSpecialEvent (IOHIDSystem *self, void * args);
void keyboardSpecialEventGated (
unsigned eventType,
unsigned flags,
unsigned key,
unsigned flavor,
UInt64 guid,
bool repeat,
AbsoluteTime ts,
OSObject * sender);
static IOReturn doUpdateEventFlags (IOHIDSystem *self, void * args);
void updateEventFlagsGated (unsigned flags, OSObject * sender);
static IOReturn doNewUserClient (IOHIDSystem *self, void * args);
IOReturn newUserClientGated (task_t owningTask,
void * security_id,
UInt32 type,
OSDictionary * properties,
IOUserClient ** handler);
static IOReturn doSetCursorEnable (IOHIDSystem *self, void * arg0);
IOReturn setCursorEnableGated (void * p1);
static IOReturn doSetContinuousCursorEnable (IOHIDSystem *self, void * arg0);
IOReturn setContinuousCursorEnableGated (void * p1);
static IOReturn doExtPostEvent(IOHIDSystem *self, void * arg0, void * arg1, void * arg2, void * arg3);
IOReturn extPostEventGated (void * p1, void * p2, void * p3);
static IOReturn doExtSetMouseLocation (IOHIDSystem *self, void * args);
IOReturn extSetMouseLocationGated (void * args);
static IOReturn doExtGetButtonEventNum (IOHIDSystem *self, void * arg0, void * arg1);
IOReturn extGetButtonEventNumGated (void * p1, void * p2);
static IOReturn doSetParamPropertiesPre (IOHIDSystem *self, void * arg0, void * arg1);
IOReturn setParamPropertiesPreGated (OSDictionary * dict, OSIterator ** pOpenIter);
static IOReturn doSetParamPropertiesPost (IOHIDSystem *self, void * arg0);
IOReturn setParamPropertiesPostGated (OSDictionary * dict);
IOReturn updateParamPropertiesGated(IOService * source);
static IOReturn doExtGetStateForSelector (IOHIDSystem *self, void *p1, void *p2);
static IOReturn doExtSetStateForSelector (IOHIDSystem *self, void *p1, void *p2);
public:
virtual UInt32 eventFlags();
virtual void sleepDisplayTickle(IOService * requester);
virtual void dispatchEvent(IOHIDEvent *event, IOOptionBits options=0);
void updateHidActivity();
void hidActivityChecker();
static void reportUserHidActivity(IOHIDSystem *self, void *args );
void reportUserHidActivityGated(void *args );
static IOReturn getUserHidActivityState(IOHIDSystem *self, void *arg0);
IOReturn getUserHidActivityStateGated(void *state);
};
#endif