[Intel-gfx] [PATCH 06/21] drm/i915: introduce page_size members

Chris Wilson chris at chris-wilson.co.uk
Tue Oct 3 16:32:58 UTC 2017


Quoting Chris Wilson (2017-09-29 22:31:27)
> Quoting Matthew Auld (2017-09-29 17:10:17)
> > diff --git a/drivers/gpu/drm/i915/i915_gem_userptr.c b/drivers/gpu/drm/i915/i915_gem_userptr.c
> > index 70ad7489827d..ad5abca1f794 100644
> > --- a/drivers/gpu/drm/i915/i915_gem_userptr.c
> > +++ b/drivers/gpu/drm/i915/i915_gem_userptr.c
> > @@ -405,6 +405,9 @@ __i915_gem_userptr_alloc_pages(struct drm_i915_gem_object *obj,
> >  {
> >         unsigned int max_segment = i915_sg_segment_size();
> >         struct sg_table *st;
> > +       struct scatterlist *sg;
> > +       unsigned int sg_mask;
> > +       int n;
> >         int ret;
> >  
> >         st = kmalloc(sizeof(*st), GFP_KERNEL);
> > @@ -434,7 +437,11 @@ __i915_gem_userptr_alloc_pages(struct drm_i915_gem_object *obj,
> >                 return ERR_PTR(ret);
> >         }
> >  
> > -       __i915_gem_object_set_pages(obj, st);
> > +       sg_mask = 0;
> > +       for_each_sg(st->sgl, sg, num_pages, n)
> > +               sg_mask |= sg->length;
> 
> No workie as num_pages != nents.

If we do something like
 
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 5ea7e1fbd0fd..c92d89ec9d5a 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -2896,6 +2896,21 @@ static inline struct scatterlist *__sg_next(struct scatterlist *sg)
             (((__iter).curr += PAGE_SIZE) >= (__iter).max) ?           \
             (__iter) = __sgt_iter(__sg_next((__iter).sgp), false), 0 : 0)
 
+static inline unsigned int i915_sg_page_sizes(struct scatterlist *sg)
+{
+       unsigned int page_sizes;
+
+       page_sizes = 0;
+       while (sg) {
+               GEM_BUG_ON(sg->offset);
+               GEM_BUG_ON(!IS_ALIGNED(sg->length, PAGE_SIZE));
+               page_sizes |= sg->length;
+               sg = __sg_next(sg);
+       }
+
+       return page_sizes;
+}
+
 static inline unsigned int i915_sg_segment_size(void)
 {
        unsigned int size = swiotlb_max_segment();

Then we can just write sg_mask = i915_sg_page_sizes(sg); for when we
don't compute them inline. For popular interfaces (userptr being one of
them) we should look at computing page_sizes inline.
-Chris


More information about the Intel-gfx mailing list