]> git.saurik.com Git - apple/xnu.git/blame_incremental - iokit/IOKit/IOCatalogue.h
xnu-344.21.74.tar.gz
[apple/xnu.git] / iokit / IOKit / IOCatalogue.h
... / ...
CommitLineData
1/*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25/*
26 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
27 *
28 * HISTORY
29 *
30 */
31
32
33#ifndef _IOKIT_IOCATALOGUE_H
34#define _IOKIT_IOCATALOGUE_H
35
36#include <libkern/c++/OSObject.h>
37#include <libkern/c++/OSCollectionIterator.h>
38#include <libkern/c++/OSArray.h>
39#include <libkern/c++/OSDictionary.h>
40#include <IOKit/IOLocks.h>
41#include <sys/cdefs.h>
42
43#include <IOKit/IOKitServer.h>
44
45class IOService;
46
47/*!
48 @class IOCatalogue
49 @abstract In-kernel database for IOKit driver personalities.
50 @discussion The IOCatalogue is a database which contains all IOKit driver personalities. IOService uses this resource when matching devices to their associated drivers.
51*/
52class IOCatalogue : public OSObject
53{
54 OSDeclareDefaultStructors(IOCatalogue)
55
56private:
57 OSCollectionIterator * kernelTables;
58 OSArray * array;
59 IOLock * lock;
60 SInt32 generation;
61
62 IOLock * kld_lock;
63
64public:
65 /*!
66 @function initialize
67 @abstract Creates and initializes the database object and poputates it with in-kernel driver personalities.
68 */
69 static void initialize( void );
70
71 /*!
72 @function init
73 @abstract Initializes the database object.
74 @param initArray The initial array of driver personalities to populate the database.
75 */
76 bool init( OSArray * initArray );
77
78 /*!
79 @function free
80 @abstract Cleans up the database and deallocates memory allocated at initialization. This is never called in normal operation of the system.
81 */
82 void free( void );
83
84 /*!
85 @function findDrivers
86 @abstract This is the primary entry point for IOService.
87 @param service
88 @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.
89 @result Returns an ordered set of driver personalities ranked on probe-scores. The ordered set must be released by the receiver.
90 */
91 OSOrderedSet * findDrivers( IOService * service, SInt32 * generationCount );
92
93 /*!
94 @function findDrivers
95 @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.
96 @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.
97 @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.
98 @result Returns an ordered set of driver personalities ranked on probe-scores. The ordered set must be released by the receiver.
99 */
100 OSOrderedSet * findDrivers( OSDictionary * matching, SInt32 * generationCount );
101
102 /*!
103 @function addDrivers
104 @abstract Adds an array of driver personalities to the database.
105 @param array Array of driver personalities to be added to the database.
106 @param doNubMatchng Start matching process after personalities have been added.
107 @result Returns true if driver personality was added to the database successfully. Failure is due to a memory allocation failure.
108 */
109 bool addDrivers( OSArray * array, bool doNubMatching = true );
110
111 /*!
112 @function removeDrivers
113 @abstract Remove driver personalities from the database based on matching information provided.
114 @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'.
115 @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.
116 @result Returns true if personality was removed successfully. Failure is due to a memory allocation failure.
117 */
118 bool removeDrivers( OSDictionary * matching, bool doNubMatching = true );
119
120 /*!
121 @function getGenerationCount
122 @abstract Get the current generation count of the database.
123 */
124 SInt32 getGenerationCount( void ) const;
125
126 /*!
127 @function isModuleLoaded
128 @abstract Reports if a kernel module has been loaded.
129 @param moduleName Name of the module.
130 @result Returns true if the associated kernel module has been loaded into the kernel.
131 */
132 bool isModuleLoaded( OSString * moduleName ) const;
133
134 /*!
135 @function isModuleLoaded
136 @abstract Reports if a kernel module has been loaded.
137 @param moduleName Name of the module.
138 @result Returns true if the associated kernel module has been loaded into the kernel.
139 */
140 bool isModuleLoaded( const char * moduleName ) const;
141
142 /*!
143 @function isModuleLoaded
144 @abstract Reports if a kernel module has been loaded for a particular personality.
145 @param driver A driver personality's property list.
146 @result Returns true if the associated kernel module has been loaded into the kernel for a particular driver personality on which it depends.
147 */
148 bool isModuleLoaded( OSDictionary * driver ) const;
149
150 /*!
151 @function moduleHasLoaded
152 @abstract Callback function called after a IOKit dependent kernel module is loaded.
153 @param name Name of the kernel module.
154 */
155 void moduleHasLoaded( OSString * name );
156
157 /*!
158 @function moduleHasLoaded
159 @abstract Callback function called after a IOKit dependent kernel module is loaded.
160 @param name Name of the kernel module.
161 */
162 void moduleHasLoaded( const char * name );
163
164 /*!
165 @function terminateDrivers
166 @abstract Terminates all instances of a driver which match the contents of the matching dictionary. Does not unload module.
167 @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'.
168 */
169 IOReturn terminateDrivers( OSDictionary * matching );
170
171 /*!
172 @function terminateDriversForModule
173 @abstract Terminates all instances of a driver which depends on a particular module and unloads the module.
174 @param moduleName Name of the module which is used to determine which driver instances to terminate and unload.
175 @param unload Flag to cause the actual unloading of the module.
176 */
177 IOReturn terminateDriversForModule( OSString * moduleName, bool unload = true);
178
179 /*!
180 @function terminateDriversForModule
181 @abstract Terminates all instances of a driver which depends on a particular module and unloads the module.
182 @param moduleName Name of the module which is used to determine which driver instances to terminate and unload.
183 @param unload Flag to cause the actual unloading of the module.
184 */
185 IOReturn terminateDriversForModule( const char * moduleName, bool unload = true);
186
187 /*!
188 @function startMatching
189 @abstract Starts an IOService matching thread where matching keys and values are provided by the matching dictionary.
190 @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'.
191 */
192 bool startMatching( OSDictionary * matching );
193
194 /*!
195 @function reset
196 @abstract Return the Catalogue to its initial state.
197 */
198 void reset(void);
199
200 /*!
201 @function serialize
202 @abstract Serializes the catalog for transport to the user.
203 @param s The serializer object.
204 @result Returns false if unable to serialize database, most likely due to memory shortage.
205 */
206 virtual bool serialize(OSSerialize * s) const;
207
208
209 /*!
210 @function recordStartupExtensions
211 @abstract Records extensions made available by the primary booter.
212 <p>
213 This function is for internal use by the kernel startup linker.
214 Kernel extensions should never call it.
215 @result Returns true if startup extensions were successfully recorded,
216 false if not.
217 */
218 virtual bool recordStartupExtensions(void);
219
220 /*!
221 @function addExtensionsFromArchive()
222 @abstract Records an archive of extensions, as from device ROM.
223 <p>
224 This function is currently for internal use.
225 Kernel extensions should never call it.
226 @param mkext An OSData object containing a multikext archive.
227 @result Returns true if mkext was properly unserialized and its
228 contents recorded, false if not.
229 */
230 virtual bool addExtensionsFromArchive(OSData * mkext);
231
232
233 /*!
234 @function removeKernelLinker
235 @abstract Removes from memory all code and data related to
236 boot-time loading of kernel extensions. kextd triggers
237 this when it first starts in order to pass responsibility
238 for loading extensions from the kernel itself to kextd.
239 @result Returns KERN_SUCCESS if the kernel linker is successfully
240 removed or wasn't present, KERN_FAILURE otherwise.
241 */
242 virtual kern_return_t removeKernelLinker(void);
243
244private:
245
246 /*!
247 @function unloadModule
248 @abstract Unloads the reqested module if no driver instances are currently depending on it.
249 @param moduleName An OSString containing the name of the module to unload.
250 */
251 IOReturn unloadModule( OSString * moduleName ) const;
252
253
254};
255
256__BEGIN_DECLS
257/*!
258 @function IOKitRelocStart
259 @abstract Deprecated API.
260*/
261kmod_start_func_t IOKitRelocStart;
262/*!
263 @function IOKitRelocStop
264 @abstract Deprecated API.
265*/
266kmod_stop_func_t IOKitRelocStop;
267__END_DECLS
268
269extern const OSSymbol * gIOClassKey;
270extern const OSSymbol * gIOProbeScoreKey;
271extern IOCatalogue * gIOCatalogue;
272
273#endif /* ! _IOKIT_IOCATALOGUE_H */