1 | /* $Id: DrvHostBase.h 64407 2016-10-25 11:53:00Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DrvHostBase - Host base drive access driver.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2016 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef __HostDrvBase_h__
|
---|
19 | #define __HostDrvBase_h__
|
---|
20 |
|
---|
21 | #include <iprt/assert.h>
|
---|
22 | #include <iprt/err.h>
|
---|
23 | #include <iprt/critsect.h>
|
---|
24 | #include <iprt/log.h>
|
---|
25 | #include <iprt/semaphore.h>
|
---|
26 | #include <VBox/cdefs.h>
|
---|
27 | #include <VBox/vmm/pdmdrv.h>
|
---|
28 | #include <VBox/vmm/pdmstorageifs.h>
|
---|
29 |
|
---|
30 | RT_C_DECLS_BEGIN
|
---|
31 |
|
---|
32 |
|
---|
33 | /** Pointer to host base drive access driver instance data. */
|
---|
34 | typedef struct DRVHOSTBASE *PDRVHOSTBASE;
|
---|
35 | /**
|
---|
36 | * Host base drive access driver instance data.
|
---|
37 | *
|
---|
38 | * @implements PDMIMOUNT
|
---|
39 | * @implements PDMIMEDIA
|
---|
40 | */
|
---|
41 | typedef struct DRVHOSTBASE
|
---|
42 | {
|
---|
43 | /** Critical section used to serialize access to the handle and other
|
---|
44 | * members of this struct. */
|
---|
45 | RTCRITSECT CritSect;
|
---|
46 | /** Pointer driver instance. */
|
---|
47 | PPDMDRVINS pDrvIns;
|
---|
48 | /** Drive type. */
|
---|
49 | PDMMEDIATYPE enmType;
|
---|
50 | /** Visible to the BIOS. */
|
---|
51 | bool fBiosVisible;
|
---|
52 | /** The configuration readonly value. */
|
---|
53 | bool fReadOnlyConfig;
|
---|
54 | /** The current readonly status. */
|
---|
55 | bool fReadOnly;
|
---|
56 | /** Flag whether failure to attach is an error or not. */
|
---|
57 | bool fAttachFailError;
|
---|
58 | /** Flag whether to keep instance working (as unmounted though). */
|
---|
59 | bool fKeepInstance;
|
---|
60 | /** Device name (MMHeap). */
|
---|
61 | char *pszDevice;
|
---|
62 | /** Device name to open (RTStrFree). */
|
---|
63 | char *pszDeviceOpen;
|
---|
64 | /** Uuid of the drive. */
|
---|
65 | RTUUID Uuid;
|
---|
66 |
|
---|
67 | /** Pointer to the media port interface above us. */
|
---|
68 | PPDMIMEDIAPORT pDrvMediaPort;
|
---|
69 | /** Pointer to the extended media port interface above us. */
|
---|
70 | PPDMIMEDIAEXPORT pDrvMediaExPort;
|
---|
71 | /** Pointer to the mount notify interface above us. */
|
---|
72 | PPDMIMOUNTNOTIFY pDrvMountNotify;
|
---|
73 | /** Our media interface. */
|
---|
74 | PDMIMEDIA IMedia;
|
---|
75 | /** Our extended media interface. */
|
---|
76 | PDMIMEDIAEX IMediaEx;
|
---|
77 | /** Our mountable interface. */
|
---|
78 | PDMIMOUNT IMount;
|
---|
79 |
|
---|
80 | /** Media present indicator. */
|
---|
81 | bool volatile fMediaPresent;
|
---|
82 | /** Locked indicator. */
|
---|
83 | bool fLocked;
|
---|
84 | /** The size of the media currently in the drive.
|
---|
85 | * This is invalid if no drive is in the drive. */
|
---|
86 | uint64_t volatile cbSize;
|
---|
87 |
|
---|
88 | /** Handle of the poller thread. */
|
---|
89 | RTTHREAD ThreadPoller;
|
---|
90 | /** Event semaphore the thread will wait on. */
|
---|
91 | RTSEMEVENT EventPoller;
|
---|
92 | /** The poller interval. */
|
---|
93 | RTMSINTERVAL cMilliesPoller;
|
---|
94 | /** The shutdown indicator. */
|
---|
95 | bool volatile fShutdownPoller;
|
---|
96 |
|
---|
97 | /** BIOS PCHS geometry. */
|
---|
98 | PDMMEDIAGEOMETRY PCHSGeometry;
|
---|
99 | /** BIOS LCHS geometry. */
|
---|
100 | PDMMEDIAGEOMETRY LCHSGeometry;
|
---|
101 |
|
---|
102 | /** Pointer to the current buffer holding data. */
|
---|
103 | void *pvBuf;
|
---|
104 | /** Size of the buffer. */
|
---|
105 | size_t cbBuf;
|
---|
106 | /** Size of the I/O request to allocate. */
|
---|
107 | size_t cbIoReqAlloc;
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * Performs the locking / unlocking of the device.
|
---|
111 | *
|
---|
112 | * This callback pointer should be set to NULL if the device doesn't support this action.
|
---|
113 | *
|
---|
114 | * @returns VBox status code.
|
---|
115 | * @param pThis Pointer to the instance data.
|
---|
116 | * @param fLock Set if locking, clear if unlocking.
|
---|
117 | */
|
---|
118 | DECLCALLBACKMEMBER(int, pfnDoLock)(PDRVHOSTBASE pThis, bool fLock);
|
---|
119 |
|
---|
120 | union
|
---|
121 | {
|
---|
122 | #ifdef DRVHOSTBASE_OS_INT_DECLARED
|
---|
123 | DRVHOSTBASEOS Os;
|
---|
124 | #endif
|
---|
125 | uint8_t abPadding[64];
|
---|
126 | };
|
---|
127 | } DRVHOSTBASE;
|
---|
128 |
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * Request structure fo a request.
|
---|
132 | */
|
---|
133 | typedef struct DRVHOSTBASEREQ
|
---|
134 | {
|
---|
135 | /** Transfer size. */
|
---|
136 | size_t cbReq;
|
---|
137 | /** Amount of residual data. */
|
---|
138 | size_t cbResidual;
|
---|
139 | /** Start of the request data for the device above us. */
|
---|
140 | uint8_t abAlloc[1];
|
---|
141 | } DRVHOSTBASEREQ;
|
---|
142 | /** Pointer to a request structure. */
|
---|
143 | typedef DRVHOSTBASEREQ *PDRVHOSTBASEREQ;
|
---|
144 |
|
---|
145 | DECLHIDDEN(int) DRVHostBaseInit(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, const char *pszCfgValid, PDMMEDIATYPE enmType);
|
---|
146 | DECLHIDDEN(int) DRVHostBaseMediaPresent(PDRVHOSTBASE pThis);
|
---|
147 | DECLHIDDEN(void) DRVHostBaseMediaNotPresent(PDRVHOSTBASE pThis);
|
---|
148 | DECLCALLBACK(void) DRVHostBaseDestruct(PPDMDRVINS pDrvIns);
|
---|
149 |
|
---|
150 | DECLHIDDEN(int) drvHostBaseScsiCmdOs(PDRVHOSTBASE pThis, const uint8_t *pbCmd, size_t cbCmd, PDMMEDIATXDIR enmTxDir,
|
---|
151 | void *pvBuf, uint32_t *pcbBuf, uint8_t *pbSense, size_t cbSense, uint32_t cTimeoutMillies);
|
---|
152 | DECLHIDDEN(int) drvHostBaseGetMediaSizeOs(PDRVHOSTBASE pThis, uint64_t *pcb);
|
---|
153 | DECLHIDDEN(int) drvHostBaseReadOs(PDRVHOSTBASE pThis, uint64_t off, void *pvBuf, size_t cbRead);
|
---|
154 | DECLHIDDEN(int) drvHostBaseWriteOs(PDRVHOSTBASE pThis, uint64_t off, const void *pvBuf, size_t cbWrite);
|
---|
155 | DECLHIDDEN(int) drvHostBaseFlushOs(PDRVHOSTBASE pThis);
|
---|
156 | DECLHIDDEN(int) drvHostBaseDoLockOs(PDRVHOSTBASE pThis, bool fLock);
|
---|
157 | DECLHIDDEN(int) drvHostBaseEjectOs(PDRVHOSTBASE pThis);
|
---|
158 |
|
---|
159 | DECLHIDDEN(void) drvHostBaseInitOs(PDRVHOSTBASE pThis);
|
---|
160 | DECLHIDDEN(int) drvHostBaseOpenOs(PDRVHOSTBASE pThis, bool fReadOnly);
|
---|
161 | DECLHIDDEN(int) drvHostBaseMediaRefreshOs(PDRVHOSTBASE pThis);
|
---|
162 | DECLHIDDEN(int) drvHostBaseQueryMediaStatusOs(PDRVHOSTBASE pThis, bool *pfMediaChanged, bool *pfMediaPresent);
|
---|
163 | DECLHIDDEN(bool) drvHostBaseIsMediaPollingRequiredOs(PDRVHOSTBASE pThis);
|
---|
164 | DECLHIDDEN(void) drvHostBaseDestructOs(PDRVHOSTBASE pThis);
|
---|
165 |
|
---|
166 | DECLHIDDEN(int) drvHostBaseBufferRetain(PDRVHOSTBASE pThis, PDRVHOSTBASEREQ pReq, size_t cbBuf, bool fWrite, void **ppvBuf);
|
---|
167 | DECLHIDDEN(int) drvHostBaseBufferRelease(PDRVHOSTBASE pThis, PDRVHOSTBASEREQ pReq, size_t cbBuf, bool fWrite, void *pvBuf);
|
---|
168 |
|
---|
169 | RT_C_DECLS_END
|
---|
170 |
|
---|
171 | #endif
|
---|