Due to resource reprovisioning, sometimes a need arises to move a living address space to a new area, preserving all the nodes and holes stored within. It is possible to do that by removing all nodes to a temporary list, reiniting the drm_mm instance and re-adding everything while applying a shift to each node. But that is a lot of extra work for a task which could be done internally without any node shuffle operations. This change introduces an interface which allows to shift the range without pruning the whole drm_mm instance. Having a drm_mm interface for such shift significantly simplifies the code required to adjust a KMD for a change in base address of a space managed by drm_mm instance. Signed-off-by: Tomasz Lis <tomasz.lis@xxxxxxxxx> --- drivers/gpu/drm/drm_mm.c | 24 ++++++++++++++++++++++++ include/drm/drm_mm.h | 1 + 2 files changed, 25 insertions(+) diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c index ca254611b382..ce3bd8b5e41f 100644 --- a/drivers/gpu/drm/drm_mm.c +++ b/drivers/gpu/drm/drm_mm.c @@ -917,6 +917,30 @@ struct drm_mm_node *drm_mm_scan_color_evict(struct drm_mm_scan *scan) } EXPORT_SYMBOL(drm_mm_scan_color_evict); +/** + * drm_mm_shift - move the range of addresses managed by this @mm + * @mm: the drm_mm structure instance to shift + * @shift: the shift value to be added to addresses of all nodes + * + * The function shifts all nodes by given offset, moving the address space + * range managed by this @mm. + */ +void drm_mm_shift(struct drm_mm *mm, s64 shift) +{ + struct drm_mm_node *node; + + /* + * Head node represents a hole, with negative size and start at the end + * of addressable area. This means it is never present within nodes + * list - needs to be shifted separately. + */ + mm->head_node.start += shift; + + drm_mm_for_each_node(node, mm) + node->start += shift; +} +EXPORT_SYMBOL(drm_mm_shift); + /** * drm_mm_init - initialize a drm-mm allocator * @mm: the drm_mm structure to initialize diff --git a/include/drm/drm_mm.h b/include/drm/drm_mm.h index f654874c4ce6..798e5a4f07ad 100644 --- a/include/drm/drm_mm.h +++ b/include/drm/drm_mm.h @@ -465,6 +465,7 @@ static inline int drm_mm_insert_node(struct drm_mm *mm, void drm_mm_remove_node(struct drm_mm_node *node); void drm_mm_init(struct drm_mm *mm, u64 start, u64 size); void drm_mm_takedown(struct drm_mm *mm); +void drm_mm_shift(struct drm_mm *mm, s64 shift); /** * drm_mm_clean - checks whether an allocator is clean -- 2.25.1