From: Imre Deak <imre.deak@intel.com>
To: Daniel Vetter <daniel@ffwll.ch>
Cc: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
Rahul Sharma <rahul.sharma@samsung.com>,
LKML <linux-kernel@vger.kernel.org>,
linaro-mm-sig@lists.linaro.org
Subject: Re: [Intel-gfx] [PATCH 1/4] drm: add helper to walk a dma scatter list a page at a time
Date: Sun, 10 Feb 2013 00:55:08 +0200 [thread overview]
Message-ID: <1360450508.5252.15.camel@ideak-mobl> (raw)
In-Reply-To: <20130209185637.GT5813@phenom.ffwll.local>
On Sat, 2013-02-09 at 19:56 +0100, Daniel Vetter wrote:
> Hi Imre!
>
> On Sat, Feb 09, 2013 at 05:27:33PM +0200, Imre Deak wrote:
> > Add a helper to walk through a scatter list a page at a time. Needed by
> > upcoming patches fixing the scatter list walking logic in the i915 driver.
>
> Nice patch, but I think this would make a rather nice addition to the
> common scatterlist api in scatterlist.h, maybe called sg_page_iter.
> There's already another helper which does cpu mappings, but it has a
> different use-case (gives you the page mapped, which we don't neeed and
> can cope with not page-aligned sg tables). With dma-buf using sg tables I
> expect more users of such a sg page iterator to pop up. Most possible
> users of this will hang around on linaro-mm-sig, so please also cc that
> besides the usual suspects.
Ok, I wanted to sneak this in to drm (and win some time) thinking there
isn't any other user of it atm. But I agree the ideal place for it is in
scatterlist.h, so will send it there.
> Cheers, Daniel
>
> >
> > Signed-off-by: Imre Deak <imre.deak@intel.com>
> > ---
> > include/drm/drmP.h | 44 ++++++++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 44 insertions(+)
> >
> > diff --git a/include/drm/drmP.h b/include/drm/drmP.h
> > index fad21c9..0c0c213 100644
> > --- a/include/drm/drmP.h
> > +++ b/include/drm/drmP.h
> > @@ -1578,6 +1578,50 @@ extern int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
> > extern int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request);
> > extern int drm_sg_free(struct drm_device *dev, void *data,
> > struct drm_file *file_priv);
> > +struct drm_sg_iter {
> > + struct scatterlist *sg;
> > + int sg_offset;
>
> Imo using sg_pfn_offset (i.e. sg_offset >> PAGE_SIZE) would make it
> clearer that this is all about iterating page-aligned sg tables.
>
> > + struct page *page;
> > +};
> > +
> > +static inline int
> > +__drm_sg_iter_seek(struct drm_sg_iter *iter)
> > +{
> > + while (iter->sg && iter->sg_offset >= iter->sg->length) {
> > + iter->sg_offset -= iter->sg->length;
> > + iter->sg = sg_next(iter->sg);
>
> And adding a WARN_ON(sg->legnth & ~PAGE_MASK); here would enforce that.
>
> > + }
> > +
> > + return iter->sg ? 0 : -1;
> > +}
> > +
> > +static inline struct page *
> > +drm_sg_iter_next(struct drm_sg_iter *iter)
> > +{
> > + struct page *page;
> > +
> > + if (__drm_sg_iter_seek(iter))
> > + return NULL;
> > +
> > + page = nth_page(sg_page(iter->sg), iter->sg_offset >> PAGE_SHIFT);
> > + iter->sg_offset = (iter->sg_offset + PAGE_SIZE) & PAGE_MASK;
> > +
> > + return page;
> > +}
> > +
> > +static inline struct page *
> > +drm_sg_iter_start(struct drm_sg_iter *iter, struct scatterlist *sg,
> > + unsigned long offset)
> > +{
> > + iter->sg = sg;
> > + iter->sg_offset = offset;
> > +
> > + return drm_sg_iter_next(iter);
> > +}
> > +
> > +#define drm_for_each_sg_page(iter, sg, pgoffset) \
> > + for ((iter)->page = drm_sg_iter_start((iter), (sg), (pgoffset));\
> > + (iter)->page; (iter)->page = drm_sg_iter_next(iter))
>
> Again, for the initialization I'd go with page numbers, not an offset in
> bytes.
Ok, can change it to use page numbers instead.
--Imre
next prev parent reply other threads:[~2013-02-09 22:55 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-09 15:27 [PATCH 0/4] drm/i915: handle compact dma scatter lists Imre Deak
2013-02-09 15:27 ` [PATCH 1/4] drm: add helper to walk a dma scatter list a page at a time Imre Deak
2013-02-09 18:56 ` [Intel-gfx] " Daniel Vetter
2013-02-09 22:55 ` Imre Deak [this message]
2013-02-09 15:27 ` [PATCH 2/4] drm: handle compact dma scatter lists in drm_clflush_sg() Imre Deak
2013-02-09 15:27 ` [PATCH 3/4] drm/i915: handle walking compact dma scatter lists Imre Deak
2013-02-09 15:50 ` Chris Wilson
2013-02-09 22:51 ` Daniel Vetter
2013-02-09 22:59 ` Imre Deak
2013-02-09 15:27 ` [PATCH 4/4] drm/i915: create compact dma scatter lists for gem objects Imre Deak
2013-02-09 18:59 ` Daniel Vetter
2013-02-09 22:46 ` Imre Deak
2013-02-18 17:28 ` [PATCH v2 0/4] drm/i915: handle compact dma scatter lists Imre Deak
2013-02-18 17:28 ` [PATCH v2 1/4] drm: handle compact dma scatter lists in drm_clflush_sg() Imre Deak
2013-02-18 17:28 ` [PATCH v2 2/4] drm/i915: handle walking compact dma scatter lists Imre Deak
2013-02-18 17:28 ` [PATCH v2 3/4] drm/i915: create compact dma scatter lists for gem objects Imre Deak
2013-02-18 17:28 ` [PATCH v2 4/4] drm/i915: use for_each_sg_page for setting up the gtt ptes Imre Deak
2013-03-19 9:05 ` Daniel Vetter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1360450508.5252.15.camel@ideak-mobl \
--to=imre.deak@intel.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rahul.sharma@samsung.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox