2 * SPDX-License-Identifier: MIT
4 * Copyright © 2016 Intel Corporation
7 #include "i915_scatterlist.h"
9 bool i915_sg_trim(struct sg_table *orig_st)
11 struct sg_table new_st;
12 struct scatterlist *sg, *new_sg;
15 if (orig_st->nents == orig_st->orig_nents)
18 if (sg_alloc_table(&new_st, orig_st->nents, GFP_KERNEL | __GFP_NOWARN))
22 for_each_sg(orig_st->sgl, sg, orig_st->nents, i) {
23 sg_set_page(new_sg, sg_page(sg), sg->length, 0);
24 sg_dma_address(new_sg) = sg_dma_address(sg);
25 sg_dma_len(new_sg) = sg_dma_len(sg);
27 new_sg = sg_next(new_sg);
29 GEM_BUG_ON(new_sg); /* Should walk exactly nents and hit the end */
31 sg_free_table(orig_st);
37 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
38 #include "selftests/scatterlist.c"