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_TYPE_MAX: max buffer types 31 */ 32 enum iris_buffer_type { 33 BUF_INPUT = 1, 34 BUF_OUTPUT, 35 BUF_BIN, 36 BUF_ARP, 37 BUF_COMV, 38 BUF_NON_COMV, 39 BUF_LINE, 40 BUF_DPB, 41 BUF_PERSIST, 42 BUF_SCRATCH_1, 43 BUF_SCRATCH_2, 44 BUF_VPSS, 45 BUF_PARTIAL, 46 BUF_TYPE_MAX, 47 }; 48 49 /* 50 * enum iris_buffer_attributes 51 * 52 * BUF_ATTR_DEFERRED: buffer queued by client but not submitted to firmware. 53 * BUF_ATTR_PENDING_RELEASE: buffers requested to be released from firmware. 54 * BUF_ATTR_QUEUED: buffers submitted to firmware. 55 * BUF_ATTR_DEQUEUED: buffers received from firmware. 56 * BUF_ATTR_BUFFER_DONE: buffers sent back to vb2. 57 */ 58 enum iris_buffer_attributes { 59 BUF_ATTR_DEFERRED = BIT(0), 60 BUF_ATTR_PENDING_RELEASE = BIT(1), 61 BUF_ATTR_QUEUED = BIT(2), 62 BUF_ATTR_DEQUEUED = BIT(3), 63 BUF_ATTR_BUFFER_DONE = BIT(4), 64 }; 65 66 /** 67 * struct iris_buffer 68 * 69 * @vb2: v4l2 vb2 buffer 70 * @list: list head for the iris_buffers structure 71 * @inst: iris instance structure 72 * @type: enum for type of iris buffer 73 * @index: identifier for the iris buffer 74 * @fd: file descriptor of the buffer 75 * @buffer_size: accessible buffer size in bytes starting from addr_offset 76 * @data_offset: accessible buffer offset from base address 77 * @data_size: data size in bytes 78 * @device_addr: device address of the buffer 79 * @kvaddr: kernel virtual address of the buffer 80 * @dma_attrs: dma attributes 81 * @flags: buffer flags. It is represented as bit masks. 82 * @timestamp: timestamp of the buffer in nano seconds (ns) 83 * @attr: enum for iris buffer attributes 84 */ 85 struct iris_buffer { 86 struct vb2_v4l2_buffer vb2; 87 struct list_head list; 88 struct iris_inst *inst; 89 enum iris_buffer_type type; 90 u32 index; 91 int fd; 92 size_t buffer_size; 93 u32 data_offset; 94 size_t data_size; 95 dma_addr_t device_addr; 96 void *kvaddr; 97 unsigned long dma_attrs; 98 u32 flags; /* V4L2_BUF_FLAG_* */ 99 u64 timestamp; 100 enum iris_buffer_attributes attr; 101 }; 102 103 struct iris_buffers { 104 struct list_head list; 105 u32 min_count; 106 u32 size; 107 }; 108 109 int iris_get_buffer_size(struct iris_inst *inst, enum iris_buffer_type buffer_type); 110 void iris_get_internal_buffers(struct iris_inst *inst, u32 plane); 111 int iris_create_internal_buffers(struct iris_inst *inst, u32 plane); 112 int iris_queue_internal_buffers(struct iris_inst *inst, u32 plane); 113 int iris_queue_internal_deferred_buffers(struct iris_inst *inst, enum iris_buffer_type buffer_type); 114 int iris_destroy_internal_buffer(struct iris_inst *inst, struct iris_buffer *buffer); 115 int iris_destroy_all_internal_buffers(struct iris_inst *inst, u32 plane); 116 int iris_destroy_dequeued_internal_buffers(struct iris_inst *inst, u32 plane); 117 int iris_alloc_and_queue_persist_bufs(struct iris_inst *inst, enum iris_buffer_type buf_type); 118 int iris_alloc_and_queue_input_int_bufs(struct iris_inst *inst); 119 int iris_queue_buffer(struct iris_inst *inst, struct iris_buffer *buf); 120 int iris_queue_deferred_buffers(struct iris_inst *inst, enum iris_buffer_type buf_type); 121 int iris_vb2_buffer_done(struct iris_inst *inst, struct iris_buffer *buf); 122 void iris_vb2_queue_error(struct iris_inst *inst); 123 124 #endif 125