2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
27 * File: kern/ipc_clock.c
28 * Purpose: Routines to support ipc semantics of new kernel
29 * alarm clock facility.
32 #include <mach/message.h>
33 #include <kern/host.h>
34 #include <kern/processor.h>
35 #include <kern/task.h>
36 #include <kern/thread.h>
37 #include <kern/ipc_host.h>
38 #include <kern/ipc_kobject.h>
39 #include <kern/clock.h>
40 #include <kern/misc_protos.h>
41 #include <ipc/ipc_port.h>
42 #include <ipc/ipc_space.h>
45 * Routine: ipc_clock_init
47 * Initialize ipc control of a clock.
55 port
= ipc_port_alloc_kernel();
57 panic("ipc_clock_init");
58 clock
->cl_service
= port
;
60 port
= ipc_port_alloc_kernel();
62 panic("ipc_clock_init");
63 clock
->cl_control
= port
;
67 * Routine: ipc_clock_enable
69 * Enable ipc access to a clock.
75 ipc_kobject_set(clock
->cl_service
,
76 (ipc_kobject_t
) clock
, IKOT_CLOCK
);
77 ipc_kobject_set(clock
->cl_control
,
78 (ipc_kobject_t
) clock
, IKOT_CLOCK_CTRL
);
82 * Routine: convert_port_to_clock
84 * Convert from a port to a clock.
85 * Doesn't consume the port ref; produces a clock ref,
91 convert_port_to_clock(
94 clock_t clock
= CLOCK_NULL
;
98 if (ip_active(port
) &&
99 ((ip_kotype(port
) == IKOT_CLOCK
) ||
100 (ip_kotype(port
) == IKOT_CLOCK_CTRL
))) {
101 clock
= (clock_t) port
->ip_kobject
;
109 * Routine: convert_port_to_clock_ctrl
111 * Convert from a port to a clock.
112 * Doesn't consume the port ref; produces a clock ref,
118 convert_port_to_clock_ctrl(
121 clock_t clock
= CLOCK_NULL
;
123 if (IP_VALID(port
)) {
125 if (ip_active(port
) &&
126 (ip_kotype(port
) == IKOT_CLOCK_CTRL
)) {
127 clock
= (clock_t) port
->ip_kobject
;
135 * Routine: convert_clock_to_port
137 * Convert from a clock to a port.
138 * Produces a naked send right which may be invalid.
143 convert_clock_to_port(
148 port
= ipc_port_make_send(clock
->cl_service
);
153 * Routine: convert_clock_ctrl_to_port
155 * Convert from a clock to a port.
156 * Produces a naked send right which may be invalid.
161 convert_clock_ctrl_to_port(
166 port
= ipc_port_make_send(clock
->cl_control
);
171 * Routine: port_name_to_clock
173 * Convert from a clock name to a clock pointer.
177 mach_port_name_t clock_name
)
179 clock_t clock
= CLOCK_NULL
;
185 space
= current_space();
186 if (ipc_port_translate_send(space
, clock_name
, &port
) != KERN_SUCCESS
)
188 if (ip_active(port
) && (ip_kotype(port
) == IKOT_CLOCK
))
189 clock
= (clock_t) port
->ip_kobject
;