xref: /openbsd-src/sys/dev/pci/drm/apple/parser.h (revision 5dd0baa8251145fcf503b060e3a9291086883454)
1 // SPDX-License-Identifier: GPL-2.0-only OR MIT
2 /* Copyright 2021 Alyssa Rosenzweig <alyssa@rosenzweig.io> */
3 
4 #ifndef __APPLE_DCP_PARSER_H__
5 #define __APPLE_DCP_PARSER_H__
6 
7 /* For mode parsing */
8 #include <drm/drm_modes.h>
9 
10 struct apple_dcp;
11 
12 struct dcp_parse_ctx {
13 	struct apple_dcp *dcp;
14 	const void *blob;
15 	u32 pos, len;
16 };
17 
18 enum dcp_color_eotf {
19 	DCP_EOTF_SDR_GAMMA = 0, // "SDR gamma"
20 	DCP_EOTF_HDR_GAMMA = 1, // "HDR gamma"
21 	DCP_EOTF_ST_2084   = 2, // "ST 2084 (PQ)"
22 	DCP_EOTF_BT_2100   = 3, // "BT.2100 (HLG)"
23 	DCP_EOTF_COUNT
24 };
25 
26 enum dcp_color_format {
27 	DCP_COLOR_FORMAT_RGB                 =  0, // "RGB"
28 	DCP_COLOR_FORMAT_YCBCR420            =  1, // "YUV 4:2:0"
29 	DCP_COLOR_FORMAT_YCBCR422            =  3, // "YUV 4:2:2"
30 	DCP_COLOR_FORMAT_YCBCR444            =  2, // "YUV 4:4:4"
31 	DCP_COLOR_FORMAT_DV_NATIVE           =  4, // "DolbyVision (native)"
32 	DCP_COLOR_FORMAT_DV_HDMI             =  5, // "DolbyVision (HDMI)"
33 	DCP_COLOR_FORMAT_YCBCR422_DP         =  6, // "YCbCr 4:2:2 (DP tunnel)"
34 	DCP_COLOR_FORMAT_YCBCR422_HDMI       =  7, // "YCbCr 4:2:2 (HDMI tunnel)"
35 	DCP_COLOR_FORMAT_DV_LL_YCBCR422      =  8, // "DolbyVision LL YCbCr 4:2:2"
36 	DCP_COLOR_FORMAT_DV_LL_YCBCR422_DP   =  9, // "DolbyVision LL YCbCr 4:2:2 (DP)"
37 	DCP_COLOR_FORMAT_DV_LL_YCBCR422_HDMI = 10, // "DolbyVision LL YCbCr 4:2:2 (HDMI)"
38 	DCP_COLOR_FORMAT_DV_LL_YCBCR444      = 11, // "DolbyVision LL YCbCr 4:4:4"
39 	DCP_COLOR_FORMAT_DV_LL_RGB422        = 12, // "DolbyVision LL RGB 4:2:2"
40 	DCP_COLOR_FORMAT_GRGB_BLUE_422       = 13, // "GRGB as YCbCr422 (Even line blue)"
41 	DCP_COLOR_FORMAT_GRGB_RED_422        = 14, // "GRGB as YCbCr422 (Even line red)"
42 	DCP_COLOR_FORMAT_COUNT
43 };
44 
45 enum dcp_colorimetry {
46 	DCP_COLORIMETRY_BT601              =  0, // "SMPTE 170M/BT.601"
47 	DCP_COLORIMETRY_BT709              =  1, // "BT.701"
48 	DCP_COLORIMETRY_XVYCC_601          =  2, // "xvYCC601"
49 	DCP_COLORIMETRY_XVYCC_709          =  3, // "xvYCC709"
50 	DCP_COLORIMETRY_SYCC_601           =  4, // "sYCC601"
51 	DCP_COLORIMETRY_ADOBE_YCC_601      =  5, // "AdobeYCC601"
52 	DCP_COLORIMETRY_BT2020_CYCC        =  6, // "BT.2020 (c)"
53 	DCP_COLORIMETRY_BT2020_YCC         =  7, // "BT.2020 (nc)"
54 	DCP_COLORIMETRY_VSVDB              =  8, // "DolbyVision VSVDB"
55 	DCP_COLORIMETRY_BT2020_RGB         =  9, // "BT.2020 (RGB)"
56 	DCP_COLORIMETRY_SRGB               = 10, // "sRGB"
57 	DCP_COLORIMETRY_SCRGB              = 11, // "scRGB"
58 	DCP_COLORIMETRY_SCRGB_FIXED        = 12, // "scRGBfixed"
59 	DCP_COLORIMETRY_ADOBE_RGB          = 13, // "AdobeRGB"
60 	DCP_COLORIMETRY_DCI_P3_RGB_D65     = 14, // "DCI-P3 (D65)"
61 	DCP_COLORIMETRY_DCI_P3_RGB_THEATER = 15, // "DCI-P3 (Theater)"
62 	DCP_COLORIMETRY_RGB                = 16, // "Default RGB"
63 	DCP_COLORIMETRY_COUNT
64 };
65 
66 enum dcp_color_range {
67 	DCP_COLOR_YCBCR_RANGE_FULL    = 0,
68 	DCP_COLOR_YCBCR_RANGE_LIMITED = 1,
69 	DCP_COLOR_YCBCR_RANGE_COUNT
70 };
71 
72 struct dcp_color_mode {
73 	s64 score;
74 	u32 id;
75 	enum dcp_color_eotf eotf;
76 	enum dcp_color_format format;
77 	enum dcp_colorimetry colorimetry;
78 	enum dcp_color_range range;
79 	u8 depth;
80 };
81 
82 /*
83  * Represents a single display mode. These mode objects are populated at
84  * runtime based on the TimingElements dictionary sent by the DCP.
85  */
86 struct dcp_display_mode {
87 	struct drm_display_mode mode;
88 	u32 color_mode_id;
89 	u32 timing_mode_id;
90 	struct dcp_color_mode sdr_rgb;
91 	struct dcp_color_mode sdr_444;
92 	struct dcp_color_mode sdr;
93 	struct dcp_color_mode best;
94 };
95 
96 struct dimension {
97 	s64 total, front_porch, sync_width, active;
98 	s64 precise_sync_rate;
99 };
100 
101 int parse(const void *blob, size_t size, struct dcp_parse_ctx *ctx);
102 struct dcp_display_mode *enumerate_modes(struct dcp_parse_ctx *handle,
103 					 unsigned int *count, int width_mm,
104 					 int height_mm, unsigned notch_height);
105 int parse_display_attributes(struct dcp_parse_ctx *handle, int *width_mm,
106 			     int *height_mm);
107 int parse_epic_service_init(struct dcp_parse_ctx *handle, const char **name,
108 			    const char **class, s64 *unit);
109 
110 struct dcp_sound_format_mask {
111 	u64 formats;			/* SNDRV_PCM_FMTBIT_* */
112 	unsigned int rates;		/* SNDRV_PCM_RATE_* */
113 	unsigned int nchans;
114 };
115 
116 struct dcp_sound_cookie {
117 	u8 data[24];
118 };
119 
120 struct snd_pcm_chmap_elem;
121 int parse_sound_constraints(struct dcp_parse_ctx *handle,
122 			    struct dcp_sound_format_mask *sieve,
123 			    struct dcp_sound_format_mask *hits);
124 int parse_sound_mode(struct dcp_parse_ctx *handle,
125 		     struct dcp_sound_format_mask *sieve,
126 		     struct snd_pcm_chmap_elem *chmap,
127 		     struct dcp_sound_cookie *cookie);
128 
129 struct dcp_system_ev_mnits {
130 	u32 timestamp;
131 	u32 millinits;
132 	u32 idac;
133 };
134 
135 int parse_system_log_mnits(struct dcp_parse_ctx *handle,
136 			   struct dcp_system_ev_mnits *entry);
137 
138 #endif
139