162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (c) 2012-2016, The Linux Foundation. All rights reserved. 462306a36Sopenharmony_ci * Copyright (C) 2017 Linaro Ltd. 562306a36Sopenharmony_ci */ 662306a36Sopenharmony_ci#ifndef __HFI_H__ 762306a36Sopenharmony_ci#define __HFI_H__ 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#include <linux/interrupt.h> 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#include "hfi_helper.h" 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci#define VIDC_SESSION_TYPE_VPE 0 1462306a36Sopenharmony_ci#define VIDC_SESSION_TYPE_ENC 1 1562306a36Sopenharmony_ci#define VIDC_SESSION_TYPE_DEC 2 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci#define VIDC_RESOURCE_NONE 0 1862306a36Sopenharmony_ci#define VIDC_RESOURCE_OCMEM 1 1962306a36Sopenharmony_ci#define VIDC_RESOURCE_VMEM 2 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_cistruct hfi_buffer_desc { 2262306a36Sopenharmony_ci u32 buffer_type; 2362306a36Sopenharmony_ci u32 buffer_size; 2462306a36Sopenharmony_ci u32 num_buffers; 2562306a36Sopenharmony_ci u32 device_addr; 2662306a36Sopenharmony_ci u32 extradata_addr; 2762306a36Sopenharmony_ci u32 extradata_size; 2862306a36Sopenharmony_ci u32 response_required; 2962306a36Sopenharmony_ci}; 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_cistruct hfi_frame_data { 3262306a36Sopenharmony_ci u32 buffer_type; 3362306a36Sopenharmony_ci u32 device_addr; 3462306a36Sopenharmony_ci u32 extradata_addr; 3562306a36Sopenharmony_ci u64 timestamp; 3662306a36Sopenharmony_ci u32 flags; 3762306a36Sopenharmony_ci u32 offset; 3862306a36Sopenharmony_ci u32 alloc_len; 3962306a36Sopenharmony_ci u32 filled_len; 4062306a36Sopenharmony_ci u32 mark_target; 4162306a36Sopenharmony_ci u32 mark_data; 4262306a36Sopenharmony_ci u32 clnt_data; 4362306a36Sopenharmony_ci u32 extradata_size; 4462306a36Sopenharmony_ci}; 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ciunion hfi_get_property { 4762306a36Sopenharmony_ci struct hfi_profile_level profile_level; 4862306a36Sopenharmony_ci struct hfi_buffer_requirements bufreq[HFI_BUFFER_TYPE_MAX]; 4962306a36Sopenharmony_ci}; 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci/* HFI events */ 5262306a36Sopenharmony_ci#define EVT_SYS_EVENT_CHANGE 1 5362306a36Sopenharmony_ci#define EVT_SYS_WATCHDOG_TIMEOUT 2 5462306a36Sopenharmony_ci#define EVT_SYS_ERROR 3 5562306a36Sopenharmony_ci#define EVT_SESSION_ERROR 4 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci/* HFI event callback structure */ 5862306a36Sopenharmony_cistruct hfi_event_data { 5962306a36Sopenharmony_ci u32 error; 6062306a36Sopenharmony_ci u32 height; 6162306a36Sopenharmony_ci u32 width; 6262306a36Sopenharmony_ci u32 event_type; 6362306a36Sopenharmony_ci u32 packet_buffer; 6462306a36Sopenharmony_ci u32 extradata_buffer; 6562306a36Sopenharmony_ci u32 tag; 6662306a36Sopenharmony_ci u32 profile; 6762306a36Sopenharmony_ci u32 level; 6862306a36Sopenharmony_ci /* the following properties start appear from v4 onwards */ 6962306a36Sopenharmony_ci u32 bit_depth; 7062306a36Sopenharmony_ci u32 pic_struct; 7162306a36Sopenharmony_ci u32 colour_space; 7262306a36Sopenharmony_ci u32 entropy_mode; 7362306a36Sopenharmony_ci u32 buf_count; 7462306a36Sopenharmony_ci struct { 7562306a36Sopenharmony_ci u32 left, top; 7662306a36Sopenharmony_ci u32 width, height; 7762306a36Sopenharmony_ci } input_crop; 7862306a36Sopenharmony_ci}; 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ci/* define core states */ 8162306a36Sopenharmony_ci#define CORE_UNINIT 0 8262306a36Sopenharmony_ci#define CORE_INIT 1 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci/* define instance states */ 8562306a36Sopenharmony_ci#define INST_UNINIT 2 8662306a36Sopenharmony_ci#define INST_INIT 3 8762306a36Sopenharmony_ci#define INST_LOAD_RESOURCES 4 8862306a36Sopenharmony_ci#define INST_START 5 8962306a36Sopenharmony_ci#define INST_STOP 6 9062306a36Sopenharmony_ci#define INST_RELEASE_RESOURCES 7 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_cistruct venus_core; 9362306a36Sopenharmony_cistruct venus_inst; 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_cistruct hfi_core_ops { 9662306a36Sopenharmony_ci void (*event_notify)(struct venus_core *core, u32 event); 9762306a36Sopenharmony_ci}; 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_cistruct hfi_inst_ops { 10062306a36Sopenharmony_ci void (*buf_done)(struct venus_inst *inst, unsigned int buf_type, 10162306a36Sopenharmony_ci u32 tag, u32 bytesused, u32 data_offset, u32 flags, 10262306a36Sopenharmony_ci u32 hfi_flags, u64 timestamp_us); 10362306a36Sopenharmony_ci void (*event_notify)(struct venus_inst *inst, u32 event, 10462306a36Sopenharmony_ci struct hfi_event_data *data); 10562306a36Sopenharmony_ci void (*flush_done)(struct venus_inst *inst); 10662306a36Sopenharmony_ci}; 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_cistruct hfi_ops { 10962306a36Sopenharmony_ci int (*core_init)(struct venus_core *core); 11062306a36Sopenharmony_ci int (*core_deinit)(struct venus_core *core); 11162306a36Sopenharmony_ci int (*core_ping)(struct venus_core *core, u32 cookie); 11262306a36Sopenharmony_ci int (*core_trigger_ssr)(struct venus_core *core, u32 trigger_type); 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ci int (*session_init)(struct venus_inst *inst, u32 session_type, 11562306a36Sopenharmony_ci u32 codec); 11662306a36Sopenharmony_ci int (*session_end)(struct venus_inst *inst); 11762306a36Sopenharmony_ci int (*session_abort)(struct venus_inst *inst); 11862306a36Sopenharmony_ci int (*session_flush)(struct venus_inst *inst, u32 flush_mode); 11962306a36Sopenharmony_ci int (*session_start)(struct venus_inst *inst); 12062306a36Sopenharmony_ci int (*session_stop)(struct venus_inst *inst); 12162306a36Sopenharmony_ci int (*session_continue)(struct venus_inst *inst); 12262306a36Sopenharmony_ci int (*session_etb)(struct venus_inst *inst, struct hfi_frame_data *fd); 12362306a36Sopenharmony_ci int (*session_ftb)(struct venus_inst *inst, struct hfi_frame_data *fd); 12462306a36Sopenharmony_ci int (*session_set_buffers)(struct venus_inst *inst, 12562306a36Sopenharmony_ci struct hfi_buffer_desc *bd); 12662306a36Sopenharmony_ci int (*session_unset_buffers)(struct venus_inst *inst, 12762306a36Sopenharmony_ci struct hfi_buffer_desc *bd); 12862306a36Sopenharmony_ci int (*session_load_res)(struct venus_inst *inst); 12962306a36Sopenharmony_ci int (*session_release_res)(struct venus_inst *inst); 13062306a36Sopenharmony_ci int (*session_parse_seq_hdr)(struct venus_inst *inst, u32 seq_hdr, 13162306a36Sopenharmony_ci u32 seq_hdr_len); 13262306a36Sopenharmony_ci int (*session_get_seq_hdr)(struct venus_inst *inst, u32 seq_hdr, 13362306a36Sopenharmony_ci u32 seq_hdr_len); 13462306a36Sopenharmony_ci int (*session_set_property)(struct venus_inst *inst, u32 ptype, 13562306a36Sopenharmony_ci void *pdata); 13662306a36Sopenharmony_ci int (*session_get_property)(struct venus_inst *inst, u32 ptype); 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ci int (*resume)(struct venus_core *core); 13962306a36Sopenharmony_ci int (*suspend)(struct venus_core *core); 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_ci /* interrupt operations */ 14262306a36Sopenharmony_ci irqreturn_t (*isr)(struct venus_core *core); 14362306a36Sopenharmony_ci irqreturn_t (*isr_thread)(struct venus_core *core); 14462306a36Sopenharmony_ci}; 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_ciint hfi_create(struct venus_core *core, const struct hfi_core_ops *ops); 14762306a36Sopenharmony_civoid hfi_destroy(struct venus_core *core); 14862306a36Sopenharmony_civoid hfi_reinit(struct venus_core *core); 14962306a36Sopenharmony_ci 15062306a36Sopenharmony_ciint hfi_core_init(struct venus_core *core); 15162306a36Sopenharmony_ciint hfi_core_deinit(struct venus_core *core, bool blocking); 15262306a36Sopenharmony_ciint hfi_core_suspend(struct venus_core *core); 15362306a36Sopenharmony_ciint hfi_core_resume(struct venus_core *core, bool force); 15462306a36Sopenharmony_ciint hfi_core_trigger_ssr(struct venus_core *core, u32 type); 15562306a36Sopenharmony_ciint hfi_core_ping(struct venus_core *core); 15662306a36Sopenharmony_ciint hfi_session_create(struct venus_inst *inst, const struct hfi_inst_ops *ops); 15762306a36Sopenharmony_civoid hfi_session_destroy(struct venus_inst *inst); 15862306a36Sopenharmony_ciint hfi_session_init(struct venus_inst *inst, u32 pixfmt); 15962306a36Sopenharmony_ciint hfi_session_deinit(struct venus_inst *inst); 16062306a36Sopenharmony_ciint hfi_session_start(struct venus_inst *inst); 16162306a36Sopenharmony_ciint hfi_session_stop(struct venus_inst *inst); 16262306a36Sopenharmony_ciint hfi_session_continue(struct venus_inst *inst); 16362306a36Sopenharmony_ciint hfi_session_abort(struct venus_inst *inst); 16462306a36Sopenharmony_ciint hfi_session_load_res(struct venus_inst *inst); 16562306a36Sopenharmony_ciint hfi_session_unload_res(struct venus_inst *inst); 16662306a36Sopenharmony_ciint hfi_session_flush(struct venus_inst *inst, u32 type, bool block); 16762306a36Sopenharmony_ciint hfi_session_set_buffers(struct venus_inst *inst, 16862306a36Sopenharmony_ci struct hfi_buffer_desc *bd); 16962306a36Sopenharmony_ciint hfi_session_unset_buffers(struct venus_inst *inst, 17062306a36Sopenharmony_ci struct hfi_buffer_desc *bd); 17162306a36Sopenharmony_ciint hfi_session_get_property(struct venus_inst *inst, u32 ptype, 17262306a36Sopenharmony_ci union hfi_get_property *hprop); 17362306a36Sopenharmony_ciint hfi_session_set_property(struct venus_inst *inst, u32 ptype, void *pdata); 17462306a36Sopenharmony_ciint hfi_session_process_buf(struct venus_inst *inst, struct hfi_frame_data *f); 17562306a36Sopenharmony_ciirqreturn_t hfi_isr_thread(int irq, void *dev_id); 17662306a36Sopenharmony_ciirqreturn_t hfi_isr(int irq, void *dev); 17762306a36Sopenharmony_ci 17862306a36Sopenharmony_ci#endif 179