1 /* 2 * Copyright © 2018 NVIDIA Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 */ 22 23 #ifndef VIC_H 24 #define VIC_H 25 26 #include <stdio.h> 27 28 #include "host1x.h" 29 30 #define DXVAHD_FRAME_FORMAT_PROGRESSIVE 0 31 #define DXVAHD_FRAME_FORMAT_INTERLACED_TOP_FIELD_FIRST 1 32 #define DXVAHD_FRAME_FORMAT_INTERLACED_BOTTOM_FIELD_FIRST 2 33 #define DXVAHD_FRAME_FORMAT_TOP_FIELD 3 34 #define DXVAHD_FRAME_FORMAT_BOTTOM_FIELD 4 35 #define DXVAHD_FRAME_FORMAT_SUBPIC_PROGRESSIVE 5 36 #define DXVAHD_FRAME_FORMAT_SUBPIC_INTERLACED_TOP_FIELD_FIRST 6 37 #define DXVAHD_FRAME_FORMAT_SUBPIC_INTERLACED_BOTTOM_FIELD_FIRST 7 38 #define DXVAHD_FRAME_FORMAT_SUBPIC_TOP_FIELD 8 39 #define DXVAHD_FRAME_FORMAT_SUBPIC_BOTTOM_FIELD 9 40 #define DXVAHD_FRAME_FORMAT_TOP_FIELD_CHROMA_BOTTOM 10 41 #define DXVAHD_FRAME_FORMAT_BOTTOM_FIELD_CHROMA_TOP 11 42 #define DXVAHD_FRAME_FORMAT_SUBPIC_TOP_FIELD_CHROMA_BOTTOM 12 43 #define DXVAHD_FRAME_FORMAT_SUBPIC_BOTTOM_FIELD_CHROMA_TOP 13 44 45 #define DXVAHD_ALPHA_FILL_MODE_OPAQUE 0 46 #define DXVAHD_ALPHA_FILL_MODE_BACKGROUND 1 47 #define DXVAHD_ALPHA_FILL_MODE_DESTINATION 2 48 #define DXVAHD_ALPHA_FILL_MODE_SOURCE_STREAM 3 49 #define DXVAHD_ALPHA_FILL_MODE_COMPOSITED 4 50 #define DXVAHD_ALPHA_FILL_MODE_SOURCE_ALPHA 5 51 52 #define VIC_BLEND_SRCFACTC_K1 0 53 #define VIC_BLEND_SRCFACTC_K1_TIMES_DST 1 54 #define VIC_BLEND_SRCFACTC_NEG_K1_TIMES_DST 2 55 #define VIC_BLEND_SRCFACTC_K1_TIMES_SRC 3 56 #define VIC_BLEND_SRCFACTC_ZERO 4 57 58 #define VIC_BLEND_DSTFACTC_K1 0 59 #define VIC_BLEND_DSTFACTC_K2 1 60 #define VIC_BLEND_DSTFACTC_K1_TIMES_DST 2 61 #define VIC_BLEND_DSTFACTC_NEG_K1_TIMES_DST 3 62 #define VIC_BLEND_DSTFACTC_NEG_K1_TIMES_SRC 4 63 #define VIC_BLEND_DSTFACTC_ZERO 5 64 #define VIC_BLEND_DSTFACTC_ONE 6 65 66 #define VIC_BLEND_SRCFACTA_K1 0 67 #define VIC_BLEND_SRCFACTA_K2 1 68 #define VIC_BLEND_SRCFACTA_NEG_K1_TIMES_DST 2 69 #define VIC_BLEND_SRCFACTA_ZERO 3 70 71 #define VIC_BLEND_DSTFACTA_K2 0 72 #define VIC_BLEND_DSTFACTA_NEG_K1_TIMES_SRC 1 73 #define VIC_BLEND_DSTFACTA_ZERO 2 74 #define VIC_BLEND_DSTFACTA_ONE 3 75 76 #define VIC_BLK_KIND_PITCH 0 77 #define VIC_BLK_KIND_GENERIC_16Bx2 1 78 79 #define VIC_PIXEL_FORMAT_L8 1 80 #define VIC_PIXEL_FORMAT_R8 4 81 #define VIC_PIXEL_FORMAT_A8R8G8B8 32 82 #define VIC_PIXEL_FORMAT_R8G8B8A8 34 83 #define VIC_PIXEL_FORMAT_Y8_U8V8_N420 67 84 #define VIC_PIXEL_FORMAT_Y8_V8U8_N420 68 85 86 #define VIC_CACHE_WIDTH_16Bx16 0 /* BL16Bx2 */ 87 #define VIC_CACHE_WIDTH_32Bx8 1 /* BL16Bx2 */ 88 #define VIC_CACHE_WIDTH_64Bx4 2 /* BL16Bx2, PL */ 89 #define VIC_CACHE_WIDTH_128Bx2 3 /* BL16Bx2, PL */ 90 #define VIC_CACHE_WIDTH_256Bx1 4 /* PL */ 91 92 struct vic_format_info { 93 unsigned int format; 94 unsigned int cpp; 95 }; 96 97 98 #define VIC_UCLASS_INCR_SYNCPT 0x00 99 #define VIC_UCLASS_METHOD_OFFSET 0x10 100 #define VIC_UCLASS_METHOD_DATA 0x11 101 102 static inline void VIC_PUSH_METHOD(struct drm_tegra_pushbuf *pushbuf, 103 uint32_t **ptrp, uint32_t method, 104 uint32_t value) 105 { 106 *(*ptrp)++ = HOST1X_OPCODE_INCR(VIC_UCLASS_METHOD_OFFSET, 2); 107 *(*ptrp)++ = method >> 2; 108 *(*ptrp)++ = value; 109 } 110 111 static inline void VIC_PUSH_BUFFER(struct drm_tegra_pushbuf *pushbuf, 112 uint32_t **ptrp, uint32_t method, 113 struct drm_tegra_mapping *map, 114 unsigned long offset, unsigned long flags) 115 { 116 *(*ptrp)++ = HOST1X_OPCODE_INCR(VIC_UCLASS_METHOD_OFFSET, 2); 117 *(*ptrp)++ = method >> 2; 118 119 drm_tegra_pushbuf_relocate(pushbuf, ptrp, map, offset, 8, flags); 120 } 121 122 struct vic_image; 123 struct vic; 124 125 struct vic_ops { 126 int (*fill)(struct vic *vic, struct vic_image *output, 127 unsigned int left, unsigned int top, 128 unsigned int right, unsigned int bottom, 129 unsigned int alpha, unsigned red, 130 unsigned int green, unsigned int blue); 131 int (*blit)(struct vic *vic, struct vic_image *output, 132 struct vic_image *input); 133 int (*flip)(struct vic *vic, struct vic_image *output, 134 struct vic_image *input); 135 int (*execute)(struct vic *vic, 136 struct drm_tegra_pushbuf *pushbuf, 137 uint32_t **ptrp, 138 struct vic_image *output, 139 struct vic_image **inputs, 140 unsigned int num_inputs); 141 void (*free)(struct vic *vic); 142 }; 143 144 struct vic { 145 struct drm_tegra *drm; 146 struct drm_tegra_channel *channel; 147 struct drm_tegra_syncpoint *syncpt; 148 const struct vic_ops *ops; 149 unsigned int version; 150 }; 151 152 int vic_new(struct drm_tegra *drm, struct drm_tegra_channel *channel, 153 struct vic **vicp); 154 void vic_free(struct vic *vic); 155 156 int vic_clear(struct vic *vic, struct vic_image *output, unsigned int alpha, 157 unsigned int red, unsigned int green, unsigned int blue); 158 159 struct vic_image { 160 struct drm_tegra_bo *bo; 161 struct drm_tegra_mapping *map; 162 unsigned int width; 163 unsigned int stride; 164 unsigned int pitch; 165 unsigned int height; 166 unsigned int format; 167 unsigned int kind; 168 169 size_t align; 170 size_t size; 171 }; 172 173 const struct vic_format_info *vic_format_get_info(unsigned int format); 174 175 int vic_image_new(struct vic *vic, unsigned int width, unsigned int height, 176 unsigned int format, unsigned int kind, uint32_t flags, 177 struct vic_image **imagep); 178 void vic_image_free(struct vic_image *image); 179 void vic_image_dump(struct vic_image *image, FILE *fp); 180 181 #endif 182