2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * @APPLE_LICENSE_HEADER_END@
26 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
30 * 1999 Mar 29 rsulack created.
36 #include <sys/appleapiopts.h>
37 #include <mach/kern_return.h>
39 #ifdef __APPLE_API_PRIVATE
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
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)
51 #endif /* __APPLE_API_PRIVATE */
53 #define KMOD_MAX_NAME 64
55 #ifdef __APPLE_API_PRIVATE
58 typedef int kmod_control_flavor_t
;
59 typedef void* kmod_args_t
;
61 #endif /* __APPLE_API_PRIVATE */
63 typedef struct kmod_reference
{
64 struct kmod_reference
*next
;
65 struct kmod_info
*info
;
69 /**************************************************************************************/
70 /* warning any changes to this structure affect the following macros. */
71 /**************************************************************************************/
73 #define KMOD_RETURN_SUCCESS KERN_SUCCESS
74 #define KMOD_RETURN_FAILURE KERN_FAILURE
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
);
79 typedef struct kmod_info
{
80 struct kmod_info
*next
;
81 int info_version
; // version of this structure
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
;
94 #ifdef __APPLE_API_PRIVATE
96 typedef kmod_info_t
*kmod_info_array_t
;
98 #endif /* __APPLE_API_PRIVATE */
100 #define KMOD_INFO_NAME kmod_info
101 #define KMOD_INFO_VERSION 1
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 };
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, \
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, \
124 // *************************************************************************************
125 // kmod kernel to user commands
126 // *************************************************************************************
128 #ifdef __APPLE_API_PRIVATE
130 #define KMOD_LOAD_EXTENSION_PACKET 1
131 #define KMOD_LOAD_WITH_DEPENDENCIES_PACKET 2
133 // for generic packets
134 #define KMOD_IOKIT_START_RANGE_PACKET 0x1000
135 #define KMOD_IOKIT_END_RANGE_PACKET 0x1fff
137 typedef struct kmod_load_extension_cmd
{
139 char name
[KMOD_MAX_NAME
];
140 } kmod_load_extension_cmd_t
;
142 typedef struct kmod_load_with_dependencies_cmd
{
144 char name
[KMOD_MAX_NAME
];
145 char dependencies
[1][KMOD_MAX_NAME
];
146 } kmod_load_with_dependencies_cmd_t
;
148 typedef struct kmod_generic_cmd
{
151 } kmod_generic_cmd_t
;
153 #ifdef KERNEL_PRIVATE
155 extern void kmod_init();
157 extern kern_return_t
kmod_create_fake(const char *name
, const char *version
);
159 extern kmod_info_t
*kmod_lookupbyname(const char * name
);
160 extern kmod_info_t
*kmod_lookupbyid(kmod_t id
);
162 extern kmod_info_t
*kmod_lookupbyname_locked(const char * name
);
163 extern kmod_info_t
*kmod_lookupbyid_locked(kmod_t id
);
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
);
169 extern kmod_start_func_t kmod_default_start
;
170 extern kmod_stop_func_t kmod_default_stop
;
172 extern kern_return_t
kmod_initialize_cpp(kmod_info_t
*info
);
173 extern kern_return_t
kmod_finalize_cpp(kmod_info_t
*info
);
175 extern void kmod_dump(vm_offset_t
*addr
, unsigned int cnt
);
177 #endif /* KERNEL_PRIVATE */
179 #endif /* __APPLE_API_PRIVATE */
182 #endif /* _MACH_KMOD_H_ */