|
26 | 26 | #include <media/videobuf2-vmalloc.h> |
27 | 27 |
|
28 | 28 | #include "mmal-common.h" |
| 29 | +#include "mmal-parameters.h" |
29 | 30 | #include "mmal-vchiq.h" |
30 | 31 | #include "mmal-msg.h" |
31 | 32 |
|
| 33 | +#include "vc-sm-cma/vc_sm_knl.h" |
| 34 | + |
32 | 35 | #define USE_VCHIQ_ARM |
33 | 36 | #include "interface/vchi/vchi.h" |
34 | 37 |
|
@@ -424,8 +427,13 @@ buffer_from_host(struct vchiq_mmal_instance *instance, |
424 | 427 |
|
425 | 428 | /* buffer header */ |
426 | 429 | m.u.buffer_from_host.buffer_header.cmd = 0; |
427 | | - m.u.buffer_from_host.buffer_header.data = |
428 | | - (u32)(unsigned long)buf->buffer; |
| 430 | + if (port->zero_copy) { |
| 431 | + m.u.buffer_from_host.buffer_header.data = buf->vc_handle; |
| 432 | + } else { |
| 433 | + m.u.buffer_from_host.buffer_header.data = |
| 434 | + (u32)(unsigned long)buf->buffer; |
| 435 | + } |
| 436 | + |
429 | 437 | m.u.buffer_from_host.buffer_header.alloc_size = buf->buffer_size; |
430 | 438 | if (port->type == MMAL_PORT_TYPE_OUTPUT) { |
431 | 439 | m.u.buffer_from_host.buffer_header.length = 0; |
@@ -590,6 +598,22 @@ static void buffer_to_host_cb(struct vchiq_mmal_instance *instance, |
590 | 598 |
|
591 | 599 | msg_context->u.bulk.status = msg->h.status; |
592 | 600 |
|
| 601 | + } else if (msg->u.buffer_from_host.is_zero_copy) { |
| 602 | + /* |
| 603 | + * Zero copy buffer, so nothing to do. |
| 604 | + * Copy buffer info and make callback. |
| 605 | + */ |
| 606 | + msg_context->u.bulk.buffer_used = |
| 607 | + msg->u.buffer_from_host.buffer_header.length; |
| 608 | + msg_context->u.bulk.mmal_flags = |
| 609 | + msg->u.buffer_from_host.buffer_header.flags; |
| 610 | + msg_context->u.bulk.dts = |
| 611 | + msg->u.buffer_from_host.buffer_header.dts; |
| 612 | + msg_context->u.bulk.pts = |
| 613 | + msg->u.buffer_from_host.buffer_header.pts; |
| 614 | + msg_context->u.bulk.cmd = |
| 615 | + msg->u.buffer_from_host.buffer_header.cmd; |
| 616 | + |
593 | 617 | } else if (msg->u.buffer_from_host.buffer_header.length == 0) { |
594 | 618 | /* empty buffer */ |
595 | 619 | if (msg->u.buffer_from_host.buffer_header.flags & |
@@ -1537,6 +1561,9 @@ int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance, |
1537 | 1561 |
|
1538 | 1562 | mutex_unlock(&instance->vchiq_mutex); |
1539 | 1563 |
|
| 1564 | + if (parameter == MMAL_PARAMETER_ZERO_COPY && !ret) |
| 1565 | + port->zero_copy = !!(*(bool *)value); |
| 1566 | + |
1540 | 1567 | return ret; |
1541 | 1568 | } |
1542 | 1569 | EXPORT_SYMBOL_GPL(vchiq_mmal_port_parameter_set); |
@@ -1705,6 +1732,31 @@ int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance, |
1705 | 1732 | unsigned long flags = 0; |
1706 | 1733 | int ret; |
1707 | 1734 |
|
| 1735 | + /* |
| 1736 | + * We really want to do this in mmal_vchi_buffer_init but can't as |
| 1737 | + * videobuf2 won't let us have the dmabuf there. |
| 1738 | + */ |
| 1739 | + if (port->zero_copy && buffer->dma_buf && !buffer->vcsm_handle) { |
| 1740 | + pr_debug("%s: import dmabuf %p\n", __func__, buffer->dma_buf); |
| 1741 | + ret = vc_sm_cma_import_dmabuf(buffer->dma_buf, |
| 1742 | + &buffer->vcsm_handle); |
| 1743 | + if (ret) { |
| 1744 | + pr_err("%s: vc_sm_import_dmabuf_fd failed, ret %d\n", |
| 1745 | + __func__, ret); |
| 1746 | + return ret; |
| 1747 | + } |
| 1748 | + |
| 1749 | + buffer->vc_handle = vc_sm_cma_int_handle(buffer->vcsm_handle); |
| 1750 | + if (!buffer->vc_handle) { |
| 1751 | + pr_err("%s: vc_sm_int_handle failed %d\n", |
| 1752 | + __func__, ret); |
| 1753 | + vc_sm_cma_free(buffer->vcsm_handle); |
| 1754 | + return ret; |
| 1755 | + } |
| 1756 | + pr_debug("%s: import dmabuf %p - got vc handle %08X\n", |
| 1757 | + __func__, buffer->dma_buf, buffer->vc_handle); |
| 1758 | + } |
| 1759 | + |
1708 | 1760 | ret = buffer_from_host(instance, port, buffer); |
1709 | 1761 | if (ret == -EINVAL) { |
1710 | 1762 | /* Port is disabled. Queue for when it is enabled. */ |
@@ -1738,6 +1790,16 @@ int mmal_vchi_buffer_cleanup(struct mmal_buffer *buf) |
1738 | 1790 | release_msg_context(msg_context); |
1739 | 1791 | buf->msg_context = NULL; |
1740 | 1792 |
|
| 1793 | + if (buf->vcsm_handle) { |
| 1794 | + int ret; |
| 1795 | + |
| 1796 | + pr_debug("%s: vc_sm_cma_free on handle %p\n", __func__, |
| 1797 | + buf->vcsm_handle); |
| 1798 | + ret = vc_sm_cma_free(buf->vcsm_handle); |
| 1799 | + if (ret) |
| 1800 | + pr_err("%s: vcsm_free failed, ret %d\n", __func__, ret); |
| 1801 | + buf->vcsm_handle = 0; |
| 1802 | + } |
1741 | 1803 | return 0; |
1742 | 1804 | } |
1743 | 1805 | EXPORT_SYMBOL_GPL(mmal_vchi_buffer_cleanup); |
|
0 commit comments