[3854] | 1 | /** @file
|
---|
| 2 | * PDM - Pluggable Device Manager, Queues.
|
---|
| 3 | */
|
---|
| 4 |
|
---|
| 5 | /*
|
---|
| 6 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
| 7 | *
|
---|
| 8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
| 9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
| 10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
[5999] | 11 | * General Public License (GPL) as published by the Free Software
|
---|
| 12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
| 13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
| 14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
| 15 | *
|
---|
| 16 | * The contents of this file may alternatively be used under the terms
|
---|
| 17 | * of the Common Development and Distribution License Version 1.0
|
---|
| 18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
| 19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
| 20 | * CDDL are applicable instead of those of the GPL.
|
---|
| 21 | *
|
---|
| 22 | * You may elect to license modified versions of this file under the
|
---|
| 23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
[3854] | 24 | */
|
---|
| 25 |
|
---|
| 26 | #ifndef ___VBox_pdmqueue_h
|
---|
| 27 | #define ___VBox_pdmqueue_h
|
---|
| 28 |
|
---|
[4011] | 29 | #include <VBox/types.h>
|
---|
| 30 |
|
---|
[3854] | 31 | __BEGIN_DECLS
|
---|
| 32 |
|
---|
| 33 | /** @defgroup grp_pdm_queue Queues
|
---|
| 34 | * @ingroup grp_pdm
|
---|
| 35 | * @{
|
---|
| 36 | */
|
---|
| 37 |
|
---|
| 38 | /** Pointer to a PDM queue. Also called PDM queue handle. */
|
---|
| 39 | typedef struct PDMQUEUE *PPDMQUEUE;
|
---|
| 40 |
|
---|
| 41 | /** Pointer to a PDM queue item core. */
|
---|
| 42 | typedef struct PDMQUEUEITEMCORE *PPDMQUEUEITEMCORE;
|
---|
| 43 |
|
---|
| 44 | /**
|
---|
| 45 | * PDM queue item core.
|
---|
| 46 | */
|
---|
| 47 | typedef struct PDMQUEUEITEMCORE
|
---|
| 48 | {
|
---|
| 49 | /** Pointer to the next item in the pending list - HC Pointer. */
|
---|
[4787] | 50 | R3R0PTRTYPE(PPDMQUEUEITEMCORE) pNextHC;
|
---|
[3854] | 51 | /** Pointer to the next item in the pending list - GC Pointer. */
|
---|
| 52 | GCPTRTYPE(PPDMQUEUEITEMCORE) pNextGC;
|
---|
| 53 | #if HC_ARCH_BITS == 64 && GC_ARCH_BITS == 32
|
---|
| 54 | uint32_t Alignment0;
|
---|
| 55 | #endif
|
---|
| 56 | } PDMQUEUEITEMCORE;
|
---|
| 57 |
|
---|
| 58 |
|
---|
| 59 | /**
|
---|
| 60 | * Queue consumer callback for devices.
|
---|
| 61 | *
|
---|
| 62 | * @returns Success indicator.
|
---|
| 63 | * If false the item will not be removed and the flushing will stop.
|
---|
| 64 | * @param pDevIns The device instance.
|
---|
| 65 | * @param pItem The item to consume. Upon return this item will be freed.
|
---|
| 66 | */
|
---|
| 67 | typedef DECLCALLBACK(bool) FNPDMQUEUEDEV(PPDMDEVINS pDevIns, PPDMQUEUEITEMCORE pItem);
|
---|
| 68 | /** Pointer to a FNPDMQUEUEDEV(). */
|
---|
| 69 | typedef FNPDMQUEUEDEV *PFNPDMQUEUEDEV;
|
---|
| 70 |
|
---|
| 71 | /**
|
---|
| 72 | * Queue consumer callback for drivers.
|
---|
| 73 | *
|
---|
| 74 | * @returns Success indicator.
|
---|
| 75 | * If false the item will not be removed and the flushing will stop.
|
---|
| 76 | * @param pDrvIns The driver instance.
|
---|
| 77 | * @param pItem The item to consume. Upon return this item will be freed.
|
---|
| 78 | */
|
---|
| 79 | typedef DECLCALLBACK(bool) FNPDMQUEUEDRV(PPDMDRVINS pDrvIns, PPDMQUEUEITEMCORE pItem);
|
---|
| 80 | /** Pointer to a FNPDMQUEUEDRV(). */
|
---|
| 81 | typedef FNPDMQUEUEDRV *PFNPDMQUEUEDRV;
|
---|
| 82 |
|
---|
| 83 | /**
|
---|
| 84 | * Queue consumer callback for internal component.
|
---|
| 85 | *
|
---|
| 86 | * @returns Success indicator.
|
---|
| 87 | * If false the item will not be removed and the flushing will stop.
|
---|
| 88 | * @param pVM The VM handle.
|
---|
| 89 | * @param pItem The item to consume. Upon return this item will be freed.
|
---|
| 90 | */
|
---|
| 91 | typedef DECLCALLBACK(bool) FNPDMQUEUEINT(PVM pVM, PPDMQUEUEITEMCORE pItem);
|
---|
| 92 | /** Pointer to a FNPDMQUEUEINT(). */
|
---|
| 93 | typedef FNPDMQUEUEINT *PFNPDMQUEUEINT;
|
---|
| 94 |
|
---|
| 95 | /**
|
---|
| 96 | * Queue consumer callback for external component.
|
---|
| 97 | *
|
---|
| 98 | * @returns Success indicator.
|
---|
| 99 | * If false the item will not be removed and the flushing will stop.
|
---|
| 100 | * @param pvUser User argument.
|
---|
| 101 | * @param pItem The item to consume. Upon return this item will be freed.
|
---|
| 102 | */
|
---|
| 103 | typedef DECLCALLBACK(bool) FNPDMQUEUEEXT(void *pvUser, PPDMQUEUEITEMCORE pItem);
|
---|
| 104 | /** Pointer to a FNPDMQUEUEEXT(). */
|
---|
| 105 | typedef FNPDMQUEUEEXT *PFNPDMQUEUEEXT;
|
---|
| 106 |
|
---|
| 107 | /**
|
---|
| 108 | * Create a queue with a device owner.
|
---|
| 109 | *
|
---|
| 110 | * @returns VBox status code.
|
---|
| 111 | * @param pVM VM handle.
|
---|
| 112 | * @param pDevIns Device instance.
|
---|
| 113 | * @param cbItem Size a queue item.
|
---|
| 114 | * @param cItems Number of items in the queue.
|
---|
| 115 | * @param cMilliesInterval Number of milliseconds between polling the queue.
|
---|
| 116 | * If 0 then the emulation thread will be notified whenever an item arrives.
|
---|
| 117 | * @param pfnCallback The consumer function.
|
---|
| 118 | * @param fGCEnabled Set if the queue must be usable from GC.
|
---|
| 119 | * @param ppQueue Where to store the queue handle on success.
|
---|
| 120 | * @thread Emulation thread only.
|
---|
| 121 | */
|
---|
| 122 | PDMR3DECL(int) PDMR3QueueCreateDevice(PVM pVM, PPDMDEVINS pDevIns, RTUINT cbItem, RTUINT cItems, uint32_t cMilliesInterval,
|
---|
| 123 | PFNPDMQUEUEDEV pfnCallback, bool fGCEnabled, PPDMQUEUE *ppQueue);
|
---|
| 124 |
|
---|
| 125 | /**
|
---|
| 126 | * Create a queue with a driver owner.
|
---|
| 127 | *
|
---|
| 128 | * @returns VBox status code.
|
---|
| 129 | * @param pVM VM handle.
|
---|
| 130 | * @param pDrvIns Driver instance.
|
---|
| 131 | * @param cbItem Size a queue item.
|
---|
| 132 | * @param cItems Number of items in the queue.
|
---|
| 133 | * @param cMilliesInterval Number of milliseconds between polling the queue.
|
---|
| 134 | * If 0 then the emulation thread will be notified whenever an item arrives.
|
---|
| 135 | * @param pfnCallback The consumer function.
|
---|
| 136 | * @param ppQueue Where to store the queue handle on success.
|
---|
| 137 | * @thread The emulation thread.
|
---|
| 138 | */
|
---|
| 139 | PDMR3DECL(int) PDMR3QueueCreateDriver(PVM pVM, PPDMDRVINS pDrvIns, RTUINT cbItem, RTUINT cItems, uint32_t cMilliesInterval,
|
---|
| 140 | PFNPDMQUEUEDRV pfnCallback, PPDMQUEUE *ppQueue);
|
---|
| 141 |
|
---|
| 142 | /**
|
---|
| 143 | * Create a queue with an internal owner.
|
---|
| 144 | *
|
---|
| 145 | * @returns VBox status code.
|
---|
| 146 | * @param pVM VM handle.
|
---|
| 147 | * @param cbItem Size a queue item.
|
---|
| 148 | * @param cItems Number of items in the queue.
|
---|
| 149 | * @param cMilliesInterval Number of milliseconds between polling the queue.
|
---|
| 150 | * If 0 then the emulation thread will be notified whenever an item arrives.
|
---|
| 151 | * @param pfnCallback The consumer function.
|
---|
| 152 | * @param fGCEnabled Set if the queue must be usable from GC.
|
---|
| 153 | * @param ppQueue Where to store the queue handle on success.
|
---|
| 154 | * @thread Emulation thread only.
|
---|
| 155 | */
|
---|
| 156 | PDMR3DECL(int) PDMR3QueueCreateInternal(PVM pVM, RTUINT cbItem, RTUINT cItems, uint32_t cMilliesInterval,
|
---|
| 157 | PFNPDMQUEUEINT pfnCallback, bool fGCEnabled, PPDMQUEUE *ppQueue);
|
---|
| 158 |
|
---|
| 159 | /**
|
---|
| 160 | * Create a queue with an external owner.
|
---|
| 161 | *
|
---|
| 162 | * @returns VBox status code.
|
---|
| 163 | * @param pVM VM handle.
|
---|
| 164 | * @param cbItem Size a queue item.
|
---|
| 165 | * @param cItems Number of items in the queue.
|
---|
| 166 | * @param cMilliesInterval Number of milliseconds between polling the queue.
|
---|
| 167 | * If 0 then the emulation thread will be notified whenever an item arrives.
|
---|
| 168 | * @param pfnCallback The consumer function.
|
---|
| 169 | * @param pvUser The user argument to the consumer function.
|
---|
| 170 | * @param ppQueue Where to store the queue handle on success.
|
---|
| 171 | * @thread The emulation thread.
|
---|
| 172 | */
|
---|
| 173 | PDMR3DECL(int) PDMR3QueueCreateExternal(PVM pVM, RTUINT cbItem, RTUINT cItems, uint32_t cMilliesInterval,
|
---|
| 174 | PFNPDMQUEUEEXT pfnCallback, void *pvUser, PPDMQUEUE *ppQueue);
|
---|
| 175 |
|
---|
| 176 | /**
|
---|
| 177 | * Destroy a queue.
|
---|
| 178 | *
|
---|
| 179 | * @returns VBox status code.
|
---|
| 180 | * @param pQueue Queue to destroy.
|
---|
| 181 | * @thread The emulation thread.
|
---|
| 182 | */
|
---|
| 183 | PDMR3DECL(int) PDMR3QueueDestroy(PPDMQUEUE pQueue);
|
---|
| 184 |
|
---|
| 185 | /**
|
---|
| 186 | * Destroy a all queues owned by the specified device.
|
---|
| 187 | *
|
---|
| 188 | * @returns VBox status code.
|
---|
| 189 | * @param pVM VM handle.
|
---|
| 190 | * @param pDevIns Device instance.
|
---|
| 191 | * @thread Emulation thread only.
|
---|
| 192 | */
|
---|
| 193 | PDMR3DECL(int) PDMR3QueueDestroyDevice(PVM pVM, PPDMDEVINS pDevIns);
|
---|
| 194 |
|
---|
| 195 | /**
|
---|
| 196 | * Destroy a all queues owned by the specified driver.
|
---|
| 197 | *
|
---|
| 198 | * @returns VBox status code.
|
---|
| 199 | * @param pVM VM handle.
|
---|
| 200 | * @param pDrvIns Driver instance.
|
---|
| 201 | * @thread Emulation thread only.
|
---|
| 202 | */
|
---|
| 203 | PDMR3DECL(int) PDMR3QueueDestroyDriver(PVM pVM, PPDMDRVINS pDrvIns);
|
---|
| 204 |
|
---|
| 205 | /**
|
---|
| 206 | * Flushes pending queues.
|
---|
| 207 | * This is a forced action callback.
|
---|
| 208 | *
|
---|
| 209 | * @param pVM VM handle.
|
---|
| 210 | * @thread The emulation thread.
|
---|
| 211 | */
|
---|
| 212 | PDMR3DECL(void) PDMR3QueueFlushAll(PVM pVM);
|
---|
| 213 |
|
---|
| 214 | /**
|
---|
| 215 | * This is a worker function used by PDMQueueFlush to perform the
|
---|
| 216 | * flush in ring-3.
|
---|
| 217 | *
|
---|
| 218 | * The queue which should be flushed is pointed to by either pQueueFlushGC,
|
---|
| 219 | * pQueueFlushHC, or pQueueue. This function will flush that queue and
|
---|
| 220 | * recalc the queue FF.
|
---|
| 221 | *
|
---|
| 222 | * @param pVM The VM handle.
|
---|
| 223 | * @param pQueue The queue to flush. Only used in Ring-3.
|
---|
| 224 | */
|
---|
| 225 | PDMR3DECL(void) PDMR3QueueFlushWorker(PVM pVM, PPDMQUEUE pQueue);
|
---|
| 226 |
|
---|
| 227 | /**
|
---|
| 228 | * Flushes a PDM queue.
|
---|
| 229 | *
|
---|
| 230 | * @param pQueue The queue handle.
|
---|
| 231 | */
|
---|
| 232 | PDMDECL(void) PDMQueueFlush(PPDMQUEUE pQueue);
|
---|
| 233 |
|
---|
| 234 | /**
|
---|
| 235 | * Allocate an item from a queue.
|
---|
| 236 | * The allocated item must be handed on to PDMQueueInsert() after the
|
---|
| 237 | * data has been filled in.
|
---|
| 238 | *
|
---|
| 239 | * @returns Pointer to allocated queue item.
|
---|
| 240 | * @returns NULL on failure. The queue is exhausted.
|
---|
| 241 | * @param pQueue The queue handle.
|
---|
| 242 | * @thread Any thread.
|
---|
| 243 | */
|
---|
| 244 | PDMDECL(PPDMQUEUEITEMCORE) PDMQueueAlloc(PPDMQUEUE pQueue);
|
---|
| 245 |
|
---|
| 246 | /**
|
---|
| 247 | * Queue an item.
|
---|
| 248 | * The item must have been obtained using PDMQueueAlloc(). Once the item
|
---|
| 249 | * has been passed to this function it must not be touched!
|
---|
| 250 | *
|
---|
| 251 | * @param pQueue The queue handle.
|
---|
| 252 | * @param pItem The item to insert.
|
---|
| 253 | * @thread Any thread.
|
---|
| 254 | */
|
---|
| 255 | PDMDECL(void) PDMQueueInsert(PPDMQUEUE pQueue, PPDMQUEUEITEMCORE pItem);
|
---|
| 256 |
|
---|
| 257 | /**
|
---|
| 258 | * Queue an item.
|
---|
| 259 | * The item must have been obtained using PDMQueueAlloc(). Once the item
|
---|
| 260 | * have been passed to this function it must not be touched!
|
---|
| 261 | *
|
---|
| 262 | * @param pQueue The queue handle.
|
---|
| 263 | * @param pItem The item to insert.
|
---|
| 264 | * @param NanoMaxDelay The maximum delay before processing the queue, in nanoseconds.
|
---|
| 265 | * This applies only to GC.
|
---|
| 266 | * @thread Any thread.
|
---|
| 267 | */
|
---|
| 268 | PDMDECL(void) PDMQueueInsertEx(PPDMQUEUE pQueue, PPDMQUEUEITEMCORE pItem, uint64_t NanoMaxDelay);
|
---|
| 269 |
|
---|
| 270 |
|
---|
| 271 | /**
|
---|
| 272 | * Gets the GC pointer for the specified queue.
|
---|
| 273 | *
|
---|
| 274 | * @returns The GC address of the queue.
|
---|
| 275 | * @returns NULL if pQueue is invalid.
|
---|
| 276 | * @param pQueue The queue handle.
|
---|
| 277 | */
|
---|
| 278 | PDMDECL(GCPTRTYPE(PPDMQUEUE)) PDMQueueGCPtr(PPDMQUEUE pQueue);
|
---|
| 279 |
|
---|
| 280 | /** @} */
|
---|
| 281 |
|
---|
| 282 | __END_DECLS
|
---|
| 283 |
|
---|
| 284 | #endif
|
---|
| 285 |
|
---|
| 286 |
|
---|