Lines Matching refs:cmdbuf
74 #define MTXMSG_END(cmdbuf) (cmdbuf->reloc_base)
75 #define RELOC_END(cmdbuf) (cmdbuf->MTX_msg + cmdbuf->reloc_size)
77 #define CMD_END(cmdbuf) (cmdbuf->lldma_base)
78 #define LLDMA_END(cmdbuf) (cmdbuf->cmd_base + cmdbuf->size)
97 psb_cmdbuf_p cmdbuf
105 cmdbuf->size = 0;
106 cmdbuf->reloc_size = 0;
107 cmdbuf->regio_size = 0;
108 cmdbuf->MTX_msg = NULL;
109 cmdbuf->cmd_base = NULL;
110 cmdbuf->regio_base = NULL;
111 cmdbuf->cmd_idx = NULL;
112 cmdbuf->regio_idx = NULL;
113 cmdbuf->cmd_bitstream_size = NULL;
114 cmdbuf->lldma_base = NULL;
115 cmdbuf->lldma_idx = NULL;
116 cmdbuf->reloc_base = NULL;
117 cmdbuf->reloc_idx = NULL;
118 cmdbuf->reg_start = NULL;
119 cmdbuf->rendec_block_start = NULL;
120 cmdbuf->rendec_chunk_start = NULL;
121 cmdbuf->skip_block_start = NULL;
122 cmdbuf->last_next_segment_cmd = NULL;
123 cmdbuf->buffer_refs_count = 0;
124 cmdbuf->buffer_refs_allocated = 10;
125 cmdbuf->buffer_refs = (psb_buffer_p *) calloc(1, sizeof(psb_buffer_p) * cmdbuf->buffer_refs_allocated);
126 if (NULL == cmdbuf->buffer_refs) {
127 cmdbuf->buffer_refs_allocated = 0;
131 vaStatus = psb_buffer_create(driver_data, size, psb_bt_cpu_vpu, &cmdbuf->buf);
132 cmdbuf->size = size;
135 vaStatus = psb_buffer_create(driver_data, reloc_size, psb_bt_cpu_only, &cmdbuf->reloc_buf);
136 cmdbuf->reloc_size = reloc_size;
139 vaStatus = psb_buffer_create(driver_data, regio_size, psb_bt_cpu_only, &cmdbuf->regio_buf);
140 cmdbuf->regio_size = regio_size;
144 psb_cmdbuf_destroy(cmdbuf);
152 void psb_cmdbuf_destroy(psb_cmdbuf_p cmdbuf)
154 if (cmdbuf->size) {
155 psb_buffer_destroy(&cmdbuf->buf);
156 cmdbuf->size = 0;
158 if (cmdbuf->reloc_size) {
159 psb_buffer_destroy(&cmdbuf->reloc_buf);
160 cmdbuf->reloc_size = 0;
162 if (cmdbuf->regio_size) {
163 psb_buffer_destroy(&cmdbuf->regio_buf);
164 cmdbuf->regio_size = 0;
166 if (cmdbuf->buffer_refs_allocated) {
167 free(cmdbuf->buffer_refs);
168 cmdbuf->buffer_refs = NULL;
169 cmdbuf->buffer_refs_allocated = 0;
178 int psb_cmdbuf_reset(psb_cmdbuf_p cmdbuf)
182 cmdbuf->MTX_msg = NULL;
183 cmdbuf->cmd_base = NULL;
184 cmdbuf->cmd_idx = NULL;
185 cmdbuf->cmd_bitstream_size = NULL;
186 cmdbuf->lldma_base = NULL;
187 cmdbuf->lldma_idx = NULL;
188 cmdbuf->reloc_base = NULL;
189 cmdbuf->reloc_idx = NULL;
190 cmdbuf->last_next_segment_cmd = NULL;
192 cmdbuf->buffer_refs_count = 0;
193 cmdbuf->cmd_count = 0;
194 cmdbuf->deblock_count = 0;
195 cmdbuf->oold_count = 0;
196 cmdbuf->host_be_opp_count = 0;
197 cmdbuf->frame_info_count = 0;
199 cmdbuf->parse_count = 0;
201 ret = psb_buffer_map(&cmdbuf->buf, &cmdbuf->cmd_base);
205 ret = psb_buffer_map(&cmdbuf->reloc_buf, &cmdbuf->MTX_msg);
207 psb_buffer_unmap(&cmdbuf->buf);
211 cmdbuf->cmd_start = cmdbuf->cmd_base;
212 cmdbuf->cmd_idx = (uint32_t *) cmdbuf->cmd_base;
213 cmdbuf->cmd_bitstream_size = NULL;
214 cmdbuf->lldma_base = cmdbuf->cmd_base + CMD_SIZE;
215 cmdbuf->lldma_idx = cmdbuf->lldma_base;
217 cmdbuf->reloc_base = cmdbuf->MTX_msg + MTXMSG_SIZE;
218 cmdbuf->reloc_idx = (struct drm_psb_reloc *) cmdbuf->reloc_base;
221 psb_cmdbuf_buffer_ref(cmdbuf, &cmdbuf->reloc_buf); /* reloc buf == 0 */
222 psb_cmdbuf_buffer_ref(cmdbuf, &cmdbuf->buf); /* cmd buf == 1 */
231 int psb_cmdbuf_unmap(psb_cmdbuf_p cmdbuf)
233 cmdbuf->MTX_msg = NULL;
234 cmdbuf->cmd_base = NULL;
235 cmdbuf->cmd_start = NULL;
236 cmdbuf->cmd_idx = NULL;
237 cmdbuf->cmd_bitstream_size = NULL;
238 cmdbuf->lldma_base = NULL;
239 cmdbuf->lldma_idx = NULL;
240 cmdbuf->reloc_base = NULL;
241 cmdbuf->reloc_idx = NULL;
242 cmdbuf->cmd_count = 0;
243 psb_buffer_unmap(&cmdbuf->buf);
244 psb_buffer_unmap(&cmdbuf->reloc_buf);
254 int psb_cmdbuf_buffer_ref(psb_cmdbuf_p cmdbuf, psb_buffer_p buf)
259 while ((item_loc < cmdbuf->buffer_refs_count)
260 && (wsbmKBufHandle(wsbmKBuf(cmdbuf->buffer_refs[item_loc]->drm_buf))
264 if (item_loc == cmdbuf->buffer_refs_count) {
266 if (item_loc >= cmdbuf->buffer_refs_allocated) {
268 int new_size = cmdbuf->buffer_refs_allocated + 10;
274 memcpy(new_array, cmdbuf->buffer_refs, sizeof(psb_buffer_p) * cmdbuf->buffer_refs_allocated);
275 free(cmdbuf->buffer_refs);
276 cmdbuf->buffer_refs_allocated = new_size;
277 cmdbuf->buffer_refs = new_array;
279 cmdbuf->buffer_refs[item_loc] = buf;
280 cmdbuf->buffer_refs_count++;
288 if ((cmdbuf->buffer_refs[item_loc] != buf)
290 psb_buffer_p tmp = cmdbuf->buffer_refs[item_loc];
312 /* Creates a relocation record for a DWORD in the mapped "cmdbuf" at address
320 void psb_cmdbuf_add_relocation(psb_cmdbuf_p cmdbuf,
327 uint32_t dst_buffer) /* 0 = reloc buf, 1 = cmdbuf, 2 = for host reloc */
329 struct drm_psb_reloc *reloc = cmdbuf->reloc_idx;
334 ASSERT(((unsigned char *)(addr_in_cmdbuf)) >= cmdbuf->cmd_base);
335 ASSERT(((unsigned char *)(addr_in_cmdbuf)) < LLDMA_END(cmdbuf));
336 reloc->where = addr_in_cmdbuf - (uint32_t *) cmdbuf->cmd_base; /* Location in DWORDs */
338 ASSERT(((unsigned char *)(addr_in_cmdbuf)) >= cmdbuf->MTX_msg);
339 ASSERT(((unsigned char *)(addr_in_cmdbuf)) < MTXMSG_END(cmdbuf));
340 reloc->where = addr_in_cmdbuf - (uint32_t *) cmdbuf->MTX_msg; /* Location in DWORDs */
343 reloc->buffer = psb_cmdbuf_buffer_ref(cmdbuf, ref_buffer);
365 cmdbuf->reloc_idx++;
367 ASSERT(((unsigned char *)(cmdbuf->reloc_idx)) < RELOC_END(cmdbuf));
371 * Advances "obj_context" to the next cmdbuf
377 psb_cmdbuf_p cmdbuf;
380 if (obj_context->cmdbuf) {
388 cmdbuf = obj_context->cmdbuf_list[obj_context->cmdbuf_current];
389 ret = psb_cmdbuf_reset(cmdbuf);
392 obj_context->cmdbuf = cmdbuf;
414 * This is the user-space do-it-all interface to the drm cmdbuf ioctl.
618 static void psb_cmdbuf_close_segment(psb_cmdbuf_p __maybe_unused cmdbuf)
621 uint32_t bytes_used = ((unsigned char *) cmdbuf->cmd_idx - cmdbuf->cmd_start) % MTX_SEG_SIZE;
622 unsigned char *segment_start = (unsigned char *) cmdbuf->cmd_idx - bytes_used;
623 uint32_t lldma_record_offset = psb_cmdbuf_lldma_create(cmdbuf,
624 &(cmdbuf->buf), (segment_start - cmdbuf->cmd_base) /* offset */,
629 RELOC_SHIFT4(*cmdbuf->last_next_segment_cmd, lldma_record_offset, cmd, &(cmdbuf->buf));
630 *(cmdbuf->last_next_segment_cmd + 1) = bytes_used;
648 psb_cmdbuf_p cmdbuf = obj_context->cmdbuf;
654 uint32_t *msg = (uint32_t *)(cmdbuf->MTX_msg + item_size * cmdbuf->cmd_count);
681 cmdbuf->deblock_count++;
698 psb_cmdbuf_p cmdbuf = obj_context->cmdbuf;
704 uint32_t *msg = (uint32_t *)(cmdbuf->MTX_msg + item_size * cmdbuf->cmd_count + cmdbuf->deblock_count * msg_size);
726 cmdbuf->deblock_count++;
731 * Submits the current cmdbuf
737 psb_cmdbuf_p cmdbuf = obj_context->cmdbuf;
743 uint32_t cmdbuffer_size = (unsigned char *) cmdbuf->cmd_idx - cmdbuf->cmd_start; // In bytes
745 if (cmdbuf->last_next_segment_cmd) {
746 cmdbuffer_size = cmdbuf->first_segment_size;
747 psb_cmdbuf_close_segment(cmdbuf);
751 uint32_t *msg = (uint32_t *)(cmdbuf->MTX_msg + cmdbuf->cmd_count * msg_size + cmdbuf->frame_info_count * FW_VA_FRAME_INFO_SIZE);
754 debug_cmd_start[cmdbuf->cmd_count] = cmdbuf->cmd_start - cmdbuf->cmd_base;
755 debug_cmd_size[cmdbuf->cmd_count] = (unsigned char *) cmdbuf->cmd_idx - cmdbuf->cmd_start;
756 debug_cmd_count = cmdbuf->cmd_count + 1;
764 sprintf(pFileName , "cmdbuf%i.txt", c++);
767 fwrite(cmdbuf->cmd_start, 1, cmdbuffer_size, pF);
770 ret = psb_cmdbuf_dump((unsigned int *)cmdbuf->cmd_start, cmdbuffer_size);
772 drv_debug_msg(VIDEO_DEBUG_GENERAL, "psb_cmdbuf: dump cmdbuf fail\n");
774 cmdbuf->cmd_count++;
777 *cmdbuf->cmd_idx = 0; // Add a trailing 0 just in case.
779 ASSERT((unsigned char *) cmdbuf->cmd_idx < CMD_END(cmdbuf));
788 (cmdbuf->cmd_start - cmdbuf->cmd_base), &(cmdbuf->buf));
794 debug_lldma_count = (cmdbuf->lldma_idx - cmdbuf->lldma_base) / sizeof(DMA_sLinkedList);
795 debug_lldma_start = cmdbuf->lldma_base - cmdbuf->cmd_base;
797 ((uint32_t *)cmdbuf->lldma_idx)[1] = 0;
800 cmdbuf->cmd_start = (unsigned char *)cmdbuf->cmd_idx;
805 if ((cmdbuf->cmd_count >= MAX_CMD_COUNT) ||
806 (MTXMSG_END(cmdbuf) - (unsigned char *) msg < MTXMSG_MARGIN) ||
807 (CMD_END(cmdbuf) - (unsigned char *) cmdbuf->cmd_idx < CMD_MARGIN) ||
808 (LLDMA_END(cmdbuf) - cmdbuf->lldma_idx < LLDMA_MARGIN) ||
809 (RELOC_END(cmdbuf) - (unsigned char *) cmdbuf->reloc_idx < RELOC_MARGIN)) {
821 psb_cmdbuf_p cmdbuf = obj_context->cmdbuf;
832 if ((NULL == cmdbuf) ||
833 (0 == (cmdbuf->cmd_count + cmdbuf->deblock_count + cmdbuf->host_be_opp_count +
834 cmdbuf->frame_info_count + cmdbuf->parse_count))) {
838 if ((NULL == cmdbuf) ||
839 (0 == (cmdbuf->cmd_count + cmdbuf->deblock_count + cmdbuf->host_be_opp_count + cmdbuf->frame_info_count))) {
845 uint32_t *msg = (uint32_t *)cmdbuf->MTX_msg;
857 for (i = 1; i <= cmdbuf->frame_info_count; i++) {
862 for (i = 1; i <= cmdbuf->cmd_count; i++) {
868 int bBatchEnd = (i == (cmdbuf->cmd_count + cmdbuf->deblock_count + cmdbuf->oold_count
869 + cmdbuf->host_be_opp_count));
897 for (i = 1; i <= cmdbuf->deblock_count; i++) {
901 for (i = 1; i <= cmdbuf->oold_count; i++) {
905 for (i = 1; i <= cmdbuf->host_be_opp_count; i++) {
909 for (i = 1; i <= cmdbuf->parse_count; i++) {
914 reloc_offset = cmdbuf->reloc_base - cmdbuf->MTX_msg;
915 num_relocs = (((unsigned char *) cmdbuf->reloc_idx) - cmdbuf->reloc_base) / sizeof(struct drm_psb_reloc);
917 drv_debug_msg(VIDEO_DEBUG_GENERAL, "Cmdbuf MTXMSG size = %08x [%08x]\n", msg_size, MTXMSG_SIZE);
918 drv_debug_msg(VIDEO_DEBUG_GENERAL, "Cmdbufcmdbuf->cmd_idx - cmdbuf->cmd_base, cmdbuf->cmd_count, CMD_SIZE);
919 drv_debug_msg(VIDEO_DEBUG_GENERAL, "Cmdbuf LLDMA size = %08x [%08x]\n", cmdbuf->lldma_idx - cmdbuf->lldma_base, LLDMA_SIZE);
920 drv_debug_msg(VIDEO_DEBUG_GENERAL, "Cmdbuf RELOC size = %08x [%08x]\n", num_relocs * sizeof(struct drm_psb_reloc), RELOC_SIZE);
922 psb_cmdbuf_unmap(cmdbuf);
926 ASSERT(NULL == cmdbuf->MTX_msg);
927 ASSERT(NULL == cmdbuf->reloc_base);
938 /* cmdbuf will be validated as part of the buffer list */
941 ret = psbDRMCmdBuf(driver_data->drm_fd, driver_data->execIoctlOffset, cmdbuf->buffer_refs,
942 cmdbuf->buffer_refs_count,
943 wsbmKBufHandle(wsbmKBuf(cmdbuf->reloc_buf.drm_buf)),
945 wsbmKBufHandle(wsbmKBuf(cmdbuf->reloc_buf.drm_buf)),
952 obj_context->cmdbuf = NULL;
968 psb_buffer_map(&cmdbuf->buf, &cmdbuf->cmd_base);
970 ret = psb_buffer_map(&cmdbuf->reloc_buf, &cmdbuf->MTX_msg);
972 psb_buffer_unmap(&cmdbuf->buf);
978 debug_lldma_count, wsbmBOOffsetHint(cmdbuf->buf.drm_buf) + CMD_SIZE);
980 DMA_sLinkedList* pasDmaList = (DMA_sLinkedList*)(cmdbuf->cmd_base + debug_lldma_start);
983 psb__trace_message("\nLLDMA record at offset %08x\n", ((unsigned char*)pasDmaList) - cmdbuf->cmd_base);
1025 debug_cmd_count, wsbmBOOffsetHint(cmdbuf->buf.drm_buf));
1027 uint32_t *msg = (uint32_t *)(cmdbuf->MTX_msg + index * item_size);
1030 debug_dump_cmdbuf((uint32_t *)(cmdbuf->cmd_base + debug_cmd_start[index]), debug_cmd_size[index]);
1067 psb_buffer_unmap(&cmdbuf->buf);
1068 psb_buffer_unmap(&cmdbuf->reloc_buf);
1070 cmdbuf->cmd_base = NULL;
1083 obj_context->cmdbuf = NULL;
1239 void *psb_cmdbuf_alloc_space(psb_cmdbuf_p cmdbuf, uint32_t byte_size)
1241 void *pos = (void *)cmdbuf->cmd_idx;
1244 cmdbuf->cmd_idx += (byte_size / 4);
1249 void psb_cmdbuf_dma_write_cmdbuf(psb_cmdbuf_p cmdbuf,
1263 dma_cmd = (DMA_CMD_WITH_OFFSET*)psb_cmdbuf_alloc_space(cmdbuf, sizeof(DMA_CMD));
1268 dma_cmd = (DMA_CMD_WITH_OFFSET*)psb_cmdbuf_alloc_space(cmdbuf, sizeof(DMA_CMD_WITH_OFFSET));
1283 void psb_cmdbuf_dma_write_bitstream(psb_cmdbuf_p cmdbuf,
1308 *cmdbuf->cmd_idx++ = CMD_SR_SETUP | flags;
1309 *cmdbuf->cmd_idx++ = offset_in_bits;
1310 cmdbuf->cmd_bitstream_size = cmdbuf->cmd_idx;
1311 *cmdbuf->cmd_idx++ = size_in_bytes;
1312 *cmdbuf->cmd_idx++ = (CMD_BITSTREAM_DMA | size_in_bytes);
1313 RELOC(*cmdbuf->cmd_idx++, buffer_offset, bitstream_buf);
1320 void psb_cmdbuf_dma_write_key(psb_cmdbuf_p cmdbuf,
1325 *cmdbuf->cmd_idx++ = CMD_SR_SETUP | flags;
1326 *cmdbuf->cmd_idx++ = key;
1333 void psb_cmdbuf_dma_write_bitstream_chained(psb_cmdbuf_p cmdbuf,
1337 *cmdbuf->cmd_idx++ = (CMD_BITSTREAM_DMA | size_in_bytes);
1338 RELOC(*cmdbuf->cmd_idx++, bitstream_buf->buffer_ofs, bitstream_buf);
1340 *(cmdbuf->cmd_bitstream_size) += size_in_bytes;
1343 void psb_cmdbuf_reg_start_block(psb_cmdbuf_p cmdbuf, uint32_t flags)
1345 ASSERT(NULL == cmdbuf->reg_start); /* Can't have both */
1347 cmdbuf->reg_wt_p = cmdbuf->cmd_idx;
1348 cmdbuf->reg_next = 0;
1349 cmdbuf->reg_flags = (flags << 4); /* flags are diff between DE2 & DE3 */
1350 cmdbuf->reg_start = NULL;
1353 void psb_cmdbuf_reg_set(psb_cmdbuf_p cmdbuf, uint32_t reg, uint32_t val)
1355 if(cmdbuf->reg_start && (reg == cmdbuf->reg_next))
1358 *cmdbuf->reg_start += (0x1 << 16);
1362 cmdbuf->reg_start = cmdbuf->reg_wt_p++;
1363 *cmdbuf->reg_start = CMD_REGVALPAIR_WRITE | cmdbuf->reg_flags | 0x10000 | (reg & 0xfffff); /* We want host reg addr */
1365 *cmdbuf->reg_wt_p++ = val;
1366 cmdbuf->reg_next = reg + 4;
1369 void psb_cmdbuf_reg_set_address(psb_cmdbuf_p cmdbuf,
1374 if(cmdbuf->reg_start && (reg == cmdbuf->reg_next))
1377 *cmdbuf->reg_start += (0x1 << 16);
1381 cmdbuf->reg_start = cmdbuf->reg_wt_p++;
1382 *cmdbuf->reg_start = CMD_REGVALPAIR_WRITE | cmdbuf->reg_flags | 0x10000 | (reg & 0xfffff); /* We want host reg addr */
1385 RELOC(*cmdbuf->reg_wt_p++, buffer_offset, buffer);
1386 cmdbuf->reg_next = reg + 4;
1389 void psb_cmdbuf_reg_end_block(psb_cmdbuf_p cmdbuf)
1391 cmdbuf->cmd_idx = cmdbuf->reg_wt_p;
1392 cmdbuf->reg_start = NULL;
1405 void psb_cmdbuf_rendec_start(psb_cmdbuf_p cmdbuf, uint32_t dest_address)
1408 cmdbuf->rendec_chunk_start = cmdbuf->cmd_idx++;
1409 *cmdbuf->rendec_chunk_start = CMD_RENDEC_BLOCK | dest_address;
1412 void psb_cmdbuf_rendec_write_block(psb_cmdbuf_p cmdbuf,
1420 psb_cmdbuf_rendec_write(cmdbuf, val);
1424 void psb_cmdbuf_rendec_write_address(psb_cmdbuf_p cmdbuf,
1428 RELOC(*cmdbuf->cmd_idx++, buffer_offset, buffer);
1434 void psb_cmdbuf_rendec_end(psb_cmdbuf_p cmdbuf)
1436 ASSERT(NULL != cmdbuf->rendec_chunk_start); /* Must have an open RENDEC chunk */
1437 uint32_t dword_count = cmdbuf->cmd_idx - cmdbuf->rendec_chunk_start;
1441 *cmdbuf->rendec_chunk_start += ((dword_count - 1) << 16);
1442 cmdbuf->rendec_chunk_start = NULL;
1448 void psb_cmdbuf_skip_start_block(psb_cmdbuf_p cmdbuf, uint32_t skip_condition)
1450 ASSERT(NULL == cmdbuf->rendec_block_start); /* Can't be inside a rendec block */
1451 ASSERT(NULL == cmdbuf->reg_start); /* Can't be inside a reg block */
1452 ASSERT(NULL == cmdbuf->skip_block_start); /* Can't be inside another skip block (limitation of current sw design)*/
1454 cmdbuf->skip_condition = skip_condition;
1455 cmdbuf->skip_block_start = cmdbuf->cmd_idx++;
1461 void psb_cmdbuf_skip_end_block(psb_cmdbuf_p cmdbuf)
1463 ASSERT(NULL == cmdbuf->rendec_block_start); /* Rendec block must be closed */
1464 ASSERT(NULL == cmdbuf->reg_start); /* Reg block must be closed */
1465 ASSERT(NULL != cmdbuf->skip_block_start); /* Skip block must still be open */
1467 uint32_t block_size = cmdbuf->cmd_idx - (cmdbuf->skip_block_start + 1);
1469 *cmdbuf->skip_block_start = CMD_CONDITIONAL_SKIP | (cmdbuf->skip_condition << 20) | block_size;
1470 cmdbuf->skip_block_start = NULL;