VirtualBox

source: vbox/trunk/include/VBox/vmm/pdmblkcache.h@ 76399

Last change on this file since 76399 was 76399, checked in by vboxsync, 6 years ago

VBox/vmm/pdmblkcache.h: Don't include err.h and assert.h if not needed. bugref:9344

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.0 KB
Line 
1/** @file
2 * PDM - Pluggable Device Manager, Block cache.
3 */
4
5/*
6 * Copyright (C) 2007-2017 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_vmm_pdmblkcache_h
27#define ___VBox_vmm_pdmblkcache_h
28
29#include <VBox/types.h>
30#include <iprt/sg.h>
31
32
33RT_C_DECLS_BEGIN
34
35/** @defgroup grp_pdm_blk_cache The PDM Block Cache API
36 * @ingroup grp_pdm
37 * @{
38 */
39
40/** Pointer to a PDM block cache. */
41typedef struct PDMBLKCACHE *PPDMBLKCACHE;
42/** Pointer to a PDM block cache pointer. */
43typedef PPDMBLKCACHE *PPPDMBLKCACHE;
44
45/** I/O transfer handle. */
46typedef struct PDMBLKCACHEIOXFER *PPDMBLKCACHEIOXFER;
47
48/**
49 * Block cache I/O request transfer direction.
50 */
51typedef enum PDMBLKCACHEXFERDIR
52{
53 /** Read */
54 PDMBLKCACHEXFERDIR_READ = 0,
55 /** Write */
56 PDMBLKCACHEXFERDIR_WRITE,
57 /** Flush */
58 PDMBLKCACHEXFERDIR_FLUSH,
59 /** Discard */
60 PDMBLKCACHEXFERDIR_DISCARD
61} PDMBLKCACHEXFERDIR;
62
63/**
64 * Completion callback for drivers.
65 *
66 * @param pDrvIns The driver instance.
67 * @param pvUser User argument given during request initiation.
68 * @param rc The status code of the completed request.
69 */
70typedef DECLCALLBACK(void) FNPDMBLKCACHEXFERCOMPLETEDRV(PPDMDRVINS pDrvIns, void *pvUser, int rc);
71/** Pointer to a FNPDMBLKCACHEXFERCOMPLETEDRV(). */
72typedef FNPDMBLKCACHEXFERCOMPLETEDRV *PFNPDMBLKCACHEXFERCOMPLETEDRV;
73
74/**
75 * I/O enqueue callback for drivers.
76 *
77 * @param pDrvIns The driver instance.
78 * @param enmXferDir Transfer direction.
79 * @param off Transfer offset.
80 * @param cbXfer Transfer size.
81 * @param pSgBuf Scather / gather buffer for the transfer.
82 * @param hIoXfer I/O transfer handle to ping on completion.
83 */
84typedef DECLCALLBACK(int) FNPDMBLKCACHEXFERENQUEUEDRV(PPDMDRVINS pDrvIns, PDMBLKCACHEXFERDIR enmXferDir,
85 uint64_t off, size_t cbXfer, PCRTSGBUF pSgBuf, PPDMBLKCACHEIOXFER hIoXfer);
86/** Pointer to a FNPDMBLKCACHEXFERENQUEUEDRV(). */
87typedef FNPDMBLKCACHEXFERENQUEUEDRV *PFNPDMBLKCACHEXFERENQUEUEDRV;
88
89/**
90 * Discard enqueue callback for drivers.
91 *
92 * @param pDrvIns The driver instance.
93 * @param paRanges Ranges to discard.
94 * @param cRanges Number of range entries.
95 * @param hIoXfer I/O handle to return on completion.
96 */
97typedef DECLCALLBACK(int) FNPDMBLKCACHEXFERENQUEUEDISCARDDRV(PPDMDRVINS pDrvIns, PCRTRANGE paRanges, unsigned cRanges,
98 PPDMBLKCACHEIOXFER hIoXfer);
99/** Pointer to a FNPDMBLKCACHEXFERENQUEUEDISCARDDRV(). */
100typedef FNPDMBLKCACHEXFERENQUEUEDISCARDDRV *PFNPDMBLKCACHEXFERENQUEUEDISCARDDRV;
101
102/**
103 * Completion callback for devices.
104 *
105 * @param pDrvIns The device instance.
106 * @param pvUser User argument given during request initiation.
107 * @param rc The status code of the completed request.
108 */
109typedef DECLCALLBACK(void) FNPDMBLKCACHEXFERCOMPLETEDEV(PPDMDEVINS pDevIns, void *pvUser, int rc);
110/** Pointer to a FNPDMBLKCACHEXFERCOMPLETEDEV(). */
111typedef FNPDMBLKCACHEXFERCOMPLETEDEV *PFNPDMBLKCACHEXFERCOMPLETEDEV;
112
113/**
114 * I/O enqueue callback for devices.
115 *
116 * @param pDevIns The device instance.
117 * @param enmXferDir Transfer direction.
118 * @param off Transfer offset.
119 * @param cbXfer Transfer size.
120 * @param pSgBuf Scather / gather buffer for the transfer.
121 * @param hIoXfer I/O transfer handle to ping on completion.
122 */
123typedef DECLCALLBACK(int) FNPDMBLKCACHEXFERENQUEUEDEV(PPDMDEVINS pDevIns, PDMBLKCACHEXFERDIR enmXferDir,
124 uint64_t off, size_t cbXfer, PCRTSGBUF pSgBuf, PPDMBLKCACHEIOXFER hIoXfer);
125/** Pointer to a FNPDMBLKCACHEXFERENQUEUEDEV(). */
126typedef FNPDMBLKCACHEXFERENQUEUEDEV *PFNPDMBLKCACHEXFERENQUEUEDEV;
127
128/**
129 * Discard enqueue callback for devices.
130 *
131 * @param pDrvIns The driver instance.
132 * @param paRanges Ranges to discard.
133 * @param cRanges Number of range entries.
134 * @param hIoXfer I/O handle to return on completion.
135 */
136typedef DECLCALLBACK(int) FNPDMBLKCACHEXFERENQUEUEDISCARDDEV(PPDMDEVINS pDevIns, PCRTRANGE paRanges, unsigned cRanges,
137 PPDMBLKCACHEIOXFER hIoXfer);
138/** Pointer to a FNPDMBLKCACHEXFERENQUEUEDISCARDDEV(). */
139typedef FNPDMBLKCACHEXFERENQUEUEDISCARDDEV *PFNPDMBLKCACHEXFERENQUEUEDISCARDDEV;
140
141/**
142 * Completion callback for drivers.
143 *
144 * @param pDrvIns The driver instance.
145 * @param pvUser User argument given during request initiation.
146 * @param rc The status code of the completed request.
147 */
148typedef DECLCALLBACK(void) FNPDMBLKCACHEXFERCOMPLETEINT(void *pvUserInt, void *pvUser, int rc);
149/** Pointer to a FNPDMBLKCACHEXFERCOMPLETEINT(). */
150typedef FNPDMBLKCACHEXFERCOMPLETEINT *PFNPDMBLKCACHEXFERCOMPLETEINT;
151
152/**
153 * I/O enqueue callback for drivers.
154 *
155 * @param pDrvIns The driver instance.
156 * @param enmXferDir Transfer direction.
157 * @param off Transfer offset.
158 * @param cbXfer Transfer size.
159 * @param pSgBuf Scather / gather buffer for the transfer.
160 * @param hIoXfer I/O transfer handle to ping on completion.
161 */
162typedef DECLCALLBACK(int) FNPDMBLKCACHEXFERENQUEUEINT(void *pvUser, PDMBLKCACHEXFERDIR enmXferDir,
163 uint64_t off, size_t cbXfer, PCRTSGBUF pSgBuf, PPDMBLKCACHEIOXFER hIoXfer);
164/** Pointer to a FNPDMBLKCACHEXFERENQUEUEINT(). */
165typedef FNPDMBLKCACHEXFERENQUEUEINT *PFNPDMBLKCACHEXFERENQUEUEINT;
166
167/**
168 * Discard enqueue callback for VMM internal users.
169 *
170 * @param pDrvIns The driver instance.
171 * @param paRanges Ranges to discard.
172 * @param cRanges Number of range entries.
173 * @param hIoXfer I/O handle to return on completion.
174 */
175typedef DECLCALLBACK(int) FNPDMBLKCACHEXFERENQUEUEDISCARDINT(void *pvUser, PCRTRANGE paRanges, unsigned cRanges,
176 PPDMBLKCACHEIOXFER hIoXfer);
177/** Pointer to a FNPDMBLKCACHEXFERENQUEUEDISCARDINT(). */
178typedef FNPDMBLKCACHEXFERENQUEUEDISCARDINT *PFNPDMBLKCACHEXFERENQUEUEDISCARDINT;
179
180/**
181 * Completion callback for USB.
182 *
183 * @param pDrvIns The driver instance.
184 * @param pvUser User argument given during request initiation.
185 * @param rc The status code of the completed request.
186 */
187typedef DECLCALLBACK(void) FNPDMBLKCACHEXFERCOMPLETEUSB(PPDMUSBINS pUsbIns, void *pvUser, int rc);
188/** Pointer to a FNPDMBLKCACHEXFERCOMPLETEUSB(). */
189typedef FNPDMBLKCACHEXFERCOMPLETEUSB *PFNPDMBLKCACHEXFERCOMPLETEUSB;
190
191/**
192 * I/O enqueue callback for drivers.
193 *
194 * @param pDrvIns The driver instance.
195 * @param enmXferDir Transfer direction.
196 * @param off Transfer offset.
197 * @param cbXfer Transfer size.
198 * @param pSgBuf Scather / gather buffer for the transfer.
199 * @param hIoXfer I/O transfer handle to ping on completion.
200 */
201typedef DECLCALLBACK(int) FNPDMBLKCACHEXFERENQUEUEUSB(PPDMUSBINS pUsbIns, PDMBLKCACHEXFERDIR enmXferDir,
202 uint64_t off, size_t cbXfer, PCRTSGBUF pSgBuf, PPDMBLKCACHEIOXFER hIoXfer);
203/** Pointer to a FNPDMBLKCACHEXFERENQUEUEUSB(). */
204typedef FNPDMBLKCACHEXFERENQUEUEUSB *PFNPDMBLKCACHEXFERENQUEUEUSB;
205
206/**
207 * Discard enqueue callback for USB devices.
208 *
209 * @param pUsbIns The USB device instance.
210 * @param paRanges Ranges to discard.
211 * @param cRanges Number of range entries.
212 * @param hIoXfer I/O handle to return on completion.
213 */
214typedef DECLCALLBACK(int) FNPDMBLKCACHEXFERENQUEUEDISCARDUSB(PPDMUSBINS pUsbIns, PCRTRANGE paRanges, unsigned cRanges,
215 PPDMBLKCACHEIOXFER hIoXfer);
216/** Pointer to a FNPDMBLKCACHEXFERENQUEUEDISCARDUSB(). */
217typedef FNPDMBLKCACHEXFERENQUEUEDISCARDUSB *PFNPDMBLKCACHEXFERENQUEUEDISCARDUSB;
218
219/**
220 * Create a block cache user for a driver instance.
221 *
222 * @returns VBox status code.
223 * @param pVM The cross context VM structure.
224 * @param pDrvIns The driver instance.
225 * @param ppBlkCache Where to store the handle to the block cache.
226 * @param pfnXferComplete The I/O transfer complete callback.
227 * @param pfnXferEnqueue The I/O request enqueue callback.
228 * @param pfnXferEnqueueDiscard The discard request enqueue callback.
229 * @param pcszId Unique ID used to identify the user.
230 */
231VMMR3DECL(int) PDMR3BlkCacheRetainDriver(PVM pVM, PPDMDRVINS pDrvIns, PPPDMBLKCACHE ppBlkCache,
232 PFNPDMBLKCACHEXFERCOMPLETEDRV pfnXferComplete,
233 PFNPDMBLKCACHEXFERENQUEUEDRV pfnXferEnqueue,
234 PFNPDMBLKCACHEXFERENQUEUEDISCARDDRV pfnXferEnqueueDiscard,
235 const char *pcszId);
236
237/**
238 * Create a block cache user for a device instance.
239 *
240 * @returns VBox status code.
241 * @param pVM The cross context VM structure.
242 * @param pDevIns The device instance.
243 * @param ppBlkCache Where to store the handle to the block cache.
244 * @param pfnXferComplete The I/O transfer complete callback.
245 * @param pfnXferEnqueue The I/O request enqueue callback.
246 * @param pfnXferEnqueueDiscard The discard request enqueue callback.
247 * @param pcszId Unique ID used to identify the user.
248 */
249VMMR3DECL(int) PDMR3BlkCacheRetainDevice(PVM pVM, PPDMDEVINS pDevIns, PPPDMBLKCACHE ppBlkCache,
250 PFNPDMBLKCACHEXFERCOMPLETEDEV pfnXferComplete,
251 PFNPDMBLKCACHEXFERENQUEUEDEV pfnXferEnqueue,
252 PFNPDMBLKCACHEXFERENQUEUEDISCARDDEV pfnXferEnqueueDiscard,
253 const char *pcszId);
254
255/**
256 * Create a block cache user for a USB instance.
257 *
258 * @returns VBox status code.
259 * @param pVM The cross context VM structure.
260 * @param pUsbIns The USB device instance.
261 * @param ppBlkCache Where to store the handle to the block cache.
262 * @param pfnXferComplete The I/O transfer complete callback.
263 * @param pfnXferEnqueue The I/O request enqueue callback.
264 * @param pfnXferEnqueueDiscard The discard request enqueue callback.
265 * @param pcszId Unique ID used to identify the user.
266 */
267VMMR3DECL(int) PDMR3BlkCacheRetainUsb(PVM pVM, PPDMUSBINS pUsbIns, PPPDMBLKCACHE ppBlkCache,
268 PFNPDMBLKCACHEXFERCOMPLETEUSB pfnXferComplete,
269 PFNPDMBLKCACHEXFERENQUEUEUSB pfnXferEnqueue,
270 PFNPDMBLKCACHEXFERENQUEUEDISCARDUSB pfnXferEnqueueDiscard,
271 const char *pcszId);
272
273/**
274 * Create a block cache user for internal use by VMM.
275 *
276 * @returns VBox status code.
277 * @param pVM The cross context VM structure.
278 * @param pvUser Opaque user data.
279 * @param ppBlkCache Where to store the handle to the block cache.
280 * @param pfnXferComplete The I/O transfer complete callback.
281 * @param pfnXferEnqueue The I/O request enqueue callback.
282 * @param pfnXferEnqueueDiscard The discard request enqueue callback.
283 * @param pcszId Unique ID used to identify the user.
284 */
285VMMR3DECL(int) PDMR3BlkCacheRetainInt(PVM pVM, void *pvUser, PPPDMBLKCACHE ppBlkCache,
286 PFNPDMBLKCACHEXFERCOMPLETEINT pfnXferComplete,
287 PFNPDMBLKCACHEXFERENQUEUEINT pfnXferEnqueue,
288 PFNPDMBLKCACHEXFERENQUEUEDISCARDINT pfnXferEnqueueDiscard,
289 const char *pcszId);
290
291/**
292 * Releases a block cache handle.
293 *
294 * @returns nothing.
295 * @param pBlkCache Block cache handle.
296 */
297VMMR3DECL(void) PDMR3BlkCacheRelease(PPDMBLKCACHE pBlkCache);
298
299/**
300 * Releases all block cache handles for a device instance.
301 *
302 * @returns nothing.
303 * @param pVM The cross context VM structure.
304 * @param pDevIns The device instance.
305 */
306VMMR3DECL(void) PDMR3BlkCacheReleaseDevice(PVM pVM, PPDMDEVINS pDevIns);
307
308/**
309 * Releases all block cache handles for a driver instance.
310 *
311 * @returns nothing.
312 * @param pVM The cross context VM structure.
313 * @param pDrvIns The driver instance.
314 */
315VMMR3DECL(void) PDMR3BlkCacheReleaseDriver(PVM pVM, PPDMDRVINS pDrvIns);
316
317/**
318 * Releases all block cache handles for a USB device instance.
319 *
320 * @returns nothing.
321 * @param pVM The cross context VM structure.
322 * @param pUsbIns The USB device instance.
323 */
324VMMR3DECL(void) PDMR3BlkCacheReleaseUsb(PVM pVM, PPDMUSBINS pUsbIns);
325
326/**
327 * Creates a read task on the given endpoint.
328 *
329 * @returns VBox status code.
330 * @param pBlkCache The cache instance.
331 * @param off Where to start reading from.
332 * @param pSgBuf Scatter gather buffer store the data in.
333 * @param cbRead The overall number of bytes to read.
334 * @param pvUser Opaque user data returned in the completion callback
335 * upon completion of the read.
336 */
337VMMR3DECL(int) PDMR3BlkCacheRead(PPDMBLKCACHE pBlkCache, uint64_t off, PCRTSGBUF pSgBuf, size_t cbRead, void *pvUser);
338
339/**
340 * Creates a write task on the given endpoint.
341 *
342 * @returns VBox status code.
343 * @param pBlkCache The cache instance.
344 * @param off Where to start writing at.
345 * @param pSgBuf Scatter gather buffer gather the data from.
346 * @param cbWrite The overall number of bytes to write.
347 * @param pvUser Opaque user data returned in the completion callback
348 * upon completion of the task.
349 */
350VMMR3DECL(int) PDMR3BlkCacheWrite(PPDMBLKCACHE pBlkCache, uint64_t off, PCRTSGBUF pSgBuf, size_t cbWrite, void *pvUser);
351
352/**
353 * Creates a flush task on the given endpoint.
354 *
355 * @returns VBox status code.
356 * @param pBlkCache The cache instance.
357 * @param pvUser Opaque user data returned in the completion callback
358 * upon completion of the task.
359 */
360VMMR3DECL(int) PDMR3BlkCacheFlush(PPDMBLKCACHE pBlkCache, void *pvUser);
361
362/**
363 * Discards the given ranges from the cache.
364 *
365 * @returns VBox status code.
366 * @param pBlkCache The cache instance.
367 * @param paRanges Array of ranges to discard.
368 * @param cRanges Number of ranges in the array.
369 * @param pvUser Opaque user data returned in the completion callback
370 * upon completion of the task.
371 */
372VMMR3DECL(int) PDMR3BlkCacheDiscard(PPDMBLKCACHE pBlkCache, PCRTRANGE paRanges, unsigned cRanges, void *pvUser);
373
374/**
375 * Notify the cache of a complete I/O transfer.
376 *
377 * @returns nothing.
378 * @param pBlkCache The cache instance.
379 * @param hIoXfer The I/O transfer handle which completed.
380 * @param rcIoXfer The status code of the completed request.
381 */
382VMMR3DECL(void) PDMR3BlkCacheIoXferComplete(PPDMBLKCACHE pBlkCache, PPDMBLKCACHEIOXFER hIoXfer, int rcIoXfer);
383
384/**
385 * Suspends the block cache.
386 *
387 * The cache waits until all I/O transfers completed and stops to enqueue new
388 * requests after the call returned but will not accept reads, write or flushes
389 * either.
390 *
391 * @returns VBox status code.
392 * @param pBlkCache The cache instance.
393 */
394VMMR3DECL(int) PDMR3BlkCacheSuspend(PPDMBLKCACHE pBlkCache);
395
396/**
397 * Resumes operation of the block cache.
398 *
399 * @returns VBox status code.
400 * @param pBlkCache The cache instance.
401 */
402VMMR3DECL(int) PDMR3BlkCacheResume(PPDMBLKCACHE pBlkCache);
403
404/**
405 * Clears the block cache and removes all entries.
406 *
407 * The cache waits until all I/O transfers completed.
408 *
409 * @returns VBox status code.
410 * @param pBlkCache The cache instance.
411 */
412VMMR3DECL(int) PDMR3BlkCacheClear(PPDMBLKCACHE pBlkCache);
413
414/** @} */
415
416RT_C_DECLS_END
417
418#endif
419
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