]> git.saurik.com Git - apple/xnu.git/blob - osfmk/mach/kmod.h
4c9dd54f8455147914bb13d27b1c3a1d7ba7dc10
[apple/xnu.git] / osfmk / mach / kmod.h
1 /*
2 * Copyright (c) 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) 1999 Apple Computer, Inc. All rights reserved.
27 *
28 * HISTORY
29 *
30 * 1999 Mar 29 rsulack created.
31 */
32
33 #ifndef _MACH_KMOD_H_
34 #define _MACH_KMOD_H_
35
36 #include <sys/appleapiopts.h>
37 #include <mach/kern_return.h>
38
39 #ifdef __APPLE_API_PRIVATE
40
41 #define KMOD_CNTL_START 1 // call kmod's start routine
42 #define KMOD_CNTL_STOP 2 // call kmod's stop routine
43 #define KMOD_CNTL_RETAIN 3 // increase a kmod's reference count
44 #define KMOD_CNTL_RELEASE 4 // decrease a kmod's reference count
45 #define KMOD_CNTL_GET_CMD 5 // get kmod load cmd from kernel
46
47 #define KMOD_PACK_IDS(from, to) (((unsigned long)from << 16) | (unsigned long)to)
48 #define KMOD_UNPACK_FROM_ID(i) ((unsigned long)i >> 16)
49 #define KMOD_UNPACK_TO_ID(i) ((unsigned long)i & 0xffff)
50
51 #endif /* __APPLE_API_PRIVATE */
52
53 #define KMOD_MAX_NAME 64
54
55 #ifdef __APPLE_API_PRIVATE
56
57 typedef int kmod_t;
58 typedef int kmod_control_flavor_t;
59 typedef void* kmod_args_t;
60
61 #endif /* __APPLE_API_PRIVATE */
62
63 typedef struct kmod_reference {
64 struct kmod_reference *next;
65 struct kmod_info *info;
66 } kmod_reference_t;
67
68
69 /**************************************************************************************/
70 /* warning any changes to this structure affect the following macros. */
71 /**************************************************************************************/
72
73 #define KMOD_RETURN_SUCCESS KERN_SUCCESS
74 #define KMOD_RETURN_FAILURE KERN_FAILURE
75
76 typedef kern_return_t kmod_start_func_t(struct kmod_info *ki, void *data);
77 typedef kern_return_t kmod_stop_func_t(struct kmod_info *ki, void *data);
78
79 typedef struct kmod_info {
80 struct kmod_info *next;
81 int info_version; // version of this structure
82 int id;
83 char name[KMOD_MAX_NAME];
84 char version[KMOD_MAX_NAME];
85 int reference_count; // # refs to this
86 kmod_reference_t *reference_list; // who this refs
87 vm_address_t address; // starting address
88 vm_size_t size; // total size
89 vm_size_t hdr_size; // unwired hdr size
90 kmod_start_func_t *start;
91 kmod_stop_func_t *stop;
92 } kmod_info_t;
93
94 #ifdef __APPLE_API_PRIVATE
95
96 typedef kmod_info_t *kmod_info_array_t;
97
98 #endif /* __APPLE_API_PRIVATE */
99
100 #define KMOD_INFO_NAME kmod_info
101 #define KMOD_INFO_VERSION 1
102
103 #define KMOD_DECL(name, version) \
104 static kmod_start_func_t name ## _module_start; \
105 static kmod_stop_func_t name ## _module_stop; \
106 kmod_info_t KMOD_INFO_NAME = { 0, KMOD_INFO_VERSION, -1, \
107 { #name }, { version }, -1, 0, 0, 0, 0, \
108 name ## _module_start, \
109 name ## _module_stop };
110
111 #define KMOD_EXPLICIT_DECL(name, version, start, stop) \
112 kmod_info_t KMOD_INFO_NAME = { 0, KMOD_INFO_VERSION, -1, \
113 { #name }, { version }, -1, 0, 0, 0, 0, \
114 start, stop };
115
116 // the following is useful for libaries that don't need their own start and stop functions
117 #define KMOD_LIB_DECL(name, version) \
118 kmod_info_t KMOD_INFO_NAME = { 0, KMOD_INFO_VERSION, -1, \
119 { #name }, { version }, -1, 0, 0, 0, 0, \
120 kmod_default_start, \
121 kmod_default_stop };
122
123
124 // *************************************************************************************
125 // kmod kernel to user commands
126 // *************************************************************************************
127
128 #ifdef __APPLE_API_PRIVATE
129
130 #define KMOD_LOAD_EXTENSION_PACKET 1
131 #define KMOD_LOAD_WITH_DEPENDENCIES_PACKET 2
132
133 // for generic packets
134 #define KMOD_IOKIT_START_RANGE_PACKET 0x1000
135 #define KMOD_IOKIT_END_RANGE_PACKET 0x1fff
136
137 typedef struct kmod_load_extension_cmd {
138 int type;
139 char name[KMOD_MAX_NAME];
140 } kmod_load_extension_cmd_t;
141
142 typedef struct kmod_load_with_dependencies_cmd {
143 int type;
144 char name[KMOD_MAX_NAME];
145 char dependencies[1][KMOD_MAX_NAME];
146 } kmod_load_with_dependencies_cmd_t;
147
148 typedef struct kmod_generic_cmd {
149 int type;
150 char data[1];
151 } kmod_generic_cmd_t;
152
153 #ifdef KERNEL_PRIVATE
154
155 extern void kmod_init();
156
157 extern kern_return_t kmod_create_fake(const char *name, const char *version);
158
159 extern kmod_info_t *kmod_lookupbyname(const char * name);
160 extern kmod_info_t *kmod_lookupbyid(kmod_t id);
161
162 extern kmod_info_t *kmod_lookupbyname_locked(const char * name);
163 extern kmod_info_t *kmod_lookupbyid_locked(kmod_t id);
164
165 extern kern_return_t kmod_load_extension(char *name);
166 extern kern_return_t kmod_load_extension_with_dependencies(char *name, char **dependencies);
167 extern kern_return_t kmod_send_generic(int type, void *data, int size);
168
169 extern kmod_start_func_t kmod_default_start;
170 extern kmod_stop_func_t kmod_default_stop;
171
172 extern kern_return_t kmod_initialize_cpp(kmod_info_t *info);
173 extern kern_return_t kmod_finalize_cpp(kmod_info_t *info);
174
175 extern void kmod_dump(vm_offset_t *addr, unsigned int cnt);
176
177 #endif /* KERNEL_PRIVATE */
178
179 #endif /* __APPLE_API_PRIVATE */
180
181
182 #endif /* _MACH_KMOD_H_ */