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