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