77
88#include "iomfb_internal.h"
99
10+ #include "iomfb_plane.h"
11+ #include "linux/printk.h"
12+ #include "vdso/align.h"
1013#include <drm/drm_atomic.h>
1114#include <drm/drm_atomic_helper.h>
1215#include <drm/drm_fourcc.h>
@@ -248,7 +251,6 @@ static void apple_plane_atomic_update(struct drm_plane *plane,
248251 .stride = fb -> pitches [0 ],
249252 .width = fb -> width ,
250253 .height = fb -> height ,
251- .buf_size = fb -> height * fb -> pitches [0 ],
252254 // .surface_id = req->swap.surf_ids[l],
253255
254256 /* Only used for compressed or multiplanar surfaces */
@@ -257,8 +259,12 @@ static void apple_plane_atomic_update(struct drm_plane *plane,
257259 .pel_h = 1 ,
258260 .has_comp = 1 ,
259261 .has_planes = 1 ,
262+ .has_compr_info = 1 ,
260263 };
261264
265+ BUILD_BUG_ON (sizeof (struct dcp_plane_info ) != 0x50 );
266+ BUILD_BUG_ON (sizeof (struct dcp_compression_info ) != 0x34 );
267+
262268 /* Populate plane information for planar formats */
263269 struct dcp_surface * surf = & new_state -> surf ;
264270 for (int i = 0 ; fb -> format -> num_planes && i < fb -> format -> num_planes ; i ++ ) {
@@ -279,8 +285,36 @@ static void apple_plane_atomic_update(struct drm_plane *plane,
279285 .tile_h = bh ,
280286 };
281287
282- if (i > 0 )
283- surf -> buf_size += surf -> planes [i ].size ;
288+ if (fb -> modifier == DRM_FORMAT_MOD_APPLE_INTERCHANGE_COMPRESSED ) {
289+ u32 tw = ALIGN (width , 16 ) / 16 ;
290+ u32 th = ALIGN (height , 16 ) / 16 ;
291+ u32 tsize_B = 16 * 16 * 4 ;
292+
293+ u32 meta_offset = ALIGN (tw * th * tsize_B , 128 );
294+ u32 meta_size = roundup_pow_of_two (width ) * roundup_pow_of_two (height ) * 8 ;
295+
296+ surf -> planes [i ].tile_w = 16 ;
297+ surf -> planes [i ].tile_h = 16 ;
298+ surf -> planes [i ].stride = tw * tsize_B ;
299+ surf -> planes [i ].size = meta_offset + meta_size ;
300+ surf -> planes [i ].tile_size = tsize_B ;
301+ surf -> planes [i ].address_format = 5 ; // interchange tiles
302+
303+ surf -> compression_info [i ] = (struct dcp_compression_info ) {
304+ .tile_w = 16 ,
305+ .tile_h = 16 ,
306+ .data_offset = 0 ,
307+ .meta_offset = meta_offset ,
308+ .tile_meta_bytes = 8 ,
309+ .tiles_w = tw ,
310+ .tiles_h = th ,
311+ .tile_bytes = tsize_B ,
312+ .row_stride = tw * tsize_B ,
313+ .compresson_type = 3 , // interchange compression
314+ };
315+ }
316+
317+ surf -> buf_size += surf -> planes [i ].size ;
284318 }
285319
286320 /* the obvious helper call drm_fb_dma_get_gem_addr() adjusts
@@ -426,6 +460,7 @@ static const u32 dcp_overlay_formats_12_x[] = {
426460};
427461
428462u64 apple_format_modifiers [] = {
463+ DRM_FORMAT_MOD_APPLE_INTERCHANGE_COMPRESSED ,
429464 DRM_FORMAT_MOD_LINEAR ,
430465 DRM_FORMAT_MOD_INVALID
431466};
0 commit comments