1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 3/* 4 * Xilinx mpeg2 transport stream muxer ioctl calls 5 * 6 * Copyright (C) 2019 Xilinx, Inc. 7 * 8 * Author: Venkateshwar Rao G <venkateshwar.rao.gannava@xilinx.com> 9 */ 10 11#ifndef __XLNX_MPG2TSMUX_INTERFACE_H__ 12#define __XLNX_MPG2TSMUX_INTERFACE_H__ 13 14#include <linux/ioctl.h> 15 16/** 17 * enum ts_mux_command - command for stream context 18 * @CREATE_TS_MISC: create misc 19 * @CREATE_TS_VIDEO_KEYFRAME: create video key frame 20 * @CREATE_TS_VIDEO_NON_KEYFRAME: create non key frame 21 * @CREATE_TS_AUDIO: create audio 22 * @WRITE_PAT: write pat 23 * @WRITE_PMT: write pmt 24 * @WRITE_SI: write si 25 * @INVALID: invalid 26 */ 27enum ts_mux_command { 28 CREATE_TS_MISC = 0, 29 CREATE_TS_VIDEO_KEYFRAME, 30 CREATE_TS_VIDEO_NON_KEYFRAME, 31 CREATE_TS_AUDIO, 32 WRITE_PAT, 33 WRITE_PMT, 34 WRITE_SI, 35 INVALID 36}; 37 38/** 39 * struct stream_context_in - struct to enqueue a stream context descriptor 40 * @command: stream context type 41 * @stream_id: stream identification number 42 * @extended_stream_id: extended stream id 43 * @is_pcr_stream: flag for pcr stream 44 * @is_valid_pts: flag for valid pts 45 * @is_valid_dts: flag for valid dts 46 * @is_dmabuf: flag to set if external src buffer is DMA allocated 47 * @pid: packet id number 48 * @size_data_in: size in bytes of input buffer 49 * @pts: presentation time stamp 50 * @dts: display time stamp 51 * @srcbuf_id: source buffer id after mmap 52 * @insert_pcr: flag for inserting pcr in stream context 53 * @pcr_extension: pcr extension number 54 * @pcr_base: pcr base number 55 */ 56struct stream_context_in { 57 enum ts_mux_command command; 58 u8 stream_id; 59 u8 extended_stream_id; 60 bool is_pcr_stream; 61 bool is_valid_pts; 62 bool is_valid_dts; 63 bool is_dmabuf; 64 u16 pid; 65 u64 size_data_in; 66 u64 pts; 67 u64 dts; 68 u32 srcbuf_id; 69 bool insert_pcr; 70 u16 pcr_extension; 71 u64 pcr_base; 72}; 73 74/** 75 * struct mux_context_in - struct to enqueue a mux context descriptor 76 * @is_dmabuf: flag to set if external src buffer is DMA allocated 77 * @dstbuf_id: destination buffer id after mmap 78 * @dmabuf_size: size in bytes of output buffer 79 */ 80struct muxer_context_in { 81 bool is_dmabuf; 82 u32 dstbuf_id; 83 u32 dmabuf_size; 84}; 85 86/** 87 * enum xlnx_tsmux_status - ip status 88 * @MPG2MUX_BUSY: device busy 89 * @MPG2MUX_READY: device ready 90 * @MPG2MUX_ERROR: error state 91 */ 92enum xlnx_tsmux_status { 93 MPG2MUX_BUSY = 0, 94 MPG2MUX_READY, 95 MPG2MUX_ERROR 96}; 97 98/** 99 * struct strc_bufs_info - struct to specify bufs requirement 100 * @num_buf: number of buffers 101 * @buf_size: size of each buffer 102 */ 103struct strc_bufs_info { 104 u32 num_buf; 105 u32 buf_size; 106}; 107 108/** 109 * struct strc_out_buf - struct to get output buffer info 110 * @buf_id: buf id into which output is written 111 * @buf_write: output bytes written in buf 112 */ 113struct out_buffer { 114 u32 buf_id; 115 u32 buf_write; 116}; 117 118/** 119 * enum strmtbl_cnxt - streamid table operation 120 * @NO_UPDATE: no table update 121 * @ADD_TO_TBL: add the entry to table 122 * @DEL_FR_TBL: delete the entry from table 123 */ 124enum strmtbl_cnxt { 125 NO_UPDATE = 0, 126 ADD_TO_TBL, 127 DEL_FR_TBL, 128}; 129 130/** 131 * struct strm_tbl_info - struct to enqueue/dequeue streamid in table 132 * @strmtbl_ctxt: enqueue/dequeue stream id 133 * @pid: stream id 134 */ 135struct strc_strminfo { 136 enum strmtbl_cnxt strmtbl_ctxt; 137 u16 pid; 138}; 139 140/** 141 * enum xlnx_tsmux_dma_dir - dma direction 142 * @DMA_TO_MPG2MUX: memory to device 143 * @DMA_FROM_MPG2MUX: device to memory 144 */ 145enum xlnx_tsmux_dma_dir { 146 DMA_TO_MPG2MUX = 1, 147 DMA_FROM_MPG2MUX, 148}; 149 150/** 151 * enum xlnx_tsmux_dmabuf_flags - dma buffer handling 152 * @DMABUF_ERROR: buffer error 153 * @DMABUF_CONTIG: contig buffer 154 * @DMABUF_NON_CONTIG: non contigs buffer 155 * @DMABUF_ATTACHED: buffer attached 156 */ 157enum xlnx_tsmux_dmabuf_flags { 158 DMABUF_ERROR = 1, 159 DMABUF_CONTIG = 2, 160 DMABUF_NON_CONTIG = 4, 161 DMABUF_ATTACHED = 8, 162}; 163 164/** 165 * struct xlnx_tsmux_dmabuf_info - struct to verify dma buf before enque 166 * @buf_fd: file descriptor 167 * @dir: direction of the dma buffer 168 * @flags: flags returned by the driver 169 */ 170struct xlnx_tsmux_dmabuf_info { 171 int buf_fd; 172 enum xlnx_tsmux_dma_dir dir; 173 enum xlnx_tsmux_dmabuf_flags flags; 174}; 175 176/* MPG2MUX IOCTL CALL LIST */ 177 178#define MPG2MUX_MAGIC 'M' 179 180/** 181 * MPG2MUX_INBUFALLOC - src buffer allocation 182 */ 183#define MPG2MUX_INBUFALLOC _IOWR(MPG2MUX_MAGIC, 1, struct strc_bufs_info *) 184 185/** 186 * MPG2MUX_INBUFDEALLOC - deallocates the all src buffers 187 */ 188#define MPG2MUX_INBUFDEALLOC _IO(MPG2MUX_MAGIC, 2) 189 190/** 191 * MPG2MUX_OUTBUFALLOC - allocates DMA able memory for dst 192 */ 193#define MPG2MUX_OUTBUFALLOC _IOWR(MPG2MUX_MAGIC, 3, struct strc_bufs_info *) 194 195/** 196 * MPG2MUX_OUTBUFDEALLOC - deallocates the all dst buffers allocated 197 */ 198#define MPG2MUX_OUTBUFDEALLOC _IO(MPG2MUX_MAGIC, 4) 199 200/** 201 * MPG2MUX_STBLALLOC - allocates DMA able memory for streamid table 202 */ 203#define MPG2MUX_STBLALLOC _IOW(MPG2MUX_MAGIC, 5, unsigned short *) 204 205/** 206 * MPG2MUX_STBLDEALLOC - deallocates streamid table memory 207 */ 208#define MPG2MUX_STBLDEALLOC _IO(MPG2MUX_MAGIC, 6) 209 210/** 211 * MPG2MUX_TBLUPDATE - enqueue or dequeue in streamid table 212 */ 213#define MPG2MUX_TBLUPDATE _IOW(MPG2MUX_MAGIC, 7, struct strc_strminfo *) 214 215/** 216 * MPG2MUX_SETSTRM - enqueue a stream descriptor in stream context 217 * linked list along with src buf address 218 */ 219#define MPG2MUX_SETSTRM _IOW(MPG2MUX_MAGIC, 8, struct stream_context_in *) 220 221/** 222 * MPG2MUX_START - starts muxer IP after configuring stream 223 * and mux context registers 224 */ 225#define MPG2MUX_START _IO(MPG2MUX_MAGIC, 9) 226 227/** 228 * MPG2MUX_STOP - stops the muxer IP 229 */ 230#define MPG2MUX_STOP _IO(MPG2MUX_MAGIC, 10) 231 232/** 233 * MPG2MUX_STATUS - command to get the status of IP 234 */ 235#define MPG2MUX_STATUS _IOR(MPG2MUX_MAGIC, 11, unsigned short *) 236 237/** 238 * MPG2MUX_GETOUTBUF - get the output buffer id with size of output data 239 */ 240#define MPG2MUX_GETOUTBUF _IOW(MPG2MUX_MAGIC, 12, struct out_buffer *) 241 242/** 243 * MPG2MUX_SETMUX - enqueue a mux descriptor with dst buf address 244 */ 245#define MPG2MUX_SETMUX _IOW(MPG2MUX_MAGIC, 13, struct muxer_context_in *) 246 247/** 248 * MPG2MUX_VRFY_DMABUF - status of a given dma buffer fd 249 */ 250#define MPG2MUX_VDBUF _IOWR(MPG2MUX_MAGIC, 14, struct xlnx_tsmux_dmabuf_info *) 251 252#endif 253