|
27 | 27 | #include <media/videobuf2-vmalloc.h> |
28 | 28 |
|
29 | 29 | #include "mmal-common.h" |
| 30 | +#include "mmal-parameters.h" |
30 | 31 | #include "mmal-vchiq.h" |
31 | 32 | #include "mmal-msg.h" |
32 | 33 |
|
| 34 | +#include "vc-sm-cma/vc_sm_knl.h" |
33 | 35 | /* |
34 | 36 | * maximum number of components supported. |
35 | 37 | * This matches the maximum permitted by default on the VPU |
@@ -419,8 +421,13 @@ buffer_from_host(struct vchiq_mmal_instance *instance, |
419 | 421 |
|
420 | 422 | /* buffer header */ |
421 | 423 | m.u.buffer_from_host.buffer_header.cmd = 0; |
422 | | - m.u.buffer_from_host.buffer_header.data = |
423 | | - (u32)(unsigned long)buf->buffer; |
| 424 | + if (port->zero_copy) { |
| 425 | + m.u.buffer_from_host.buffer_header.data = buf->vc_handle; |
| 426 | + } else { |
| 427 | + m.u.buffer_from_host.buffer_header.data = |
| 428 | + (u32)(unsigned long)buf->buffer; |
| 429 | + } |
| 430 | + |
424 | 431 | m.u.buffer_from_host.buffer_header.alloc_size = buf->buffer_size; |
425 | 432 | if (port->type == MMAL_PORT_TYPE_OUTPUT) { |
426 | 433 | m.u.buffer_from_host.buffer_header.length = 0; |
@@ -586,6 +593,22 @@ static void buffer_to_host_cb(struct vchiq_mmal_instance *instance, |
586 | 593 |
|
587 | 594 | msg_context->u.bulk.status = msg->h.status; |
588 | 595 |
|
| 596 | + } else if (msg->u.buffer_from_host.is_zero_copy) { |
| 597 | + /* |
| 598 | + * Zero copy buffer, so nothing to do. |
| 599 | + * Copy buffer info and make callback. |
| 600 | + */ |
| 601 | + msg_context->u.bulk.buffer_used = |
| 602 | + msg->u.buffer_from_host.buffer_header.length; |
| 603 | + msg_context->u.bulk.mmal_flags = |
| 604 | + msg->u.buffer_from_host.buffer_header.flags; |
| 605 | + msg_context->u.bulk.dts = |
| 606 | + msg->u.buffer_from_host.buffer_header.dts; |
| 607 | + msg_context->u.bulk.pts = |
| 608 | + msg->u.buffer_from_host.buffer_header.pts; |
| 609 | + msg_context->u.bulk.cmd = |
| 610 | + msg->u.buffer_from_host.buffer_header.cmd; |
| 611 | + |
589 | 612 | } else if (msg->u.buffer_from_host.buffer_header.length == 0) { |
590 | 613 | /* empty buffer */ |
591 | 614 | if (msg->u.buffer_from_host.buffer_header.flags & |
@@ -1530,6 +1553,9 @@ int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance, |
1530 | 1553 |
|
1531 | 1554 | mutex_unlock(&instance->vchiq_mutex); |
1532 | 1555 |
|
| 1556 | + if (parameter == MMAL_PARAMETER_ZERO_COPY && !ret) |
| 1557 | + port->zero_copy = !!(*(bool *)value); |
| 1558 | + |
1533 | 1559 | return ret; |
1534 | 1560 | } |
1535 | 1561 | EXPORT_SYMBOL_GPL(vchiq_mmal_port_parameter_set); |
@@ -1698,6 +1724,31 @@ int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance, |
1698 | 1724 | unsigned long flags = 0; |
1699 | 1725 | int ret; |
1700 | 1726 |
|
| 1727 | + /* |
| 1728 | + * We really want to do this in mmal_vchi_buffer_init but can't as |
| 1729 | + * videobuf2 won't let us have the dmabuf there. |
| 1730 | + */ |
| 1731 | + if (port->zero_copy && buffer->dma_buf && !buffer->vcsm_handle) { |
| 1732 | + pr_debug("%s: import dmabuf %p\n", __func__, buffer->dma_buf); |
| 1733 | + ret = vc_sm_cma_import_dmabuf(buffer->dma_buf, |
| 1734 | + &buffer->vcsm_handle); |
| 1735 | + if (ret) { |
| 1736 | + pr_err("%s: vc_sm_import_dmabuf_fd failed, ret %d\n", |
| 1737 | + __func__, ret); |
| 1738 | + return ret; |
| 1739 | + } |
| 1740 | + |
| 1741 | + buffer->vc_handle = vc_sm_cma_int_handle(buffer->vcsm_handle); |
| 1742 | + if (!buffer->vc_handle) { |
| 1743 | + pr_err("%s: vc_sm_int_handle failed %d\n", |
| 1744 | + __func__, ret); |
| 1745 | + vc_sm_cma_free(buffer->vcsm_handle); |
| 1746 | + return ret; |
| 1747 | + } |
| 1748 | + pr_debug("%s: import dmabuf %p - got vc handle %08X\n", |
| 1749 | + __func__, buffer->dma_buf, buffer->vc_handle); |
| 1750 | + } |
| 1751 | + |
1701 | 1752 | ret = buffer_from_host(instance, port, buffer); |
1702 | 1753 | if (ret == -EINVAL) { |
1703 | 1754 | /* Port is disabled. Queue for when it is enabled. */ |
@@ -1731,6 +1782,16 @@ int mmal_vchi_buffer_cleanup(struct mmal_buffer *buf) |
1731 | 1782 | release_msg_context(msg_context); |
1732 | 1783 | buf->msg_context = NULL; |
1733 | 1784 |
|
| 1785 | + if (buf->vcsm_handle) { |
| 1786 | + int ret; |
| 1787 | + |
| 1788 | + pr_debug("%s: vc_sm_cma_free on handle %p\n", __func__, |
| 1789 | + buf->vcsm_handle); |
| 1790 | + ret = vc_sm_cma_free(buf->vcsm_handle); |
| 1791 | + if (ret) |
| 1792 | + pr_err("%s: vcsm_free failed, ret %d\n", __func__, ret); |
| 1793 | + buf->vcsm_handle = 0; |
| 1794 | + } |
1734 | 1795 | return 0; |
1735 | 1796 | } |
1736 | 1797 | EXPORT_SYMBOL_GPL(mmal_vchi_buffer_cleanup); |
|
0 commit comments