From: Alex Deucher <alexdeucher@gmail.com>
To: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Cc: "Christian König" <christian.koenig@amd.com>,
"Alex Deucher" <alexander.deucher@amd.com>,
amd-gfx@lists.freedesktop.org
Subject: Re: [RFC PATCH v2 7/8] drm/amdgpu/ttm: Allocate/Free 4K MMIO_REMAP Singleton BO
Date: Mon, 25 Aug 2025 10:57:59 -0400 [thread overview]
Message-ID: <CADnq5_PCZ2M-Q9bEdoAqk0nUEPdofLS43twxjP+wt4roPujBJw@mail.gmail.com> (raw)
In-Reply-To: <20250823072016.1272328-8-srinivasan.shanmugam@amd.com>
On Sat, Aug 23, 2025 at 3:20 AM Srinivasan Shanmugam
<srinivasan.shanmugam@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@amd.com>
> Suggested-by: Alex Deucher <alexander.deucher@amd.com>
> Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@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
>
next prev parent reply other threads:[~2025-08-25 14:58 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-20 11:32 [RFC PATCH 0/7] drm/amdgpu: add MMIO-remap singleton BO for HDP flush Srinivasan Shanmugam
2025-08-20 11:32 ` [RFC PATCH 1/7] drm/amdgpu/uapi: add AMDGPU_GEM_DOMAIN_MMIO_REMAP Srinivasan Shanmugam
2025-08-20 21:41 ` Alex Deucher
2025-08-20 11:32 ` [RFC PATCH 2/7] drm/amdgpu: Add New TTM Placement - AMDGPU_PL_MMIO_REMAP and wire up plumbing Srinivasan Shanmugam
2025-08-25 14:37 ` Christian König
2025-08-20 11:32 ` [RFC PATCH 3/7] drm/amdgpu: Plumbing for MMIO_REMAP memtype and user-visible strings Srinivasan Shanmugam
2025-08-20 11:32 ` [RFC PATCH 4/7] drm/amdgpu: Add mmio_remap fields to amdgpu_device Srinivasan Shanmugam
2025-08-20 21:00 ` Deucher, Alexander
2025-08-21 7:35 ` Christian König
2025-08-20 21:08 ` Deucher, Alexander
2025-08-20 21:49 ` Deucher, Alexander
2025-08-25 14:40 ` Christian König
2025-08-20 11:32 ` [RFC PATCH 5/7] drm/amdgpu: Implement TTM handling for MMIO_REMAP placement Srinivasan Shanmugam
2025-08-20 21:14 ` Alex Deucher
2025-08-25 14:43 ` Christian König
2025-08-20 11:32 ` [RFC PATCH 6/7] drm/amdgpu: Create Singleton MMIO_REMAP BO and Initialize its pool Srinivasan Shanmugam
2025-08-20 21:28 ` Alex Deucher
2025-08-25 14:48 ` Christian König
2025-08-20 11:32 ` [RFC PATCH 7/7] drm/amdgpu: Return Handle to MMIO_REMAP Singleton for GEM Create Srinivasan Shanmugam
2025-08-20 21:39 ` Alex Deucher
2025-08-25 14:57 ` Christian König
2025-08-20 21:47 ` [RFC PATCH 0/7] drm/amdgpu: add MMIO-remap singleton BO for HDP flush Alex Deucher
2025-08-23 7:20 ` [RFC PATCH v2 0/8] drm/amdgpu: Add MMIO-remap Singleton " Srinivasan Shanmugam
2025-08-23 7:20 ` [RFC PATCH v2 1/8] drm/amdgpu/uapi: Introduce AMDGPU_GEM_DOMAIN_MMIO_REMAP Srinivasan Shanmugam
2025-08-23 7:20 ` [RFC PATCH v2 2/8] drm/amdgpu/ttm: Add New AMDGPU_PL_MMIO_REMAP Placement Srinivasan Shanmugam
2025-08-23 7:20 ` [RFC PATCH v2 3/8] drm/amdgpu: Wire up MMIO_REMAP placement and User-visible strings Srinivasan Shanmugam
2025-08-23 7:20 ` [RFC PATCH v2 4/8] drm/amdgpu: Add mmio_remap bookkeeping to amdgpu_device Srinivasan Shanmugam
2025-08-23 7:20 ` [RFC PATCH v2 5/8] drm/amdgpu: Implement TTM handling for MMIO_REMAP placement Srinivasan Shanmugam
2025-08-25 14:52 ` Alex Deucher
2025-08-25 14:54 ` Alex Deucher
2025-08-23 7:20 ` [RFC PATCH v2 6/8] drm/amdgpu/ttm: Initialize AMDGPU_PL_MMIO_REMAP Heap Srinivasan Shanmugam
2025-08-23 7:20 ` [RFC PATCH v2 7/8] drm/amdgpu/ttm: Allocate/Free 4K MMIO_REMAP Singleton BO Srinivasan Shanmugam
2025-08-25 14:57 ` Alex Deucher [this message]
2025-08-23 7:20 ` [RFC PATCH v2 8/8] drm/amdgpu/gem: Return Handle to MMIO_REMAP Singleton in GEM_CREATE Srinivasan Shanmugam
2025-08-25 15:05 ` Alex Deucher
2025-08-25 14:57 ` [RFC PATCH 0/7] drm/amdgpu: add MMIO-remap singleton BO for HDP flush Christian König
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CADnq5_PCZ2M-Q9bEdoAqk0nUEPdofLS43twxjP+wt4roPujBJw@mail.gmail.com \
--to=alexdeucher@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=srinivasan.shanmugam@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).