Message ID | 20230530160643.2344551-7-suijingfeng@loongson.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2294636vqr; Tue, 30 May 2023 09:11:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ54xbdnIusuJ17WwezMpvCEjd33OjDZuRTI9nk3SnPsRJ7InBdt5Bq7msHyRlPHhmU/Y9k5 X-Received: by 2002:a17:902:e5d0:b0:1af:981b:eeff with SMTP id u16-20020a170902e5d000b001af981beeffmr3134212plf.64.1685463075131; Tue, 30 May 2023 09:11:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685463075; cv=none; d=google.com; s=arc-20160816; b=l/AF1R9/njcwJAuxgN0zwWDT4bvAZUL3VsWS7SGp33hGILwwsgkTmZ/WFEfn/H7ZDL QNV4AsU3TbXkVYPJ/h2b49A9cFmi1jCBOEGm5+Ke6dLKorj40AOeAG4ijYL8p9RP8OJd clpa9/cmTCZceaQKVKsTOQ4QjKknCGRtJq6vXzjWyWdRffTJwoV6PtrxIta3utztn4rO BFSLlAAnrcAhau9ZgfyTNPBX5KLhxxnGlQvfS6VHR90wfQzyWvuH62BUCSI2+BN5QRDY 9NqmMdN6aZwRTb2UEDYy732HrlqmYJfGAsp1eOHg4vvHuNIC7EaqPuliRudqDZXGv5we ND9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=gLpnV9R/pkjzQEOYgaXyEywX4NlQ5aEf7/ZwOHv7Xdc=; b=bN6x0YHxhTSTb7smHgzcH37Qiz2/Bv8ZKaYD4iVnm71vaoAuH5s2GHdDH5/bnsH2ly jHFZFZEJ/pfYSgkkDFpLtrx0FqjisgJCcYwL1k3de2Pib5hB1uV5VL4pDCWuoIpJkaPw wVdwWfv438J5rmbVJMtShng6mv+vUL94lAhlBt6tEJLjvEmTmF20TrIJCpjiBw01H37k SxG2DRrKWyensntEsl6tpZ6mqQ8ZeM/H+QcrJBb60e1IvAkUEFt014T85dvFeoqtppK8 4RgQURQmz6sOHU55y+TnPBc2lvdqu1HqloXa6wkuqimFJpzviWJ8OJyLvqZvUnT27Z5n aGpw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m5-20020a170902768500b001ac6d4e1d72si11118625pll.149.2023.05.30.09.10.59; Tue, 30 May 2023 09:11:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231256AbjE3QHI (ORCPT <rfc822;andrewvogler123@gmail.com> + 99 others); Tue, 30 May 2023 12:07:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232315AbjE3QGx (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 30 May 2023 12:06:53 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0EC66113 for <linux-kernel@vger.kernel.org>; Tue, 30 May 2023 09:06:45 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8Dxd_EUH3ZkOaYCAA--.6090S3; Wed, 31 May 2023 00:06:44 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxqrYTH3Zket+AAA--.13773S8; Wed, 31 May 2023 00:06:44 +0800 (CST) From: Sui Jingfeng <suijingfeng@loongson.cn> To: Lucas Stach <l.stach@pengutronix.de>, Russell King <linux+etnaviv@armlinux.org.uk>, Christian Gmeiner <christian.gmeiner@gmail.com>, David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch> Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, loongson-kernel@lists.loongnix.cn Subject: [PATCH v6 6/6] drm/etnaviv: allow usperspace create cached coherent bo Date: Wed, 31 May 2023 00:06:43 +0800 Message-Id: <20230530160643.2344551-7-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230530160643.2344551-1-suijingfeng@loongson.cn> References: <20230530160643.2344551-1-suijingfeng@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8CxqrYTH3Zket+AAA--.13773S8 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxXF4fGryfAF4UZFyUZFykAFb_yoWrKFWUpF Z3AFyYkrW0v3yDK34xAFn8Za43Gw12gFZ2k3sxtwn09w45tF42qr95KFZ8Crn8Jr1fGry3 tw1Dtry5K3WjyrJanT9S1TB71UUUUj7qnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU b68YFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_JF0_JFyl8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM2 8EF7xvwVC2z280aVAFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVCY1x0267AKxVW8Jr0_Cr1U M2kKe7AKxVWUAVWUtwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYIkI8VC2zV CFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVW3AVW8Xw1lYx0E x4A2jsIE14v26F4j6r4UJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7 CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l 4IxYO2xFxVAFwI0_JF0_Jw1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxV WUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAF wI0_tr0E3s1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF04k26cxKx2 IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26F4j6r4UJwCI42IY6I8E87Iv6xkF7I0E14v2 6r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7IU01E_tUUUUU== X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767336129288318650?= X-GMAIL-MSGID: =?utf-8?q?1767336129288318650?= |
Series |
drm/etnaviv: add pci device driver support
|
|
Commit Message
Sui Jingfeng
May 30, 2023, 4:06 p.m. UTC
cached system RAM is coherent on loongson CPUs, and the GPU and DC allways
snoop the CPU's cache. write-combine caching property is not suitiable for
us.
Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn>
---
drivers/gpu/drm/etnaviv/etnaviv_drv.c | 2 +-
drivers/gpu/drm/etnaviv/etnaviv_gem.c | 22 +++++++++++++++++++--
drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c | 9 ++++++++-
include/uapi/drm/etnaviv_drm.h | 11 ++++++-----
4 files changed, 35 insertions(+), 9 deletions(-)
Comments
s/usperspace/userspace/ (in subject) On Wed, May 31, 2023 at 12:06:43AM +0800, Sui Jingfeng wrote: > cached system RAM is coherent on loongson CPUs, and the GPU and DC allways > snoop the CPU's cache. write-combine caching property is not suitiable for > us. s/allways/always/ s/suitiable/suitable/
Hi, Thanks a lot, will be fixed at next version. On 2023/5/31 02:58, Bjorn Helgaas wrote: > s/usperspace/userspace/ (in subject) > > On Wed, May 31, 2023 at 12:06:43AM +0800, Sui Jingfeng wrote: >> cached system RAM is coherent on loongson CPUs, and the GPU and DC allways >> snoop the CPU's cache. write-combine caching property is not suitiable for >> us. > s/allways/always/ > s/suitiable/suitable/
Hi Sui Jingfeng, Am Mittwoch, dem 31.05.2023 um 00:06 +0800 schrieb Sui Jingfeng: > cached system RAM is coherent on loongson CPUs, and the GPU and DC allways > snoop the CPU's cache. write-combine caching property is not suitiable for > us. > As previously mentioned in the Mesa MR, I don't think this is the right approach. ETNA_BO_CACHED already looks coherent to userspace, as all accesses are bracketed via the ETNAVIV_GEM_CPU_PREP and ETNAVIV_GEM_CPU_FINI ioctls, which will do the necessary cache maintenance on platforms where device coherence isn't enforced by the hardware, so there is no need for a separate ETNA_BO_CACHED_COHERENT. Instead we just need a new ETNAVIV_PARAM to inform userspace about hardware cache coherence being available for a specific GPU core, in which case the userspace driver should switch to preferring ETNA_BO_CACHED over ETNA_BO_WC. Regards, Lucas > Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn> > --- > drivers/gpu/drm/etnaviv/etnaviv_drv.c | 2 +- > drivers/gpu/drm/etnaviv/etnaviv_gem.c | 22 +++++++++++++++++++-- > drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c | 9 ++++++++- > include/uapi/drm/etnaviv_drm.h | 11 ++++++----- > 4 files changed, 35 insertions(+), 9 deletions(-) > > diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c > index 052f745cecc0..2816c654c023 100644 > --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c > +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c > @@ -274,7 +274,7 @@ static int etnaviv_ioctl_gem_new(struct drm_device *dev, void *data, > struct drm_etnaviv_gem_new *args = data; > > if (args->flags & ~(ETNA_BO_CACHED | ETNA_BO_WC | ETNA_BO_UNCACHED | > - ETNA_BO_FORCE_MMU)) > + ETNA_BO_CACHED_COHERENT | ETNA_BO_FORCE_MMU)) > return -EINVAL; > > return etnaviv_gem_new_handle(dev, file, args->size, > diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem.c b/drivers/gpu/drm/etnaviv/etnaviv_gem.c > index b5f73502e3dd..d8b559bd33d3 100644 > --- a/drivers/gpu/drm/etnaviv/etnaviv_gem.c > +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem.c > @@ -343,6 +343,7 @@ void *etnaviv_gem_vmap(struct drm_gem_object *obj) > static void *etnaviv_gem_vmap_impl(struct etnaviv_gem_object *obj) > { > struct page **pages; > + pgprot_t prot; > > lockdep_assert_held(&obj->lock); > > @@ -350,8 +351,20 @@ static void *etnaviv_gem_vmap_impl(struct etnaviv_gem_object *obj) > if (IS_ERR(pages)) > return NULL; > > - return vmap(pages, obj->base.size >> PAGE_SHIFT, > - VM_MAP, pgprot_writecombine(PAGE_KERNEL)); > + switch (obj->flags) { > + case ETNA_BO_CACHED_COHERENT: > + case ETNA_BO_CACHED: > + prot = PAGE_KERNEL; > + break; > + case ETNA_BO_UNCACHED: > + prot = pgprot_noncached(PAGE_KERNEL); > + break; > + case ETNA_BO_WC: > + default: > + prot = pgprot_writecombine(PAGE_KERNEL); > + } > + > + return vmap(pages, obj->base.size >> PAGE_SHIFT, VM_MAP, prot); > } > > static inline enum dma_data_direction etnaviv_op_to_dma_dir(u32 op) > @@ -545,6 +558,7 @@ static const struct drm_gem_object_funcs etnaviv_gem_object_funcs = { > static int etnaviv_gem_new_impl(struct drm_device *dev, u32 size, u32 flags, > const struct etnaviv_gem_ops *ops, struct drm_gem_object **obj) > { > + struct etnaviv_drm_private *priv = dev->dev_private; > struct etnaviv_gem_object *etnaviv_obj; > unsigned sz = sizeof(*etnaviv_obj); > bool valid = true; > @@ -555,6 +569,10 @@ static int etnaviv_gem_new_impl(struct drm_device *dev, u32 size, u32 flags, > case ETNA_BO_CACHED: > case ETNA_BO_WC: > break; > + case ETNA_BO_CACHED_COHERENT: > + if (priv->has_cached_coherent) > + break; > + fallthrough; > default: > valid = false; > } > diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c > index 3524b5811682..671d91d8f1c6 100644 > --- a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c > +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c > @@ -112,11 +112,18 @@ static const struct etnaviv_gem_ops etnaviv_gem_prime_ops = { > struct drm_gem_object *etnaviv_gem_prime_import_sg_table(struct drm_device *dev, > struct dma_buf_attachment *attach, struct sg_table *sgt) > { > + struct etnaviv_drm_private *priv = dev->dev_private; > struct etnaviv_gem_object *etnaviv_obj; > size_t size = PAGE_ALIGN(attach->dmabuf->size); > + u32 cache_flags; > int ret, npages; > > - ret = etnaviv_gem_new_private(dev, size, ETNA_BO_WC, > + if (priv->has_cached_coherent) > + cache_flags = ETNA_BO_CACHED_COHERENT; > + else > + cache_flags = ETNA_BO_WC; > + > + ret = etnaviv_gem_new_private(dev, size, cache_flags, > &etnaviv_gem_prime_ops, &etnaviv_obj); > if (ret < 0) > return ERR_PTR(ret); > diff --git a/include/uapi/drm/etnaviv_drm.h b/include/uapi/drm/etnaviv_drm.h > index af024d90453d..474b0db286de 100644 > --- a/include/uapi/drm/etnaviv_drm.h > +++ b/include/uapi/drm/etnaviv_drm.h > @@ -90,13 +90,14 @@ struct drm_etnaviv_param { > * GEM buffers: > */ > > -#define ETNA_BO_CACHE_MASK 0x000f0000 > +#define ETNA_BO_CACHE_MASK 0x000f0000 > /* cache modes */ > -#define ETNA_BO_CACHED 0x00010000 > -#define ETNA_BO_WC 0x00020000 > -#define ETNA_BO_UNCACHED 0x00040000 > +#define ETNA_BO_CACHED 0x00010000 > +#define ETNA_BO_WC 0x00020000 > +#define ETNA_BO_UNCACHED 0x00040000 > +#define ETNA_BO_CACHED_COHERENT 0x00080000 > /* map flags */ > -#define ETNA_BO_FORCE_MMU 0x00100000 > +#define ETNA_BO_FORCE_MMU 0x00100000 > > struct drm_etnaviv_gem_new { > __u64 size; /* in */
Hi, On 2023/6/1 00:33, Lucas Stach wrote: > Hi Sui Jingfeng, > > Am Mittwoch, dem 31.05.2023 um 00:06 +0800 schrieb Sui Jingfeng: >> cached system RAM is coherent on loongson CPUs, and the GPU and DC allways >> snoop the CPU's cache. write-combine caching property is not suitiable for >> us. >> > As previously mentioned in the Mesa MR, I don't think this is the right > approach. > > ETNA_BO_CACHED already looks coherent to userspace, as all accesses are > bracketed via the ETNAVIV_GEM_CPU_PREP and ETNAVIV_GEM_CPU_FINI ioctls, > which will do the necessary cache maintenance on platforms where device > coherence isn't enforced by the hardware, so there is no need for a > separate ETNA_BO_CACHED_COHERENT. As far as I can see, ETNA_BO_CACHED_COHERENT could probably help to bypass the overhead of dma_sync_sgtable_for_cpu() and dma_sync_sgtable_for_device() brings to us. I have tested long time ago, there no need call this function on our platform. The glmark2 works as before if I comment out thoes two function. Are you serious, sir? > Instead we just need a new ETNAVIV_PARAM to inform userspace about > hardware cache coherence being available for a specific GPU core, Ok, let me think about for a while how to implement this. But How about we merge this first, I create another patch to improve it with a roughly working base first? I'm just asking if the answer is No :-) > in > which case the userspace driver should switch to preferring > ETNA_BO_CACHED over ETNA_BO_WC. Yeah, ETNA_BO_CACHED is enough. ETNA_BO_CACHED_COHERENT is actually a special case of ETNA_BO_CACHED. > Regards, > Lucas > >> Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn> >> --- >> drivers/gpu/drm/etnaviv/etnaviv_drv.c | 2 +- >> drivers/gpu/drm/etnaviv/etnaviv_gem.c | 22 +++++++++++++++++++-- >> drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c | 9 ++++++++- >> include/uapi/drm/etnaviv_drm.h | 11 ++++++----- >> 4 files changed, 35 insertions(+), 9 deletions(-) >> >> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c >> index 052f745cecc0..2816c654c023 100644 >> --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c >> +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c >> @@ -274,7 +274,7 @@ static int etnaviv_ioctl_gem_new(struct drm_device *dev, void *data, >> struct drm_etnaviv_gem_new *args = data; >> >> if (args->flags & ~(ETNA_BO_CACHED | ETNA_BO_WC | ETNA_BO_UNCACHED | >> - ETNA_BO_FORCE_MMU)) >> + ETNA_BO_CACHED_COHERENT | ETNA_BO_FORCE_MMU)) >> return -EINVAL; >> >> return etnaviv_gem_new_handle(dev, file, args->size, >> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem.c b/drivers/gpu/drm/etnaviv/etnaviv_gem.c >> index b5f73502e3dd..d8b559bd33d3 100644 >> --- a/drivers/gpu/drm/etnaviv/etnaviv_gem.c >> +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem.c >> @@ -343,6 +343,7 @@ void *etnaviv_gem_vmap(struct drm_gem_object *obj) >> static void *etnaviv_gem_vmap_impl(struct etnaviv_gem_object *obj) >> { >> struct page **pages; >> + pgprot_t prot; >> >> lockdep_assert_held(&obj->lock); >> >> @@ -350,8 +351,20 @@ static void *etnaviv_gem_vmap_impl(struct etnaviv_gem_object *obj) >> if (IS_ERR(pages)) >> return NULL; >> >> - return vmap(pages, obj->base.size >> PAGE_SHIFT, >> - VM_MAP, pgprot_writecombine(PAGE_KERNEL)); >> + switch (obj->flags) { >> + case ETNA_BO_CACHED_COHERENT: >> + case ETNA_BO_CACHED: >> + prot = PAGE_KERNEL; >> + break; >> + case ETNA_BO_UNCACHED: >> + prot = pgprot_noncached(PAGE_KERNEL); >> + break; >> + case ETNA_BO_WC: >> + default: >> + prot = pgprot_writecombine(PAGE_KERNEL); >> + } >> + >> + return vmap(pages, obj->base.size >> PAGE_SHIFT, VM_MAP, prot); >> } >> >> static inline enum dma_data_direction etnaviv_op_to_dma_dir(u32 op) >> @@ -545,6 +558,7 @@ static const struct drm_gem_object_funcs etnaviv_gem_object_funcs = { >> static int etnaviv_gem_new_impl(struct drm_device *dev, u32 size, u32 flags, >> const struct etnaviv_gem_ops *ops, struct drm_gem_object **obj) >> { >> + struct etnaviv_drm_private *priv = dev->dev_private; >> struct etnaviv_gem_object *etnaviv_obj; >> unsigned sz = sizeof(*etnaviv_obj); >> bool valid = true; >> @@ -555,6 +569,10 @@ static int etnaviv_gem_new_impl(struct drm_device *dev, u32 size, u32 flags, >> case ETNA_BO_CACHED: >> case ETNA_BO_WC: >> break; >> + case ETNA_BO_CACHED_COHERENT: >> + if (priv->has_cached_coherent) >> + break; >> + fallthrough; >> default: >> valid = false; >> } >> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c >> index 3524b5811682..671d91d8f1c6 100644 >> --- a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c >> +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c >> @@ -112,11 +112,18 @@ static const struct etnaviv_gem_ops etnaviv_gem_prime_ops = { >> struct drm_gem_object *etnaviv_gem_prime_import_sg_table(struct drm_device *dev, >> struct dma_buf_attachment *attach, struct sg_table *sgt) >> { >> + struct etnaviv_drm_private *priv = dev->dev_private; >> struct etnaviv_gem_object *etnaviv_obj; >> size_t size = PAGE_ALIGN(attach->dmabuf->size); >> + u32 cache_flags; >> int ret, npages; >> >> - ret = etnaviv_gem_new_private(dev, size, ETNA_BO_WC, >> + if (priv->has_cached_coherent) >> + cache_flags = ETNA_BO_CACHED_COHERENT; >> + else >> + cache_flags = ETNA_BO_WC; >> + >> + ret = etnaviv_gem_new_private(dev, size, cache_flags, >> &etnaviv_gem_prime_ops, &etnaviv_obj); >> if (ret < 0) >> return ERR_PTR(ret); >> diff --git a/include/uapi/drm/etnaviv_drm.h b/include/uapi/drm/etnaviv_drm.h >> index af024d90453d..474b0db286de 100644 >> --- a/include/uapi/drm/etnaviv_drm.h >> +++ b/include/uapi/drm/etnaviv_drm.h >> @@ -90,13 +90,14 @@ struct drm_etnaviv_param { >> * GEM buffers: >> */ >> >> -#define ETNA_BO_CACHE_MASK 0x000f0000 >> +#define ETNA_BO_CACHE_MASK 0x000f0000 >> /* cache modes */ >> -#define ETNA_BO_CACHED 0x00010000 >> -#define ETNA_BO_WC 0x00020000 >> -#define ETNA_BO_UNCACHED 0x00040000 >> +#define ETNA_BO_CACHED 0x00010000 >> +#define ETNA_BO_WC 0x00020000 >> +#define ETNA_BO_UNCACHED 0x00040000 >> +#define ETNA_BO_CACHED_COHERENT 0x00080000 >> /* map flags */ >> -#define ETNA_BO_FORCE_MMU 0x00100000 >> +#define ETNA_BO_FORCE_MMU 0x00100000 >> >> struct drm_etnaviv_gem_new { >> __u64 size; /* in */
Am Donnerstag, dem 01.06.2023 um 01:29 +0800 schrieb Sui Jingfeng: > Hi, > > On 2023/6/1 00:33, Lucas Stach wrote: > > Hi Sui Jingfeng, > > > > Am Mittwoch, dem 31.05.2023 um 00:06 +0800 schrieb Sui Jingfeng: > > > cached system RAM is coherent on loongson CPUs, and the GPU and DC allways > > > snoop the CPU's cache. write-combine caching property is not suitiable for > > > us. > > > > > As previously mentioned in the Mesa MR, I don't think this is the right > > approach. > > > > ETNA_BO_CACHED already looks coherent to userspace, as all accesses are > > bracketed via the ETNAVIV_GEM_CPU_PREP and ETNAVIV_GEM_CPU_FINI ioctls, > > which will do the necessary cache maintenance on platforms where device > > coherence isn't enforced by the hardware, so there is no need for a > > separate ETNA_BO_CACHED_COHERENT. > > As far as I can see, ETNA_BO_CACHED_COHERENT could probably help to > bypass the overhead of > > dma_sync_sgtable_for_cpu() and dma_sync_sgtable_for_device() brings to us. > > > I have tested long time ago, there no need call this function on our > platform. > > The glmark2 works as before if I comment out thoes two function. > > Are you serious, sir? > The dma_sync* functions are more or less no-ops when the device is marked as being coherent. As the mapping is done via the DRM device instance, you might need to propagate the coherent property from the GPU core device to the virtual DRM device, along the lines of how we propagate other DMA properties from the GPU device to the DRM device in etnaviv_pdev_probe. Other than that things should just work with minimal overhead. > > Instead we just need a new ETNAVIV_PARAM to inform userspace about > > hardware cache coherence being available for a specific GPU core, > > Ok, let me think about for a while how to implement this. > Simple: add new ETNAVIV_PARAM_GPU_COHERENT to include/uapi/drm/etnaviv_drm.h, return the result from dev_is_dma_coherent in etnaviv_gpu_get_param(). > But How about we merge this first, I create another patch to improve it > > with a roughly working base first? I'm just asking if the answer is No :-) > The answer is a firm no. This impacts UAPI, so there is no chance to ever get rid of any wrong decisions here, as any added UAPI needs to be supported indefinitely. I'm not signing up for maintaining something I believe is implemented upside down. Please don't take this the wrong way: I'm pretty excited to see etnaviv used on more architectures and outside of the proven platform device paths, so I'm happy to assist in working out the design and help you get things merged in both kernel and Mesa. But I think we are still quite a few steps away from having things worked out enough to even think about merging those patchsets. Also please allow me to comment on the other patches of the series, so I can get a better understanding of your platform/integration, before sending another revision of those patches. Regards, Lucas > > in > > which case the userspace driver should switch to preferring > > ETNA_BO_CACHED over ETNA_BO_WC. > > Yeah, ETNA_BO_CACHED is enough. > > ETNA_BO_CACHED_COHERENT is actually a special case of ETNA_BO_CACHED. > > > Regards, > > Lucas > > > > > Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn> > > > --- > > > drivers/gpu/drm/etnaviv/etnaviv_drv.c | 2 +- > > > drivers/gpu/drm/etnaviv/etnaviv_gem.c | 22 +++++++++++++++++++-- > > > drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c | 9 ++++++++- > > > include/uapi/drm/etnaviv_drm.h | 11 ++++++----- > > > 4 files changed, 35 insertions(+), 9 deletions(-) > > > > > > diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c > > > index 052f745cecc0..2816c654c023 100644 > > > --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c > > > +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c > > > @@ -274,7 +274,7 @@ static int etnaviv_ioctl_gem_new(struct drm_device *dev, void *data, > > > struct drm_etnaviv_gem_new *args = data; > > > > > > if (args->flags & ~(ETNA_BO_CACHED | ETNA_BO_WC | ETNA_BO_UNCACHED | > > > - ETNA_BO_FORCE_MMU)) > > > + ETNA_BO_CACHED_COHERENT | ETNA_BO_FORCE_MMU)) > > > return -EINVAL; > > > > > > return etnaviv_gem_new_handle(dev, file, args->size, > > > diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem.c b/drivers/gpu/drm/etnaviv/etnaviv_gem.c > > > index b5f73502e3dd..d8b559bd33d3 100644 > > > --- a/drivers/gpu/drm/etnaviv/etnaviv_gem.c > > > +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem.c > > > @@ -343,6 +343,7 @@ void *etnaviv_gem_vmap(struct drm_gem_object *obj) > > > static void *etnaviv_gem_vmap_impl(struct etnaviv_gem_object *obj) > > > { > > > struct page **pages; > > > + pgprot_t prot; > > > > > > lockdep_assert_held(&obj->lock); > > > > > > @@ -350,8 +351,20 @@ static void *etnaviv_gem_vmap_impl(struct etnaviv_gem_object *obj) > > > if (IS_ERR(pages)) > > > return NULL; > > > > > > - return vmap(pages, obj->base.size >> PAGE_SHIFT, > > > - VM_MAP, pgprot_writecombine(PAGE_KERNEL)); > > > + switch (obj->flags) { > > > + case ETNA_BO_CACHED_COHERENT: > > > + case ETNA_BO_CACHED: > > > + prot = PAGE_KERNEL; > > > + break; > > > + case ETNA_BO_UNCACHED: > > > + prot = pgprot_noncached(PAGE_KERNEL); > > > + break; > > > + case ETNA_BO_WC: > > > + default: > > > + prot = pgprot_writecombine(PAGE_KERNEL); > > > + } > > > + > > > + return vmap(pages, obj->base.size >> PAGE_SHIFT, VM_MAP, prot); > > > } > > > > > > static inline enum dma_data_direction etnaviv_op_to_dma_dir(u32 op) > > > @@ -545,6 +558,7 @@ static const struct drm_gem_object_funcs etnaviv_gem_object_funcs = { > > > static int etnaviv_gem_new_impl(struct drm_device *dev, u32 size, u32 flags, > > > const struct etnaviv_gem_ops *ops, struct drm_gem_object **obj) > > > { > > > + struct etnaviv_drm_private *priv = dev->dev_private; > > > struct etnaviv_gem_object *etnaviv_obj; > > > unsigned sz = sizeof(*etnaviv_obj); > > > bool valid = true; > > > @@ -555,6 +569,10 @@ static int etnaviv_gem_new_impl(struct drm_device *dev, u32 size, u32 flags, > > > case ETNA_BO_CACHED: > > > case ETNA_BO_WC: > > > break; > > > + case ETNA_BO_CACHED_COHERENT: > > > + if (priv->has_cached_coherent) > > > + break; > > > + fallthrough; > > > default: > > > valid = false; > > > } > > > diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c > > > index 3524b5811682..671d91d8f1c6 100644 > > > --- a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c > > > +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c > > > @@ -112,11 +112,18 @@ static const struct etnaviv_gem_ops etnaviv_gem_prime_ops = { > > > struct drm_gem_object *etnaviv_gem_prime_import_sg_table(struct drm_device *dev, > > > struct dma_buf_attachment *attach, struct sg_table *sgt) > > > { > > > + struct etnaviv_drm_private *priv = dev->dev_private; > > > struct etnaviv_gem_object *etnaviv_obj; > > > size_t size = PAGE_ALIGN(attach->dmabuf->size); > > > + u32 cache_flags; > > > int ret, npages; > > > > > > - ret = etnaviv_gem_new_private(dev, size, ETNA_BO_WC, > > > + if (priv->has_cached_coherent) > > > + cache_flags = ETNA_BO_CACHED_COHERENT; > > > + else > > > + cache_flags = ETNA_BO_WC; > > > + > > > + ret = etnaviv_gem_new_private(dev, size, cache_flags, > > > &etnaviv_gem_prime_ops, &etnaviv_obj); > > > if (ret < 0) > > > return ERR_PTR(ret); > > > diff --git a/include/uapi/drm/etnaviv_drm.h b/include/uapi/drm/etnaviv_drm.h > > > index af024d90453d..474b0db286de 100644 > > > --- a/include/uapi/drm/etnaviv_drm.h > > > +++ b/include/uapi/drm/etnaviv_drm.h > > > @@ -90,13 +90,14 @@ struct drm_etnaviv_param { > > > * GEM buffers: > > > */ > > > > > > -#define ETNA_BO_CACHE_MASK 0x000f0000 > > > +#define ETNA_BO_CACHE_MASK 0x000f0000 > > > /* cache modes */ > > > -#define ETNA_BO_CACHED 0x00010000 > > > -#define ETNA_BO_WC 0x00020000 > > > -#define ETNA_BO_UNCACHED 0x00040000 > > > +#define ETNA_BO_CACHED 0x00010000 > > > +#define ETNA_BO_WC 0x00020000 > > > +#define ETNA_BO_UNCACHED 0x00040000 > > > +#define ETNA_BO_CACHED_COHERENT 0x00080000 > > > /* map flags */ > > > -#define ETNA_BO_FORCE_MMU 0x00100000 > > > +#define ETNA_BO_FORCE_MMU 0x00100000 > > > > > > struct drm_etnaviv_gem_new { > > > __u64 size; /* in */ >
Hi, On 2023/6/1 01:53, Lucas Stach wrote: > Am Donnerstag, dem 01.06.2023 um 01:29 +0800 schrieb Sui Jingfeng: >> Hi, >> >> On 2023/6/1 00:33, Lucas Stach wrote: >>> Hi Sui Jingfeng, >>> >>> Am Mittwoch, dem 31.05.2023 um 00:06 +0800 schrieb Sui Jingfeng: >>>> cached system RAM is coherent on loongson CPUs, and the GPU and DC allways >>>> snoop the CPU's cache. write-combine caching property is not suitiable for >>>> us. >>>> >>> As previously mentioned in the Mesa MR, I don't think this is the right >>> approach. >>> >>> ETNA_BO_CACHED already looks coherent to userspace, as all accesses are >>> bracketed via the ETNAVIV_GEM_CPU_PREP and ETNAVIV_GEM_CPU_FINI ioctls, >>> which will do the necessary cache maintenance on platforms where device >>> coherence isn't enforced by the hardware, so there is no need for a >>> separate ETNA_BO_CACHED_COHERENT. >> As far as I can see, ETNA_BO_CACHED_COHERENT could probably help to >> bypass the overhead of >> >> dma_sync_sgtable_for_cpu() and dma_sync_sgtable_for_device() brings to us. >> >> >> I have tested long time ago, there no need call this function on our >> platform. >> >> The glmark2 works as before if I comment out thoes two function. >> >> Are you serious, sir? >> > The dma_sync* functions are more or less no-ops when the device is > marked as being coherent. ce > instance, you might need to propagate the coherent property from the > GPU core device to the virtual DRM device, along the lines of how we > propagate other DMA properties from the GPU device to the DRM device in > etnaviv_pdev_probe. > > Other than that things should just work with minimal overhead. >>> Instead we just need a new ETNAVIV_PARAM to inform userspace about >>> hardware cache coherence being available for a specific GPU core, >> Ok, let me think about for a while how to implement this. >> > Simple: add new ETNAVIV_PARAM_GPU_COHERENT to > include/uapi/drm/etnaviv_drm.h, return the result from > dev_is_dma_coherent in etnaviv_gpu_get_param(). Okay, agree >> But How about we merge this first, I create another patch to improve it >> >> with a roughly working base first? I'm just asking if the answer is No :-) >> > The answer is a firm no. > > This impacts UAPI, so there is no chance to ever get rid of any wrong > decisions here, as any added UAPI needs to be supported indefinitely. > I'm not signing up for maintaining something I believe is implemented > upside down. > > Please don't take this the wrong way: I'm pretty excited to see etnaviv > used on more architectures and outside of the proven platform device > paths, so I'm happy to assist in working out the design and help you > get things merged in both kernel and Mesa. But I think we are still > quite a few steps away from having things worked out enough to even > think about merging those patchsets. > > Also please allow me to comment on the other patches of the series, so > I can get a better understanding of your platform/integration, before > sending another revision of those patches. I go to sleep yesterday. Okay, this sound fine. > Regards, > Lucas > >>> in >>> which case the userspace driver should switch to preferring >>> ETNA_BO_CACHED over ETNA_BO_WC. >> Yeah, ETNA_BO_CACHED is enough. >> >> ETNA_BO_CACHED_COHERENT is actually a special case of ETNA_BO_CACHED. >> >>> Regards, >>> Lucas >>> >>>> Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn> >>>> --- >>>> drivers/gpu/drm/etnaviv/etnaviv_drv.c | 2 +- >>>> drivers/gpu/drm/etnaviv/etnaviv_gem.c | 22 +++++++++++++++++++-- >>>> drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c | 9 ++++++++- >>>> include/uapi/drm/etnaviv_drm.h | 11 ++++++----- >>>> 4 files changed, 35 insertions(+), 9 deletions(-) >>>> >>>> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c >>>> index 052f745cecc0..2816c654c023 100644 >>>> --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c >>>> +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c >>>> @@ -274,7 +274,7 @@ static int etnaviv_ioctl_gem_new(struct drm_device *dev, void *data, >>>> struct drm_etnaviv_gem_new *args = data; >>>> >>>> if (args->flags & ~(ETNA_BO_CACHED | ETNA_BO_WC | ETNA_BO_UNCACHED | >>>> - ETNA_BO_FORCE_MMU)) >>>> + ETNA_BO_CACHED_COHERENT | ETNA_BO_FORCE_MMU)) >>>> return -EINVAL; >>>> >>>> return etnaviv_gem_new_handle(dev, file, args->size, >>>> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem.c b/drivers/gpu/drm/etnaviv/etnaviv_gem.c >>>> index b5f73502e3dd..d8b559bd33d3 100644 >>>> --- a/drivers/gpu/drm/etnaviv/etnaviv_gem.c >>>> +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem.c >>>> @@ -343,6 +343,7 @@ void *etnaviv_gem_vmap(struct drm_gem_object *obj) >>>> static void *etnaviv_gem_vmap_impl(struct etnaviv_gem_object *obj) >>>> { >>>> struct page **pages; >>>> + pgprot_t prot; >>>> >>>> lockdep_assert_held(&obj->lock); >>>> >>>> @@ -350,8 +351,20 @@ static void *etnaviv_gem_vmap_impl(struct etnaviv_gem_object *obj) >>>> if (IS_ERR(pages)) >>>> return NULL; >>>> >>>> - return vmap(pages, obj->base.size >> PAGE_SHIFT, >>>> - VM_MAP, pgprot_writecombine(PAGE_KERNEL)); >>>> + switch (obj->flags) { >>>> + case ETNA_BO_CACHED_COHERENT: >>>> + case ETNA_BO_CACHED: >>>> + prot = PAGE_KERNEL; >>>> + break; >>>> + case ETNA_BO_UNCACHED: >>>> + prot = pgprot_noncached(PAGE_KERNEL); >>>> + break; >>>> + case ETNA_BO_WC: >>>> + default: >>>> + prot = pgprot_writecombine(PAGE_KERNEL); >>>> + } >>>> + >>>> + return vmap(pages, obj->base.size >> PAGE_SHIFT, VM_MAP, prot); >>>> } >>>> >>>> static inline enum dma_data_direction etnaviv_op_to_dma_dir(u32 op) >>>> @@ -545,6 +558,7 @@ static const struct drm_gem_object_funcs etnaviv_gem_object_funcs = { >>>> static int etnaviv_gem_new_impl(struct drm_device *dev, u32 size, u32 flags, >>>> const struct etnaviv_gem_ops *ops, struct drm_gem_object **obj) >>>> { >>>> + struct etnaviv_drm_private *priv = dev->dev_private; >>>> struct etnaviv_gem_object *etnaviv_obj; >>>> unsigned sz = sizeof(*etnaviv_obj); >>>> bool valid = true; >>>> @@ -555,6 +569,10 @@ static int etnaviv_gem_new_impl(struct drm_device *dev, u32 size, u32 flags, >>>> case ETNA_BO_CACHED: >>>> case ETNA_BO_WC: >>>> break; >>>> + case ETNA_BO_CACHED_COHERENT: >>>> + if (priv->has_cached_coherent) >>>> + break; >>>> + fallthrough; >>>> default: >>>> valid = false; >>>> } >>>> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c >>>> index 3524b5811682..671d91d8f1c6 100644 >>>> --- a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c >>>> +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c >>>> @@ -112,11 +112,18 @@ static const struct etnaviv_gem_ops etnaviv_gem_prime_ops = { >>>> struct drm_gem_object *etnaviv_gem_prime_import_sg_table(struct drm_device *dev, >>>> struct dma_buf_attachment *attach, struct sg_table *sgt) >>>> { >>>> + struct etnaviv_drm_private *priv = dev->dev_private; >>>> struct etnaviv_gem_object *etnaviv_obj; >>>> size_t size = PAGE_ALIGN(attach->dmabuf->size); >>>> + u32 cache_flags; >>>> int ret, npages; >>>> >>>> - ret = etnaviv_gem_new_private(dev, size, ETNA_BO_WC, >>>> + if (priv->has_cached_coherent) >>>> + cache_flags = ETNA_BO_CACHED_COHERENT; >>>> + else >>>> + cache_flags = ETNA_BO_WC; >>>> + >>>> + ret = etnaviv_gem_new_private(dev, size, cache_flags, >>>> &etnaviv_gem_prime_ops, &etnaviv_obj); >>>> if (ret < 0) >>>> return ERR_PTR(ret); >>>> diff --git a/include/uapi/drm/etnaviv_drm.h b/include/uapi/drm/etnaviv_drm.h >>>> index af024d90453d..474b0db286de 100644 >>>> --- a/include/uapi/drm/etnaviv_drm.h >>>> +++ b/include/uapi/drm/etnaviv_drm.h >>>> @@ -90,13 +90,14 @@ struct drm_etnaviv_param { >>>> * GEM buffers: >>>> */ >>>> >>>> -#define ETNA_BO_CACHE_MASK 0x000f0000 >>>> +#define ETNA_BO_CACHE_MASK 0x000f0000 >>>> /* cache modes */ >>>> -#define ETNA_BO_CACHED 0x00010000 >>>> -#define ETNA_BO_WC 0x00020000 >>>> -#define ETNA_BO_UNCACHED 0x00040000 >>>> +#define ETNA_BO_CACHED 0x00010000 >>>> +#define ETNA_BO_WC 0x00020000 >>>> +#define ETNA_BO_UNCACHED 0x00040000 >>>> +#define ETNA_BO_CACHED_COHERENT 0x00080000 >>>> /* map flags */ >>>> -#define ETNA_BO_FORCE_MMU 0x00100000 >>>> +#define ETNA_BO_FORCE_MMU 0x00100000 >>>> >>>> struct drm_etnaviv_gem_new { >>>> __u64 size; /* in */
diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index 052f745cecc0..2816c654c023 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -274,7 +274,7 @@ static int etnaviv_ioctl_gem_new(struct drm_device *dev, void *data, struct drm_etnaviv_gem_new *args = data; if (args->flags & ~(ETNA_BO_CACHED | ETNA_BO_WC | ETNA_BO_UNCACHED | - ETNA_BO_FORCE_MMU)) + ETNA_BO_CACHED_COHERENT | ETNA_BO_FORCE_MMU)) return -EINVAL; return etnaviv_gem_new_handle(dev, file, args->size, diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem.c b/drivers/gpu/drm/etnaviv/etnaviv_gem.c index b5f73502e3dd..d8b559bd33d3 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gem.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem.c @@ -343,6 +343,7 @@ void *etnaviv_gem_vmap(struct drm_gem_object *obj) static void *etnaviv_gem_vmap_impl(struct etnaviv_gem_object *obj) { struct page **pages; + pgprot_t prot; lockdep_assert_held(&obj->lock); @@ -350,8 +351,20 @@ static void *etnaviv_gem_vmap_impl(struct etnaviv_gem_object *obj) if (IS_ERR(pages)) return NULL; - return vmap(pages, obj->base.size >> PAGE_SHIFT, - VM_MAP, pgprot_writecombine(PAGE_KERNEL)); + switch (obj->flags) { + case ETNA_BO_CACHED_COHERENT: + case ETNA_BO_CACHED: + prot = PAGE_KERNEL; + break; + case ETNA_BO_UNCACHED: + prot = pgprot_noncached(PAGE_KERNEL); + break; + case ETNA_BO_WC: + default: + prot = pgprot_writecombine(PAGE_KERNEL); + } + + return vmap(pages, obj->base.size >> PAGE_SHIFT, VM_MAP, prot); } static inline enum dma_data_direction etnaviv_op_to_dma_dir(u32 op) @@ -545,6 +558,7 @@ static const struct drm_gem_object_funcs etnaviv_gem_object_funcs = { static int etnaviv_gem_new_impl(struct drm_device *dev, u32 size, u32 flags, const struct etnaviv_gem_ops *ops, struct drm_gem_object **obj) { + struct etnaviv_drm_private *priv = dev->dev_private; struct etnaviv_gem_object *etnaviv_obj; unsigned sz = sizeof(*etnaviv_obj); bool valid = true; @@ -555,6 +569,10 @@ static int etnaviv_gem_new_impl(struct drm_device *dev, u32 size, u32 flags, case ETNA_BO_CACHED: case ETNA_BO_WC: break; + case ETNA_BO_CACHED_COHERENT: + if (priv->has_cached_coherent) + break; + fallthrough; default: valid = false; } diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c index 3524b5811682..671d91d8f1c6 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c @@ -112,11 +112,18 @@ static const struct etnaviv_gem_ops etnaviv_gem_prime_ops = { struct drm_gem_object *etnaviv_gem_prime_import_sg_table(struct drm_device *dev, struct dma_buf_attachment *attach, struct sg_table *sgt) { + struct etnaviv_drm_private *priv = dev->dev_private; struct etnaviv_gem_object *etnaviv_obj; size_t size = PAGE_ALIGN(attach->dmabuf->size); + u32 cache_flags; int ret, npages; - ret = etnaviv_gem_new_private(dev, size, ETNA_BO_WC, + if (priv->has_cached_coherent) + cache_flags = ETNA_BO_CACHED_COHERENT; + else + cache_flags = ETNA_BO_WC; + + ret = etnaviv_gem_new_private(dev, size, cache_flags, &etnaviv_gem_prime_ops, &etnaviv_obj); if (ret < 0) return ERR_PTR(ret); diff --git a/include/uapi/drm/etnaviv_drm.h b/include/uapi/drm/etnaviv_drm.h index af024d90453d..474b0db286de 100644 --- a/include/uapi/drm/etnaviv_drm.h +++ b/include/uapi/drm/etnaviv_drm.h @@ -90,13 +90,14 @@ struct drm_etnaviv_param { * GEM buffers: */ -#define ETNA_BO_CACHE_MASK 0x000f0000 +#define ETNA_BO_CACHE_MASK 0x000f0000 /* cache modes */ -#define ETNA_BO_CACHED 0x00010000 -#define ETNA_BO_WC 0x00020000 -#define ETNA_BO_UNCACHED 0x00040000 +#define ETNA_BO_CACHED 0x00010000 +#define ETNA_BO_WC 0x00020000 +#define ETNA_BO_UNCACHED 0x00040000 +#define ETNA_BO_CACHED_COHERENT 0x00080000 /* map flags */ -#define ETNA_BO_FORCE_MMU 0x00100000 +#define ETNA_BO_FORCE_MMU 0x00100000 struct drm_etnaviv_gem_new { __u64 size; /* in */