Skip to content

Commit 56cf531

Browse files
Caterina Shabliajannau
authored andcommitted
drm/gpuvm: Add a helper to check if two VA can be merged
We are going to add flags/properties that will impact the VA merging ability. Instead of sprinkling tests all over the place in __drm_gpuvm_sm_map(), let's add a helper aggregating all these checks can call it for every existing VA we walk through in the __drm_gpuvm_sm_map() loop. Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com> Signed-off-by: Caterina Shablia <caterina.shablia@collabora.com>
1 parent a4547e1 commit 56cf531

1 file changed

Lines changed: 39 additions & 1 deletion

File tree

drivers/gpu/drm/drm_gpuvm.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2172,6 +2172,44 @@ op_unmap_cb(const struct drm_gpuvm_ops *fn, void *priv,
21722172
return fn->sm_step_unmap(&op, priv);
21732173
}
21742174

2175+
static bool __can_merge(struct drm_gpuvm *gpuvm, const struct drm_gpuva_op_map *a,
2176+
const struct drm_gpuva_op_map *b)
2177+
{
2178+
/* Only GEM-based mappings can be merged, and they must point to
2179+
* the same GEM object.
2180+
*/
2181+
if (a->gem.obj != b->gem.obj || !a->gem.obj)
2182+
return false;
2183+
2184+
/* Order VAs for the rest of the checks. */
2185+
if (a->va.addr > b->va.addr)
2186+
swap(a, b);
2187+
2188+
/* We assume the caller already checked that VAs overlap or are
2189+
* contiguous.
2190+
*/
2191+
if (drm_WARN_ON(gpuvm->drm, b->va.addr > a->va.addr + a->va.range))
2192+
return false;
2193+
2194+
/* We intentionally ignore u64 underflows because all we care about
2195+
* here is whether the VA diff matches the GEM offset diff.
2196+
*/
2197+
return b->va.addr - a->va.addr == b->gem.offset - a->gem.offset;
2198+
}
2199+
2200+
static bool can_merge(struct drm_gpuvm *gpuvm, const struct drm_gpuva *a,
2201+
const struct drm_gpuva_op_map *b)
2202+
{
2203+
struct drm_gpuva_op_map tmp = {
2204+
.va.addr = a->va.addr,
2205+
.va.range = a->va.range,
2206+
.gem.offset = a->gem.offset,
2207+
.gem.obj = a->gem.obj,
2208+
};
2209+
2210+
return __can_merge(gpuvm, &tmp, b);
2211+
}
2212+
21752213
static int
21762214
__drm_gpuvm_sm_map(struct drm_gpuvm *gpuvm,
21772215
const struct drm_gpuvm_ops *ops, void *priv,
@@ -2196,7 +2234,7 @@ __drm_gpuvm_sm_map(struct drm_gpuvm *gpuvm,
21962234
u64 addr = va->va.addr;
21972235
u64 range = va->va.range;
21982236
u64 end = addr + range;
2199-
bool merge = !!va->gem.obj;
2237+
bool merge = can_merge(gpuvm, va, &req->map);
22002238

22012239
if (madvise && obj)
22022240
continue;

0 commit comments

Comments
 (0)