2 * Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
3 * Copyright (C) 2017 Linaro Ltd.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 and
7 * only version 2 as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <linux/hash.h>
16 #include <linux/list.h>
17 #include <linux/slab.h>
18 #include <media/videobuf2-v4l2.h>
22 #include "hfi_helper.h"
25 static void event_seq_changed(struct venus_core *core, struct venus_inst *inst,
26 struct hfi_msg_event_notify_pkt *pkt)
28 struct hfi_event_data event = {0};
29 int num_properties_changed;
30 struct hfi_framesize *frame_sz;
31 struct hfi_profile_level *profile_level;
35 inst->error = HFI_ERR_NONE;
37 switch (pkt->event_data1) {
38 case HFI_EVENT_DATA_SEQUENCE_CHANGED_SUFFICIENT_BUF_RESOURCES:
39 case HFI_EVENT_DATA_SEQUENCE_CHANGED_INSUFFICIENT_BUF_RESOURCES:
42 inst->error = HFI_ERR_SESSION_INVALID_PARAMETER;
46 event.event_type = pkt->event_data1;
48 num_properties_changed = pkt->event_data2;
49 if (!num_properties_changed) {
50 inst->error = HFI_ERR_SESSION_INSUFFICIENT_RESOURCES;
54 data_ptr = (u8 *)&pkt->ext_event_data[0];
56 ptype = *((u32 *)data_ptr);
58 case HFI_PROPERTY_PARAM_FRAME_SIZE:
59 data_ptr += sizeof(u32);
60 frame_sz = (struct hfi_framesize *)data_ptr;
61 event.width = frame_sz->width;
62 event.height = frame_sz->height;
63 data_ptr += sizeof(frame_sz);
65 case HFI_PROPERTY_PARAM_PROFILE_LEVEL_CURRENT:
66 data_ptr += sizeof(u32);
67 profile_level = (struct hfi_profile_level *)data_ptr;
68 event.profile = profile_level->profile;
69 event.level = profile_level->level;
70 data_ptr += sizeof(profile_level);
75 num_properties_changed--;
76 } while (num_properties_changed > 0);
79 inst->ops->event_notify(inst, EVT_SYS_EVENT_CHANGE, &event);
82 static void event_release_buffer_ref(struct venus_core *core,
83 struct venus_inst *inst,
84 struct hfi_msg_event_notify_pkt *pkt)
86 struct hfi_event_data event = {0};
87 struct hfi_msg_event_release_buffer_ref_pkt *data;
89 data = (struct hfi_msg_event_release_buffer_ref_pkt *)
92 event.event_type = HFI_EVENT_RELEASE_BUFFER_REFERENCE;
93 event.packet_buffer = data->packet_buffer;
94 event.extradata_buffer = data->extradata_buffer;
95 event.tag = data->output_tag;
97 inst->error = HFI_ERR_NONE;
98 inst->ops->event_notify(inst, EVT_SYS_EVENT_CHANGE, &event);
101 static void event_sys_error(struct venus_core *core, u32 event,
102 struct hfi_msg_event_notify_pkt *pkt)
106 "sys error (session id:%x, data1:%x, data2:%x)\n",
107 pkt->shdr.session_id, pkt->event_data1,
110 core->core_ops->event_notify(core, event);
114 event_session_error(struct venus_core *core, struct venus_inst *inst,
115 struct hfi_msg_event_notify_pkt *pkt)
117 struct device *dev = core->dev;
119 dev_dbg(dev, "session error: event id:%x, session id:%x\n",
120 pkt->event_data1, pkt->shdr.session_id);
125 switch (pkt->event_data1) {
126 /* non fatal session errors */
127 case HFI_ERR_SESSION_INVALID_SCALE_FACTOR:
128 case HFI_ERR_SESSION_UNSUPPORT_BUFFERTYPE:
129 case HFI_ERR_SESSION_UNSUPPORTED_SETTING:
130 case HFI_ERR_SESSION_UPSCALE_NOT_SUPPORTED:
131 inst->error = HFI_ERR_NONE;
134 dev_err(dev, "session error: event id:%x (%x), session id:%x\n",
135 pkt->event_data1, pkt->event_data2,
136 pkt->shdr.session_id);
138 inst->error = pkt->event_data1;
139 inst->ops->event_notify(inst, EVT_SESSION_ERROR, NULL);
144 static void hfi_event_notify(struct venus_core *core, struct venus_inst *inst,
147 struct hfi_msg_event_notify_pkt *pkt = packet;
152 switch (pkt->event_id) {
153 case HFI_EVENT_SYS_ERROR:
154 event_sys_error(core, EVT_SYS_ERROR, pkt);
156 case HFI_EVENT_SESSION_ERROR:
157 event_session_error(core, inst, pkt);
159 case HFI_EVENT_SESSION_SEQUENCE_CHANGED:
160 event_seq_changed(core, inst, pkt);
162 case HFI_EVENT_RELEASE_BUFFER_REFERENCE:
163 event_release_buffer_ref(core, inst, pkt);
165 case HFI_EVENT_SESSION_PROPERTY_CHANGED:
172 static void hfi_sys_init_done(struct venus_core *core, struct venus_inst *inst,
175 struct hfi_msg_sys_init_done_pkt *pkt = packet;
176 u32 rem_bytes, read_bytes = 0, num_properties;
180 error = pkt->error_type;
181 if (error != HFI_ERR_NONE)
184 num_properties = pkt->num_properties;
186 if (!num_properties) {
187 error = HFI_ERR_SYS_INVALID_PARAMETER;
191 rem_bytes = pkt->hdr.size - sizeof(*pkt) + sizeof(u32);
194 /* missing property data */
195 error = HFI_ERR_SYS_INSUFFICIENT_RESOURCES;
199 data = (u8 *)&pkt->data[0];
201 if (core->res->hfi_version == HFI_VERSION_3XX)
204 while (num_properties && rem_bytes >= sizeof(u32)) {
205 ptype = *((u32 *)data);
209 case HFI_PROPERTY_PARAM_CODEC_SUPPORTED: {
210 struct hfi_codec_supported *prop;
212 prop = (struct hfi_codec_supported *)data;
214 if (rem_bytes < sizeof(*prop)) {
215 error = HFI_ERR_SYS_INSUFFICIENT_RESOURCES;
219 read_bytes += sizeof(*prop) + sizeof(u32);
220 core->dec_codecs = prop->dec_codecs;
221 core->enc_codecs = prop->enc_codecs;
224 case HFI_PROPERTY_PARAM_MAX_SESSIONS_SUPPORTED: {
225 struct hfi_max_sessions_supported *prop;
227 if (rem_bytes < sizeof(*prop)) {
228 error = HFI_ERR_SYS_INSUFFICIENT_RESOURCES;
232 prop = (struct hfi_max_sessions_supported *)data;
233 read_bytes += sizeof(*prop) + sizeof(u32);
234 core->max_sessions_supported = prop->max_sessions;
238 error = HFI_ERR_SYS_INVALID_PARAMETER;
243 rem_bytes -= read_bytes;
251 complete(&core->done);
255 sys_get_prop_image_version(struct device *dev,
256 struct hfi_msg_sys_property_info_pkt *pkt)
260 req_bytes = pkt->hdr.size - sizeof(*pkt);
262 if (req_bytes < 128 || !pkt->data[1] || pkt->num_properties > 1)
266 dev_dbg(dev, "F/W version: %s\n", (u8 *)&pkt->data[1]);
269 static void hfi_sys_property_info(struct venus_core *core,
270 struct venus_inst *inst, void *packet)
272 struct hfi_msg_sys_property_info_pkt *pkt = packet;
273 struct device *dev = core->dev;
275 if (!pkt->num_properties) {
276 dev_dbg(dev, "%s: no properties\n", __func__);
280 switch (pkt->data[0]) {
281 case HFI_PROPERTY_SYS_IMAGE_VERSION:
282 sys_get_prop_image_version(dev, pkt);
285 dev_dbg(dev, "%s: unknown property data\n", __func__);
290 static void hfi_sys_rel_resource_done(struct venus_core *core,
291 struct venus_inst *inst,
294 struct hfi_msg_sys_release_resource_done_pkt *pkt = packet;
296 core->error = pkt->error_type;
297 complete(&core->done);
300 static void hfi_sys_ping_done(struct venus_core *core, struct venus_inst *inst,
303 struct hfi_msg_sys_ping_ack_pkt *pkt = packet;
305 core->error = HFI_ERR_NONE;
307 if (pkt->client_data != 0xbeef)
308 core->error = HFI_ERR_SYS_FATAL;
310 complete(&core->done);
313 static void hfi_sys_idle_done(struct venus_core *core, struct venus_inst *inst,
316 dev_dbg(core->dev, "sys idle\n");
319 static void hfi_sys_pc_prepare_done(struct venus_core *core,
320 struct venus_inst *inst, void *packet)
322 struct hfi_msg_sys_pc_prep_done_pkt *pkt = packet;
324 dev_dbg(core->dev, "pc prepare done (error %x)\n", pkt->error_type);
328 hfi_copy_cap_prop(struct hfi_capability *in, struct venus_inst *inst)
333 switch (in->capability_type) {
334 case HFI_CAPABILITY_FRAME_WIDTH:
335 inst->cap_width = *in;
337 case HFI_CAPABILITY_FRAME_HEIGHT:
338 inst->cap_height = *in;
340 case HFI_CAPABILITY_MBS_PER_FRAME:
341 inst->cap_mbs_per_frame = *in;
343 case HFI_CAPABILITY_MBS_PER_SECOND:
344 inst->cap_mbs_per_sec = *in;
346 case HFI_CAPABILITY_FRAMERATE:
347 inst->cap_framerate = *in;
349 case HFI_CAPABILITY_SCALE_X:
350 inst->cap_scale_x = *in;
352 case HFI_CAPABILITY_SCALE_Y:
353 inst->cap_scale_y = *in;
355 case HFI_CAPABILITY_BITRATE:
356 inst->cap_bitrate = *in;
358 case HFI_CAPABILITY_HIER_P_NUM_ENH_LAYERS:
359 inst->cap_hier_p = *in;
361 case HFI_CAPABILITY_ENC_LTR_COUNT:
362 inst->cap_ltr_count = *in;
364 case HFI_CAPABILITY_CP_OUTPUT2_THRESH:
365 inst->cap_secure_output2_threshold = *in;
373 session_get_prop_profile_level(struct hfi_msg_session_property_info_pkt *pkt,
374 struct hfi_profile_level *profile_level)
376 struct hfi_profile_level *hfi;
379 req_bytes = pkt->shdr.hdr.size - sizeof(*pkt);
381 if (!req_bytes || req_bytes % sizeof(struct hfi_profile_level))
383 return HFI_ERR_SESSION_INVALID_PARAMETER;
385 hfi = (struct hfi_profile_level *)&pkt->data[1];
386 profile_level->profile = hfi->profile;
387 profile_level->level = hfi->level;
393 session_get_prop_buf_req(struct hfi_msg_session_property_info_pkt *pkt,
394 struct hfi_buffer_requirements *bufreq)
396 struct hfi_buffer_requirements *buf_req;
398 unsigned int idx = 0;
400 req_bytes = pkt->shdr.hdr.size - sizeof(*pkt);
402 if (!req_bytes || req_bytes % sizeof(*buf_req) || !pkt->data[1])
404 return HFI_ERR_SESSION_INVALID_PARAMETER;
406 buf_req = (struct hfi_buffer_requirements *)&pkt->data[1];
408 return HFI_ERR_SESSION_INVALID_PARAMETER;
411 memcpy(&bufreq[idx], buf_req, sizeof(*bufreq));
414 if (idx > HFI_BUFFER_TYPE_MAX)
415 return HFI_ERR_SESSION_INVALID_PARAMETER;
417 req_bytes -= sizeof(struct hfi_buffer_requirements);
424 static void hfi_session_prop_info(struct venus_core *core,
425 struct venus_inst *inst, void *packet)
427 struct hfi_msg_session_property_info_pkt *pkt = packet;
428 struct device *dev = core->dev;
429 union hfi_get_property *hprop = &inst->hprop;
430 unsigned int error = HFI_ERR_NONE;
432 if (!pkt->num_properties) {
433 error = HFI_ERR_SESSION_INVALID_PARAMETER;
434 dev_err(dev, "%s: no properties\n", __func__);
438 switch (pkt->data[0]) {
439 case HFI_PROPERTY_CONFIG_BUFFER_REQUIREMENTS:
440 memset(hprop->bufreq, 0, sizeof(hprop->bufreq));
441 error = session_get_prop_buf_req(pkt, hprop->bufreq);
443 case HFI_PROPERTY_PARAM_PROFILE_LEVEL_CURRENT:
444 memset(&hprop->profile_level, 0, sizeof(hprop->profile_level));
445 error = session_get_prop_profile_level(pkt,
446 &hprop->profile_level);
448 case HFI_PROPERTY_CONFIG_VDEC_ENTROPY:
451 dev_dbg(dev, "%s: unknown property id:%x\n", __func__,
458 complete(&inst->done);
461 static u32 init_done_read_prop(struct venus_core *core, struct venus_inst *inst,
462 struct hfi_msg_session_init_done_pkt *pkt)
464 struct device *dev = core->dev;
465 u32 rem_bytes, num_props;
466 u32 ptype, next_offset = 0;
470 rem_bytes = pkt->shdr.hdr.size - sizeof(*pkt) + sizeof(u32);
472 dev_err(dev, "%s: missing property info\n", __func__);
473 return HFI_ERR_SESSION_INSUFFICIENT_RESOURCES;
476 err = pkt->error_type;
480 data = (u8 *)&pkt->data[0];
481 num_props = pkt->num_properties;
483 while (err == HFI_ERR_NONE && num_props && rem_bytes >= sizeof(u32)) {
484 ptype = *((u32 *)data);
485 next_offset = sizeof(u32);
488 case HFI_PROPERTY_PARAM_CODEC_MASK_SUPPORTED: {
489 struct hfi_codec_mask_supported *masks =
490 (struct hfi_codec_mask_supported *)
491 (data + next_offset);
493 next_offset += sizeof(*masks);
497 case HFI_PROPERTY_PARAM_CAPABILITY_SUPPORTED: {
498 struct hfi_capabilities *caps;
499 struct hfi_capability *cap;
502 if ((rem_bytes - next_offset) < sizeof(*cap)) {
503 err = HFI_ERR_SESSION_INVALID_PARAMETER;
507 caps = (struct hfi_capabilities *)(data + next_offset);
509 num_caps = caps->num_capabilities;
510 cap = &caps->data[0];
511 next_offset += sizeof(u32);
514 (rem_bytes - next_offset) >= sizeof(u32)) {
515 hfi_copy_cap_prop(cap, inst);
517 next_offset += sizeof(*cap);
523 case HFI_PROPERTY_PARAM_UNCOMPRESSED_FORMAT_SUPPORTED: {
524 struct hfi_uncompressed_format_supported *prop =
525 (struct hfi_uncompressed_format_supported *)
526 (data + next_offset);
529 struct hfi_uncompressed_plane_info *inf;
531 if ((rem_bytes - next_offset) < sizeof(*prop)) {
532 err = HFI_ERR_SESSION_INVALID_PARAMETER;
536 num_fmt_entries = prop->format_entries;
537 next_offset = sizeof(*prop) - sizeof(u32);
538 fmt = (u8 *)&prop->format_info[0];
540 dev_dbg(dev, "uncomm format support num entries:%u\n",
543 while (num_fmt_entries) {
544 struct hfi_uncompressed_plane_constraints *cnts;
547 inf = (struct hfi_uncompressed_plane_info *)fmt;
549 if ((rem_bytes - next_offset) < sizeof(*inf)) {
550 err = HFI_ERR_SESSION_INVALID_PARAMETER;
554 dev_dbg(dev, "plane info: fmt:%x, planes:%x\n",
555 inf->format, inf->num_planes);
557 cnts = &inf->plane_format[0];
558 dev_dbg(dev, "%u %u %u %u\n",
559 cnts->stride_multiples,
561 cnts->min_plane_buffer_height_multiple,
562 cnts->buffer_alignment);
564 bytes_to_skip = sizeof(*inf) - sizeof(*cnts) +
565 inf->num_planes * sizeof(*cnts);
567 fmt += bytes_to_skip;
568 next_offset += bytes_to_skip;
574 case HFI_PROPERTY_PARAM_PROPERTIES_SUPPORTED: {
575 struct hfi_properties_supported *prop =
576 (struct hfi_properties_supported *)
577 (data + next_offset);
579 next_offset += sizeof(*prop) - sizeof(u32)
580 + prop->num_properties * sizeof(u32);
584 case HFI_PROPERTY_PARAM_PROFILE_LEVEL_SUPPORTED: {
585 struct hfi_profile_level_supported *prop =
586 (struct hfi_profile_level_supported *)
587 (data + next_offset);
588 struct hfi_profile_level *pl;
589 unsigned int prop_count = 0;
590 unsigned int count = 0;
593 ptr = (u8 *)&prop->profile_level[0];
594 prop_count = prop->profile_count;
596 if (prop_count > HFI_MAX_PROFILE_COUNT)
597 prop_count = HFI_MAX_PROFILE_COUNT;
601 pl = (struct hfi_profile_level *)ptr;
603 inst->pl[count].profile = pl->profile;
604 inst->pl[count].level = pl->level;
607 ptr += sizeof(*pl) / sizeof(u32);
610 inst->pl_count = count;
611 next_offset += sizeof(*prop) - sizeof(*pl) +
612 prop->profile_count * sizeof(*pl);
617 case HFI_PROPERTY_PARAM_INTERLACE_FORMAT_SUPPORTED: {
619 sizeof(struct hfi_interlace_format_supported);
623 case HFI_PROPERTY_PARAM_NAL_STREAM_FORMAT_SUPPORTED: {
624 struct hfi_nal_stream_format *nal =
625 (struct hfi_nal_stream_format *)
626 (data + next_offset);
627 dev_dbg(dev, "NAL format: %x\n", nal->format);
628 next_offset += sizeof(*nal);
632 case HFI_PROPERTY_PARAM_NAL_STREAM_FORMAT_SELECT: {
633 next_offset += sizeof(u32);
637 case HFI_PROPERTY_PARAM_MAX_SEQUENCE_HEADER_SIZE: {
638 u32 *max_seq_sz = (u32 *)(data + next_offset);
640 dev_dbg(dev, "max seq header sz: %x\n", *max_seq_sz);
641 next_offset += sizeof(u32);
645 case HFI_PROPERTY_PARAM_VENC_INTRA_REFRESH: {
646 next_offset += sizeof(struct hfi_intra_refresh);
650 case HFI_PROPERTY_PARAM_BUFFER_ALLOC_MODE_SUPPORTED: {
651 struct hfi_buffer_alloc_mode_supported *prop =
652 (struct hfi_buffer_alloc_mode_supported *)
653 (data + next_offset);
656 for (i = 0; i < prop->num_entries; i++) {
657 if (prop->buffer_type == HFI_BUFFER_OUTPUT ||
658 prop->buffer_type == HFI_BUFFER_OUTPUT2) {
659 switch (prop->data[i]) {
660 case HFI_BUFFER_MODE_STATIC:
661 inst->cap_bufs_mode_static = 1;
663 case HFI_BUFFER_MODE_DYNAMIC:
664 inst->cap_bufs_mode_dynamic = 1;
671 next_offset += sizeof(*prop) -
672 sizeof(u32) + prop->num_entries * sizeof(u32);
677 dev_dbg(dev, "%s: default case %#x\n", __func__, ptype);
681 rem_bytes -= next_offset;
688 static void hfi_session_init_done(struct venus_core *core,
689 struct venus_inst *inst, void *packet)
691 struct hfi_msg_session_init_done_pkt *pkt = packet;
694 error = pkt->error_type;
695 if (error != HFI_ERR_NONE)
698 if (core->res->hfi_version != HFI_VERSION_1XX)
701 error = init_done_read_prop(core, inst, pkt);
705 complete(&inst->done);
708 static void hfi_session_load_res_done(struct venus_core *core,
709 struct venus_inst *inst, void *packet)
711 struct hfi_msg_session_load_resources_done_pkt *pkt = packet;
713 inst->error = pkt->error_type;
714 complete(&inst->done);
717 static void hfi_session_flush_done(struct venus_core *core,
718 struct venus_inst *inst, void *packet)
720 struct hfi_msg_session_flush_done_pkt *pkt = packet;
722 inst->error = pkt->error_type;
723 complete(&inst->done);
726 static void hfi_session_etb_done(struct venus_core *core,
727 struct venus_inst *inst, void *packet)
729 struct hfi_msg_session_empty_buffer_done_pkt *pkt = packet;
731 inst->error = pkt->error_type;
732 inst->ops->buf_done(inst, HFI_BUFFER_INPUT, pkt->input_tag,
733 pkt->filled_len, pkt->offset, 0, 0, 0);
736 static void hfi_session_ftb_done(struct venus_core *core,
737 struct venus_inst *inst, void *packet)
739 u32 session_type = inst->session_type;
740 u64 timestamp_us = 0;
741 u32 timestamp_hi = 0, timestamp_lo = 0;
743 u32 flags = 0, hfi_flags = 0, offset = 0, filled_len = 0;
744 u32 pic_type = 0, buffer_type = 0, output_tag = -1;
746 if (session_type == VIDC_SESSION_TYPE_ENC) {
747 struct hfi_msg_session_fbd_compressed_pkt *pkt = packet;
749 timestamp_hi = pkt->time_stamp_hi;
750 timestamp_lo = pkt->time_stamp_lo;
751 hfi_flags = pkt->flags;
752 offset = pkt->offset;
753 filled_len = pkt->filled_len;
754 pic_type = pkt->picture_type;
755 output_tag = pkt->output_tag;
756 buffer_type = HFI_BUFFER_OUTPUT;
758 error = pkt->error_type;
759 } else if (session_type == VIDC_SESSION_TYPE_DEC) {
760 struct hfi_msg_session_fbd_uncompressed_plane0_pkt *pkt =
763 timestamp_hi = pkt->time_stamp_hi;
764 timestamp_lo = pkt->time_stamp_lo;
765 hfi_flags = pkt->flags;
766 offset = pkt->offset;
767 filled_len = pkt->filled_len;
768 pic_type = pkt->picture_type;
769 output_tag = pkt->output_tag;
771 if (pkt->stream_id == 0)
772 buffer_type = HFI_BUFFER_OUTPUT;
773 else if (pkt->stream_id == 1)
774 buffer_type = HFI_BUFFER_OUTPUT2;
776 error = pkt->error_type;
778 error = HFI_ERR_SESSION_INVALID_PARAMETER;
781 if (buffer_type != HFI_BUFFER_OUTPUT)
784 if (hfi_flags & HFI_BUFFERFLAG_EOS)
785 flags |= V4L2_BUF_FLAG_LAST;
788 case HFI_PICTURE_IDR:
790 flags |= V4L2_BUF_FLAG_KEYFRAME;
793 flags |= V4L2_BUF_FLAG_PFRAME;
796 flags |= V4L2_BUF_FLAG_BFRAME;
798 case HFI_FRAME_NOTCODED:
799 case HFI_UNUSED_PICT:
805 if (!(hfi_flags & HFI_BUFFERFLAG_TIMESTAMPINVALID) && filled_len) {
806 timestamp_us = timestamp_hi;
807 timestamp_us = (timestamp_us << 32) | timestamp_lo;
812 inst->ops->buf_done(inst, buffer_type, output_tag, filled_len,
813 offset, flags, hfi_flags, timestamp_us);
816 static void hfi_session_start_done(struct venus_core *core,
817 struct venus_inst *inst, void *packet)
819 struct hfi_msg_session_start_done_pkt *pkt = packet;
821 inst->error = pkt->error_type;
822 complete(&inst->done);
825 static void hfi_session_stop_done(struct venus_core *core,
826 struct venus_inst *inst, void *packet)
828 struct hfi_msg_session_stop_done_pkt *pkt = packet;
830 inst->error = pkt->error_type;
831 complete(&inst->done);
834 static void hfi_session_rel_res_done(struct venus_core *core,
835 struct venus_inst *inst, void *packet)
837 struct hfi_msg_session_release_resources_done_pkt *pkt = packet;
839 inst->error = pkt->error_type;
840 complete(&inst->done);
843 static void hfi_session_rel_buf_done(struct venus_core *core,
844 struct venus_inst *inst, void *packet)
846 struct hfi_msg_session_release_buffers_done_pkt *pkt = packet;
848 inst->error = pkt->error_type;
849 complete(&inst->done);
852 static void hfi_session_end_done(struct venus_core *core,
853 struct venus_inst *inst, void *packet)
855 struct hfi_msg_session_end_done_pkt *pkt = packet;
857 inst->error = pkt->error_type;
858 complete(&inst->done);
861 static void hfi_session_abort_done(struct venus_core *core,
862 struct venus_inst *inst, void *packet)
864 struct hfi_msg_sys_session_abort_done_pkt *pkt = packet;
866 inst->error = pkt->error_type;
867 complete(&inst->done);
870 static void hfi_session_get_seq_hdr_done(struct venus_core *core,
871 struct venus_inst *inst, void *packet)
873 struct hfi_msg_session_get_sequence_hdr_done_pkt *pkt = packet;
875 inst->error = pkt->error_type;
876 complete(&inst->done);
879 struct hfi_done_handler {
883 void (*done)(struct venus_core *, struct venus_inst *, void *);
887 static const struct hfi_done_handler handlers[] = {
888 {.pkt = HFI_MSG_EVENT_NOTIFY,
889 .pkt_sz = sizeof(struct hfi_msg_event_notify_pkt),
890 .done = hfi_event_notify,
892 {.pkt = HFI_MSG_SYS_INIT,
893 .pkt_sz = sizeof(struct hfi_msg_sys_init_done_pkt),
894 .done = hfi_sys_init_done,
897 {.pkt = HFI_MSG_SYS_PROPERTY_INFO,
898 .pkt_sz = sizeof(struct hfi_msg_sys_property_info_pkt),
899 .done = hfi_sys_property_info,
902 {.pkt = HFI_MSG_SYS_RELEASE_RESOURCE,
903 .pkt_sz = sizeof(struct hfi_msg_sys_release_resource_done_pkt),
904 .done = hfi_sys_rel_resource_done,
907 {.pkt = HFI_MSG_SYS_PING_ACK,
908 .pkt_sz = sizeof(struct hfi_msg_sys_ping_ack_pkt),
909 .done = hfi_sys_ping_done,
912 {.pkt = HFI_MSG_SYS_IDLE,
913 .pkt_sz = sizeof(struct hfi_msg_sys_idle_pkt),
914 .done = hfi_sys_idle_done,
917 {.pkt = HFI_MSG_SYS_PC_PREP,
918 .pkt_sz = sizeof(struct hfi_msg_sys_pc_prep_done_pkt),
919 .done = hfi_sys_pc_prepare_done,
922 {.pkt = HFI_MSG_SYS_SESSION_INIT,
923 .pkt_sz = sizeof(struct hfi_msg_session_init_done_pkt),
924 .done = hfi_session_init_done,
926 {.pkt = HFI_MSG_SYS_SESSION_END,
927 .pkt_sz = sizeof(struct hfi_msg_session_end_done_pkt),
928 .done = hfi_session_end_done,
930 {.pkt = HFI_MSG_SESSION_LOAD_RESOURCES,
931 .pkt_sz = sizeof(struct hfi_msg_session_load_resources_done_pkt),
932 .done = hfi_session_load_res_done,
934 {.pkt = HFI_MSG_SESSION_START,
935 .pkt_sz = sizeof(struct hfi_msg_session_start_done_pkt),
936 .done = hfi_session_start_done,
938 {.pkt = HFI_MSG_SESSION_STOP,
939 .pkt_sz = sizeof(struct hfi_msg_session_stop_done_pkt),
940 .done = hfi_session_stop_done,
942 {.pkt = HFI_MSG_SYS_SESSION_ABORT,
943 .pkt_sz = sizeof(struct hfi_msg_sys_session_abort_done_pkt),
944 .done = hfi_session_abort_done,
946 {.pkt = HFI_MSG_SESSION_EMPTY_BUFFER,
947 .pkt_sz = sizeof(struct hfi_msg_session_empty_buffer_done_pkt),
948 .done = hfi_session_etb_done,
950 {.pkt = HFI_MSG_SESSION_FILL_BUFFER,
951 .pkt_sz = sizeof(struct hfi_msg_session_fbd_uncompressed_plane0_pkt),
952 .pkt_sz2 = sizeof(struct hfi_msg_session_fbd_compressed_pkt),
953 .done = hfi_session_ftb_done,
955 {.pkt = HFI_MSG_SESSION_FLUSH,
956 .pkt_sz = sizeof(struct hfi_msg_session_flush_done_pkt),
957 .done = hfi_session_flush_done,
959 {.pkt = HFI_MSG_SESSION_PROPERTY_INFO,
960 .pkt_sz = sizeof(struct hfi_msg_session_property_info_pkt),
961 .done = hfi_session_prop_info,
963 {.pkt = HFI_MSG_SESSION_RELEASE_RESOURCES,
964 .pkt_sz = sizeof(struct hfi_msg_session_release_resources_done_pkt),
965 .done = hfi_session_rel_res_done,
967 {.pkt = HFI_MSG_SESSION_GET_SEQUENCE_HEADER,
968 .pkt_sz = sizeof(struct hfi_msg_session_get_sequence_hdr_done_pkt),
969 .done = hfi_session_get_seq_hdr_done,
971 {.pkt = HFI_MSG_SESSION_RELEASE_BUFFERS,
972 .pkt_sz = sizeof(struct hfi_msg_session_release_buffers_done_pkt),
973 .done = hfi_session_rel_buf_done,
977 void hfi_process_watchdog_timeout(struct venus_core *core)
979 event_sys_error(core, EVT_SYS_WATCHDOG_TIMEOUT, NULL);
982 static struct venus_inst *to_instance(struct venus_core *core, u32 session_id)
984 struct venus_inst *inst;
986 mutex_lock(&core->lock);
987 list_for_each_entry(inst, &core->instances, list)
988 if (hash32_ptr(inst) == session_id) {
989 mutex_unlock(&core->lock);
992 mutex_unlock(&core->lock);
997 u32 hfi_process_msg_packet(struct venus_core *core, struct hfi_pkt_hdr *hdr)
999 const struct hfi_done_handler *handler;
1000 struct device *dev = core->dev;
1001 struct venus_inst *inst;
1005 for (i = 0; i < ARRAY_SIZE(handlers); i++) {
1006 handler = &handlers[i];
1007 if (handler->pkt != hdr->pkt_type)
1014 return hdr->pkt_type;
1016 if (hdr->size && hdr->size < handler->pkt_sz &&
1017 hdr->size < handler->pkt_sz2) {
1018 dev_err(dev, "bad packet size (%d should be %d, pkt type:%x)\n",
1019 hdr->size, handler->pkt_sz, hdr->pkt_type);
1021 return hdr->pkt_type;
1024 if (handler->is_sys_pkt) {
1027 struct hfi_session_pkt *pkt;
1029 pkt = (struct hfi_session_pkt *)hdr;
1030 inst = to_instance(core, pkt->shdr.session_id);
1033 dev_warn(dev, "no valid instance(pkt session_id:%x, pkt:%x)\n",
1034 pkt->shdr.session_id,
1035 handler ? handler->pkt : 0);
1038 * Event of type HFI_EVENT_SYS_ERROR will not have any session
1039 * associated with it
1041 if (!inst && hdr->pkt_type != HFI_MSG_EVENT_NOTIFY) {
1042 dev_err(dev, "got invalid session id:%x\n",
1043 pkt->shdr.session_id);
1044 goto invalid_session;
1048 handler->done(core, inst, hdr);
1051 return hdr->pkt_type;