1/*
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28/*
29 * Copyright (C) 1998 Apple Computer
30 * All Rights Reserved
31 */
32/*
33 * @OSF_COPYRIGHT@
34 */
35/*
36 * Mach Operating System
37 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
38 * All Rights Reserved.
39 *
40 * Permission to use, copy, modify and distribute this software and its
41 * documentation is hereby granted, provided that both the copyright
42 * notice and this permission notice appear in all copies of the
43 * software, derivative works or modified versions, and any portions
44 * thereof, and that both notices appear in supporting documentation.
45 *
46 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
47 * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
48 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
49 *
50 * Carnegie Mellon requests users of this software to return to
51 *
52 *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
53 *  School of Computer Science
54 *  Carnegie Mellon University
55 *  Pittsburgh PA 15213-3890
56 *
57 * any improvements or extensions that they make and grant Carnegie Mellon
58 * the rights to redistribute these changes.
59 */
60/*
61 *	File:	kern/simple_lock.h (derived from kern/lock.h)
62 *	Author:	Avadis Tevanian, Jr., Michael Wayne Young
63 *	Date:	1985
64 *
65 *	Atomic primitives and Simple Locking primitives definitions
66 */
67
68#ifdef	KERNEL_PRIVATE
69
70#ifndef	_KERN_SIMPLE_LOCK_H_
71#define	_KERN_SIMPLE_LOCK_H_
72
73#include <sys/cdefs.h>
74#include <mach/boolean.h>
75#include <kern/kern_types.h>
76#include <machine/simple_lock.h>
77
78#include <machine/lock.h>
79
80#ifdef	MACH_KERNEL_PRIVATE
81#include <mach_ldebug.h>
82
83extern void			hw_lock_init(
84					hw_lock_t);
85
86extern void			hw_lock_lock(
87					hw_lock_t);
88
89extern void			hw_lock_unlock(
90					hw_lock_t);
91
92extern unsigned int		hw_lock_to(
93					hw_lock_t,
94					unsigned int);
95
96extern unsigned int		hw_lock_try(
97					hw_lock_t);
98
99extern unsigned int		hw_lock_held(
100					hw_lock_t);
101
102#endif	/* MACH_KERNEL_PRIVATE */
103
104__BEGIN_DECLS
105
106extern uint32_t			hw_atomic_add(
107					volatile uint32_t	*dest,
108					uint32_t	delt);
109
110extern uint32_t			hw_atomic_sub(
111					volatile uint32_t	*dest,
112					uint32_t	delt);
113
114extern uint32_t			hw_atomic_or(
115					volatile uint32_t	*dest,
116					uint32_t	mask);
117
118extern uint32_t			hw_atomic_and(
119					volatile uint32_t	*dest,
120					uint32_t	mask);
121
122/*
123 * Variant of hw_atomic_or which doesn't return a value; potentially
124 * more efficient on some platforms.
125 */
126extern void			hw_atomic_or_noret(
127					volatile uint32_t	*dest,
128					uint32_t	mask);
129
130
131extern void			hw_atomic_and_noret(
132					volatile uint32_t	*dest,
133					uint32_t	mask);
134
135
136#ifdef __arm__
137#define hw_atomic_or     hw_atomic_or_noret
138#define hw_atomic_and    hw_atomic_and_noret
139#endif
140
141/*
142 * Variant of hw_atomic_and which doesn't return a value; potentially
143 * more efficient on some platforms.
144 */
145
146extern void			hw_atomic_and_noret(
147					volatile uint32_t	*dest,
148					uint32_t	mask);
149
150extern uint32_t			hw_compare_and_store(
151					uint32_t	oldval,
152					uint32_t	newval,
153					volatile uint32_t	*dest);
154
155extern void			hw_queue_atomic(
156					unsigned int *anchor,
157					unsigned int *elem,
158					unsigned int disp);
159
160extern void 			hw_queue_atomic_list(
161					unsigned int *anchor,
162					unsigned int *first,
163					unsigned int *last,
164					unsigned int disp);
165
166extern unsigned int 		*hw_dequeue_atomic(
167					unsigned int *anchor,
168					unsigned int disp);
169
170extern void			usimple_lock_init(
171					usimple_lock_t,
172					unsigned short);
173
174extern void			usimple_lock(
175					usimple_lock_t);
176
177extern void			usimple_unlock(
178					usimple_lock_t);
179
180extern unsigned int		usimple_lock_try(
181					usimple_lock_t);
182
183__END_DECLS
184
185#define	ETAP_NO_TRACE	0
186#define ETAP_IO_AHA		0
187
188/*
189 * If we got to here and we still don't have simple_lock_init
190 * defined, then we must either be outside the osfmk component,
191 * running on a true SMP, or need debug.
192 */
193#if !defined(simple_lock_init)
194#define simple_lock_init(l,t)	usimple_lock_init(l,t)
195#define	simple_lock(l)		usimple_lock(l)
196#define	simple_unlock(l)	usimple_unlock(l)
197#define simple_lock_try(l)	usimple_lock_try(l)
198#define simple_lock_addr(l)	(&(l))
199#define thread_sleep_simple_lock(l, e, i) \
200				thread_sleep_usimple_lock((l), (e), (i))
201#endif /* !defined(simple_lock_init) */
202
203#endif /*!_KERN_SIMPLE_LOCK_H_*/
204
205#endif	/* KERNEL_PRIVATE */
206