linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/5] enhance configuring an ITS
@ 2015-03-06  4:13 Yun Wu
  2015-03-06  4:13 ` [PATCH v4 1/5] irqchip: gicv3-its: zero itt before handling to hardware Yun Wu
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Yun Wu @ 2015-03-06  4:13 UTC (permalink / raw)
  To: marc.zyngier, tglx, jason; +Cc: linux-kernel, linux-arm-kernel, Yun Wu

This patch series makes some enhancement to ITS configuration in the
following aspects:

o make allocation of the ITS tables more sensible
o replace magic numbers with sensible macros
o guarantees a safe quiescent status before initializing an ITS

This patch series is based on Marc's branch[1], and tested on Hisilion
ARM64 board with GICv3 ITS hardware.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git irq/gic-fixes

v3 -> v4:
o Spell out device table instead of DT to avoid misunderstanding
o Change its_check_quiesced() to a more sensible name its_force_quiescent()

v2 -> v3:
o drop the patch of tracing LPI enabling status since Vladimir Murzin
  had already posted a similar patch
o fix several improper description issues

v1 -> v2:
o rebase to Marc's GIC fix branch
o drop size calculation for Device Table since Marc had already posted one
o guarantees a safe quiescent status before initializing an ITS as
  Marc suggested, rather than register a reboot notifier
o fix an issue about the enabling status of LPI feature

Yun Wu (5):
  irqchip: gicv3-its: zero itt before handling to hardware
  irqchip: gicv3-its: use 64KB page as default granule
  irqchip: gicv3-its: add limitation to page order
  irqchip: gicv3-its: define macros for GITS_CTLR fields
  irqchip: gicv3-its: support safe initialization

 drivers/irqchip/irq-gic-v3-its.c   | 46 +++++++++++++++++++++++++++++++++++---
 include/linux/irqchip/arm-gic-v3.h |  3 +++
 2 files changed, 46 insertions(+), 3 deletions(-)

--
1.8.0



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v4 1/5] irqchip: gicv3-its: zero itt before handling to hardware
  2015-03-06  4:13 [PATCH v4 0/5] enhance configuring an ITS Yun Wu
@ 2015-03-06  4:13 ` Yun Wu
  2015-03-06  4:13 ` [PATCH v4 2/5] irqchip: gicv3-its: use 64KB page as default granule Yun Wu
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Yun Wu @ 2015-03-06  4:13 UTC (permalink / raw)
  To: marc.zyngier, tglx, jason; +Cc: linux-kernel, linux-arm-kernel, Yun Wu

Some kind of brain-dead implementations chooses to insert ITEes in
rapid sequence of disabled ITEes, and an un-zeroed ITT will confuse
ITS on judging whether an ITE is really enabled or not. Considering
the implementations are still supported by the GICv3 architecture,
in which ITT is not required to be zeroed before being handled to
hardware, we do the favor in ITS driver.

Acked-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Yun Wu <wuyun.wu@huawei.com>
---
 drivers/irqchip/irq-gic-v3-its.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index 6850141..69eeea3 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -1076,7 +1076,7 @@ static struct its_device *its_create_device(struct its_node *its, u32 dev_id,
 	nr_ites = max(2UL, roundup_pow_of_two(nvecs));
 	sz = nr_ites * its->ite_size;
 	sz = max(sz, ITS_ITT_ALIGN) + ITS_ITT_ALIGN - 1;
-	itt = kmalloc(sz, GFP_KERNEL);
+	itt = kzalloc(sz, GFP_KERNEL);
 	lpi_map = its_lpi_alloc_chunks(nvecs, &lpi_base, &nr_lpis);

 	if (!dev || !itt || !lpi_map) {
--
1.8.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v4 2/5] irqchip: gicv3-its: use 64KB page as default granule
  2015-03-06  4:13 [PATCH v4 0/5] enhance configuring an ITS Yun Wu
  2015-03-06  4:13 ` [PATCH v4 1/5] irqchip: gicv3-its: zero itt before handling to hardware Yun Wu
@ 2015-03-06  4:13 ` Yun Wu
  2015-03-06 16:04   ` Marc Zyngier
  2015-03-06  4:13 ` [PATCH v4 3/5] irqchip: gicv3-its: add limitation to page order Yun Wu
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 7+ messages in thread
From: Yun Wu @ 2015-03-06  4:13 UTC (permalink / raw)
  To: marc.zyngier, tglx, jason; +Cc: linux-kernel, linux-arm-kernel, Yun Wu

The field of page size in register GITS_BASERn might be read-only
if an implementation only supports a single, fixed page size. But
currently the ITS driver will throw out an error when PAGE_SIZE
is less than the minimum size supported by an ITS. So addressing
this problem by using 64KB pages as default granule for all the
ITS base tables.

Acked-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Yun Wu <wuyun.wu@huawei.com>
---
 drivers/irqchip/irq-gic-v3-its.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index 69eeea3..f5bfa42 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -800,7 +800,7 @@ static int its_alloc_tables(struct its_node *its)
 {
 	int err;
 	int i;
-	int psz = PAGE_SIZE;
+	int psz = SZ_64K;
 	u64 shr = GITS_BASER_InnerShareable;

 	for (i = 0; i < GITS_BASER_NR_REGS; i++) {
--
1.8.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v4 3/5] irqchip: gicv3-its: add limitation to page order
  2015-03-06  4:13 [PATCH v4 0/5] enhance configuring an ITS Yun Wu
  2015-03-06  4:13 ` [PATCH v4 1/5] irqchip: gicv3-its: zero itt before handling to hardware Yun Wu
  2015-03-06  4:13 ` [PATCH v4 2/5] irqchip: gicv3-its: use 64KB page as default granule Yun Wu
@ 2015-03-06  4:13 ` Yun Wu
  2015-03-06  4:13 ` [PATCH v4 4/5] irqchip: gicv3-its: define macros for GITS_CTLR fields Yun Wu
  2015-03-06  4:13 ` [PATCH v4 5/5] irqchip: gicv3-its: support safe initialization Yun Wu
  4 siblings, 0 replies; 7+ messages in thread
From: Yun Wu @ 2015-03-06  4:13 UTC (permalink / raw)
  To: marc.zyngier, tglx, jason; +Cc: linux-kernel, linux-arm-kernel, Yun Wu

When required size of Device Table is out of the page allocator's
capability, the whole ITS will fail in probing. This actually is
not the hardware's problem and is mainly a limitation of the kernel
page allocator. This patch will keep ITS going on to the next
initializaion stage with an explicit warning.

Acked-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Yun Wu <wuyun.wu@huawei.com>
---
 drivers/irqchip/irq-gic-v3-its.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index f5bfa42..e8bda0b 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -828,6 +828,11 @@ static int its_alloc_tables(struct its_node *its)
 			u32 ids = GITS_TYPER_DEVBITS(typer);

 			order = get_order((1UL << ids) * entry_size);
+			if (order >= MAX_ORDER) {
+				order = MAX_ORDER - 1;
+				pr_warn("%s: Device Table too large, reduce its page order to %u\n",
+					its->msi_chip.of_node->full_name, order);
+			}
 		}

 		alloc_size = (1 << order) * PAGE_SIZE;
--
1.8.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v4 4/5] irqchip: gicv3-its: define macros for GITS_CTLR fields
  2015-03-06  4:13 [PATCH v4 0/5] enhance configuring an ITS Yun Wu
                   ` (2 preceding siblings ...)
  2015-03-06  4:13 ` [PATCH v4 3/5] irqchip: gicv3-its: add limitation to page order Yun Wu
@ 2015-03-06  4:13 ` Yun Wu
  2015-03-06  4:13 ` [PATCH v4 5/5] irqchip: gicv3-its: support safe initialization Yun Wu
  4 siblings, 0 replies; 7+ messages in thread
From: Yun Wu @ 2015-03-06  4:13 UTC (permalink / raw)
  To: marc.zyngier, tglx, jason; +Cc: linux-kernel, linux-arm-kernel, Yun Wu

Define macros for GITS_CTLR fields to avoid using magic numbers.

Acked-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Yun Wu <wuyun.wu@huawei.com>
---
 drivers/irqchip/irq-gic-v3-its.c   | 2 +-
 include/linux/irqchip/arm-gic-v3.h | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index e8bda0b..d13c24e 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -1388,7 +1388,7 @@ static int its_probe(struct device_node *node, struct irq_domain *parent)
 	writeq_relaxed(baser, its->base + GITS_CBASER);
 	tmp = readq_relaxed(its->base + GITS_CBASER);
 	writeq_relaxed(0, its->base + GITS_CWRITER);
-	writel_relaxed(1, its->base + GITS_CTLR);
+	writel_relaxed(GITS_CTLR_ENABLE, its->base + GITS_CTLR);

 	if ((tmp ^ baser) & GITS_BASER_SHAREABILITY_MASK) {
 		pr_info("ITS: using cache flushing for cmd queue\n");
diff --git a/include/linux/irqchip/arm-gic-v3.h b/include/linux/irqchip/arm-gic-v3.h
index 3459b43..c9d3002 100644
--- a/include/linux/irqchip/arm-gic-v3.h
+++ b/include/linux/irqchip/arm-gic-v3.h
@@ -134,6 +134,9 @@

 #define GITS_TRANSLATER			0x10040

+#define GITS_CTLR_ENABLE		(1U << 0)
+#define GITS_CTLR_QUIESCENT		(1U << 31)
+
 #define GITS_TYPER_DEVBITS_SHIFT	13
 #define GITS_TYPER_DEVBITS(r)		((((r) >> GITS_TYPER_DEVBITS_SHIFT) & 0x1f) + 1)
 #define GITS_TYPER_PTA			(1UL << 19)
--
1.8.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v4 5/5] irqchip: gicv3-its: support safe initialization
  2015-03-06  4:13 [PATCH v4 0/5] enhance configuring an ITS Yun Wu
                   ` (3 preceding siblings ...)
  2015-03-06  4:13 ` [PATCH v4 4/5] irqchip: gicv3-its: define macros for GITS_CTLR fields Yun Wu
@ 2015-03-06  4:13 ` Yun Wu
  4 siblings, 0 replies; 7+ messages in thread
From: Yun Wu @ 2015-03-06  4:13 UTC (permalink / raw)
  To: marc.zyngier, tglx, jason; +Cc: linux-kernel, linux-arm-kernel, Yun Wu

It's unsafe to change the configurations of an activated ITS directly
since this will lead to unpredictable results. This patch guarantees
the ITSes being initialized are quiescent.

Acked-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Yun Wu <wuyun.wu@huawei.com>
---
 drivers/irqchip/irq-gic-v3-its.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index d13c24e..9e09aa0 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -1320,6 +1320,34 @@ static const struct irq_domain_ops its_domain_ops = {
 	.deactivate		= its_irq_domain_deactivate,
 };

+static int its_force_quiescent(void __iomem *base)
+{
+	u32 count = 1000000;	/* 1s */
+	u32 val;
+
+	val = readl_relaxed(base + GITS_CTLR);
+	if (val & GITS_CTLR_QUIESCENT)
+		return 0;
+
+	/* Disable the generation of all interrupts to this ITS */
+	val &= ~GITS_CTLR_ENABLE;
+	writel_relaxed(val, base + GITS_CTLR);
+
+	/* Poll GITS_CTLR and wait until ITS becomes quiescent */
+	while (1) {
+		val = readl_relaxed(base + GITS_CTLR);
+		if (val & GITS_CTLR_QUIESCENT)
+			return 0;
+
+		count--;
+		if (!count)
+			return -EBUSY;
+
+		cpu_relax();
+		udelay(1);
+	}
+}
+
 static int its_probe(struct device_node *node, struct irq_domain *parent)
 {
 	struct resource res;
@@ -1348,6 +1376,13 @@ static int its_probe(struct device_node *node, struct irq_domain *parent)
 		goto out_unmap;
 	}

+	err = its_force_quiescent(its_base);
+	if (err) {
+		pr_warn("%s: failed to quiesce, giving up\n",
+			node->full_name);
+		goto out_unmap;
+	}
+
 	pr_info("ITS: %s\n", node->full_name);

 	its = kzalloc(sizeof(*its), GFP_KERNEL);
--
1.8.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v4 2/5] irqchip: gicv3-its: use 64KB page as default granule
  2015-03-06  4:13 ` [PATCH v4 2/5] irqchip: gicv3-its: use 64KB page as default granule Yun Wu
@ 2015-03-06 16:04   ` Marc Zyngier
  0 siblings, 0 replies; 7+ messages in thread
From: Marc Zyngier @ 2015-03-06 16:04 UTC (permalink / raw)
  To: Yun Wu, tglx, jason; +Cc: linux-kernel, linux-arm-kernel

On 06/03/15 04:13, Yun Wu wrote:
> The field of page size in register GITS_BASERn might be read-only
> if an implementation only supports a single, fixed page size. But
> currently the ITS driver will throw out an error when PAGE_SIZE
> is less than the minimum size supported by an ITS. So addressing
> this problem by using 64KB pages as default granule for all the
> ITS base tables.
> 
> Acked-by: Marc Zyngier <marc.zyngier@arm.com>
> Signed-off-by: Yun Wu <wuyun.wu@huawei.com>
> ---
>  drivers/irqchip/irq-gic-v3-its.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
> index 69eeea3..f5bfa42 100644
> --- a/drivers/irqchip/irq-gic-v3-its.c
> +++ b/drivers/irqchip/irq-gic-v3-its.c
> @@ -800,7 +800,7 @@ static int its_alloc_tables(struct its_node *its)
>  {
>  	int err;
>  	int i;
> -	int psz = PAGE_SIZE;
> +	int psz = SZ_64K;
>  	u64 shr = GITS_BASER_InnerShareable;
> 
>  	for (i = 0; i < GITS_BASER_NR_REGS; i++) {

Just went through a test run with this, and this breaks any non Device
Table allocation when PAGE_SIZE != 64K.

The following hunk fixes it:

@@ -806,7 +806,7 @@ static int its_alloc_tables(struct its_node *its)
 		u64 val = readq_relaxed(its->base + GITS_BASER + i * 8);
 		u64 type = GITS_BASER_TYPE(val);
 		u64 entry_size = GITS_BASER_ENTRY_SIZE(val);
-		int order = 0;
+		int order = get_order(psz);
 		int alloc_size;
 		u64 tmp;
 		void *base;

I'll fold it in to the original patch, but I'd be grateful if you could
do a slightly more thorough testing before sending patches.

Thanks,

	M.
-- 
Jazz is not dead. It just smells funny...

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-03-06 16:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-06  4:13 [PATCH v4 0/5] enhance configuring an ITS Yun Wu
2015-03-06  4:13 ` [PATCH v4 1/5] irqchip: gicv3-its: zero itt before handling to hardware Yun Wu
2015-03-06  4:13 ` [PATCH v4 2/5] irqchip: gicv3-its: use 64KB page as default granule Yun Wu
2015-03-06 16:04   ` Marc Zyngier
2015-03-06  4:13 ` [PATCH v4 3/5] irqchip: gicv3-its: add limitation to page order Yun Wu
2015-03-06  4:13 ` [PATCH v4 4/5] irqchip: gicv3-its: define macros for GITS_CTLR fields Yun Wu
2015-03-06  4:13 ` [PATCH v4 5/5] irqchip: gicv3-its: support safe initialization Yun Wu

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).