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