2018-08-22 18:22:14 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Advanced Micro Devices, Inc.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sub license, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
* USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial portions
|
|
|
|
* of the Software.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "amdgpu.h"
|
|
|
|
|
2018-08-22 20:11:19 +08:00
|
|
|
/**
|
|
|
|
* amdgpu_gmc_get_pde_for_bo - get the PDE for a BO
|
|
|
|
*
|
|
|
|
* @bo: the BO to get the PDE for
|
|
|
|
* @level: the level in the PD hirarchy
|
|
|
|
* @addr: resulting addr
|
|
|
|
* @flags: resulting flags
|
|
|
|
*
|
|
|
|
* Get the address and flags to be used for a PDE (Page Directory Entry).
|
|
|
|
*/
|
|
|
|
void amdgpu_gmc_get_pde_for_bo(struct amdgpu_bo *bo, int level,
|
|
|
|
uint64_t *addr, uint64_t *flags)
|
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
|
|
|
|
struct ttm_dma_tt *ttm;
|
|
|
|
|
|
|
|
switch (bo->tbo.mem.mem_type) {
|
|
|
|
case TTM_PL_TT:
|
|
|
|
ttm = container_of(bo->tbo.ttm, struct ttm_dma_tt, ttm);
|
|
|
|
*addr = ttm->dma_address[0];
|
|
|
|
break;
|
|
|
|
case TTM_PL_VRAM:
|
|
|
|
*addr = amdgpu_bo_gpu_offset(bo);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*addr = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*flags = amdgpu_ttm_tt_pde_flags(bo->tbo.ttm, &bo->tbo.mem);
|
|
|
|
amdgpu_gmc_get_vm_pde(adev, level, addr, flags);
|
|
|
|
}
|
|
|
|
|
2018-08-22 18:22:14 +08:00
|
|
|
/**
|
|
|
|
* amdgpu_gmc_pd_addr - return the address of the root directory
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
uint64_t amdgpu_gmc_pd_addr(struct amdgpu_bo *bo)
|
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
|
|
|
|
uint64_t pd_addr;
|
|
|
|
|
|
|
|
/* TODO: move that into ASIC specific code */
|
|
|
|
if (adev->asic_type >= CHIP_VEGA10) {
|
|
|
|
uint64_t flags = AMDGPU_PTE_VALID;
|
|
|
|
|
2018-08-22 20:11:19 +08:00
|
|
|
amdgpu_gmc_get_pde_for_bo(bo, -1, &pd_addr, &flags);
|
2018-08-22 18:22:14 +08:00
|
|
|
pd_addr |= flags;
|
2018-08-22 20:11:19 +08:00
|
|
|
} else {
|
|
|
|
pd_addr = amdgpu_bo_gpu_offset(bo);
|
2018-08-22 18:22:14 +08:00
|
|
|
}
|
|
|
|
return pd_addr;
|
|
|
|
}
|
2018-08-23 21:20:43 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* amdgpu_gmc_vram_location - try to find VRAM location
|
|
|
|
*
|
|
|
|
* @adev: amdgpu device structure holding all necessary informations
|
|
|
|
* @mc: memory controller structure holding memory informations
|
|
|
|
* @base: base address at which to put VRAM
|
|
|
|
*
|
|
|
|
* Function will try to place VRAM at base address provided
|
|
|
|
* as parameter.
|
|
|
|
*/
|
|
|
|
void amdgpu_gmc_vram_location(struct amdgpu_device *adev, struct amdgpu_gmc *mc,
|
|
|
|
u64 base)
|
|
|
|
{
|
|
|
|
uint64_t limit = (uint64_t)amdgpu_vram_limit << 20;
|
|
|
|
|
|
|
|
mc->vram_start = base;
|
|
|
|
mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
|
|
|
|
if (limit && limit < mc->real_vram_size)
|
|
|
|
mc->real_vram_size = limit;
|
|
|
|
dev_info(adev->dev, "VRAM: %lluM 0x%016llX - 0x%016llX (%lluM used)\n",
|
|
|
|
mc->mc_vram_size >> 20, mc->vram_start,
|
|
|
|
mc->vram_end, mc->real_vram_size >> 20);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* amdgpu_gmc_gart_location - try to find GART location
|
|
|
|
*
|
|
|
|
* @adev: amdgpu device structure holding all necessary informations
|
|
|
|
* @mc: memory controller structure holding memory informations
|
|
|
|
*
|
|
|
|
* Function will place try to place GART before or after VRAM.
|
|
|
|
*
|
|
|
|
* If GART size is bigger than space left then we ajust GART size.
|
|
|
|
* Thus function will never fails.
|
|
|
|
*/
|
|
|
|
void amdgpu_gmc_gart_location(struct amdgpu_device *adev, struct amdgpu_gmc *mc)
|
|
|
|
{
|
2018-08-24 16:48:12 +08:00
|
|
|
const uint64_t four_gb = 0x100000000ULL;
|
2018-08-23 21:20:43 +08:00
|
|
|
u64 size_af, size_bf;
|
|
|
|
|
|
|
|
mc->gart_size += adev->pm.smu_prv_buffer_size;
|
|
|
|
|
2018-08-24 02:38:52 +08:00
|
|
|
/* VCE doesn't like it when BOs cross a 4GB segment, so align
|
|
|
|
* the GART base on a 4GB boundary as well.
|
|
|
|
*/
|
2018-08-23 21:20:43 +08:00
|
|
|
size_bf = mc->vram_start;
|
2018-08-24 16:48:12 +08:00
|
|
|
size_af = adev->gmc.mc_mask + 1 - ALIGN(mc->vram_end + 1, four_gb);
|
2018-08-24 02:38:52 +08:00
|
|
|
|
|
|
|
if (mc->gart_size > max(size_bf, size_af)) {
|
|
|
|
dev_warn(adev->dev, "limiting GART\n");
|
|
|
|
mc->gart_size = max(size_bf, size_af);
|
|
|
|
}
|
|
|
|
|
2018-08-24 15:40:10 +08:00
|
|
|
if ((size_bf >= mc->gart_size && size_bf < size_af) ||
|
|
|
|
(size_af < mc->gart_size))
|
2018-08-23 21:20:43 +08:00
|
|
|
mc->gart_start = 0;
|
2018-08-24 02:38:52 +08:00
|
|
|
else
|
2018-08-24 16:48:12 +08:00
|
|
|
mc->gart_start = mc->mc_mask - mc->gart_size + 1;
|
|
|
|
|
|
|
|
mc->gart_start &= four_gb - 1;
|
2018-08-23 21:20:43 +08:00
|
|
|
mc->gart_end = mc->gart_start + mc->gart_size - 1;
|
|
|
|
dev_info(adev->dev, "GART: %lluM 0x%016llX - 0x%016llX\n",
|
|
|
|
mc->gart_size >> 20, mc->gart_start, mc->gart_end);
|
|
|
|
}
|