1 /*
2 * Copyright (c) 2007-2024 Broadcom. All Rights Reserved.
3 * The term “Broadcom” refers to Broadcom Inc.
4 * and/or its subsidiaries.
5 * SPDX-License-Identifier: GPL-2.0 OR MIT
6 */
7
8 /*
9 * svga_overlay.h --
10 *
11 * Definitions for video-overlay support.
12 */
13
14 #ifndef _SVGA_OVERLAY_H_
15 #define _SVGA_OVERLAY_H_
16
17 #include "svga_reg.h"
18
19 /*
20 * Video formats we support
21 */
22
23 #define VMWARE_FOURCC_YV12 0x32315659 /* 'Y' 'V' '1' '2' */
24 #define VMWARE_FOURCC_YUY2 0x32595559 /* 'Y' 'U' 'Y' '2' */
25 #define VMWARE_FOURCC_UYVY 0x59565955 /* 'U' 'Y' 'V' 'Y' */
26
27 typedef enum {
28 SVGA_OVERLAY_FORMAT_INVALID = 0,
29 SVGA_OVERLAY_FORMAT_YV12 = VMWARE_FOURCC_YV12,
30 SVGA_OVERLAY_FORMAT_YUY2 = VMWARE_FOURCC_YUY2,
31 SVGA_OVERLAY_FORMAT_UYVY = VMWARE_FOURCC_UYVY,
32 } SVGAOverlayFormat;
33
34 #define SVGA_VIDEO_COLORKEY_MASK 0x00ffffff
35
36 #define SVGA_ESCAPE_VMWARE_VIDEO 0x00020000
37
38 #define SVGA_ESCAPE_VMWARE_VIDEO_SET_REGS 0x00020001
39 /* FIFO escape layout:
40 * Type, Stream Id, (Register Id, Value) pairs */
41
42 #define SVGA_ESCAPE_VMWARE_VIDEO_FLUSH 0x00020002
43 /* FIFO escape layout:
44 * Type, Stream Id */
45
46 typedef
47 struct SVGAEscapeVideoSetRegs {
48 struct {
49 uint32 cmdType;
50 uint32 streamId;
51 } header;
52
53 /* May include zero or more items. */
54 struct {
55 uint32 registerId;
56 uint32 value;
57 } items[1];
58 } SVGAEscapeVideoSetRegs;
59
60 typedef
61 struct SVGAEscapeVideoFlush {
62 uint32 cmdType;
63 uint32 streamId;
64 } SVGAEscapeVideoFlush;
65
66
67 /*
68 * Struct definitions for the video overlay commands built on
69 * SVGAFifoCmdEscape.
70 */
71 typedef
72 struct {
73 uint32 command;
74 uint32 overlay;
75 } SVGAFifoEscapeCmdVideoBase;
76
77 typedef
78 struct {
79 SVGAFifoEscapeCmdVideoBase videoCmd;
80 } SVGAFifoEscapeCmdVideoFlush;
81
82 typedef
83 struct {
84 SVGAFifoEscapeCmdVideoBase videoCmd;
85 struct {
86 uint32 regId;
87 uint32 value;
88 } items[1];
89 } SVGAFifoEscapeCmdVideoSetRegs;
90
91 typedef
92 struct {
93 SVGAFifoEscapeCmdVideoBase videoCmd;
94 struct {
95 uint32 regId;
96 uint32 value;
97 } items[SVGA_VIDEO_NUM_REGS];
98 } SVGAFifoEscapeCmdVideoSetAllRegs;
99
100
101 /*
102 *----------------------------------------------------------------------
103 *
104 * VMwareVideoGetAttributes --
105 *
106 * Computes the size, pitches and offsets for YUV frames.
107 *
108 * Results:
109 * TRUE on success; otherwise FALSE on failure.
110 *
111 * Side effects:
112 * Pitches and offsets for the given YUV frame are put in 'pitches'
113 * and 'offsets' respectively. They are both optional though.
114 *
115 *----------------------------------------------------------------------
116 */
117
118 static inline Bool
VMwareVideoGetAttributes(const SVGAOverlayFormat format,uint32 * width,uint32 * height,uint32 * size,uint32 * pitches,uint32 * offsets)119 VMwareVideoGetAttributes(const SVGAOverlayFormat format, /* IN */
120 uint32 *width, /* IN / OUT */
121 uint32 *height, /* IN / OUT */
122 uint32 *size, /* OUT */
123 uint32 *pitches, /* OUT (optional) */
124 uint32 *offsets) /* OUT (optional) */
125 {
126 int tmp;
127
128 *width = (*width + 1) & ~1;
129
130 if (offsets) {
131 offsets[0] = 0;
132 }
133
134 switch (format) {
135 case VMWARE_FOURCC_YV12:
136 *height = (*height + 1) & ~1;
137 *size = (*width) * (*height);
138
139 if (pitches) {
140 pitches[0] = *width;
141 }
142
143 if (offsets) {
144 offsets[1] = *size;
145 }
146
147 tmp = *width >> 1;
148
149 if (pitches) {
150 pitches[1] = pitches[2] = tmp;
151 }
152
153 tmp *= (*height >> 1);
154 *size += tmp;
155
156 if (offsets) {
157 offsets[2] = *size;
158 }
159
160 *size += tmp;
161 break;
162
163 case VMWARE_FOURCC_YUY2:
164 case VMWARE_FOURCC_UYVY:
165 *size = *width * 2;
166
167 if (pitches) {
168 pitches[0] = *size;
169 }
170
171 *size *= *height;
172 break;
173
174 default:
175 return false;
176 }
177
178 return true;
179 }
180
181 #endif /* _SVGA_OVERLAY_H_ */
182