1 // SPDX-License-Identifier: GPL-2.0-only OR MIT
2 /* Copyright 2021 Alyssa Rosenzweig <alyssa@rosenzweig.io> */
3
4 /*
5 * This file is intended to be included multiple times with IOMFB_VER
6 * defined to declare DCP firmware version dependent structs.
7 */
8
9 #ifdef DCP_FW_VER
10
11 #include <drm/drm_crtc.h>
12
13 #include <linux/types.h>
14
15 #include "iomfb.h"
16 #include "version_utils.h"
17
DCP_FW_NAME(dcp_swap)18 struct DCP_FW_NAME(dcp_swap) {
19 u64 ts1;
20 u64 ts2;
21 u64 unk_10[6];
22 u64 flags1;
23 u64 flags2;
24
25 u32 swap_id;
26
27 u32 surf_ids[SWAP_SURFACES];
28 struct dcp_rect src_rect[SWAP_SURFACES];
29 u32 surf_flags[SWAP_SURFACES];
30 u32 surf_unk[SWAP_SURFACES];
31 struct dcp_rect dst_rect[SWAP_SURFACES];
32 u32 swap_enabled;
33 u32 swap_completed;
34
35 u32 bg_color;
36 u8 unk_110[0x1b8];
37 u32 unk_2c8;
38 u8 unk_2cc[0x14];
39 u32 unk_2e0;
40 #if DCP_FW_VER < DCP_FW_VERSION(13, 2, 0)
41 u16 unk_2e2;
42 #else
43 u8 unk_2e2[3];
44 #endif
45 u64 bl_unk;
46 u32 bl_value; // min value is 0x10000000
47 u8 bl_power; // constant 0x40 for on
48 u8 unk_2f3[0x2d];
49 #if DCP_FW_VER >= DCP_FW_VERSION(13, 2, 0)
50 u8 unk_320[0x13f];
51 u64 unk_1;
52 #endif
53 } __packed;
54
55 /* Information describing a surface */
DCP_FW_NAME(dcp_surface)56 struct DCP_FW_NAME(dcp_surface) {
57 u8 is_tiled;
58 u8 is_tearing_allowed;
59 u8 is_premultiplied;
60 u32 plane_cnt;
61 u32 plane_cnt2;
62 u32 format; /* DCP fourcc */
63 u32 ycbcr_matrix;
64 u8 xfer_func;
65 u8 colorspace;
66 u32 stride;
67 u16 pix_size;
68 u8 pel_w;
69 u8 pel_h;
70 u32 offset;
71 u32 width;
72 u32 height;
73 u32 buf_size;
74 u64 protection_opts;
75 u32 surface_id;
76 struct dcp_component_types comp_types[MAX_PLANES];
77 u64 has_comp;
78 struct dcp_plane_info planes[MAX_PLANES];
79 u64 has_planes;
80 u32 compression_info[MAX_PLANES][13];
81 u64 has_compr_info;
82 u32 unk_num;
83 u32 unk_denom;
84 #if DCP_FW_VER < DCP_FW_VERSION(13, 2, 0)
85 u8 padding[7];
86 #else
87 u8 padding[47];
88 #endif
89 } __packed;
90
91 /* Prototypes */
92
DCP_FW_NAME(dcp_swap_submit_req)93 struct DCP_FW_NAME(dcp_swap_submit_req) {
94 struct DCP_FW_NAME(dcp_swap) swap;
95 struct DCP_FW_NAME(dcp_surface) surf[SWAP_SURFACES];
96 u64 surf_iova[SWAP_SURFACES];
97 #if DCP_FW_VER >= DCP_FW_VERSION(13, 2, 0)
98 u64 unk_u64_a[SWAP_SURFACES];
99 struct DCP_FW_NAME(dcp_surface) surf2[5];
100 u64 surf2_iova[5];
101 #endif
102 u8 unkbool;
103 u64 unkdouble;
104 #if DCP_FW_VER >= DCP_FW_VERSION(13, 2, 0)
105 u64 unkU64;
106 u8 unkbool2;
107 #endif
108 u32 clear; // or maybe switch to default fb?
109 #if DCP_FW_VER >= DCP_FW_VERSION(13, 2, 0)
110 u32 unkU32Ptr;
111 #endif
112 u8 swap_null;
113 u8 surf_null[SWAP_SURFACES];
114 #if DCP_FW_VER >= DCP_FW_VERSION(13, 2, 0)
115 u8 surf2_null[5];
116 #endif
117 u8 unkoutbool_null;
118 #if DCP_FW_VER >= DCP_FW_VERSION(13, 2, 0)
119 u8 unkU32Ptr_null;
120 u8 unkU32out_null;
121 #endif
122 u8 padding[1];
123 } __packed;
124
DCP_FW_NAME(dcp_swap_submit_resp)125 struct DCP_FW_NAME(dcp_swap_submit_resp) {
126 u8 unkoutbool;
127 #if DCP_FW_VER >= DCP_FW_VERSION(13, 2, 0)
128 u32 unkU32out;
129 #endif
130 u32 ret;
131 u8 padding[3];
132 } __packed;
133
DCP_FW_NAME(dc_swap_complete_resp)134 struct DCP_FW_NAME(dc_swap_complete_resp) {
135 u32 swap_id;
136 u8 unkbool;
137 u64 swap_data;
138 #if DCP_FW_VER < DCP_FW_VERSION(13, 2, 0)
139 u8 swap_info[0x6c4];
140 #else
141 u8 swap_info[0x6c5];
142 #endif
143 u32 unkint;
144 u8 swap_info_null;
145 } __packed;
146
DCP_FW_NAME(dcp_map_reg_req)147 struct DCP_FW_NAME(dcp_map_reg_req) {
148 char obj[4];
149 u32 index;
150 u32 flags;
151 #if DCP_FW_VER >= DCP_FW_VERSION(13, 2, 0)
152 u8 unk_u64_null;
153 #endif
154 u8 addr_null;
155 u8 length_null;
156 #if DCP_FW_VER >= DCP_FW_VERSION(13, 2, 0)
157 u8 padding[1];
158 #else
159 u8 padding[2];
160 #endif
161 } __packed;
162
DCP_FW_NAME(dcp_map_reg_resp)163 struct DCP_FW_NAME(dcp_map_reg_resp) {
164 #if DCP_FW_VER >= DCP_FW_VERSION(13, 2, 0)
165 u64 dva;
166 #endif
167 u64 addr;
168 u64 length;
169 u32 ret;
170 } __packed;
171
172
173 struct apple_dcp;
174
175 int DCP_FW_NAME(iomfb_modeset)(struct apple_dcp *dcp,
176 struct drm_crtc_state *crtc_state);
177 void DCP_FW_NAME(iomfb_flush)(struct apple_dcp *dcp, struct drm_crtc *crtc, struct drm_atomic_state *state);
178 void DCP_FW_NAME(iomfb_poweron)(struct apple_dcp *dcp);
179 void DCP_FW_NAME(iomfb_poweroff)(struct apple_dcp *dcp);
180 void DCP_FW_NAME(iomfb_sleep)(struct apple_dcp *dcp);
181 void DCP_FW_NAME(iomfb_start)(struct apple_dcp *dcp);
182 void DCP_FW_NAME(iomfb_shutdown)(struct apple_dcp *dcp);
183
184 #endif
185