From: Hanjun Guo <hanjun.guo@linaro.org>
To: Marc Zyngier <marc.zyngier@arm.com>,
Jason Cooper <jason@lakedaemon.net>,
Will Deacon <Will.Deacon@arm.com>,
Catalin Marinas <Catalin.Marinas@arm.com>,
"Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Jiang Liu <jiang.liu@linux.intel.com>,
Bjorn Helgaas <bhelgaas@google.com>,
Lorenzo Pieralisi <Lorenzo.Pieralisi@arm.com>,
"suravee.suthikulpanit@amd.com" <suravee.suthikulpanit@amd.com>,
Timur Tabi <timur@codeaurora.org>,
Tomasz Nowicki <tomasz.nowicki@linaro.org>,
"grant.likely@linaro.org" <grant.likely@linaro.org>,
Mark Brown <broonie@kernel.org>, Wei Huang <wei@redhat.com>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"linux-acpi@vger.kernel.org" <linux-acpi@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linaro-acpi@lists.linaro.org" <linaro-acpi@lists.linaro.org>
Subject: Re: [PATCH v4 01/10] irqchip / GIC: Add GIC version support in ACPI MADT
Date: Wed, 05 Aug 2015 21:11:31 +0800 [thread overview]
Message-ID: <55C20B83.10808@linaro.org> (raw)
In-Reply-To: <55C2082A.7000508@arm.com>
On 08/05/2015 08:57 PM, Marc Zyngier wrote:
> On 05/08/15 13:40, Hanjun Guo wrote:
>> On 08/04/2015 08:06 PM, Marc Zyngier wrote:
>>> On 29/07/15 11:08, Hanjun Guo wrote:
>>>> There is a field added in ACPI 6.0 MADT table to indicate the
>>>> GIC version, so parse the table to get its value for later use.
>>>>
>>>> If GIC version presented in MADT is 0, we need to fallback to
>>>> hardware discovery to get the GIC version.
>>>>
>>>> In ACPI MADT table there is no compatible strings to indicate
>>>> various irqchips and also ACPI doesn't support irqchips which
>>>> are not compatible with ARM GIC spec, so GIC version can be used
>>>> to load different GIC drivers which is needed for the later patch.
>>>>
>>>> Signed-off-by: Hanjun Guo <hanjun.guo@linaro.org>
>>>> ---
>>>> arch/arm64/Kconfig | 1 +
>>>> drivers/irqchip/Kconfig | 3 +
>>>> drivers/irqchip/Makefile | 1 +
>>>> drivers/irqchip/irq-gic-acpi.c | 109 +++++++++++++++++++++++++++++++++++
>>>> include/linux/irqchip/arm-gic-acpi.h | 1 +
>>>> 5 files changed, 115 insertions(+)
>>>> create mode 100644 drivers/irqchip/irq-gic-acpi.c
>>>>
>>>> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
>>>> index 318175f..f2ff61f 100644
>>>> --- a/arch/arm64/Kconfig
>>>> +++ b/arch/arm64/Kconfig
>>>> @@ -16,6 +16,7 @@ config ARM64
>>>> select ARM_AMBA
>>>> select ARM_ARCH_TIMER
>>>> select ARM_GIC
>>>> + select ARM_GIC_ACPI if ACPI
>>>> select AUDIT_ARCH_COMPAT_GENERIC
>>>> select ARM_GIC_V2M if PCI_MSI
>>>> select ARM_GIC_V3
>>>> diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig
>>>> index 120d815..557ec2f 100644
>>>> --- a/drivers/irqchip/Kconfig
>>>> +++ b/drivers/irqchip/Kconfig
>>>> @@ -47,6 +47,9 @@ config ARM_VIC_NR
>>>> The maximum number of VICs available in the system, for
>>>> power management.
>>>>
>>>> +config ARM_GIC_ACPI
>>>> + bool
>>>> +
>>>> config ATMEL_AIC_IRQ
>>>> bool
>>>> select GENERIC_IRQ_CHIP
>>>> diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
>>>> index 11d08c9..383f421 100644
>>>> --- a/drivers/irqchip/Makefile
>>>> +++ b/drivers/irqchip/Makefile
>>>> @@ -23,6 +23,7 @@ obj-$(CONFIG_ARM_GIC) += irq-gic.o irq-gic-common.o
>>>> obj-$(CONFIG_ARM_GIC_V2M) += irq-gic-v2m.o
>>>> obj-$(CONFIG_ARM_GIC_V3) += irq-gic-v3.o irq-gic-common.o
>>>> obj-$(CONFIG_ARM_GIC_V3_ITS) += irq-gic-v3-its.o irq-gic-v3-its-pci-msi.o irq-gic-v3-its-platform-msi.o
>>>> +obj-$(CONFIG_ARM_GIC_ACPI) += irq-gic-acpi.o
>>>> obj-$(CONFIG_ARM_NVIC) += irq-nvic.o
>>>> obj-$(CONFIG_ARM_VIC) += irq-vic.o
>>>> obj-$(CONFIG_ATMEL_AIC_IRQ) += irq-atmel-aic-common.o irq-atmel-aic.o
>>>> diff --git a/drivers/irqchip/irq-gic-acpi.c b/drivers/irqchip/irq-gic-acpi.c
>>>> new file mode 100644
>>>> index 0000000..6537b43
>>>> --- /dev/null
>>>> +++ b/drivers/irqchip/irq-gic-acpi.c
>>>> @@ -0,0 +1,109 @@
>>>> +/*
>>>> + * ACPI based support for ARM GIC init
>>>> + *
>>>> + * Copyright (C) 2015, Linaro Ltd.
>>>> + * Author: Hanjun Guo <hanjun.guo@linaro.org>
>>>> + *
>>>> + * This program is free software; you can redistribute it and/or modify
>>>> + * it under the terms of the GNU General Public License version 2 as
>>>> + * published by the Free Software Foundation.
>>>> + */
>>>> +
>>>> +#define pr_fmt(fmt) "ACPI: GIC: " fmt
>>>> +
>>>> +#include <linux/acpi.h>
>>>> +#include <linux/init.h>
>>>> +#include <linux/irqchip/arm-gic-acpi.h>
>>>> +#include <linux/irqchip/arm-gic-v3.h>
>>>> +
>>>> +/* GIC version presented in MADT GIC distributor structure */
>>>> +static u8 gic_version __initdata = ACPI_MADT_GIC_VERSION_NONE;
>>>> +
>>>> +static phys_addr_t dist_phy_base __initdata;
>>>> +
>>>> +static int __init
>>>> +acpi_gic_parse_distributor(struct acpi_subtable_header *header,
>>>> + const unsigned long end)
>>>> +{
>>>> + struct acpi_madt_generic_distributor *dist;
>>>> +
>>>> + dist = (struct acpi_madt_generic_distributor *)header;
>>>> +
>>>> + if (BAD_MADT_ENTRY(dist, end))
>>>> + return -EINVAL;
>>>> +
>>>> + gic_version = dist->version;
>>>> + dist_phy_base = dist->base_address;
>>>> + return 0;
>>>> +}
>>>> +
>>>> +static int __init
>>>> +match_gic_redist(struct acpi_subtable_header *header, const unsigned long end)
>>>> +{
>>>> + return 0;
>>>> +}
>>>> +
>>>> +static bool __init acpi_gic_redist_is_present(void)
>>>> +{
>>>> + int count;
>>>> +
>>>> + /* scan MADT table to find if we have redistributor entries */
>>>> + count = acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR,
>>>> + match_gic_redist, 0);
>>>> +
>>>> + /* that's true if we have at least one GIC redistributor entry */
>>>> + return count > 0;
>>>> +}
>>>> +
>>>> +static int __init acpi_gic_version_init(void)
>>>> +{
>>>> + int count;
>>>> + u32 reg;
>>>> + void __iomem *dist_base;
>>>> +
>>>> + count = acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_DISTRIBUTOR,
>>>> + acpi_gic_parse_distributor, 0);
>>>> +
>>>> + if (count <= 0) {
>>>> + pr_err("No valid GIC distributor entry exists\n");
>>>> + return -ENODEV;
>>>> + }
>>>> +
>>>> + if (gic_version >= ACPI_MADT_GIC_VERSION_RESERVED) {
>>>> + pr_err("Invalid GIC version %d in MADT\n", gic_version);
>>>> + return -EINVAL;
>>>> + }
>>>> +
>>>> + /*
>>>> + * when the GIC version is 0, we fallback to hardware discovery.
>>>> + * this is also needed to keep compatiable with ACPI 5.1,
>>>> + * which has no gic_version field in distributor structure and
>>>> + * reserved as 0.
>>>> + *
>>>> + * For hardware discovery, the offset for GICv1/2 and GICv3/4 to
>>>> + * get the GIC version is different (0xFE8 for GICv1/2 and 0xFFE8
>>>> + * for GICv3/4), so we need to handle it separately.
>>>> + */
>>>> + if (gic_version == ACPI_MADT_GIC_VERSION_NONE) {
>>>> + /* it's GICv3/v4 if redistributor is present */
>>>> + if (acpi_gic_redist_is_present()) {
>>>> + dist_base = ioremap(dist_phy_base,
>>>> + ACPI_GICV3_DIST_MEM_SIZE);
>>>> + if (!dist_base)
>>>> + return -ENOMEM;
>>>> +
>>>> + reg = readl_relaxed(dist_base + GICD_PIDR2) &
>>>> + GIC_PIDR2_ARCH_MASK;
>>>> + if (reg == GIC_PIDR2_ARCH_GICv3)
>>>> + gic_version = ACPI_MADT_GIC_VERSION_V3;
>>>> + else
>>>> + gic_version = ACPI_MADT_GIC_VERSION_V4;
>>>
>>> Frankly, why should we care? If there is no redistributor, this is a V2.
>>> If there are redistributors, then it is a V3/V4, and it shouldn't matter
>>> which one this is as the GICv3 driver can find out all by itself. Also,
>>> the GICv4 feature only matter for KVM, which can probe this on its own.
>>
>> For hardware discovery, it works.
>>
>> I use the gic_version in later patch to ioremap physical base address of
>> GICR (which 2 or 4 64k pages), but I can get it from register in later
>> patch then remove the code above.
>>
>> For gic version in GICD subtable, we must consider V4 as firmware may
>> just present ACPI_MADT_GIC_VERSION_V4 as the GIC version, that's why
>> we need to match V4 in the GICv3 driver.
>
> My point is: the GICv3 driver doesn't give a damn. At all. And it
> shouldn't! The *only* difference is the size of the redistributor, and
> this can be worked out *inside the GIC driver* by looking at:
>
> - GICR_PIDR2.ArchRev (and not GICD_PIDR2)
> - GICR_TYPER.VLPIS
>
> Whatever the firmware says is absolutely irrelevant, and even if we
> needed to override what the HW reports (because it is broken), we can
> implement it as a quirk inside the driver itself, without any of this
> ioremap dance that doesn't even do the right thing.
>
> So to "we must consider V4", my answer is no. Certainly not at this
> location.
Sorry, I didn't make it clear. what I mean is that when GIC version
is presented as V4, we can match the GICv3 driver with it, and
everything will be the same in the driver itself.
Thanks
Hanjun
next prev parent reply other threads:[~2015-08-05 13:11 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-29 10:08 [PATCH v4 00/10] ACPI GIC Self-probing, GICv2m and GICv3 support Hanjun Guo
2015-07-29 10:08 ` [PATCH v4 01/10] irqchip / GIC: Add GIC version support in ACPI MADT Hanjun Guo
2015-08-04 12:06 ` Marc Zyngier
2015-08-05 12:40 ` Hanjun Guo
2015-08-05 12:57 ` Marc Zyngier
2015-08-05 13:11 ` Hanjun Guo [this message]
2015-07-29 10:08 ` [PATCH v4 02/10] ACPI / irqchip: Add self-probe infrastructure to initialize IRQ controller Hanjun Guo
2015-08-04 12:27 ` Marc Zyngier
2015-08-05 13:24 ` Hanjun Guo
2015-08-06 16:29 ` Marc Zyngier
2015-07-29 10:08 ` [PATCH v4 03/10] irqchip / GIC / ACPI: Use IRQCHIP_ACPI_DECLARE to simplify GICv2 init code Hanjun Guo
2015-07-29 10:08 ` [PATCH v4 04/10] irqchip / GICv3: Refactor gic_of_init() for GICv3 driver Hanjun Guo
2015-07-29 10:08 ` [PATCH v4 05/10] irqchip / GICv3: remove the useless comparision of device node in xlate Hanjun Guo
2015-07-29 10:08 ` [PATCH v4 06/10] irqchip / GICv3: Add ACPI support for GICv3+ initialization Hanjun Guo
2015-08-04 13:17 ` Marc Zyngier
2015-08-05 14:00 ` Hanjun Guo
2015-08-06 16:42 ` Marc Zyngier
2015-08-11 7:19 ` Hanjun Guo
2015-07-29 10:08 ` [PATCH v4 07/10] irqchip / GICv3 / ACPI: Add GICR support via GICC structures Hanjun Guo
2015-08-04 13:37 ` Marc Zyngier
2015-08-05 14:11 ` Hanjun Guo
2015-08-06 16:42 ` Marc Zyngier
2015-07-29 10:08 ` [PATCH v4 08/10] ACPI: GIC: Add ACPI helper functions to query irq-domain tokens for for GIC MSI and ITS Hanjun Guo
2015-08-04 14:02 ` Marc Zyngier
2015-08-09 8:02 ` Suravee Suthikulpanit
2015-07-29 10:08 ` [PATCH v4 09/10] PCI: ACPI: Bind GIC MSI frame to PCI host bridge Hanjun Guo
2015-08-04 14:04 ` Marc Zyngier
2015-08-07 8:42 ` Hanjun Guo
2015-08-09 8:02 ` Suravee Suthikulpanit
2015-08-07 10:03 ` Tomasz Nowicki
2015-08-07 10:48 ` Mark Brown
2015-08-07 12:06 ` Marc Zyngier
2015-07-29 10:08 ` [PATCH v4 10/10] irqchip / gicv2m: Introducing gicv2m_acpi_init() Hanjun Guo
2015-08-04 14:23 ` Marc Zyngier
2015-08-09 8:04 ` Suravee Suthikulpanit
2015-08-11 22:01 ` [PATCH v4 00/10] ACPI GIC Self-probing, GICv2m and GICv3 support Timur Tabi
2015-08-11 22:24 ` [Linaro-acpi] " G Gregory
2015-08-11 22:25 ` Marc Zyngier
2015-08-11 22:36 ` Timur Tabi
2015-08-11 22:48 ` Marc Zyngier
2015-08-11 23:33 ` Timur Tabi
2015-08-12 7:21 ` Marc Zyngier
2015-08-12 19:20 ` Timur Tabi
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=55C20B83.10808@linaro.org \
--to=hanjun.guo@linaro.org \
--cc=Catalin.Marinas@arm.com \
--cc=Lorenzo.Pieralisi@arm.com \
--cc=Will.Deacon@arm.com \
--cc=bhelgaas@google.com \
--cc=broonie@kernel.org \
--cc=grant.likely@linaro.org \
--cc=jason@lakedaemon.net \
--cc=jiang.liu@linux.intel.com \
--cc=linaro-acpi@lists.linaro.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marc.zyngier@arm.com \
--cc=rjw@rjwysocki.net \
--cc=suravee.suthikulpanit@amd.com \
--cc=tglx@linutronix.de \
--cc=timur@codeaurora.org \
--cc=tomasz.nowicki@linaro.org \
--cc=wei@redhat.com \
/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;
as well as URLs for NNTP newsgroup(s).