1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (C) 2018 Linaro Ltd. */
3 #ifndef __VENUS_HFI_PARSER_H__
4 #define __VENUS_HFI_PARSER_H__
5 
6 #include "core.h"
7 
8 u32 hfi_parser(struct venus_core *core, struct venus_inst *inst,
9 	       void *buf, u32 size);
10 
11 #define WHICH_CAP_MIN	0
12 #define WHICH_CAP_MAX	1
13 #define WHICH_CAP_STEP	2
14 
get_cap(struct venus_inst * inst,u32 type,u32 which)15 static inline u32 get_cap(struct venus_inst *inst, u32 type, u32 which)
16 {
17 	struct venus_core *core = inst->core;
18 	struct hfi_capability *cap = NULL;
19 	struct hfi_plat_caps *caps;
20 	unsigned int i;
21 
22 	caps = venus_caps_by_codec(core, inst->hfi_codec, inst->session_type);
23 	if (!caps)
24 		return 0;
25 
26 	for (i = 0; i < caps->num_caps; i++) {
27 		if (caps->caps[i].capability_type == type) {
28 			cap = &caps->caps[i];
29 			break;
30 		}
31 	}
32 
33 	if (!cap)
34 		return 0;
35 
36 	switch (which) {
37 	case WHICH_CAP_MIN:
38 		return cap->min;
39 	case WHICH_CAP_MAX:
40 		return cap->max;
41 	case WHICH_CAP_STEP:
42 		return cap->step_size;
43 	default:
44 		break;
45 	}
46 
47 	return 0;
48 }
49 
cap_min(struct venus_inst * inst,u32 type)50 static inline u32 cap_min(struct venus_inst *inst, u32 type)
51 {
52 	return get_cap(inst, type, WHICH_CAP_MIN);
53 }
54 
cap_max(struct venus_inst * inst,u32 type)55 static inline u32 cap_max(struct venus_inst *inst, u32 type)
56 {
57 	return get_cap(inst, type, WHICH_CAP_MAX);
58 }
59 
cap_step(struct venus_inst * inst,u32 type)60 static inline u32 cap_step(struct venus_inst *inst, u32 type)
61 {
62 	return get_cap(inst, type, WHICH_CAP_STEP);
63 }
64 
frame_width_min(struct venus_inst * inst)65 static inline u32 frame_width_min(struct venus_inst *inst)
66 {
67 	return cap_min(inst, HFI_CAPABILITY_FRAME_WIDTH);
68 }
69 
frame_width_max(struct venus_inst * inst)70 static inline u32 frame_width_max(struct venus_inst *inst)
71 {
72 	return cap_max(inst, HFI_CAPABILITY_FRAME_WIDTH);
73 }
74 
frame_width_step(struct venus_inst * inst)75 static inline u32 frame_width_step(struct venus_inst *inst)
76 {
77 	return cap_step(inst, HFI_CAPABILITY_FRAME_WIDTH);
78 }
79 
frame_height_min(struct venus_inst * inst)80 static inline u32 frame_height_min(struct venus_inst *inst)
81 {
82 	return cap_min(inst, HFI_CAPABILITY_FRAME_HEIGHT);
83 }
84 
frame_height_max(struct venus_inst * inst)85 static inline u32 frame_height_max(struct venus_inst *inst)
86 {
87 	return cap_max(inst, HFI_CAPABILITY_FRAME_HEIGHT);
88 }
89 
frame_height_step(struct venus_inst * inst)90 static inline u32 frame_height_step(struct venus_inst *inst)
91 {
92 	return cap_step(inst, HFI_CAPABILITY_FRAME_HEIGHT);
93 }
94 
frate_min(struct venus_inst * inst)95 static inline u32 frate_min(struct venus_inst *inst)
96 {
97 	return cap_min(inst, HFI_CAPABILITY_FRAMERATE);
98 }
99 
frate_max(struct venus_inst * inst)100 static inline u32 frate_max(struct venus_inst *inst)
101 {
102 	return cap_max(inst, HFI_CAPABILITY_FRAMERATE);
103 }
104 
frate_step(struct venus_inst * inst)105 static inline u32 frate_step(struct venus_inst *inst)
106 {
107 	return cap_step(inst, HFI_CAPABILITY_FRAMERATE);
108 }
109 
core_num_max(struct venus_inst * inst)110 static inline u32 core_num_max(struct venus_inst *inst)
111 {
112 	return cap_max(inst, HFI_CAPABILITY_MAX_VIDEOCORES);
113 }
114 
mbs_per_frame_max(struct venus_inst * inst)115 static inline u32 mbs_per_frame_max(struct venus_inst *inst)
116 {
117 	return cap_max(inst, HFI_CAPABILITY_MBS_PER_FRAME);
118 }
119 
120 #endif
121