xref: /aosp_15_r20/external/gmmlib/Source/GmmLib/inc/External/Common/GmmUtil.h (revision 35ffd701415c9e32e53136d61a677a8d0a8fc4a5)
1 /*==============================================================================
2 Copyright(c) 2017 Intel Corporation
3 
4 Permission is hereby granted, free of charge, to any person obtaining a
5 copy of this software and associated documentation files(the "Software"),
6 to deal in the Software without restriction, including without limitation
7 the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 and / or sell copies of the Software, and to permit persons to whom the
9 Software is furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included
12 in all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 OTHER DEALINGS IN THE SOFTWARE.
21 ============================================================================*/
22 
23 #pragma once
24 
25 
26 //------------------------------------------------------------------------
27 // Size macros
28 //------------------------------------------------------------------------
29 #define GMM_BITS(a)                                     (a)
30 #define GMM_BYTES(a)                                    (a)
31 #define GMM_KBYTE(a)                                    ((a) * 1024)
32 #define GMM_MBYTE(a)                                    ((a) * 1024 * 1024)
33 #define GMM_GBYTE(a)                                    (((uint64_t) 1024) * 1024 * 1024 * (a))
34 #define GMM_TBYTE(a)                                    (((uint64_t) 1024) * 1024 * 1024 * 1024 * (a))
35 #define GMM_SCANLINES(a)                                (a)
36 #define GMM_DEPTH(a)                                    (a)
37 #define GMM_PIXELS(a)                                   (a)
38 #define GMM_BYTES_TO_MBYTES(a)                          ((a) / (1024*1024))
39 #define GMM_BYTES_TO_KBYTES(a)                          ((a) / 1024)
40 
41 //------------------------------------------------------------------------
42 // Bit manipulation macros
43 //------------------------------------------------------------------------
44 #define __GMM_IS_ALIGN(A, B)            (((A) % (B)) == 0)
45 #define __BIT(x)                        (1UL << (x))
46 #define __MASKED_BIT(x)                 (__BIT(x) | (__BIT(x) << 16))
47 #define __BIT64(x)                      ((uint64_t)1 << (x))
48 #define __GMM_SET_BIT(A, b)             (A |= __BIT(b))
49 #define __GMM_CLEAR_BIT(A, b)           (A &= ~__BIT(b))
50 #define __GMM_SET_BIT64(A, b)           (A |= __BIT64(b))
51 #define __GMM_CLEAR_BIT64(A, b)         (A &= ~__BIT64(b))
52 #define __GMM_IS_BIT_SET(A, b)          (A & __BIT(b))
53 #define __GMM_IS_BIT_CLEAR(A, b)        ((A & __BIT(b)) == 0)
54 
55 #define __SET_VALUE(editDst, editMask, editShift, editValue)        \
56                                         (editDst) = (((editDst) & ~(editMask)) |\
57                                         (((editValue) << (editShift)) & (editMask)))
58 
59 #define GMM_UNREFERENCED_PARAMETER(param)                   ((void)(param))
60 #define GMM_UNREFERENCED_LOCAL_VARIABLE(debug_var)          ((void)(debug_var))
61 
62 
63 //------------------------------------------------------------------------
64 // Escape macros
65 //------------------------------------------------------------------------
66 #define GMM_ESCAPE_D3D_SET_DEV_CTX(Escape, AdapterHandle, DeviceHandle)       \
67     {                                                           \
68         Escape.hContext   = NULL;                               \
69         Escape.hDevice    = DeviceHandle;                            \
70     }
71 
72 #define GMM_CALL_D3D_ESCAPE(pfnEscape, hAdapter, Escape) (pfnEscape(hAdapter, &Escape))
73 
74 #define GMM_ESCAPE_OGL_SET_DEV_CTX(Escape, AdapterHandle, DeviceHandle)       \
75     {                                                           \
76         Escape.hAdapter = (D3DKMT_HANDLE)(uintptr_t)AdapterHandle;              \
77         Escape.hContext = (D3DKMT_HANDLE)(uintptr_t)NULL;                  \
78         Escape.hDevice  = (D3DKMT_HANDLE)(uintptr_t)DeviceHandle;               \
79         Escape.Type     = D3DKMT_ESCAPE_DRIVERPRIVATE;          \
80     }
81 #define GMM_CALL_OGL_ESCAPE(pfnEscape, hAdapter, Escape) (pfnEscape(&Escape))
82 
83 #define __GMM_RANGE_IN_GMADR(RangeBase, RangeSize,pGmmLibContext)                              \
84     (((RangeBase) >= GmmGetGttContext(pGmmLibContext)->GfxAddrRange.Global.Base) &&           \
85     (((RangeBase) + (RangeSize)) <=                                             \
86         (GmmGetGttContext(pGmmLibContext)->GfxAddrRange.Global.Base +        \
87         GmmGetGttContext(pGmmLibContext)->GlobalGfxApertureSize)))
88 
89 #define __GMM_RANGE_IN_GLOBAL_GTT_SPACE(RangeBase, RangeSize,pGmmLibContext)                   \
90     (((RangeBase) >= GmmGetGttContext(pGmmLibContext)->GfxAddrRange.Global.Base) &&           \
91     (((RangeBase) + (RangeSize)) <=                                             \
92         (GmmGetGttContext(pGmmLibContext)->GfxAddrRange.Global.Base +        \
93          GmmGetGttContext(pGmmLibContext)->GfxAddrRange.Global.Size)))
94 
95 #define __GMM_RANGE_IN_PPGTT_SPACE(RangeBase, RangeSize,pGmmLibContext)                        \
96     (((RangeBase) >= GmmGetGttContext(pGmmLibContext)->GfxAddrRange.PP.Base) &&               \
97     (((RangeBase) + (RangeSize)) <=                                             \
98         (GmmGetGttContext(pGmmLibContext)->GfxAddrRange.PP.Base +                             \
99          GmmGetGttContext(pGmmLibContext)->GfxAddrRange.PP.Size)))
100 
101 #define GMM_INLINE __inline
102 
103 #if(defined(__GMM_KMD__))
104 #define GMM_OVERRIDE_SIZE_64KB_ALLOC(pGmmLibContext)  if(GmmGetSkuTable(pGmmLibContext)->FtrPpgtt64KBWalkOptimization){ return (this->GetSizeAllocation());}
105 #else
106 #define GMM_OVERRIDE_SIZE_64KB_ALLOC(pGmmLibContext)  if(((GmmClientContext*)pClientContext)->GetSkuTable().FtrPpgtt64KBWalkOptimization){ return (this->GetSizeAllocation());}
107 #endif
108 
109