From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: suijingfeng <suijingfeng@loongson.cn>
Cc: Sui Jingfeng <sui.jingfeng@linux.dev>,
Bjorn Helgaas <bhelgaas@google.com>,
Dave Airlie <airlied@redhat.com>, Daniel Vetter <daniel@ffwll.ch>,
linux-pci@vger.kernel.org, dri-devel@lists.freedesktop.org,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 02/11] PCI: Add the pci_get_class_masked() helper
Date: Fri, 11 Aug 2023 09:31:15 +0300 (EEST) [thread overview]
Message-ID: <9e512f44-c47f-85e8-0ea-81d7cbc99a67@linux.intel.com> (raw)
In-Reply-To: <a0d6277c-a4ad-38a5-bc6f-883513987547@loongson.cn>
[-- Attachment #1: Type: text/plain, Size: 5586 bytes --]
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 <suijingfeng@loongson.cn>
> > >
> > > 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 <suijingfeng@loongson.cn>
> > > ---
> > > 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; }
> > >
>
WARNING: multiple messages have this Message-ID (diff)
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: suijingfeng <suijingfeng@loongson.cn>
Cc: Sui Jingfeng <sui.jingfeng@linux.dev>,
linux-pci@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>,
dri-devel@lists.freedesktop.org,
Bjorn Helgaas <bhelgaas@google.com>,
Dave Airlie <airlied@redhat.com>
Subject: Re: [PATCH v2 02/11] PCI: Add the pci_get_class_masked() helper
Date: Fri, 11 Aug 2023 09:31:15 +0300 (EEST) [thread overview]
Message-ID: <9e512f44-c47f-85e8-0ea-81d7cbc99a67@linux.intel.com> (raw)
In-Reply-To: <a0d6277c-a4ad-38a5-bc6f-883513987547@loongson.cn>
[-- Attachment #1: Type: text/plain, Size: 5586 bytes --]
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 <suijingfeng@loongson.cn>
> > >
> > > 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 <suijingfeng@loongson.cn>
> > > ---
> > > 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; }
> > >
>
next prev parent reply other threads:[~2023-08-11 6:31 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-08 22:34 [PATCH v2 00/11] Fix typos, comments and copyright Sui Jingfeng
2023-08-08 22:34 ` Sui Jingfeng
2023-08-08 22:34 ` [PATCH v2 01/11] PCI/VGA: Use unsigned type for the io_state variable Sui Jingfeng
2023-08-08 22:34 ` Sui Jingfeng
2023-08-09 13:57 ` Ilpo Järvinen
2023-08-09 13:57 ` Ilpo Järvinen
2023-08-08 22:34 ` [PATCH v2 02/11] PCI: Add the pci_get_class_masked() helper Sui Jingfeng
2023-08-08 22:34 ` Sui Jingfeng
2023-08-09 14:01 ` Ilpo Järvinen
2023-08-09 14:01 ` Ilpo Järvinen
2023-08-10 13:05 ` suijingfeng
2023-08-10 13:05 ` suijingfeng
2023-08-11 6:31 ` Ilpo Järvinen [this message]
2023-08-11 6:31 ` Ilpo Järvinen
2023-08-08 22:34 ` [PATCH v2 03/11] PCI/VGA: Deal with VGA class devices Sui Jingfeng
2023-08-08 22:34 ` Sui Jingfeng
2023-08-08 22:34 ` [PATCH v2 04/11] PCI/VGA: Drop the inline in the vga_update_device_decodes() function Sui Jingfeng
2023-08-08 22:34 ` Sui Jingfeng
2023-08-09 14:10 ` Ilpo Järvinen
2023-08-09 14:10 ` Ilpo Järvinen
2023-08-08 22:34 ` [PATCH v2 05/11] PCI/VGA: Move the new_state assignment out of the loop Sui Jingfeng
2023-08-08 22:34 ` Sui Jingfeng
2023-08-09 13:55 ` Ilpo Järvinen
2023-08-09 13:55 ` Ilpo Järvinen
2023-08-08 22:34 ` [PATCH v2 06/11] PCI/VGA: Fix two typos in the comments of pci_notify() Sui Jingfeng
2023-08-08 22:34 ` Sui Jingfeng
2023-08-09 14:12 ` Ilpo Järvinen
2023-08-09 14:12 ` Ilpo Järvinen
2023-08-10 12:04 ` suijingfeng
2023-08-10 12:04 ` suijingfeng
2023-08-08 22:34 ` [PATCH v2 07/11] PCI/VGA: vga_client_register() return -ENODEV on failure, not -1 Sui Jingfeng
2023-08-08 22:34 ` Sui Jingfeng
2023-08-09 13:52 ` Ilpo Järvinen
2023-08-09 13:52 ` Ilpo Järvinen
2023-08-10 11:56 ` suijingfeng
2023-08-10 11:56 ` suijingfeng
2023-08-10 12:13 ` Ilpo Järvinen
2023-08-10 12:13 ` Ilpo Järvinen
2023-08-10 12:18 ` Sui Jingfeng
2023-08-10 12:18 ` Sui Jingfeng
2023-08-08 22:34 ` [PATCH v2 08/11] PCI/VGA: Fix a typo to the comment of vga_default Sui Jingfeng
2023-08-08 22:34 ` Sui Jingfeng
2023-08-09 14:14 ` Ilpo Järvinen
2023-08-09 14:14 ` Ilpo Järvinen
2023-08-08 22:34 ` [PATCH v2 09/11] PCI/VGA: Fix a typo to the comments in vga_str_to_iostate() function Sui Jingfeng
2023-08-08 22:34 ` Sui Jingfeng
2023-08-08 22:34 ` [PATCH v2 10/11] PCI/VGA: Tidy up the code and comment format Sui Jingfeng
2023-08-08 22:34 ` Sui Jingfeng
2023-08-09 14:18 ` Ilpo Järvinen
2023-08-09 14:18 ` Ilpo Järvinen
2023-08-08 22:34 ` [PATCH v2 11/11] PCI/VGA: Replace full MIT license text with SPDX identifier Sui Jingfeng
2023-08-08 22:34 ` Sui Jingfeng
2023-08-23 22:29 ` [PATCH v2 00/11] Fix typos, comments and copyright Bjorn Helgaas
2023-08-23 22:29 ` Bjorn Helgaas
2023-08-24 6:21 ` suijingfeng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9e512f44-c47f-85e8-0ea-81d7cbc99a67@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=airlied@redhat.com \
--cc=bhelgaas@google.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=sui.jingfeng@linux.dev \
--cc=suijingfeng@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.