1 // SPDX-License-Identifier: GPL-2.0
3 * (C) COPYRIGHT 2018 ARM Limited. All rights reserved.
4 * Author: James.Qian.Wang <james.qian.wang@arm.com>
8 #include <linux/slab.h>
9 #include "komeda_format_caps.h"
10 #include "malidp_utils.h"
12 const struct komeda_format_caps
*
13 komeda_get_format_caps(struct komeda_format_caps_table
*table
,
14 u32 fourcc
, u64 modifier
)
16 const struct komeda_format_caps
*caps
;
17 u64 afbc_features
= modifier
& ~(AFBC_FORMAT_MOD_BLOCK_SIZE_MASK
);
18 u32 afbc_layout
= modifier
& AFBC_FORMAT_MOD_BLOCK_SIZE_MASK
;
21 for (id
= 0; id
< table
->n_formats
; id
++) {
22 caps
= &table
->format_caps
[id
];
24 if (fourcc
!= caps
->fourcc
)
27 if ((modifier
== 0ULL) && (caps
->supported_afbc_layouts
== 0))
30 if (has_bits(afbc_features
, caps
->supported_afbc_features
) &&
31 has_bit(afbc_layout
, caps
->supported_afbc_layouts
))
38 u32
komeda_get_afbc_format_bpp(const struct drm_format_info
*info
, u64 modifier
)
42 switch (info
->format
) {
43 case DRM_FORMAT_YUV420_8BIT
:
46 case DRM_FORMAT_YUV420_10BIT
:
50 bpp
= info
->cpp
[0] * 8;
58 * 1. RGB always has YTR
59 * 2. Tiled RGB always has SC
61 u64 komeda_supported_modifiers
[] = {
62 /* AFBC_16x16 + features: YUV+RGB both */
67 AFBC_16x16(_YTR
| _SPARSE
),
69 /* SPLIT + SPARSE + YTR RGB only */
70 /* split mode is only allowed for sparse mode */
71 AFBC_16x16(_SPLIT
| _SPARSE
| _YTR
),
72 /* TILED + (SPARSE) */
73 /* TILED YUV format only */
74 AFBC_16x16(_TILED
| _SPARSE
),
76 /* TILED + SC + (SPLIT+SPARSE | SPARSE) + (YTR) */
77 AFBC_16x16(_TILED
| _SC
| _SPLIT
| _SPARSE
| _YTR
),
78 AFBC_16x16(_TILED
| _SC
| _SPARSE
| _YTR
),
79 AFBC_16x16(_TILED
| _SC
| _YTR
),
80 /* AFBC_32x8 + features: which are RGB formats only */
82 AFBC_32x8(_YTR
| _SPARSE
),
84 /* SPLIT + SPARSE + (YTR) */
85 /* split mode is only allowed for sparse mode */
86 AFBC_32x8(_SPLIT
| _SPARSE
| _YTR
),
87 /* TILED + SC + (SPLIT+SPARSE | SPARSE) + YTR */
88 AFBC_32x8(_TILED
| _SC
| _SPLIT
| _SPARSE
| _YTR
),
89 AFBC_32x8(_TILED
| _SC
| _SPARSE
| _YTR
),
90 AFBC_32x8(_TILED
| _SC
| _YTR
),
91 DRM_FORMAT_MOD_LINEAR
,
92 DRM_FORMAT_MOD_INVALID
95 bool komeda_format_mod_supported(struct komeda_format_caps_table
*table
,
96 u32 layer_type
, u32 fourcc
, u64 modifier
,
99 const struct komeda_format_caps
*caps
;
101 caps
= komeda_get_format_caps(table
, fourcc
, modifier
);
105 if (!(caps
->supported_layer_types
& layer_type
))
108 if (table
->format_mod_supported
)
109 return table
->format_mod_supported(caps
, layer_type
, modifier
,
115 u32
*komeda_get_layer_fourcc_list(struct komeda_format_caps_table
*table
,
116 u32 layer_type
, u32
*n_fmts
)
118 const struct komeda_format_caps
*cap
;
122 fmts
= kcalloc(table
->n_formats
, sizeof(u32
), GFP_KERNEL
);
126 for (i
= 0; i
< table
->n_formats
; i
++) {
127 cap
= &table
->format_caps
[i
];
128 if (!(layer_type
& cap
->supported_layer_types
) ||
132 /* one fourcc may has two caps items in table (afbc/none-afbc),
133 * so check the existing list to avoid adding a duplicated one.
135 for (j
= n
- 1; j
>= 0; j
--)
136 if (fmts
[j
] == cap
->fourcc
)
140 fmts
[n
++] = cap
->fourcc
;
149 void komeda_put_fourcc_list(u32
*fourcc_list
)