* [PATCH v2] drm/amdgpu: Map all visible VRAM at startup
@ 2018-02-27 18:36 Amber Lin
[not found] ` <1519756593-11409-1-git-send-email-Amber.Lin-5C7GfCeVMHo@public.gmane.org>
0 siblings, 1 reply; 2+ messages in thread
From: Amber Lin @ 2018-02-27 18:36 UTC (permalink / raw)
To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW; +Cc: Amber Lin
When using CPU to update page table, we need to kmap all the PDs/PTs after
they are allocated and that requires a TLB shot down on each CPU, which is
quite heavy.
Instead, we map the whole visible VRAM to a kernel address at once. Pages
can be obtained from the offset.
v2: move the mapping base from gmc to amdgpu_mman structure, and the
implementation in amdgpu_ttm_* functions
Change-Id: I56574bd544dae273da50e8b5dd6894cd5d9454bd
Signed-off-by: Amber Lin <Amber.Lin@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 17 +++++++++++++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 1 +
2 files changed, 18 insertions(+)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index e38e6db..f126a5a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -621,6 +621,7 @@ static int amdgpu_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_mem_
{
struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type];
struct amdgpu_device *adev = amdgpu_ttm_adev(bdev);
+ struct drm_mm_node *mm_node = mem->mm_node;
mem->bus.addr = NULL;
mem->bus.offset = 0;
@@ -640,6 +641,15 @@ static int amdgpu_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_mem_
/* check if it's visible */
if ((mem->bus.offset + mem->bus.size) > adev->gmc.visible_vram_size)
return -EINVAL;
+ /* Only physically contiguous buffers apply. In a contiguous
+ * buffer, size of the first mm_node would match the number of
+ * pages in ttm_mem_reg.
+ */
+ if (adev->mman.aper_base_kaddr &&
+ (mm_node->size == mem->num_pages))
+ mem->bus.addr = (u8 *)adev->mman.aper_base_kaddr +
+ mem->bus.offset;
+
mem->bus.base = adev->gmc.aper_base;
mem->bus.is_iomem = true;
break;
@@ -1402,6 +1412,10 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
/* Change the size here instead of the init above so only lpfn is affected */
amdgpu_ttm_set_active_vram_size(adev, adev->gmc.visible_vram_size);
+#ifdef CONFIG_64BIT
+ adev->mman.aper_base_kaddr = ioremap_wc(adev->gmc.aper_base,
+ adev->gmc.visible_vram_size);
+#endif
/*
*The reserved vram for firmware must be pinned to the specified
@@ -1494,6 +1508,9 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
amdgpu_ttm_debugfs_fini(adev);
amdgpu_bo_free_kernel(&adev->stolen_vga_memory, NULL, NULL);
amdgpu_ttm_fw_reserve_vram_fini(adev);
+ if (adev->mman.aper_base_kaddr)
+ iounmap(adev->mman.aper_base_kaddr);
+ adev->mman.aper_base_kaddr = NULL;
ttm_bo_clean_mm(&adev->mman.bdev, TTM_PL_VRAM);
ttm_bo_clean_mm(&adev->mman.bdev, TTM_PL_TT);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
index 1e275c7..d314910 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
@@ -44,6 +44,7 @@ struct amdgpu_mman {
struct ttm_bo_device bdev;
bool mem_global_referenced;
bool initialized;
+ void __iomem *aper_base_kaddr;
#if defined(CONFIG_DEBUG_FS)
struct dentry *debugfs_entries[8];
--
2.7.4
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] drm/amdgpu: Map all visible VRAM at startup
[not found] ` <1519756593-11409-1-git-send-email-Amber.Lin-5C7GfCeVMHo@public.gmane.org>
@ 2018-02-28 7:56 ` Christian König
0 siblings, 0 replies; 2+ messages in thread
From: Christian König @ 2018-02-28 7:56 UTC (permalink / raw)
To: Amber Lin, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
Am 27.02.2018 um 19:36 schrieb Amber Lin:
> When using CPU to update page table, we need to kmap all the PDs/PTs after
> they are allocated and that requires a TLB shot down on each CPU, which is
> quite heavy.
>
> Instead, we map the whole visible VRAM to a kernel address at once. Pages
> can be obtained from the offset.
>
> v2: move the mapping base from gmc to amdgpu_mman structure, and the
> implementation in amdgpu_ttm_* functions
>
> Change-Id: I56574bd544dae273da50e8b5dd6894cd5d9454bd
> Signed-off-by: Amber Lin <Amber.Lin@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 17 +++++++++++++++++
> drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 1 +
> 2 files changed, 18 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> index e38e6db..f126a5a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> @@ -621,6 +621,7 @@ static int amdgpu_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_mem_
> {
> struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type];
> struct amdgpu_device *adev = amdgpu_ttm_adev(bdev);
> + struct drm_mm_node *mm_node = mem->mm_node;
>
> mem->bus.addr = NULL;
> mem->bus.offset = 0;
> @@ -640,6 +641,15 @@ static int amdgpu_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_mem_
> /* check if it's visible */
> if ((mem->bus.offset + mem->bus.size) > adev->gmc.visible_vram_size)
> return -EINVAL;
> + /* Only physically contiguous buffers apply. In a contiguous
> + * buffer, size of the first mm_node would match the number of
> + * pages in ttm_mem_reg.
> + */
> + if (adev->mman.aper_base_kaddr &&
> + (mm_node->size == mem->num_pages))
> + mem->bus.addr = (u8 *)adev->mman.aper_base_kaddr +
> + mem->bus.offset;
> +
> mem->bus.base = adev->gmc.aper_base;
> mem->bus.is_iomem = true;
> break;
> @@ -1402,6 +1412,10 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
>
> /* Change the size here instead of the init above so only lpfn is affected */
> amdgpu_ttm_set_active_vram_size(adev, adev->gmc.visible_vram_size);
> +#ifdef CONFIG_64BIT
> + adev->mman.aper_base_kaddr = ioremap_wc(adev->gmc.aper_base,
> + adev->gmc.visible_vram_size);
> +#endif
>
> /*
> *The reserved vram for firmware must be pinned to the specified
> @@ -1494,6 +1508,9 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
> amdgpu_ttm_debugfs_fini(adev);
> amdgpu_bo_free_kernel(&adev->stolen_vga_memory, NULL, NULL);
> amdgpu_ttm_fw_reserve_vram_fini(adev);
> + if (adev->mman.aper_base_kaddr)
> + iounmap(adev->mman.aper_base_kaddr);
> + adev->mman.aper_base_kaddr = NULL;
>
> ttm_bo_clean_mm(&adev->mman.bdev, TTM_PL_VRAM);
> ttm_bo_clean_mm(&adev->mman.bdev, TTM_PL_TT);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
> index 1e275c7..d314910 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
> @@ -44,6 +44,7 @@ struct amdgpu_mman {
> struct ttm_bo_device bdev;
> bool mem_global_referenced;
> bool initialized;
> + void __iomem *aper_base_kaddr;
>
> #if defined(CONFIG_DEBUG_FS)
> struct dentry *debugfs_entries[8];
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-02-28 7:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-27 18:36 [PATCH v2] drm/amdgpu: Map all visible VRAM at startup Amber Lin
[not found] ` <1519756593-11409-1-git-send-email-Amber.Lin-5C7GfCeVMHo@public.gmane.org>
2018-02-28 7:56 ` Christian König
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.