Skip to content

Commit 721225f

Browse files
authored
media: iris/venus: backport upstream fixes and encoder enhancements (#385)
media: iris/venus: backport upstream fixes and encoder enhancements
2 parents 6eabd42 + 5a245d3 commit 721225f

31 files changed

+1395
-392
lines changed

drivers/media/platform/amphion/vpu_core.c

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <linux/kernel.h>
1111
#include <linux/module.h>
1212
#include <linux/of.h>
13-
#include <linux/of_address.h>
13+
#include <linux/of_reserved_mem.h>
1414
#include <linux/platform_device.h>
1515
#include <linux/slab.h>
1616
#include <linux/types.h>
@@ -542,47 +542,30 @@ const struct vpu_core_resources *vpu_get_resource(struct vpu_inst *inst)
542542

543543
static int vpu_core_parse_dt(struct vpu_core *core, struct device_node *np)
544544
{
545-
struct device_node *node;
546545
struct resource res;
547546
int ret;
548547

549-
if (of_count_phandle_with_args(np, "memory-region", NULL) < 2) {
550-
dev_err(core->dev, "need 2 memory-region for boot and rpc\n");
551-
return -ENODEV;
548+
ret = of_reserved_mem_region_to_resource(np, 0, &res);
549+
if (ret) {
550+
dev_err(core->dev, "Cannot get boot-region\n");
551+
return ret;
552552
}
553553

554-
node = of_parse_phandle(np, "memory-region", 0);
555-
if (!node) {
556-
dev_err(core->dev, "boot-region of_parse_phandle error\n");
557-
return -ENODEV;
558-
}
559-
if (of_address_to_resource(node, 0, &res)) {
560-
dev_err(core->dev, "boot-region of_address_to_resource error\n");
561-
of_node_put(node);
562-
return -EINVAL;
563-
}
564554
core->fw.phys = res.start;
565555
core->fw.length = resource_size(&res);
566556

567-
of_node_put(node);
568-
569-
node = of_parse_phandle(np, "memory-region", 1);
570-
if (!node) {
571-
dev_err(core->dev, "rpc-region of_parse_phandle error\n");
572-
return -ENODEV;
573-
}
574-
if (of_address_to_resource(node, 0, &res)) {
575-
dev_err(core->dev, "rpc-region of_address_to_resource error\n");
576-
of_node_put(node);
577-
return -EINVAL;
557+
ret = of_reserved_mem_region_to_resource(np, 1, &res);
558+
if (ret) {
559+
dev_err(core->dev, "Cannot get rpc-region\n");
560+
return ret;
578561
}
562+
579563
core->rpc.phys = res.start;
580564
core->rpc.length = resource_size(&res);
581565

582566
if (core->rpc.length < core->res->rpc_size + core->res->fwlog_size) {
583567
dev_err(core->dev, "the rpc-region <%pad, 0x%x> is not enough\n",
584568
&core->rpc.phys, core->rpc.length);
585-
of_node_put(node);
586569
return -EINVAL;
587570
}
588571

@@ -594,7 +577,6 @@ static int vpu_core_parse_dt(struct vpu_core *core, struct device_node *np)
594577
if (ret != VPU_CORE_MEMORY_UNCACHED) {
595578
dev_err(core->dev, "rpc region<%pad, 0x%x> isn't uncached\n",
596579
&core->rpc.phys, core->rpc.length);
597-
of_node_put(node);
598580
return -EINVAL;
599581
}
600582

@@ -606,8 +588,6 @@ static int vpu_core_parse_dt(struct vpu_core *core, struct device_node *np)
606588
core->act.length = core->rpc.length - core->res->rpc_size - core->log.length;
607589
core->rpc.length = core->res->rpc_size;
608590

609-
of_node_put(node);
610-
611591
return 0;
612592
}
613593

drivers/media/platform/qcom/iris/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ qcom-iris-objs += iris_buffer.o \
2222
iris_venc.o \
2323
iris_vpu2.o \
2424
iris_vpu3x.o \
25+
iris_vpu4x.o \
2526
iris_vpu_buffer.o \
2627
iris_vpu_common.o \
2728

drivers/media/platform/qcom/iris/iris_ctrls.c

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ static enum platform_inst_fw_cap_type iris_get_cap_id(u32 id)
102102
return PROFILE_AV1;
103103
case V4L2_CID_MPEG_VIDEO_AV1_LEVEL:
104104
return LEVEL_AV1;
105+
case V4L2_CID_ROTATE:
106+
return ROTATION;
107+
case V4L2_CID_HFLIP:
108+
return HFLIP;
109+
case V4L2_CID_VFLIP:
110+
return VFLIP;
111+
case V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD_TYPE:
112+
return IR_TYPE;
113+
case V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD:
114+
return IR_PERIOD;
105115
default:
106116
return INST_FW_CAP_MAX;
107117
}
@@ -193,6 +203,16 @@ static u32 iris_get_v4l2_id(enum platform_inst_fw_cap_type cap_id)
193203
return V4L2_CID_MPEG_VIDEO_AV1_PROFILE;
194204
case LEVEL_AV1:
195205
return V4L2_CID_MPEG_VIDEO_AV1_LEVEL;
206+
case ROTATION:
207+
return V4L2_CID_ROTATE;
208+
case HFLIP:
209+
return V4L2_CID_HFLIP;
210+
case VFLIP:
211+
return V4L2_CID_VFLIP;
212+
case IR_TYPE:
213+
return V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD_TYPE;
214+
case IR_PERIOD:
215+
return V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD;
196216
default:
197217
return 0;
198218
}
@@ -901,6 +921,81 @@ int iris_set_qp_range(struct iris_inst *inst, enum platform_inst_fw_cap_type cap
901921
&range, sizeof(range));
902922
}
903923

924+
int iris_set_rotation(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id)
925+
{
926+
const struct iris_hfi_command_ops *hfi_ops = inst->core->hfi_ops;
927+
u32 hfi_id = inst->fw_caps[cap_id].hfi_id;
928+
u32 hfi_val;
929+
930+
switch (inst->fw_caps[cap_id].value) {
931+
case 0:
932+
hfi_val = HFI_ROTATION_NONE;
933+
return 0;
934+
case 90:
935+
hfi_val = HFI_ROTATION_90;
936+
break;
937+
case 180:
938+
hfi_val = HFI_ROTATION_180;
939+
break;
940+
case 270:
941+
hfi_val = HFI_ROTATION_270;
942+
break;
943+
default:
944+
return -EINVAL;
945+
}
946+
947+
return hfi_ops->session_set_property(inst, hfi_id,
948+
HFI_HOST_FLAGS_NONE,
949+
iris_get_port_info(inst, cap_id),
950+
HFI_PAYLOAD_U32,
951+
&hfi_val, sizeof(u32));
952+
}
953+
954+
int iris_set_flip(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id)
955+
{
956+
const struct iris_hfi_command_ops *hfi_ops = inst->core->hfi_ops;
957+
u32 hfi_id = inst->fw_caps[cap_id].hfi_id;
958+
u32 hfi_val = HFI_DISABLE_FLIP;
959+
960+
if (inst->fw_caps[HFLIP].value)
961+
hfi_val |= HFI_HORIZONTAL_FLIP;
962+
963+
if (inst->fw_caps[VFLIP].value)
964+
hfi_val |= HFI_VERTICAL_FLIP;
965+
966+
return hfi_ops->session_set_property(inst, hfi_id,
967+
HFI_HOST_FLAGS_NONE,
968+
iris_get_port_info(inst, cap_id),
969+
HFI_PAYLOAD_U32_ENUM,
970+
&hfi_val, sizeof(u32));
971+
}
972+
973+
int iris_set_ir_period(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id)
974+
{
975+
const struct iris_hfi_command_ops *hfi_ops = inst->core->hfi_ops;
976+
struct vb2_queue *q = v4l2_m2m_get_dst_vq(inst->m2m_ctx);
977+
u32 ir_period = inst->fw_caps[cap_id].value;
978+
u32 ir_type = 0;
979+
980+
if (inst->fw_caps[IR_TYPE].value ==
981+
V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD_TYPE_RANDOM) {
982+
if (vb2_is_streaming(q))
983+
return 0;
984+
ir_type = HFI_PROP_IR_RANDOM_PERIOD;
985+
} else if (inst->fw_caps[IR_TYPE].value ==
986+
V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD_TYPE_CYCLIC) {
987+
ir_type = HFI_PROP_IR_CYCLIC_PERIOD;
988+
} else {
989+
return -EINVAL;
990+
}
991+
992+
return hfi_ops->session_set_property(inst, ir_type,
993+
HFI_HOST_FLAGS_NONE,
994+
iris_get_port_info(inst, cap_id),
995+
HFI_PAYLOAD_U32,
996+
&ir_period, sizeof(u32));
997+
}
998+
904999
int iris_set_properties(struct iris_inst *inst, u32 plane)
9051000
{
9061001
const struct iris_hfi_command_ops *hfi_ops = inst->core->hfi_ops;

drivers/media/platform/qcom/iris/iris_ctrls.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ int iris_set_min_qp(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_i
3232
int iris_set_max_qp(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
3333
int iris_set_frame_qp(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
3434
int iris_set_qp_range(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
35+
int iris_set_rotation(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
36+
int iris_set_flip(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
37+
int iris_set_ir_period(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
3538
int iris_set_properties(struct iris_inst *inst, u32 plane);
3639

3740
#endif

drivers/media/platform/qcom/iris/iris_firmware.c

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ static int iris_load_fw_to_memory(struct iris_core *core, const char *fw_name)
2525
struct qcom_scm_pas_context *ctx;
2626
const struct firmware *firmware = NULL;
2727
struct device *dev = core->dev;
28-
struct reserved_mem *rmem;
29-
struct device_node *node;
28+
struct resource res;
3029
phys_addr_t mem_phys;
3130
size_t res_size;
3231
ssize_t fw_size;
@@ -35,17 +34,12 @@ static int iris_load_fw_to_memory(struct iris_core *core, const char *fw_name)
3534
if (strlen(fw_name) >= MAX_FIRMWARE_NAME_SIZE - 4)
3635
return -EINVAL;
3736

38-
node = of_parse_phandle(dev->of_node, "memory-region", 0);
39-
if (!node)
40-
return -EINVAL;
41-
42-
rmem = of_reserved_mem_lookup(node);
43-
of_node_put(node);
44-
if (!rmem)
45-
return -EINVAL;
37+
ret = of_reserved_mem_region_to_resource(dev->of_node, 0, &res);
38+
if (ret)
39+
return ret;
4640

47-
mem_phys = rmem->base;
48-
res_size = rmem->size;
41+
mem_phys = res.start;
42+
res_size = resource_size(&res);
4943

5044
dev = core->fw.dev ? : core->dev;
5145

@@ -95,9 +89,9 @@ static int iris_load_fw_to_memory(struct iris_core *core, const char *fw_name)
9589

9690
int iris_fw_load(struct iris_core *core)
9791
{
98-
struct tz_cp_config *cp_config = core->iris_platform_data->tz_cp_config_data;
92+
const struct tz_cp_config *cp_config;
9993
const char *fwpath = NULL;
100-
int ret;
94+
int i, ret;
10195

10296
ret = of_property_read_string_index(core->dev->of_node, "firmware-name", 0,
10397
&fwpath);
@@ -110,14 +104,17 @@ int iris_fw_load(struct iris_core *core)
110104
return -ENOMEM;
111105
}
112106

113-
ret = qcom_scm_mem_protect_video_var(cp_config->cp_start,
114-
cp_config->cp_size,
115-
cp_config->cp_nonpixel_start,
116-
cp_config->cp_nonpixel_size);
117-
if (ret) {
118-
dev_err(core->dev, "protect memory failed\n");
119-
iris_fw_unload(core);
120-
return ret;
107+
for (i = 0; i < core->iris_platform_data->tz_cp_config_data_size; i++) {
108+
cp_config = &core->iris_platform_data->tz_cp_config_data[i];
109+
ret = qcom_scm_mem_protect_video_var(cp_config->cp_start,
110+
cp_config->cp_size,
111+
cp_config->cp_nonpixel_start,
112+
cp_config->cp_nonpixel_size);
113+
if (ret) {
114+
dev_err(core->dev, "qcom_scm_mem_protect_video_var failed: %d\n", ret);
115+
iris_fw_unload(core);
116+
return ret;
117+
}
121118
}
122119

123120
return ret;

0 commit comments

Comments
 (0)