2 * Copyright (c) 1998-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@
29 * Copyright (c) 1998 Apple Inc. All rights reserved.
36 #ifndef _IOKIT_IOCATALOGUE_H
37 #define _IOKIT_IOCATALOGUE_H
39 #include <libkern/c++/OSObject.h>
40 #include <libkern/c++/OSCollectionIterator.h>
41 #include <libkern/c++/OSArray.h>
42 #include <libkern/c++/OSDictionary.h>
43 #include <IOKit/IOLocks.h>
44 #include <sys/cdefs.h>
46 #include <IOKit/IOKitServer.h>
50 extern const OSSymbol
* gIOModuleIdentifierKey
;
51 extern const OSSymbol
* gIOModuleIdentifierKernelKey
;
56 * @abstract In-kernel database for IOKit driver personalities.
57 * @discussion The IOCatalogue is a database which contains all IOKit driver personalities. IOService uses this resource when matching devices to their associated drivers.
59 class IOCatalogue
: public OSObject
61 OSDeclareDefaultStructors(IOCatalogue
);
66 OSDictionary
* personalities
;
67 OSArray
* arrayForPersonality(OSDictionary
* dict
);
68 void addPersonality(OSDictionary
* dict
);
72 * @function initialize
73 * @abstract Creates and initializes the database object and poputates it with in-kernel driver personalities.
75 static void initialize( void );
79 * @abstract Initializes the database object.
80 * @param initArray The initial array of driver personalities to populate the database.
82 bool init( OSArray
* initArray
);
86 * @abstract Cleans up the database and deallocates memory allocated at initialization. This is never called in normal operation of the system.
88 void free( void ) APPLE_KEXT_OVERRIDE
;
91 * @function findDrivers
92 * @abstract This is the primary entry point for IOService.
93 * @param service The service
94 * @param generationCount Returns a reference to the generation count of the database. The generation count increases only when personalities are added to the database *and* IOService matching has been initiated.
95 * @result Returns an ordered set of driver personalities ranked on probe-scores. The ordered set must be released by the receiver.
97 OSOrderedSet
* findDrivers( IOService
* service
, SInt32
* generationCount
);
100 * @function findDrivers
101 * @abstract A more general purpose interface which allows one to retreive driver personalities based the intersection of the 'matching' dictionary and the personality's own property list.
102 * @param matching A dictionary containing only keys and values which are to be used for matching. For example, a matching dictionary containing 'IOProviderClass'='IOPCIDevice' will return all personalities with an IOProviderClass key and a value of IOPCIDevice.
103 * @param generationCount Returns a reference to the current generation of the database. The generation count increases only when personalities are added to the database *and* IOService matching has been initiated.
104 * @result Returns an ordered set of driver personalities ranked on probe-scores. The ordered set must be released by the receiver.
106 OSOrderedSet
* findDrivers( OSDictionary
* matching
, SInt32
* generationCount
);
109 * @function addDrivers
110 * @abstract Adds an array of driver personalities to the database.
111 * @param array Array of driver personalities to be added to the database.
112 * @param doNubMatching Start matching process after personalities have been added.
113 * @result Returns true if driver personality was added to the database successfully. Failure is due to a memory allocation failure.
115 bool addDrivers( OSArray
* array
, bool doNubMatching
= true );
118 * @function removeDrivers
119 * @abstract Remove driver personalities from the database based on matching information provided.
120 * @param matching A dictionary whose keys and values are used for matching personalities in the database. For example, a matching dictionary containing a 'IOProviderClass' key with the value 'IOPCIDevice' will remove all personalities which have the key 'IOProviderClass' equal to 'IOPCIDevice'.
121 * @param doNubMatching Start matching process after personalities have been removed. Matching criteria is based on IOProviderClass of those personalities which were removed. This is to allow drivers which haven't been matched to match against NUB's which were blocked by the previous personalities.
122 * @result Returns true if personality was removed successfully. Failure is due to a memory allocation failure.
124 bool removeDrivers( OSDictionary
* matching
, bool doNubMatching
= true );
127 * @function getGenerationCount
128 * @abstract Get the current generation count of the database.
130 SInt32
getGenerationCount( void ) const;
133 * @function isModuleLoaded
134 * @abstract Reports if a kernel module has been loaded for a particular personality.
135 * @param driver A driver personality's property list.
136 * @param kextRef A reference to the kext getting loaded.
137 * @result Returns true if the associated kernel module has been loaded into the kernel for a particular driver personality on which it depends.
139 bool isModuleLoaded( OSDictionary
* driver
, OSObject
** kextRef
) const;
142 * @function moduleHasLoaded
143 * @abstract Callback function called after a IOKit dependent kernel module is loaded.
144 * @param name Name of the kernel module.
146 void moduleHasLoaded( const OSSymbol
* name
);
149 * @function moduleHasLoaded
150 * @abstract Callback function called after a IOKit dependent kernel module is loaded.
151 * @param name Name of the kernel module.
153 void moduleHasLoaded( const char * name
);
156 * @function terminateDrivers
157 * @abstract Terminates all instances of a driver which match the contents of the matching dictionary. Does not unload module.
158 * @param matching A dictionary whose keys and values are used for matching personalities in the database. For example, a matching dictionary containing a 'IOProviderClass' key with the value 'IOPCIDevice' will cause termination for all instances whose personalities have the key 'IOProviderClass' equal to 'IOPCIDevice'.
160 IOReturn
terminateDrivers( OSDictionary
* matching
);
163 * @function terminateDriversForModule
164 * @abstract Terminates all instances of a driver which depends on a particular module and unloads the module.
165 * @param moduleName Name of the module which is used to determine which driver instances to terminate and unload.
166 * @param unload Flag to cause the actual unloading of the module.
168 IOReturn
terminateDriversForModule( OSString
* moduleName
, bool unload
= true);
171 * @function terminateDriversForModule
172 * @abstract Terminates all instances of a driver which depends on a particular module and unloads the module.
173 * @param moduleName Name of the module which is used to determine which driver instances to terminate and unload.
174 * @param unload Flag to cause the actual unloading of the module.
176 IOReturn
terminateDriversForModule( const char * moduleName
, bool unload
= true);
179 * @function startMatching
180 * @abstract Restarts IOService matching.
181 * @param identifier All IOService objects with this bundle indentifier are rematched.
183 bool startMatching( const OSSymbol
* identifier
);
185 // deprecated, for bin compat
186 #if defined(__i386__) || defined(__x86_64__)
187 bool startMatching( OSDictionary
* matching
);
192 * @abstract Return the Catalogue to its initial state.
194 * Should only be used by kextd just before it sends all kext personalities down during a rescan.
199 * @function resetAndAddDrivers
200 * @abstract Replace personalities in IOCatalog with those provided.
202 * Resets the catalogue with a new set of drivers, preserving matching originals to keep wired memory usage down.
204 bool resetAndAddDrivers(OSArray
* drivers
, bool doNubMatching
= true);
207 * @function serialize
208 * @abstract Serializes the catalog for transport to the user.
209 * @param s The serializer object.
210 * @result Returns false if unable to serialize database, most likely due to memory shortage.
212 virtual bool serialize(OSSerialize
* s
) const APPLE_KEXT_OVERRIDE
;
214 bool serializeData(IOOptionBits kind
, OSSerialize
* s
) const;
216 /* This stuff is no longer used at all we keep it around for i386
217 * binary compatibility only. Symbols are no longer exported.
223 * @function unloadModule
224 * @abstract Unloads the reqested module if no driver instances are currently depending on it.
225 * @param moduleName An OSString containing the name of the module to unload.
227 IOReturn
unloadModule( OSString
* moduleName
) const;
229 IOReturn
_removeDrivers(OSDictionary
* matching
);
230 IOReturn
_terminateDrivers(OSDictionary
* matching
);
233 extern const OSSymbol
* gIOClassKey
;
234 extern const OSSymbol
* gIOProbeScoreKey
;
235 extern IOCatalogue
* gIOCatalogue
;
237 #endif /* ! _IOKIT_IOCATALOGUE_H */