1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2018-2020 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23 
24 #ifndef _HALDEFS_FLCN_NVSWITCH_H_
25 #define _HALDEFS_FLCN_NVSWITCH_H_
26 
27 
28 #include "nvstatus.h"
29 #include "flcn/flcnqueue_nvswitch.h"
30 #include "flcnifcmn.h"
31 
32 struct nvswitch_device;
33 struct NVSWITCH_TIMEOUT;
34 struct FLCN;
35 union  RM_FLCN_MSG;
36 union  RM_FLCN_CMD;
37 struct FLCNQUEUE;
38 struct FLCN_QMGR_SEQ_INFO;
39 
40 typedef struct {
41     // OBJECT Interfaces
42     NV_STATUS   (*queueReadData)                    (struct nvswitch_device *, struct FLCN *, NvU32 queueId, void *pData, NvBool bMsg);
43     NV_STATUS   (*queueCmdWrite)                    (struct nvswitch_device *, struct FLCN *, NvU32 queueId, union RM_FLCN_CMD *pCmd, struct NVSWITCH_TIMEOUT *pTimeout);
44     NV_STATUS   (*queueCmdCancel)                   (struct nvswitch_device *, struct FLCN *, NvU32 seqDesc);
45     NV_STATUS   (*queueCmdPostNonBlocking)          (struct nvswitch_device *, struct FLCN *, union RM_FLCN_CMD *pCmd, union RM_FLCN_MSG *pMsg, void *pPayload, NvU32 queueIdLogical, FlcnQMgrClientCallback pCallback, void *pCallbackParams, NvU32 *pSeqDesc, struct NVSWITCH_TIMEOUT *pTimeout);
46     NV_STATUS   (*queueCmdWait)                     (struct nvswitch_device *, struct FLCN *, NvU32 seqDesc, struct NVSWITCH_TIMEOUT *pTimeout);
47     NvU8        (*coreRevisionGet)                  (struct nvswitch_device *, struct FLCN *);
48     void        (*markNotReady)                     (struct nvswitch_device *, struct FLCN *);
49     NV_STATUS   (*cmdQueueHeadGet)                  (struct nvswitch_device *, struct FLCN *, struct FLCNQUEUE *pQueue, NvU32 *pHead);
50     NV_STATUS   (*msgQueueHeadGet)                  (struct nvswitch_device *, struct FLCN *, struct FLCNQUEUE *pQueue, NvU32 *pHead);
51     NV_STATUS   (*cmdQueueTailGet)                  (struct nvswitch_device *, struct FLCN *, struct FLCNQUEUE *pQueue, NvU32 *pTail);
52     NV_STATUS   (*msgQueueTailGet)                  (struct nvswitch_device *, struct FLCN *, struct FLCNQUEUE *pQueue, NvU32 *pTail);
53     NV_STATUS   (*cmdQueueHeadSet)                  (struct nvswitch_device *, struct FLCN *, struct FLCNQUEUE *pQueue, NvU32 head);
54     NV_STATUS   (*msgQueueHeadSet)                  (struct nvswitch_device *, struct FLCN *, struct FLCNQUEUE *pQueue, NvU32 head);
55     NV_STATUS   (*cmdQueueTailSet)                  (struct nvswitch_device *, struct FLCN *, struct FLCNQUEUE *pQueue, NvU32 tail);
56     NV_STATUS   (*msgQueueTailSet)                  (struct nvswitch_device *, struct FLCN *, struct FLCNQUEUE *pQueue, NvU32 tail);
57     struct FLCN_QMGR_SEQ_INFO *(*queueSeqInfoFind)  (struct nvswitch_device *, struct FLCN *, NvU32 seqDesc);
58     struct FLCN_QMGR_SEQ_INFO *(*queueSeqInfoAcq)   (struct nvswitch_device *, struct FLCN *);
59     void        (*queueSeqInfoRel)                  (struct nvswitch_device *, struct FLCN *, struct FLCN_QMGR_SEQ_INFO *pSeqInfo);
60     void        (*queueSeqInfoStateInit)            (struct nvswitch_device *, struct FLCN *);
61     void        (*queueSeqInfoCancelAll)            (struct nvswitch_device *, struct FLCN *);
62     NV_STATUS   (*queueSeqInfoFree)                 (struct nvswitch_device *, struct FLCN *, struct FLCN_QMGR_SEQ_INFO *);
63     NV_STATUS   (*queueEventRegister)               (struct nvswitch_device *, struct FLCN *, NvU32 unitId, NvU8 *pMsg, FlcnQMgrClientCallback pCallback, void *pParams, NvU32 *pEvtDesc);
64     NV_STATUS   (*queueEventUnregister)             (struct nvswitch_device *, struct FLCN *, NvU32 evtDesc);
65     NV_STATUS   (*queueEventHandle)                 (struct nvswitch_device *, struct FLCN *, union RM_FLCN_MSG *pMsg, NV_STATUS evtStatus);
66     NV_STATUS   (*queueResponseHandle)              (struct nvswitch_device *, struct FLCN *, union RM_FLCN_MSG *pMsg);
67     NvU32       (*queueCmdStatus)                   (struct nvswitch_device *, struct FLCN *, NvU32 seqDesc);
68     NV_STATUS   (*dmemCopyFrom)                     (struct nvswitch_device *, struct FLCN *, NvU32 src, NvU8 *pDst, NvU32 sizeBytes, NvU8 port);
69     NV_STATUS   (*dmemCopyTo)                       (struct nvswitch_device *, struct FLCN *, NvU32 dst, NvU8 *pSrc, NvU32 sizeBytes, NvU8 port);
70     void        (*postDiscoveryInit)                (struct nvswitch_device *, struct FLCN *);
71     void        (*dbgInfoDmemOffsetSet)             (struct nvswitch_device *, struct FLCN *, NvU16 debugInfoDmemOffset);
72 
73 
74     //HAL Interfaces
75     NV_STATUS   (*construct)                        (struct nvswitch_device *, struct FLCN *);
76     void        (*destruct)                         (struct nvswitch_device *, struct FLCN *);
77     NvU32       (*regRead)                          (struct nvswitch_device *, struct FLCN *, NvU32 offset);
78     void        (*regWrite)                         (struct nvswitch_device *, struct FLCN *, NvU32 offset, NvU32 data);
79     const char *(*getName)                          (struct nvswitch_device *, struct FLCN *);
80     NvU8        (*readCoreRev)                      (struct nvswitch_device *, struct FLCN *);
81     void        (*getCoreInfo)                      (struct nvswitch_device *, struct FLCN *);
82     NV_STATUS   (*dmemTransfer)                     (struct nvswitch_device *, struct FLCN *, NvU32 src, NvU8 *pDst, NvU32 sizeBytes, NvU8 port, NvBool bCopyFrom);
83     void        (*intrRetrigger)                    (struct nvswitch_device *, struct FLCN *);
84     NvBool      (*areEngDescsInitialized)           (struct nvswitch_device *, struct FLCN *);
85     NV_STATUS   (*waitForResetToFinish)             (struct nvswitch_device *, struct FLCN *);
86     void        (*dbgInfoCapturePcTrace)            (struct nvswitch_device *, struct FLCN *);
87     void        (*dbgInfoCaptureRiscvPcTrace)       (struct nvswitch_device *, struct FLCN *);
88     NvU32       (*dmemSize)                         (struct nvswitch_device *, struct FLCN *);
89     NvU32       (*setImemAddr)                      (struct nvswitch_device *, struct FLCN *, NvU32 dst);
90     void        (*imemCopyTo)                       (struct nvswitch_device *, struct FLCN *, NvU32 dst, NvU8 *pSrc, NvU32 sizeBytes, NvBool bSecure, NvU32 tag, NvU8 port);
91     NvU32       (*setDmemAddr)                      (struct nvswitch_device *, struct FLCN *, NvU32 dst);
92     NvU32       (*riscvRegRead)                     (struct nvswitch_device *, struct FLCN *, NvU32 offset);
93     void        (*riscvRegWrite)                    (struct nvswitch_device *, struct FLCN *, NvU32 offset, NvU32 data);
94     NV_STATUS   (*debugBufferInit)                  (struct nvswitch_device *, struct FLCN *, NvU32 debugBufferMaxSize, NvU32 writeRegAddr, NvU32 readRegAddr);
95     NV_STATUS   (*debugBufferDestroy)               (struct nvswitch_device *, struct FLCN *);
96     NV_STATUS   (*debugBufferDisplay)               (struct nvswitch_device *, struct FLCN *);
97     NvBool      (*debugBufferIsEmpty)               (struct nvswitch_device *, struct FLCN *);
98 } flcn_hal;
99 
100 void flcnQueueSetupHal(struct FLCN *pFlcn);
101 void flcnRtosSetupHal(struct FLCN *pFlcn);
102 void flcnQueueRdSetupHal(struct FLCN *pFlcn);
103 
104 void flcnSetupHal_LS10(struct FLCN *pFlcn);
105 void flcnSetupHal_LR10(struct FLCN *pFlcn);
106 
107 void flcnSetupHal_v03_00(struct FLCN *pFlcn);
108 void flcnSetupHal_v04_00(struct FLCN *pFlcn);
109 void flcnSetupHal_v05_01(struct FLCN *pFlcn);
110 void flcnSetupHal_v06_00(struct FLCN *pFlcn);
111 
112 #endif //_HALDEFS_FLCN_NVSWITCH_H_
113