]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/IOCatalogue.h
xnu-792.6.56.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_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /*
24 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
25 *
26 * HISTORY
27 *
28 */
29
30
31 #ifndef _IOKIT_IOCATALOGUE_H
32 #define _IOKIT_IOCATALOGUE_H
33
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>
40
41 #include <IOKit/IOKitServer.h>
42
43 class IOService;
44
45 /*!
46 @class IOCatalogue
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.
49 */
50 class IOCatalogue : public OSObject
51 {
52 OSDeclareDefaultStructors(IOCatalogue)
53
54 private:
55 OSCollectionIterator * kernelTables;
56 OSArray * array;
57 IOLock * lock;
58 SInt32 generation;
59
60 IOLock * kld_lock;
61
62 public:
63 /*!
64 @function initialize
65 @abstract Creates and initializes the database object and poputates it with in-kernel driver personalities.
66 */
67 static void initialize( void );
68
69 /*!
70 @function init
71 @abstract Initializes the database object.
72 @param initArray The initial array of driver personalities to populate the database.
73 */
74 bool init( OSArray * initArray );
75
76 /*!
77 @function free
78 @abstract Cleans up the database and deallocates memory allocated at initialization. This is never called in normal operation of the system.
79 */
80 void free( void );
81
82 /*!
83 @function findDrivers
84 @abstract This is the primary entry point for IOService.
85 @param service
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.
88 */
89 OSOrderedSet * findDrivers( IOService * service, SInt32 * generationCount );
90
91 /*!
92 @function findDrivers
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.
97 */
98 OSOrderedSet * findDrivers( OSDictionary * matching, SInt32 * generationCount );
99
100 /*!
101 @function addDrivers
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.
106 */
107 bool addDrivers( OSArray * array, bool doNubMatching = true );
108
109 /*!
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.
115 */
116 bool removeDrivers( OSDictionary * matching, bool doNubMatching = true );
117
118 /*!
119 @function getGenerationCount
120 @abstract Get the current generation count of the database.
121 */
122 SInt32 getGenerationCount( void ) const;
123
124 /*!
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.
129 */
130 bool isModuleLoaded( OSString * moduleName ) const;
131
132 /*!
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.
137 */
138 bool isModuleLoaded( const char * moduleName ) const;
139
140 /*!
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.
145 */
146 bool isModuleLoaded( OSDictionary * driver ) const;
147
148 /*!
149 @function moduleHasLoaded
150 @abstract Callback function called after a IOKit dependent kernel module is loaded.
151 @param name Name of the kernel module.
152 */
153 void moduleHasLoaded( OSString * name );
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( const char * name );
161
162 /*!
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'.
166 */
167 IOReturn terminateDrivers( OSDictionary * matching );
168
169 /*!
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.
174 */
175 IOReturn terminateDriversForModule( OSString * moduleName, bool unload = true);
176
177 /*!
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.
182 */
183 IOReturn terminateDriversForModule( const char * moduleName, bool unload = true);
184
185 /*!
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'.
189 */
190 bool startMatching( OSDictionary * matching );
191
192 /*!
193 @function reset
194 @abstract Return the Catalogue to its initial state.
195 */
196 void reset(void);
197
198 /*!
199 @function serialize
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.
203 */
204 virtual bool serialize(OSSerialize * s) const;
205
206 bool serializeData(IOOptionBits kind, OSSerialize * s) const;
207
208 /*!
209 @function recordStartupExtensions
210 @abstract Records extensions made available by the primary booter.
211 <p>
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,
215 false if not.
216 */
217 virtual bool recordStartupExtensions(void);
218
219 /*!
220 @function addExtensionsFromArchive()
221 @abstract Records an archive of extensions, as from device ROM.
222 <p>
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.
228 */
229 virtual bool addExtensionsFromArchive(OSData * mkext);
230
231
232 /*!
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.
240 */
241 virtual kern_return_t removeKernelLinker(void);
242
243 static void disableExternalLinker(void);
244
245 private:
246
247 /*!
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.
251 */
252 IOReturn unloadModule( OSString * moduleName ) const;
253 };
254
255 __BEGIN_DECLS
256 /*!
257 @function IOKitRelocStart
258 @abstract Deprecated API.
259 */
260 kmod_start_func_t IOKitRelocStart;
261 /*!
262 @function IOKitRelocStop
263 @abstract Deprecated API.
264 */
265 kmod_stop_func_t IOKitRelocStop;
266 __END_DECLS
267
268 extern const OSSymbol * gIOClassKey;
269 extern const OSSymbol * gIOProbeScoreKey;
270 extern IOCatalogue * gIOCatalogue;
271
272 #endif /* ! _IOKIT_IOCATALOGUE_H */