1*27b03b36SApple OSS Distributions /* 2*27b03b36SApple OSS Distributions * Copyright (c) 2017 Apple Inc. All rights reserved. 3*27b03b36SApple OSS Distributions */ 4*27b03b36SApple OSS Distributions 5*27b03b36SApple OSS Distributions #pragma once 6*27b03b36SApple OSS Distributions 7*27b03b36SApple OSS Distributions #ifdef KERNEL_PRIVATE 8*27b03b36SApple OSS Distributions #ifdef __cplusplus 9*27b03b36SApple OSS Distributions 10*27b03b36SApple OSS Distributions #include <IOKit/IOService.h> 11*27b03b36SApple OSS Distributions #include <stdatomic.h> 12*27b03b36SApple OSS Distributions #include <kern/bits.h> 13*27b03b36SApple OSS Distributions #include <libkern/c++/OSPtr.h> 14*27b03b36SApple OSS Distributions 15*27b03b36SApple OSS Distributions struct thread_group; 16*27b03b36SApple OSS Distributions 17*27b03b36SApple OSS Distributions enum{ 18*27b03b36SApple OSS Distributions kIOPerfControlClientWorkUntracked = 0, 19*27b03b36SApple OSS Distributions }; 20*27b03b36SApple OSS Distributions 21*27b03b36SApple OSS Distributions /*! 22*27b03b36SApple OSS Distributions * @class IOPerfControlClient : public OSObject 23*27b03b36SApple OSS Distributions * @abstract Class which implements an interface allowing device drivers to participate in performance control. 24*27b03b36SApple OSS Distributions * @discussion TODO 25*27b03b36SApple OSS Distributions */ 26*27b03b36SApple OSS Distributions class IOPerfControlClient final : public OSObject 27*27b03b36SApple OSS Distributions { 28*27b03b36SApple OSS Distributions OSDeclareDefaultStructors(IOPerfControlClient); 29*27b03b36SApple OSS Distributions 30*27b03b36SApple OSS Distributions protected: 31*27b03b36SApple OSS Distributions virtual bool init(IOService *driver, uint64_t maxWorkCapacity); 32*27b03b36SApple OSS Distributions virtual void free() APPLE_KEXT_OVERRIDE; 33*27b03b36SApple OSS Distributions 34*27b03b36SApple OSS Distributions public: 35*27b03b36SApple OSS Distributions /*! 36*27b03b36SApple OSS Distributions * @function copyClient 37*27b03b36SApple OSS Distributions * @abstract Return a retained reference to a client object, to be released by the driver. It may be 38*27b03b36SApple OSS Distributions * shared with other drivers in the system. 39*27b03b36SApple OSS Distributions * @param driver The device driver that will be using this interface. 40*27b03b36SApple OSS Distributions * @param maxWorkCapacity The maximum number of concurrent work items supported by the device driver. 41*27b03b36SApple OSS Distributions * @returns An instance of IOPerfControlClient. 42*27b03b36SApple OSS Distributions */ 43*27b03b36SApple OSS Distributions static IOPerfControlClient *copyClient(IOService *driver, uint64_t maxWorkCapacity); 44*27b03b36SApple OSS Distributions 45*27b03b36SApple OSS Distributions /*! 46*27b03b36SApple OSS Distributions * @function registerDevice 47*27b03b36SApple OSS Distributions * @abstract Inform the system that work will be dispatched to a device in the future. 48*27b03b36SApple OSS Distributions * @discussion The system will do some one-time setup work associated with the device, and may block the 49*27b03b36SApple OSS Distributions * current thread during the setup. Devices should not be passed to work workSubmit, workSubmitAndBegin, 50*27b03b36SApple OSS Distributions * workBegin, or workEnd until they have been successfully registered. The unregistration process happens 51*27b03b36SApple OSS Distributions * automatically when the device object is deallocated. 52*27b03b36SApple OSS Distributions * @param device The device object. Some platforms require device to be a specific subclass of IOService. 53*27b03b36SApple OSS Distributions * @returns kIOReturnSuccess or an IOReturn error code 54*27b03b36SApple OSS Distributions */ 55*27b03b36SApple OSS Distributions virtual IOReturn registerDevice(IOService *driver, IOService *device); 56*27b03b36SApple OSS Distributions 57*27b03b36SApple OSS Distributions /*! 58*27b03b36SApple OSS Distributions * @function unregisterDevice 59*27b03b36SApple OSS Distributions * @abstract Inform the system that work will be no longer be dispatched to a device in the future. 60*27b03b36SApple OSS Distributions * @discussion This call is optional as the unregistration process happens automatically when the device 61*27b03b36SApple OSS Distributions * object is deallocated. This call may block the current thread and/or acquire locks. It should not be 62*27b03b36SApple OSS Distributions * called until after all submitted work has been ended using workEnd. 63*27b03b36SApple OSS Distributions * @param device The device object. Some platforms require device to be a specific subclass of IOService. 64*27b03b36SApple OSS Distributions */ 65*27b03b36SApple OSS Distributions virtual void unregisterDevice(IOService *driver, IOService *device); 66*27b03b36SApple OSS Distributions 67*27b03b36SApple OSS Distributions /*! 68*27b03b36SApple OSS Distributions * @struct WorkSubmitArgs 69*27b03b36SApple OSS Distributions * @discussion Drivers may submit additional device-specific arguments related to the submission of a work item 70*27b03b36SApple OSS Distributions * by passing a struct with WorkSubmitArgs as its first member. Note: Drivers are responsible for publishing 71*27b03b36SApple OSS Distributions * a header file describing these arguments. 72*27b03b36SApple OSS Distributions */ 73*27b03b36SApple OSS Distributions struct WorkSubmitArgs { 74*27b03b36SApple OSS Distributions uint32_t version; 75*27b03b36SApple OSS Distributions uint32_t size; 76*27b03b36SApple OSS Distributions uint64_t submit_time; 77*27b03b36SApple OSS Distributions uint64_t reserved[4]; 78*27b03b36SApple OSS Distributions void *driver_data; 79*27b03b36SApple OSS Distributions }; 80*27b03b36SApple OSS Distributions 81*27b03b36SApple OSS Distributions /*! 82*27b03b36SApple OSS Distributions * @function workSubmit 83*27b03b36SApple OSS Distributions * @abstract Tell the performance controller that work was submitted. 84*27b03b36SApple OSS Distributions * @param device The device that will execute the work. Some platforms require device to be a 85*27b03b36SApple OSS Distributions * specific subclass of IOService. 86*27b03b36SApple OSS Distributions * @param args Optional device-specific arguments related to the submission of this work item. 87*27b03b36SApple OSS Distributions * @returns A token representing this work item, which must be passed to workEnd when the work is finished 88*27b03b36SApple OSS Distributions * unless the token equals kIOPerfControlClientWorkUntracked. Failure to do this will result in memory leaks 89*27b03b36SApple OSS Distributions * and a degradation of system performance. 90*27b03b36SApple OSS Distributions */ 91*27b03b36SApple OSS Distributions virtual uint64_t workSubmit(IOService *device, WorkSubmitArgs *args = nullptr); 92*27b03b36SApple OSS Distributions 93*27b03b36SApple OSS Distributions /*! 94*27b03b36SApple OSS Distributions * @struct WorkBeginArgs 95*27b03b36SApple OSS Distributions * @discussion Drivers may submit additional device-specific arguments related to the start of a work item 96*27b03b36SApple OSS Distributions * by passing a struct with WorkBeginArgs as its first member. Note: Drivers are responsible for publishing 97*27b03b36SApple OSS Distributions * a header file describing these arguments. 98*27b03b36SApple OSS Distributions */ 99*27b03b36SApple OSS Distributions struct WorkBeginArgs { 100*27b03b36SApple OSS Distributions uint32_t version; 101*27b03b36SApple OSS Distributions uint32_t size; 102*27b03b36SApple OSS Distributions uint64_t begin_time; 103*27b03b36SApple OSS Distributions uint64_t reserved[4]; 104*27b03b36SApple OSS Distributions void *driver_data; 105*27b03b36SApple OSS Distributions }; 106*27b03b36SApple OSS Distributions 107*27b03b36SApple OSS Distributions /*! 108*27b03b36SApple OSS Distributions * @function workSubmitAndBegin 109*27b03b36SApple OSS Distributions * @abstract Tell the performance controller that work was submitted and immediately began executing. 110*27b03b36SApple OSS Distributions * @param device The device that is executing the work. Some platforms require device to be a 111*27b03b36SApple OSS Distributions * specific subclass of IOService. 112*27b03b36SApple OSS Distributions * @param submitArgs Optional device-specific arguments related to the submission of this work item. 113*27b03b36SApple OSS Distributions * @param beginArgs Optional device-specific arguments related to the start of this work item. 114*27b03b36SApple OSS Distributions * @returns A token representing this work item, which must be passed to workEnd when the work is finished 115*27b03b36SApple OSS Distributions * unless the token equals kIOPerfControlClientWorkUntracked. Failure to do this will result in memory leaks 116*27b03b36SApple OSS Distributions * and a degradation of system performance. 117*27b03b36SApple OSS Distributions */ 118*27b03b36SApple OSS Distributions virtual uint64_t workSubmitAndBegin(IOService *device, WorkSubmitArgs *submitArgs = nullptr, 119*27b03b36SApple OSS Distributions WorkBeginArgs *beginArgs = nullptr); 120*27b03b36SApple OSS Distributions 121*27b03b36SApple OSS Distributions /*! 122*27b03b36SApple OSS Distributions * @function workBegin 123*27b03b36SApple OSS Distributions * @abstract Tell the performance controller that previously submitted work began executing. 124*27b03b36SApple OSS Distributions * @param device The device that is executing the work. Some platforms require device to be a 125*27b03b36SApple OSS Distributions * specific subclass of IOService. 126*27b03b36SApple OSS Distributions * @param args Optional device-specific arguments related to the start of this work item. 127*27b03b36SApple OSS Distributions */ 128*27b03b36SApple OSS Distributions virtual void workBegin(IOService *device, uint64_t token, WorkBeginArgs *args = nullptr); 129*27b03b36SApple OSS Distributions 130*27b03b36SApple OSS Distributions /*! 131*27b03b36SApple OSS Distributions * @struct WorkEndArgs 132*27b03b36SApple OSS Distributions * @discussion Drivers may submit additional device-specific arguments related to the end of a work item 133*27b03b36SApple OSS Distributions * by passing a struct with WorkEndArgs as its first member. Note: Drivers are responsible for publishing 134*27b03b36SApple OSS Distributions * a header file describing these arguments. 135*27b03b36SApple OSS Distributions */ 136*27b03b36SApple OSS Distributions struct WorkEndArgs { 137*27b03b36SApple OSS Distributions uint32_t version; 138*27b03b36SApple OSS Distributions uint32_t size; 139*27b03b36SApple OSS Distributions uint64_t end_time; 140*27b03b36SApple OSS Distributions uint64_t reserved[4]; 141*27b03b36SApple OSS Distributions void *driver_data; 142*27b03b36SApple OSS Distributions }; 143*27b03b36SApple OSS Distributions 144*27b03b36SApple OSS Distributions /*! 145*27b03b36SApple OSS Distributions * @function workEnd 146*27b03b36SApple OSS Distributions * @abstract Tell the performance controller that previously started work finished executing. 147*27b03b36SApple OSS Distributions * @param device The device that executed the work. Some platforms require device to be a 148*27b03b36SApple OSS Distributions * specific subclass of IOService. 149*27b03b36SApple OSS Distributions * @param args Optional device-specific arguments related to the end of this work item. 150*27b03b36SApple OSS Distributions * @param done Optional Set to false if the work has not yet completed. Drivers are then responsible for 151*27b03b36SApple OSS Distributions * calling workBegin when the work resumes and workEnd with done set to True when it has completed. A workEnd() call 152*27b03b36SApple OSS Distributions * without a corresponding workBegin() call is a way to cancel a work item and return token to IOPerfControl. 153*27b03b36SApple OSS Distributions */ 154*27b03b36SApple OSS Distributions virtual void workEnd(IOService *device, uint64_t token, WorkEndArgs *args = nullptr, bool done = true); 155*27b03b36SApple OSS Distributions 156*27b03b36SApple OSS Distributions /*! 157*27b03b36SApple OSS Distributions * @function copyWorkContext 158*27b03b36SApple OSS Distributions * @abstract Return a retained reference to an opaque OSObject, to be released by the driver. This object can 159*27b03b36SApple OSS Distributions * be used by IOPerfControl to track a work item. This may perform dynamic memory allocation. 160*27b03b36SApple OSS Distributions * @returns A pointer to an OSObject 161*27b03b36SApple OSS Distributions */ 162*27b03b36SApple OSS Distributions OSPtr<OSObject> copyWorkContext(); 163*27b03b36SApple OSS Distributions 164*27b03b36SApple OSS Distributions /*! 165*27b03b36SApple OSS Distributions * @function workSubmitAndBeginWithContext 166*27b03b36SApple OSS Distributions * @abstract Tell the performance controller that work was submitted and immediately began executing 167*27b03b36SApple OSS Distributions * @param device The device that is executing the work. Some platforms require device to be a 168*27b03b36SApple OSS Distributions * specific subclass of IOService. 169*27b03b36SApple OSS Distributions * @param context An OSObject returned by copyWorkContext(). The context object will be used by IOPerfControl to track 170*27b03b36SApple OSS Distributions * this work item. 171*27b03b36SApple OSS Distributions * @param submitArgs Optional device-specific arguments related to the submission of this work item. 172*27b03b36SApple OSS Distributions * @param beginArgs Optional device-specific arguments related to the start of this work item. 173*27b03b36SApple OSS Distributions * @returns true if IOPerfControl is tracking this work item, else false. 174*27b03b36SApple OSS Distributions * @note The workEndWithContext() call is optional if the corresponding workSubmitWithContext() call returned false. 175*27b03b36SApple OSS Distributions */ 176*27b03b36SApple OSS Distributions bool workSubmitAndBeginWithContext(IOService *device, OSObject *context, WorkSubmitArgs *submitArgs = nullptr, 177*27b03b36SApple OSS Distributions WorkBeginArgs *beginArgs = nullptr); 178*27b03b36SApple OSS Distributions 179*27b03b36SApple OSS Distributions /*! 180*27b03b36SApple OSS Distributions * @function workSubmitWithContext 181*27b03b36SApple OSS Distributions * @abstract Tell the performance controller that work was submitted. 182*27b03b36SApple OSS Distributions * @param device The device that will execute the work. Some platforms require device to be a 183*27b03b36SApple OSS Distributions * specific subclass of IOService. 184*27b03b36SApple OSS Distributions * @param context An OSObject returned by copyWorkContext(). The context object will be used by IOPerfControl to track 185*27b03b36SApple OSS Distributions * this work item. 186*27b03b36SApple OSS Distributions * @param args Optional device-specific arguments related to the submission of this work item. 187*27b03b36SApple OSS Distributions * @returns true if IOPerfControl is tracking this work item, else false. 188*27b03b36SApple OSS Distributions */ 189*27b03b36SApple OSS Distributions bool workSubmitWithContext(IOService *device, OSObject *context, WorkSubmitArgs *args = nullptr); 190*27b03b36SApple OSS Distributions 191*27b03b36SApple OSS Distributions /*! 192*27b03b36SApple OSS Distributions * @function workBeginWithContext 193*27b03b36SApple OSS Distributions * @abstract Tell the performance controller that previously submitted work began executing. 194*27b03b36SApple OSS Distributions * @param device The device that is executing the work. Some platforms require device to be a 195*27b03b36SApple OSS Distributions * specific subclass of IOService. 196*27b03b36SApple OSS Distributions * @param context An OSObject returned by copyWorkContext() and provided to the previous call to workSubmitWithContext(). 197*27b03b36SApple OSS Distributions * @param args Optional device-specific arguments related to the start of this work item. 198*27b03b36SApple OSS Distributions * @note The workBeginWithContext() and workEndWithContext() calls are optional if the corresponding workSubmitWithContext() call returned false. 199*27b03b36SApple OSS Distributions */ 200*27b03b36SApple OSS Distributions void workBeginWithContext(IOService *device, OSObject *context, WorkBeginArgs *args = nullptr); 201*27b03b36SApple OSS Distributions 202*27b03b36SApple OSS Distributions /*! 203*27b03b36SApple OSS Distributions * @function workEndWithContext 204*27b03b36SApple OSS Distributions * @abstract Tell the performance controller that previously started work finished executing. 205*27b03b36SApple OSS Distributions * @param device The device that executed the work. Some platforms require device to be a 206*27b03b36SApple OSS Distributions * specific subclass of IOService. 207*27b03b36SApple OSS Distributions * @param context An OSObject returned by copyWorkContext() and provided to the previous call to workSubmitWithContext(). 208*27b03b36SApple OSS Distributions * @param args Optional device-specific arguments related to the end of this work item. 209*27b03b36SApple OSS Distributions * @param done Optional Set to false if the work has not yet completed. Drivers are then responsible for 210*27b03b36SApple OSS Distributions * calling workBegin when the work resumes and workEnd with done set to True when it has completed. 211*27b03b36SApple OSS Distributions * @note The workEndWithContext() call is optional if the corresponding workSubmitWithContext() call returned false. A workEndWithContext() 212*27b03b36SApple OSS Distributions * call without a corresponding workBeginWithContext() call is a way to cancel a work item. 213*27b03b36SApple OSS Distributions */ 214*27b03b36SApple OSS Distributions void workEndWithContext(IOService *device, OSObject *context, WorkEndArgs *args = nullptr, bool done = true); 215*27b03b36SApple OSS Distributions 216*27b03b36SApple OSS Distributions /*! 217*27b03b36SApple OSS Distributions * @struct WorkUpdateArgs 218*27b03b36SApple OSS Distributions * @discussion Drivers may submit additional device-specific arguments related to a work item by passing a 219*27b03b36SApple OSS Distributions * struct with WorkUpdateArgs as its first member. Note: Drivers are responsible for publishing 220*27b03b36SApple OSS Distributions * a header file describing these arguments. 221*27b03b36SApple OSS Distributions */ 222*27b03b36SApple OSS Distributions struct WorkUpdateArgs { 223*27b03b36SApple OSS Distributions uint32_t version; 224*27b03b36SApple OSS Distributions uint32_t size; 225*27b03b36SApple OSS Distributions uint64_t update_time; 226*27b03b36SApple OSS Distributions uint64_t reserved[4]; 227*27b03b36SApple OSS Distributions void *driver_data; 228*27b03b36SApple OSS Distributions }; 229*27b03b36SApple OSS Distributions 230*27b03b36SApple OSS Distributions /*! 231*27b03b36SApple OSS Distributions * @function workUpdateWithContext 232*27b03b36SApple OSS Distributions * @abstract Provide and receive additional information from the performance controller. If this call is 233*27b03b36SApple OSS Distributions * made at all, it should be between workSubmit and workEnd. The purpose and implementation of this call are 234*27b03b36SApple OSS Distributions * device specific, and may do nothing on some devices. 235*27b03b36SApple OSS Distributions * @param device The device that submitted the work. Some platforms require device to be a 236*27b03b36SApple OSS Distributions * specific subclass of IOService. 237*27b03b36SApple OSS Distributions * @param context An OSObject returned by copyWorkContext() and provided to the previous call to workSubmitWithContext(). 238*27b03b36SApple OSS Distributions * @param args Optional device-specific arguments. 239*27b03b36SApple OSS Distributions */ 240*27b03b36SApple OSS Distributions void workUpdateWithContext(IOService *device, OSObject *context, WorkUpdateArgs *args = nullptr); 241*27b03b36SApple OSS Distributions 242*27b03b36SApple OSS Distributions /* 243*27b03b36SApple OSS Distributions * Callers should always use the CURRENT version so that the kernel can detect both older 244*27b03b36SApple OSS Distributions * and newer structure layouts. New callbacks should always be added at the end of the 245*27b03b36SApple OSS Distributions * structure, and xnu should expect existing source recompiled against newer headers 246*27b03b36SApple OSS Distributions * to pass NULL for unimplemented callbacks. 247*27b03b36SApple OSS Distributions */ 248*27b03b36SApple OSS Distributions 249*27b03b36SApple OSS Distributions #define PERFCONTROL_INTERFACE_VERSION_NONE (0) /* no interface */ 250*27b03b36SApple OSS Distributions #define PERFCONTROL_INTERFACE_VERSION_1 (1) /* up-to workEnd */ 251*27b03b36SApple OSS Distributions #define PERFCONTROL_INTERFACE_VERSION_2 (2) /* up-to workUpdate */ 252*27b03b36SApple OSS Distributions #define PERFCONTROL_INTERFACE_VERSION_3 (3) /* up-to (un)registerDriverDevice */ 253*27b03b36SApple OSS Distributions #define PERFCONTROL_INTERFACE_VERSION_CURRENT PERFCONTROL_INTERFACE_VERSION_3 254*27b03b36SApple OSS Distributions 255*27b03b36SApple OSS Distributions /*! 256*27b03b36SApple OSS Distributions * @struct PerfControllerInterface 257*27b03b36SApple OSS Distributions * @discussion Function pointers necessary to register a performance controller. Not for general driver use. 258*27b03b36SApple OSS Distributions */ 259*27b03b36SApple OSS Distributions struct PerfControllerInterface { 260*27b03b36SApple OSS Distributions struct DriverState { 261*27b03b36SApple OSS Distributions uint32_t has_target_thread_group : 1; 262*27b03b36SApple OSS Distributions uint32_t has_device_info : 1; 263*27b03b36SApple OSS Distributions uint32_t reserved : 30; 264*27b03b36SApple OSS Distributions 265*27b03b36SApple OSS Distributions uint64_t target_thread_group_id; 266*27b03b36SApple OSS Distributions void *target_thread_group_data; 267*27b03b36SApple OSS Distributions 268*27b03b36SApple OSS Distributions uint32_t device_type; 269*27b03b36SApple OSS Distributions uint32_t instance_id; 270*27b03b36SApple OSS Distributions }; 271*27b03b36SApple OSS Distributions 272*27b03b36SApple OSS Distributions struct WorkState { 273*27b03b36SApple OSS Distributions uint64_t thread_group_id; 274*27b03b36SApple OSS Distributions void *thread_group_data; 275*27b03b36SApple OSS Distributions void *work_data; 276*27b03b36SApple OSS Distributions uint32_t work_data_size; 277*27b03b36SApple OSS Distributions uint32_t started : 1; 278*27b03b36SApple OSS Distributions uint32_t reserved : 31; 279*27b03b36SApple OSS Distributions const DriverState* driver_state; 280*27b03b36SApple OSS Distributions }; 281*27b03b36SApple OSS Distributions 282*27b03b36SApple OSS Distributions using RegisterDeviceFunction = IOReturn (*)(IOService *); 283*27b03b36SApple OSS Distributions using RegisterDriverDeviceFunction = IOReturn (*)(IOService *, IOService *, DriverState *); 284*27b03b36SApple OSS Distributions using WorkCanSubmitFunction = bool (*)(IOService *, WorkState *, WorkSubmitArgs *); 285*27b03b36SApple OSS Distributions using WorkSubmitFunction = void (*)(IOService *, uint64_t, WorkState *, WorkSubmitArgs *); 286*27b03b36SApple OSS Distributions using WorkBeginFunction = void (*)(IOService *, uint64_t, WorkState *, WorkBeginArgs *); 287*27b03b36SApple OSS Distributions using WorkEndFunction = void (*)(IOService *, uint64_t, WorkState *, WorkEndArgs *, bool); 288*27b03b36SApple OSS Distributions using WorkUpdateFunction = void (*)(IOService *, uint64_t, WorkState *, WorkUpdateArgs *); 289*27b03b36SApple OSS Distributions 290*27b03b36SApple OSS Distributions uint64_t version; 291*27b03b36SApple OSS Distributions RegisterDeviceFunction registerDevice; 292*27b03b36SApple OSS Distributions RegisterDeviceFunction unregisterDevice; 293*27b03b36SApple OSS Distributions WorkCanSubmitFunction workCanSubmit; 294*27b03b36SApple OSS Distributions WorkSubmitFunction workSubmit; 295*27b03b36SApple OSS Distributions WorkBeginFunction workBegin; 296*27b03b36SApple OSS Distributions WorkEndFunction workEnd; 297*27b03b36SApple OSS Distributions WorkUpdateFunction workUpdate; 298*27b03b36SApple OSS Distributions RegisterDriverDeviceFunction registerDriverDevice; 299*27b03b36SApple OSS Distributions RegisterDriverDeviceFunction unregisterDriverDevice; 300*27b03b36SApple OSS Distributions }; 301*27b03b36SApple OSS Distributions 302*27b03b36SApple OSS Distributions struct IOPerfControlClientShared { 303*27b03b36SApple OSS Distributions atomic_uint_fast8_t maxDriverIndex; 304*27b03b36SApple OSS Distributions PerfControllerInterface interface; 305*27b03b36SApple OSS Distributions IOLock *interfaceLock; 306*27b03b36SApple OSS Distributions OSSet *deviceRegistrationList; 307*27b03b36SApple OSS Distributions }; 308*27b03b36SApple OSS Distributions 309*27b03b36SApple OSS Distributions struct IOPerfControlClientData { 310*27b03b36SApple OSS Distributions struct thread_group *target_thread_group; 311*27b03b36SApple OSS Distributions PerfControllerInterface::DriverState driverState; 312*27b03b36SApple OSS Distributions IOService* device; 313*27b03b36SApple OSS Distributions }; 314*27b03b36SApple OSS Distributions /*! 315*27b03b36SApple OSS Distributions * @function registerPerformanceController 316*27b03b36SApple OSS Distributions * @abstract Register a performance controller to receive callbacks. Not for general driver use. 317*27b03b36SApple OSS Distributions * @param interface Struct containing callback functions implemented by the performance controller. 318*27b03b36SApple OSS Distributions * @returns kIOReturnSuccess or kIOReturnError if the interface was already registered. 319*27b03b36SApple OSS Distributions */ 320*27b03b36SApple OSS Distributions virtual IOReturn registerPerformanceController(PerfControllerInterface *interface); 321*27b03b36SApple OSS Distributions 322*27b03b36SApple OSS Distributions /*! 323*27b03b36SApple OSS Distributions * @function getClientData 324*27b03b36SApple OSS Distributions * @abstract Not for general driver use. Only used by registerPerformanceController(). Allows performanceController to register existing IOPerfControlClient. 325*27b03b36SApple OSS Distributions * @returns IOPerfControlData associated with a IOPerfControlClient 326*27b03b36SApple OSS Distributions */ 327*27b03b36SApple OSS Distributions IOPerfControlClientData * getClientData()328*27b03b36SApple OSS Distributions getClientData() 329*27b03b36SApple OSS Distributions { 330*27b03b36SApple OSS Distributions return &clientData; 331*27b03b36SApple OSS Distributions } 332*27b03b36SApple OSS Distributions 333*27b03b36SApple OSS Distributions private: 334*27b03b36SApple OSS Distributions struct WorkTableEntry { 335*27b03b36SApple OSS Distributions struct thread_group *thread_group; 336*27b03b36SApple OSS Distributions bool started; 337*27b03b36SApple OSS Distributions uint8_t perfcontrol_data[32]; 338*27b03b36SApple OSS Distributions }; 339*27b03b36SApple OSS Distributions 340*27b03b36SApple OSS Distributions static constexpr size_t kMaxWorkTableNumEntries = 1024; 341*27b03b36SApple OSS Distributions static constexpr size_t kWorkTableIndexBits = 24; 342*27b03b36SApple OSS Distributions static constexpr size_t kWorkTableMaxSize = (1 << kWorkTableIndexBits) - 1; // - 1 since 343*27b03b36SApple OSS Distributions // kIOPerfControlClientWorkUntracked takes number 0 344*27b03b36SApple OSS Distributions static constexpr size_t kWorkTableIndexMask = (const size_t)mask(kWorkTableIndexBits); 345*27b03b36SApple OSS Distributions 346*27b03b36SApple OSS Distributions uint64_t allocateToken(thread_group *thread_group); 347*27b03b36SApple OSS Distributions void deallocateToken(uint64_t token); 348*27b03b36SApple OSS Distributions WorkTableEntry *getEntryForToken(uint64_t token); 349*27b03b36SApple OSS Distributions void markEntryStarted(uint64_t token, bool started); 350*27b03b36SApple OSS Distributions inline uint64_t tokenToGlobalUniqueToken(uint64_t token); 351*27b03b36SApple OSS Distributions 352*27b03b36SApple OSS Distributions uint8_t driverIndex; 353*27b03b36SApple OSS Distributions IOPerfControlClientShared *shared; 354*27b03b36SApple OSS Distributions WorkTableEntry *workTable; 355*27b03b36SApple OSS Distributions size_t workTableLength; 356*27b03b36SApple OSS Distributions size_t workTableNextIndex; 357*27b03b36SApple OSS Distributions IOSimpleLock *workTableLock; 358*27b03b36SApple OSS Distributions 359*27b03b36SApple OSS Distributions IOPerfControlClientData clientData; 360*27b03b36SApple OSS Distributions }; 361*27b03b36SApple OSS Distributions 362*27b03b36SApple OSS Distributions #endif /* __cplusplus */ 363*27b03b36SApple OSS Distributions #endif /* KERNEL_PRIVATE */ 364