VirtualBox

source: vbox/trunk/include/VBox/vmm/pdmqueue.h@ 93922

Last change on this file since 93922 was 93609, checked in by vboxsync, 3 years ago

VMM/PDMQueue: Rewrote the queue code to not use the hyper heap and be a bit safer. Added a testcase (driverless). bugref:10093

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 6.6 KB
Line 
1/** @file
2 * PDM - Pluggable Device Manager, Queues.
3 */
4
5/*
6 * Copyright (C) 2006-2022 Oracle Corporation
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
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.
24 */
25
26#ifndef VBOX_INCLUDED_vmm_pdmqueue_h
27#define VBOX_INCLUDED_vmm_pdmqueue_h
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
31
32#include <VBox/types.h>
33
34RT_C_DECLS_BEGIN
35
36/** @defgroup grp_pdm_queue The PDM Queues API
37 * @ingroup grp_pdm
38 * @{
39 */
40
41/** Pointer to a PDM queue. */
42typedef struct PDMQUEUE *PPDMQUEUE;
43
44/** Pointer to a PDM queue item core. */
45typedef union PDMQUEUEITEMCORE *PPDMQUEUEITEMCORE;
46
47/**
48 * PDM queue item core.
49 */
50typedef union PDMQUEUEITEMCORE
51{
52 /** The next queue item on the pending list (UINT32_MAX for NIL). */
53 uint32_t volatile iNext;
54 /** The next item about to be flushed. */
55 R3PTRTYPE(PPDMQUEUEITEMCORE) pNext;
56 /** Make sure the core is 64-bit wide. */
57 uint64_t u64View;
58} PDMQUEUEITEMCORE;
59
60
61/**
62 * Queue consumer callback for devices.
63 *
64 * @returns Success indicator.
65 * If false the item will not be removed and the flushing will stop.
66 * @param pDevIns The device instance.
67 * @param pItem The item to consume. Upon return this item will be freed.
68 * @remarks The device critical section will NOT be entered before calling the
69 * callback. No locks will be held, but for now it's safe to assume
70 * that only one EMT will do queue callbacks at any one time.
71 */
72typedef DECLCALLBACKTYPE(bool, FNPDMQUEUEDEV,(PPDMDEVINS pDevIns, PPDMQUEUEITEMCORE pItem));
73/** Pointer to a FNPDMQUEUEDEV(). */
74typedef FNPDMQUEUEDEV *PFNPDMQUEUEDEV;
75
76/**
77 * Queue consumer callback for USB devices.
78 *
79 * @returns Success indicator.
80 * If false the item will not be removed and the flushing will stop.
81 * @param pUsbIns The USB device instance.
82 * @param pItem The item to consume. Upon return this item will be freed.
83 * @remarks No locks will be held, but for now it's safe to assume that only one
84 * EMT will do queue callbacks at any one time.
85 */
86typedef DECLCALLBACKTYPE(bool, FNPDMQUEUEUSB,(PPDMUSBINS pUsbIns, PPDMQUEUEITEMCORE pItem));
87/** Pointer to a FNPDMQUEUEUSB(). */
88typedef FNPDMQUEUEUSB *PFNPDMQUEUEUSB;
89
90/**
91 * Queue consumer callback for drivers.
92 *
93 * @returns Success indicator.
94 * If false the item will not be removed and the flushing will stop.
95 * @param pDrvIns The driver instance.
96 * @param pItem The item to consume. Upon return this item will be freed.
97 * @remarks No locks will be held, but for now it's safe to assume that only one
98 * EMT will do queue callbacks at any one time.
99 */
100typedef DECLCALLBACKTYPE(bool, FNPDMQUEUEDRV,(PPDMDRVINS pDrvIns, PPDMQUEUEITEMCORE pItem));
101/** Pointer to a FNPDMQUEUEDRV(). */
102typedef FNPDMQUEUEDRV *PFNPDMQUEUEDRV;
103
104/**
105 * Queue consumer callback for internal component.
106 *
107 * @returns Success indicator.
108 * If false the item will not be removed and the flushing will stop.
109 * @param pVM The cross context VM structure.
110 * @param pItem The item to consume. Upon return this item will be freed.
111 * @remarks No locks will be held, but for now it's safe to assume that only one
112 * EMT will do queue callbacks at any one time.
113 */
114typedef DECLCALLBACKTYPE(bool, FNPDMQUEUEINT,(PVM pVM, PPDMQUEUEITEMCORE pItem));
115/** Pointer to a FNPDMQUEUEINT(). */
116typedef FNPDMQUEUEINT *PFNPDMQUEUEINT;
117
118/**
119 * Queue consumer callback for external component.
120 *
121 * @returns Success indicator.
122 * If false the item will not be removed and the flushing will stop.
123 * @param pvUser User argument.
124 * @param pItem The item to consume. Upon return this item will be freed.
125 * @remarks No locks will be held, but for now it's safe to assume that only one
126 * EMT will do queue callbacks at any one time.
127 */
128typedef DECLCALLBACKTYPE(bool, FNPDMQUEUEEXT,(void *pvUser, PPDMQUEUEITEMCORE pItem));
129/** Pointer to a FNPDMQUEUEEXT(). */
130typedef FNPDMQUEUEEXT *PFNPDMQUEUEEXT;
131
132#ifdef VBOX_IN_VMM
133VMMR3_INT_DECL(int) PDMR3QueueCreateDevice(PVM pVM, PPDMDEVINS pDevIns, size_t cbItem, uint32_t cItems,
134 uint32_t cMilliesInterval, PFNPDMQUEUEDEV pfnCallback,
135 bool fRZEnabled, const char *pszName, PDMQUEUEHANDLE *phQueue);
136VMMR3_INT_DECL(int) PDMR3QueueCreateDriver(PVM pVM, PPDMDRVINS pDrvIns, size_t cbItem, uint32_t cItems,
137 uint32_t cMilliesInterval, PFNPDMQUEUEDRV pfnCallback,
138 const char *pszName, PDMQUEUEHANDLE *phQueue);
139VMMR3_INT_DECL(int) PDMR3QueueCreateInternal(PVM pVM, size_t cbItem, uint32_t cItems,
140 uint32_t cMilliesInterval, PFNPDMQUEUEINT pfnCallback,
141 bool fRZEnabled, const char *pszName, PDMQUEUEHANDLE *phQueue);
142VMMR3DECL(int) PDMR3QueueCreateExternal(PVM pVM, size_t cbItem, uint32_t cItems, uint32_t cMilliesInterval,
143 PFNPDMQUEUEEXT pfnCallback, void *pvUser, const char *pszName, PDMQUEUEHANDLE *phQueue);
144VMMR3DECL(int) PDMR3QueueDestroy(PVM pVM, PDMQUEUEHANDLE hQueue, void *pvOwner);
145VMMR3_INT_DECL(int) PDMR3QueueDestroyDevice(PVM pVM, PPDMDEVINS pDevIns);
146VMMR3_INT_DECL(int) PDMR3QueueDestroyDriver(PVM pVM, PPDMDRVINS pDrvIns);
147VMMR3DECL(void) PDMR3QueueFlushAll(PVM pVM);
148#endif /* VBOX_IN_VMM */
149
150VMMDECL(PPDMQUEUEITEMCORE) PDMQueueAlloc(PVMCC pVM, PDMQUEUEHANDLE hQueue, void *pvOwner);
151VMMDECL(int) PDMQueueInsert(PVMCC pVM, PDMQUEUEHANDLE hQueue, void *pvOwner, PPDMQUEUEITEMCORE pInsert);
152VMMDECL(int) PDMQueueFlushIfNecessary(PVMCC pVM, PDMQUEUEHANDLE hQueue, void *pvOwner);
153
154/** @} */
155
156RT_C_DECLS_END
157
158#endif /* !VBOX_INCLUDED_vmm_pdmqueue_h */
159
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette