xref: /aosp_15_r20/external/mesa3d/src/amd/vpelib/src/chip/vpe11/vpe11_vpe_desc_writer.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /* Copyright 2024 Advanced Micro Devices, Inc.
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a
4  * copy of this software and associated documentation files (the "Software"),
5  * to deal in the Software without restriction, including without limitation
6  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7  * and/or sell copies of the Software, and to permit persons to whom the
8  * Software is furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
16  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
17  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
18  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
19  * OTHER DEALINGS IN THE SOFTWARE.
20  *
21  * Authors: AMD
22  *
23  */
24 
25 #include "vpe_assert.h"
26 #include "common.h"
27 #include "reg_helper.h"
28 #include "vpe10_vpe_desc_writer.h"
29 #include "vpe11_vpe_desc_writer.h"
30 #include "vpe11_command.h"
31 
vpe11_construct_vpe_desc_writer(struct vpe_desc_writer * writer)32 void vpe11_construct_vpe_desc_writer(struct vpe_desc_writer *writer)
33 {
34     writer->init            = vpe11_vpe_desc_writer_init;
35     writer->add_plane_desc  = vpe10_vpe_desc_writer_add_plane_desc;
36     writer->add_config_desc = vpe10_vpe_desc_writer_add_config_desc;
37     writer->complete        = vpe10_vpe_desc_writer_complete;
38 }
39 
vpe11_vpe_desc_writer_init(struct vpe_desc_writer * writer,struct vpe_buf * buf,int cd)40 enum vpe_status vpe11_vpe_desc_writer_init(
41     struct vpe_desc_writer *writer, struct vpe_buf *buf, int cd)
42 {
43     uint32_t *cmd_space;
44     uint64_t  size = sizeof(uint32_t);
45 
46     writer->base_cpu_va      = buf->cpu_va;
47     writer->base_gpu_va      = buf->gpu_va;
48     writer->buf              = buf;
49     writer->num_config_desc  = 0;
50     writer->plane_desc_added = false;
51     writer->status           = VPE_STATUS_OK;
52 
53     if (buf->size < size) {
54         writer->status = VPE_STATUS_BUFFER_OVERFLOW;
55         return writer->status;
56     }
57 
58     if (writer->status == VPE_STATUS_OK) {
59         cmd_space = (uint32_t *)(uintptr_t)writer->buf->cpu_va;
60         *cmd_space++ = VPE_DESC_CMD_HEADER(cd);
61 
62         writer->buf->cpu_va += size;
63         writer->buf->gpu_va += size;
64         writer->buf->size -= size;
65     }
66 
67     return writer->status;
68 }
69 
70