Lines Matching defs:pIns

173     HGSMIINSTANCE *pIns;               /* Backlink to the HGSMI instance. */
213 static void hgsmiGuestCompletionFIFOFree (HGSMIINSTANCE *pIns, HGSMIGUESTCOMPLENTRY *pEntry)
215 NOREF (pIns);
219 static int hgsmiGuestCompletionFIFOAlloc (HGSMIINSTANCE *pIns, HGSMIGUESTCOMPLENTRY **ppEntry)
223 NOREF (pIns);
237 static int hgsmiLock (HGSMIINSTANCE *pIns)
239 int rc = RTCritSectEnter (&pIns->instanceCritSect);
244 static void hgsmiUnlock (HGSMIINSTANCE *pIns)
246 int rc = RTCritSectLeave (&pIns->instanceCritSect);
250 static int hgsmiFIFOLock (HGSMIINSTANCE *pIns)
252 int rc = RTCritSectEnter (&pIns->hostFIFOCritSect);
257 static void hgsmiFIFOUnlock (HGSMIINSTANCE *pIns)
259 int rc = RTCritSectLeave (&pIns->hostFIFOCritSect);
271 void HGSMIGuestWrite (PHGSMIINSTANCE pIns,
274 HGSMIBufferProcess (&pIns->area, &pIns->channelInfo, offBuffer);
278 static HGSMIOFFSET hgsmiProcessGuestCmdCompletion(HGSMIINSTANCE *pIns)
281 int rc = hgsmiFIFOLock(pIns);
285 HGSMIGUESTCOMPLENTRY *pEntry = RTListGetFirst(&pIns->guestCmdCompleted, HGSMIGUESTCOMPLENTRY, nodeEntry);
291 if (RTListIsEmpty(&pIns->guestCmdCompleted))
293 if(pIns->pHGFlags)
295 ASMAtomicAndU32(&pIns->pHGFlags->u32HostFlags, ~HGSMIHOSTFLAGS_GCOMMAND_COMPLETED);
299 hgsmiFIFOUnlock(pIns);
307 hgsmiGuestCompletionFIFOFree(pIns, pEntry);
316 HGSMIOFFSET HGSMIGuestRead (PHGSMIINSTANCE pIns)
318 LogFlowFunc(("pIns %p\n", pIns));
320 AssertPtr(pIns);
322 VM_ASSERT_EMT(pIns->pVM);
326 NOREF(pIns);
332 HGSMIOFFSET offCmd = hgsmiProcessGuestCmdCompletion(pIns);
337 static bool hgsmiProcessHostCmdCompletion(HGSMIINSTANCE *pIns,
341 VM_ASSERT_EMT(pIns->pVM);
343 int rc = hgsmiFIFOLock(pIns);
350 RTListForEach(&pIns->hostFIFORead, pIter, HGSMIHOSTFIFOENTRY, nodeEntry)
371 RTListAppend(&pIns->hostFIFOProcessed, &pEntry->nodeEntry);
373 hgsmiFIFOUnlock(pIns);
386 hgsmiFIFOUnlock(pIns);
388 LogRel(("HGSMI[%s]: ignored invalid write to the host FIFO: 0x%08X!!!\n", pIns->pszName, offBuffer));
397 void HGSMIHostWrite (HGSMIINSTANCE *pIns,
400 LogFlowFunc(("pIns %p offBuffer 0x%x\n", pIns, offBuffer));
402 hgsmiProcessHostCmdCompletion (pIns, offBuffer, false);
409 HGSMIOFFSET HGSMIHostRead (HGSMIINSTANCE *pIns)
411 LogFlowFunc(("pIns %p\n", pIns));
413 VM_ASSERT_EMT(pIns->pVM);
415 AssertPtrReturn(pIns->pHGFlags, VERR_WRONG_ORDER);
416 int rc = hgsmiFIFOLock(pIns);
421 HGSMIHOSTFIFOENTRY *pEntry = RTListGetFirst(&pIns->hostFIFO, HGSMIHOSTFIFOENTRY, nodeEntry);
434 if (RTListIsEmpty(&pIns->hostFIFO))
436 ASMAtomicAndU32(&pIns->pHGFlags->u32HostFlags, (~HGSMIHOSTFLAGS_COMMANDS_PENDING));
442 RTListAppend(&pIns->hostFIFORead, &pEntry->nodeEntry);
444 hgsmiFIFOUnlock(pIns);
449 hgsmiFIFOUnlock(pIns);
457 static void hgsmiNotifyGuest (HGSMIINSTANCE *pIns)
459 if (pIns->pfnNotifyGuest)
461 pIns->pfnNotifyGuest (pIns->pvNotifyGuest);
465 void HGSMISetHostGuestFlags(HGSMIINSTANCE *pIns, uint32_t flags)
467 AssertPtrReturnVoid(pIns->pHGFlags);
468 ASMAtomicOrU32(&pIns->pHGFlags->u32HostFlags, flags);
471 void HGSMIClearHostGuestFlags(HGSMIINSTANCE *pIns, uint32_t flags)
473 AssertPtrReturnVoid(pIns->pHGFlags);
474 ASMAtomicAndU32(&pIns->pHGFlags->u32HostFlags, (~flags));
498 static int hgsmiHostHeapLock (HGSMIINSTANCE *pIns)
500 int rc = RTCritSectEnter (&pIns->hostHeapCritSect);
505 static void hgsmiHostHeapUnlock (HGSMIINSTANCE *pIns)
507 int rc = RTCritSectLeave (&pIns->hostHeapCritSect);
511 static int hgsmiHostFIFOAlloc (HGSMIINSTANCE *pIns, HGSMIHOSTFIFOENTRY **ppEntry)
515 NOREF (pIns);
544 static void hgsmiHostFIFOFree (HGSMIINSTANCE *pIns, HGSMIHOSTFIFOENTRY *pEntry)
546 NOREF (pIns);
558 HGSMIINSTANCE *pIns = pEntry->pIns;
559 int rc = hgsmiFIFOLock (pIns);
563 hgsmiFIFOUnlock (pIns);
565 void *pvMem = HGSMIBufferDataFromOffset(&pIns->area, pEntry->offBuffer);
567 rc = hgsmiHostHeapLock (pIns);
571 HGSMIHeapFree (&pIns->hostHeap, pvMem);
573 hgsmiHostHeapUnlock(pIns);
576 hgsmiHostFIFOFree (pIns, pEntry);
581 static int hgsmiHostCommandFree (HGSMIINSTANCE *pIns,
584 HGSMIOFFSET offMem = HGSMIHeapBufferOffset (&pIns->hostHeap, pvMem);
588 rc = hgsmiFIFOLock (pIns);
595 RTListForEach(&pIns->hostFIFOProcessed, pIter, HGSMIHOSTFIFOENTRY, nodeEntry)
612 LogRel(("HGSMI[%s]: the host frees unprocessed FIFO entry: 0x%08X\n", pIns->pszName, offMem));
616 hgsmiFIFOUnlock (pIns);
618 rc = hgsmiHostHeapLock (pIns);
622 HGSMIHeapFree (&pIns->hostHeap, pvMem);
624 hgsmiHostHeapUnlock(pIns);
630 hgsmiHostFIFOFree (pIns, pEntry);
638 LogRel(("HGSMI[%s]: the host frees invalid FIFO entry: %p\n", pIns->pszName, pvMem));
668 static int hgsmiHostCommandWrite (HGSMIINSTANCE *pIns, HGSMIOFFSET offMem
676 AssertPtrReturn(pIns->pHGFlags, VERR_WRONG_ORDER);
677 int rc = hgsmiHostFIFOAlloc (pIns, &pEntry);
684 pEntry->pIns = pIns;
691 rc = hgsmiFIFOLock(pIns);
694 RTListAppend(&pIns->hostFIFO, &pEntry->nodeEntry);
695 ASMAtomicOrU32(&pIns->pHGFlags->u32HostFlags, HGSMIHOSTFLAGS_COMMANDS_PENDING);
697 hgsmiFIFOUnlock(pIns);
704 hgsmiHostFIFOFree(pIns, pEntry);
715 * @param pIns Pointer to HGSMI instance,
725 static int hgsmiHostCommandProcess (HGSMIINSTANCE *pIns, HGSMIOFFSET offBuffer,
733 // int rc = hgsmiCheckMemPtr (pIns, pvMem, &offMem);
738 int rc = hgsmiHostCommandWrite (pIns, offBuffer
749 hgsmiNotifyGuest (pIns);
779 * @param pIns Pointer to HGSMI instance,
783 int HGSMIHostCommandAlloc (HGSMIINSTANCE *pIns,
789 LogFlowFunc (("pIns = %p, cbMem = 0x%08X(%d)\n", pIns, cbMem, cbMem));
791 int rc = hgsmiHostHeapLock (pIns);
794 void *pvMem = HGSMIHeapAlloc (&pIns->hostHeap,
798 hgsmiHostHeapUnlock(pIns);
822 * @param pIns Pointer to HGSMI instance,
828 int HGSMIHostCommandProcessAndFreeAsynch (PHGSMIINSTANCE pIns,
832 LogFlowFunc(("pIns = %p, pvMem = %p\n", pIns, pvMem));
838 HGSMIOFFSET offBuffer = HGSMIHeapBufferOffset (&pIns->hostHeap, pvMem);
840 int rc = hgsmiHostCommandProcess (pIns, offBuffer,
855 * @param pIns Pointer to HGSMI instance,
858 int HGSMIHostCommandProcess (HGSMIINSTANCE *pIns,
861 LogFlowFunc(("pIns = %p, pvMem = %p\n", pIns, pvMem));
863 VM_ASSERT_OTHER_THREAD(pIns->pVM);
867 HGSMIOFFSET offBuffer = HGSMIHeapBufferOffset (&pIns->hostHeap, pvMem);
870 // int rc = VMR3ReqCallVoid (pIns->pVM, &pReq, RT_INDEFINITE_WAIT,
872 // 3, pIns, offBuffer, &pvContext);
874 int rc = hgsmiHostCommandProcess (pIns, offBuffer,
896 * @param pIns Pointer to HGSMI instance,
899 int HGSMIHostCommandFree (HGSMIINSTANCE *pIns,
902 LogFlowFunc(("pIns = %p, pvMem = %p\n", pIns, pvMem));
904 return hgsmiHostCommandFree (pIns, pvMem);
926 int HGSMISetupHostHeap (PHGSMIINSTANCE pIns,
930 LogFlowFunc(("pIns %p, offHeap 0x%08X, cbHeap = 0x%08X\n", pIns, offHeap, cbHeap));
934 Assert (pIns);
936 // if ( offHeap >= pIns->cbMem
937 // || cbHeap > pIns->cbMem
938 // || offHeap + cbHeap > pIns->cbMem)
944 rc = hgsmiHostHeapLock (pIns);
948 if (pIns->hostHeap.cRefs)
956 rc = HGSMIHeapSetup (&pIns->hostHeap,
958 pIns->area.pu8Base+offHeap,
964 hgsmiHostHeapUnlock (pIns);
1033 static int hgsmiHostLoadFifoEntryLocked (PHGSMIINSTANCE pIns, HGSMIHOSTFIFOENTRY **ppEntry, PSSMHANDLE pSSM)
1036 int rc = hgsmiHostFIFOAlloc (pIns, &pEntry); AssertRC(rc);
1040 pEntry->pIns = pIns;
1047 hgsmiHostFIFOFree (pIns, pEntry);
1053 static int hgsmiHostLoadFifoLocked(PHGSMIINSTANCE pIns, RTLISTANCHOR *pList, PSSMHANDLE pSSM)
1065 rc = hgsmiHostLoadFifoEntryLocked(pIns, &pEntry, pSSM);
1077 static int hgsmiHostLoadGuestCmdCompletedFifoEntryLocked (PHGSMIINSTANCE pIns, HGSMIGUESTCOMPLENTRY **ppEntry, PSSMHANDLE pSSM)
1080 int rc = hgsmiGuestCompletionFIFOAlloc (pIns, &pEntry); AssertRC(rc);
1087 hgsmiGuestCompletionFIFOFree (pIns, pEntry);
1092 static int hgsmiHostLoadGuestCmdCompletedFifoLocked(PHGSMIINSTANCE pIns, RTLISTANCHOR *pList, PSSMHANDLE pSSM, uint32_t u32Version)
1107 rc = hgsmiHostLoadGuestCmdCompletedFifoEntryLocked(pIns, &pEntry, pSSM);
1122 rc = hgsmiHostLoadFifoEntryLocked(pIns, &pEntry, pSSM);
1125 hgsmiHostFIFOFree(pIns, pEntry);
1193 int HGSMIHostSaveStateExec (PHGSMIINSTANCE pIns, PSSMHANDLE pSSM)
1199 SSMR3PutU32(pSSM, pIns->hostHeap.u32HeapType);
1201 HGSMIOFFSET off = pIns->pHGFlags ? HGSMIPointerToOffset(&pIns->area, (const HGSMIBUFFERHEADER *)pIns->pHGFlags) : HGSMIOFFSET_VOID;
1204 off = pIns->hostHeap.u32HeapType == HGSMI_HEAP_TYPE_MA?
1206 HGSMIHeapHandleLocationOffset(&pIns->hostHeap);
1210 SSMR3PutU32 (pSSM, HGSMIHeapOffset(&pIns->hostHeap));
1211 SSMR3PutU32 (pSSM, HGSMIHeapSize(&pIns->hostHeap));
1213 SSMR3PutU64 (pSSM, (uint64_t)(uintptr_t)pIns->area.pu8Base);
1214 rc = hgsmiFIFOLock (pIns);
1217 rc = hgsmiHostSaveFifoLocked (&pIns->hostFIFO, pSSM); AssertRC(rc);
1218 rc = hgsmiHostSaveFifoLocked (&pIns->hostFIFORead, pSSM); AssertRC(rc);
1219 rc = hgsmiHostSaveFifoLocked (&pIns->hostFIFOProcessed, pSSM); AssertRC(rc);
1221 rc = hgsmiHostSaveGuestCmdCompletedFifoLocked (&pIns->guestCmdCompleted, pSSM); AssertRC(rc);
1224 hgsmiFIFOUnlock (pIns);
1229 if (pIns->hostHeap.u32HeapType == HGSMI_HEAP_TYPE_MA)
1231 rc = hgsmiHostSaveMA(pSSM, &pIns->hostHeap.u.ma);
1241 int HGSMIHostLoadStateExec (PHGSMIINSTANCE pIns, PSSMHANDLE pSSM, uint32_t u32Version)
1260 pIns->pHGFlags = (off != HGSMIOFFSET_VOID) ? (HGSMIHOSTFLAGS*)HGSMIOffsetToPointer (&pIns->area, off) : NULL;
1262 HGSMIHEAP hHeap = pIns->hostHeap;
1285 rc = hgsmiFIFOLock (pIns);
1288 rc = hgsmiHostLoadFifoLocked (pIns, &pIns->hostFIFO, pSSM);
1290 rc = hgsmiHostLoadFifoLocked (pIns, &pIns->hostFIFORead, pSSM);
1292 rc = hgsmiHostLoadFifoLocked (pIns, &pIns->hostFIFOProcessed, pSSM);
1295 rc = hgsmiHostLoadGuestCmdCompletedFifoLocked (pIns, &pIns->guestCmdCompleted, pSSM, u32Version);
1298 hgsmiFIFOUnlock (pIns);
1312 rc = HGSMIHeapRestoreMA(&pIns->hostHeap,
1313 pIns->area.pu8Base+offHeap,
1327 rc = hgsmiHostHeapLock (pIns);
1330 Assert(!pIns->hostHeap.cRefs);
1331 pIns->hostHeap.cRefs = 0;
1333 rc = HGSMIHeapRelocate(&pIns->hostHeap,
1335 pIns->area.pu8Base+offHeap,
1337 uintptr_t(pIns->area.pu8Base) - uintptr_t(oldMem),
1341 hgsmiHostHeapUnlock (pIns);
1356 static int hgsmiChannelMapCreate (PHGSMIINSTANCE pIns,
1366 int HGSMIHostChannelRegister(PHGSMIINSTANCE pIns,
1371 LogFlowFunc(("pIns %p, u8Channel %x, pfnChannelHandler %p, pvChannelHandler %p\n",
1372 pIns, u8Channel, pfnChannelHandler, pvChannelHandler));
1375 AssertPtrReturn(pIns, VERR_INVALID_PARAMETER);
1378 int rc = hgsmiLock (pIns);
1382 rc = HGSMIChannelRegister (&pIns->channelInfo, u8Channel, NULL, pfnChannelHandler, pvChannelHandler);
1384 hgsmiUnlock (pIns);
1394 int HGSMIChannelRegisterName (PHGSMIINSTANCE pIns,
1400 LogFlowFunc(("pIns %p, pszChannel %s, pfnChannelHandler %p, pvChannelHandler %p, pu8Channel %p\n",
1401 pIns, pszChannel, pfnChannelHandler, pvChannelHandler, pu8Channel));
1403 AssertPtrReturn(pIns, VERR_INVALID_PARAMETER);
1415 rc = hgsmiLock (pIns);
1419 rc = hgsmiChannelMapCreate (pIns, pszName, pu8Channel);
1423 rc = HGSMIChannelRegister (&pIns->channelInfo, *pu8Channel, pszName, pfnChannelHandler, pvChannelHandler);
1426 hgsmiUnlock (pIns);
1444 void *HGSMIOffsetToPointerHost (PHGSMIINSTANCE pIns,
1447 const HGSMIAREA *pArea = &pIns->area;
1460 HGSMIOFFSET HGSMIPointerToOffsetHost (PHGSMIINSTANCE pIns,
1463 const HGSMIAREA *pArea = &pIns->area;
1480 void *HGSMIContext (PHGSMIINSTANCE pIns)
1482 uint8_t *p = (uint8_t *)pIns;
1494 PHGSMIINSTANCE pIns = (PHGSMIINSTANCE)pvHandler;
1513 pIns->pHGFlags = (HGSMIHOSTFLAGS*)HGSMIOffsetToPointer (&pIns->area, pLoc->offLocation);
1553 PHGSMIINSTANCE pIns = (PHGSMIINSTANCE)RTMemAllocZ (sizeof (HGSMIINSTANCE) + cbContext);
1555 if (!pIns)
1562 rc = HGSMIAreaInitialize (&pIns->area, pu8MemBase, cbMem, offBase);
1567 rc = RTCritSectInit (&pIns->instanceCritSect);
1572 rc = RTCritSectInit (&pIns->hostHeapCritSect);
1577 rc = RTCritSectInit (&pIns->hostFIFOCritSect);
1582 pIns->pVM = pVM;
1584 pIns->pszName = VALID_PTR(pszName)? pszName: "";
1586 HGSMIHeapSetupUninitialized(&pIns->hostHeap);
1588 pIns->pfnNotifyGuest = pfnNotifyGuest;
1589 pIns->pvNotifyGuest = pvNotifyGuest;
1591 RTListInit(&pIns->hostFIFO);
1592 RTListInit(&pIns->hostFIFORead);
1593 RTListInit(&pIns->hostFIFOProcessed);
1594 RTListInit(&pIns->hostFIFOFree);
1595 RTListInit(&pIns->guestCmdCompleted);
1598 rc = HGSMIHostChannelRegister (pIns,
1601 pIns);
1605 *ppIns = pIns;
1609 HGSMIDestroy (pIns);
1612 LogFlowFunc(("leave rc = %Rrc, pIns = %p\n", rc, pIns));
1617 uint32_t HGSMIReset (PHGSMIINSTANCE pIns)
1620 if(pIns->pHGFlags)
1623 while(HGSMIHostRead (pIns) != HGSMIOFFSET_VOID) {}
1624 flags = pIns->pHGFlags->u32HostFlags;
1625 pIns->pHGFlags->u32HostFlags = 0;
1629 while(hgsmiProcessHostCmdCompletion (pIns, 0, true)) {}
1632 while(hgsmiProcessGuestCmdCompletion(pIns) != HGSMIOFFSET_VOID) {}
1635 HGSMIHeapDestroy(&pIns->hostHeap);
1637 HGSMIHeapSetupUninitialized(&pIns->hostHeap);
1642 void HGSMIDestroy (PHGSMIINSTANCE pIns)
1644 LogFlowFunc(("pIns = %p\n", pIns));
1646 if (pIns)
1648 HGSMIHeapDestroy(&pIns->hostHeap);
1650 if (RTCritSectIsInitialized (&pIns->hostHeapCritSect))
1652 RTCritSectDelete (&pIns->hostHeapCritSect);
1655 if (RTCritSectIsInitialized (&pIns->instanceCritSect))
1657 RTCritSectDelete (&pIns->instanceCritSect);
1660 if (RTCritSectIsInitialized (&pIns->hostFIFOCritSect))
1662 RTCritSectDelete (&pIns->hostFIFOCritSect);
1665 memset (pIns, 0, sizeof (HGSMIINSTANCE));
1667 RTMemFree (pIns);
1675 static int hgsmiGuestCommandComplete (HGSMIINSTANCE *pIns, HGSMIOFFSET offMem)
1679 AssertPtrReturn(pIns->pHGFlags, VERR_WRONG_ORDER);
1680 int rc = hgsmiGuestCompletionFIFOAlloc (pIns, &pEntry);
1686 rc = hgsmiFIFOLock(pIns);
1690 RTListAppend(&pIns->guestCmdCompleted, &pEntry->nodeEntry);
1691 ASMAtomicOrU32(&pIns->pHGFlags->u32HostFlags, HGSMIHOSTFLAGS_GCOMMAND_COMPLETED);
1693 hgsmiFIFOUnlock(pIns);
1697 hgsmiGuestCompletionFIFOFree(pIns, pEntry);
1704 int hgsmiCompleteGuestCommand(PHGSMIINSTANCE pIns,
1708 int rc = hgsmiGuestCommandComplete (pIns, offBuffer);
1714 hgsmiNotifyGuest (pIns);
1726 int HGSMICompleteGuestCommand(PHGSMIINSTANCE pIns,
1730 LogFlowFunc(("pIns = %p, pvMem = %p\n", pIns, pvMem));
1735 HGSMIOFFSET offBuffer = HGSMIPointerToOffset(&pIns->area, pHeader);
1740 rc = hgsmiCompleteGuestCommand (pIns, offBuffer, bDoIrq);