diff options
| author | Thomas Hellström <thomas.hellstrom@linux.intel.com> | 2025-12-19 12:33:00 +0100 |
|---|---|---|
| committer | Thomas Hellström <thomas.hellstrom@linux.intel.com> | 2025-12-23 09:35:53 +0100 |
| commit | a599b98607decdc899630fc99a3a2847f6b72965 (patch) | |
| tree | b20ad6414638fe4388bfe56f6af878a13d3ee5d6 /include/drm | |
| parent | 16b5ad31952476fb925c401897fc171cd37f536b (diff) | |
drm/pagemap, drm/xe: Add refcounting to struct drm_pagemap
With the end goal of being able to free unused pagemaps
and allocate them on demand, add a refcount to struct drm_pagemap,
remove the xe embedded drm_pagemap, allocating and freeing it
explicitly.
v2:
- Make the drm_pagemap pointer in drm_gpusvm_pages reference-counted.
v3:
- Call drm_pagemap_get() before drm_pagemap_put() in drm_gpusvm_pages
(Himal Prasad Ghimiray)
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com> #v1
Reviewed-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Acked-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> # For merging through drm-xe.
Link: https://patch.msgid.link/20251219113320.183860-5-thomas.hellstrom@linux.intel.com
Diffstat (limited to 'include/drm')
| -rw-r--r-- | include/drm/drm_pagemap.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/include/drm/drm_pagemap.h b/include/drm/drm_pagemap.h index 70a7991f784f..093e7199c44b 100644 --- a/include/drm/drm_pagemap.h +++ b/include/drm/drm_pagemap.h @@ -130,11 +130,15 @@ struct drm_pagemap_ops { * struct drm_pagemap: Additional information for a struct dev_pagemap * used for device p2p handshaking. * @ops: The struct drm_pagemap_ops. + * @ref: Reference count. * @dev: The struct drevice owning the device-private memory. + * @pagemap: Pointer to the underlying dev_pagemap. */ struct drm_pagemap { const struct drm_pagemap_ops *ops; + struct kref ref; struct device *dev; + struct dev_pagemap *pagemap; }; struct drm_pagemap_devmem; @@ -209,6 +213,37 @@ struct drm_pagemap_devmem_ops { struct dma_fence *pre_migrate_fence); }; +struct drm_pagemap *drm_pagemap_create(struct device *dev, + struct dev_pagemap *pagemap, + const struct drm_pagemap_ops *ops); + +#if IS_ENABLED(CONFIG_DRM_GPUSVM) + +void drm_pagemap_put(struct drm_pagemap *dpagemap); + +#else + +static inline void drm_pagemap_put(struct drm_pagemap *dpagemap) +{ +} + +#endif /* IS_ENABLED(CONFIG_DRM_GPUSVM) */ + +/** + * drm_pagemap_get() - Obtain a reference on a struct drm_pagemap + * @dpagemap: Pointer to the struct drm_pagemap. + * + * Return: Pointer to the struct drm_pagemap. + */ +static inline struct drm_pagemap * +drm_pagemap_get(struct drm_pagemap *dpagemap) +{ + if (likely(dpagemap)) + kref_get(&dpagemap->ref); + + return dpagemap; +} + /** * struct drm_pagemap_devmem - Structure representing a GPU SVM device memory allocation * @@ -257,3 +292,4 @@ int drm_pagemap_populate_mm(struct drm_pagemap *dpagemap, unsigned long timeslice_ms); #endif + |
