Skip to content

Commit

Permalink
viogpu: Support different implementation of VioGpuAdapter
Browse files Browse the repository at this point in the history
Based on #943

Signed-off-by: Max Ramanouski <[email protected]>
Signed-off-by: Kostiantyn Kostiuk <[email protected]>
  • Loading branch information
kostyanf14 authored and YanVugenfirer committed Dec 2, 2024
1 parent 33fa7ed commit 6a463a3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
17 changes: 8 additions & 9 deletions viogpu/common/viogpu_pci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,15 @@ void mem_free_nonpaged_block(void *context, void *addr)

PAGED_CODE_SEG_BEGIN
static int PCIReadConfig(
VioGpuAdapter* pdev,
IVioGpuPCI* pDev,
int where,
void *buffer,
size_t length)
{
PAGED_CODE();

NTSTATUS Status;
VioGpuDod* pVioGpu = pdev->GetVioGpu();
PDXGKRNL_INTERFACE pDxgkInterface = pVioGpu->GetDxgkInterface();
PDXGKRNL_INTERFACE pDxgkInterface = pDev->GetDxgkInterface();
ULONG BytesRead = 0;

DbgPrint(TRACE_LEVEL_VERBOSE, ("---> %s\n", __FUNCTION__));
Expand All @@ -187,42 +186,42 @@ static int PCIReadConfig(
static int pci_read_config_byte(void *context, int where, u8 *bVal)
{
PAGED_CODE();
VioGpuAdapter* pdev = static_cast<VioGpuAdapter*>(context);
IVioGpuPCI* pdev = static_cast<IVioGpuPCI*>(context);
return PCIReadConfig(pdev, where, bVal, sizeof(*bVal));
}

int pci_read_config_word(void *context, int where, u16 *wVal)
{
PAGED_CODE();
VioGpuAdapter* pdev = static_cast<VioGpuAdapter*>(context);
IVioGpuPCI* pdev = static_cast<IVioGpuPCI*>(context);
return PCIReadConfig(pdev, where, wVal, sizeof(*wVal));
}

int pci_read_config_dword(void *context, int where, u32 *dwVal)
{
PAGED_CODE();
VioGpuAdapter* pdev = static_cast<VioGpuAdapter*>(context);
IVioGpuPCI* pdev = static_cast<IVioGpuPCI*>(context);
return PCIReadConfig(pdev, where, dwVal, sizeof(*dwVal));
}
PAGED_CODE_SEG_END

size_t pci_get_resource_len(void *context, int bar)
{
VioGpuAdapter* pdev = static_cast<VioGpuAdapter*>(context);
IVioGpuPCI* pdev = static_cast<IVioGpuPCI*>(context);
return pdev->GetPciResources()->GetBarSize(bar);
}

void *pci_map_address_range(void *context, int bar, size_t offset, size_t maxlen)
{
UNREFERENCED_PARAMETER(maxlen);

VioGpuAdapter* pdev = static_cast<VioGpuAdapter*>(context);
IVioGpuPCI* pdev = static_cast<IVioGpuPCI*>(context);
return pdev->GetPciResources()->GetMappedAddress(bar, (ULONG)offset);
}

u16 vdev_get_msix_vector(void *context, int queue)
{
VioGpuAdapter* pdev = static_cast<VioGpuAdapter*>(context);
IVioGpuPCI* pdev = static_cast<IVioGpuPCI*>(context);
u16 vector = VIRTIO_MSI_NO_VECTOR;

if (queue >= 0) {
Expand Down
7 changes: 7 additions & 0 deletions viogpu/common/viogpu_pci.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ class CPciResources
CPciBar m_Bars[PCI_TYPE0_ADDRESSES];
};

class IVioGpuPCI {
public:
virtual PDXGKRNL_INTERFACE GetDxgkInterface() = 0;
virtual CPciResources* GetPciResources() = 0;
virtual BOOLEAN IsMSIEnabled() = 0;
};

NTSTATUS
MapFrameBuffer(
_In_ PHYSICAL_ADDRESS PhysicalAddress,
Expand Down
6 changes: 5 additions & 1 deletion viogpu/viogpudo/viogpudo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2141,7 +2141,7 @@ NTSTATUS VioGpuAdapter::VirtIoDeviceInit()
return virtio_device_initialize(
&m_VioDev,
&VioGpuSystemOps,
this,
reinterpret_cast<IVioGpuPCI*>(this),
m_PciResources.IsMSIEnabled());
}

Expand Down Expand Up @@ -3539,3 +3539,7 @@ BOOLEAN VioGpuAdapter::GpuObjectAttach(UINT res_id, VioGpuObj* obj)
return TRUE;
}
PAGED_CODE_SEG_END

PDXGKRNL_INTERFACE VioGpuAdapter::GetDxgkInterface() {
return m_pVioGpuDod->GetDxgkInterface();
}
3 changes: 2 additions & 1 deletion viogpu/viogpudo/viogpudo.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ typedef struct _CURRENT_MODE

class VioGpuDod;

class VioGpuAdapter
class VioGpuAdapter: IVioGpuPCI
{
public:
VioGpuAdapter(_In_ VioGpuDod* pVioGpuDod);
Expand Down Expand Up @@ -104,6 +104,7 @@ class VioGpuAdapter
BOOLEAN ResetToVgaMode(void);
BOOLEAN IsMSIEnabled() { return m_PciResources.IsMSIEnabled(); }
PHYSICAL_ADDRESS GetFrameBufferPA(void) { return m_PciResources.GetPciBar(0)->GetPA(); }
PDXGKRNL_INTERFACE GetDxgkInterface(void);

PVIDEO_MODE_INFORMATION GetModeInfo(UINT idx) { return &m_ModeInfo[idx]; }
USHORT GetModeNumber(USHORT idx) { return (USHORT)m_ModeInfo[idx].ModeIndex; }
Expand Down

0 comments on commit 6a463a3

Please sign in to comment.