From deb35af5181d960c4334414981b8fd3e603a94b3 Mon Sep 17 00:00:00 2001 From: Lucas Fryzek Date: Sat, 3 Aug 2024 12:47:29 +0100 Subject: drv: Add code to create hw render ctx --- src/drv.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 107 insertions(+), 3 deletions(-) (limited to 'src/drv.c') diff --git a/src/drv.c b/src/drv.c index b5d5943..a2b8c84 100644 --- a/src/drv.c +++ b/src/drv.c @@ -42,7 +42,16 @@ struct driver_state { IMG_HANDLE global_eventobject; PVRSRV_HEAP_INFO kernel_heap; + PVRSRV_HEAP_INFO perctx_3d_heap; + PVRSRV_HEAP_INFO ta_data_heap; PVRSRV_BRIDGE_OUT_ALLOCDEVICEMEM ccb_buffer; + PVRSRV_BRIDGE_OUT_ALLOCDEVICEMEM kernel_buffer_2; + PVRSRV_BRIDGE_OUT_ALLOCDEVICEMEM kernel_buffer_3; + PVRSRV_BRIDGE_OUT_ALLOCDEVICEMEM perctx_3d_buffer; + PVRSRV_BRIDGE_OUT_ALLOCDEVICEMEM ta_data_buffer; + + IMG_HANDLE hw_render_ctx; + IMG_DEV_VIRTADDR hw_render_ctx_addr; }; static void check_pvr_error(PVRSRV_ERROR error) { @@ -271,9 +280,19 @@ static void get_dev_mem_heapinfo(struct driver_state *state) { if (out.sHeapInfo[i].ui32HeapID == HEAP_ID( PVRSRV_DEVICE_TYPE_SGX, SGX_KERNEL_DATA_HEAP_ID)) { state->kernel_heap = out.sHeapInfo[i]; } + + if (out.sHeapInfo[i].ui32HeapID == HEAP_ID( PVRSRV_DEVICE_TYPE_SGX, SGX_TADATA_HEAP_ID)) { + state->ta_data_heap = out.sHeapInfo[i]; + } + + if (out.sHeapInfo[i].ui32HeapID == HEAP_ID( PVRSRV_DEVICE_TYPE_SGX, SGX_PERCONTEXT_3DPARAMETERS_HEAP_ID)) { + state->perctx_3d_heap = out.sHeapInfo[i]; + } } assert(state->kernel_heap.ui32HeapID != 0); + assert(state->ta_data_heap.ui32HeapID != 0); + assert(state->perctx_3d_heap.ui32HeapID != 0); } static PVRSRV_BRIDGE_OUT_ALLOCDEVICEMEM allocate_memobj(struct driver_state *state, PVRSRV_BRIDGE_IN_ALLOCDEVICEMEM *alloc) { @@ -281,8 +300,8 @@ static PVRSRV_BRIDGE_OUT_ALLOCDEVICEMEM allocate_memobj(struct driver_state *sta PVRSRV_BRIDGE_PACKAGE data = { .ui32BridgeID = PVRSRV_BRIDGE_ALLOC_DEVICEMEM, .ui32Size = sizeof(data), - .pvParamIn = &alloc, - .ui32InBufferSize = sizeof(alloc), + .pvParamIn = alloc, + .ui32InBufferSize = sizeof(*alloc), .pvParamOut = &out, .ui32OutBufferSize = sizeof(out), .hKernelServices = state->kernel_services @@ -303,8 +322,92 @@ static void allocate_memory(struct driver_state *state) { .uSize = 0x86a4, .uAlignment = 0x1000, }; - state->ccb_buffer = allocate_memobj(state, &alloc_CCB); + + PVRSRV_BRIDGE_IN_ALLOCDEVICEMEM alloc_kernel_buffer_2 = { + .hDevCookie = state->dev_cookie, + .hDevMemHeap = state->kernel_heap.hDevMemHeap, + .ui32Attribs = PVRSRV_MEM_READ | PVRSRV_MEM_WRITE | PVRSRV_MEM_CACHE_CONSISTENT | PVRSRV_MEM_NO_SYNCOBJ | PVRSRV_MEM_EDM_PROTECT, + .uSize = 0x8, + .uAlignment = 0x20, + }; + state->kernel_buffer_2 = allocate_memobj(state, &alloc_kernel_buffer_2); + + PVRSRV_BRIDGE_IN_ALLOCDEVICEMEM alloc_kernel_buffer_3 = { + .hDevCookie = state->dev_cookie, + .hDevMemHeap = state->kernel_heap.hDevMemHeap, + .ui32Attribs = PVRSRV_MEM_READ | PVRSRV_MEM_WRITE | PVRSRV_MEM_CACHE_CONSISTENT | PVRSRV_MEM_NO_SYNCOBJ, + .uSize = 0x44, + .uAlignment = 0x20, + }; + state->kernel_buffer_3 = allocate_memobj(state, &alloc_kernel_buffer_3); + + PVRSRV_BRIDGE_IN_ALLOCDEVICEMEM alloc_perctx_3d_buffer = { + .hDevCookie = state->dev_cookie, + .hDevMemHeap = state->perctx_3d_heap.hDevMemHeap, + .ui32Attribs = PVRSRV_MEM_READ | PVRSRV_MEM_WRITE | PVRSRV_MEM_NO_SYNCOBJ, + .uSize = 0x40, + .uAlignment = 0x40, + }; + state->perctx_3d_buffer = allocate_memobj(state, &alloc_perctx_3d_buffer); + + PVRSRV_BRIDGE_IN_ALLOCDEVICEMEM alloc_ta_data_buffer = { + .hDevCookie = state->dev_cookie, + .hDevMemHeap = state->ta_data_heap.hDevMemHeap, + .ui32Attribs = PVRSRV_MEM_READ | PVRSRV_MEM_WRITE | PVRSRV_MEM_NO_SYNCOBJ, + .uSize = 0xc0, + .uAlignment = 0x40, + }; + state->ta_data_buffer = allocate_memobj(state, &alloc_ta_data_buffer); +} + +static void register_hw_render_ctx(struct driver_state *state) { + /* Data copied directly from dump on hw + * Not sure what other params mean, but the buffer + * ones are obvious once you start offsetting buffer addresses + */ + uint32_t render_ctx[] = { + 0x21, + 0x1, + 0x0, + state->ccb_buffer.sClientMemInfo.sDevVAddr.uiAddr, + state->kernel_buffer_2.sClientMemInfo.sDevVAddr.uiAddr, + 0x0, + state->kernel_buffer_3.sClientMemInfo.sDevVAddr.uiAddr, + state->perctx_3d_buffer.sClientMemInfo.sDevVAddr.uiAddr, + state->ta_data_buffer.sClientMemInfo.sDevVAddr.uiAddr, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x50f, + }; + PVRSRV_BRIDGE_IN_SGX_REGISTER_HW_RENDER_CONTEXT in = { + .hDevCookie = state->dev_cookie, + .pHWRenderContextCpuVAddr = render_ctx, + .ui32HWRenderContextSize = sizeof(render_ctx), + .hDevMemContext = state->dev_mem_context, + }; + PVRSRV_BRIDGE_OUT_SGX_REGISTER_HW_RENDER_CONTEXT out; + PVRSRV_BRIDGE_PACKAGE data = { + .ui32BridgeID = PVRSRV_BRIDGE_SGX_REGISTER_HW_RENDER_CONTEXT, + .ui32Size = sizeof(data), + .pvParamIn = &in, + .ui32InBufferSize = sizeof(in), + .pvParamOut = &out, + .ui32OutBufferSize = sizeof(out), + .hKernelServices = state->kernel_services + }; + + check_ioctl(state->fd, DRM_IOCTL_PVR_SRVKM, &data); + check_pvr_error(out.eError); + + state->hw_render_ctx = out.hHWRenderContext; + state->hw_render_ctx_addr = out.sHWRenderContextDevVAddr; } int main(int argc, char *argv[]) { @@ -337,6 +440,7 @@ int main(int argc, char *argv[]) { open_eventobject(&state); get_dev_mem_heapinfo(&state); allocate_memory(&state); + register_hw_render_ctx(&state); close(state.fd); -- cgit