1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. 4 */ 5 6 #ifndef __IRIS_BUFFER_H__ 7 #define __IRIS_BUFFER_H__ 8 9 #include <media/videobuf2-v4l2.h> 10 11 struct iris_inst; 12 13 #define to_iris_buffer(ptr) container_of(ptr, struct iris_buffer, vb2) 14 15 /** 16 * enum iris_buffer_type 17 * 18 * @BUF_INPUT: input buffer to the iris hardware 19 * @BUF_OUTPUT: output buffer from the iris hardware 20 * @BUF_BIN: buffer to store intermediate bin data 21 * @BUF_ARP: buffer for auto register programming 22 * @BUF_COMV: buffer to store colocated motion vectors 23 * @BUF_NON_COMV: buffer to hold config data for HW 24 * @BUF_LINE: buffer to store decoding/encoding context data for HW 25 * @BUF_DPB: buffer to store display picture buffers for reference 26 * @BUF_PERSIST: buffer to store session context data 27 * @BUF_SCRATCH_1: buffer to store decoding/encoding context data for HW 28 * @BUF_SCRATCH_2: buffer to store encoding context data for HW 29 * @BUF_VPSS: buffer to store VPSS context data for HW 30 * @BUF_PARTIAL: buffer for AV1 IBC data 31 * @BUF_TYPE_MAX: max buffer types 32 */ 33 enum iris_buffer_type { 34 BUF_INPUT = 1, 35 BUF_OUTPUT, 36 BUF_BIN, 37 BUF_ARP, 38 BUF_COMV, 39 BUF_NON_COMV, 40 BUF_LINE, 41 BUF_DPB, 42 BUF_PERSIST, 43 BUF_SCRATCH_1, 44 BUF_SCRATCH_2, 45 BUF_VPSS, 46 BUF_PARTIAL, 47 BUF_TYPE_MAX, 48 }; 49 50 /* 51 * enum iris_buffer_attributes 52 * 53 * BUF_ATTR_DEFERRED: buffer queued by client but not submitted to firmware. 54 * BUF_ATTR_PENDING_RELEASE: buffers requested to be released from firmware. 55 * BUF_ATTR_QUEUED: buffers submitted to firmware. 56 * BUF_ATTR_DEQUEUED: buffers received from firmware. 57 * BUF_ATTR_BUFFER_DONE: buffers sent back to vb2. 58 */ 59 enum iris_buffer_attributes { 60 BUF_ATTR_DEFERRED = BIT(0), 61 BUF_ATTR_PENDING_RELEASE = BIT(1), 62 BUF_ATTR_QUEUED = BIT(2), 63 BUF_ATTR_DEQUEUED = BIT(3), 64 BUF_ATTR_BUFFER_DONE = BIT(4), 65 }; 66 67 /** 68 * struct iris_buffer 69 * 70 * @vb2: v4l2 vb2 buffer 71 * @list: list head for the iris_buffers structure 72 * @inst: iris instance structure 73 * @type: enum for type of iris buffer 74 * @index: identifier for the iris buffer 75 * @fd: file descriptor of the buffer 76 * @buffer_size: accessible buffer size in bytes starting from addr_offset 77 * @data_offset: accessible buffer offset from base address 78 * @data_size: data size in bytes 79 * @device_addr: device address of the buffer 80 * @kvaddr: kernel virtual address of the buffer 81 * @dma_attrs: dma attributes 82 * @flags: buffer flags. It is represented as bit masks. 83 * @timestamp: timestamp of the buffer in nano seconds (ns) 84 * @attr: enum for iris buffer attributes 85 */ 86 struct iris_buffer { 87 struct vb2_v4l2_buffer vb2; 88 struct list_head list; 89 struct iris_inst *inst; 90 enum iris_buffer_type type; 91 u32 index; 92 int fd; 93 size_t buffer_size; 94 u32 data_offset; 95 size_t data_size; 96 dma_addr_t device_addr; 97 void *kvaddr; 98 unsigned long dma_attrs; 99 u32 flags; /* V4L2_BUF_FLAG_* */ 100 u64 timestamp; 101 enum iris_buffer_attributes attr; 102 }; 103 104 struct iris_buffers { 105 struct list_head list; 106 u32 min_count; 107 u32 size; 108 }; 109 110 int iris_get_buffer_size(struct iris_inst *inst, enum iris_buffer_type buffer_type); 111 void iris_get_internal_buffers(struct iris_inst *inst, u32 plane); 112 int iris_create_internal_buffers(struct iris_inst *inst, u32 plane); 113 int iris_queue_internal_buffers(struct iris_inst *inst, u32 plane); 114 int iris_queue_internal_deferred_buffers(struct iris_inst *inst, enum iris_buffer_type buffer_type); 115 int iris_destroy_internal_buffer(struct iris_inst *inst, struct iris_buffer *buffer); 116 int iris_destroy_all_internal_buffers(struct iris_inst *inst, u32 plane); 117 int iris_destroy_dequeued_internal_buffers(struct iris_inst *inst, u32 plane); 118 int iris_alloc_and_queue_persist_bufs(struct iris_inst *inst, enum iris_buffer_type buf_type); 119 int iris_alloc_and_queue_input_int_bufs(struct iris_inst *inst); 120 int iris_queue_buffer(struct iris_inst *inst, struct iris_buffer *buf); 121 int iris_queue_deferred_buffers(struct iris_inst *inst, enum iris_buffer_type buf_type); 122 int iris_vb2_buffer_done(struct iris_inst *inst, struct iris_buffer *buf); 123 void iris_vb2_queue_error(struct iris_inst *inst); 124 125 #endif 126