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