xref: /xnu-8792.61.2/iokit/DriverKit/IOWorkGroup.iig (revision 42e220869062b56f8d7d0726fd4c88954f87902c)
1*42e22086SApple OSS Distributions/*
2*42e22086SApple OSS Distributions * Copyright (c) 2021 Apple Inc. All rights reserved.
3*42e22086SApple OSS Distributions *
4*42e22086SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*42e22086SApple OSS Distributions *
6*42e22086SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7*42e22086SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8*42e22086SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9*42e22086SApple OSS Distributions * compliance with the License. The rights granted to you under the License
10*42e22086SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
11*42e22086SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
12*42e22086SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
13*42e22086SApple OSS Distributions * terms of an Apple operating system software license agreement.
14*42e22086SApple OSS Distributions *
15*42e22086SApple OSS Distributions * Please obtain a copy of the License at
16*42e22086SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*42e22086SApple OSS Distributions *
18*42e22086SApple OSS Distributions * The Original Code and all software distributed under the License are
19*42e22086SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*42e22086SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*42e22086SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*42e22086SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*42e22086SApple OSS Distributions * Please see the License for the specific language governing rights and
24*42e22086SApple OSS Distributions * limitations under the License.
25*42e22086SApple OSS Distributions *
26*42e22086SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*42e22086SApple OSS Distributions */
28*42e22086SApple OSS Distributions
29*42e22086SApple OSS Distributions#ifndef _IOKIT_UIOWORKGROUP_H
30*42e22086SApple OSS Distributions#define _IOKIT_UIOWORKGROUP_H
31*42e22086SApple OSS Distributions
32*42e22086SApple OSS Distributions#include <DriverKit/OSObject.iig>
33*42e22086SApple OSS Distributions#include <DriverKit/IOUserClient.iig>
34*42e22086SApple OSS Distributions
35*42e22086SApple OSS Distributionsenum {
36*42e22086SApple OSS Distributions	kIOWorkGroupMaxNameLength = 64,
37*42e22086SApple OSS Distributions};
38*42e22086SApple OSS Distributions
39*42e22086SApple OSS Distributions/*!
40*42e22086SApple OSS Distributions * @class IOWorkGroup
41*42e22086SApple OSS Distributions *
42*42e22086SApple OSS Distributions * @abstract
43*42e22086SApple OSS Distributions * Workgroups allow multiple threads to coordinate activities for realtime operations.
44*42e22086SApple OSS Distributions *
45*42e22086SApple OSS Distributions * @discussion
46*42e22086SApple OSS Distributions *
47*42e22086SApple OSS Distributions * Applications that open user clients to a DriverKit driver can send a workgroup to use in the driver.
48*42e22086SApple OSS Distributions *
49*42e22086SApple OSS Distributions * The application will have to first create an workgroup object. The application then should copy the
50*42e22086SApple OSS Distributions * workgroup port with os_workgroup_copy_port(). To send the workgroup port to the driver, use:
51*42e22086SApple OSS Distributions *
52*42e22086SApple OSS Distributions * const char * name = "Work Group Name"; // This must match the name the driver used in IOWorkGroup::Create().
53*42e22086SApple OSS Distributions * kern_return_t ret = IOConnectTrap3(connect, // user client connection (io_connect_t)
54*42e22086SApple OSS Distributions *                                    1, // specifies event link configuration trap
55*42e22086SApple OSS Distributions *                                    (uintptr_t)name,
56*42e22086SApple OSS Distributions *                                    (uintptr_t)strlen(name),
57*42e22086SApple OSS Distributions *                                    (uintptr_t)wgPort // port from os_workgroup_copy_port
58*42e22086SApple OSS Distributions *                                    );
59*42e22086SApple OSS Distributions *
60*42e22086SApple OSS Distributions * Once the workgroup port has been sent to the driver, the driver should be notified with a user-defined external method
61*42e22086SApple OSS Distributions * or other existing signaling mechanism.
62*42e22086SApple OSS Distributions */
63*42e22086SApple OSS Distributionsclass NATIVE KERNEL IOWorkGroup : public OSObject
64*42e22086SApple OSS Distributions{
65*42e22086SApple OSS Distributionspublic:
66*42e22086SApple OSS Distributions
67*42e22086SApple OSS Distributions	virtual bool
68*42e22086SApple OSS Distributions	init() override;
69*42e22086SApple OSS Distributions
70*42e22086SApple OSS Distributions	virtual void
71*42e22086SApple OSS Distributions	free() override;
72*42e22086SApple OSS Distributions
73*42e22086SApple OSS Distributions    /*!
74*42e22086SApple OSS Distributions     * @brief       Create an IOWorkGroup object. This object is not functional until a workgroup port has been set.
75*42e22086SApple OSS Distributions     * @param       name        Name of the workgroup
76*42e22086SApple OSS Distributions     * @param       userClient  Userclient to create the workgroup in. The DriverKit runtime will retain the userclient, and will
77*42e22086SApple OSS Distributions     *                          release it in Invalidate() or when the IOWorkGroup is freed.
78*42e22086SApple OSS Distributions     * @param       workgroup   Created IOWorkGroup with +1 retain count to be released by the caller.
79*42e22086SApple OSS Distributions     * @return      kIOReturnSuccess on success. See IOReturn.h for error codes.
80*42e22086SApple OSS Distributions     */
81*42e22086SApple OSS Distributions	static kern_return_t
82*42e22086SApple OSS Distributions	Create(OSString * name, IOUserClient * userClient, IOWorkGroup ** workgroup) LOCAL;
83*42e22086SApple OSS Distributions
84*42e22086SApple OSS Distributions#if DRIVERKIT_PRIVATE
85*42e22086SApple OSS Distributions
86*42e22086SApple OSS Distributions    /*!
87*42e22086SApple OSS Distributions     * @brief       Set the port for this workgroup. This should not be called directly.
88*42e22086SApple OSS Distributions     * @param       port Workgroup port
89*42e22086SApple OSS Distributions     * @return      kIOReturnSuccess on success. See IOReturn.h for error codes.
90*42e22086SApple OSS Distributions     */
91*42e22086SApple OSS Distributions    virtual kern_return_t
92*42e22086SApple OSS Distributions    SetWorkGroupPort(mach_port_t port PORTCOPYSEND) LOCAL;
93*42e22086SApple OSS Distributions
94*42e22086SApple OSS Distributions#endif /* DRIVERKIT_PRIVATE */
95*42e22086SApple OSS Distributions
96*42e22086SApple OSS Distributions    /*!
97*42e22086SApple OSS Distributions     * @brief       Get the size of the workgroup token.
98*42e22086SApple OSS Distributions     * @discussion  Join() and Leave() require the caller to pass a token. This token should be allocated by the caller, and freed when
99*42e22086SApple OSS Distributions     *              no longer needed. Use this method to determine how much memory to allocate for the token.
100*42e22086SApple OSS Distributions     * @return      Workgroup token size
101*42e22086SApple OSS Distributions     */
102*42e22086SApple OSS Distributions    size_t
103*42e22086SApple OSS Distributions    GetTokenSize() LOCALONLY;
104*42e22086SApple OSS Distributions
105*42e22086SApple OSS Distributions    /*!
106*42e22086SApple OSS Distributions     * @brief       Join the workgroup.
107*42e22086SApple OSS Distributions     * @discussion  Before calling this method, the caller must allocate a token. This token must be passed to this method. When leaving
108*42e22086SApple OSS Distributions     *              a workgroup with Leave(), use the same token that was passed to Join().
109*42e22086SApple OSS Distributions     * @param       token  The workgroup token.
110*42e22086SApple OSS Distributions     * @return      kIOReturnSuccess on success. See IOReturn.h for error codes.
111*42e22086SApple OSS Distributions     */
112*42e22086SApple OSS Distributions    kern_return_t
113*42e22086SApple OSS Distributions    Join(void * token) LOCALONLY;
114*42e22086SApple OSS Distributions
115*42e22086SApple OSS Distributions    /*!
116*42e22086SApple OSS Distributions     * @brief       Leave the workgroup.
117*42e22086SApple OSS Distributions     * @discussion  The workgroup must have been joined with Join(). Use the same token in Join() for this method.
118*42e22086SApple OSS Distributions     * @param       token  The workgroup token.
119*42e22086SApple OSS Distributions     * @return      kIOReturnSuccess on success. See IOReturn.h for error codes.
120*42e22086SApple OSS Distributions     */
121*42e22086SApple OSS Distributions    kern_return_t
122*42e22086SApple OSS Distributions    Leave(void * token) LOCALONLY;
123*42e22086SApple OSS Distributions
124*42e22086SApple OSS Distributions    /*!
125*42e22086SApple OSS Distributions     * @brief       Invalidate the IOWorkGroup.
126*42e22086SApple OSS Distributions     * @discussion  This releases the kernel reference to the IOWorkGroup, allowing the name to be used for a different
127*42e22086SApple OSS Distributions     *              IOWorkGroup. This method should be called after the client has configured the eventlink with the IOConnectTrap
128*42e22086SApple OSS Distributions     *              call. After invalidation, the IOWorkGroup can no longer be configured through the IOConnectTrap call. No other
129*42e22086SApple OSS Distributions     *              functionality is affected.
130*42e22086SApple OSS Distributions     * @return      kIOReturnSuccess on success. See IOReturn.h for error codes.
131*42e22086SApple OSS Distributions     */
132*42e22086SApple OSS Distributions    kern_return_t
133*42e22086SApple OSS Distributions    Invalidate() LOCALONLY;
134*42e22086SApple OSS Distributions
135*42e22086SApple OSS Distributions#if DRIVERKIT_PRIVATE
136*42e22086SApple OSS Distributions
137*42e22086SApple OSS Distributions    virtual kern_return_t
138*42e22086SApple OSS Distributions    InvalidateKernel(IOUserClient * client);
139*42e22086SApple OSS Distributions
140*42e22086SApple OSS Distributions#endif /* DRIVERKIT_PRIVATE */
141*42e22086SApple OSS Distributions
142*42e22086SApple OSS Distributions};
143*42e22086SApple OSS Distributions
144*42e22086SApple OSS Distributions#endif /* ! _IOKIT_UIOWORKGROUP_H */
145