Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4958032rwd; Tue, 30 May 2023 12:22:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5kr5CmsxqzLR/rbBMYcoOpY1+WxQC5sCqCHCCy9bUVM6t0R3HhZbJSIaCQW/FDaFfzO3px X-Received: by 2002:a17:90a:c217:b0:256:4b34:8bdf with SMTP id e23-20020a17090ac21700b002564b348bdfmr3384082pjt.39.1685474565862; Tue, 30 May 2023 12:22:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685474565; cv=none; d=google.com; s=arc-20160816; b=AyeqOWfa40qKL18/HYNjbItAoMIbcCGUzYyavLN2qhs8A6QYJ0xulgALYZNL5D/Xnh bgHAPIgVeGRmCk1ar5K7/9EuiGItHr4jZ1xedsyp6Vg5j7RqhK43v598OwYM9S4S9HIA vtxxG+nO2lSvSeoO+EnXbkYOybyOif5vZcgKGYk487uRvTmKo2Z7A4WLMgDaR5MHWL4I ayWuJ6+X+FC5EBOwg0jPsUiNI6nACkC//J6XhlunBQzt9JR7GUacTen7/wS/ufcwd4ZV F7ie/1GuJ0CgoXyV7Jf3qN23oTPoRyCH5z8PumjgschrDFhPyQIJcr6X3TYpw8JbxLp/ 6UhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=acE3AToL6+KIbdl+du0hiCQX1b0gTQKo953l7nSPr/4=; b=OI9B9y2YC+yjb6L4v+IxOXHwFvZdrTCFubVpjyJjnPr3AmxawRXCA7YnuepL5/8dIp 7Q8ZWJszL9rH16/HKrs7jVWd6DvOK4I/DVpdvzJZKQL9iyXXEU3pvlZ61sRaHh2uWYd2 24dcASRZJuET+EwEDURe9k12DpelXXbBxfCBucFrA3uG+zi6L8L09M5bJpUuA4SEaVlk DfVpTLJ71FIUqLSlizxGxU64QUcURQNsoK5aqXWtgSzg+5I+ttCZvStxYxuiBpIg6Y+0 ePuejukGcI5je+oP+OgR1h2o01e1Y3Ezu3snvchhEpDapn7WOYst/dMmGBFpBTLTGEgu WTnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=g1hBOyaZ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w4-20020a17090a8a0400b00257a8dafd4esi311117pjn.60.2023.05.30.12.22.33; Tue, 30 May 2023 12:22:45 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=g1hBOyaZ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232318AbjE3TC7 (ORCPT + 99 others); Tue, 30 May 2023 15:02:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229877AbjE3TC6 (ORCPT ); Tue, 30 May 2023 15:02:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 629E6F9 for ; Tue, 30 May 2023 12:02:56 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EA8B760B8D for ; Tue, 30 May 2023 19:02:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DEA0C433EF; Tue, 30 May 2023 19:02:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685473375; bh=kqSuTI2XGCTdxpVxLgnvdx2lAi2xmZWmmkMTJXpgv4Y=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=g1hBOyaZ1E6vGI0X9WG1fjLb5qZGi5nMCTUAx7ik4Sx6kJ0lBrbhN3IQ2bYqQRBdQ fA/jqnvGr1PGFGopbCALz/Rp0EWBxCKtMEOT93RL5JVsQJf40GKNW44Crj+zb+OCMZ ugiNdAAMmPn/8oz1QvTCDiOdRJKI7rcPnLUfXC3RW/Me7xKfMd0MXa7wNl42PnvCP+ Po4GZpa9DBjb6GLukZP0IUmvdAL0hI4QDagL+kgSvleeNLZ9BtDVw9sUieWupHJRKl e5GWKVgoTJ2egwUdJlEHCvO0kNumOPce4cIyVquIyZRNduKjujNbASNsMHwUncbKdZ HvCB8hdNREkCg== Date: Tue, 30 May 2023 14:02:53 -0500 From: Bjorn Helgaas To: Sui Jingfeng Cc: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter , linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, loongson-kernel@lists.loongnix.cn Subject: Re: [PATCH v6 5/6] drm/etnaviv: add driver support for the PCI devices Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230530160643.2344551-6-suijingfeng@loongson.cn> X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 31, 2023 at 12:06:42AM +0800, Sui Jingfeng wrote: > This patch adds PCI driver support on top of what already have. Take the > GC1000 in LS7A1000/LS2K1000 as the first instance of the PCI device driver. > There is only one GPU core for the GC1000 in the LS7A1000 and LS2K1000. > Therefore, component frameworks can be avoided. Because we want to bind the > DRM driver service to the PCI driver manually. > + * Loongson Mips and LoongArch CPU(ls3a5000, ls3a4000, ls2k1000la) > + * maintain cache coherency by hardware > + */ > + if (IS_ENABLED(CONFIG_CPU_LOONGSON64) || IS_ENABLED(CONFIG_LOONGARCH)) > + priv->has_cached_coherent = true; This looks like something that should be a runtime check, not a compile-time check. If it's possible to build a single kernel image that runs on Loongson MIPS or LoongArch CPU and, in addition, runs on other platforms, you cannot assume that all the others maintain this cache coherency. > +static struct etnaviv_drm_private *etna_private_s; A static pointer looks wrong because it probably limits you to a single instance of something. > @@ -727,6 +756,12 @@ static int __init etnaviv_init(void) > if (ret != 0) > goto unregister_gpu_driver; > > +#ifdef CONFIG_DRM_ETNAVIV_PCI_DRIVER > + ret = pci_register_driver(&etnaviv_pci_driver); > +#endif > + if (ret != 0) > + goto unregister_platform_driver; Why is this outside the #ifdef? If CONFIG_DRM_ETNAVIV_PCI_DRIVER is not set, you already tested "ret != 0" above and will never take this goto. > +static int etnaviv_gpu_plat_drv_init(struct etnaviv_gpu *gpu, bool component) > +{ > + struct device *dev = gpu->dev; > + struct platform_device *pdev = to_platform_device(dev); > + int err; > + > + /* Map registers: */ > + gpu->mmio = devm_platform_ioremap_resource(pdev, 0); > + if (IS_ERR(gpu->mmio)) > + return PTR_ERR(gpu->mmio); > + > + if (component) { > + err = component_add(dev, &gpu_ops); > + if (err < 0) { > + dev_err(dev, "failed to register component: %d\n", err); > + return err; > + } > + } > + > + return 0; > +} All this platform driver rearrangement looks like it should be a separate patch so adding PCI support only adds PCI-related stuff. > +++ b/drivers/gpu/drm/etnaviv/etnaviv_pci_drv.c > @@ -0,0 +1,87 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +#include > + > +#include "etnaviv_drv.h" > +#include "etnaviv_gpu.h" > +#include "etnaviv_pci_drv.h" > + > +enum etnaviv_pci_gpu_family { > + GC1000_IN_LS7A1000 = 0, > + GC1000_IN_LS2K1000 = 1, Seems unused; why is this here? > +static int etnaviv_pci_probe(struct pci_dev *pdev, > + const struct pci_device_id *ent) > +{ > + struct device *dev = &pdev->dev; > + int ret; > + > + ret = pcim_enable_device(pdev); > + if (ret) { > + dev_err(&pdev->dev, "failed to enable\n"); Use "dev", no need for "&pdev->dev" since you already looked it up above. Also below for dma_set_mask_and_coherent(). > + return ret; > + } > + > + pci_set_master(pdev); > + > + ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); > +static const struct pci_device_id etnaviv_pci_id_lists[] = { > + {0x0014, 0x7a15, PCI_ANY_ID, PCI_ANY_ID, 0, 0, GC1000_IN_LS7A1000}, > + {0x0014, 0x7a05, PCI_ANY_ID, PCI_ANY_ID, 0, 0, GC1000_IN_LS2K1000}, > + {0, 0, 0, 0, 0, 0, 0} Should probably use PCI_DEVICE_DATA(). Use PCI_VENDOR_ID_LOONGSON. Only "{ }" required to terminate. > +++ b/drivers/gpu/drm/etnaviv/etnaviv_pci_drv.h > @@ -0,0 +1,12 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > + > +#ifndef __ETNAVIV_PCI_DRV_H__ > +#define __ETNAVIV_PCI_DRV_H__ > + > +#include This #include isn't required by this file. > +#ifdef CONFIG_DRM_ETNAVIV_PCI_DRIVER > +extern struct pci_driver etnaviv_pci_driver; > +#endif > + > +#endif