2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
31 #ifndef _IOKIT_IOCATALOGUE_H
32 #define _IOKIT_IOCATALOGUE_H
34 #include <libkern/c++/OSObject.h>
35 #include <libkern/c++/OSCollectionIterator.h>
36 #include <libkern/c++/OSArray.h>
37 #include <libkern/c++/OSDictionary.h>
38 #include <IOKit/IOLocks.h>
39 #include <sys/cdefs.h>
41 #include <IOKit/IOKitServer.h>
47 @abstract In-kernel database for IOKit driver personalities.
48 @discussion The IOCatalogue is a database which contains all IOKit driver personalities. IOService uses this resource when matching devices to their associated drivers.
50 class IOCatalogue
: public OSObject
52 OSDeclareDefaultStructors(IOCatalogue
)
55 OSCollectionIterator
* kernelTables
;
65 @abstract Creates and initializes the database object and poputates it with in-kernel driver personalities.
67 static void initialize( void );
71 @abstract Initializes the database object.
72 @param initArray The initial array of driver personalities to populate the database.
74 bool init( OSArray
* initArray
);
78 @abstract Cleans up the database and deallocates memory allocated at initialization. This is never called in normal operation of the system.
84 @abstract This is the primary entry point for IOService.
86 @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.
87 @result Returns an ordered set of driver personalities ranked on probe-scores. The ordered set must be released by the receiver.
89 OSOrderedSet
* findDrivers( IOService
* service
, SInt32
* generationCount
);
93 @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.
94 @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.
95 @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.
96 @result Returns an ordered set of driver personalities ranked on probe-scores. The ordered set must be released by the receiver.
98 OSOrderedSet
* findDrivers( OSDictionary
* matching
, SInt32
* generationCount
);
102 @abstract Adds an array of driver personalities to the database.
103 @param array Array of driver personalities to be added to the database.
104 @param doNubMatchng Start matching process after personalities have been added.
105 @result Returns true if driver personality was added to the database successfully. Failure is due to a memory allocation failure.
107 bool addDrivers( OSArray
* array
, bool doNubMatching
= true );
110 @function removeDrivers
111 @abstract Remove driver personalities from the database based on matching information provided.
112 @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'.
113 @param doNubMatchng 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.
114 @result Returns true if personality was removed successfully. Failure is due to a memory allocation failure.
116 bool removeDrivers( OSDictionary
* matching
, bool doNubMatching
= true );
119 @function getGenerationCount
120 @abstract Get the current generation count of the database.
122 SInt32
getGenerationCount( void ) const;
125 @function isModuleLoaded
126 @abstract Reports if a kernel module has been loaded.
127 @param moduleName Name of the module.
128 @result Returns true if the associated kernel module has been loaded into the kernel.
130 bool isModuleLoaded( OSString
* moduleName
) const;
133 @function isModuleLoaded
134 @abstract Reports if a kernel module has been loaded.
135 @param moduleName Name of the module.
136 @result Returns true if the associated kernel module has been loaded into the kernel.
138 bool isModuleLoaded( const char * moduleName
) const;
141 @function isModuleLoaded
142 @abstract Reports if a kernel module has been loaded for a particular personality.
143 @param driver A driver personality's property list.
144 @result Returns true if the associated kernel module has been loaded into the kernel for a particular driver personality on which it depends.
146 bool isModuleLoaded( OSDictionary
* driver
) const;
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( OSString
* name
);
156 @function moduleHasLoaded
157 @abstract Callback function called after a IOKit dependent kernel module is loaded.
158 @param name Name of the kernel module.
160 void moduleHasLoaded( const char * name
);
163 @function terminateDrivers
164 @abstract Terminates all instances of a driver which match the contents of the matching dictionary. Does not unload module.
165 @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'.
167 IOReturn
terminateDrivers( OSDictionary
* matching
);
170 @function terminateDriversForModule
171 @abstract Terminates all instances of a driver which depends on a particular module and unloads the module.
172 @param moduleName Name of the module which is used to determine which driver instances to terminate and unload.
173 @param unload Flag to cause the actual unloading of the module.
175 IOReturn
terminateDriversForModule( OSString
* moduleName
, bool unload
= true);
178 @function terminateDriversForModule
179 @abstract Terminates all instances of a driver which depends on a particular module and unloads the module.
180 @param moduleName Name of the module which is used to determine which driver instances to terminate and unload.
181 @param unload Flag to cause the actual unloading of the module.
183 IOReturn
terminateDriversForModule( const char * moduleName
, bool unload
= true);
186 @function startMatching
187 @abstract Starts an IOService matching thread where matching keys and values are provided by the matching dictionary.
188 @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 start matching for all personalities which have the key 'IOProviderClass' equal to 'IOPCIDevice'.
190 bool startMatching( OSDictionary
* matching
);
194 @abstract Return the Catalogue to its initial state.
200 @abstract Serializes the catalog for transport to the user.
201 @param s The serializer object.
202 @result Returns false if unable to serialize database, most likely due to memory shortage.
204 virtual bool serialize(OSSerialize
* s
) const;
206 bool serializeData(IOOptionBits kind
, OSSerialize
* s
) const;
209 @function recordStartupExtensions
210 @abstract Records extensions made available by the primary booter.
212 This function is for internal use by the kernel startup linker.
213 Kernel extensions should never call it.
214 @result Returns true if startup extensions were successfully recorded,
217 virtual bool recordStartupExtensions(void);
220 @function addExtensionsFromArchive()
221 @abstract Records an archive of extensions, as from device ROM.
223 This function is currently for internal use.
224 Kernel extensions should never call it.
225 @param mkext An OSData object containing a multikext archive.
226 @result Returns true if mkext was properly unserialized and its
227 contents recorded, false if not.
229 virtual bool addExtensionsFromArchive(OSData
* mkext
);
233 @function removeKernelLinker
234 @abstract Removes from memory all code and data related to
235 boot-time loading of kernel extensions. kextd triggers
236 this when it first starts in order to pass responsibility
237 for loading extensions from the kernel itself to kextd.
238 @result Returns KERN_SUCCESS if the kernel linker is successfully
239 removed or wasn't present, KERN_FAILURE otherwise.
241 virtual kern_return_t
removeKernelLinker(void);
243 static void disableExternalLinker(void);
248 @function unloadModule
249 @abstract Unloads the reqested module if no driver instances are currently depending on it.
250 @param moduleName An OSString containing the name of the module to unload.
252 IOReturn
unloadModule( OSString
* moduleName
) const;
257 @function IOKitRelocStart
258 @abstract Deprecated API.
260 kmod_start_func_t IOKitRelocStart
;
262 @function IOKitRelocStop
263 @abstract Deprecated API.
265 kmod_stop_func_t IOKitRelocStop
;
268 extern const OSSymbol
* gIOClassKey
;
269 extern const OSSymbol
* gIOProbeScoreKey
;
270 extern IOCatalogue
* gIOCatalogue
;
272 #endif /* ! _IOKIT_IOCATALOGUE_H */