VirtualBox

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

Last change on this file since 49852 was 44528, checked in by vboxsync, 12 years ago

header (C) fixes

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

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