1*0f4c859eSApple OSS Distributions/* 2*0f4c859eSApple OSS Distributions * Copyright (c) 2019-2019 Apple Inc. All rights reserved. 3*0f4c859eSApple OSS Distributions * 4*0f4c859eSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*0f4c859eSApple OSS Distributions * 6*0f4c859eSApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7*0f4c859eSApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8*0f4c859eSApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9*0f4c859eSApple OSS Distributions * compliance with the License. The rights granted to you under the License 10*0f4c859eSApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11*0f4c859eSApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12*0f4c859eSApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13*0f4c859eSApple OSS Distributions * terms of an Apple operating system software license agreement. 14*0f4c859eSApple OSS Distributions * 15*0f4c859eSApple OSS Distributions * Please obtain a copy of the License at 16*0f4c859eSApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17*0f4c859eSApple OSS Distributions * 18*0f4c859eSApple OSS Distributions * The Original Code and all software distributed under the License are 19*0f4c859eSApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*0f4c859eSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*0f4c859eSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*0f4c859eSApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*0f4c859eSApple OSS Distributions * Please see the License for the specific language governing rights and 24*0f4c859eSApple OSS Distributions * limitations under the License. 25*0f4c859eSApple OSS Distributions * 26*0f4c859eSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*0f4c859eSApple OSS Distributions */ 28*0f4c859eSApple OSS Distributions 29*0f4c859eSApple OSS Distributions#ifndef _IOKIT_UIOINTERRUPTDISPATCHSOURCE_H 30*0f4c859eSApple OSS Distributions#define _IOKIT_UIOINTERRUPTDISPATCHSOURCE_H 31*0f4c859eSApple OSS Distributions 32*0f4c859eSApple OSS Distributions#include <DriverKit/IODispatchQueue.iig> 33*0f4c859eSApple OSS Distributions#include <DriverKit/IOService.iig> 34*0f4c859eSApple OSS Distributions 35*0f4c859eSApple OSS Distributionsstruct IOInterruptDispatchSourcePayload { 36*0f4c859eSApple OSS Distributions uint64_t time; 37*0f4c859eSApple OSS Distributions uint64_t count; 38*0f4c859eSApple OSS Distributions}; 39*0f4c859eSApple OSS Distributions 40*0f4c859eSApple OSS Distributionsenum { 41*0f4c859eSApple OSS Distributions kIOInterruptDispatchSourceTypeEdge = 0x00000000, 42*0f4c859eSApple OSS Distributions kIOInterruptDispatchSourceTypeLevel = 0x00000001 43*0f4c859eSApple OSS Distributions}; 44*0f4c859eSApple OSS Distributions 45*0f4c859eSApple OSS Distributionsenum { 46*0f4c859eSApple OSS Distributions kIOInterruptSourceIndexMask = 0x0000FFFF, 47*0f4c859eSApple OSS Distributions kIOInterruptSourceAbsoluteTime = 0x00000000, 48*0f4c859eSApple OSS Distributions kIOInterruptSourceContinuousTime = 0x00010000 49*0f4c859eSApple OSS Distributions}; 50*0f4c859eSApple OSS Distributions 51*0f4c859eSApple OSS Distributions/*! 52*0f4c859eSApple OSS Distributions * @class IOInterruptDispatchSource 53*0f4c859eSApple OSS Distributions * 54*0f4c859eSApple OSS Distributions * @abstract 55*0f4c859eSApple OSS Distributions * IOInterruptDispatchSource delivers interrupts to a handler block on a dispatch queue. 56*0f4c859eSApple OSS Distributions * 57*0f4c859eSApple OSS Distributions * @discussion 58*0f4c859eSApple OSS Distributions * A driver can run code in response to an interrupt from a device, specified as an IOService 59*0f4c859eSApple OSS Distributions * and index. The code runs at normal thread level, but is notified with the mach_absolute_time 60*0f4c859eSApple OSS Distributions * the primary interrupt fired. For IOPCIDevices, only MSI interrupt sources are supported. 61*0f4c859eSApple OSS Distributions */ 62*0f4c859eSApple OSS Distributions 63*0f4c859eSApple OSS Distributionsclass NATIVE KERNEL IOInterruptDispatchSource : public IODispatchSource 64*0f4c859eSApple OSS Distributions{ 65*0f4c859eSApple OSS Distributionspublic: 66*0f4c859eSApple OSS Distributions 67*0f4c859eSApple OSS Distributions /*! 68*0f4c859eSApple OSS Distributions * @brief Create an IOInterruptDispatchSource for an interrupt by index from an IOService provider. 69*0f4c859eSApple OSS Distributions * @param provider The IOService object representing the HW device producing the interrupt. 70*0f4c859eSApple OSS Distributions * @param index Index for the interrupt, optionally or'ed with one of the following constants: 71*0f4c859eSApple OSS Distributions kIOInterruptSourceContinuousTime time values sent to the InterruptOccurred() method will be in mach_continuous_time() units. 72*0f4c859eSApple OSS Distributions * @param queue Target queue to run the handler block. 73*0f4c859eSApple OSS Distributions * @param source Created source with +1 retain count to be released by the caller. 74*0f4c859eSApple OSS Distributions * @return kIOReturnSuccess on success. See IOReturn.h for error codes. 75*0f4c859eSApple OSS Distributions */ 76*0f4c859eSApple OSS Distributions static kern_return_t 77*0f4c859eSApple OSS Distributions Create(IOService * provider, 78*0f4c859eSApple OSS Distributions uint32_t index, 79*0f4c859eSApple OSS Distributions IODispatchQueue * queue, 80*0f4c859eSApple OSS Distributions IOInterruptDispatchSource ** source) LOCAL; 81*0f4c859eSApple OSS Distributions 82*0f4c859eSApple OSS Distributions /*! 83*0f4c859eSApple OSS Distributions * @brief Returns the type of interrupt used for a device supplying hardware interrupts, by index from an IOService provider. 84*0f4c859eSApple OSS Distributions * @param provider The IOService object representing the HW device producing the interrupt. 85*0f4c859eSApple OSS Distributions * @param index Index for the interrupt. 86*0f4c859eSApple OSS Distributions * @param interruptType The interrupt type for the interrupt source will be stored here. 87*0f4c859eSApple OSS Distributions * kIOInterruptTypeEdge will be returned for edge-trigggered sources. 88*0f4c859eSApple OSS Distributions * kIOInterruptTypeLevel will be returned for level-trigggered sources. 89*0f4c859eSApple OSS Distributions * Other flags may be returned depending on the provider, for example PCI flags for messaged interrupts. 90*0f4c859eSApple OSS Distributions * @return kIOReturnSuccess on success. See IOReturn.h for error codes. 91*0f4c859eSApple OSS Distributions */ 92*0f4c859eSApple OSS Distributions 93*0f4c859eSApple OSS Distributions static kern_return_t 94*0f4c859eSApple OSS Distributions GetInterruptType(IOService * provider, 95*0f4c859eSApple OSS Distributions uint32_t index, 96*0f4c859eSApple OSS Distributions uint64_t * interruptType); 97*0f4c859eSApple OSS Distributions 98*0f4c859eSApple OSS Distributions virtual bool 99*0f4c859eSApple OSS Distributions init() override; 100*0f4c859eSApple OSS Distributions 101*0f4c859eSApple OSS Distributions virtual void 102*0f4c859eSApple OSS Distributions free() override; 103*0f4c859eSApple OSS Distributions 104*0f4c859eSApple OSS Distributions /*! 105*0f4c859eSApple OSS Distributions * @brief Set the handler block to run when the interupt fires. 106*0f4c859eSApple OSS Distributions * @param action OSAction instance specifying the callback method. The OSAction object will be retained 107*0f4c859eSApple OSS Distributions * until SetHandler is called again or the event source is cancelled. 108*0f4c859eSApple OSS Distributions * @return kIOReturnSuccess on success. See IOReturn.h for error codes. 109*0f4c859eSApple OSS Distributions */ 110*0f4c859eSApple OSS Distributions virtual kern_return_t 111*0f4c859eSApple OSS Distributions SetHandler( 112*0f4c859eSApple OSS Distributions OSAction * action TYPE(InterruptOccurred)) LOCAL; 113*0f4c859eSApple OSS Distributions 114*0f4c859eSApple OSS Distributions /*! 115*0f4c859eSApple OSS Distributions * @brief Control the enable state of the interrupt source. 116*0f4c859eSApple OSS Distributions * @param enable Pass true to enable the source or false to disable. 117*0f4c859eSApple OSS Distributions * @param handler Optional block to be executed after the interrupt has been disabled and any pending 118*0f4c859eSApple OSS Distributions * interrupt handlers completed. 119*0f4c859eSApple OSS Distributions * @return kIOReturnSuccess on success. See IOReturn.h for error codes. 120*0f4c859eSApple OSS Distributions */ 121*0f4c859eSApple OSS Distributions virtual kern_return_t 122*0f4c859eSApple OSS Distributions SetEnableWithCompletion( 123*0f4c859eSApple OSS Distributions bool enable, 124*0f4c859eSApple OSS Distributions IODispatchSourceCancelHandler handler) override LOCAL; 125*0f4c859eSApple OSS Distributions 126*0f4c859eSApple OSS Distributions /*! 127*0f4c859eSApple OSS Distributions * @brief Cancel all callbacks from the event source. 128*0f4c859eSApple OSS Distributions * @discussion After cancellation, the source can only be freed. It cannot be reactivated. 129*0f4c859eSApple OSS Distributions * @param handler Handler block to be invoked after any callbacks have completed. 130*0f4c859eSApple OSS Distributions * @return kIOReturnSuccess on success. See IOReturn.h for error codes. 131*0f4c859eSApple OSS Distributions */ 132*0f4c859eSApple OSS Distributions virtual kern_return_t 133*0f4c859eSApple OSS Distributions Cancel(IODispatchSourceCancelHandler handler) override LOCAL; 134*0f4c859eSApple OSS Distributions 135*0f4c859eSApple OSS Distributions /*! 136*0f4c859eSApple OSS Distributions * @brief Get the count and time of the last interrupt received by the kernel 137*0f4c859eSApple OSS Distributions primary interrupt handler. 138*0f4c859eSApple OSS Distributions * @param count Interrupt count. 139*0f4c859eSApple OSS Distributions * @param time Interrupt time. 140*0f4c859eSApple OSS Distributions * @return kIOReturnSuccess on success. See IOReturn.h for error codes. 141*0f4c859eSApple OSS Distributions */ 142*0f4c859eSApple OSS Distributions virtual kern_return_t 143*0f4c859eSApple OSS Distributions GetLastInterrupt( 144*0f4c859eSApple OSS Distributions uint64_t * count, 145*0f4c859eSApple OSS Distributions uint64_t * time); 146*0f4c859eSApple OSS Distributions 147*0f4c859eSApple OSS Distributionsprivate: 148*0f4c859eSApple OSS Distributions virtual kern_return_t 149*0f4c859eSApple OSS Distributions CheckForWork(bool synchronous) override LOCAL; 150*0f4c859eSApple OSS Distributions 151*0f4c859eSApple OSS Distributions virtual void 152*0f4c859eSApple OSS Distributions InterruptOccurred( 153*0f4c859eSApple OSS Distributions OSAction * action TARGET, 154*0f4c859eSApple OSS Distributions uint64_t count, 155*0f4c859eSApple OSS Distributions uint64_t time) REPLY LOCAL; 156*0f4c859eSApple OSS Distributions}; 157*0f4c859eSApple OSS Distributions 158*0f4c859eSApple OSS Distributions#endif /* ! _IOKIT_UIOINTERRUPTDISPATCHSOURCE_H */ 159