1 /*
2  * Copyright (C) 2020 Samsung Electronics Co. Ltd.
3  * Copyright (C) 2021 Google LLC.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #pragma once
19 
20 #if __has_include(<video/mfc_macros.h>)
21 #error "This header should not be included if mfc_macros is available in UAPI"
22 #endif
23 
24 /* helper macros */
25 #ifndef __ALIGN_UP
26 #define __ALIGN_UP(x, a)					(((x) + ((a) - 1)) & ~((a) - 1))
27 #endif
28 
29 /* SBWC align macros */
30 #define SBWC_8B_STRIDE(w)					(128 * (((w) + 31) / 32))
31 #define SBWC_10B_STRIDE(w)					(160 * (((w) + 31) / 32))
32 #define SBWC_HEADER_STRIDE(w)				((((((w) + 63) / 64) + 15) / 16) * 16)
33 
34 #define SBWC_Y_VSTRIDE_BLOCKS(h)			((__ALIGN_UP((h), 16) + 3) / 4)
35 #define SBWC_CBCR_VSTRIDE_BLOCKS(h)			(((__ALIGN_UP((h), 16) / 2) + 3) / 4)
36 
37 #define SBWC_8B_Y_SIZE(w, h)				((SBWC_8B_STRIDE(w) * ((__ALIGN_UP((h), 16) + 3) / 4)) + 64)
38 #define SBWC_8B_Y_HEADER_SIZE(w, h)			__ALIGN_UP(((SBWC_HEADER_STRIDE(w) * ((__ALIGN_UP((h), 16) + 3) / 4)) + 256), 32)
39 #define SBWC_8B_CBCR_SIZE(w, h)				((SBWC_8B_STRIDE(w) * (((__ALIGN_UP((h), 16) / 2) + 3) / 4)) + 64)
40 #define SBWC_8B_CBCR_HEADER_SIZE(w, h)		((SBWC_HEADER_STRIDE(w) * (((__ALIGN_UP((h), 16) / 2) + 3) / 4)) + 128)
41 
42 #define SBWC_10B_Y_SIZE(w, h)				((SBWC_10B_STRIDE(w) * ((__ALIGN_UP((h), 16) + 3) / 4)) + 64)
43 #define SBWC_10B_Y_HEADER_SIZE(w, h)		__ALIGN_UP((((__ALIGN_UP((w), 32) * __ALIGN_UP((h), 16) * 2) + 256) - SBWC_10B_Y_SIZE(w, h)), 32)
44 #define SBWC_10B_CBCR_SIZE(w, h)			((SBWC_10B_STRIDE(w) * (((__ALIGN_UP((h), 16) / 2) + 3) / 4)) + 64)
45 #define SBWC_10B_CBCR_HEADER_SIZE(w, h)		(((__ALIGN_UP((w), 32) * __ALIGN_UP((h), 16)) + 256) - SBWC_10B_CBCR_SIZE(w, h))
46 
47 /* SBWC Lossy align macros */
48 #define SBWCL_8B_STRIDE(w, r)				(((128 * (r)) / 100) * (((w) + 31) / 32))
49 #define SBWCL_10B_STRIDE(w, r)				(((160 * (r)) / 100) * (((w) + 31) / 32))
50 
51 #define SBWCL_8B_Y_SIZE(w, h, r)			((SBWCL_8B_STRIDE(w, r) * ((__ALIGN_UP((h), 8) + 3) / 4)) + 64)
52 #define SBWCL_8B_CBCR_SIZE(w, h, r)			((SBWCL_8B_STRIDE(w, r) * (((__ALIGN_UP((h), 8) / 2) + 3) / 4)) + 64)
53 
54 #define SBWCL_10B_Y_SIZE(w, h, r)			((SBWCL_10B_STRIDE(w, r) * ((__ALIGN_UP((h), 8) + 3) / 4)) + 64)
55 #define SBWCL_10B_CBCR_SIZE(w, h, r)		((SBWCL_10B_STRIDE(w, r) * (((__ALIGN_UP((h), 8) / 2) + 3) / 4)) + 64)
56 
57 #define SBWCL_8B_CBCR_BASE(base, w, h, r)	((base) + SBWCL_8B_Y_SIZE(w, h, r))
58 #define SBWCL_10B_CBCR_BASE(base, w, h, r)	((base) + SBWCL_10B_Y_SIZE(w, h, r))
59 
60