1 | /** $Id: timer-r0drv-solaris.c 9176 2008-05-27 15:22:00Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Timer, Ring-0 Driver, Solaris.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | *
|
---|
26 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
27 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
28 | * additional information or have any questions.
|
---|
29 | */
|
---|
30 |
|
---|
31 |
|
---|
32 | /*******************************************************************************
|
---|
33 | * Header Files *
|
---|
34 | *******************************************************************************/
|
---|
35 | #include "the-solaris-kernel.h"
|
---|
36 |
|
---|
37 | #include <iprt/timer.h>
|
---|
38 | #include <iprt/time.h>
|
---|
39 | #include <iprt/spinlock.h>
|
---|
40 | #include <iprt/err.h>
|
---|
41 | #include <iprt/asm.h>
|
---|
42 | #include <iprt/assert.h>
|
---|
43 | #include <iprt/alloc.h>
|
---|
44 |
|
---|
45 | #include "internal/magics.h"
|
---|
46 |
|
---|
47 |
|
---|
48 | /*******************************************************************************
|
---|
49 | * Structures and Typedefs *
|
---|
50 | *******************************************************************************/
|
---|
51 | /**
|
---|
52 | * The internal representation of a Solaris timer handle.
|
---|
53 | */
|
---|
54 | typedef struct RTTIMER
|
---|
55 | {
|
---|
56 | /** Magic.
|
---|
57 | * This is RTTIMER_MAGIC, but changes to something else before the timer
|
---|
58 | * is destroyed to indicate clearly that thread should exit. */
|
---|
59 | uint32_t volatile u32Magic;
|
---|
60 | /** Flag indicating the the timer is suspended. */
|
---|
61 | uint8_t volatile fSuspended;
|
---|
62 | /** Whether the timer must run on a specific CPU or not. */
|
---|
63 | uint8_t fSpecificCpu;
|
---|
64 | /** The CPU it must run on if fSpecificCpu is set. */
|
---|
65 | uint8_t iCpu;
|
---|
66 | /** The Solaris timer handle. */
|
---|
67 | void *handle;
|
---|
68 | } RTTIMER;
|
---|
69 |
|
---|
70 |
|
---|
71 | RTDECL(int) RTTimerCreateEx(PRTTIMER *ppTimer, uint64_t u64NanoInterval, unsigned fFlags, PFNRTTIMER pfnTimer, void *pvUser)
|
---|
72 | {
|
---|
73 | *ppTimer = NULL;
|
---|
74 |
|
---|
75 | /*
|
---|
76 | * Validate flags.
|
---|
77 | */
|
---|
78 | if (!RTTIMER_FLAGS_IS_VALID(fFlags))
|
---|
79 | return VERR_INVALID_PARAMETER;
|
---|
80 | if ( (fFlags & RTTIMER_FLAGS_CPU_SPECIFIC)
|
---|
81 | /** @todo implement && (fFlags & RTTIMER_FLAGS_CPU_ALL) != RTTIMER_FLAGS_CPU_ALL*/)
|
---|
82 | return VERR_NOT_SUPPORTED;
|
---|
83 |
|
---|
84 | /*
|
---|
85 | * Allocate and initialize the timer handle.
|
---|
86 | */
|
---|
87 | PRTTIMER pTimer = (PRTTIMER)RTMemAlloc(sizeof(*pTimer));
|
---|
88 | if (!pTimer)
|
---|
89 | return VERR_NO_MEMORY;
|
---|
90 |
|
---|
91 | pTimer->u32Magic = RTTIMER_MAGIC;
|
---|
92 | pTimer->fSuspended = true;
|
---|
93 | pTimer->fSpecificCpu = !!(fFlags & RTTIMER_FLAGS_CPU_SPECIFIC);
|
---|
94 | pTimer->iCpu = fFlags & RTTIMER_FLAGS_CPU_MASK;
|
---|
95 | pTimer->handle = vbi_timer_create(pfnTimer, pTimer, pvUser, u64NanoInterval);
|
---|
96 |
|
---|
97 | *ppTimer = pTimer;
|
---|
98 | return VINF_SUCCESS;
|
---|
99 | }
|
---|
100 |
|
---|
101 |
|
---|
102 | /**
|
---|
103 | * Validates the timer handle.
|
---|
104 | *
|
---|
105 | * @returns true if valid, false if invalid.
|
---|
106 | * @param pTimer The handle.
|
---|
107 | */
|
---|
108 | DECLINLINE(bool) rtTimerIsValid(PRTTIMER pTimer)
|
---|
109 | {
|
---|
110 | AssertReturn(VALID_PTR(pTimer), false);
|
---|
111 | AssertReturn(pTimer->u32Magic == RTTIMER_MAGIC, false);
|
---|
112 | return true;
|
---|
113 | }
|
---|
114 |
|
---|
115 |
|
---|
116 | RTDECL(int) RTTimerDestroy(PRTTIMER pTimer)
|
---|
117 | {
|
---|
118 | if (pTimer == NULL)
|
---|
119 | return VINF_SUCCESS;
|
---|
120 | if (!rtTimerIsValid(pTimer))
|
---|
121 | return VERR_INVALID_HANDLE;
|
---|
122 |
|
---|
123 | /*
|
---|
124 | * Free the associated resources.
|
---|
125 | */
|
---|
126 | pTimer->u32Magic++;
|
---|
127 | vbi_timer_stop(pTimer->handle);
|
---|
128 | vbi_timer_destroy(pTimer->handle);
|
---|
129 | RTMemFree(pTimer);
|
---|
130 | return VINF_SUCCESS;
|
---|
131 | }
|
---|
132 |
|
---|
133 |
|
---|
134 | RTDECL(int) RTTimerStart(PRTTIMER pTimer, uint64_t u64First)
|
---|
135 | {
|
---|
136 | if (!rtTimerIsValid(pTimer))
|
---|
137 | return VERR_INVALID_HANDLE;
|
---|
138 | if (!pTimer->fSuspended)
|
---|
139 | return VERR_TIMER_ACTIVE;
|
---|
140 |
|
---|
141 | /*
|
---|
142 | * Calc when it should start firing.
|
---|
143 | */
|
---|
144 | pTimer->fSuspended = false;
|
---|
145 | vbi_timer_start(pTimer->handle, u64First);
|
---|
146 |
|
---|
147 | return VINF_SUCCESS;
|
---|
148 | }
|
---|
149 |
|
---|
150 |
|
---|
151 | RTDECL(int) RTTimerStop(PRTTIMER pTimer)
|
---|
152 | {
|
---|
153 | if (!rtTimerIsValid(pTimer))
|
---|
154 | return VERR_INVALID_HANDLE;
|
---|
155 | if (pTimer->fSuspended)
|
---|
156 | return VERR_TIMER_SUSPENDED;
|
---|
157 |
|
---|
158 | /*
|
---|
159 | * Suspend the timer.
|
---|
160 | */
|
---|
161 | pTimer->fSuspended = true;
|
---|
162 | vbi_timer_stop(pTimer->handle);
|
---|
163 |
|
---|
164 | return VINF_SUCCESS;
|
---|
165 | }
|
---|
166 |
|
---|
167 |
|
---|
168 |
|
---|
169 | RTDECL(uint32_t) RTTimerGetSystemGranularity(void)
|
---|
170 | {
|
---|
171 | return vbi_timer_granularity();
|
---|
172 | }
|
---|
173 |
|
---|
174 |
|
---|
175 | RTDECL(int) RTTimerRequestSystemGranularity(uint32_t u32Request, uint32_t *pu32Granted)
|
---|
176 | {
|
---|
177 | return VERR_NOT_SUPPORTED;
|
---|
178 | }
|
---|
179 |
|
---|
180 |
|
---|
181 | RTDECL(int) RTTimerReleaseSystemGranularity(uint32_t u32Granted)
|
---|
182 | {
|
---|
183 | return VERR_NOT_SUPPORTED;
|
---|
184 | }
|
---|
185 |
|
---|