Changeset 81512 in vbox for trunk/src/VBox/Devices/EFI
- Timestamp:
- Oct 24, 2019 9:19:42 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/DevFlash.cpp
r81509 r81512 43 43 *********************************************************************************************************************************/ 44 44 /** 45 * The flash device 45 * The flash device, shared state. 46 46 */ 47 47 typedef struct DEVFLASH … … 51 51 /** The guest physical memory base address. */ 52 52 RTGCPHYS GCPhysFlashBase; 53 /** The file conaining the flash content. */54 char *pszFlashFile;53 /** The handle to the MMIO region. */ 54 IOMMMIOHANDLE hMmio; 55 55 } DEVFLASH; 56 56 /** Pointer to the Flash device state. */ 57 57 typedef DEVFLASH *PDEVFLASH; 58 58 59 /** 60 * The flash device, ring-3 state. 61 */ 62 typedef struct DEVFLASHR3 63 { 64 /** The file conaining the flash content. */ 65 char *pszFlashFile; 66 } DEVFLASHR3; 67 /** Pointer to the ring-3 Flash device state. */ 68 typedef DEVFLASHR3 *PDEVFLASHR3; 69 70 59 71 #ifndef VBOX_DEVICE_STRUCT_TESTCASE 60 72 61 73 62 #ifdef IN_RING3 /* for now */ 63 64 /** @callback_method_impl{FNIOMMIWRITE, Flash memory write}*/65 PDMBOTHCBDECL( int) flashMMIOWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void const *pv, unsigned cb)74 /** 75 * @callback_method_impl{FNIOMMMIONEWWRITE, Flash memory write} 76 */ 77 PDMBOTHCBDECL(VBOXSTRICTRC) flashMMIOWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void const *pv, unsigned cb) 66 78 { 67 79 PDEVFLASH pThis = PDMINS_2_DATA(pDevIns, PDEVFLASH); 68 80 RT_NOREF1(pvUser); 69 70 return VBOXSTRICTRC_TODO(flashWrite(&pThis->Core, GCPhysAddr - pThis->GCPhysFlashBase, pv, cb)); 71 } 72 73 74 /** @callback_method_impl{FNIOMMIOREAD, Flash memory read} */ 75 PDMBOTHCBDECL(int) flashMMIORead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb) 81 return flashWrite(&pThis->Core, off, pv, cb); 82 } 83 84 85 /** 86 * @callback_method_impl{FNIOMMMIONEWREAD, Flash memory read} 87 */ 88 PDMBOTHCBDECL(VBOXSTRICTRC) flashMMIORead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void *pv, unsigned cb) 76 89 { 77 90 PDEVFLASH pThis = PDMINS_2_DATA(pDevIns, PDEVFLASH); 78 91 RT_NOREF1(pvUser); 79 80 return VBOXSTRICTRC_TODO(flashRead(&pThis->Core, GCPhysAddr - pThis->GCPhysFlashBase, pv, cb)); 81 } 82 83 #endif /* IN_RING3 for now */ 92 return flashRead(&pThis->Core, off, pv, cb); 93 } 84 94 85 95 #ifdef IN_RING3 86 96 87 /** @callback_method_impl{FNSSMDEVSAVEEXEC} */ 97 /** 98 * @callback_method_impl{FNSSMDEVSAVEEXEC} 99 */ 88 100 static DECLCALLBACK(int) flashSaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM) 89 101 { … … 93 105 94 106 95 /** @callback_method_impl{FNSSMDEVLOADEXEC} */ 107 /** 108 * @callback_method_impl{FNSSMDEVLOADEXEC} 109 */ 96 110 static DECLCALLBACK(int) flashLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass) 97 111 { … … 106 120 } 107 121 122 108 123 /** 109 124 * @interface_method_impl{PDMDEVREG,pfnReset} … … 112 127 { 113 128 PDEVFLASH pThis = PDMINS_2_DATA(pDevIns, PDEVFLASH); 114 115 129 flashR3Reset(&pThis->Core); 116 130 } 117 131 132 118 133 /** 119 134 * @interface_method_impl{PDMDEVREG,pfnDestruct} … … 122 137 { 123 138 PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns); 124 PDEVFLASH pThis = PDMINS_2_DATA(pDevIns, PDEVFLASH); 125 126 int rc = flashR3SaveToFile(&pThis->Core, pDevIns, pThis->pszFlashFile); 127 if (RT_FAILURE(rc)) 128 LogRel(("Flash: Failed to save flash file: %Rrc\n", rc)); 129 130 if (pThis->pszFlashFile) 139 PDEVFLASH pThis = PDMINS_2_DATA(pDevIns, PDEVFLASH); 140 PDEVFLASHR3 pThisR3 = PDMINS_2_DATA_CC(pDevIns, PDEVFLASHR3); 141 142 if (pThisR3->pszFlashFile) 131 143 { 132 PDMDevHlpMMHeapFree(pDevIns, pThis->pszFlashFile); 133 pThis->pszFlashFile = NULL; 144 int rc = flashR3SaveToFile(&pThis->Core, pDevIns, pThisR3->pszFlashFile); 145 if (RT_FAILURE(rc)) 146 LogRel(("Flash: Failed to save flash file: %Rrc\n", rc)); 147 148 PDMDevHlpMMHeapFree(pDevIns, pThisR3->pszFlashFile); 149 pThisR3->pszFlashFile = NULL; 134 150 } 135 151 … … 138 154 } 139 155 156 140 157 /** 141 158 * @interface_method_impl{PDMDEVREG,pfnConstruct} … … 144 161 { 145 162 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns); 146 RT_NOREF1(iInstance); 147 PDEVFLASH pThis = PDMINS_2_DATA(pDevIns, PDEVFLASH); 148 Assert(iInstance == 0); 163 PDEVFLASH pThis = PDMINS_2_DATA(pDevIns, PDEVFLASH); 164 PDEVFLASHR3 pThisR3 = PDMINS_2_DATA_CC(pDevIns, PDEVFLASHR3); 165 PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3; 166 167 Assert(iInstance == 0); RT_NOREF1(iInstance); 149 168 150 169 /* … … 159 178 /* The default device ID is Intel 28F800SA. */ 160 179 uint16_t u16FlashId = 0; 161 int rc = CFGMR3QueryU16Def(pCfg, "DeviceId", &u16FlashId, 0xA289);180 int rc = pHlp->pfnCFGMQueryU16Def(pCfg, "DeviceId", &u16FlashId, 0xA289); 162 181 if (RT_FAILURE(rc)) 163 182 return PDMDEV_SET_ERROR(pDevIns, rc, … … 165 184 166 185 /* The default base address is 2MB below 4GB. */ 167 rc = CFGMR3QueryU64Def(pCfg, "BaseAddress", &pThis->GCPhysFlashBase, 0xFFE00000);186 rc = pHlp->pfnCFGMQueryU64Def(pCfg, "BaseAddress", &pThis->GCPhysFlashBase, 0xFFE00000); 168 187 if (RT_FAILURE(rc)) 169 188 return PDMDEV_SET_ERROR(pDevIns, rc, … … 172 191 /* The default flash device size is 128K. */ 173 192 uint32_t cbFlash = 0; 174 rc = CFGMR3QueryU32Def(pCfg, "Size", &cbFlash, 128 * _1K);193 rc = pHlp->pfnCFGMQueryU32Def(pCfg, "Size", &cbFlash, 128 * _1K); 175 194 if (RT_FAILURE(rc)) 176 195 return PDMDEV_SET_ERROR(pDevIns, rc, … … 179 198 /* The default flash device block size is 4K. */ 180 199 uint16_t cbBlock = 0; 181 rc = CFGMR3QueryU16Def(pCfg, "BlockSize", &cbBlock, _4K);200 rc = pHlp->pfnCFGMQueryU16Def(pCfg, "BlockSize", &cbBlock, _4K); 182 201 if (RT_FAILURE(rc)) 183 202 return PDMDEV_SET_ERROR(pDevIns, rc, 184 203 N_("Configuration error: Querying \"BlockSize\" as an integer failed")); 185 204 186 rc = CFGMR3QueryStringAlloc(pCfg, "FlashFile", &pThis->pszFlashFile);205 rc = pHlp->pfnCFGMQueryStringAlloc(pCfg, "FlashFile", &pThisR3->pszFlashFile); 187 206 if (RT_FAILURE(rc)) 188 207 return PDMDEV_SET_ERROR(pDevIns, rc, 189 208 N_("Configuration error: Querying \"FlashFile\" as a string failed")); 190 209 210 /* 211 * Initialize the flash core. 212 */ 191 213 rc = flashR3Init(&pThis->Core, pDevIns, u16FlashId, cbFlash, cbBlock); 192 214 if (RT_FAILURE(rc)) … … 195 217 196 218 /* Try to load the flash content from file. */ 197 rc = flashR3LoadFromFile(&pThis->Core, pDevIns, pThis ->pszFlashFile);219 rc = flashR3LoadFromFile(&pThis->Core, pDevIns, pThisR3->pszFlashFile); 198 220 if (RT_FAILURE(rc)) 199 221 return PDMDEV_SET_ERROR(pDevIns, rc, … … 203 225 * Register MMIO region. 204 226 */ 205 rc = PDMDevHlpMMIORegister(pDevIns, pThis->GCPhysFlashBase, cbFlash, NULL /*pvUser*/, 206 IOMMMIO_FLAGS_READ_PASSTHRU | IOMMMIO_FLAGS_WRITE_PASSTHRU, 207 flashMMIOWrite, flashMMIORead, 208 "Flash Memory"); 227 rc = PDMDevHlpMmioCreateExAndMap(pDevIns, pThis->GCPhysFlashBase, cbFlash, 228 IOMMMIO_FLAGS_READ_PASSTHRU | IOMMMIO_FLAGS_WRITE_PASSTHRU, NULL, UINT32_MAX, 229 flashMMIOWrite, flashMMIORead, NULL, NULL, "Flash Memory", &pThis->hMmio); 209 230 AssertRCReturn(rc, rc); 210 231 LogRel(("Registered %uKB flash at %RGp\n", pThis->Core.cbFlashSize / _1K, pThis->GCPhysFlashBase)); … … 214 235 */ 215 236 rc = PDMDevHlpSSMRegister(pDevIns, FLASH_SAVED_STATE_VERSION, sizeof(*pThis), flashSaveExec, flashLoadExec); 216 if (RT_FAILURE(rc)) 217 return rc; 237 AssertRCReturn(rc, rc); 218 238 219 239 return VINF_SUCCESS; 220 240 } 221 241 222 #endif /* IN_RING3 */ 242 #else /* !IN_RING3 */ 243 244 /** 245 * @callback_method_impl{PDMDEVREGR0,pfnConstruct} 246 */ 247 static DECLCALLBACK(int) flashRZConstruct(PPDMDEVINS pDevIns) 248 { 249 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns); 250 PDEVFLASH pThis = PDMINS_2_DATA(pDevIns, PDEVFLASH); 251 252 # if 1 253 int rc = PDMDevHlpMmioSetUpContext(pDevIns, pThis->hMmio, flashMMIOWrite, flashMMIORead, NULL /*pvUser*/); 254 AssertRCReturn(rc, rc); 255 # else 256 RT_NOREF(pDevIns, pThis); (void)&flashMMIOWrite; (void)&flashMMIORead; 257 # endif 258 259 return VINF_SUCCESS; 260 } 261 262 #endif /* !IN_RING3 */ 223 263 224 264 /** … … 230 270 /* .uReserved0 = */ 0, 231 271 /* .szName = */ "flash", 232 /* .fFlags = */ PDM_DEVREG_FLAGS_DEFAULT_BITS ,272 /* .fFlags = */ PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_RZ | PDM_DEVREG_FLAGS_NEW_STYLE, 233 273 /* .fClass = */ PDM_DEVREG_CLASS_ARCH, 234 274 /* .cMaxInstances = */ 1, … … 267 307 #elif defined(IN_RING0) 268 308 /* .pfnEarlyConstruct = */ NULL, 269 /* .pfnConstruct = */ NULL,309 /* .pfnConstruct = */ flashRZConstruct, 270 310 /* .pfnDestruct = */ NULL, 271 311 /* .pfnFinalDestruct = */ NULL, … … 281 321 #elif defined(IN_RC) 282 322 /* .pfnConstruct = */ NULL, 283 /* .pfnReserved0 = */ NULL,323 /* .pfnReserved0 = */ flashRZConstruct, 284 324 /* .pfnReserved1 = */ NULL, 285 325 /* .pfnReserved2 = */ NULL,
Note:
See TracChangeset
for help on using the changeset viewer.