1 /* 2 * SPDX-FileCopyrightText: Copyright (c) 2015-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 #include "core/core.h" 25 #include "gpu/gpu.h" 26 #include "gpu/mem_mgr/mem_mgr.h" 27 28 #include "published/volta/gv100/dev_mmu.h" 29 30 #include "class/clc361.h" 31 32 NV_STATUS 33 memmgrScrubMapDoorbellRegion_GV100 34 ( 35 OBJGPU *pGpu, 36 MemoryManager *pMemoryManager, 37 OBJCHANNEL *pChannel 38 ) 39 { 40 NV_STATUS status = NV_OK; 41 RM_API *pRmApi = rmapiGetInterface(RMAPI_GPU_LOCK_INTERNAL); 42 43 // GSPTODO: disable doorbell region scrubbing for now 44 if (RMCFG_FEATURE_PLATFORM_GSP) 45 return NV_OK; 46 47 // allocate object for the class VOLTA_USER_MODE_A 48 status = pRmApi->AllocWithHandle(pRmApi, 49 pChannel->hClient, 50 pChannel->subdeviceId, 51 pChannel->doorbellRegionHandle, 52 VOLTA_USERMODE_A, 53 NULL, 54 0); 55 if (status != NV_OK) 56 goto exit; 57 58 // Map the doorbell region onto CPU to submit work in the future 59 status = pRmApi->MapToCpu(pRmApi, 60 pChannel->hClient, 61 pChannel->deviceId, 62 pChannel->doorbellRegionHandle, 63 0, 64 NVC361_NV_USERMODE__SIZE, 65 (void**)(&pChannel->pDoorbellRegion), 66 DRF_DEF(OS33, _FLAGS, _ACCESS, _WRITE_ONLY)); 67 if (status != NV_OK) 68 { 69 pRmApi->Free(pRmApi, pChannel->hClient, pChannel->doorbellRegionHandle); 70 goto exit; 71 } 72 73 pChannel->pDoorbellRegisterOffset = (NvU32*)(pChannel->pDoorbellRegion + 74 NVC361_NOTIFY_CHANNEL_PENDING); 75 76 // setting the use of doorbell register for this channel 77 pChannel->bUseDoorbellRegister = NV_TRUE; 78 exit: 79 return status; 80 81 82 } 83 84 /*! 85 * Returns the max context size 86 * 87 * @returns NvU64 88 */ 89 NvU64 90 memmgrGetMaxContextSize_GV100 91 ( 92 OBJGPU *pGpu, 93 MemoryManager *pMemoryManager 94 ) 95 { 96 extern NvU64 memmgrGetMaxContextSize_GP100(OBJGPU *pGpu, MemoryManager *pMemoryManager); 97 98 NvU64 size = memmgrGetMaxContextSize_GP100(pGpu, pMemoryManager); 99 100 // In Volta, the GR context buffer size increased by about 847 KB (doubled from Pascal) 101 if (RMCFG_FEATURE_PLATFORM_WINDOWS_LDDM) 102 { 103 // 104 // We are increasing the reserved mem size by 10 MB. 105 // This is to account for GR context buffer allocs by KMD's private channels. 106 // KMD allocates 10 GR channels (not in virtual context mode). 107 // This is causing an additional 8470 KB allocations from RM reserved heap. 108 // See bug 1882679 for more details. 109 // 110 size += (10 * 1024 *1024); 111 } 112 else if (RMCFG_FEATURE_PLATFORM_MODS) 113 { 114 // Double the context size 115 size *= 2; 116 } 117 else 118 { 119 if (memmgrIsPmaEnabled(pMemoryManager) && 120 memmgrIsPmaSupportedOnPlatform(pMemoryManager)) 121 { 122 // 123 // Increase the context size by 120 MB. 124 // This is needed to run the same number glxgears instances as in GP102. 125 // See bug 1885000 comment 7 and bug 1885000 comment 36 126 // 127 size += (120 * 1024 *1024); 128 } 129 } 130 131 return size; 132 } 133 134 /** 135 * This will return NV_TRUE if surface is BL. otherwise it returns NV_FALSE. 136 */ 137 NvBool 138 memmgrIsSurfaceBlockLinear_GV100 139 ( 140 MemoryManager *pMemoryManager, 141 Memory *pMemory, 142 NvU32 kind, 143 NvU32 dmaFlags 144 ) 145 { 146 if (FLD_TEST_DRF(OS03, _FLAGS, _PTE_KIND, _BL, dmaFlags)) 147 { 148 return NV_TRUE; 149 } 150 else if (FLD_TEST_DRF(OS03, _FLAGS, _PTE_KIND, _PITCH, dmaFlags)) 151 { 152 return NV_FALSE; 153 } 154 155 return (kind != NV_MMU_PTE_KIND_PITCH) ? NV_TRUE: NV_FALSE; 156 } 157