2023-09-30 02:43:46

by D Scott Phillips

[permalink] [raw]
Subject: [PATCH v2 1/2] PCI: acpiphp: Allow built-in attention drivers

Starting from the introduction of the attention callback in acpiphp, a
non-zero struct module *owner field has been required in
acpiphp_register_attention(). Then intent seemed to be that the core code
could then hold a refcount on the module while invoking a callback.

This check accidentally precludes the possiblity of attention callbacks to
drivers which are built-in.

Remove the check on `struct module *owner` in acpiphp_register_attention()
so that attention callbacks can also be registered from built-in drivers.

Signed-off-by: D Scott Phillips <[email protected]>
---
Changes since v1:
- new patch in the series

drivers/pci/hotplug/acpiphp_core.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/pci/hotplug/acpiphp_core.c b/drivers/pci/hotplug/acpiphp_core.c
index c02257f4b61c4..9dad14e80bcf2 100644
--- a/drivers/pci/hotplug/acpiphp_core.c
+++ b/drivers/pci/hotplug/acpiphp_core.c
@@ -78,8 +78,7 @@ int acpiphp_register_attention(struct acpiphp_attention_info *info)
{
int retval = -EINVAL;

- if (info && info->owner && info->set_attn &&
- info->get_attn && !attention_info) {
+ if (info && info->set_attn && info->get_attn && !attention_info) {
retval = 0;
attention_info = info;
}
--
2.41.0


2023-09-30 10:27:27

by D Scott Phillips

[permalink] [raw]
Subject: [PATCH v2 2/2] PCI: hotplug: Add extension driver for Ampere Altra hotplug LED control

On Ampere Altra, PCIe hotplug is handled through ACPI. A side interface is
also present to request system firmware control of attention LEDs. Add an
ACPI PCI Hotplug companion driver to support attention LED control.

Signed-off-by: D Scott Phillips <[email protected]>
---
Changes since v1:
- remove build-as-module restriction
- add some more description
- don't open code PCI_SLOT()
- convert to a platform driver

drivers/pci/hotplug/Kconfig | 12 ++
drivers/pci/hotplug/Makefile | 1 +
drivers/pci/hotplug/acpiphp_ampere_altra.c | 127 +++++++++++++++++++++
3 files changed, 140 insertions(+)
create mode 100644 drivers/pci/hotplug/acpiphp_ampere_altra.c

diff --git a/drivers/pci/hotplug/Kconfig b/drivers/pci/hotplug/Kconfig
index 48113b210cf93..1472aef0fb812 100644
--- a/drivers/pci/hotplug/Kconfig
+++ b/drivers/pci/hotplug/Kconfig
@@ -61,6 +61,18 @@ config HOTPLUG_PCI_ACPI

When in doubt, say N.

+config HOTPLUG_PCI_ACPI_AMPERE_ALTRA
+ tristate "ACPI PCI Hotplug driver Ampere Altra extensions"
+ depends on HOTPLUG_PCI_ACPI
+ depends on HAVE_ARM_SMCCC_DISCOVERY
+ help
+ Say Y here if you have an Ampere Altra system.
+
+ To compile this driver as a module, choose M here: the
+ module will be called acpiphp_ampere_altra.
+
+ When in doubt, say N.
+
config HOTPLUG_PCI_ACPI_IBM
tristate "ACPI PCI Hotplug driver IBM extensions"
depends on HOTPLUG_PCI_ACPI
diff --git a/drivers/pci/hotplug/Makefile b/drivers/pci/hotplug/Makefile
index 5196983220df6..240c99517d5e9 100644
--- a/drivers/pci/hotplug/Makefile
+++ b/drivers/pci/hotplug/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_HOTPLUG_PCI_S390) += s390_pci_hpc.o

# acpiphp_ibm extends acpiphp, so should be linked afterwards.

+obj-$(CONFIG_HOTPLUG_PCI_ACPI_AMPERE_ALTRA) += acpiphp_ampere_altra.o
obj-$(CONFIG_HOTPLUG_PCI_ACPI_IBM) += acpiphp_ibm.o

pci_hotplug-objs := pci_hotplug_core.o
diff --git a/drivers/pci/hotplug/acpiphp_ampere_altra.c b/drivers/pci/hotplug/acpiphp_ampere_altra.c
new file mode 100644
index 0000000000000..1b1fe5d6a3fbf
--- /dev/null
+++ b/drivers/pci/hotplug/acpiphp_ampere_altra.c
@@ -0,0 +1,127 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * ACPI PCI Hot Plug Extension for Ampere Altra. Allows control of
+ * attention LEDs via requests to system firmware.
+ *
+ * Copyright (C) 2023 Ampere Computing LLC
+ */
+
+#define pr_fmt(fmt) "acpiphp_ampere_altra: " fmt
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/pci_hotplug.h>
+#include <linux/platform_device.h>
+
+#include "acpiphp.h"
+
+#define HANDLE_OPEN 0xb0200000
+#define HANDLE_CLOSE 0xb0300000
+#define REQUEST 0xf0700000
+#define LED_CMD 0x00000004
+#define LED_ATTENTION 0x00000002
+#define LED_SET_ON 0x00000001
+#define LED_SET_OFF 0x00000002
+#define LED_SET_BLINK 0x00000003
+
+static u32 led_service_id[4];
+
+static int led_status(u8 status)
+{
+ switch (status) {
+ case 1: return LED_SET_ON;
+ case 2: return LED_SET_BLINK;
+ default: return LED_SET_OFF;
+ }
+}
+
+static int set_attention_status(struct hotplug_slot *slot, u8 status)
+{
+ struct arm_smccc_res res;
+ struct pci_bus *bus;
+ struct pci_dev *root_port;
+ unsigned long flags;
+ u32 handle;
+ int ret = 0;
+
+ bus = slot->pci_slot->bus;
+ root_port = pcie_find_root_port(bus->self);
+ if (!root_port)
+ return -ENODEV;
+
+ local_irq_save(flags);
+ arm_smccc_smc(HANDLE_OPEN, led_service_id[0], led_service_id[1],
+ led_service_id[2], led_service_id[3], 0, 0, 0, &res);
+ if (res.a0) {
+ ret = -ENODEV;
+ goto out;
+ }
+ handle = res.a1 & 0xffff0000;
+
+ arm_smccc_smc(REQUEST, LED_CMD, led_status(status), LED_ATTENTION,
+ pci_domain_nr(bus) | (PCI_SLOT(root_port->devfn) << 4), 0, 0,
+ handle, &res);
+ if (res.a0)
+ ret = -ENODEV;
+
+ arm_smccc_smc(HANDLE_CLOSE, handle, 0, 0, 0, 0, 0, 0, &res);
+
+ out:
+ local_irq_restore(flags);
+ return ret;
+}
+
+static int get_attention_status(struct hotplug_slot *slot, u8 *status)
+{
+ return -EINVAL;
+}
+
+static struct acpiphp_attention_info ampere_altra_attn = {
+ .set_attn = set_attention_status,
+ .get_attn = get_attention_status,
+ .owner = THIS_MODULE,
+};
+
+static int altra_led_probe(struct platform_device *pdev)
+{
+ struct fwnode_handle *fwnode = dev_fwnode(&pdev->dev);
+ int ret;
+
+ ret = fwnode_property_read_u32_array(fwnode, "uuid", led_service_id, 4);
+ if (ret) {
+ dev_err(&pdev->dev, "can't find uuid\n");
+ return ret;
+ }
+
+ ret = acpiphp_register_attention(&ampere_altra_attn);
+ if (ret) {
+ dev_err(&pdev->dev, "can't register driver\n");
+ return ret;
+ }
+ return 0;
+}
+
+static void altra_led_remove(struct platform_device *pdev)
+{
+ acpiphp_unregister_attention(&ampere_altra_attn);
+}
+
+static const struct acpi_device_id altra_led_ids[] = {
+ { "AMPC0008", 0 },
+ { }
+};
+MODULE_DEVICE_TABLE(acpi, altra_led_ids);
+
+static struct platform_driver altra_led_driver = {
+ .driver = {
+ .name = "ampere-altra-leds",
+ .acpi_match_table = altra_led_ids,
+ },
+ .probe = altra_led_probe,
+ .remove_new = altra_led_remove,
+};
+module_platform_driver(altra_led_driver);
+
+MODULE_AUTHOR("D Scott Phillips <[email protected]>");
+MODULE_LICENSE("GPL");
--
2.41.0

2023-10-03 18:33:14

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] PCI: hotplug: Add extension driver for Ampere Altra hotplug LED control

On Sat, Sep 30, 2023 at 2:20 AM D Scott Phillips
<[email protected]> wrote:
>
> On Ampere Altra, PCIe hotplug is handled through ACPI. A side interface is
> also present to request system firmware control of attention LEDs. Add an
> ACPI PCI Hotplug companion driver to support attention LED control.
>
> Signed-off-by: D Scott Phillips <[email protected]>

Acked-by: Rafael J. Wysocki <[email protected]>

for the probing part.

> ---
> Changes since v1:
> - remove build-as-module restriction
> - add some more description
> - don't open code PCI_SLOT()
> - convert to a platform driver
>
> drivers/pci/hotplug/Kconfig | 12 ++
> drivers/pci/hotplug/Makefile | 1 +
> drivers/pci/hotplug/acpiphp_ampere_altra.c | 127 +++++++++++++++++++++
> 3 files changed, 140 insertions(+)
> create mode 100644 drivers/pci/hotplug/acpiphp_ampere_altra.c
>
> diff --git a/drivers/pci/hotplug/Kconfig b/drivers/pci/hotplug/Kconfig
> index 48113b210cf93..1472aef0fb812 100644
> --- a/drivers/pci/hotplug/Kconfig
> +++ b/drivers/pci/hotplug/Kconfig
> @@ -61,6 +61,18 @@ config HOTPLUG_PCI_ACPI
>
> When in doubt, say N.
>
> +config HOTPLUG_PCI_ACPI_AMPERE_ALTRA
> + tristate "ACPI PCI Hotplug driver Ampere Altra extensions"
> + depends on HOTPLUG_PCI_ACPI
> + depends on HAVE_ARM_SMCCC_DISCOVERY
> + help
> + Say Y here if you have an Ampere Altra system.
> +
> + To compile this driver as a module, choose M here: the
> + module will be called acpiphp_ampere_altra.
> +
> + When in doubt, say N.
> +
> config HOTPLUG_PCI_ACPI_IBM
> tristate "ACPI PCI Hotplug driver IBM extensions"
> depends on HOTPLUG_PCI_ACPI
> diff --git a/drivers/pci/hotplug/Makefile b/drivers/pci/hotplug/Makefile
> index 5196983220df6..240c99517d5e9 100644
> --- a/drivers/pci/hotplug/Makefile
> +++ b/drivers/pci/hotplug/Makefile
> @@ -23,6 +23,7 @@ obj-$(CONFIG_HOTPLUG_PCI_S390) += s390_pci_hpc.o
>
> # acpiphp_ibm extends acpiphp, so should be linked afterwards.
>
> +obj-$(CONFIG_HOTPLUG_PCI_ACPI_AMPERE_ALTRA) += acpiphp_ampere_altra.o
> obj-$(CONFIG_HOTPLUG_PCI_ACPI_IBM) += acpiphp_ibm.o
>
> pci_hotplug-objs := pci_hotplug_core.o
> diff --git a/drivers/pci/hotplug/acpiphp_ampere_altra.c b/drivers/pci/hotplug/acpiphp_ampere_altra.c
> new file mode 100644
> index 0000000000000..1b1fe5d6a3fbf
> --- /dev/null
> +++ b/drivers/pci/hotplug/acpiphp_ampere_altra.c
> @@ -0,0 +1,127 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * ACPI PCI Hot Plug Extension for Ampere Altra. Allows control of
> + * attention LEDs via requests to system firmware.
> + *
> + * Copyright (C) 2023 Ampere Computing LLC
> + */
> +
> +#define pr_fmt(fmt) "acpiphp_ampere_altra: " fmt
> +
> +#include <linux/init.h>
> +#include <linux/module.h>
> +#include <linux/pci.h>
> +#include <linux/pci_hotplug.h>
> +#include <linux/platform_device.h>
> +
> +#include "acpiphp.h"
> +
> +#define HANDLE_OPEN 0xb0200000
> +#define HANDLE_CLOSE 0xb0300000
> +#define REQUEST 0xf0700000
> +#define LED_CMD 0x00000004
> +#define LED_ATTENTION 0x00000002
> +#define LED_SET_ON 0x00000001
> +#define LED_SET_OFF 0x00000002
> +#define LED_SET_BLINK 0x00000003
> +
> +static u32 led_service_id[4];
> +
> +static int led_status(u8 status)
> +{
> + switch (status) {
> + case 1: return LED_SET_ON;
> + case 2: return LED_SET_BLINK;
> + default: return LED_SET_OFF;
> + }
> +}
> +
> +static int set_attention_status(struct hotplug_slot *slot, u8 status)
> +{
> + struct arm_smccc_res res;
> + struct pci_bus *bus;
> + struct pci_dev *root_port;
> + unsigned long flags;
> + u32 handle;
> + int ret = 0;
> +
> + bus = slot->pci_slot->bus;
> + root_port = pcie_find_root_port(bus->self);
> + if (!root_port)
> + return -ENODEV;
> +
> + local_irq_save(flags);
> + arm_smccc_smc(HANDLE_OPEN, led_service_id[0], led_service_id[1],
> + led_service_id[2], led_service_id[3], 0, 0, 0, &res);
> + if (res.a0) {
> + ret = -ENODEV;
> + goto out;
> + }
> + handle = res.a1 & 0xffff0000;
> +
> + arm_smccc_smc(REQUEST, LED_CMD, led_status(status), LED_ATTENTION,
> + pci_domain_nr(bus) | (PCI_SLOT(root_port->devfn) << 4), 0, 0,
> + handle, &res);
> + if (res.a0)
> + ret = -ENODEV;
> +
> + arm_smccc_smc(HANDLE_CLOSE, handle, 0, 0, 0, 0, 0, 0, &res);
> +
> + out:
> + local_irq_restore(flags);
> + return ret;
> +}
> +
> +static int get_attention_status(struct hotplug_slot *slot, u8 *status)
> +{
> + return -EINVAL;
> +}
> +
> +static struct acpiphp_attention_info ampere_altra_attn = {
> + .set_attn = set_attention_status,
> + .get_attn = get_attention_status,
> + .owner = THIS_MODULE,
> +};
> +
> +static int altra_led_probe(struct platform_device *pdev)
> +{
> + struct fwnode_handle *fwnode = dev_fwnode(&pdev->dev);
> + int ret;
> +
> + ret = fwnode_property_read_u32_array(fwnode, "uuid", led_service_id, 4);
> + if (ret) {
> + dev_err(&pdev->dev, "can't find uuid\n");
> + return ret;
> + }
> +
> + ret = acpiphp_register_attention(&ampere_altra_attn);
> + if (ret) {
> + dev_err(&pdev->dev, "can't register driver\n");
> + return ret;
> + }
> + return 0;
> +}
> +
> +static void altra_led_remove(struct platform_device *pdev)
> +{
> + acpiphp_unregister_attention(&ampere_altra_attn);
> +}
> +
> +static const struct acpi_device_id altra_led_ids[] = {
> + { "AMPC0008", 0 },
> + { }
> +};
> +MODULE_DEVICE_TABLE(acpi, altra_led_ids);
> +
> +static struct platform_driver altra_led_driver = {
> + .driver = {
> + .name = "ampere-altra-leds",
> + .acpi_match_table = altra_led_ids,
> + },
> + .probe = altra_led_probe,
> + .remove_new = altra_led_remove,
> +};
> +module_platform_driver(altra_led_driver);
> +
> +MODULE_AUTHOR("D Scott Phillips <[email protected]>");
> +MODULE_LICENSE("GPL");
> --
> 2.41.0
>

2023-10-11 00:13:45

by D Scott Phillips

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] PCI: acpiphp: Allow built-in attention drivers

D Scott Phillips <[email protected]> writes:

> Starting from the introduction of the attention callback in acpiphp, a
> non-zero struct module *owner field has been required in
> acpiphp_register_attention(). Then intent seemed to be that the core code
> could then hold a refcount on the module while invoking a callback.
>
> This check accidentally precludes the possiblity of attention callbacks to
> drivers which are built-in.
>
> Remove the check on `struct module *owner` in acpiphp_register_attention()
> so that attention callbacks can also be registered from built-in drivers.

Hi Bjorn, ping on these, thanks

Scott

>
> Signed-off-by: D Scott Phillips <[email protected]>
> ---
> Changes since v1:
> - new patch in the series
>
> drivers/pci/hotplug/acpiphp_core.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/pci/hotplug/acpiphp_core.c b/drivers/pci/hotplug/acpiphp_core.c
> index c02257f4b61c4..9dad14e80bcf2 100644
> --- a/drivers/pci/hotplug/acpiphp_core.c
> +++ b/drivers/pci/hotplug/acpiphp_core.c
> @@ -78,8 +78,7 @@ int acpiphp_register_attention(struct acpiphp_attention_info *info)
> {
> int retval = -EINVAL;
>
> - if (info && info->owner && info->set_attn &&
> - info->get_attn && !attention_info) {
> + if (info && info->set_attn && info->get_attn && !attention_info) {
> retval = 0;
> attention_info = info;
> }
> --
> 2.41.0

2023-10-25 17:23:16

by Bjorn Helgaas

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] PCI: hotplug: Add extension driver for Ampere Altra hotplug LED control

On Fri, Sep 29, 2023 at 05:20:36PM -0700, D Scott Phillips wrote:
> On Ampere Altra, PCIe hotplug is handled through ACPI. A side interface is
> also present to request system firmware control of attention LEDs. Add an
> ACPI PCI Hotplug companion driver to support attention LED control.
> ...

> + arm_smccc_smc(REQUEST, LED_CMD, led_status(status), LED_ATTENTION,
> + pci_domain_nr(bus) | (PCI_SLOT(root_port->devfn) << 4), 0, 0,

pci_domain_nr() returns "int" (normally 32 bits), but since this is an
ACPI system, the domain comes from _SEG, which is defined to be 16
bits (ACPI r6.5, sec 6.5.6).

So it looks like ORing in the "slot << 4" clobbers the upper 12 bits
of _SEG.

Is this code doing the right thing?

2023-10-25 17:42:59

by D Scott Phillips

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] PCI: hotplug: Add extension driver for Ampere Altra hotplug LED control

Bjorn Helgaas <[email protected]> writes:

> On Fri, Sep 29, 2023 at 05:20:36PM -0700, D Scott Phillips wrote:
>> On Ampere Altra, PCIe hotplug is handled through ACPI. A side interface is
>> also present to request system firmware control of attention LEDs. Add an
>> ACPI PCI Hotplug companion driver to support attention LED control.
>> ...
>
>> + arm_smccc_smc(REQUEST, LED_CMD, led_status(status), LED_ATTENTION,
>> + pci_domain_nr(bus) | (PCI_SLOT(root_port->devfn) << 4), 0, 0,
>
> pci_domain_nr() returns "int" (normally 32 bits), but since this is an
> ACPI system, the domain comes from _SEG, which is defined to be 16
> bits (ACPI r6.5, sec 6.5.6).
>
> So it looks like ORing in the "slot << 4" clobbers the upper 12 bits
> of _SEG.
>
> Is this code doing the right thing?

Hi Bjorn,

on these Altra platforms _SEG is limited within 0-11. I can add an `&
0xf` to pci_domain_nr() to make it clear that the segment number is
encoded down into 4 bits in the smc request.

2023-10-25 18:08:08

by Bjorn Helgaas

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] PCI: hotplug: Add extension driver for Ampere Altra hotplug LED control

On Wed, Oct 25, 2023 at 10:41:46AM -0700, D Scott Phillips wrote:
> Bjorn Helgaas <[email protected]> writes:
>
> > On Fri, Sep 29, 2023 at 05:20:36PM -0700, D Scott Phillips wrote:
> >> On Ampere Altra, PCIe hotplug is handled through ACPI. A side interface is
> >> also present to request system firmware control of attention LEDs. Add an
> >> ACPI PCI Hotplug companion driver to support attention LED control.
> >> ...
> >
> >> + arm_smccc_smc(REQUEST, LED_CMD, led_status(status), LED_ATTENTION,
> >> + pci_domain_nr(bus) | (PCI_SLOT(root_port->devfn) << 4), 0, 0,
> >
> > pci_domain_nr() returns "int" (normally 32 bits), but since this is an
> > ACPI system, the domain comes from _SEG, which is defined to be 16
> > bits (ACPI r6.5, sec 6.5.6).
> >
> > So it looks like ORing in the "slot << 4" clobbers the upper 12 bits
> > of _SEG.
> >
> > Is this code doing the right thing?
>
> Hi Bjorn,
>
> on these Altra platforms _SEG is limited within 0-11. I can add an `&
> 0xf` to pci_domain_nr() to make it clear that the segment number is
> encoded down into 4 bits in the smc request.

If the following looks OK, we're all set. I put these on pci/hotplug
for v6.7, thanks!

+static int set_attention_status(struct hotplug_slot *slot, u8 status)
+{
+ struct arm_smccc_res res;
+ struct pci_bus *bus;
+ struct pci_dev *root_port;
+ unsigned long flags;
+ u32 handle;
+ int ret = 0;
+
+ bus = slot->pci_slot->bus;
+ root_port = pcie_find_root_port(bus->self);
+ if (!root_port)
+ return -ENODEV;
+
+ local_irq_save(flags);
+ arm_smccc_smc(HANDLE_OPEN, led_service_id[0], led_service_id[1],
+ led_service_id[2], led_service_id[3], 0, 0, 0, &res);
+ if (res.a0) {
+ ret = -ENODEV;
+ goto out;
+ }
+ handle = res.a1 & 0xffff0000;
+
+ arm_smccc_smc(REQUEST, LED_CMD, led_status(status), LED_ATTENTION,
+ PCI_SLOT(root_port->devfn) << 4 | pci_domain_nr(bus) & 0xf,
+ 0, 0, handle, &res);
+ if (res.a0)
+ ret = -ENODEV;
+
+ arm_smccc_smc(HANDLE_CLOSE, handle, 0, 0, 0, 0, 0, 0, &res);
+
+ out:
+ local_irq_restore(flags);
+ return ret;
+}

2023-10-26 10:47:50

by Anders Roxell

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] PCI: hotplug: Add extension driver for Ampere Altra hotplug LED control

On 2023-10-25 13:06, Bjorn Helgaas wrote:
> On Wed, Oct 25, 2023 at 10:41:46AM -0700, D Scott Phillips wrote:
> > Bjorn Helgaas <[email protected]> writes:
> >
> > > On Fri, Sep 29, 2023 at 05:20:36PM -0700, D Scott Phillips wrote:
> > >> On Ampere Altra, PCIe hotplug is handled through ACPI. A side interface is
> > >> also present to request system firmware control of attention LEDs. Add an
> > >> ACPI PCI Hotplug companion driver to support attention LED control.
> > >> ...
> > >
> > >> + arm_smccc_smc(REQUEST, LED_CMD, led_status(status), LED_ATTENTION,
> > >> + pci_domain_nr(bus) | (PCI_SLOT(root_port->devfn) << 4), 0, 0,
> > >
> > > pci_domain_nr() returns "int" (normally 32 bits), but since this is an
> > > ACPI system, the domain comes from _SEG, which is defined to be 16
> > > bits (ACPI r6.5, sec 6.5.6).
> > >
> > > So it looks like ORing in the "slot << 4" clobbers the upper 12 bits
> > > of _SEG.
> > >
> > > Is this code doing the right thing?
> >
> > Hi Bjorn,
> >
> > on these Altra platforms _SEG is limited within 0-11. I can add an `&
> > 0xf` to pci_domain_nr() to make it clear that the segment number is
> > encoded down into 4 bits in the smc request.
>
> If the following looks OK, we're all set. I put these on pci/hotplug
> for v6.7, thanks!
>
> +static int set_attention_status(struct hotplug_slot *slot, u8 status)
> +{
> + struct arm_smccc_res res;
> + struct pci_bus *bus;
> + struct pci_dev *root_port;
> + unsigned long flags;
> + u32 handle;
> + int ret = 0;
> +
> + bus = slot->pci_slot->bus;
> + root_port = pcie_find_root_port(bus->self);
> + if (!root_port)
> + return -ENODEV;
> +
> + local_irq_save(flags);
> + arm_smccc_smc(HANDLE_OPEN, led_service_id[0], led_service_id[1],
> + led_service_id[2], led_service_id[3], 0, 0, 0, &res);
> + if (res.a0) {
> + ret = -ENODEV;
> + goto out;
> + }
> + handle = res.a1 & 0xffff0000;
> +
> + arm_smccc_smc(REQUEST, LED_CMD, led_status(status), LED_ATTENTION,
> + PCI_SLOT(root_port->devfn) << 4 | pci_domain_nr(bus) & 0xf,
> + 0, 0, handle, &res);
> + if (res.a0)
> + ret = -ENODEV;
> +
> + arm_smccc_smc(HANDLE_CLOSE, handle, 0, 0, 0, 0, 0, 0, &res);
> +
> + out:
> + local_irq_restore(flags);
> + return ret;
> +}

Hi,

Building todays linux-next tag next-20231026 for arm64 with
CONFIG_HOTPLUG_PCI_ACPI_AMPERE_ALTRA=m I see the following build error.

drivers/pci/hotplug/acpiphp_ampere_altra.c: In function 'set_attention_status':
drivers/pci/hotplug/acpiphp_ampere_altra.c:63:75: error: suggest parentheses around arithmetic in operand of '|' [-Werror=parentheses]
63 | PCI_SLOT(root_port->devfn) << 4 | pci_domain_nr(bus) & 0xf,
| ~~~~~~~~~~~~~~~~~~~^~~~~
include/linux/arm-smccc.h:382:44: note: in definition of macro 'arm_smccc_smc'
382 | #define arm_smccc_smc(...) __arm_smccc_smc(__VA_ARGS__, NULL)
| ^~~~~~~~~~~
cc1: all warnings being treated as errors
make[6]: *** [scripts/Makefile.build:243: drivers/pci/hotplug/acpiphp_ampere_altra.o] Error 1

Looks like this is the problematic patch
13ba8a09c4f6 ("PCI: hotplug: Add Ampere Altra Attention Indicator extension driver")

Cheers,
Anders

2023-10-26 11:04:40

by Bjorn Helgaas

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] PCI: hotplug: Add extension driver for Ampere Altra hotplug LED control

On Thu, Oct 26, 2023 at 12:47:31PM +0200, Anders Roxell wrote:
> On 2023-10-25 13:06, Bjorn Helgaas wrote:
> > On Wed, Oct 25, 2023 at 10:41:46AM -0700, D Scott Phillips wrote:
> > > Bjorn Helgaas <[email protected]> writes:
> > >
> > > > On Fri, Sep 29, 2023 at 05:20:36PM -0700, D Scott Phillips wrote:
> > > >> On Ampere Altra, PCIe hotplug is handled through ACPI. A side interface is
> > > >> also present to request system firmware control of attention LEDs. Add an
> > > >> ACPI PCI Hotplug companion driver to support attention LED control.
> > > >> ...
> > > >
> > > >> + arm_smccc_smc(REQUEST, LED_CMD, led_status(status), LED_ATTENTION,
> > > >> + pci_domain_nr(bus) | (PCI_SLOT(root_port->devfn) << 4), 0, 0,
> > > >
> > > > pci_domain_nr() returns "int" (normally 32 bits), but since this is an
> > > > ACPI system, the domain comes from _SEG, which is defined to be 16
> > > > bits (ACPI r6.5, sec 6.5.6).
> > > >
> > > > So it looks like ORing in the "slot << 4" clobbers the upper 12 bits
> > > > of _SEG.
> > > >
> > > > Is this code doing the right thing?
> > >
> > > Hi Bjorn,
> > >
> > > on these Altra platforms _SEG is limited within 0-11. I can add an `&
> > > 0xf` to pci_domain_nr() to make it clear that the segment number is
> > > encoded down into 4 bits in the smc request.
> >
> > If the following looks OK, we're all set. I put these on pci/hotplug
> > for v6.7, thanks!
> >
> > +static int set_attention_status(struct hotplug_slot *slot, u8 status)
> > +{
> > + struct arm_smccc_res res;
> > + struct pci_bus *bus;
> > + struct pci_dev *root_port;
> > + unsigned long flags;
> > + u32 handle;
> > + int ret = 0;
> > +
> > + bus = slot->pci_slot->bus;
> > + root_port = pcie_find_root_port(bus->self);
> > + if (!root_port)
> > + return -ENODEV;
> > +
> > + local_irq_save(flags);
> > + arm_smccc_smc(HANDLE_OPEN, led_service_id[0], led_service_id[1],
> > + led_service_id[2], led_service_id[3], 0, 0, 0, &res);
> > + if (res.a0) {
> > + ret = -ENODEV;
> > + goto out;
> > + }
> > + handle = res.a1 & 0xffff0000;
> > +
> > + arm_smccc_smc(REQUEST, LED_CMD, led_status(status), LED_ATTENTION,
> > + PCI_SLOT(root_port->devfn) << 4 | pci_domain_nr(bus) & 0xf,
> > + 0, 0, handle, &res);
> > + if (res.a0)
> > + ret = -ENODEV;
> > +
> > + arm_smccc_smc(HANDLE_CLOSE, handle, 0, 0, 0, 0, 0, 0, &res);
> > +
> > + out:
> > + local_irq_restore(flags);
> > + return ret;
> > +}
>
> Hi,
>
> Building todays linux-next tag next-20231026 for arm64 with
> CONFIG_HOTPLUG_PCI_ACPI_AMPERE_ALTRA=m I see the following build error.
>
> drivers/pci/hotplug/acpiphp_ampere_altra.c: In function 'set_attention_status':
> drivers/pci/hotplug/acpiphp_ampere_altra.c:63:75: error: suggest parentheses around arithmetic in operand of '|' [-Werror=parentheses]
> 63 | PCI_SLOT(root_port->devfn) << 4 | pci_domain_nr(bus) & 0xf,
> | ~~~~~~~~~~~~~~~~~~~^~~~~
> include/linux/arm-smccc.h:382:44: note: in definition of macro 'arm_smccc_smc'
> 382 | #define arm_smccc_smc(...) __arm_smccc_smc(__VA_ARGS__, NULL)
> | ^~~~~~~~~~~
> cc1: all warnings being treated as errors
> make[6]: *** [scripts/Makefile.build:243: drivers/pci/hotplug/acpiphp_ampere_altra.o] Error 1

My fault, fixed.

Bjorn