]> git.saurik.com Git - apple/xnu.git/blame - iokit/IOKit/IOLib.h
xnu-7195.101.1.tar.gz
[apple/xnu.git] / iokit / IOKit / IOLib.h
CommitLineData
1c79356b 1/*
39037602 2 * Copyright (c) 1998-2016 Apple Computer, Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 5 *
2d21ac55
A
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.
0a7de745 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
0a7de745 17 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
0a7de745 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/*
0a7de745 29 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
1c79356b
A
30 *
31 * HISTORY
32 *
33 */
34
35#ifndef __IOKIT_IOLIB_H
36#define __IOKIT_IOLIB_H
37
38#ifndef KERNEL
39#error IOLib.h is for kernel use only
40#endif
41
b0d623f7 42#include <stdarg.h>
55e303ae 43#include <sys/cdefs.h>
cb323159 44#include <os/overflow.h>
55e303ae 45
9bccf70c 46#include <sys/appleapiopts.h>
1c79356b
A
47
48#include <IOKit/system.h>
49
50#include <IOKit/IOReturn.h>
51#include <IOKit/IOTypes.h>
52#include <IOKit/IOLocks.h>
53
54#include <libkern/OSAtomic.h>
55
55e303ae 56__BEGIN_DECLS
1c79356b
A
57
58#include <kern/thread_call.h>
59#include <kern/clock.h>
0b4e3aa0 60
1c79356b
A
61/*
62 * min/max macros.
63 */
64
0a7de745
A
65#define min(a, b) ((a) < (b) ? (a) : (b))
66#define max(a, b) ((a) > (b) ? (a) : (b))
1c79356b
A
67
68/*
69 * These are opaque to the user.
70 */
71typedef thread_t IOThread;
72typedef void (*IOThreadFunc)(void *argument);
73
74/*
75 * Memory allocation functions.
76 */
77
78/*! @function IOMalloc
0a7de745
A
79 * @abstract Allocates general purpose, wired memory in the kernel map.
80 * @discussion This is a general purpose utility to allocate memory in the kernel. There are no alignment guarantees given on the returned memory, and alignment may vary depending on the kernel configuration. This function may block and so should not be called from interrupt level or while a simple lock is held.
81 * @param size Size of the memory requested.
82 * @result Pointer to the allocated memory, or zero on failure. */
1c79356b 83
f427ee49
A
84#if defined(XNU_KERNEL_PRIVATE)
85
86/*
87 * IOMalloc_internal allocates memory from the specifed kalloc heap, which can be:
88 * - KHEAP_DATA_BUFFERS: Should be used for data buffers
89 * - KHEAP_KEXT: Should be used for non core kernel allocations
90 * - KHEAP_DEFAULT: Should be used for all core kernel allocations that
91 * aren't data buffers.
92 *
93 * The kalloc heap used by IOMalloc calls from core kernel is KHEAP_DEFAULT
94 * and that used by kexts (accessed via IOMalloc_external) is KHEAP_KEXT.
95 *
96 * For more details on kalloc_heaps see kalloc.h
97 */
98
99extern void *
100IOMalloc_internal(
101 struct kalloc_heap * kalloc_heap_cfg,
102 vm_size_t size) __attribute__((alloc_size(2)));
103
104extern void *
105IOMallocZero_internal(
106 struct kalloc_heap * kalloc_heap_cfg,
107 vm_size_t size) __attribute__((alloc_size(2)));
108
109#define IOMalloc(size) IOMalloc_internal(KHEAP_DEFAULT, size)
110
111#define IOMallocZero(size) IOMallocZero_internal(KHEAP_DEFAULT, size)
112
113#else/* defined(XNU_KERNEL_PRIVATE) */
114
cb323159
A
115void * IOMalloc(vm_size_t size) __attribute__((alloc_size(1)));
116void * IOMallocZero(vm_size_t size) __attribute__((alloc_size(1)));
1c79356b 117
f427ee49
A
118#endif /* !defined(XNU_KERNEL_PRIVATE) */
119
1c79356b 120/*! @function IOFree
0a7de745
A
121 * @abstract Frees memory allocated with IOMalloc.
122 * @discussion This function frees memory allocated with IOMalloc, it may block and so should not be called from interrupt level or while a simple lock is held.
123 * @param address Pointer to the allocated memory. Must be identical to result
124 * @of a prior IOMalloc.
125 * @param size Size of the memory allocated. Must be identical to size of
126 * @the corresponding IOMalloc */
1c79356b
A
127
128void IOFree(void * address, vm_size_t size);
129
130/*! @function IOMallocAligned
0a7de745
A
131 * @abstract Allocates wired memory in the kernel map, with an alignment restriction.
132 * @discussion This is a utility to allocate memory in the kernel, with an alignment restriction which is specified as a byte count. This function may block and so should not be called from interrupt level or while a simple lock is held.
133 * @param size Size of the memory requested.
134 * @param alignment Byte count of the alignment for the memory. For example, pass 256 to get memory allocated at an address with bit 0-7 zero.
135 * @result Pointer to the allocated memory, or zero on failure. */
1c79356b 136
f427ee49
A
137#if defined(XNU_KERNEL_PRIVATE)
138
139extern void *
140IOMallocAligned_internal(
141 struct kalloc_heap * kalloc_heap_cfg,
142 vm_size_t size,
143 vm_size_t alignment) __attribute__((alloc_size(2)));
144
145#define IOMallocAligned(size, alignment) IOMallocAligned_internal(KHEAP_DEFAULT, size, alignment)
146
147#else/* defined(XNU_KERNEL_PRIVATE) */
148
5ba3f43e 149void * IOMallocAligned(vm_size_t size, vm_offset_t alignment) __attribute__((alloc_size(1)));
1c79356b 150
f427ee49
A
151#endif /* !defined(XNU_KERNEL_PRIVATE) */
152
1c79356b 153/*! @function IOFreeAligned
0a7de745
A
154 * @abstract Frees memory allocated with IOMallocAligned.
155 * @discussion This function frees memory allocated with IOMallocAligned, it may block and so should not be called from interrupt level or while a simple lock is held.
156 * @param address Pointer to the allocated memory.
157 * @param size Size of the memory allocated. */
1c79356b
A
158
159void IOFreeAligned(void * address, vm_size_t size);
160
161/*! @function IOMallocContiguous
0a7de745
A
162 * @abstract Deprecated - use IOBufferMemoryDescriptor. Allocates wired memory in the kernel map, with an alignment restriction and physically contiguous.
163 * @discussion This is a utility to allocate memory in the kernel, with an alignment restriction which is specified as a byte count, and will allocate only physically contiguous memory. The request may fail if memory is fragmented, and may cause large amounts of paging activity. This function may block and so should not be called from interrupt level or while a simple lock is held.
164 * @param size Size of the memory requested.
165 * @param alignment Byte count of the alignment for the memory. For example, pass 256 to get memory allocated at an address with bits 0-7 zero.
166 * @param physicalAddress IOMallocContiguous returns the physical address of the allocated memory here, if physicalAddress is a non-zero pointer. The physicalAddress argument is deprecated and should be passed as NULL. To obtain the physical address for a memory buffer, use the IODMACommand class in conjunction with the IOMemoryDescriptor or IOBufferMemoryDescriptor classes.
167 * @result Virtual address of the allocated memory, or zero on failure. */
1c79356b
A
168
169void * IOMallocContiguous(vm_size_t size, vm_size_t alignment,
0a7de745 170 IOPhysicalAddress * physicalAddress) __attribute__((deprecated)) __attribute__((alloc_size(1)));
1c79356b
A
171
172/*! @function IOFreeContiguous
0a7de745
A
173 * @abstract Deprecated - use IOBufferMemoryDescriptor. Frees memory allocated with IOMallocContiguous.
174 * @discussion This function frees memory allocated with IOMallocContiguous, it may block and so should not be called from interrupt level or while a simple lock is held.
175 * @param address Virtual address of the allocated memory.
176 * @param size Size of the memory allocated. */
1c79356b 177
b0d623f7 178void IOFreeContiguous(void * address, vm_size_t size) __attribute__((deprecated));
1c79356b
A
179
180
181/*! @function IOMallocPageable
0a7de745
A
182 * @abstract Allocates pageable memory in the kernel map.
183 * @discussion This is a utility to allocate pageable memory in the kernel. This function may block and so should not be called from interrupt level or while a simple lock is held.
184 * @param size Size of the memory requested.
185 * @param alignment Byte count of the alignment for the memory. For example, pass 256 to get memory allocated at an address with bits 0-7 zero.
186 * @result Pointer to the allocated memory, or zero on failure. */
1c79356b 187
5ba3f43e 188void * IOMallocPageable(vm_size_t size, vm_size_t alignment) __attribute__((alloc_size(1)));
1c79356b 189
f427ee49
A
190/*! @function IOMallocPageableZero
191 * @abstract Allocates pageable, zeroed memory in the kernel map.
192 * @discussion Same as IOMallocPageable but guarantees the returned memory will be zeroed.
193 * @param size Size of the memory requested.
194 * @param alignment Byte count of the alignment for the memory. For example, pass 256 to get memory allocated at an address with bits 0-7 zero.
195 * @result Pointer to the allocated memory, or zero on failure. */
196
197void * IOMallocPageableZero(vm_size_t size, vm_size_t alignment) __attribute__((alloc_size(1)));
198
1c79356b 199/*! @function IOFreePageable
0a7de745
A
200 * @abstract Frees memory allocated with IOMallocPageable.
201 * @discussion This function frees memory allocated with IOMallocPageable, it may block and so should not be called from interrupt level or while a simple lock is held.
202 * @param address Virtual address of the allocated memory.
203 * @param size Size of the memory allocated. */
1c79356b
A
204
205void IOFreePageable(void * address, vm_size_t size);
206
207/*
cb323159 208 * Typed memory allocation macros. All may block.
1c79356b 209 */
3e170ce0 210
cb323159
A
211#define IONew(type, count) \
212({ \
213 size_t __size; \
214 (os_mul_overflow(sizeof(type), (count), &__size) \
215 ? ((type *) NULL) \
216 : ((type *) IOMalloc(__size))); \
217})
218
219#define IONewZero(type, count) \
220({ \
221 size_t __size; \
222 (os_mul_overflow(sizeof(type), (count), &__size) \
223 ? ((type *) NULL) \
224 : ((type *) IOMallocZero(__size))); \
225})
226
227#define IODelete(ptr, type, count) \
228({ \
229 size_t __size; \
230 if (!os_mul_overflow(sizeof(type), (count), &__size)) { \
231 IOFree(ptr, __size); \
232 } \
233})
234
235#define IOSafeDeleteNULL(ptr, type, count) \
236 do { \
237 if (NULL != (ptr)) { \
238 IODelete((ptr), type, count); \
239 (ptr) = NULL; \
240 } \
241 } while (0) \
1c79356b 242
55e303ae
A
243/////////////////////////////////////////////////////////////////////////////
244//
245//
246// These functions are now implemented in IOMapper.cpp
247//
248//
249/////////////////////////////////////////////////////////////////////////////
250
251/*! @function IOMappedRead8
0a7de745
A
252 * @abstract Read one byte from the desired "Physical" IOSpace address.
253 * @discussion Read one byte from the desired "Physical" IOSpace address. This function allows the developer to read an address returned from any memory descriptor's getPhysicalSegment routine. It can then be used by segmenting a physical page slightly to tag the physical page with its kernel space virtual address.
254 * @param address The desired address, as returned by IOMemoryDescriptor::getPhysicalSegment.
255 * @result Data contained at that location */
55e303ae
A
256
257UInt8 IOMappedRead8(IOPhysicalAddress address);
258
259/*! @function IOMappedRead16
0a7de745
A
260 * @abstract Read two bytes from the desired "Physical" IOSpace address.
261 * @discussion Read two bytes from the desired "Physical" IOSpace address. This function allows the developer to read an address returned from any memory descriptor's getPhysicalSegment routine. It can then be used by segmenting a physical page slightly to tag the physical page with its kernel space virtual address.
262 * @param address The desired address, as returned by IOMemoryDescriptor::getPhysicalSegment.
263 * @result Data contained at that location */
55e303ae
A
264
265UInt16 IOMappedRead16(IOPhysicalAddress address);
266
267/*! @function IOMappedRead32
0a7de745
A
268 * @abstract Read four bytes from the desired "Physical" IOSpace address.
269 * @discussion Read four bytes from the desired "Physical" IOSpace address. This function allows the developer to read an address returned from any memory descriptor's getPhysicalSegment routine. It can then be used by segmenting a physical page slightly to tag the physical page with its kernel space virtual address.
270 * @param address The desired address, as returned by IOMemoryDescriptor::getPhysicalSegment.
271 * @result Data contained at that location */
55e303ae
A
272
273UInt32 IOMappedRead32(IOPhysicalAddress address);
274
275/*! @function IOMappedRead64
0a7de745
A
276 * @abstract Read eight bytes from the desired "Physical" IOSpace address.
277 * @discussion Read eight bytes from the desired "Physical" IOSpace address. This function allows the developer to read an address returned from any memory descriptor's getPhysicalSegment routine. It can then be used by segmenting a physical page slightly to tag the physical page with its kernel space virtual address.
278 * @param address The desired address, as returned by IOMemoryDescriptor::getPhysicalSegment.
279 * @result Data contained at that location */
55e303ae
A
280
281UInt64 IOMappedRead64(IOPhysicalAddress address);
282
283/*! @function IOMappedWrite8
0a7de745
A
284 * @abstract Write one byte to the desired "Physical" IOSpace address.
285 * @discussion Write one byte to the desired "Physical" IOSpace address. This function allows the developer to write to an address returned from any memory descriptor's getPhysicalSegment routine.
286 * @param address The desired address, as returned by IOMemoryDescriptor::getPhysicalSegment.
287 * @param value Data to be writen to the desired location */
55e303ae
A
288
289void IOMappedWrite8(IOPhysicalAddress address, UInt8 value);
290
291/*! @function IOMappedWrite16
0a7de745
A
292 * @abstract Write two bytes to the desired "Physical" IOSpace address.
293 * @discussion Write two bytes to the desired "Physical" IOSpace address. This function allows the developer to write to an address returned from any memory descriptor's getPhysicalSegment routine.
294 * @param address The desired address, as returned by IOMemoryDescriptor::getPhysicalSegment.
295 * @param value Data to be writen to the desired location */
55e303ae
A
296
297void IOMappedWrite16(IOPhysicalAddress address, UInt16 value);
298
299/*! @function IOMappedWrite32
0a7de745
A
300 * @abstract Write four bytes to the desired "Physical" IOSpace address.
301 * @discussion Write four bytes to the desired "Physical" IOSpace address. This function allows the developer to write to an address returned from any memory descriptor's getPhysicalSegment routine.
302 * @param address The desired address, as returned by IOMemoryDescriptor::getPhysicalSegment.
303 * @param value Data to be writen to the desired location */
55e303ae
A
304
305void IOMappedWrite32(IOPhysicalAddress address, UInt32 value);
306
307/*! @function IOMappedWrite64
0a7de745
A
308 * @abstract Write eight bytes to the desired "Physical" IOSpace address.
309 * @discussion Write eight bytes to the desired "Physical" IOSpace address. This function allows the developer to write to an address returned from any memory descriptor's getPhysicalSegment routine.
310 * @param address The desired address, as returned by IOMemoryDescriptor::getPhysicalSegment.
311 * @param value Data to be writen to the desired location */
55e303ae
A
312
313void IOMappedWrite64(IOPhysicalAddress address, UInt64 value);
314
6d2010ae 315/* This function is deprecated. Cache settings may be set for allocated memory with the IOBufferMemoryDescriptor api. */
1c79356b
A
316
317IOReturn IOSetProcessorCacheMode( task_t task, IOVirtualAddress address,
0a7de745 318 IOByteCount length, IOOptionBits cacheMode ) __attribute__((deprecated));
1c79356b
A
319
320/*! @function IOFlushProcessorCache
0a7de745
A
321 * @abstract Flushes the processor cache for mapped memory.
322 * @discussion This function flushes the processor cache of an already mapped memory range. Note in most cases it is preferable to use IOMemoryDescriptor::prepare and complete to manage cache coherency since they are aware of the architecture's requirements. Flushing the processor cache is not required for coherency in most situations.
323 * @param task Task the memory is mapped into.
324 * @param address Virtual address of the memory.
325 * @param length Length of the range to set.
326 * @result An IOReturn code. */
1c79356b
A
327
328IOReturn IOFlushProcessorCache( task_t task, IOVirtualAddress address,
0a7de745 329 IOByteCount length );
1c79356b
A
330
331/*! @function IOThreadSelf
0a7de745
A
332 * @abstract Returns the osfmk identifier for the currently running thread.
333 * @discussion This function returns the current thread (a pointer to the currently active osfmk thread_shuttle). */
1c79356b
A
334
335#define IOThreadSelf() (current_thread())
336
337/*! @function IOCreateThread
0a7de745
A
338 * @abstract Deprecated function - use kernel_thread_start(). Create a kernel thread.
339 * @discussion This function creates a kernel thread, and passes the caller supplied argument to the new thread. Warning: the value returned by this function is not 100% reliable. There is a race condition where it is possible that the new thread has already terminated before this call returns. Under that circumstance the IOThread returned will be invalid. In general there is little that can be done with this value except compare it against 0. The thread itself can call IOThreadSelf() 100% reliably and that is the prefered mechanism to manipulate the IOThreads state.
340 * @param function A C-function pointer where the thread will begin execution.
341 * @param argument Caller specified data to be passed to the new thread.
342 * @result An IOThread identifier for the new thread, equivalent to an osfmk thread_t. */
1c79356b 343
b0d623f7 344IOThread IOCreateThread(IOThreadFunc function, void *argument) __attribute__((deprecated));
1c79356b
A
345
346/*! @function IOExitThread
0a7de745
A
347 * @abstract Deprecated function - use thread_terminate(). Terminate execution of current thread.
348 * @discussion This function destroys the currently running thread, and does not return. */
1c79356b 349
b0d623f7 350void IOExitThread(void) __attribute__((deprecated));
1c79356b
A
351
352/*! @function IOSleep
0a7de745
A
353 * @abstract Sleep the calling thread for a number of milliseconds.
354 * @discussion This function blocks the calling thread for at least the number of specified milliseconds, giving time to other processes.
355 * @param milliseconds The integer number of milliseconds to wait. */
1c79356b
A
356
357void IOSleep(unsigned milliseconds);
358
3e170ce0 359/*! @function IOSleepWithLeeway
0a7de745
A
360 * @abstract Sleep the calling thread for a number of milliseconds, with a specified leeway the kernel may use for timer coalescing.
361 * @discussion This function blocks the calling thread for at least the number of specified milliseconds, giving time to other processes. The kernel may also coalesce any timers involved in the delay, using the leeway given as a guideline.
362 * @param intervalMilliseconds The integer number of milliseconds to wait.
363 * @param leewayMilliseconds The integer number of milliseconds to use as a timer coalescing guideline. */
3e170ce0
A
364
365void IOSleepWithLeeway(unsigned intervalMilliseconds, unsigned leewayMilliseconds);
366
1c79356b 367/*! @function IODelay
0a7de745
A
368 * @abstract Spin delay for a number of microseconds.
369 * @discussion This function spins to delay for at least the number of specified microseconds. Since the CPU is busy spinning no time is made available to other processes; this method of delay should be used only for short periods. Also, the AbsoluteTime based APIs of kern/clock.h provide finer grained and lower cost delays.
370 * @param microseconds The integer number of microseconds to spin wait. */
1c79356b
A
371
372void IODelay(unsigned microseconds);
373
2d21ac55 374/*! @function IOPause
0a7de745
A
375 * @abstract Spin delay for a number of nanoseconds.
376 * @discussion This function spins to delay for at least the number of specified nanoseconds. Since the CPU is busy spinning no time is made available to other processes; this method of delay should be used only for short periods.
377 * @param nanoseconds The integer number of nanoseconds to spin wait. */
2d21ac55
A
378
379void IOPause(unsigned nanoseconds);
380
1c79356b 381/*! @function IOLog
0a7de745
A
382 * @abstract Log a message to console in text mode, and /var/log/system.log.
383 * @discussion This function allows a driver to log diagnostic information to the screen during verbose boots, and to a log file found at /var/log/system.log. IOLog should not be called from interrupt context.
384 * @param format A printf() style format string (see printf(3) documentation).
385 */
1c79356b
A
386
387void IOLog(const char *format, ...)
388__attribute__((format(printf, 1, 2)));
389
b0d623f7 390/*! @function IOLogv
0a7de745
A
391 * @abstract Log a message to console in text mode, and /var/log/system.log.
392 * @discussion This function allows a driver to log diagnostic information to the screen during verbose boots, and to a log file found at /var/log/system.log. IOLogv should not be called from interrupt context.
393 * @param format A printf() style format string (see printf(3) documentation).
394 * @param ap stdarg(3) style variable arguments. */
b0d623f7 395
5ba3f43e
A
396void IOLogv(const char *format, va_list ap)
397__attribute__((format(printf, 1, 0)));
b0d623f7 398
91447636 399#ifndef _FN_KPRINTF
0a7de745 400#define _FN_KPRINTF
f427ee49 401void kprintf(const char *format, ...) __printflike(1, 2);
91447636
A
402#endif
403#ifndef _FN_KPRINTF_DECLARED
0a7de745 404#define _FN_KPRINTF_DECLARED
91447636 405#endif
1c79356b
A
406
407/*
408 * Convert a integer constant (typically a #define or enum) to a string
409 * via an array of IONamedValue.
410 */
0a7de745
A
411const char *IOFindNameForValue(int value,
412 const IONamedValue *namedValueArray);
1c79356b
A
413
414/*
415 * Convert a string to an int via an array of IONamedValue. Returns
416 * kIOReturnSuccess of string found, else returns kIOReturnBadArgument.
417 */
0a7de745
A
418IOReturn IOFindValueForName(const char *string,
419 const IONamedValue *regValueArray,
420 int *value); /* RETURNED */
1c79356b
A
421
422/*! @function Debugger
0a7de745
A
423 * @abstract Enter the kernel debugger.
424 * @discussion This function freezes the kernel and enters the builtin debugger. It may not be possible to exit the debugger without a second machine.
425 * @param reason A C-string to describe why the debugger is being entered. */
426
1c79356b 427void Debugger(const char * reason);
b0d623f7
A
428#if __LP64__
429#define IOPanic(reason) panic("%s", reason)
430#else
cb323159 431void IOPanic(const char *reason) __attribute__((deprecated)) __abortlike;
b0d623f7 432#endif
1c79356b 433
6d2010ae
A
434#ifdef __cplusplus
435class OSDictionary;
436#endif
437
438#ifdef __cplusplus
439OSDictionary *
440#else
441struct OSDictionary *
442#endif
443IOBSDNameMatching( const char * name );
444
445#ifdef __cplusplus
446OSDictionary *
447#else
448struct OSDictionary *
449#endif
316670eb 450IOOFPathMatching( const char * path, char * buf, int maxLen ) __attribute__((deprecated));
1c79356b
A
451
452/*
453 * Convert between size and a power-of-two alignment.
454 */
455IOAlignment IOSizeToAlignment(unsigned int size);
456unsigned int IOAlignmentToSize(IOAlignment align);
457
458/*
459 * Multiply and divide routines for IOFixed datatype.
460 */
461
0a7de745
A
462static inline IOFixed
463IOFixedMultiply(IOFixed a, IOFixed b)
1c79356b 464{
0a7de745 465 return (IOFixed)((((SInt64) a) * ((SInt64) b)) >> 16);
1c79356b
A
466}
467
0a7de745
A
468static inline IOFixed
469IOFixedDivide(IOFixed a, IOFixed b)
1c79356b 470{
0a7de745 471 return (IOFixed)((((SInt64) a) << 16) / ((SInt64) b));
1c79356b
A
472}
473
474/*
475 * IORound and IOTrunc convenience functions, in the spirit
476 * of vm's round_page() and trunc_page().
477 */
0a7de745
A
478#define IORound(value, multiple) \
479 ((((value) + (multiple) - 1) / (multiple)) * (multiple))
1c79356b 480
0a7de745
A
481#define IOTrunc(value, multiple) \
482 (((value) / (multiple)) * (multiple));
1c79356b
A
483
484
b0d623f7 485#if defined(__APPLE_API_OBSOLETE)
1c79356b
A
486
487/* The following API is deprecated */
488
0b4e3aa0 489/* The API exported by kern/clock.h
0a7de745 490 * should be used for high resolution timing. */
1c79356b 491
b0d623f7
A
492void IOGetTime( mach_timespec_t * clock_time) __attribute__((deprecated));
493
494#if !defined(__LP64__)
495
496#undef eieio
497#define eieio() \
498 OSSynchronizeIO()
1c79356b
A
499
500extern mach_timespec_t IOZeroTvalspec;
501
b0d623f7
A
502#endif /* !defined(__LP64__) */
503
9bccf70c 504#endif /* __APPLE_API_OBSOLETE */
1c79356b 505
3e170ce0
A
506#if XNU_KERNEL_PRIVATE
507vm_tag_t
508IOMemoryTag(vm_map_t map);
509#endif
510
55e303ae 511__END_DECLS
1c79356b
A
512
513#endif /* !__IOKIT_IOLIB_H */