]> git.saurik.com Git - apple/xnu.git/blame - osfmk/mach/kmod.h
xnu-344.23.tar.gz
[apple/xnu.git] / osfmk / mach / kmod.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
de355530
A
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.
1c79356b 11 *
de355530
A
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
1c79356b
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
de355530
A
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
1c79356b
A
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/*
23 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
24 *
25 * HISTORY
26 *
27 * 1999 Mar 29 rsulack created.
28 */
29
30#ifndef _MACH_KMOD_H_
31#define _MACH_KMOD_H_
32
9bccf70c 33#include <sys/appleapiopts.h>
1c79356b
A
34#include <mach/kern_return.h>
35
9bccf70c
A
36#ifdef __APPLE_API_PRIVATE
37
1c79356b
A
38#define KMOD_CNTL_START 1 // call kmod's start routine
39#define KMOD_CNTL_STOP 2 // call kmod's stop routine
40#define KMOD_CNTL_RETAIN 3 // increase a kmod's reference count
41#define KMOD_CNTL_RELEASE 4 // decrease a kmod's reference count
42#define KMOD_CNTL_GET_CMD 5 // get kmod load cmd from kernel
43
44#define KMOD_PACK_IDS(from, to) (((unsigned long)from << 16) | (unsigned long)to)
45#define KMOD_UNPACK_FROM_ID(i) ((unsigned long)i >> 16)
46#define KMOD_UNPACK_TO_ID(i) ((unsigned long)i & 0xffff)
47
9bccf70c
A
48#endif /* __APPLE_API_PRIVATE */
49
1c79356b
A
50#define KMOD_MAX_NAME 64
51
9bccf70c
A
52#ifdef __APPLE_API_PRIVATE
53
1c79356b
A
54typedef int kmod_t;
55typedef int kmod_control_flavor_t;
56typedef void* kmod_args_t;
57
9bccf70c
A
58#endif /* __APPLE_API_PRIVATE */
59
1c79356b
A
60typedef struct kmod_reference {
61 struct kmod_reference *next;
62 struct kmod_info *info;
63} kmod_reference_t;
64
9bccf70c 65
1c79356b
A
66/**************************************************************************************/
67/* warning any changes to this structure affect the following macros. */
68/**************************************************************************************/
69
70#define KMOD_RETURN_SUCCESS KERN_SUCCESS
71#define KMOD_RETURN_FAILURE KERN_FAILURE
72
73typedef kern_return_t kmod_start_func_t(struct kmod_info *ki, void *data);
74typedef kern_return_t kmod_stop_func_t(struct kmod_info *ki, void *data);
75
76typedef struct kmod_info {
77 struct kmod_info *next;
78 int info_version; // version of this structure
79 int id;
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;
89} kmod_info_t;
90
9bccf70c
A
91#ifdef __APPLE_API_PRIVATE
92
1c79356b
A
93typedef kmod_info_t *kmod_info_array_t;
94
9bccf70c
A
95#endif /* __APPLE_API_PRIVATE */
96
1c79356b
A
97#define KMOD_INFO_NAME kmod_info
98#define KMOD_INFO_VERSION 1
99
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 };
107
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, \
111 start, stop };
112
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, \
118 kmod_default_stop };
119
120
121// *************************************************************************************
122// kmod kernel to user commands
123// *************************************************************************************
124
9bccf70c
A
125#ifdef __APPLE_API_PRIVATE
126
1c79356b
A
127#define KMOD_LOAD_EXTENSION_PACKET 1
128#define KMOD_LOAD_WITH_DEPENDENCIES_PACKET 2
129
130// for generic packets
131#define KMOD_IOKIT_START_RANGE_PACKET 0x1000
132#define KMOD_IOKIT_END_RANGE_PACKET 0x1fff
133
134typedef struct kmod_load_extension_cmd {
135 int type;
136 char name[KMOD_MAX_NAME];
137} kmod_load_extension_cmd_t;
138
139typedef struct kmod_load_with_dependencies_cmd {
140 int type;
141 char name[KMOD_MAX_NAME];
142 char dependencies[1][KMOD_MAX_NAME];
143} kmod_load_with_dependencies_cmd_t;
144
145typedef struct kmod_generic_cmd {
146 int type;
147 char data[1];
148} kmod_generic_cmd_t;
149
150#ifdef KERNEL_PRIVATE
151
152extern void kmod_init();
153
9bccf70c 154extern kern_return_t kmod_create_fake(const char *name, const char *version);
1c79356b 155
0b4e3aa0 156extern kmod_info_t *kmod_lookupbyname(const char * name);
1c79356b
A
157extern kmod_info_t *kmod_lookupbyid(kmod_t id);
158
9bccf70c
A
159extern kmod_info_t *kmod_lookupbyname_locked(const char * name);
160extern kmod_info_t *kmod_lookupbyid_locked(kmod_t id);
161
1c79356b
A
162extern kern_return_t kmod_load_extension(char *name);
163extern kern_return_t kmod_load_extension_with_dependencies(char *name, char **dependencies);
164extern kern_return_t kmod_send_generic(int type, void *data, int size);
165
166extern kmod_start_func_t kmod_default_start;
167extern kmod_stop_func_t kmod_default_stop;
168
169extern kern_return_t kmod_initialize_cpp(kmod_info_t *info);
170extern kern_return_t kmod_finalize_cpp(kmod_info_t *info);
171
172extern void kmod_dump(vm_offset_t *addr, unsigned int cnt);
173
174#endif /* KERNEL_PRIVATE */
175
9bccf70c
A
176#endif /* __APPLE_API_PRIVATE */
177
178
1c79356b 179#endif /* _MACH_KMOD_H_ */