2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * File: kern/ipc_clock.c
33 * Purpose: Routines to support ipc semantics of new kernel
34 * alarm clock facility.
37 #include <mach/message.h>
38 #include <kern/host.h>
39 #include <kern/processor.h>
40 #include <kern/task.h>
41 #include <kern/thread.h>
42 #include <kern/ipc_host.h>
43 #include <kern/ipc_kobject.h>
44 #include <kern/clock.h>
45 #include <kern/misc_protos.h>
46 #include <ipc/ipc_port.h>
47 #include <ipc/ipc_space.h>
50 * Routine: ipc_clock_init
52 * Initialize ipc control of a clock.
60 port
= ipc_port_alloc_kernel();
61 if (port
== IP_NULL
) {
62 panic("ipc_clock_init");
64 clock
->cl_service
= port
;
66 port
= ipc_port_alloc_kernel();
67 if (port
== IP_NULL
) {
68 panic("ipc_clock_init");
70 clock
->cl_control
= port
;
74 * Routine: ipc_clock_enable
76 * Enable ipc access to a clock.
82 ipc_kobject_set(clock
->cl_service
,
83 (ipc_kobject_t
) clock
, IKOT_CLOCK
);
84 ipc_kobject_set(clock
->cl_control
,
85 (ipc_kobject_t
) clock
, IKOT_CLOCK_CTRL
);
89 * Routine: convert_port_to_clock
91 * Convert from a port to a clock.
92 * Doesn't consume the port ref; produces a clock ref,
98 convert_port_to_clock(
101 clock_t clock
= CLOCK_NULL
;
103 if (IP_VALID(port
)) {
105 if (ip_active(port
) &&
106 ((ip_kotype(port
) == IKOT_CLOCK
) ||
107 (ip_kotype(port
) == IKOT_CLOCK_CTRL
))) {
108 clock
= (clock_t) port
->ip_kobject
;
116 * Routine: convert_port_to_clock_ctrl
118 * Convert from a port to a clock.
119 * Doesn't consume the port ref; produces a clock ref,
125 convert_port_to_clock_ctrl(
128 clock_t clock
= CLOCK_NULL
;
130 if (IP_VALID(port
)) {
132 if (ip_active(port
) &&
133 (ip_kotype(port
) == IKOT_CLOCK_CTRL
)) {
134 clock
= (clock_t) port
->ip_kobject
;
142 * Routine: convert_clock_to_port
144 * Convert from a clock to a port.
145 * Produces a naked send right which may be invalid.
150 convert_clock_to_port(
155 port
= ipc_port_make_send(clock
->cl_service
);
160 * Routine: convert_clock_ctrl_to_port
162 * Convert from a clock to a port.
163 * Produces a naked send right which may be invalid.
168 convert_clock_ctrl_to_port(
173 port
= ipc_port_make_send(clock
->cl_control
);
178 * Routine: port_name_to_clock
180 * Convert from a clock name to a clock pointer.
184 mach_port_name_t clock_name
)
186 clock_t clock
= CLOCK_NULL
;
190 if (clock_name
== 0) {
193 space
= current_space();
194 if (ipc_port_translate_send(space
, clock_name
, &port
) != KERN_SUCCESS
) {
197 if (ip_kotype(port
) == IKOT_CLOCK
) {
198 clock
= (clock_t) port
->ip_kobject
;