From patchwork Sat Feb 9 15:27:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Imre Deak X-Patchwork-Id: 2120371 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork2.kernel.org (Postfix) with ESMTP id 5CFF1DF24C for ; Sat, 9 Feb 2013 15:29:52 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8DDFDE5D3B for ; Sat, 9 Feb 2013 07:29:52 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga03.intel.com (mga03.intel.com [143.182.124.21]) by gabe.freedesktop.org (Postfix) with ESMTP id 20FAAE5D24; Sat, 9 Feb 2013 07:28:08 -0800 (PST) Received: from azsmga001.ch.intel.com ([10.2.17.19]) by azsmga101.ch.intel.com with ESMTP; 09 Feb 2013 07:28:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.84,634,1355126400"; d="scan'208";a="254823170" Received: from unknown (HELO localhost) ([10.252.120.87]) by azsmga001.ch.intel.com with ESMTP; 09 Feb 2013 07:28:04 -0800 From: Imre Deak To: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH 1/4] drm: add helper to walk a dma scatter list a page at a time Date: Sat, 9 Feb 2013 17:27:33 +0200 Message-Id: <1360423656-10816-2-git-send-email-imre.deak@intel.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1360423656-10816-1-git-send-email-imre.deak@intel.com> References: <1360423656-10816-1-git-send-email-imre.deak@intel.com> Cc: Rahul Sharma X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org 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. Signed-off-by: Imre Deak --- 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; + 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); + } + + 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)) /* ATI PCIGART support (ati_pcigart.h) */ extern int drm_ati_pcigart_init(struct drm_device *dev,