[RFC PATCH v2 7/8] drm/amdgpu/ttm: Allocate/Free 4K MMIO_REMAP Singleton BO
Alex Deucher
alexdeucher at gmail.com
Mon Aug 25 14:57:59 UTC 2025
On Sat, Aug 23, 2025 at 3:20 AM Srinivasan Shanmugam
<srinivasan.shanmugam at amd.com> wrote:
>
> Add amdgpu_ttm_mmio_remap_bo_init()/fini() to manage the kernel-owned
> one-page(4K) MMIO_REMAP BO. The allocator runs during TTM init when the
> hardware exposes a remap base (adev->rmmio_base) and the host
> PAGE_SIZE is <= AMDGPU_GPU_PAGE_SIZE (4K).
>
> The helper is idempotent (returns 0 if already allocated) and only
> returns an error when the actual allocation fails.
>
> This keeps MMIO_REMAP lifetime handling localized and prepares for the
> subsequent patch that exposes a userspace handle.
>
> Cc: Christian König <christian.koenig at amd.com>
> Suggested-by: Alex Deucher <alexander.deucher at amd.com>
> Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam at amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 69 +++++++++++++++++++++++++
> 1 file changed, 69 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> index 58b6ab1be4c1..c76c41a312b0 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> @@ -1853,6 +1853,68 @@ static void amdgpu_ttm_pools_fini(struct amdgpu_device *adev)
> adev->mman.ttm_pools = NULL;
> }
>
> +/**
> + * amdgpu_ttm_mmio_remap_bo_init - allocate the singleton 4K MMIO_REMAP BO
> + * @adev: amdgpu device
> + *
> + * Allocates the kernel-owned one-page buffer in AMDGPU_GEM_DOMAIN_MMIO_REMAP
> + * when the hardware exposes a remap base (adev->rmmio_remap.base) and the host
> + * PAGE_SIZE is <= AMDGPU_GPU_PAGE_SIZE (4K). If either condition is not met, the
> + * function returns 0 and leaves adev->rmmio_remap.bo as NULL.
> + *
> + * If the BO is already allocated, the function does nothing and returns 0.
> + * Only errors during actual allocation (e.g., amdgpu_bo_create_kernel()) are
> + * propagated as negative returns.
> + *
> + * Return:
> + * * 0 on success or intentional skip (feature not present/unsupported)
> + * * negative errno on allocation failure
> + */
> +static int amdgpu_ttm_mmio_remap_bo_init(struct amdgpu_device *adev)
> +{
> + int r;
> +
> + if (!adev->rmmio_base)
Check for adev->rmmio_remap.bus_addr here.
> + return 0;
> +
> + /* Hardware remap page is fixed 4K; skip on larger PAGE_SIZE. */
> + if (PAGE_SIZE > AMDGPU_GPU_PAGE_SIZE) {
> + dev_warn(adev->dev, "MMIO_REMAP disabled: PAGE_SIZE=%lu > 4K\n", PAGE_SIZE);
No need to warn here.
> + return 0;
> + }
> +
> + if (adev->rmmio_remap.bo)
> + return 0;
Why is this here?
> +
> + /* Create exactly ONE kernel-owned BO in the MMIO_REMAP domain */
> + r = amdgpu_bo_create_kernel(adev,
> + AMDGPU_GPU_PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE,
> + AMDGPU_GEM_DOMAIN_MMIO_REMAP,
> + &adev->rmmio_remap.bo,
> + NULL, NULL);
> + if (r) {
> + dev_err(adev->dev, "MMIO_REMAP: BO create failed (%d)\n", r);
> + return r;
> + }
> +
> + return 0;
> +}
> +
> +/**
> + * amdgpu_ttm_mmio_remap_bo_fini - free the singleton MMIO_REMAP BO
> + * @adev: amdgpu device
> + *
> + * Frees the kernel-owned MMIO_REMAP BO if it was allocated by
> + * amdgpu_ttm_mmio_remap_bo_init().
> + */
> +static void amdgpu_ttm_mmio_remap_bo_fini(struct amdgpu_device *adev)
> +{
> + if (adev->rmmio_remap.bo) {
> + amdgpu_bo_free_kernel(&adev->rmmio_remap.bo, NULL, NULL);
> + adev->rmmio_remap.bo = NULL;
> + }
> +}
> +
> /*
> * amdgpu_ttm_init - Init the memory management (ttm) as well as various
> * gtt/vram related fields.
> @@ -2027,6 +2089,11 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
> return r;
> }
>
> + /* Allocate the singleton MMIO_REMAP BO (4K) if supported */
> + r = amdgpu_ttm_mmio_remap_bo_init(adev);
> + if (r)
> + return r;
> +
> /* Initialize preemptible memory pool */
> r = amdgpu_preempt_mgr_init(adev);
> if (r) {
> @@ -2090,6 +2157,8 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
> amdgpu_bo_free_kernel(&adev->mman.sdma_access_bo, NULL,
> &adev->mman.sdma_access_ptr);
>
> + /* Drop the singleton MMIO_REMAP BO (if allocated) */
> + amdgpu_ttm_mmio_remap_bo_fini(adev);
> amdgpu_ttm_fw_reserve_vram_fini(adev);
> amdgpu_ttm_drv_reserve_vram_fini(adev);
>
> --
> 2.34.1
>
More information about the amd-gfx
mailing list