]> git.saurik.com Git - apple/xnu.git/blame - iokit/IOKit/IOCatalogue.h
xnu-7195.101.1.tar.gz
[apple/xnu.git] / iokit / IOKit / IOCatalogue.h
CommitLineData
1c79356b 1/*
cb323159 2 * Copyright (c) 1998-2019 Apple Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 5 *
2d21ac55
A
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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
0a7de745 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
0a7de745 17 *
2d21ac55
A
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
0a7de745 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/*
0a7de745 29 * Copyright (c) 1998 Apple Inc. All rights reserved.
1c79356b
A
30 *
31 * HISTORY
32 *
33 */
34
35
36#ifndef _IOKIT_IOCATALOGUE_H
37#define _IOKIT_IOCATALOGUE_H
38
f427ee49 39#include <libkern/c++/OSPtr.h>
1c79356b
A
40#include <libkern/c++/OSObject.h>
41#include <libkern/c++/OSCollectionIterator.h>
42#include <libkern/c++/OSArray.h>
43#include <libkern/c++/OSDictionary.h>
44#include <IOKit/IOLocks.h>
45#include <sys/cdefs.h>
46
47#include <IOKit/IOKitServer.h>
48
49class IOService;
50
f427ee49
A
51extern OSPtr<const OSSymbol> gIOModuleIdentifierKey;
52extern OSPtr<const OSSymbol> gIOModuleIdentifierKernelKey;
cb323159
A
53
54
1c79356b 55/*!
0a7de745
A
56 * @class IOCatalogue
57 * @abstract In-kernel database for IOKit driver personalities.
58 * @discussion The IOCatalogue is a database which contains all IOKit driver personalities. IOService uses this resource when matching devices to their associated drivers.
59 */
1c79356b
A
60class IOCatalogue : public OSObject
61{
cb323159 62 OSDeclareDefaultStructors(IOCatalogue);
0a7de745 63
1c79356b 64private:
0a7de745
A
65 IORWLock * lock;
66 SInt32 generation;
f427ee49 67 OSPtr<OSDictionary> personalities;
0a7de745
A
68 OSArray * arrayForPersonality(OSDictionary * dict);
69 void addPersonality(OSDictionary * dict);
0b4e3aa0 70
1c79356b 71public:
0a7de745
A
72/*!
73 * @function initialize
74 * @abstract Creates and initializes the database object and poputates it with in-kernel driver personalities.
75 */
76 static void initialize( void );
77
78/*!
79 * @function init
80 * @abstract Initializes the database object.
81 * @param initArray The initial array of driver personalities to populate the database.
82 */
83 bool init( OSArray * initArray );
84
85/*!
86 * @function free
87 * @abstract Cleans up the database and deallocates memory allocated at initialization. This is never called in normal operation of the system.
88 */
89 void free( void ) APPLE_KEXT_OVERRIDE;
90
91/*!
92 * @function findDrivers
93 * @abstract This is the primary entry point for IOService.
94 * @param service The service
95 * @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.
96 * @result Returns an ordered set of driver personalities ranked on probe-scores. The ordered set must be released by the receiver.
97 */
f427ee49 98 OSPtr<OSOrderedSet> findDrivers( IOService * service, SInt32 * generationCount );
0a7de745
A
99
100/*!
101 * @function findDrivers
102 * @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.
103 * @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.
104 * @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.
105 * @result Returns an ordered set of driver personalities ranked on probe-scores. The ordered set must be released by the receiver.
106 */
f427ee49 107 OSPtr<OSOrderedSet> findDrivers( OSDictionary * matching, SInt32 * generationCount );
0a7de745
A
108
109/*!
110 * @function addDrivers
111 * @abstract Adds an array of driver personalities to the database.
112 * @param array Array of driver personalities to be added to the database.
113 * @param doNubMatching Start matching process after personalities have been added.
114 * @result Returns true if driver personality was added to the database successfully. Failure is due to a memory allocation failure.
115 */
116 bool addDrivers( OSArray * array, bool doNubMatching = true );
117
118/*!
119 * @function removeDrivers
120 * @abstract Remove driver personalities from the database based on matching information provided.
121 * @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'.
122 * @param doNubMatching 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.
123 * @result Returns true if personality was removed successfully. Failure is due to a memory allocation failure.
124 */
125 bool removeDrivers( OSDictionary * matching, bool doNubMatching = true );
126
f427ee49
A
127#if XNU_KERNEL_PRIVATE
128 bool removeDrivers(bool doNubMatching, bool (^shouldRemove)(OSDictionary *personality));
129#endif /* XNU_KERNEL_PRIVATE */
130
0a7de745
A
131/*!
132 * @function getGenerationCount
133 * @abstract Get the current generation count of the database.
134 */
135 SInt32 getGenerationCount( void ) const;
136
0a7de745
A
137/*!
138 * @function isModuleLoaded
139 * @abstract Reports if a kernel module has been loaded for a particular personality.
140 * @param driver A driver personality's property list.
cb323159 141 * @param kextRef A reference to the kext getting loaded.
0a7de745
A
142 * @result Returns true if the associated kernel module has been loaded into the kernel for a particular driver personality on which it depends.
143 */
cb323159 144 bool isModuleLoaded( OSDictionary * driver, OSObject ** kextRef ) const;
0a7de745 145
f427ee49
A
146 bool isModuleLoaded( OSDictionary * driver, OSSharedPtr<OSObject>& kextRef ) const;
147
0a7de745
A
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 */
cb323159 153 void moduleHasLoaded( const OSSymbol * name );
0a7de745
A
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);
ea3f0419
A
184#if XNU_KERNEL_PRIVATE
185 IOReturn terminateDrivers(OSDictionary * matching, io_name_t className);
f427ee49
A
186
187 IOReturn terminateDriversForUserspaceReboot();
188
189 IOReturn resetAfterUserspaceReboot();
ea3f0419 190#endif /* XNU_KERNEL_PRIVATE */
0a7de745
A
191
192/*!
193 * @function startMatching
cb323159
A
194 * @abstract Restarts IOService matching.
195 * @param identifier All IOService objects with this bundle indentifier are rematched.
0a7de745 196 */
cb323159
A
197 bool startMatching( const OSSymbol * identifier );
198
199 // deprecated, for bin compat
200#if defined(__i386__) || defined(__x86_64__)
0a7de745 201 bool startMatching( OSDictionary * matching );
cb323159 202#endif
0a7de745
A
203
204/*!
205 * @function reset
206 * @abstract Return the Catalogue to its initial state.
207 * @discussion
208 * Should only be used by kextd just before it sends all kext personalities down during a rescan.
209 */
210 void reset(void);
211
212/*!
213 * @function resetAndAddDrivers
214 * @abstract Replace personalities in IOCatalog with those provided.
215 * @discussion
216 * Resets the catalogue with a new set of drivers, preserving matching originals to keep wired memory usage down.
217 */
218 bool resetAndAddDrivers(OSArray * drivers, bool doNubMatching = true);
219
220/*!
221 * @function serialize
222 * @abstract Serializes the catalog for transport to the user.
223 * @param s The serializer object.
224 * @result Returns false if unable to serialize database, most likely due to memory shortage.
225 */
226 virtual bool serialize(OSSerialize * s) const APPLE_KEXT_OVERRIDE;
227
228 bool serializeData(IOOptionBits kind, OSSerialize * s) const;
1c79356b 229
6d2010ae 230/* This stuff is no longer used at all we keep it around for i386
b0d623f7
A
231 * binary compatibility only. Symbols are no longer exported.
232 */
91447636 233
1c79356b
A
234private:
235
0a7de745
A
236/*!
237 * @function unloadModule
238 * @abstract Unloads the reqested module if no driver instances are currently depending on it.
239 * @param moduleName An OSString containing the name of the module to unload.
240 */
241 IOReturn unloadModule( OSString * moduleName ) const;
316670eb 242
0a7de745 243 IOReturn _removeDrivers(OSDictionary * matching);
1c79356b
A
244};
245
f427ee49
A
246extern OSPtr<const OSSymbol> gIOClassKey;
247extern OSPtr<const OSSymbol> gIOProbeScoreKey;
248extern OSPtr<IOCatalogue> gIOCatalogue;
1c79356b
A
249
250#endif /* ! _IOKIT_IOCATALOGUE_H */