From patchwork Tue Dec 20 22:54:28 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 5905 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 138FE23E2E for ; Tue, 20 Dec 2011 22:54:35 +0000 (UTC) Received: from mail-ey0-f180.google.com (mail-ey0-f180.google.com [209.85.215.180]) by fiordland.canonical.com (Postfix) with ESMTP id EB9A6A18433 for ; Tue, 20 Dec 2011 22:54:34 +0000 (UTC) Received: by eaac11 with SMTP id c11so3944933eaa.11 for ; Tue, 20 Dec 2011 14:54:34 -0800 (PST) Received: by 10.204.133.207 with SMTP id g15mr1479435bkt.17.1324421674726; Tue, 20 Dec 2011 14:54:34 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.205.82.144 with SMTP id ac16cs24231bkc; Tue, 20 Dec 2011 14:54:34 -0800 (PST) Received: by 10.236.91.84 with SMTP id g60mr6982086yhf.90.1324421672333; Tue, 20 Dec 2011 14:54:32 -0800 (PST) Received: from mail-gy0-f178.google.com (mail-gy0-f178.google.com [209.85.160.178]) by mx.google.com with ESMTPS id d28si1837611ano.42.2011.12.20.14.54.31 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 20 Dec 2011 14:54:32 -0800 (PST) Received-SPF: pass (google.com: domain of robdclark@gmail.com designates 209.85.160.178 as permitted sender) client-ip=209.85.160.178; Authentication-Results: mx.google.com; spf=pass (google.com: domain of robdclark@gmail.com designates 209.85.160.178 as permitted sender) smtp.mail=robdclark@gmail.com; dkim=pass (test mode) header.i=@gmail.com Received: by ghbg21 with SMTP id g21so4903080ghb.37 for ; Tue, 20 Dec 2011 14:54:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer; bh=tagruTr/IlbWkafXmlg//+f9TssXlpb3Wdk6bhxJXh0=; b=XnUMLWZasQwAqpTFEyF9RRTvQJTwAHSJ6iIA60mrOhC0C+4p+YBHEprsq3by4Jnmf2 0HMv8wMY1jwJSrsDPt1JjijyMHvlhotBiycIYpFHvfZSs3l5gTj4P6vr8TmuYzABKzCi jIe4zNi5V53EOu4LhBSoLVvv/PkVjNsvDF6Bw= Received: by 10.236.165.98 with SMTP id d62mr6941114yhl.15.1324421671825; Tue, 20 Dec 2011 14:54:31 -0800 (PST) Received: from localhost (ppp-70-129-134-180.dsl.rcsntx.swbell.net. [70.129.134.180]) by mx.google.com with ESMTPS id f17sm9093367ang.20.2011.12.20.14.54.30 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 20 Dec 2011 14:54:31 -0800 (PST) Sender: Rob Clark From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: patches@linaro.org, Greg KH , Tomi Valkeinen , Rob Clark Subject: [PATCH] drm/omap: GEM, deal with cache Date: Tue, 20 Dec 2011 16:54:28 -0600 Message-Id: <1324421668-18056-1-git-send-email-rob.clark@linaro.org> X-Mailer: git-send-email 1.7.5.4 From: Rob Clark Uncached/writecombine buffers need to be clean before creating uc/wc userspace mappings, lest dirty cache lines fall down and corrupt the contents of the buffer. Signed-off-by: Rob Clark --- drivers/staging/omapdrm/omap_gem.c | 30 ++++++++++++++++++++++++++++++ 1 files changed, 30 insertions(+), 0 deletions(-) diff --git a/drivers/staging/omapdrm/omap_gem.c b/drivers/staging/omapdrm/omap_gem.c index 63490f7..e0ebd1d 100644 --- a/drivers/staging/omapdrm/omap_gem.c +++ b/drivers/staging/omapdrm/omap_gem.c @@ -84,6 +84,9 @@ struct omap_gem_object { */ struct page **pages; + /** addresses corresponding to pages in above array */ + dma_addr_t *addrs; + /** * Virtual address, if mapped. */ @@ -208,6 +211,19 @@ static int omap_gem_attach_pages(struct drm_gem_object *obj) return PTR_ERR(pages); } + /* for non-cached buffers, ensure the new pages are clean because + * DSS, GPU, etc. are not cache coherent: + */ + if (omap_obj->flags & (OMAP_BO_WC|OMAP_BO_UNCACHED)) { + int i, npages = obj->size >> PAGE_SHIFT; + dma_addr_t *addrs = kmalloc(npages * sizeof(addrs), GFP_KERNEL); + for (i = 0; i < npages; i++) { + addrs[i] = dma_map_page(obj->dev->dev, pages[i], + 0, PAGE_SIZE, DMA_BIDIRECTIONAL); + } + omap_obj->addrs = addrs; + } + omap_obj->pages = pages; return 0; } @@ -216,6 +232,20 @@ static int omap_gem_attach_pages(struct drm_gem_object *obj) static void omap_gem_detach_pages(struct drm_gem_object *obj) { struct omap_gem_object *omap_obj = to_omap_bo(obj); + + /* for non-cached buffers, ensure the new pages are clean because + * DSS, GPU, etc. are not cache coherent: + */ + if (omap_obj->flags & (OMAP_BO_WC|OMAP_BO_UNCACHED)) { + int i, npages = obj->size >> PAGE_SHIFT; + for (i = 0; i < npages; i++) { + dma_unmap_page(obj->dev->dev, omap_obj->addrs[i], + PAGE_SIZE, DMA_BIDIRECTIONAL); + } + kfree(omap_obj->addrs); + omap_obj->addrs = NULL; + } + _drm_gem_put_pages(obj, omap_obj->pages, true, false); omap_obj->pages = NULL; }