Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1561795

[PATCH v20 06/17] clocksource/drivers/arm_arch_timer: rework PPI determination

From fu.wei@linaro.org
Newsgroups linux.kernel
Subject [PATCH v20 06/17] clocksource/drivers/arm_arch_timer: rework PPI determination
Date 2017-01-18 14:30 +0100
Message-ID <t0Ytn-4D1-79@gated-at.bofh.it> (permalink)
References <t0Ytk-4D1-15@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Fu Wei <fu.wei@linaro.org>

Currently, the arch timer driver uses ARCH_TIMER_PHYS_SECURE_PPI to
mean the driver will use the secure PPI *and* potentialy also use the
non-secure PPI. This is somewhat confusing.

For arm64, where it never makes sense to use the secure PPI, this
means we must always request the useless secure PPI, adding to the
confusion. For ACPI, where we may not even have a valid secure PPI
number, this is additionally problematic. We need the driver to be
able to use *only* the non-secure PPI.

The logic to choose which PPI to use is intertwined with other logic
in arch_timer_init(). This patch factors the PPI determination out
into a new function named arch_timer_select_ppi, and then reworks it
so that we can handle having only a non-secure PPI.

This patch also moves arch_timer_ppi verification out to caller,
because we can verify the configuration from device-tree for ARM by this
way.

Meanwhile, because we will select ARCH_TIMER_PHYS_NONSECURE_PPI for ARM64,
the logic in arch_timer_register also need to be updated.

Signed-off-by: Fu Wei <fu.wei@linaro.org>
Tested-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
---
 drivers/clocksource/arm_arch_timer.c | 77 +++++++++++++++++++++---------------
 1 file changed, 46 insertions(+), 31 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index ca73513..674d89f 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -702,7 +702,7 @@ static int __init arch_timer_register(void)
 	case ARCH_TIMER_PHYS_NONSECURE_PPI:
 		err = request_percpu_irq(ppi, arch_timer_handler_phys,
 					 "arch_timer", arch_timer_evt);
-		if (!err && arch_timer_ppi[ARCH_TIMER_PHYS_NONSECURE_PPI]) {
+		if (!err && arch_timer_has_nonsecure_ppi()) {
 			ppi = arch_timer_ppi[ARCH_TIMER_PHYS_NONSECURE_PPI];
 			err = request_percpu_irq(ppi, arch_timer_handler_phys,
 						 "arch_timer", arch_timer_evt);
@@ -824,39 +824,41 @@ static int __init arch_timer_common_init(void)
 	return arch_timer_arch_init();
 }
 
-static int __init arch_timer_init(void)
+/**
+ * arch_timer_select_ppi() - Select suitable PPI for the current system.
+ *
+ * If HYP mode is available, we know that the physical timer
+ * has been configured to be accessible from PL1. Use it, so
+ * that a guest can use the virtual timer instead.
+ *
+ * On ARMv8.1 with VH extensions, the kernel runs in HYP. VHE
+ * accesses to CNTP_*_EL1 registers are silently redirected to
+ * their CNTHP_*_EL2 counterparts, and use a different PPI
+ * number.
+ *
+ * If no interrupt provided for virtual timer, we'll have to
+ * stick to the physical timer. It'd better be accessible...
+ * For arm64 we never use the secure interrupt.
+ *
+ * Return: a suitable PPI type for the current system.
+ */
+static enum arch_timer_ppi_nr __init arch_timer_select_ppi(void)
 {
-	int ret;
-	/*
-	 * If HYP mode is available, we know that the physical timer
-	 * has been configured to be accessible from PL1. Use it, so
-	 * that a guest can use the virtual timer instead.
-	 *
-	 * If no interrupt provided for virtual timer, we'll have to
-	 * stick to the physical timer. It'd better be accessible...
-	 *
-	 * On ARMv8.1 with VH extensions, the kernel runs in HYP. VHE
-	 * accesses to CNTP_*_EL1 registers are silently redirected to
-	 * their CNTHP_*_EL2 counterparts, and use a different PPI
-	 * number.
-	 */
-	if (is_hyp_mode_available() || !arch_timer_ppi[ARCH_TIMER_VIRT_PPI]) {
-		bool has_ppi;
+	if (is_kernel_in_hyp_mode())
+		return ARCH_TIMER_HYP_PPI;
 
-		if (is_kernel_in_hyp_mode()) {
-			arch_timer_uses_ppi = ARCH_TIMER_HYP_PPI;
-			has_ppi = !!arch_timer_ppi[ARCH_TIMER_HYP_PPI];
-		} else {
-			arch_timer_uses_ppi = ARCH_TIMER_PHYS_SECURE_PPI;
-			has_ppi = (!!arch_timer_ppi[ARCH_TIMER_PHYS_SECURE_PPI] ||
-				   !!arch_timer_ppi[ARCH_TIMER_PHYS_NONSECURE_PPI]);
-		}
+	if (!is_hyp_mode_available() && arch_timer_ppi[ARCH_TIMER_VIRT_PPI])
+		return ARCH_TIMER_VIRT_PPI;
 
-		if (!has_ppi) {
-			pr_warn("No interrupt available, giving up\n");
-			return -EINVAL;
-		}
-	}
+	if (IS_ENABLED(CONFIG_ARM64))
+		return ARCH_TIMER_PHYS_NONSECURE_PPI;
+
+	return ARCH_TIMER_PHYS_SECURE_PPI;
+}
+
+static int __init arch_timer_init(void)
+{
+	int ret;
 
 	ret = arch_timer_register();
 	if (ret)
@@ -904,6 +906,13 @@ static int __init arch_timer_of_init(struct device_node *np)
 	if (IS_ENABLED(CONFIG_ARM) &&
 	    of_property_read_bool(np, "arm,cpu-registers-not-fw-configured"))
 		arch_timer_uses_ppi = ARCH_TIMER_PHYS_SECURE_PPI;
+	else
+		arch_timer_uses_ppi = arch_timer_select_ppi();
+
+	if (!arch_timer_ppi[arch_timer_uses_ppi]) {
+		pr_err("No interrupt available, giving up\n");
+		return -EINVAL;
+	}
 
 	/* On some systems, the counter stops ticking when in suspend. */
 	arch_counter_suspend_stop = of_property_read_bool(np,
@@ -1049,6 +1058,12 @@ static int __init arch_timer_acpi_init(struct acpi_table_header *table)
 	/* Get the frequency from CNTFRQ */
 	arch_timer_detect_rate(NULL, NULL);
 
+	arch_timer_uses_ppi = arch_timer_select_ppi();
+	if (!arch_timer_ppi[arch_timer_uses_ppi]) {
+		pr_err("No interrupt available, giving up\n");
+		return -EINVAL;
+	}
+
 	/* Always-on capability */
 	arch_timer_c3stop = !(gtdt->non_secure_el1_flags & ACPI_GTDT_ALWAYS_ON);
 
-- 
2.9.3

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v20 00/17] acpi, clocksource: add GTDT driver and GTDT support in arm_arch_timer fu.wei@linaro.org - 2017-01-18 14:30 +0100
  [PATCH v20 01/17] clocksource/drivers/arm_arch_timer: Improve printk relevant code fu.wei@linaro.org - 2017-01-18 14:30 +0100
  [PATCH v20 02/17] clocksource/drivers/arm_arch_timer: Rename the timer type macros. fu.wei@linaro.org - 2017-01-18 14:30 +0100
  [PATCH v20 06/17] clocksource/drivers/arm_arch_timer: rework PPI determination fu.wei@linaro.org - 2017-01-18 14:30 +0100
  [PATCH v20 12/17] clocksource/drivers/arm_arch_timer: Refactor MMIO timer probing. fu.wei@linaro.org - 2017-01-18 14:40 +0100
  [PATCH v20 16/17] clocksource/drivers/arm_arch_timer: Add GTDT support for memory-mapped timer fu.wei@linaro.org - 2017-01-18 14:40 +0100
    Re: [PATCH v20 16/17] clocksource/drivers/arm_arch_timer: Add GTDT  support for memory-mapped timer Hanjun Guo <hanjun.guo@linaro.org> - 2017-01-19 10:20 +0100
      Re: [PATCH v20 16/17] clocksource/drivers/arm_arch_timer: Add GTDT  support for memory-mapped timer Fu Wei <fu.wei@linaro.org> - 2017-01-19 11:10 +0100
        Re: [PATCH v20 16/17] clocksource/drivers/arm_arch_timer: Add GTDT  support for memory-mapped timer Hanjun Guo <hanjun.guo@linaro.org> - 2017-01-19 13:50 +0100
  [PATCH v20 11/17] clocksource/drivers/arm_arch_timer: Introduce some new structs to prepare for GTDT fu.wei@linaro.org - 2017-01-18 14:40 +0100
    Re: [PATCH v20 11/17] clocksource/drivers/arm_arch_timer: Introduce  some new structs to prepare for GTDT Hanjun Guo <hanjun.guo@linaro.org> - 2017-01-19 09:30 +0100
      Re: [PATCH v20 11/17] clocksource/drivers/arm_arch_timer: Introduce  some new structs to prepare for GTDT Fu Wei <fu.wei@linaro.org> - 2017-01-19 11:00 +0100
  [PATCH v20 07/17] clocksource/drivers/arm_arch_timer: Separate out device-tree code from arch_timer_detect_rate fu.wei@linaro.org - 2017-01-18 14:40 +0100
  [PATCH v20 09/17] clocksource/drivers/arm_arch_timer: Refactor arch_timer_needs_probing fu.wei@linaro.org - 2017-01-18 14:40 +0100
  [PATCH v20 13/17] acpi/arm64: Add GTDT table parse driver fu.wei@linaro.org - 2017-01-18 14:40 +0100
    Re: [PATCH v20 13/17] acpi/arm64: Add GTDT table parse driver Hanjun Guo <hanjun.guo@linaro.org> - 2017-01-19 10:20 +0100
      Re: [PATCH v20 13/17] acpi/arm64: Add GTDT table parse driver Fu Wei <fu.wei@linaro.org> - 2017-01-19 11:40 +0100
        Re: [PATCH v20 13/17] acpi/arm64: Add GTDT table parse driver Mark Rutland <mark.rutland@arm.com> - 2017-01-19 12:20 +0100
          Re: [PATCH v20 13/17] acpi/arm64: Add GTDT table parse driver Fu Wei <fu.wei@linaro.org> - 2017-01-19 13:30 +0100
  [PATCH v20 05/17] clocksource/drivers/arm_arch_timer: Add a new enum for spi type fu.wei@linaro.org - 2017-01-18 14:40 +0100
  [PATCH v20 08/17] clocksource/drivers/arm_arch_timer: Rework counter frequency detection. fu.wei@linaro.org - 2017-01-18 14:40 +0100
    Re: [PATCH v20 08/17] clocksource/drivers/arm_arch_timer: Rework  counter frequency detection. Hanjun Guo <hanjun.guo@linaro.org> - 2017-01-19 09:10 +0100
      Re: [PATCH v20 08/17] clocksource/drivers/arm_arch_timer: Rework  counter frequency detection. Fu Wei <fu.wei@linaro.org> - 2017-01-19 10:50 +0100
        Re: [PATCH v20 08/17] clocksource/drivers/arm_arch_timer: Rework  counter frequency detection. Hanjun Guo <hanjun.guo@linaro.org> - 2017-01-19 13:50 +0100
    Re: [PATCH v20 08/17] clocksource/drivers/arm_arch_timer: Rework  counter frequency detection. Mark Rutland <mark.rutland@arm.com> - 2017-01-24 18:30 +0100
      Re: [PATCH v20 08/17] clocksource/drivers/arm_arch_timer: Rework  counter frequency detection. Fu Wei <fu.wei@linaro.org> - 2017-01-25 07:50 +0100
        Re: [PATCH v20 08/17] clocksource/drivers/arm_arch_timer: Rework  counter frequency detection. Fu Wei <fu.wei@linaro.org> - 2017-01-25 08:30 +0100
        Re: [PATCH v20 08/17] clocksource/drivers/arm_arch_timer: Rework  counter frequency detection. Christopher Covington <cov@codeaurora.org> - 2017-01-25 16:40 +0100
          Re: [PATCH v20 08/17] clocksource/drivers/arm_arch_timer: Rework  counter frequency detection. Mark Rutland <mark.rutland@arm.com> - 2017-01-25 18:40 +0100
            Re: [PATCH v20 08/17] clocksource/drivers/arm_arch_timer: Rework  counter frequency detection. Fu Wei <fu.wei@linaro.org> - 2017-01-26 07:00 +0100
        Re: [PATCH v20 08/17] clocksource/drivers/arm_arch_timer: Rework  counter frequency detection. Mark Rutland <mark.rutland@arm.com> - 2017-01-25 18:30 +0100
          Re: [PATCH v20 08/17] clocksource/drivers/arm_arch_timer: Rework  counter frequency detection. Fu Wei <fu.wei@linaro.org> - 2017-01-26 06:50 +0100
            Re: [PATCH v20 08/17] clocksource/drivers/arm_arch_timer: Rework  counter frequency detection. Mark Rutland <mark.rutland@arm.com> - 2017-01-30 19:00 +0100
  [PATCH v20 10/17] clocksource/drivers/arm_arch_timer: Move arch_timer_needs_of_probing into DT init call fu.wei@linaro.org - 2017-01-18 14:40 +0100
  [PATCH v20 14/17] clocksource/drivers/arm_arch_timer: Simplify ACPI support code. fu.wei@linaro.org - 2017-01-18 14:40 +0100
  [PATCH v20 15/17] acpi/arm64: Add memory-mapped timer support in GTDT driver fu.wei@linaro.org - 2017-01-18 14:40 +0100
  [PATCH v20 17/17] acpi/arm64: Add SBSA Generic Watchdog support in GTDT driver fu.wei@linaro.org - 2017-01-18 14:50 +0100
  Re: [PATCH v20 00/17] acpi, clocksource: add GTDT driver and GTDT  support in arm_arch_timer Hanjun Guo <hanjun.guo@linaro.org> - 2017-01-19 10:30 +0100
    Re: [PATCH v20 00/17] acpi, clocksource: add GTDT driver and GTDT  support in arm_arch_timer Fu Wei <fu.wei@linaro.org> - 2017-01-19 12:20 +0100
  Re: [PATCH v20 00/17] acpi, clocksource: add GTDT driver and GTDT  support in arm_arch_timer Mark Rutland <mark.rutland@arm.com> - 2017-01-23 20:00 +0100
    Re: [PATCH v20 00/17] acpi, clocksource: add GTDT driver and GTDT  support in arm_arch_timer Fu Wei <fu.wei@linaro.org> - 2017-01-24 06:20 +0100

csiph-web