2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
26 * File: kern/ipc_clock.c
27 * Purpose: Routines to support ipc semantics of new kernel
28 * alarm clock facility.
31 #include <mach/message.h>
32 #include <kern/host.h>
33 #include <kern/processor.h>
34 #include <kern/task.h>
35 #include <kern/thread.h>
36 #include <kern/ipc_host.h>
37 #include <kern/ipc_kobject.h>
38 #include <kern/clock.h>
39 #include <kern/misc_protos.h>
40 #include <ipc/ipc_port.h>
41 #include <ipc/ipc_space.h>
44 * Routine: ipc_clock_init
46 * Initialize ipc control of a clock.
54 port
= ipc_port_alloc_kernel();
56 panic("ipc_clock_init");
57 clock
->cl_service
= port
;
59 port
= ipc_port_alloc_kernel();
61 panic("ipc_clock_init");
62 clock
->cl_control
= port
;
66 * Routine: ipc_clock_enable
68 * Enable ipc access to a clock.
74 ipc_kobject_set(clock
->cl_service
,
75 (ipc_kobject_t
) clock
, IKOT_CLOCK
);
76 ipc_kobject_set(clock
->cl_control
,
77 (ipc_kobject_t
) clock
, IKOT_CLOCK_CTRL
);
81 * Routine: convert_port_to_clock
83 * Convert from a port to a clock.
84 * Doesn't consume the port ref; produces a clock ref,
90 convert_port_to_clock(
93 clock_t clock
= CLOCK_NULL
;
97 if (ip_active(port
) &&
98 ((ip_kotype(port
) == IKOT_CLOCK
) ||
99 (ip_kotype(port
) == IKOT_CLOCK_CTRL
))) {
100 clock
= (clock_t) port
->ip_kobject
;
108 * Routine: convert_port_to_clock_ctrl
110 * Convert from a port to a clock.
111 * Doesn't consume the port ref; produces a clock ref,
117 convert_port_to_clock_ctrl(
120 clock_t clock
= CLOCK_NULL
;
122 if (IP_VALID(port
)) {
124 if (ip_active(port
) &&
125 (ip_kotype(port
) == IKOT_CLOCK_CTRL
)) {
126 clock
= (clock_t) port
->ip_kobject
;
134 * Routine: convert_clock_to_port
136 * Convert from a clock to a port.
137 * Produces a naked send right which may be invalid.
142 convert_clock_to_port(
147 port
= ipc_port_make_send(clock
->cl_service
);
152 * Routine: convert_clock_ctrl_to_port
154 * Convert from a clock to a port.
155 * Produces a naked send right which may be invalid.
160 convert_clock_ctrl_to_port(
165 port
= ipc_port_make_send(clock
->cl_control
);
170 * Routine: port_name_to_clock
172 * Convert from a clock name to a clock pointer.
176 mach_port_name_t clock_name
)
178 clock_t clock
= CLOCK_NULL
;
184 space
= current_space();
185 if (ipc_port_translate_send(space
, clock_name
, &port
) != KERN_SUCCESS
)
187 if (ip_active(port
) && (ip_kotype(port
) == IKOT_CLOCK
))
188 clock
= (clock_t) port
->ip_kobject
;