Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp832624rdg; Fri, 11 Aug 2023 00:44:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHJVQvrbhM0z21Em97zdRQLA48w1iYRR+b5IDks5CtFgGLMJUkSKkX1WOl+WzPXAxzAqGpz X-Received: by 2002:a05:6830:4ab:b0:6b8:691e:ec53 with SMTP id l11-20020a05683004ab00b006b8691eec53mr1124513otd.11.1691739859641; Fri, 11 Aug 2023 00:44:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691739859; cv=none; d=google.com; s=arc-20160816; b=Y+b4nBpXrPwhQRZ5PlOu5dn008eVe2swSc5N7lpGJtWhxhX2R46nt2D/Zx5LGX2MPC GmJer1g2/PJKPaW5XbqUXyzQfmlbwG8yR7V1YCJ55g1Wpobe4DhZlHiH/XWW83ClyLxF 6w7HPLSvngcXspnY3BwmtOHPAXfGe/kX9891dUepBPqjTcmZweeAPQOUo8K35BENwU1J se6MQdU1l+wW2mjh5E0wlu+BT6+h3MJI8MgzkOQWVsYO/MCGZNHk1EpqthODd3f1GDvi C5fPA1AdmkPPO88ep3PnsC4yBu0EACGP0TyQ456iaZQDr6dWxZr388c+aZO7gJ8O7R8s a8mA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-id:mime-version:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=+99eROtw6Hdoq4SjD9lauww6yKchPP4uvMOdBiJReNk=; fh=jzOxGGitWEHw1onNaLh/VCcX6gby8pOffE48y2SSTDk=; b=CU/5x2Y1tOSFCHptvRzsMsNRVn1kcmGWoTbiXG1G22/J7wVjxIlWhc1UAOhHEOT0jn /6oSe5473iGkOPhmZhs8u/TtMwTsNMe1jdXZ4UYqulNbpMTDRCZjEm1+PIDWwNzUqvuO SYM728mHVapdfzR6z/RTihgJyWCBXDi9ahDagAf6TjcyDzv3irHd3FcKuD0DRW2ghzJh 44M8nJo+ErcvPWpyGIaBiIDn/ySbjyrQDvXrEuKmOvv7xMjiX0N7/FWl04ROMVHDgHd7 WGecDUnvDupj4+5VbSFL09ewKpb4mIoPmJqoly+Ad3jZUeZWZNVCP26uB0C8/PbLwsbO lIeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SF74kWAa; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ls9-20020a17090b350900b00263bfa6e205si5425346pjb.50.2023.08.11.00.44.06; Fri, 11 Aug 2023 00:44:19 -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=@intel.com header.s=Intel header.b=SF74kWAa; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233265AbjHKGb0 (ORCPT + 99 others); Fri, 11 Aug 2023 02:31:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229829AbjHKGbZ (ORCPT ); Fri, 11 Aug 2023 02:31:25 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 998D4E3; Thu, 10 Aug 2023 23:31:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1691735484; x=1723271484; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version:content-id; bh=V7PsEkPjhDBm1ENkVpxF6OMUVudl/gPj3e7UY4Zbwrc=; b=SF74kWAanqmhu8F2pX7MECYz/55d8SBqiI+RKrKkOWVwb+3QWoJrvOsh IAwCdhzaAmgpKqTwBXmc5LzW2egyUpmOFkuN7aHq6OhJRB01I28LMJzI0 9IPU53s1IwwNodPgU3laXJoLykwT10UH5wPgya+765zvWGlAyqcoftvvR ZQWW65f1EobA0SxoibjB/nkJ+w6g5rVsTavNSKi6v4AJ/L33EIrH9g+pt RgNbR6vUzl7dOeeWUk9708WpHn1xcz5DscNB5fWKl+Y+VQHDSfdwYo6xa Lxmokbl/mdSq55T9dSW1dHF797H+ajIpn+r9OtaKbTi5YaSb0+cUAP8hX g==; X-IronPort-AV: E=McAfee;i="6600,9927,10798"; a="356571517" X-IronPort-AV: E=Sophos;i="6.01,164,1684825200"; d="scan'208";a="356571517" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Aug 2023 23:31:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10798"; a="822550154" X-IronPort-AV: E=Sophos;i="6.01,164,1684825200"; d="scan'208";a="822550154" Received: from aberko-mobl1.ger.corp.intel.com ([10.252.51.87]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Aug 2023 23:31:21 -0700 Date: Fri, 11 Aug 2023 09:31:15 +0300 (EEST) From: =?ISO-8859-15?Q?Ilpo_J=E4rvinen?= To: suijingfeng cc: Sui Jingfeng , Bjorn Helgaas , Dave Airlie , Daniel Vetter , linux-pci@vger.kernel.org, dri-devel@lists.freedesktop.org, LKML Subject: Re: [PATCH v2 02/11] PCI: Add the pci_get_class_masked() helper In-Reply-To: Message-ID: <9e512f44-c47f-85e8-0ea-81d7cbc99a67@linux.intel.com> References: <20230808223412.1743176-1-sui.jingfeng@linux.dev> <20230808223412.1743176-3-sui.jingfeng@linux.dev> <19dc4b81-5b72-247c-d459-3ea9d1cddff0@linux.intel.com> MIME-Version: 1.0 Content-Type: multipart/mixed; BOUNDARY="8323329-1349199904-1691734933=:1742" Content-ID: <50a536e7-4387-1688-4c95-d3496f7b66d@linux.intel.com> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED 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 This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-1349199904-1691734933=:1742 Content-Type: text/plain; CHARSET=ISO-8859-15 Content-Transfer-Encoding: 8BIT Content-ID: On Thu, 10 Aug 2023, suijingfeng wrote: > Hi, > > > On 2023/8/9 22:01, Ilpo J?rvinen wrote: > > On Wed, 9 Aug 2023, Sui Jingfeng wrote: > > > > > From: Sui Jingfeng > > > > > > Because there is no good way to get the mask member used to searching for > > > devices that conform to a specific PCI class code, an application needs to > > > process all PCI display devices can achieve its goal as follows: > > This is mixing old and new way in a single sentence (which is confusing)? > > > Thanks for reviewing, but I can't understand this sentence. > Are you telling me that my description have grammar problem or something else? I think it's a bit of both. > I means that before apply this patch, we don't have a function can be used > to get all PCI(e) devices in a system by matching against its the PCI base > class code only, > while keep the Sub-Class code and the Programming Interface ignored. > By supply a mask as argument, such thing become possible. This explanation you put into this reply is much easier to follow and understand. I recommend you'd use it to replace the unclear fragment above. So something along the lines of: There is no function that can be used to get all PCI(e) devices in a system by matching against its the PCI base class code only, while keep the Sub-Class code and the Programming Interface ignored. Add pci_get_class_masked() to allow supplying a mask for the get. [After this you can put the explanining code block+its intro if you want] -- i. > If an application want to process all PCI display devices in the system, > then it can achieve its goal by calling pci_get_class_masked() function. > > > > > pdev = NULL; > > > do { > > > pdev = pci_get_class_masked(PCI_BASE_CLASS_DISPLAY << 16, 0xFF0000, > > > pdev); > > > if (pdev) > > > do_something_for_pci_display_device(pdev); > > > } while (pdev); > > > > > > While previously, we just can not ignore Sub-Class code and the > > > Programming > > cannot > > > > > Interface byte when do the searching. > > doing the search. > > > OK, will be fixed at the next version. > > > > > Signed-off-by: Sui Jingfeng > > > --- > > > drivers/pci/search.c | 30 ++++++++++++++++++++++++++++++ > > > include/linux/pci.h | 7 +++++++ > > > 2 files changed, 37 insertions(+) > > > > > > diff --git a/drivers/pci/search.c b/drivers/pci/search.c > > > index b4c138a6ec02..f1c15aea868b 100644 > > > --- a/drivers/pci/search.c > > > +++ b/drivers/pci/search.c > > > @@ -334,6 +334,36 @@ struct pci_dev *pci_get_device(unsigned int vendor, > > > unsigned int device, > > > } > > > EXPORT_SYMBOL(pci_get_device); > > > +/** > > > + * pci_get_class_masked - begin or continue searching for a PCI device by > > > class and mask > > > + * @class: search for a PCI device with this class designation > > > + * @from: Previous PCI device found in search, or %NULL for new search. > > > + * > > > + * Iterates through the list of known PCI devices. If a PCI device is > > No double spaces in kernel comments. Perhaps your editor might be adding > > them on reflow (might be configurable to not do that). > > > > > + * found with a matching @class, the reference count to the device is > > > + * incremented and a pointer to its device structure is returned. > > > + * Otherwise, %NULL is returned. > > > + * A new search is initiated by passing %NULL as the @from argument. > > > + * Otherwise if @from is not %NULL, searches continue from next device > > > + * on the global list. The reference count for @from is always > > > decremented > > > + * if it is not %NULL. > > Use kerneldoc's Return: section for describing return value. > > > > > + */ > > > +struct pci_dev *pci_get_class_masked(unsigned int class, unsigned int > > > mask, > > > + struct pci_dev *from) > > > +{ > > > + struct pci_device_id id = { > > > + .vendor = PCI_ANY_ID, > > > + .device = PCI_ANY_ID, > > > + .subvendor = PCI_ANY_ID, > > > + .subdevice = PCI_ANY_ID, > > > + .class_mask = mask, > > > + .class = class, > > > + }; > > > + > > > + return pci_get_dev_by_id(&id, from); > > > +} > > > +EXPORT_SYMBOL(pci_get_class_masked); > > > + > > > /** > > > * pci_get_class - begin or continue searching for a PCI device by class > > > * @class: search for a PCI device with this class designation > > > diff --git a/include/linux/pci.h b/include/linux/pci.h > > > index 0ff7500772e6..b20e7ba844bf 100644 > > > --- a/include/linux/pci.h > > > +++ b/include/linux/pci.h > > > @@ -1180,6 +1180,9 @@ struct pci_dev *pci_get_slot(struct pci_bus *bus, > > > unsigned int devfn); > > > struct pci_dev *pci_get_domain_bus_and_slot(int domain, unsigned int > > > bus, > > > unsigned int devfn); > > > struct pci_dev *pci_get_class(unsigned int class, struct pci_dev *from); > > > +struct pci_dev *pci_get_class_masked(unsigned int class, unsigned int > > > mask, > > > + struct pci_dev *from); > > > + > > > int pci_dev_present(const struct pci_device_id *ids); > > > int pci_bus_read_config_byte(struct pci_bus *bus, unsigned int devfn, > > > @@ -1895,6 +1898,10 @@ static inline struct pci_dev > > > *pci_get_class(unsigned int class, > > > struct pci_dev *from) > > > { return NULL; } > > > +static inline struct pci_dev *pci_get_class_masked(unsigned int class, > > > + unsigned int mask, > > > + struct pci_dev *from) > > > +{ return NULL; } > > > static inline int pci_dev_present(const struct pci_device_id *ids) > > > { return 0; } > > > > --8323329-1349199904-1691734933=:1742--