2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
26 #include <mach/kern_return.h>
28 #include <sys/cdefs.h>
30 #define KMOD_CNTL_START 1 // call kmod's start routine
31 #define KMOD_CNTL_STOP 2 // call kmod's stop routine
32 #define KMOD_CNTL_RETAIN 3 // increase a kmod's reference count
33 #define KMOD_CNTL_RELEASE 4 // decrease a kmod's reference count
34 #define KMOD_CNTL_GET_CMD 5 // get kmod load cmd from kernel
36 #define KMOD_PACK_IDS(from, to) (((unsigned long)from << 16) | (unsigned long)to)
37 #define KMOD_UNPACK_FROM_ID(i) ((unsigned long)i >> 16)
38 #define KMOD_UNPACK_TO_ID(i) ((unsigned long)i & 0xffff)
41 typedef int kmod_control_flavor_t
;
42 typedef void* kmod_args_t
;
44 #define KMOD_MAX_NAME 64
46 #if __DARWIN_ALIGN_POWER
47 #pragma options align=power
50 /* LP64todo - not 64-bit safe */
51 typedef struct kmod_reference
{
52 struct kmod_reference
*next
;
53 struct kmod_info
*info
;
56 #if __DARWIN_ALIGN_POWER
57 #pragma options align=reset
60 /**************************************************************************************/
61 /* warning any changes to this structure affect the following macros. */
62 /**************************************************************************************/
64 #define KMOD_RETURN_SUCCESS KERN_SUCCESS
65 #define KMOD_RETURN_FAILURE KERN_FAILURE
67 typedef kern_return_t
kmod_start_func_t(struct kmod_info
*ki
, void *data
);
68 typedef kern_return_t
kmod_stop_func_t(struct kmod_info
*ki
, void *data
);
70 #if __DARWIN_ALIGN_POWER
71 #pragma options align=power
74 /* LP64todo - not 64-bit safe */
76 typedef struct kmod_info
{
77 struct kmod_info
*next
;
78 int info_version
; // version of this structure
80 char name
[KMOD_MAX_NAME
];
81 char version
[KMOD_MAX_NAME
];
82 int reference_count
; // # refs to this
83 kmod_reference_t
*reference_list
; // who this refs
84 vm_address_t address
; // starting address
85 vm_size_t size
; // total size
86 vm_size_t hdr_size
; // unwired hdr size
87 kmod_start_func_t
*start
;
88 kmod_stop_func_t
*stop
;
91 #if __DARWIN_ALIGN_POWER
92 #pragma options align=reset
95 typedef kmod_info_t
*kmod_info_array_t
;
97 #define KMOD_INFO_NAME kmod_info
98 #define KMOD_INFO_VERSION 1
100 #define KMOD_DECL(name, version) \
101 static kmod_start_func_t name ## _module_start; \
102 static kmod_stop_func_t name ## _module_stop; \
103 kmod_info_t KMOD_INFO_NAME = { 0, KMOD_INFO_VERSION, -1, \
104 { #name }, { version }, -1, 0, 0, 0, 0, \
105 name ## _module_start, \
106 name ## _module_stop };
108 #define KMOD_EXPLICIT_DECL(name, version, start, stop) \
109 kmod_info_t KMOD_INFO_NAME = { 0, KMOD_INFO_VERSION, -1, \
110 { #name }, { version }, -1, 0, 0, 0, 0, \
113 // the following is useful for libaries that don't need their own start and stop functions
114 #define KMOD_LIB_DECL(name, version) \
115 kmod_info_t KMOD_INFO_NAME = { 0, KMOD_INFO_VERSION, -1, \
116 { #name }, { version }, -1, 0, 0, 0, 0, \
117 kmod_default_start, \
121 // *************************************************************************************
122 // kmod kernel to user commands
123 // *************************************************************************************
125 #define KMOD_LOAD_EXTENSION_PACKET 1
126 #define KMOD_LOAD_WITH_DEPENDENCIES_PACKET 2
128 // for generic packets
129 #define KMOD_IOKIT_START_RANGE_PACKET 0x1000
130 #define KMOD_IOKIT_END_RANGE_PACKET 0x1fff
132 typedef struct kmod_load_extension_cmd
{
134 char name
[KMOD_MAX_NAME
];
135 } kmod_load_extension_cmd_t
;
137 typedef struct kmod_load_with_dependencies_cmd
{
139 char name
[KMOD_MAX_NAME
];
140 char dependencies
[1][KMOD_MAX_NAME
];
141 } kmod_load_with_dependencies_cmd_t
;
143 typedef struct kmod_generic_cmd
{
146 } kmod_generic_cmd_t
;
148 #ifdef KERNEL_PRIVATE
150 extern kmod_info_t
*kmod_lookupbyname(const char * name
);
151 extern kmod_info_t
*kmod_lookupbyid(kmod_t id
);
153 extern kmod_info_t
*kmod_lookupbyname_locked(const char * name
);
154 extern kmod_info_t
*kmod_lookupbyid_locked(kmod_t id
);
155 extern kmod_start_func_t kmod_default_start
;
156 extern kmod_stop_func_t kmod_default_stop
;
159 extern void kmod_init(void);
161 extern kern_return_t
kmod_create_fake(const char *name
, const char *version
);
162 extern kern_return_t
kmod_create_fake_with_address(const char *name
, const char *version
,
163 vm_address_t address
, vm_size_t size
,
165 extern kern_return_t
kmod_destroy_fake(kmod_t id
);
167 extern kern_return_t
kmod_load_extension(char *name
);
168 extern kern_return_t
kmod_load_extension_with_dependencies(char *name
, char **dependencies
);
169 extern kern_return_t
kmod_send_generic(int type
, void *data
, int size
);
171 extern kern_return_t
kmod_initialize_cpp(kmod_info_t
*info
);
172 extern kern_return_t
kmod_finalize_cpp(kmod_info_t
*info
);
174 extern void kmod_dump(vm_offset_t
*addr
, unsigned int dump_cnt
);
177 #endif /* KERNEL_PRIVATE */
179 #endif /* _MACH_KMOD_H_ */