diff options
Diffstat (limited to 'src/psb_buffer_dm.c')
-rw-r--r-- | src/psb_buffer_dm.c | 207 |
1 files changed, 29 insertions, 178 deletions
diff --git a/src/psb_buffer_dm.c b/src/psb_buffer_dm.c index ec06dda..a433fe1 100644 --- a/src/psb_buffer_dm.c +++ b/src/psb_buffer_dm.c @@ -8,11 +8,11 @@ * distribute, sub license, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: - * + * * The above copyright notice and this permission notice (including the * next paragraph) shall be included in all copies or substantial portions * of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. @@ -33,7 +33,6 @@ #include <stdlib.h> #include <unistd.h> #include <wsbm/wsbm_manager.h> -/* #include <linux/rar_register.h> */ #include "psb_drm.h" #include "psb_def.h" @@ -180,7 +179,7 @@ VAStatus psb_buffer_create_camera_from_ub(psb_driver_data_p driver_data, buf->rar_handle = 0; buf->buffer_ofs = 0; buf->type = psb_bt_user_buffer; - buf->user_ptr = (void *)user_ptr; + buf->user_ptr = (unsigned char *)user_ptr; buf->driver_data = driver_data; allignment = 4096; @@ -202,7 +201,7 @@ VAStatus psb_buffer_create_camera_from_ub(psb_driver_data_p driver_data, #ifndef ANDROID extern int wsbmBODataUB(struct _WsbmBufferObject * buf, - unsigned size, const void * data, + unsigned size, const unsigned char * data, struct _WsbmBufferPool * newPool, uint32_t placement, const unsigned long * user_ptr); /* here use the placement when gen buffer setted */ @@ -224,7 +223,6 @@ VAStatus psb_buffer_create_camera_from_ub(psb_driver_data_p driver_data, return VA_STATUS_SUCCESS; } - static int psb_buffer_info_rar(psb_driver_data_p driver_data) { struct drm_lnc_video_getparam_arg arg; @@ -240,6 +238,7 @@ static int psb_buffer_info_rar(psb_driver_data_p driver_data) if (ret == 0) { driver_data->rar_phyaddr = rar_info[0]; driver_data->rar_size = rar_info[1]; + driver_data->rar_size = driver_data->rar_size & 0xfffff000; /* page align */ psb__information_message("RAR region physical address = 0x%08x, size=%dK\n", driver_data->rar_phyaddr, driver_data->rar_size / 1024); @@ -251,62 +250,20 @@ static int psb_buffer_info_rar(psb_driver_data_p driver_data) } -static int psb_buffer_offset_rar(psb_driver_data_p driver_data, - psb_buffer_p buf, - uint32_t rar_handle, - unsigned int *bo_offset - ) +static VAStatus psb_buffer_init_imr(psb_driver_data_p driver_data) { - struct drm_lnc_video_getparam_arg arg; - unsigned long offset; int ret = 0; - *bo_offset = 0; - - arg.key = LNC_VIDEO_GETPARAM_RAR_HANDLER_OFFSET; - arg.arg = (uint64_t)((unsigned long) & rar_handle); - arg.value = (uint64_t)((unsigned long) & offset); - ret = drmCommandWriteRead(driver_data->drm_fd, driver_data->getParamIoctlOffset, - &arg, sizeof(arg)); - if (ret == 0) { - *bo_offset = offset; - - return ret; - } - - psb__information_message("RAR buffer 0x%08x, get offset failed\n", rar_handle); - return ret; -} - - -static VAStatus psb_buffer_init_rar(psb_driver_data_p driver_data) -{ - int ret = 0; - RAR_desc_t *rar_rd; - - /* hasn't grab RAR device memory region - * grab the whole 8M RAR device memory + /* hasn't grab IMR device memory region + * grab the whole IMR3 device memory */ driver_data->rar_bo = calloc(1, sizeof(struct psb_buffer_s)); if (driver_data->rar_bo == NULL) goto exit_error; - driver_data->rar_rd = calloc(1, sizeof(RAR_desc_t)); - if (driver_data->rar_rd == NULL) - goto exit_error; - - memset(driver_data->rar_rd, 0, sizeof(RAR_desc_t)); - - psb__information_message("Init RAR device\n"); - - ret = RAR_init(driver_data->rar_rd); - if (ret != 0) { - psb__error_message("RAR device init failed\n"); - goto exit_error; - } - + psb__information_message("Init IMR device\n"); if (psb_buffer_info_rar(driver_data)) { - psb__error_message("Get RAR region size failed\n"); + psb__error_message("Get IMR region size failed\n"); goto exit_error; } @@ -314,169 +271,63 @@ static VAStatus psb_buffer_init_rar(psb_driver_data_p driver_data) ret = psb_buffer_create(driver_data, driver_data->rar_size, psb_bt_rar, (psb_buffer_p) driver_data->rar_bo); if (ret != VA_STATUS_SUCCESS) { - psb__error_message("Grab RAR device memory failed\n"); + psb__error_message("Grab IMR device memory failed\n"); goto exit_error; } return VA_STATUS_SUCCESS; exit_error: - rar_rd = driver_data->rar_rd; - - if (rar_rd) { - if (rar_rd->mrfd) - RAR_fini(driver_data->rar_rd); - free(rar_rd); - } - if (driver_data->rar_bo) free(driver_data->rar_bo); driver_data->rar_bo = NULL; - driver_data->rar_rd = NULL; return VA_STATUS_ERROR_ALLOCATION_FAILED; } - /* - * Create RAR buffer - * Only used when create a protected surface + * Reference one IMR buffer from offset + * only used to reference a slice IMR buffer which is created outside of video driver */ -VAStatus psb_buffer_create_rar(psb_driver_data_p driver_data, - unsigned int size, - psb_buffer_p buf - ) -{ - VAStatus vaStatus; - uint32_t rar_handle = 0; - unsigned int rar_offset = 0; - RAR_desc_t *rar_rd; - int ret; - - if (driver_data->rar_rd == NULL) { - vaStatus = psb_buffer_init_rar(driver_data); - if (vaStatus != VA_STATUS_SUCCESS) { - psb__error_message("RAR init failed!\n"); - return vaStatus; - } - } - - rar_rd = driver_data->rar_rd; - - /* Call RAR interface to allocate RAR buffers */ - ret = RAR_reserve(rar_rd, size, RAR_TYPE_VIDEO, &rar_handle); - if (ret != 0) { - psb__error_message("RAR reserver memory failed\n"); - RAR_fini(rar_rd); - - return VA_STATUS_ERROR_UNKNOWN; - } - - ret = psb_buffer_offset_rar(driver_data, buf, rar_handle, &rar_offset); - if (ret != 0) { - psb__error_message("Get buffer offset of RAR device memory failed!\n"); - return ret; - } - - /* reference the global RAR BO */ - ret = psb_buffer_reference(driver_data, buf, (psb_buffer_p) driver_data->rar_bo); - if (ret != VA_STATUS_SUCCESS) { - psb__error_message("Reference RAR device memory failed\n"); - return ret; - } - - buf->rar_handle = rar_handle; - buf->buffer_ofs = rar_offset; - - /* reference the global RAR buffer, reset buffer type */ - buf->type = psb_bt_rar_surface; /* need RAR_release */ - - psb__information_message("Create RAR buffer, handle 0x%08x, RAR region offset =0x%08x, RAR BO GPU offset hint=0x%08x\n", - rar_handle, rar_offset, wsbmBOOffsetHint(buf->drm_buf)); - - return VA_STATUS_SUCCESS; -} - - -/* - * Destroy RAR buffer - */ -VAStatus psb_buffer_destroy_rar(psb_driver_data_p driver_data, - psb_buffer_p buf - ) -{ - RAR_desc_t *rar_rd; - int ret; - - ASSERT(driver_data->rar_rd); - - if (buf->type == psb_bt_rar_slice) { - psb__information_message("return RAR slice buffer to application\n"); - buf->rar_handle = 0; - return VA_STATUS_SUCCESS; - } - - - rar_rd = driver_data->rar_rd; - - ret = RAR_release(rar_rd, buf->rar_handle); - if (ret != 0) - psb__error_message("RAR release memory failed\n"); - - buf->rar_handle = 0; - - return VA_STATUS_SUCCESS; -} - -/* - * Reference one RAR buffer from handle - * only used to reference a slice RAR buffer which is created outside of video driver - */ -VAStatus psb_buffer_reference_rar(psb_driver_data_p driver_data, - uint32_t rar_handle, +VAStatus psb_buffer_reference_imr(psb_driver_data_p driver_data, + uint32_t imr_offset, psb_buffer_p buf ) { VAStatus vaStatus; - unsigned int rar_offset = 0; int ret; - if (driver_data->rar_rd == NULL) { - vaStatus = psb_buffer_init_rar(driver_data); + if (driver_data->rar_bo == NULL) { + vaStatus = psb_buffer_init_imr(driver_data); if (vaStatus != VA_STATUS_SUCCESS) { - psb__error_message("RAR init failed!\n"); + psb__error_message("IMR init failed!\n"); return vaStatus; } } - /* don't need to assign the handle to buffer + /* don't need to assign the offset to buffer * so that when destroy the buffer, we just * need to unreference */ - /* buf->rar_handle = rar_handle; */ + /* buf->imr_offset = imr_offset; */ - ret = psb_buffer_offset_rar(driver_data, buf, rar_handle, &rar_offset); - if (ret != VA_STATUS_SUCCESS) { - psb__error_message("Get surfae offset of RAR device memory failed!\n"); - return ret; - } - - /* reference the global RAR BO */ + /* reference the global IMR BO */ ret = psb_buffer_reference(driver_data, buf, (psb_buffer_p) driver_data->rar_bo); if (ret != VA_STATUS_SUCCESS) { - psb__error_message("Reference RAR device memory failed\n"); + psb__error_message("Reference IMR device memory failed\n"); return ret; } - buf->rar_handle = rar_handle; - buf->buffer_ofs = rar_offset; - /* reference the global RAR buffer, reset buffer type */ - buf->type = psb_bt_rar_slice; /* don't need to RAR_release */ + buf->rar_handle = imr_offset; + buf->buffer_ofs = imr_offset; + + /* reference the global IMR buffer, reset buffer type */ + buf->type = psb_bt_rar_slice; /* don't need to IMR_release */ - psb__information_message("Reference RAR buffer, handle 0x%08x, RAR region offset =0x%08x, RAR BO GPU offset hint=0x%08x\n", - rar_handle, rar_offset, wsbmBOOffsetHint(buf->drm_buf)); + psb__information_message("Reference IMR buffer, IMR region offset =0x%08x, IMR BO GPU offset hint=0x%08x\n", + imr_offset, wsbmBOOffsetHint(buf->drm_buf)); return VA_STATUS_SUCCESS; } |