1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2021 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 VBLANK_H
25 #define VBLANK_H
26 
27 #include "gpu/gpu.h"
28 /* ------------------------ Types definitions ------------------------------ */
29 /*!
30  * Callback function prototype
31  */
32 typedef NV_STATUS (*VBLANKCALLBACKPROC)(OBJGPU*, void *, NvU32, NvU32, NV_STATUS);
33 
34 typedef struct VBLANKCALLBACK
35 {
36     VBLANKCALLBACKPROC Proc;
37     void              *pObject;
38     NvBool             bObjectIsChannelDescendant;
39     NvU32              Param1;
40     NvU32              Param2;
41     NvU32              VBlankCount;
42     NvU32              VBlankOffset;
43     NvU64              TimeStamp;
44     NvU32              MC_CallbackFlag;
45     NvU32              Flags;
46     NV_STATUS          Status;
47     struct VBLANKCALLBACK *Next;
48     NvBool             bImmediateCallback;
49     NvBool             bIsVblankNotifyEnable;
50 }VBLANKCALLBACK;
51 
52 /* ------------------------ Macros & Defines ------------------------------- */
53 
54 /*!
55  * Callback function registration flags
56  */
57 #define VBLANK_CALLBACK_FLAG_SPECIFIED_VBLANK_COUNT        0x00000001
58 #define VBLANK_CALLBACK_FLAG_COMPLETE_ON_OBJECT_CLEANUP    0x00000002
59 #define VBLANK_CALLBACK_FLAG_PERSISTENT                    0x00000004
60 #define VBLANK_CALLBACK_FLAG_SPECIFIED_TIMESTAMP           0x00000010
61 #define VBLANK_CALLBACK_FLAG_SPECIFIED_VBLANK_NEXT         0x00000020  // Explicit request for the next vblank.
62 #define VBLANK_CALLBACK_FLAG_SPECIFIED_VBLANK_OFFSET       0x00000040  // Explicit request for the vblank offset from the current one
63 #define VBLANK_CALLBACK_FLAG_PROMOTE_TO_FRONT              0x00000080  // Promotes to being 'first', while still honoring VBlankCount
64 #define VBLANK_CALLBACK_FLAG_RELEASES_SEMAPHORE            0x00000100  // A flag for deadlock detection to check if this callback could release a semaphore
65 #define VBLANK_CALLBACK_FLAG_GUARANTEE_SAFETY              0x00000200  // This callback absolutely needs to run during vertical blank, even if it runs late as a consequence.
66 #define VBLANK_CALLBACK_FLAG_LOW_LATENCY__ISR_ONLY         0x08000000  // This means always process during ISR (never DPC.) Be careful!
67 #define VBLANK_CALLBACK_FLAG_LOW_LATENCY                   0x10000000  // This now means ASAP, which could be ISR or DPC, depending on which happens first
68 #define VBLANK_CALLBACK_FLAG_MC_EXECUTE_ONCE               0x40000000  // A special flag for MultiChip configurations to have the callback execute only once
69 #define VBLANK_CALLBACK_FLAG_USER                          0x80000000
70 
71 /*!
72  * A little macro help for the CALLBACK_FLAG_MC_EXECUTE_ONCE flag above
73  */
74 #define VBLANK_CALLBACK_EXECUTE_ONCE(x)    (x & VBLANK_CALLBACK_FLAG_MC_EXECUTE_ONCE)
75 
76 /*!
77  * VBlank Service info gathering keep-alive in seconds. This value is the number of seconds the vblank service will run after a client request vblank info.
78  */
79 #define VBLANK_INFO_GATHER_KEEPALIVE_SECONDS    (5)
80 
81 /*!
82  * VBLANK SERVICE RELATED
83  * VBlank Service callback processing flags
84  * These two flags describe when to process the queues
85  */
86 
87 #define VBLANK_STATE_PROCESS_NORMAL                  (0x00000000)    // Process the requested queues if associated vblank interrupt is pending
88 #define VBLANK_STATE_PROCESS_IMMEDIATE               (0x00000001)    // Process the requested queues now, regardless of any vblank interrupt pending state
89 
90 /*!
91  * These three flags describe which queues to process
92  */
93 #define VBLANK_STATE_PROCESS_LOW_LATENCY             (0x00000002)    // Process the low-latency vblank callback queue
94 #define VBLANK_STATE_PROCESS_NORMAL_LATENCY          (0x00000004)    // Process the normal-latency vblank callback queue
95 
96 #define VBLANK_STATE_PROCESS_ALL_CALLBACKS           (VBLANK_STATE_PROCESS_LOW_LATENCY|VBLANK_STATE_PROCESS_NORMAL_LATENCY) // Process all callback (high and low latency) queues
97 
98 #define VBLANK_STATE_PROCESS_CALLBACKS_ONLY          (0x00000008)    // Process only the callback queue(s) and nothing else
99 
100 /*!
101  * set when called from an ISR; if VBlank() is in an ISR and there is
102  * more work to do, then VBlank() will not clear the pending bit
103  */
104 #define VBLANK_STATE_PROCESS_CALLED_FROM_ISR         (0x00000010)
105 #define VBLANK_STATE_PROCESS_CALLED_FROM_DPC         (0x00000020)
106 
107 /*! Vblank Interrupt state */
108 #define NV_HEAD_VBLANK_INTR_UNAVAILABLE              (0x00000000)
109 #define NV_HEAD_VBLANK_INTR_AVAILABLE                (0x00000001)
110 #define NV_HEAD_VBLANK_INTR_ENABLED                  (0x00000002)
111 
112 #endif // VBLANK_H
113