2 * Copyright (c) 2019-2019 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
31 #include <IOKit/IOService.h>
35 #ifndef _IOKIT_UIOSERVICE_H
36 #define _IOKIT_UIOSERVICE_H
38 #include <DriverKit/OSObject.iig>
40 class IOMemoryDescriptor;
41 class IOBufferMemoryDescriptor;
44 typedef char IOServiceName[128];
45 typedef char IOPropertyName[128];
46 typedef char IORegistryPlaneName[128];
49 kIOServiceSearchPropertyParents = 0x00000001,
52 #define kIOServiceDefaultQueueName "Default"
55 kIOServicePowerCapabilityOff = 0x00000000,
56 kIOServicePowerCapabilityOn = 0x00000002,
57 kIOServicePowerCapabilityLow = 0x00010000,
64 * IOService represents an device or OS service in IOKit and DriverKit.
67 * IOKit provides driver lifecycle management through the IOService APIs.
68 * Drivers and devices are represented as subclasses of IOService.
72 #include <DriverKit/IOUserClient.h>
76 class KERNEL IOService : public OSObject
86 * @brief First call made to a matched IOService.
87 * @discussion During matching IOKit will create an IOService object for successful matches.
88 * Start is the first call made to the new object.
89 * @param provider The IOService provider for the match. This should be OSRequiredCast to the expected class.
90 * The provider is retained by DriverKit for the duration of Start() and on successful Start() until
91 * IOService::Stop() is called.
92 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
95 Start(IOService * provider) LOCAL;
98 * @brief Terminate access to provider.
99 * @discussion During termination IOKit will teardown any IOService objects attached to a terminated provider.
100 * Stop should quiesce all activity and when complete, pass the call to super. After calling super, the
101 * provider is no longer valid and this object will likely be freed.
102 * @param provider The IOService provider for being terminated, one previously passed to Start
103 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
105 virtual kern_return_t
106 Stop(IOService * provider) LOCAL;
109 * @brief Obtain IOKit IORegistryEntryID.
110 * @param registryEntryID IORegistryEntryID for the IOKit object.
111 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
113 virtual kern_return_t
114 GetRegistryEntryID(uint64_t * registryEntryID) LOCAL;
117 * @brief Set the IORegistryEntry name.
118 * @param name Name for the IOKit object. The c-string will be copied.
119 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
121 virtual kern_return_t
123 const IOServiceName name);
126 * @brief Start the matching process on the IOService object.
127 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
129 virtual kern_return_t
133 * @brief Set the IODispatchQueue for a given name on the IOService.
134 * @param name Name for the queue. The name may be referenced by methods in the .iig class definition
135 * with the QUEUENAME() attribute to indicate the method must be invoked on that queue. If a method
136 * is invoked before the queue is set for the name, the default queue is used. A default queue is
137 * created by DriverKit for every new IOService object with the name kIOServiceDefaultQueueName.
138 * @param queue Queue to be associated with the name on this IOService.
139 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
141 virtual kern_return_t
143 const IODispatchQueueName name,
144 IODispatchQueue * queue) override LOCAL;
147 * @brief Obtain the IODispatchQueue for a given name on the IOService.
148 * @param name Name for the queue.
149 * @param queue Returned, retained queue or NULL. The caller should release this queue.
150 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
152 virtual kern_return_t
154 const IODispatchQueueName name,
155 IODispatchQueue ** queue) override;
158 * @brief Obtain the IOKit registry properties for the IOService.
159 * @param properties Returned, retained dictionary of properties or NULL. The caller should release this dictionary.
160 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
162 virtual kern_return_t
164 OSDictionary ** properties);
167 * @brief Obtain the an IOKit registry properties from the service or one of its parents.
168 * @param name Name of the property as a c-string.
169 * @param plane Name of the registry plane to be searched, if the option kIOServiceSearchPropertyParents
171 * @param options Pass kIOServiceSearchPropertyParents to search for the property in the IOService and all
172 * its parents in the IOKit registry.
173 * @param property Returned, retained property object or NULL. The caller should release this property.
174 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
176 virtual kern_return_t
178 const IOPropertyName name,
179 const IORegistryPlaneName plane,
181 OSContainer ** property);
184 * @brief Send a dictionary of properties to an IOService.
185 * @discussion By default the method will fail. A DriverKit subclass or kernel class may implement this method.
186 * @param properties Dictionary of properties.
187 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
189 virtual kern_return_t
191 OSDictionary * properties);
194 * @brief Notification of change in power state of a provider.
195 * @discussion DriverKit notifies of changes in power of a provider. The driver should make itself safe for
196 * the new state before passing the call to super.
197 * @param powerFlags The power capabilities of the new state. The values possible are:
198 * kIOServicePowerCapabilityOff the system will be entering sleep state
199 * kIOServicePowerCapabilityOn the device and system are fully powered
200 * kIOServicePowerCapabilityLow the device is in a reduced power state while the system is running
201 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
203 virtual kern_return_t
205 uint32_t powerFlags) LOCAL;
208 * @brief Allow provider to enter a low power state.
209 * @discussion A driver may allow a device to enter a lower power state.
210 * @param powerFlags The power capabilities of the new state. The values possible are:
211 * kIOServicePowerCapabilityLow the device is in a reduced power state while the system is running
212 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
214 virtual kern_return_t
216 uint32_t powerFlags);
219 * @brief Request create a new user client for a client process.
220 * @discussion An application may request an IOUserClient be opened with the IOKit framework
221 * IOServiceOpen() call. The type parameter of that call is passed here. The driver should respond to
222 * the call by calling IOService::Create() with a plist entry describing the new user client object.
223 * @param type The type passed to IOServiceOpen().
224 * @param userClient The object created by IOService::Create()
225 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
227 virtual kern_return_t
230 IOUserClient ** userClient);
233 * @brief Request to create an IOService object from a plist property.
234 * @discussion An IOService interface or IOUserClient subclass may be created from a plist property of the driver.
235 * The plist should contain the following IOKit matching keys:
236 * IOClass - kernel class of IOUserUserClient
237 * IOUserClass - DriverKit class to be instantiated
238 * IOServiceDEXTEntitlements - Array of entitlements to be checked against a user client owning task
239 * @param provider The provider of the new object.
240 * @param propertiesKey The name of the properties dictionary in this IOService
241 * @param result The created object retained, to be released by the caller.
242 * @return kIOReturnSuccess on success. See IOReturn.h for error codes.
244 virtual kern_return_t
246 IOService * provider,
247 const IOPropertyName propertiesKey,
248 IOService ** result);
251 #endif /* ! _IOKIT_UIOSERVICE_H */