From: Bjorn Helgaas <helgaas@kernel.org>
To: "Krzysztof Wilczyński" <kw@linux.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>, linux-pci@vger.kernel.org
Subject: Re: [PATCH 2/4] PCI/sysfs: Add pci_dev_resource_attr() macro
Date: Thu, 26 Aug 2021 16:12:54 -0500 [thread overview]
Message-ID: <20210826211254.GA3717803@bjorn-Precision-5520> (raw)
In-Reply-To: <20210825212255.878043-3-kw@linux.com>
On Wed, Aug 25, 2021 at 09:22:53PM +0000, Krzysztof Wilczyński wrote:
> The pci_dev_resource_attr() macro will be used to declare and define
> each of the PCI resource sysfs objects statically while also reducing
> unnecessary code repetition.
>
> Internally this macro relies on the pci_dev_resource_attr_is_visible()
> helper which should correctly handle different types of PCI BAR address
> space while also providing support for creating either normal and/or
> write-combine attributes as required.
This makes a lot of sense. To make it more approachable, I think we
might extend the commit log to mention that each BAR is independently
visible/hidden based on its existence, and each .is_visible() function
applies to the entire attribute group, which means we need a separate
attribute group for each BAR. Actually I guess we need *two* for each
BAR -- the normal one and the WC one. So 12 attribute groups per
device.
> Signed-off-by: Krzysztof Wilczyński <kw@linux.com>
> ---
> drivers/pci/pci-sysfs.c | 47 +++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 47 insertions(+)
>
> diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
> index c94ab9830932..6eba5c0887df 100644
> --- a/drivers/pci/pci-sysfs.c
> +++ b/drivers/pci/pci-sysfs.c
> @@ -1277,6 +1277,53 @@ static umode_t pci_dev_resource_attr_is_visible(struct kobject *kobj,
>
> return attr->attr.mode;
> }
> +
> +#define pci_dev_resource_attr(_bar) \
> +static struct bin_attribute \
> +pci_dev_resource##_bar##_attr = __BIN_ATTR(resource##_bar, \
> + 0600, NULL, NULL, 0); \
> + \
> +static struct bin_attribute *pci_dev_resource##_bar##_attrs[] = { \
> + &pci_dev_resource##_bar##_attr, \
> + NULL, \
> +}; \
> + \
> +static umode_t \
> +pci_dev_resource##_bar##_attr_is_visible(struct kobject *kobj, \
> + struct bin_attribute *a, \
> + int n) \
> +{ \
> + return pci_dev_resource_attr_is_visible(kobj, a, _bar, false); \
> +}; \
> + \
> +static const struct \
> +attribute_group pci_dev_resource##_bar##_attr_group = { \
> + .bin_attrs = pci_dev_resource##_bar##_attrs, \
> + .is_bin_visible = pci_dev_resource##_bar##_attr_is_visible, \
> +}; \
> + \
> +static struct bin_attribute \
> +pci_dev_resource##_bar##_wc_attr = __BIN_ATTR(resource##_bar##_wc, \
> + 0600, NULL, NULL, 0); \
> + \
> +static struct bin_attribute *pci_dev_resource##_bar##_wc_attrs[] = { \
> + &pci_dev_resource##_bar##_wc_attr, \
> + NULL, \
> +}; \
> + \
> +static umode_t \
> +pci_dev_resource##_bar##_wc_attr_is_visible(struct kobject *kobj, \
> + struct bin_attribute *a, \
> + int n) \
> +{ \
> + return pci_dev_resource_attr_is_visible(kobj, a, _bar, true); \
> +}; \
> + \
> +static const struct \
> +attribute_group pci_dev_resource##_bar##_wc_attr_group = { \
> + .bin_attrs = pci_dev_resource##_bar##_wc_attrs, \
> + .is_bin_visible = pci_dev_resource##_bar##_wc_attr_is_visible, \
> +}
> #else /* !(defined(HAVE_PCI_MMAP) || defined(ARCH_GENERIC_PCI_MMAP_RESOURCE)) */
> int __weak pci_create_resource_files(struct pci_dev *dev) { return 0; }
> void __weak pci_remove_resource_files(struct pci_dev *dev) { return; }
> --
> 2.32.0
>
next prev parent reply other threads:[~2021-08-26 21:12 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-25 21:22 [PATCH 0/4] PCI: Convert dynamic PCI resources sysfs objects into static Krzysztof Wilczyński
2021-08-25 21:22 ` [PATCH 1/4] PCI/sysfs: Add pci_dev_resource_attr_is_visible() helper Krzysztof Wilczyński
2021-08-26 23:35 ` Bjorn Helgaas
2021-08-27 12:11 ` Greg Kroah-Hartman
2021-08-27 22:23 ` Bjorn Helgaas
2021-09-10 14:08 ` Greg Kroah-Hartman
2021-09-10 17:21 ` Krzysztof Wilczyński
2021-09-11 10:13 ` Greg Kroah-Hartman
2021-09-13 19:47 ` Bjorn Helgaas
2021-09-14 5:06 ` Greg Kroah-Hartman
2021-09-10 16:12 ` Krzysztof Wilczyński
2021-08-25 21:22 ` [PATCH 2/4] PCI/sysfs: Add pci_dev_resource_attr() macro Krzysztof Wilczyński
2021-08-26 21:12 ` Bjorn Helgaas [this message]
2021-08-25 21:22 ` [PATCH 3/4] PCI/sysfs: Add pci_dev_resource_group() macro Krzysztof Wilczyński
2021-08-25 21:22 ` [PATCH 4/4] PCI/sysfs: Convert PCI resource files to static attributes Krzysztof Wilczyński
2021-08-25 23:02 ` [PATCH 0/4] PCI: Convert dynamic PCI resources sysfs objects into static Krzysztof Wilczyński
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=20210826211254.GA3717803@bjorn-Precision-5520 \
--to=helgaas@kernel.org \
--cc=bhelgaas@google.com \
--cc=kw@linux.com \
--cc=linux-pci@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox