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@
29 * File: kern/ipc_clock.c
30 * Purpose: Routines to support ipc semantics of new kernel
31 * alarm clock facility.
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>
47 * Routine: ipc_clock_init
49 * Initialize ipc control of a clock.
57 port
= ipc_port_alloc_kernel();
59 panic("ipc_clock_init");
60 clock
->cl_service
= port
;
62 port
= ipc_port_alloc_kernel();
64 panic("ipc_clock_init");
65 clock
->cl_control
= port
;
69 * Routine: ipc_clock_enable
71 * Enable ipc access to a clock.
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
);
84 * Routine: convert_port_to_clock
86 * Convert from a port to a clock.
87 * Doesn't consume the port ref; produces a clock ref,
93 convert_port_to_clock(
96 clock_t clock
= CLOCK_NULL
;
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
;
111 * Routine: convert_port_to_clock_ctrl
113 * Convert from a port to a clock.
114 * Doesn't consume the port ref; produces a clock ref,
120 convert_port_to_clock_ctrl(
123 clock_t clock
= CLOCK_NULL
;
125 if (IP_VALID(port
)) {
127 if (ip_active(port
) &&
128 (ip_kotype(port
) == IKOT_CLOCK_CTRL
)) {
129 clock
= (clock_t) port
->ip_kobject
;
137 * Routine: convert_clock_to_port
139 * Convert from a clock to a port.
140 * Produces a naked send right which may be invalid.
145 convert_clock_to_port(
150 port
= ipc_port_make_send(clock
->cl_service
);
155 * Routine: convert_clock_ctrl_to_port
157 * Convert from a clock to a port.
158 * Produces a naked send right which may be invalid.
163 convert_clock_ctrl_to_port(
168 port
= ipc_port_make_send(clock
->cl_control
);
173 * Routine: port_name_to_clock
175 * Convert from a clock name to a clock pointer.
179 mach_port_name_t clock_name
)
181 clock_t clock
= CLOCK_NULL
;
187 space
= current_space();
188 if (ipc_port_translate_send(space
, clock_name
, &port
) != KERN_SUCCESS
)
190 if (ip_active(port
) && (ip_kotype(port
) == IKOT_CLOCK
))
191 clock
= (clock_t) port
->ip_kobject
;