Allocate m_MemSlots statically inside QxlDevice

There were always 2 slots used so make no sense to allocate
always dynamically.
Also in this way m_MainMemSlot and m_SurfaceMemSlot become
constant making the code slightly smaller.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Yuri Benditovich <yuri.benditovich@daynix.com>
This commit is contained in:
Frediano Ziglio 2017-04-10 15:50:54 +01:00
parent 7e0642c3f2
commit 6ec0533a7d
2 changed files with 17 additions and 29 deletions

View File

@ -3548,24 +3548,14 @@ BOOL QxlDevice::InitMemSlots(void)
m_SlotGenBits = m_RomHdr->slot_gen_bits; m_SlotGenBits = m_RomHdr->slot_gen_bits;
m_SlotIdBits = m_RomHdr->slot_id_bits; m_SlotIdBits = m_RomHdr->slot_id_bits;
m_VaSlotMask = (~(uint64_t)0) >> (m_SlotIdBits + m_SlotGenBits); m_VaSlotMask = (~(uint64_t)0) >> (m_SlotIdBits + m_SlotGenBits);
size_t size = m_RomHdr->slots_end * sizeof(MemSlot); RtlZeroMemory(m_MemSlots, sizeof(m_MemSlots));
m_MemSlots = reinterpret_cast<MemSlot*>
(new (PagedPool) BYTE[size]);
if (m_MemSlots)
{
RtlZeroMemory(m_MemSlots, size);
return TRUE; return TRUE;
} }
DbgPrint(TRACE_LEVEL_ERROR, ("---> %s Failed to init mem slot\n", __FUNCTION__));
return FALSE;
}
void QxlDevice::DestroyMemSlots(void) void QxlDevice::DestroyMemSlots(void)
{ {
PAGED_CODE(); PAGED_CODE();
DbgPrint(TRACE_LEVEL_VERBOSE, ("---> %s\n", __FUNCTION__)); DbgPrint(TRACE_LEVEL_VERBOSE, ("---> %s\n", __FUNCTION__));
delete [] reinterpret_cast<BYTE*>(m_MemSlots);
m_MemSlots = NULL;
DbgPrint(TRACE_LEVEL_VERBOSE, ("<--- %s\n", __FUNCTION__)); DbgPrint(TRACE_LEVEL_VERBOSE, ("<--- %s\n", __FUNCTION__));
} }
@ -3693,7 +3683,7 @@ void QxlDevice::SyncIo(UCHAR Port, UCHAR Value)
ReleaseMutex(&m_IoLock, locked); ReleaseMutex(&m_IoLock, locked);
} }
UINT8 QxlDevice::SetupMemSlot(UINT8 Idx, UINT64 pastart, UINT64 paend, UINT64 vastart, UINT64 vaend) void QxlDevice::SetupMemSlot(UINT8 Idx, UINT64 pastart, UINT64 paend, UINT64 vastart, UINT64 vaend)
{ {
PAGED_CODE(); PAGED_CODE();
UINT64 high_bits; UINT64 high_bits;
@ -3702,7 +3692,7 @@ UINT8 QxlDevice::SetupMemSlot(UINT8 Idx, UINT64 pastart, UINT64 paend, UINT64 va
DbgPrint(TRACE_LEVEL_VERBOSE, ("---> %s\n", __FUNCTION__)); DbgPrint(TRACE_LEVEL_VERBOSE, ("---> %s\n", __FUNCTION__));
slot_index = m_RomHdr->slots_start + Idx; slot_index = m_RomHdr->slots_start + Idx;
pSlot = &m_MemSlots[slot_index]; pSlot = &m_MemSlots[Idx];
pSlot->start_phys_addr = pastart; pSlot->start_phys_addr = pastart;
pSlot->end_phys_addr = paend; pSlot->end_phys_addr = paend;
pSlot->start_virt_addr = vastart; pSlot->start_virt_addr = vastart;
@ -3716,7 +3706,6 @@ UINT8 QxlDevice::SetupMemSlot(UINT8 Idx, UINT64 pastart, UINT64 paend, UINT64 va
high_bits <<= (64 - (m_SlotGenBits + m_SlotIdBits)); high_bits <<= (64 - (m_SlotGenBits + m_SlotIdBits));
pSlot->high_bits = high_bits; pSlot->high_bits = high_bits;
DbgPrint(TRACE_LEVEL_VERBOSE, ("<--- %s\n", __FUNCTION__)); DbgPrint(TRACE_LEVEL_VERBOSE, ("<--- %s\n", __FUNCTION__));
return slot_index;
} }
BOOL QxlDevice::CreateMemSlots(void) BOOL QxlDevice::CreateMemSlots(void)
@ -3724,13 +3713,13 @@ BOOL QxlDevice::CreateMemSlots(void)
PAGED_CODE(); PAGED_CODE();
DbgPrint(TRACE_LEVEL_VERBOSE, ("---> %s 3\n", __FUNCTION__)); DbgPrint(TRACE_LEVEL_VERBOSE, ("---> %s 3\n", __FUNCTION__));
UINT64 len = m_RomHdr->surface0_area_size + m_RomHdr->num_pages * PAGE_SIZE; UINT64 len = m_RomHdr->surface0_area_size + m_RomHdr->num_pages * PAGE_SIZE;
m_MainMemSlot = SetupMemSlot(0, SetupMemSlot(m_MainMemSlot,
(UINT64)m_RamPA.QuadPart, (UINT64)m_RamPA.QuadPart,
(UINT64)(m_RamPA.QuadPart + len), (UINT64)(m_RamPA.QuadPart + len),
(UINT64)m_RamStart, (UINT64)m_RamStart,
(UINT64)(m_RamStart + len)); (UINT64)(m_RamStart + len));
len = m_VRamSize; len = m_VRamSize;
m_SurfaceMemSlot = SetupMemSlot(1, SetupMemSlot(m_SurfaceMemSlot,
(UINT64)m_VRamPA.QuadPart, (UINT64)m_VRamPA.QuadPart,
(UINT64)(m_VRamPA.QuadPart + len), (UINT64)(m_VRamPA.QuadPart + len),
(UINT64)m_VRamStart, (UINT64)m_VRamStart,

View File

@ -581,7 +581,7 @@ private:
void CreatePrimarySurface(PVIDEO_MODE_INFORMATION pModeInfo); void CreatePrimarySurface(PVIDEO_MODE_INFORMATION pModeInfo);
void DestroyPrimarySurface(void); void DestroyPrimarySurface(void);
void SetupHWSlot(UINT8 Idx, MemSlot *pSlot); void SetupHWSlot(UINT8 Idx, MemSlot *pSlot);
UINT8 SetupMemSlot(UINT8 Idx, UINT64 pastart, UINT64 paend, UINT64 vastart, UINT64 vaend); void SetupMemSlot(UINT8 Idx, UINT64 pastart, UINT64 paend, UINT64 vastart, UINT64 vaend);
BOOL CreateEvents(void); BOOL CreateEvents(void);
BOOL CreateRings(void); BOOL CreateRings(void);
UINT64 VA(QXLPHYSICAL paddr, UINT8 slot_id); UINT64 VA(QXLPHYSICAL paddr, UINT8 slot_id);
@ -646,9 +646,8 @@ private:
QXLRom *m_RomHdr; QXLRom *m_RomHdr;
ULONG m_RomSize; ULONG m_RomSize;
MemSlot *m_MemSlots; MemSlot m_MemSlots[2];
UINT8 m_MainMemSlot; enum { m_MainMemSlot = 0, m_SurfaceMemSlot = 1 };
UINT8 m_SurfaceMemSlot;
UINT8 m_SlotIdBits; UINT8 m_SlotIdBits;
UINT8 m_SlotGenBits; UINT8 m_SlotGenBits;
QXLPHYSICAL m_VaSlotMask; QXLPHYSICAL m_VaSlotMask;