Lines Matching refs:pDev

42 DECLINLINE(uint16_t)  msixGetMessageControl(PPCIDEVICE pDev)
44 return PCIDevGetWord(pDev, pDev->Int.s.u8MsixCapOffset + VBOX_MSIX_CAP_MESSAGE_CONTROL);
47 DECLINLINE(bool) msixIsEnabled(PPCIDEVICE pDev)
49 return (msixGetMessageControl(pDev) & VBOX_PCI_MSIX_FLAGS_ENABLE) != 0;
52 DECLINLINE(bool) msixIsMasked(PPCIDEVICE pDev)
54 return (msixGetMessageControl(pDev) & VBOX_PCI_MSIX_FLAGS_FUNCMASK) != 0;
57 DECLINLINE(uint16_t) msixTableSize(PPCIDEVICE pDev)
59 return (msixGetMessageControl(pDev) & 0x3ff) + 1;
62 DECLINLINE(uint8_t*) msixGetPageOffset(PPCIDEVICE pDev, uint32_t off)
64 return (uint8_t*)pDev->Int.s.CTX_SUFF(pMsixPage) + off;
67 DECLINLINE(MsixTableRecord*) msixGetVectorRecord(PPCIDEVICE pDev, uint32_t iVector)
69 return (MsixTableRecord*)msixGetPageOffset(pDev, iVector * VBOX_MSIX_ENTRY_SIZE);
72 DECLINLINE(RTGCPHYS) msixGetMsiAddress(PPCIDEVICE pDev, uint32_t iVector)
74 MsixTableRecord* pRec = msixGetVectorRecord(pDev, iVector);
78 DECLINLINE(uint32_t) msixGetMsiData(PPCIDEVICE pDev, uint32_t iVector)
80 return msixGetVectorRecord(pDev, iVector)->u32MsgData;
83 DECLINLINE(uint32_t) msixIsVectorMasked(PPCIDEVICE pDev, uint32_t iVector)
85 return (msixGetVectorRecord(pDev, iVector)->u32VectorControl & 0x1) != 0;
88 DECLINLINE(uint8_t*) msixPendingByte(PPCIDEVICE pDev, uint32_t iVector)
90 return msixGetPageOffset(pDev, 0x800 + iVector / 8);
93 DECLINLINE(void) msixSetPending(PPCIDEVICE pDev, uint32_t iVector)
95 *msixPendingByte(pDev, iVector) |= (1 << (iVector & 0x7));
98 DECLINLINE(void) msixClearPending(PPCIDEVICE pDev, uint32_t iVector)
100 *msixPendingByte(pDev, iVector) &= ~(1 << (iVector & 0x7));
103 DECLINLINE(bool) msixIsPending(PPCIDEVICE pDev, uint32_t iVector)
105 return (*msixPendingByte(pDev, iVector) & (1 << (iVector & 0x7))) != 0;
108 static void msixCheckPendingVector(PPDMDEVINS pDevIns, PCPDMPCIHLP pPciHlp, PPCIDEVICE pDev, uint32_t iVector)
110 if (msixIsPending(pDev, iVector) && !msixIsVectorMasked(pDev, iVector))
111 MsixNotify(pDevIns, pPciHlp, pDev, iVector, 1 /* iLevel */, 0 /*uTagSrc*/);
168 int MsixInit(PCPDMPCIHLP pPciHlp, PPCIDEVICE pDev, PPDMMSIREG pMsiReg)
174 Assert(!pciDevIsPassthrough(pDev));
198 if (!pciDevIsPassthrough(pDev))
200 rc = PDMDevHlpPCIIORegionRegister (pDev->pDevIns, iBar, 0x1000, PCI_ADDRESS_SPACE_MEM, msixMap);
205 pDev->Int.s.u8MsixCapOffset = iCapOffset;
206 pDev->Int.s.u8MsixCapSize = VBOX_MSIX_CAP_SIZE;
207 PVM pVM = PDMDevHlpGetVM(pDev->pDevIns);
209 pDev->Int.s.pMsixPageR3 = NULL;
211 rc = MMHyperAlloc(pVM, 0x1000, 1, MM_TAG_PDM_DEVICE_USER, (void **)&pDev->Int.s.pMsixPageR3);
212 if (RT_FAILURE(rc) || (pDev->Int.s.pMsixPageR3 == NULL))
214 RT_BZERO(pDev->Int.s.pMsixPageR3, 0x1000);
215 pDev->Int.s.pMsixPageR0 = MMHyperR3ToR0(pVM, pDev->Int.s.pMsixPageR3);
216 pDev->Int.s.pMsixPageRC = MMHyperR3ToRC(pVM, pDev->Int.s.pMsixPageR3);
219 pDev->Int.s.pPciBusPtrR3 = pPciHlp;
221 PCIDevSetByte(pDev, iCapOffset + 0, VBOX_PCI_CAP_ID_MSIX);
222 PCIDevSetByte(pDev, iCapOffset + 1, iNextOffset); /* next */
223 PCIDevSetWord(pDev, iCapOffset + VBOX_MSIX_CAP_MESSAGE_CONTROL, cVectors - 1);
227 PCIDevSetDWord(pDev, iCapOffset + VBOX_MSIX_TABLE_BIROFFSET, offTable | iBar);
228 PCIDevSetDWord(pDev, iCapOffset + VBOX_MSIX_PBA_BIROFFSET, offPBA | iBar);
230 pciDevSetMsixCapable(pDev);
236 bool MsixIsEnabled(PPCIDEVICE pDev)
238 return pciDevIsMsixCapable(pDev) && msixIsEnabled(pDev);
241 void MsixNotify(PPDMDEVINS pDevIns, PCPDMPCIHLP pPciHlp, PPCIDEVICE pDev, int iVector, int iLevel, uint32_t uTagSrc)
243 AssertMsg(msixIsEnabled(pDev), ("Must be enabled to use that"));
254 if (msixIsMasked(pDev) || msixIsVectorMasked(pDev, iVector))
257 msixSetPending(pDev, iVector);
262 msixClearPending(pDev, iVector);
264 RTGCPHYS GCAddr = msixGetMsiAddress(pDev, iVector);
265 uint32_t u32Value = msixGetMsiData(pDev, iVector);
277 static void msixCheckPendingVectors(PPDMDEVINS pDevIns, PCPDMPCIHLP pPciHlp, PPCIDEVICE pDev)
279 for (uint32_t i = 0; i < msixTableSize(pDev); i++)
280 msixCheckPendingVector(pDevIns, pPciHlp, pDev, i);
284 void MsixPciConfigWrite(PPDMDEVINS pDevIns, PCPDMPCIHLP pPciHlp, PPCIDEVICE pDev, uint32_t u32Address, uint32_t val, unsigned len)
286 int32_t iOff = u32Address - pDev->Int.s.u8MsixCapOffset;
287 Assert(iOff >= 0 && (pciDevIsMsixCapable(pDev) && iOff < pDev->Int.s.u8MsixCapSize));
310 u8NewVal = (u8Val & UINT8_C(~0x3f)) | (pDev->config[uAddr] & UINT8_C(0x3f));
312 fJustEnabled |= msixBitJustCleared(pDev->config[uAddr], u8NewVal, VBOX_PCI_MSIX_FLAGS_ENABLE >> 8);
313 fJustEnabled |= msixBitJustCleared(pDev->config[uAddr], u8NewVal, VBOX_PCI_MSIX_FLAGS_FUNCMASK >> 8);
314 pDev->config[uAddr] = u8NewVal;
326 msixCheckPendingVectors(pDevIns, pPciHlp, pDev);
330 uint32_t MsixPciConfigRead(PPDMDEVINS pDevIns, PPCIDEVICE pDev, uint32_t u32Address, unsigned len)
332 int32_t iOff = u32Address - pDev->Int.s.u8MsixCapOffset;
335 Assert(iOff >= 0 && (pciDevIsMsixCapable(pDev) && iOff < pDev->Int.s.u8MsixCapSize));
341 rv = PCIDevGetByte(pDev, u32Address);
344 rv = PCIDevGetWord(pDev, u32Address);
347 rv = PCIDevGetDWord(pDev, u32Address);