Changeset 42099 in vbox
- Timestamp:
- Jul 10, 2012 5:14:45 PM (13 years ago)
- Location:
- trunk/src/VBox/Devices
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Makefile.kmk
r42062 r42099 418 418 VBoxDD_DEFS += VBOX_WITH_AHCI IN_AHCI_R3 419 419 VBoxDD_SOURCES += \ 420 Storage/DevAHCI.cpp \ 421 Storage/ATAController.cpp 420 Storage/DevAHCI.cpp 422 421 endif 423 422 … … 867 866 VBoxDDGC_DEFS += VBOX_WITH_AHCI IN_AHCI_GC 868 867 VBoxDDGC_SOURCES += \ 869 Storage/DevAHCI.cpp \ 870 Storage/ATAController.cpp 868 Storage/DevAHCI.cpp 871 869 endif 872 870 … … 1020 1018 VBoxDDR0_DEFS += VBOX_WITH_AHCI IN_AHCI_R0 1021 1019 VBoxDDR0_SOURCES += \ 1022 Storage/DevAHCI.cpp \ 1023 Storage/ATAController.cpp 1020 Storage/DevAHCI.cpp 1024 1021 endif 1025 1022 -
trunk/src/VBox/Devices/Storage/DevAHCI.cpp
r41774 r42099 2298 2298 } 2299 2299 2300 PDMBOTHCBDECL(int) ahciIOPortWrite1(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)2301 {2302 uint32_t iChannel = (uint32_t)(uintptr_t)pvUser;2303 PAHCI pAhci = PDMINS_2_DATA(pDevIns, PAHCI);2304 PAHCIATACONTROLLER pCtl = &pAhci->aCts[iChannel];2305 2306 Assert(iChannel < 2);2307 2308 return ataControllerIOPortWrite1(pCtl, Port, u32, cb);2309 }2310 2311 PDMBOTHCBDECL(int) ahciIOPortRead1(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)2312 {2313 uint32_t iChannel = (uint32_t)(uintptr_t)pvUser;2314 PAHCI pAhci = PDMINS_2_DATA(pDevIns, PAHCI);2315 PAHCIATACONTROLLER pCtl = &pAhci->aCts[iChannel];2316 2317 Assert(iChannel < 2);2318 2319 return ataControllerIOPortRead1(pCtl, Port, pu32, cb);2320 }2321 2322 PDMBOTHCBDECL(int) ahciIOPortWrite2(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)2323 {2324 uint32_t iChannel = (uint32_t)(uintptr_t)pvUser;2325 PAHCI pAhci = PDMINS_2_DATA(pDevIns, PAHCI);2326 PAHCIATACONTROLLER pCtl = &pAhci->aCts[iChannel];2327 2328 Assert(iChannel < 2);2329 2330 return ataControllerIOPortWrite2(pCtl, Port, u32, cb);2331 }2332 2333 PDMBOTHCBDECL(int) ahciIOPortRead2(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)2334 {2335 uint32_t iChannel = (uint32_t)(uintptr_t)pvUser;2336 PAHCI pAhci = PDMINS_2_DATA(pDevIns, PAHCI);2337 PAHCIATACONTROLLER pCtl = &pAhci->aCts[iChannel];2338 2339 Assert(iChannel < 2);2340 2341 return ataControllerIOPortRead2(pCtl, Port, pu32, cb);2342 }2343 2344 2300 PDMBOTHCBDECL(int) ahciLegacyFakeWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb) 2345 2301 { … … 2438 2394 return rc; 2439 2395 } 2440 2441 #ifndef IN_RING02442 /**2443 * Port I/O Handler for primary port range IN string operations.2444 * @see FNIOMIOPORTINSTRING for details.2445 */2446 PDMBOTHCBDECL(int) ahciIOPortReadStr1(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, RTGCPTR *pGCPtrDst, PRTGCUINTREG pcTransfer, unsigned cb)2447 {2448 uint32_t iChannel = (uint32_t)(uintptr_t)pvUser;2449 PAHCI pAhci = PDMINS_2_DATA(pDevIns, PAHCI);2450 PAHCIATACONTROLLER pCtl = &pAhci->aCts[iChannel];2451 2452 Assert(iChannel < 2);2453 2454 return ataControllerIOPortReadStr1(pCtl, Port, pGCPtrDst, pcTransfer, cb);2455 }2456 2457 2458 /**2459 * Port I/O Handler for primary port range OUT string operations.2460 * @see FNIOMIOPORTOUTSTRING for details.2461 */2462 PDMBOTHCBDECL(int) ahciIOPortWriteStr1(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, RTGCPTR *pGCPtrSrc, PRTGCUINTREG pcTransfer, unsigned cb)2463 {2464 uint32_t iChannel = (uint32_t)(uintptr_t)pvUser;2465 PAHCI pAhci = PDMINS_2_DATA(pDevIns, PAHCI);2466 PAHCIATACONTROLLER pCtl = &pAhci->aCts[iChannel];2467 2468 Assert(iChannel < 2);2469 2470 return ataControllerIOPortReadStr1(pCtl, Port, pGCPtrSrc, pcTransfer, cb);2471 }2472 #endif /* !IN_RING0 */2473 2396 2474 2397 #ifdef IN_RING3 … … 6661 6584 } 6662 6585 } 6663 6664 if (pThis->fBootable)6665 for (uint32_t i = 0; i < RT_ELEMENTS(pThis->aCts); i++)6666 if (!ataControllerIsIdle(&pThis->aCts[i]))6667 return false;6668 6669 6586 return true; 6670 6587 } … … 6792 6709 } 6793 6710 6794 /* Now the emulated ata controllers. */6795 for (i = 0; i < RT_ELEMENTS(pThis->aCts); i++)6796 {6797 rc = ataControllerSaveExec(&pThis->aCts[i], pSSM);6798 if (RT_FAILURE(rc))6799 return rc;6800 }6801 6802 6711 return SSMR3PutU32(pSSM, UINT32_MAX); /* sanity/terminator */ 6803 6712 } … … 6977 6886 } 6978 6887 } 6979 6980 /* Now the emulated ata controllers. */6981 for (uint32_t i = 0; i < RT_ELEMENTS(pThis->aCts); i++)6982 {6983 rc = ataControllerLoadExec(&pThis->aCts[i], pSSM);6984 if (RT_FAILURE(rc))6985 return rc;6986 }6987 6988 rc = SSMR3GetU32(pSSM, &u32);6989 if (RT_FAILURE(rc))6990 return rc;6991 AssertMsgReturn(u32 == UINT32_MAX, ("%#x\n", u32), VERR_SSM_DATA_UNIT_FORMAT_CHANGED);6992 6888 } 6993 6889 … … 7013 6909 pAhciPort->pDevInsRC += offDelta; 7014 6910 } 7015 7016 /* Relocate emulated ATA controllers. */7017 for (i = 0; i < RT_ELEMENTS(pAhci->aCts); i++)7018 ataControllerRelocate(&pAhci->aCts[i], offDelta);7019 6911 } 7020 6912 … … 7066 6958 } 7067 6959 7068 /* Destroy emulated ATA controllers. */7069 for (unsigned i = 0; i < RT_ELEMENTS(pAhci->aCts); i++)7070 ataControllerDestroy(&pAhci->aCts[i]);7071 7072 6960 PDMR3CritSectDelete(&pAhci->lock); 7073 6961 } … … 7346 7234 7347 7235 Log(("%s:\n", __FUNCTION__)); 7348 if (pAhci->fBootable)7349 for (uint32_t i = 0; i < RT_ELEMENTS(pAhci->aCts); i++)7350 ataControllerResume(&pAhci->aCts[i]);7351 7236 } 7352 7237 … … 7512 7397 } 7513 7398 } 7514 7515 if (pCtl)7516 ataControllerDetach(pCtl, fMaster);7517 7399 7518 7400 if (pAhciPort->fATAPI) … … 7604 7486 } 7605 7487 } 7606 7607 /* Attach to the controller if available */7608 if (pCtl)7609 rc = ataControllerAttach(pCtl, pAhciPort->pDrvBase, fMaster);7610 7611 if (RT_SUCCESS(rc))7612 {7613 char szName[24];7614 RTStrPrintf(szName, sizeof(szName), "Port%d", iLUN);7615 7616 if ( pAhciPort->pDrvBlockAsync7617 && !pAhciPort->fATAPI)7618 {7619 pAhciPort->fAsyncInterface = true;7620 }7621 else7622 {7623 pAhciPort->fAsyncInterface = false;7624 7625 /* Create event semaphore. */7626 rc = RTSemEventCreate(&pAhciPort->AsyncIORequestSem);7627 if (RT_FAILURE(rc))7628 {7629 Log(("%s: Failed to create event semaphore for %s.\n", __FUNCTION__, szName));7630 return rc;7631 }7632 7633 /* Create the async IO thread. */7634 rc = PDMDevHlpThreadCreate(pDevIns, &pAhciPort->pAsyncIOThread, pAhciPort, ahciAsyncIOLoop, ahciAsyncIOLoopWakeUp, 0,7635 RTTHREADTYPE_IO, szName);7636 if (RT_FAILURE(rc))7637 {7638 AssertMsgFailed(("%s: Async IO Thread creation for %s failed rc=%d\n", __FUNCTION__, szName, rc));7639 return rc;7640 }7641 }7642 7643 /*7644 * Init vendor product data.7645 */7646 if (RT_SUCCESS(rc))7647 rc = ahciR3VpdInit(pDevIns, pAhciPort, szName);7648 7649 /* Inform the guest about the added device in case of hotplugging. */7650 if ( RT_SUCCESS(rc)7651 && !(fFlags & PDM_TACH_FLAGS_NOT_HOT_PLUG))7652 {7653 /*7654 * Initialize registers7655 */7656 ASMAtomicOrU32(&pAhciPort->regCMD, AHCI_PORT_CMD_CPS);7657 ASMAtomicOrU32(&pAhciPort->regIS, AHCI_PORT_IS_CPDS | AHCI_PORT_IS_PRCS | AHCI_PORT_IS_PCS);7658 ASMAtomicOrU32(&pAhciPort->regSERR, AHCI_PORT_SERR_X | AHCI_PORT_SERR_N);7659 7660 if (pAhciPort->fATAPI)7661 pAhciPort->regSIG = AHCI_PORT_SIG_ATAPI;7662 else7663 pAhciPort->regSIG = AHCI_PORT_SIG_DISK;7664 pAhciPort->regSSTS = (0x01 << 8) | /* Interface is active. */7665 (0x02 << 4) | /* Generation 2 (3.0GBps) speed. */7666 (0x03 << 0); /* Device detected and communication established. */7667 7668 if ( (pAhciPort->regIE & AHCI_PORT_IE_CPDE)7669 || (pAhciPort->regIE & AHCI_PORT_IE_PCE)7670 || (pAhciPort->regIE & AHCI_PORT_IE_PRCE))7671 ahciHbaSetInterrupt(pAhciPort->CTX_SUFF(pAhci), pAhciPort->iLUN, VERR_IGNORED);7672 }7673 }7674 7488 } 7675 7489 … … 7691 7505 for (uint32_t i = 0; i < RT_ELEMENTS(pAhci->ahciPort); i++) 7692 7506 ahciPortHwReset(&pAhci->ahciPort[i]); 7693 7694 if (pAhci->fBootable)7695 for (uint32_t i = 0; i < RT_ELEMENTS(pAhci->aCts); i++)7696 ataControllerReset(&pAhci->aCts[i]);7697 7507 return VINF_SUCCESS; 7698 7508 } … … 8093 7903 return PDMDEV_SET_ERROR(pDevIns, rc, N_("AHCI cannot attach to status driver")); 8094 7904 } 8095 8096 if (pThis->fBootable)8097 {8098 /*8099 * Setup IDE emulation.8100 * We only emulate the I/O ports but not bus master DMA.8101 * If the configuration values are not found the setup of the ports is as follows:8102 * Primary Master: Port 08103 * Primary Slave: Port 18104 * Secondary Master: Port 28105 * Secondary Slave: Port 38106 */8107 8108 /*8109 * Setup I/O ports for the PCI device.8110 */8111 pThis->aCts[0].irq = 12;8112 pThis->aCts[0].IOPortBase1 = 0x1e8;8113 pThis->aCts[0].IOPortBase2 = 0x3e6;8114 pThis->aCts[1].irq = 11;8115 pThis->aCts[1].IOPortBase1 = 0x168;8116 pThis->aCts[1].IOPortBase2 = 0x366;8117 8118 for (i = 0; i < RT_ELEMENTS(pThis->aCts); i++)8119 {8120 PAHCIATACONTROLLER pCtl = &pThis->aCts[i];8121 uint32_t iPortMaster, iPortSlave;8122 uint32_t cbSSMState = 0;8123 static const char *s_apszDescs[RT_ELEMENTS(pThis->aCts)][RT_ELEMENTS(pCtl->aIfs)] =8124 {8125 { "PrimaryMaster", "PrimarySlave" },8126 { "SecondaryMaster", "SecondarySlave" }8127 };8128 8129 rc = CFGMR3QueryU32Def(pCfg, s_apszDescs[i][0], &iPortMaster, 2 * i);8130 if (RT_FAILURE(rc))8131 return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,8132 N_("AHCI configuration error: failed to read %s as U32"), s_apszDescs[i][0]);8133 8134 rc = CFGMR3QueryU32Def(pCfg, s_apszDescs[i][1], &iPortSlave, 2 * i + 1);8135 if (RT_FAILURE(rc))8136 return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,8137 N_("AHCI configuration error: failed to read %s as U32"), s_apszDescs[i][1]);8138 8139 char szName[24];8140 RTStrPrintf(szName, sizeof(szName), "EmulatedATA%d", i);8141 rc = ataControllerInit(pDevIns, pCtl, pThis->pMediaNotify,8142 iPortMaster, pThis->ahciPort[iPortMaster].pDrvBase,8143 &pThis->ahciPort[iPortMaster].Led,8144 &pThis->ahciPort[iPortMaster].StatBytesRead,8145 &pThis->ahciPort[iPortMaster].StatBytesWritten,8146 pThis->ahciPort[iPortMaster].szSerialNumber,8147 pThis->ahciPort[iPortMaster].szFirmwareRevision,8148 pThis->ahciPort[iPortMaster].szModelNumber,8149 pThis->ahciPort[iPortMaster].szInquiryVendorId,8150 pThis->ahciPort[iPortMaster].szInquiryProductId,8151 pThis->ahciPort[iPortMaster].szInquiryRevision,8152 pThis->ahciPort[iPortMaster].fNonRotational,8153 iPortSlave, pThis->ahciPort[iPortSlave].pDrvBase,8154 &pThis->ahciPort[iPortSlave].Led,8155 &pThis->ahciPort[iPortSlave].StatBytesRead,8156 &pThis->ahciPort[iPortSlave].StatBytesWritten,8157 pThis->ahciPort[iPortSlave].szSerialNumber,8158 pThis->ahciPort[iPortSlave].szFirmwareRevision,8159 pThis->ahciPort[iPortSlave].szModelNumber,8160 pThis->ahciPort[iPortSlave].szInquiryVendorId,8161 pThis->ahciPort[iPortSlave].szInquiryProductId,8162 pThis->ahciPort[iPortSlave].szInquiryRevision,8163 pThis->ahciPort[iPortSlave].fNonRotational,8164 &cbSSMState, szName);8165 if (RT_FAILURE(rc))8166 return rc;8167 8168 cbTotalBufferSize += cbSSMState;8169 8170 rc = PDMDevHlpIOPortRegister(pDevIns, pCtl->IOPortBase1, 8, (RTHCPTR)i,8171 ahciIOPortWrite1, ahciIOPortRead1, ahciIOPortWriteStr1, ahciIOPortReadStr1, "AHCI");8172 if (RT_FAILURE(rc))8173 return rc;8174 8175 if (pThis->fR0Enabled)8176 {8177 rc = PDMDevHlpIOPortRegisterR0(pDevIns, pCtl->IOPortBase1, 8, (RTR0PTR)i,8178 "ahciIOPortWrite1", "ahciIOPortRead1", NULL, NULL, "AHCI R0");8179 if (RT_FAILURE(rc))8180 return rc;8181 }8182 8183 if (pThis->fGCEnabled)8184 {8185 rc = PDMDevHlpIOPortRegisterRC(pDevIns, pCtl->IOPortBase1, 8, (RTGCPTR)i,8186 "ahciIOPortWrite1", "ahciIOPortRead1", NULL, NULL, "AHCI GC");8187 if (RT_FAILURE(rc))8188 return rc;8189 }8190 8191 rc = PDMDevHlpIOPortRegister(pDevIns, pCtl->IOPortBase2, 1, (RTHCPTR)i,8192 ahciIOPortWrite2, ahciIOPortRead2, NULL, NULL, "AHCI");8193 if (RT_FAILURE(rc))8194 return rc;8195 8196 if (pThis->fR0Enabled)8197 {8198 rc = PDMDevHlpIOPortRegisterR0(pDevIns, pCtl->IOPortBase2, 1, (RTR0PTR)i,8199 "ahciIOPortWrite2", "ahciIOPortRead2", NULL, NULL, "AHCI R0");8200 if (RT_FAILURE(rc))8201 return rc;8202 }8203 8204 if (pThis->fGCEnabled)8205 {8206 rc = PDMDevHlpIOPortRegisterRC(pDevIns, pCtl->IOPortBase2, 1, (RTGCPTR)i,8207 "ahciIOPortWrite2", "ahciIOPortRead2", NULL, NULL, "AHCI GC");8208 if (RT_FAILURE(rc))8209 return rc;8210 }8211 }8212 }8213 8214 7905 rc = PDMDevHlpSSMRegisterEx(pDevIns, AHCI_SAVED_STATE_VERSION, sizeof(*pThis)+cbTotalBufferSize, NULL, 8215 7906 NULL, ahciR3LiveExec, NULL,
Note:
See TracChangeset
for help on using the changeset viewer.