Compute dynamically slot_id in PA and VA functions

This make easier to change allocation of memory using different
memory Bars.

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 16:02:47 +01:00
parent 53fb38c92f
commit 8a8c6c41c0
2 changed files with 27 additions and 25 deletions

View File

@ -3571,7 +3571,7 @@ void QxlDevice::CreatePrimarySurface(PVIDEO_MODE_INFORMATION pModeInfo)
primary_surface_create->height = pModeInfo->VisScreenHeight; primary_surface_create->height = pModeInfo->VisScreenHeight;
primary_surface_create->stride = pModeInfo->ScreenStride; primary_surface_create->stride = pModeInfo->ScreenStride;
primary_surface_create->mem = PA( m_RamStart, m_MainMemSlot); primary_surface_create->mem = PA(m_RamStart);
primary_surface_create->flags = 0; primary_surface_create->flags = 0;
primary_surface_create->type = QXL_SURF_TYPE_PRIMARY; primary_surface_create->type = QXL_SURF_TYPE_PRIMARY;
@ -3591,23 +3591,25 @@ void QxlDevice::DestroyPrimarySurface(void)
DbgPrint(TRACE_LEVEL_VERBOSE, ("<--- %s\n", __FUNCTION__)); DbgPrint(TRACE_LEVEL_VERBOSE, ("<--- %s\n", __FUNCTION__));
} }
_inline QXLPHYSICAL QxlDevice::PA(PVOID virt, UINT8 slot_id) _inline QXLPHYSICAL QxlDevice::PA(PVOID virt)
{ {
PAGED_CODE(); PAGED_CODE();
DbgPrint(TRACE_LEVEL_VERBOSE, ("<--> %s\n", __FUNCTION__)); DbgPrint(TRACE_LEVEL_VERBOSE, ("<--> %s\n", __FUNCTION__));
MemSlot *pSlot = &m_MemSlots[slot_id];
const MemSlot *pSlot = m_MemSlots;
if (virt < pSlot->start_virt_addr || virt > pSlot->last_virt_addr)
++pSlot;
return pSlot->high_bits | ((UINT8*)virt - pSlot->start_virt_addr); return pSlot->high_bits | ((UINT8*)virt - pSlot->start_virt_addr);
} }
_inline UINT8 *QxlDevice::VA(QXLPHYSICAL paddr, UINT8 slot_id) _inline UINT8 *QxlDevice::VA(QXLPHYSICAL paddr)
{ {
PAGED_CODE(); PAGED_CODE();
UINT64 virt;
MemSlot *pSlot = &m_MemSlots[slot_id];
DbgPrint(TRACE_LEVEL_VERBOSE, ("---> %s\n", __FUNCTION__)); DbgPrint(TRACE_LEVEL_VERBOSE, ("---> %s\n", __FUNCTION__));
virt = paddr & m_VaSlotMask;
return pSlot->start_virt_addr + virt; UINT8 slot_id = UINT8(paddr >> (64 - m_SlotIdBits)) - m_RomHdr->slots_start;
const MemSlot *pSlot = &m_MemSlots[slot_id & 1];
return pSlot->start_virt_addr + (paddr & m_VaSlotMask);
} }
void QxlDevice::SetupHWSlot(UINT8 Idx, MemSlot *pSlot) void QxlDevice::SetupHWSlot(UINT8 Idx, MemSlot *pSlot)
@ -3743,7 +3745,7 @@ NTSTATUS QxlDevice::InitMonitorConfig(void)
if (m_monitor_config) { if (m_monitor_config) {
RtlZeroMemory(m_monitor_config, config_size); RtlZeroMemory(m_monitor_config, config_size);
m_monitor_config_pa = &m_RamHdr->monitors_config; m_monitor_config_pa = &m_RamHdr->monitors_config;
*m_monitor_config_pa = PA(m_monitor_config, m_MainMemSlot); *m_monitor_config_pa = PA(m_monitor_config);
} }
return m_monitor_config ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL; return m_monitor_config ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL;
} }
@ -4193,7 +4195,7 @@ BOOL QxlDevice::SetClip(const RECT *clip, QXLDrawable *drawable)
DrawableAddRes(drawable, rects_res); DrawableAddRes(drawable, rects_res);
drawable->clip.type = SPICE_CLIP_TYPE_RECTS; drawable->clip.type = SPICE_CLIP_TYPE_RECTS;
drawable->clip.data = PA(rects_res->res, m_SurfaceMemSlot); drawable->clip.data = PA(rects_res->res);
return TRUE; return TRUE;
} }
@ -4245,7 +4247,7 @@ void QxlDevice::FreeClipRects(Resource *res)
chunk_phys = ((QXLClipRects *)res->res)->chunk.next_chunk; chunk_phys = ((QXLClipRects *)res->res)->chunk.next_chunk;
while (chunk_phys) { while (chunk_phys) {
QXLDataChunk *chunk = (QXLDataChunk *)VA(chunk_phys, m_SurfaceMemSlot); QXLDataChunk *chunk = (QXLDataChunk *)VA(chunk_phys);
chunk_phys = chunk->next_chunk; chunk_phys = chunk->next_chunk;
FreeMem(chunk); FreeMem(chunk);
} }
@ -4272,7 +4274,7 @@ void QxlDevice::FreeBitmapImage(Resource *res)
chunk_phys = ((QXLDataChunk *)(&internal->image.bitmap + 1))->next_chunk; chunk_phys = ((QXLDataChunk *)(&internal->image.bitmap + 1))->next_chunk;
while (chunk_phys) { while (chunk_phys) {
QXLDataChunk *chunk = (QXLDataChunk *)VA(chunk_phys, m_SurfaceMemSlot); QXLDataChunk *chunk = (QXLDataChunk *)VA(chunk_phys);
chunk_phys = chunk->next_chunk; chunk_phys = chunk->next_chunk;
FreeMem(chunk); FreeMem(chunk);
} }
@ -4297,7 +4299,7 @@ void QxlDevice::FreeCursor(Resource *res)
DbgPrint(TRACE_LEVEL_VERBOSE, ("---> %s\n", __FUNCTION__)); DbgPrint(TRACE_LEVEL_VERBOSE, ("---> %s\n", __FUNCTION__));
chunk_phys = ((InternalCursor *)res->res)->cursor.chunk.next_chunk; chunk_phys = ((InternalCursor *)res->res)->cursor.chunk.next_chunk;
while (chunk_phys) { while (chunk_phys) {
QXLDataChunk *chunk = (QXLDataChunk *)VA(chunk_phys, m_SurfaceMemSlot); QXLDataChunk *chunk = (QXLDataChunk *)VA(chunk_phys);
chunk_phys = chunk->next_chunk; chunk_phys = chunk->next_chunk;
FreeMem(chunk); FreeMem(chunk);
} }
@ -4349,7 +4351,7 @@ void QxlDevice::PushDrawable(QXLDrawable *drawable)
WaitForCmdRing(); WaitForCmdRing();
cmd = SPICE_RING_PROD_ITEM(m_CommandRing); cmd = SPICE_RING_PROD_ITEM(m_CommandRing);
cmd->type = QXL_CMD_DRAW; cmd->type = QXL_CMD_DRAW;
cmd->data = PA(drawable, m_SurfaceMemSlot); cmd->data = PA(drawable);
PushCmd(); PushCmd();
ReleaseMutex(&m_CmdLock, locked); ReleaseMutex(&m_CmdLock, locked);
DbgPrint(TRACE_LEVEL_VERBOSE, ("<--- %s\n", __FUNCTION__)); DbgPrint(TRACE_LEVEL_VERBOSE, ("<--- %s\n", __FUNCTION__));
@ -4367,7 +4369,7 @@ void QxlDevice::PushCursorCmd(QXLCursorCmd *cursor_cmd)
WaitForCursorRing(); WaitForCursorRing();
cmd = SPICE_RING_PROD_ITEM(m_CursorRing); cmd = SPICE_RING_PROD_ITEM(m_CursorRing);
cmd->type = QXL_CMD_CURSOR; cmd->type = QXL_CMD_CURSOR;
cmd->data = PA(cursor_cmd, m_SurfaceMemSlot); cmd->data = PA(cursor_cmd);
PushCursor(); PushCursor();
ReleaseMutex(&m_CrsLock, locked); ReleaseMutex(&m_CrsLock, locked);
DbgPrint(TRACE_LEVEL_VERBOSE, ("<--- %s\n", __FUNCTION__)); DbgPrint(TRACE_LEVEL_VERBOSE, ("<--- %s\n", __FUNCTION__));
@ -4447,7 +4449,7 @@ BOOLEAN QxlDevice::AttachNewBitmap(QXLDrawable *drawable, UINT8 *src, UINT8 *src
chunk->data_size = 0; chunk->data_size = 0;
chunk->prev_chunk = 0; chunk->prev_chunk = 0;
chunk->next_chunk = 0; chunk->next_chunk = 0;
internal->image.bitmap.data = PA(chunk, m_SurfaceMemSlot); internal->image.bitmap.data = PA(chunk);
internal->image.bitmap.flags = 0; internal->image.bitmap.flags = 0;
internal->image.descriptor.width = internal->image.bitmap.x = width; internal->image.descriptor.width = internal->image.bitmap.x = width;
internal->image.descriptor.height = internal->image.bitmap.y = height; internal->image.descriptor.height = internal->image.bitmap.y = height;
@ -4458,7 +4460,7 @@ BOOLEAN QxlDevice::AttachNewBitmap(QXLDrawable *drawable, UINT8 *src, UINT8 *src
dest = chunk->data; dest = chunk->data;
dest_end = (UINT8 *)image_res + alloc_size; dest_end = (UINT8 *)image_res + alloc_size;
drawable->u.copy.src_bitmap = PA(&internal->image, m_SurfaceMemSlot); drawable->u.copy.src_bitmap = PA(&internal->image);
DrawableAddRes(drawable, image_res); DrawableAddRes(drawable, image_res);
RELEASE_RES(image_res); RELEASE_RES(image_res);
@ -4597,8 +4599,8 @@ BOOLEAN QxlDevice::PutBytesAlign(QXLDataChunk **chunk_ptr, UINT8 **now_ptr,
if (!cp_size) { if (!cp_size) {
void *ptr = (bForced || IsListEmpty(pDelayed)) ? AllocMem(MSPACE_TYPE_VRAM, alloc_size + sizeof(QXLDataChunk), bForced) : NULL; void *ptr = (bForced || IsListEmpty(pDelayed)) ? AllocMem(MSPACE_TYPE_VRAM, alloc_size + sizeof(QXLDataChunk), bForced) : NULL;
if (ptr) { if (ptr) {
chunk->next_chunk = PA(ptr, m_SurfaceMemSlot); chunk->next_chunk = PA(ptr);
((QXLDataChunk *)ptr)->prev_chunk = PA(chunk, m_SurfaceMemSlot); ((QXLDataChunk *)ptr)->prev_chunk = PA(chunk);
chunk = (QXLDataChunk *)ptr; chunk = (QXLDataChunk *)ptr;
chunk->next_chunk = 0; chunk->next_chunk = 0;
} }
@ -4758,7 +4760,7 @@ NTSTATUS QxlDevice::SetPointerShape(_In_ CONST DXGKARG_SETPOINTERSHAPE* pSetPoi
} }
CursorCmdAddRes(cursor_cmd, res); CursorCmdAddRes(cursor_cmd, res);
RELEASE_RES(res); RELEASE_RES(res);
cursor_cmd->u.set.shape = PA(&internal->cursor, m_SurfaceMemSlot); cursor_cmd->u.set.shape = PA(&internal->cursor);
PushCursorCmd(cursor_cmd); PushCursorCmd(cursor_cmd);
DbgPrint(TRACE_LEVEL_VERBOSE, ("<--- %s\n", __FUNCTION__)); DbgPrint(TRACE_LEVEL_VERBOSE, ("<--- %s\n", __FUNCTION__));
@ -5232,8 +5234,8 @@ ULONG QxlDevice::PrepareDrawable(QXLDrawable*& drawable)
// some chunks were not allocated // some chunks were not allocated
chunk = MakeChunk(pdc); chunk = MakeChunk(pdc);
if (chunk) { if (chunk) {
chunk->prev_chunk = PA(lastchunk, m_SurfaceMemSlot); chunk->prev_chunk = PA(lastchunk);
lastchunk->next_chunk = PA(chunk, m_SurfaceMemSlot); lastchunk->next_chunk = PA(chunk);
lastchunk = chunk; lastchunk = chunk;
++n; ++n;
} else { } else {

View File

@ -584,8 +584,8 @@ private:
void SetupMemSlot(UINT8 Idx, UINT64 pastart, UINT64 paend, UINT8 *vastart, UINT8 *valast); void SetupMemSlot(UINT8 Idx, UINT64 pastart, UINT64 paend, UINT8 *vastart, UINT8 *valast);
BOOL CreateEvents(void); BOOL CreateEvents(void);
BOOL CreateRings(void); BOOL CreateRings(void);
UINT8 *VA(QXLPHYSICAL paddr, UINT8 slot_id); UINT8 *VA(QXLPHYSICAL paddr);
QXLPHYSICAL PA(PVOID virt, UINT8 slot_id); QXLPHYSICAL PA(PVOID virt);
void InitDeviceMemoryResources(void); void InitDeviceMemoryResources(void);
NTSTATUS InitMonitorConfig(); NTSTATUS InitMonitorConfig();
void InitMspace(UINT32 mspace_type, UINT8 *start, size_t capacity); void InitMspace(UINT32 mspace_type, UINT8 *start, size_t capacity);