Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2144772rdb; Tue, 3 Oct 2023 11:33:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQjgUZomG+93sKR3BQDvCSauu44eQrkTwegnP26Ilxt2JvG7QJiR242T4LbyrjNEbTmX8s X-Received: by 2002:a17:903:1252:b0:1c2:36a:52a5 with SMTP id u18-20020a170903125200b001c2036a52a5mr421348plh.57.1696357993645; Tue, 03 Oct 2023 11:33:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696357993; cv=none; d=google.com; s=arc-20160816; b=vc2xBsqlmsRsnw2/qrLsWzV8UvnXTvap1P51AM1TX3O+/F2HTOwyFzaVrbiSUb6kfV 9fpDaPgwrtaZ53UW8FfDFd50r5k8GQFUAF3jrDDSEZXqgP7GNxOLeCnJBn1tu/DsFBqH uI91IsEDKwwvKx1fSTvg/of2/ePYYPxG8NO8umQVJTJ2L6j4OkQnmv5zFkRprwNG/KCb GVa3iwdAAferj+j0UIXH6D6lHTwVLF++x7J8ziK5x0G2WmpiHlHEcSS8xiAMZ/6w4Rf0 3thPUdf8QXqoyqdDwwxiYyCSqzHZeDFrw06SjQ72CyC4lSE5TO8FHUz5LugB98rRssGE ioiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=C8CY6yTjM43P7Gw4BR6IZchc9FnDj1ZwTQ90GprwrFo=; fh=epRyLatAta3YDr4EKiHNvIXKebZVs8w3m6uC7E+bPns=; b=aCQEI5qFjxtI6g0FGlkmTTRaoXgfcbQKZuchmtkcXyJ/rZTXkx/EcmClUjFhHDw/q+ hul3fmfLUG2V3tw6S05FVMlN352FD40UwhACFxOJVimCRw04Y3s00RyAL96ojgInww3I JwIa8MDfyeAaHBGcbE8cmY3YmQBBMG1sWYuWM5fXxv4ZEZHG3fkP4muOcZt/LAeOOt5X GGr2I5/Jfgcy0etB/eLvMuzv2ydFXLEMglNlOFS6OLTDFKllM6bE47pFKkBFQ8E4rHo5 7i47kSt4d7qSxIoJZhlnKZSSAkftgBXvZ4wYNRiUc90G5IB09Bu+GU0wJdE3WCQlrRA/ 1y9Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id lm11-20020a170903298b00b001c72699dcd3si1958819plb.367.2023.10.03.11.33.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 11:33:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id EB6D981A6E57; Tue, 3 Oct 2023 11:33:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240782AbjJCSdL convert rfc822-to-8bit (ORCPT + 99 others); Tue, 3 Oct 2023 14:33:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231670AbjJCSdK (ORCPT ); Tue, 3 Oct 2023 14:33:10 -0400 Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A877683; Tue, 3 Oct 2023 11:33:07 -0700 (PDT) Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-57c0775d4fcso236489eaf.0; Tue, 03 Oct 2023 11:33:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696357987; x=1696962787; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eEV1DyG9Qc64Bv5Nj/cVJ3Nlaofe0o2A5B76dhvJOR0=; b=fyvx1VIyKJPzMNqtEWFxn+sceSxEeoNKH09rLT7l4oOeM9kc27ZGnPLJfylUgLCx24 RVvzlp9+j2V+lk5b3bXkHLRoJg2/Wl+jj/NqGO1Dh8APilEtIUxCkbRkzEW/XLnFfs5x 9peIPWQdRdGx71mkSUxTGxJvhYJkZ1c77L4zD1IHTdnxQWxz7+JQCdeziKI6kkMu8bcp QHrhCKgY7ijGq0bvjtGXpQSKGrz+pFnVGoGNvR0tXfbm7p8QgAzhu516drrAmqd4BURV P4Lxc5mWpFMj2L1UX3I+Wj44oH/ZW/rqSF3l6m0Odpdhr9VUvB/AZbaDfgF0y9UlB9jD 11Ew== X-Gm-Message-State: AOJu0Yzg+nnmjGplGr70SNVblUwFykZWQ+uUNzQmT2K7dxCKPX7XifSN S9nWK7wHuDFx1nrpygEhixgunBlimPEU8yRmZBxLgtep X-Received: by 2002:a4a:de08:0:b0:56e:94ed:c098 with SMTP id y8-20020a4ade08000000b0056e94edc098mr219991oot.0.1696357986930; Tue, 03 Oct 2023 11:33:06 -0700 (PDT) MIME-Version: 1.0 References: <20230930002036.6491-1-scott@os.amperecomputing.com> <20230930002036.6491-2-scott@os.amperecomputing.com> In-Reply-To: <20230930002036.6491-2-scott@os.amperecomputing.com> From: "Rafael J. Wysocki" Date: Tue, 3 Oct 2023 20:32:55 +0200 Message-ID: Subject: Re: [PATCH v2 2/2] PCI: hotplug: Add extension driver for Ampere Altra hotplug LED control To: D Scott Phillips Cc: linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org, "Rafael J. Wysocki" , Bjorn Helgaas , linux-kernel@vger.kernel.org, Len Brown , Darren Hart , patches@amperecomputing.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=no 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 03 Oct 2023 11:33:12 -0700 (PDT) On Sat, Sep 30, 2023 at 2:20 AM 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. > > Signed-off-by: D Scott Phillips Acked-by: Rafael J. Wysocki 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 > +#include > +#include > +#include > +#include > + > +#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(&ere_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(&ere_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 "); > +MODULE_LICENSE("GPL"); > -- > 2.41.0 >