18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: MIT */ 28c2ecf20Sopenharmony_ci#ifndef __NVKM_FALCON_QMGR_H__ 38c2ecf20Sopenharmony_ci#define __NVKM_FALCON_QMGR_H__ 48c2ecf20Sopenharmony_ci#include <core/falcon.h> 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#define HDR_SIZE sizeof(struct nvfw_falcon_msg) 78c2ecf20Sopenharmony_ci#define QUEUE_ALIGNMENT 4 88c2ecf20Sopenharmony_ci/* max size of the messages we can receive */ 98c2ecf20Sopenharmony_ci#define MSG_BUF_SIZE 128 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci/** 128c2ecf20Sopenharmony_ci * struct nvkm_falcon_qmgr_seq - keep track of ongoing commands 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * Every time a command is sent, a sequence is assigned to it so the 158c2ecf20Sopenharmony_ci * corresponding message can be matched. Upon receiving the message, a callback 168c2ecf20Sopenharmony_ci * can be called and/or a completion signaled. 178c2ecf20Sopenharmony_ci * 188c2ecf20Sopenharmony_ci * @id: sequence ID 198c2ecf20Sopenharmony_ci * @state: current state 208c2ecf20Sopenharmony_ci * @callback: callback to call upon receiving matching message 218c2ecf20Sopenharmony_ci * @completion: completion to signal after callback is called 228c2ecf20Sopenharmony_ci */ 238c2ecf20Sopenharmony_cistruct nvkm_falcon_qmgr_seq { 248c2ecf20Sopenharmony_ci u16 id; 258c2ecf20Sopenharmony_ci enum { 268c2ecf20Sopenharmony_ci SEQ_STATE_FREE = 0, 278c2ecf20Sopenharmony_ci SEQ_STATE_PENDING, 288c2ecf20Sopenharmony_ci SEQ_STATE_USED, 298c2ecf20Sopenharmony_ci SEQ_STATE_CANCELLED 308c2ecf20Sopenharmony_ci } state; 318c2ecf20Sopenharmony_ci bool async; 328c2ecf20Sopenharmony_ci nvkm_falcon_qmgr_callback callback; 338c2ecf20Sopenharmony_ci void *priv; 348c2ecf20Sopenharmony_ci struct completion done; 358c2ecf20Sopenharmony_ci int result; 368c2ecf20Sopenharmony_ci}; 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci/* 398c2ecf20Sopenharmony_ci * We can have an arbitrary number of sequences, but realistically we will 408c2ecf20Sopenharmony_ci * probably not use that much simultaneously. 418c2ecf20Sopenharmony_ci */ 428c2ecf20Sopenharmony_ci#define NVKM_FALCON_QMGR_SEQ_NUM 16 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cistruct nvkm_falcon_qmgr { 458c2ecf20Sopenharmony_ci struct nvkm_falcon *falcon; 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci struct { 488c2ecf20Sopenharmony_ci struct mutex mutex; 498c2ecf20Sopenharmony_ci struct nvkm_falcon_qmgr_seq id[NVKM_FALCON_QMGR_SEQ_NUM]; 508c2ecf20Sopenharmony_ci unsigned long tbl[BITS_TO_LONGS(NVKM_FALCON_QMGR_SEQ_NUM)]; 518c2ecf20Sopenharmony_ci } seq; 528c2ecf20Sopenharmony_ci}; 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_cistruct nvkm_falcon_qmgr_seq * 558c2ecf20Sopenharmony_cinvkm_falcon_qmgr_seq_acquire(struct nvkm_falcon_qmgr *); 568c2ecf20Sopenharmony_civoid nvkm_falcon_qmgr_seq_release(struct nvkm_falcon_qmgr *, 578c2ecf20Sopenharmony_ci struct nvkm_falcon_qmgr_seq *); 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_cistruct nvkm_falcon_cmdq { 608c2ecf20Sopenharmony_ci struct nvkm_falcon_qmgr *qmgr; 618c2ecf20Sopenharmony_ci const char *name; 628c2ecf20Sopenharmony_ci struct mutex mutex; 638c2ecf20Sopenharmony_ci struct completion ready; 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci u32 head_reg; 668c2ecf20Sopenharmony_ci u32 tail_reg; 678c2ecf20Sopenharmony_ci u32 offset; 688c2ecf20Sopenharmony_ci u32 size; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci u32 position; 718c2ecf20Sopenharmony_ci}; 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_cistruct nvkm_falcon_msgq { 748c2ecf20Sopenharmony_ci struct nvkm_falcon_qmgr *qmgr; 758c2ecf20Sopenharmony_ci const char *name; 768c2ecf20Sopenharmony_ci struct mutex mutex; 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci u32 head_reg; 798c2ecf20Sopenharmony_ci u32 tail_reg; 808c2ecf20Sopenharmony_ci u32 offset; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci u32 position; 838c2ecf20Sopenharmony_ci}; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci#define FLCNQ_PRINTK(t,q,f,a...) \ 868c2ecf20Sopenharmony_ci FLCN_PRINTK(t, (q)->qmgr->falcon, "%s: "f, (q)->name, ##a) 878c2ecf20Sopenharmony_ci#define FLCNQ_DBG(q,f,a...) FLCNQ_PRINTK(debug, (q), f, ##a) 888c2ecf20Sopenharmony_ci#define FLCNQ_ERR(q,f,a...) FLCNQ_PRINTK(error, (q), f, ##a) 898c2ecf20Sopenharmony_ci#endif 90