2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
30 #ifndef _IOKIT_IOCATALOGUE_H
31 #define _IOKIT_IOCATALOGUE_H
33 #include <libkern/c++/OSObject.h>
34 #include <libkern/c++/OSCollectionIterator.h>
35 #include <libkern/c++/OSArray.h>
36 #include <libkern/c++/OSDictionary.h>
37 #include <IOKit/IOLocks.h>
38 #include <sys/cdefs.h>
40 #include <IOKit/IOKitServer.h>
46 @abstract In-kernel database for IOKit driver personalities.
47 @discussion The IOCatalogue is a database which contains all IOKit driver personalities. IOService uses this resource when matching devices to their associated drivers.
49 class IOCatalogue
: public OSObject
51 OSDeclareDefaultStructors(IOCatalogue
)
54 OSCollectionIterator
* kernelTables
;
64 @abstract Creates and initializes the database object and poputates it with in-kernel driver personalities.
66 static void initialize( void );
70 @abstract Initializes the database object.
71 @param initArray The initial array of driver personalities to populate the database.
73 bool init( OSArray
* initArray
);
77 @abstract Cleans up the database and deallocates memory allocated at initialization. This is never called in normal operation of the system.
83 @abstract This is the primary entry point for IOService.
85 @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.
86 @result Returns an ordered set of driver personalities ranked on probe-scores. The ordered set must be released by the receiver.
88 OSOrderedSet
* findDrivers( IOService
* service
, SInt32
* generationCount
);
92 @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.
93 @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.
94 @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.
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( OSDictionary
* matching
, SInt32
* generationCount
);
101 @abstract Adds an array of driver personalities to the database.
102 @param array Array of driver personalities to be added to the database.
103 @param doNubMatchng Start matching process after personalities have been added.
104 @result Returns true if driver personality was added to the database successfully. Failure is due to a memory allocation failure.
106 bool addDrivers( OSArray
* array
, bool doNubMatching
= true );
109 @function removeDrivers
110 @abstract Remove driver personalities from the database based on matching information provided.
111 @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'.
112 @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.
113 @result Returns true if personality was removed successfully. Failure is due to a memory allocation failure.
115 bool removeDrivers( OSDictionary
* matching
, bool doNubMatching
= true );
118 @function getGenerationCount
119 @abstract Get the current generation count of the database.
121 SInt32
getGenerationCount( void ) const;
124 @function isModuleLoaded
125 @abstract Reports if a kernel module has been loaded.
126 @param moduleName Name of the module.
127 @result Returns true if the associated kernel module has been loaded into the kernel.
129 bool isModuleLoaded( OSString
* moduleName
) const;
132 @function isModuleLoaded
133 @abstract Reports if a kernel module has been loaded.
134 @param moduleName Name of the module.
135 @result Returns true if the associated kernel module has been loaded into the kernel.
137 bool isModuleLoaded( const char * moduleName
) const;
140 @function isModuleLoaded
141 @abstract Reports if a kernel module has been loaded for a particular personality.
142 @param driver A driver personality's property list.
143 @result Returns true if the associated kernel module has been loaded into the kernel for a particular driver personality on which it depends.
145 bool isModuleLoaded( OSDictionary
* driver
) const;
148 @function moduleHasLoaded
149 @abstract Callback function called after a IOKit dependent kernel module is loaded.
150 @param name Name of the kernel module.
152 void moduleHasLoaded( OSString
* name
);
155 @function moduleHasLoaded
156 @abstract Callback function called after a IOKit dependent kernel module is loaded.
157 @param name Name of the kernel module.
159 void moduleHasLoaded( const char * name
);
162 @function terminateDrivers
163 @abstract Terminates all instances of a driver which match the contents of the matching dictionary. Does not unload module.
164 @param matching Dictionary containing the matching criteria.
166 IOReturn
terminateDrivers( OSDictionary
* matching
);
169 @function terminateDriversForModule
170 @abstract Terminates all instances of a driver which depends on a particular module and unloads the module.
171 @param moduleName Name of the module which is used to determine which driver instances to terminate and unload.
172 @param unload Flag to cause the actual unloading of the module.
174 IOReturn
terminateDriversForModule( OSString
* moduleName
, bool unload
= true);
177 @function terminateDriversForModule
178 @abstract Terminates all instances of a driver which depends on a particular module and unloads the module.
179 @param moduleName Name of the module which is used to determine which driver instances to terminate and unload.
180 @param unload Flag to cause the actual unloading of the module.
182 IOReturn
terminateDriversForModule( const char * moduleName
, bool unload
= true);
185 @function startMatching
186 @abstract Starts an IOService matching thread where matching keys and values are provided by the matching dictionary.
187 @param matching A dictionary containing keys and values to match against.
189 bool startMatching( OSDictionary
* matching
);
193 @abstract Return the Catalogue to its initial state.
199 @abstract Serializes the catalog for transport to the user.
200 @param s The serializer object.
201 @result Returns false if unable to serialize database, most likely due to memory shortage.
203 virtual bool serialize(OSSerialize
* s
) const;
207 @function recordStartupExtensions
208 @abstract Records extensions made available by the primary booter.
210 This function is for internal use by the kernel startup linker.
211 Kernel extensions should never call it.
212 @result Returns true if startup extensions were successfully recorded,
215 virtual bool recordStartupExtensions(void);
218 @function addExtensionsFromArchive()
219 @abstract Records an archive of extensions, as from device ROM.
221 This function is currently for internal use.
222 Kernel extensions should never call it.
223 @param mkext An OSData object containing a multikext archive.
224 @result Returns true if mkext was properly unserialized and its
225 contents recorded, false if not.
227 virtual bool addExtensionsFromArchive(OSData
* mkext
);
231 @function removeKernelLinker
232 @abstract Removes from memory all code and data related to
233 boot-time loading of kernel extensions. kextd triggers
234 this when it first starts in order to pass responsibility
235 for loading extensions from the kernel itself to kextd.
236 @result Returns KERN_SUCCESS if the kernel linker is successfully
237 removed or wasn't present, KERN_FAILURE otherwise.
239 virtual kern_return_t
removeKernelLinker(void);
244 @function unloadModule
245 @abstract Unloads the reqested module if no driver instances are currently depending on it.
246 @param moduleName An OSString containing the name of the module to unload.
248 IOReturn
unloadModule( OSString
* moduleName
) const;
255 @function IOKitRelocStart
256 @abstract Deprecated API.
258 kmod_start_func_t IOKitRelocStart
;
260 @function IOKitRelocStop
261 @abstract Deprecated API.
263 kmod_stop_func_t IOKitRelocStop
;
266 extern const OSSymbol
* gIOClassKey
;
267 extern const OSSymbol
* gIOProbeScoreKey
;
268 extern IOCatalogue
* gIOCatalogue
;
270 #endif /* ! _IOKIT_IOCATALOGUE_H */