]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
43866e37 | 6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
1c79356b | 7 | * |
43866e37 A |
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 | |
1c79356b A |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
43866e37 A |
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. | |
1c79356b A |
22 | * |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | /* | |
26 | * @OSF_COPYRIGHT@ | |
27 | */ | |
28 | /* | |
29 | * File: kern/ipc_clock.c | |
30 | * Purpose: Routines to support ipc semantics of new kernel | |
31 | * alarm clock facility. | |
32 | */ | |
33 | ||
34 | #include <mach/message.h> | |
35 | #include <kern/host.h> | |
36 | #include <kern/processor.h> | |
37 | #include <kern/task.h> | |
38 | #include <kern/thread.h> | |
39 | #include <kern/ipc_host.h> | |
40 | #include <kern/ipc_kobject.h> | |
41 | #include <kern/clock.h> | |
42 | #include <kern/misc_protos.h> | |
43 | #include <ipc/ipc_port.h> | |
44 | #include <ipc/ipc_space.h> | |
45 | ||
46 | /* | |
47 | * Routine: ipc_clock_init | |
48 | * Purpose: | |
49 | * Initialize ipc control of a clock. | |
50 | */ | |
51 | void | |
52 | ipc_clock_init( | |
53 | clock_t clock) | |
54 | { | |
55 | ipc_port_t port; | |
56 | ||
57 | port = ipc_port_alloc_kernel(); | |
58 | if (port == IP_NULL) | |
59 | panic("ipc_clock_init"); | |
60 | clock->cl_service = port; | |
61 | ||
62 | port = ipc_port_alloc_kernel(); | |
63 | if (port == IP_NULL) | |
64 | panic("ipc_clock_init"); | |
65 | clock->cl_control = port; | |
66 | } | |
67 | ||
68 | /* | |
69 | * Routine: ipc_clock_enable | |
70 | * Purpose: | |
71 | * Enable ipc access to a clock. | |
72 | */ | |
73 | void | |
74 | ipc_clock_enable( | |
75 | clock_t clock) | |
76 | { | |
77 | ipc_kobject_set(clock->cl_service, | |
78 | (ipc_kobject_t) clock, IKOT_CLOCK); | |
79 | ipc_kobject_set(clock->cl_control, | |
80 | (ipc_kobject_t) clock, IKOT_CLOCK_CTRL); | |
81 | } | |
82 | ||
83 | /* | |
84 | * Routine: convert_port_to_clock | |
85 | * Purpose: | |
86 | * Convert from a port to a clock. | |
87 | * Doesn't consume the port ref; produces a clock ref, | |
88 | * which may be null. | |
89 | * Conditions: | |
90 | * Nothing locked. | |
91 | */ | |
92 | clock_t | |
93 | convert_port_to_clock( | |
94 | ipc_port_t port) | |
95 | { | |
96 | clock_t clock = CLOCK_NULL; | |
97 | ||
98 | if (IP_VALID(port)) { | |
99 | ip_lock(port); | |
100 | if (ip_active(port) && | |
101 | ((ip_kotype(port) == IKOT_CLOCK) || | |
102 | (ip_kotype(port) == IKOT_CLOCK_CTRL))) { | |
103 | clock = (clock_t) port->ip_kobject; | |
104 | } | |
105 | ip_unlock(port); | |
106 | } | |
107 | return (clock); | |
108 | } | |
109 | ||
110 | /* | |
111 | * Routine: convert_port_to_clock_ctrl | |
112 | * Purpose: | |
113 | * Convert from a port to a clock. | |
114 | * Doesn't consume the port ref; produces a clock ref, | |
115 | * which may be null. | |
116 | * Conditions: | |
117 | * Nothing locked. | |
118 | */ | |
119 | clock_t | |
120 | convert_port_to_clock_ctrl( | |
121 | ipc_port_t port) | |
122 | { | |
123 | clock_t clock = CLOCK_NULL; | |
124 | ||
125 | if (IP_VALID(port)) { | |
126 | ip_lock(port); | |
127 | if (ip_active(port) && | |
128 | (ip_kotype(port) == IKOT_CLOCK_CTRL)) { | |
129 | clock = (clock_t) port->ip_kobject; | |
130 | } | |
131 | ip_unlock(port); | |
132 | } | |
133 | return (clock); | |
134 | } | |
135 | ||
136 | /* | |
137 | * Routine: convert_clock_to_port | |
138 | * Purpose: | |
139 | * Convert from a clock to a port. | |
140 | * Produces a naked send right which may be invalid. | |
141 | * Conditions: | |
142 | * Nothing locked. | |
143 | */ | |
144 | ipc_port_t | |
145 | convert_clock_to_port( | |
146 | clock_t clock) | |
147 | { | |
148 | ipc_port_t port; | |
149 | ||
150 | port = ipc_port_make_send(clock->cl_service); | |
151 | return (port); | |
152 | } | |
153 | ||
154 | /* | |
155 | * Routine: convert_clock_ctrl_to_port | |
156 | * Purpose: | |
157 | * Convert from a clock to a port. | |
158 | * Produces a naked send right which may be invalid. | |
159 | * Conditions: | |
160 | * Nothing locked. | |
161 | */ | |
162 | ipc_port_t | |
163 | convert_clock_ctrl_to_port( | |
164 | clock_t clock) | |
165 | { | |
166 | ipc_port_t port; | |
167 | ||
168 | port = ipc_port_make_send(clock->cl_control); | |
169 | return (port); | |
170 | } | |
171 | ||
172 | /* | |
173 | * Routine: port_name_to_clock | |
174 | * Purpose: | |
175 | * Convert from a clock name to a clock pointer. | |
176 | */ | |
177 | clock_t | |
178 | port_name_to_clock( | |
179 | mach_port_name_t clock_name) | |
180 | { | |
181 | clock_t clock = CLOCK_NULL; | |
182 | ipc_space_t space; | |
183 | ipc_port_t port; | |
184 | ||
185 | if (clock_name == 0) | |
186 | return (clock); | |
187 | space = current_space(); | |
188 | if (ipc_port_translate_send(space, clock_name, &port) != KERN_SUCCESS) | |
189 | return (clock); | |
190 | if (ip_active(port) && (ip_kotype(port) == IKOT_CLOCK)) | |
191 | clock = (clock_t) port->ip_kobject; | |
192 | ip_unlock(port); | |
193 | return (clock); | |
194 | } |