All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v23 00/11] acpi, clocksource: add GTDT driver and GTDT support in arm_arch_timer
@ 2017-03-31 17:50 ` fu.wei at linaro.org
  0 siblings, 0 replies; 66+ messages in thread
From: fu.wei @ 2017-03-31 17:50 UTC (permalink / raw)
  To: rjw, lenb, daniel.lezcano, tglx, marc.zyngier, mark.rutland,
	lorenzo.pieralisi, sudeep.holla, hanjun.guo
  Cc: linux-arm-kernel, linaro-acpi, linux-kernel, linux-acpi,
	rruigrok, harba, cov, timur, graeme.gregory, al.stone, jcm, wei,
	arnd, catalin.marinas, will.deacon, Suravee.Suthikulpanit,
	leo.duran, wim, linux, linux-watchdog, tn, christoffer.dall,
	julien.grall, Fu Wei

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

This patchset:
    (1)Preparation for adding GTDT support in arm_arch_timer:
        1. Introduce a MMIO CNTFRQ helper.
        2. separate out device-tree code from arch_timer_detect_rate
        3. remove arch_timer_detect_rate use arch_timer_*get_cntfrq directly
        4. Refactor arch_timer_needs_probing, and move it into DT init call
        5. Introduce some new structs and refactor the MMIO timer init code
        for reusing some common code.

    (2)Introduce ACPI GTDT parser: drivers/acpi/arm64/acpi_gtdt.c
    Parse all kinds of timer in GTDT table of ACPI:arch timer,
    memory-mapped timer and SBSA Generic Watchdog timer.
    This driver can help to simplify all the relevant timer drivers,
    and separate all the ACPI GTDT knowledge from them.

    (3)Simplify ACPI code for arm_arch_timer

    (4)Add GTDT support for ARM memory-mapped timer.

This patchset has been tested on the following platforms with ACPI enabled:
    (1)ARM Foundation v8 model

Changelog:
v23: https://lkml.org/lkml/2017/3/31/
     Rebase to git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arch-timer/cleanup
     Improve the data struct of arch_timer_mem and arch_timer_mem_frame to
     improve the parser of GT blocks and arch_timer_mem initualization.
     Improve arch_timer_rate detection: sysreg frequency is primary in DT boot
     Improve some comments in GTDT parser driver.
     Improve acpi_gtdt_init function, and make a comment for the multiple calls.
     Improve the unwinding for the irq of timers, when an error occurs.
     Handle the case of virtual timer GSIV is 0.

v22: https://lkml.org/lkml/2017/3/21/523
     Rebase to git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arch-timer/cleanup
     Only Introduce arch_timer_mem_get_cntfrq to get the frequency from mmio.
     Merged patch 2,3(about arch_timer_detect_rate).
     Keep arch_timer_rate, do NOT split it for different types of timer.
     Improve  memory-mapped timer support by comments and variable name:
         data-->timer_mem
         frame-->gtdt_frame
     Delete zero check for SBSA watchdog irq.
     Skip secure SBSA watchdog in GTDT driver.
     Delete Kconfig modification for SBSA watchdog driver.
     Delete no_irq, using nr_res instead.

v21: https://lkml.org/lkml/2017/2/6/734
     Introduce two functions to get the frequency from mmio and sysreg.
     Remove arch_timer_detect_rate use arch_timer_get_*_freq directly
     Split arch_timer_rate for different types of timer.
     Skip secure timer frame in GTDT driver.
     Rebase to git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arch-timer/cleanup
     (The first 6 patches in v20 have been merged into arch-timer/cleanup branch)

v20: https://lkml.org/lkml/2017/1/18/534
     Reorder the first 4 patches and split the 4th patches.
     Leave CNTHCTL_* as they originally were.
     Fix the bug in arch_timer_select_ppi.
     Split "Rework counter frequency detection" patch.
     Rework the arch_timer_detect_rate function.
     Improve the commit message of "Refactor MMIO timer probing".
     Rebase to 4.10.0-rc4

v19: https://lkml.org/lkml/2016/12/21/25
     Fix a '\n' missing in a error message in arch_timer_mem_init.
     Add "request_mem_region" for ioremapping cntbase, according to
     f947ee1 clocksource/drivers/arm_arch_timer: Map frame with of_io_request_and_map()
     Rebase to 4.9.0-gfb779ff

v18: https://lkml.org/lkml/2016/12/8/446
     Fix 8/15 patch problem of "int ret;" in arch_timer_acpi_init.
     Rebase to 4.9.0-rc8-g9269898

v17: https://lkml.org/lkml/2016/11/25/140
     Take out some cleanups from 4/15.
     Merge 5/15 and 6/15, improve PPI determination code,
     improve commit message.
     Rework counter frequency detection.
     Move arch_timer_needs_of_probing into DT init call.
     Move Platform Timer scan loop back to timer init call to avoid allocating
     and free memory.
     Improve all the exported functions' comment.

v16: https://lkml.org/lkml/2016/11/16/268
     Fix patchset problem about static enum ppi_nr of 01/13 in v15.
     Refactor arch_timer_detect_rate.
     Refactor arch_timer_needs_probing.

v15: https://lkml.org/lkml/2016/11/15/366
     Re-order patches
     Add arm_arch_timer refactoring patches to prepare for GTDT:
         1. rename some  enums and defines, and some cleanups
         2. separate out arch_timer_uses_ppi init code and fix a potential bug
         3. Improve some new structs, refactor the timer init code.
     Since the some structs have been changed, GTDT parser for memory-mapped
     timer and SBSA Generic Watchdog timer have been update.

v14: https://lkml.org/lkml/2016/9/28/573
     Separate memory-mapped timer GTDT support into two patches
         1. Refactor the timer init code to prepare for GTDT
         2. Add GTDT support for memory-mapped timer

v13: http://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1231717.html
     Improve arm_arch_timer code for memory-mapped
     timer GTDT support, refactor original memory-mapped timer
     dt support for reusing some common code.

v12: https://lkml.org/lkml/2016/9/13/250
     Rebase to latest Linux 4.8-rc6
     Delete the confusing "skipping" in the error message.

V11: https://lkml.org/lkml/2016/9/6/354
     Rebase to latest Linux 4.8-rc5
     Delete typedef (suggested by checkpatch.pl)

V10: https://lkml.org/lkml/2016/7/26/215
     Drop the "readq" patch.
     Rebase to latest Linux 4.7.

V9: https://lkml.org/lkml/2016/7/25/345
    Improve pr_err message in acpi gtdt driver.
    Update Commit message for 7/9
    shorten the irq mapping function name
    Improve GTDT driver for memory-mapped timer

v8: https://lkml.org/lkml/2016/7/19/660
    Improve "pr_fmt(fmt)" definition: add "ACPI" in front of "GTDT",
    and also improve printk message.
    Simplify is_timer_block and is_watchdog.
    Merge acpi_gtdt_desc_init and gtdt_arch_timer_init into acpi_gtdt_init();
    Delete __init in include/linux/acpi.h for GTDT API
    Make ARM64 select GTDT.
    Delete "#include <linux/module.h>" from acpi_gtdt.c
    Simplify GT block parse code.

v7: https://lkml.org/lkml/2016/7/13/769
    Move the GTDT driver to drivers/acpi/arm64
    Add add the ARM64-specific ACPI Support maintainers in MAINTAINERS
    Merge 3 patches of GTDT parser driver.
    Fix the for_each_platform_timer bug.

v6: https://lkml.org/lkml/2016/6/29/580
    split the GTDT driver to 4 parts: basic, arch_timer, memory-mapped timer,
    and SBSA Generic Watchdog timer
    Improve driver by suggestions and example code from Daniel Lezcano

v5: https://lkml.org/lkml/2016/5/24/356
    Sorting out all patches, simplify the API of GTDT driver:
    GTDT driver just fills the data struct for arm_arch_timer driver.

v4: https://lists.linaro.org/pipermail/linaro-acpi/2016-March/006667.html
    Delete the kvm relevant patches
    Separate two patches for sorting out the code for arm_arch_timer.
    Improve irq info export code to allow missing irq info in GTDT table.

v3: https://lkml.org/lkml/2016/2/1/658
    Improve GTDT driver code:
      (1)improve pr_* by defining pr_fmt(fmt)
      (2)simplify gtdt_sbsa_gwdt_init
      (3)improve gtdt_arch_timer_data_init, if table is NULL, it will try
      to get GTDT table.
    Move enum ppi_nr to arm_arch_timer.h, and add enum spi_nr.
    Add arm_arch_timer get ppi from DT and GTDT support for kvm.

v2: https://lkml.org/lkml/2015/12/2/10
    Rebase to latest kernel version(4.4-rc3).
    Fix the bug about the config problem,
    use CONFIG_ACPI_GTDT instead of CONFIG_ACPI in arm_arch_timer.c

v1: The first upstreaming version: https://lkml.org/lkml/2015/10/28/553

Fu Wei (11):
  clocksource: arm_arch_timer: add MMIO CNTFRQ helper
  clocksource: arm_arch_timer: split dt-only rate handling
  clocksource: arm_arch_timer: refactor arch_timer_needs_probing
  clocksource: arm_arch_timer: move arch_timer_needs_of_probing into DT
    init call
  clocksource: arm_arch_timer: add structs to describe MMIO timer
  clocksource: arm_arch_timer: refactor MMIO timer probing.
  acpi/arm64: Add GTDT table parse driver
  clocksource: arm_arch_timer: simplify ACPI support code.
  acpi/arm64: Add memory-mapped timer support in GTDT driver
  clocksource: arm_arch_timer: add GTDT support for memory-mapped timer
  acpi/arm64: Add SBSA Generic Watchdog support in GTDT driver

 arch/arm64/Kconfig                   |   1 +
 drivers/acpi/arm64/Kconfig           |   3 +
 drivers/acpi/arm64/Makefile          |   1 +
 drivers/acpi/arm64/gtdt.c            | 406 +++++++++++++++++++++++++++++++++++
 drivers/clocksource/arm_arch_timer.c | 338 ++++++++++++++++++-----------
 include/clocksource/arm_arch_timer.h |  16 ++
 include/linux/acpi.h                 |   7 +
 7 files changed, 648 insertions(+), 124 deletions(-)
 create mode 100644 drivers/acpi/arm64/gtdt.c

-- 
2.9.3

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

* [PATCH v23 00/11] acpi, clocksource: add GTDT driver and GTDT support in arm_arch_timer
@ 2017-03-31 17:50 ` fu.wei at linaro.org
  0 siblings, 0 replies; 66+ messages in thread
From: fu.wei at linaro.org @ 2017-03-31 17:50 UTC (permalink / raw)
  To: linux-arm-kernel

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

This patchset:
    (1)Preparation for adding GTDT support in arm_arch_timer:
        1. Introduce a MMIO CNTFRQ helper.
        2. separate out device-tree code from arch_timer_detect_rate
        3. remove arch_timer_detect_rate use arch_timer_*get_cntfrq directly
        4. Refactor arch_timer_needs_probing, and move it into DT init call
        5. Introduce some new structs and refactor the MMIO timer init code
        for reusing some common code.

    (2)Introduce ACPI GTDT parser: drivers/acpi/arm64/acpi_gtdt.c
    Parse all kinds of timer in GTDT table of ACPI:arch timer,
    memory-mapped timer and SBSA Generic Watchdog timer.
    This driver can help to simplify all the relevant timer drivers,
    and separate all the ACPI GTDT knowledge from them.

    (3)Simplify ACPI code for arm_arch_timer

    (4)Add GTDT support for ARM memory-mapped timer.

This patchset has been tested on the following platforms with ACPI enabled:
    (1)ARM Foundation v8 model

Changelog:
v23: https://lkml.org/lkml/2017/3/31/
     Rebase to git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arch-timer/cleanup
     Improve the data struct of arch_timer_mem and arch_timer_mem_frame to
     improve the parser of GT blocks and arch_timer_mem initualization.
     Improve arch_timer_rate detection: sysreg frequency is primary in DT boot
     Improve some comments in GTDT parser driver.
     Improve acpi_gtdt_init function, and make a comment for the multiple calls.
     Improve the unwinding for the irq of timers, when an error occurs.
     Handle the case of virtual timer GSIV is 0.

v22: https://lkml.org/lkml/2017/3/21/523
     Rebase to git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arch-timer/cleanup
     Only Introduce arch_timer_mem_get_cntfrq to get the frequency from mmio.
     Merged patch 2,3(about arch_timer_detect_rate).
     Keep arch_timer_rate, do NOT split it for different types of timer.
     Improve  memory-mapped timer support by comments and variable name:
         data-->timer_mem
         frame-->gtdt_frame
     Delete zero check for SBSA watchdog irq.
     Skip secure SBSA watchdog in GTDT driver.
     Delete Kconfig modification for SBSA watchdog driver.
     Delete no_irq, using nr_res instead.

v21: https://lkml.org/lkml/2017/2/6/734
     Introduce two functions to get the frequency from mmio and sysreg.
     Remove arch_timer_detect_rate use arch_timer_get_*_freq directly
     Split arch_timer_rate for different types of timer.
     Skip secure timer frame in GTDT driver.
     Rebase to git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arch-timer/cleanup
     (The first 6 patches in v20 have been merged into arch-timer/cleanup branch)

v20: https://lkml.org/lkml/2017/1/18/534
     Reorder the first 4 patches and split the 4th patches.
     Leave CNTHCTL_* as they originally were.
     Fix the bug in arch_timer_select_ppi.
     Split "Rework counter frequency detection" patch.
     Rework the arch_timer_detect_rate function.
     Improve the commit message of "Refactor MMIO timer probing".
     Rebase to 4.10.0-rc4

v19: https://lkml.org/lkml/2016/12/21/25
     Fix a '\n' missing in a error message in arch_timer_mem_init.
     Add "request_mem_region" for ioremapping cntbase, according to
     f947ee1 clocksource/drivers/arm_arch_timer: Map frame with of_io_request_and_map()
     Rebase to 4.9.0-gfb779ff

v18: https://lkml.org/lkml/2016/12/8/446
     Fix 8/15 patch problem of "int ret;" in arch_timer_acpi_init.
     Rebase to 4.9.0-rc8-g9269898

v17: https://lkml.org/lkml/2016/11/25/140
     Take out some cleanups from 4/15.
     Merge 5/15 and 6/15, improve PPI determination code,
     improve commit message.
     Rework counter frequency detection.
     Move arch_timer_needs_of_probing into DT init call.
     Move Platform Timer scan loop back to timer init call to avoid allocating
     and free memory.
     Improve all the exported functions' comment.

v16: https://lkml.org/lkml/2016/11/16/268
     Fix patchset problem about static enum ppi_nr of 01/13 in v15.
     Refactor arch_timer_detect_rate.
     Refactor arch_timer_needs_probing.

v15: https://lkml.org/lkml/2016/11/15/366
     Re-order patches
     Add arm_arch_timer refactoring patches to prepare for GTDT:
         1. rename some  enums and defines, and some cleanups
         2. separate out arch_timer_uses_ppi init code and fix a potential bug
         3. Improve some new structs, refactor the timer init code.
     Since the some structs have been changed, GTDT parser for memory-mapped
     timer and SBSA Generic Watchdog timer have been update.

v14: https://lkml.org/lkml/2016/9/28/573
     Separate memory-mapped timer GTDT support into two patches
         1. Refactor the timer init code to prepare for GTDT
         2. Add GTDT support for memory-mapped timer

v13: http://www.mail-archive.com/linux-kernel at vger.kernel.org/msg1231717.html
     Improve arm_arch_timer code for memory-mapped
     timer GTDT support, refactor original memory-mapped timer
     dt support for reusing some common code.

v12: https://lkml.org/lkml/2016/9/13/250
     Rebase to latest Linux 4.8-rc6
     Delete the confusing "skipping" in the error message.

V11: https://lkml.org/lkml/2016/9/6/354
     Rebase to latest Linux 4.8-rc5
     Delete typedef (suggested by checkpatch.pl)

V10: https://lkml.org/lkml/2016/7/26/215
     Drop the "readq" patch.
     Rebase to latest Linux 4.7.

V9: https://lkml.org/lkml/2016/7/25/345
    Improve pr_err message in acpi gtdt driver.
    Update Commit message for 7/9
    shorten the irq mapping function name
    Improve GTDT driver for memory-mapped timer

v8: https://lkml.org/lkml/2016/7/19/660
    Improve "pr_fmt(fmt)" definition: add "ACPI" in front of "GTDT",
    and also improve printk message.
    Simplify is_timer_block and is_watchdog.
    Merge acpi_gtdt_desc_init and gtdt_arch_timer_init into acpi_gtdt_init();
    Delete __init in include/linux/acpi.h for GTDT API
    Make ARM64 select GTDT.
    Delete "#include <linux/module.h>" from acpi_gtdt.c
    Simplify GT block parse code.

v7: https://lkml.org/lkml/2016/7/13/769
    Move the GTDT driver to drivers/acpi/arm64
    Add add the ARM64-specific ACPI Support maintainers in MAINTAINERS
    Merge 3 patches of GTDT parser driver.
    Fix the for_each_platform_timer bug.

v6: https://lkml.org/lkml/2016/6/29/580
    split the GTDT driver to 4 parts: basic, arch_timer, memory-mapped timer,
    and SBSA Generic Watchdog timer
    Improve driver by suggestions and example code from Daniel Lezcano

v5: https://lkml.org/lkml/2016/5/24/356
    Sorting out all patches, simplify the API of GTDT driver:
    GTDT driver just fills the data struct for arm_arch_timer driver.

v4: https://lists.linaro.org/pipermail/linaro-acpi/2016-March/006667.html
    Delete the kvm relevant patches
    Separate two patches for sorting out the code for arm_arch_timer.
    Improve irq info export code to allow missing irq info in GTDT table.

v3: https://lkml.org/lkml/2016/2/1/658
    Improve GTDT driver code:
      (1)improve pr_* by defining pr_fmt(fmt)
      (2)simplify gtdt_sbsa_gwdt_init
      (3)improve gtdt_arch_timer_data_init, if table is NULL, it will try
      to get GTDT table.
    Move enum ppi_nr to arm_arch_timer.h, and add enum spi_nr.
    Add arm_arch_timer get ppi from DT and GTDT support for kvm.

v2: https://lkml.org/lkml/2015/12/2/10
    Rebase to latest kernel version(4.4-rc3).
    Fix the bug about the config problem,
    use CONFIG_ACPI_GTDT instead of CONFIG_ACPI in arm_arch_timer.c

v1: The first upstreaming version: https://lkml.org/lkml/2015/10/28/553

Fu Wei (11):
  clocksource: arm_arch_timer: add MMIO CNTFRQ helper
  clocksource: arm_arch_timer: split dt-only rate handling
  clocksource: arm_arch_timer: refactor arch_timer_needs_probing
  clocksource: arm_arch_timer: move arch_timer_needs_of_probing into DT
    init call
  clocksource: arm_arch_timer: add structs to describe MMIO timer
  clocksource: arm_arch_timer: refactor MMIO timer probing.
  acpi/arm64: Add GTDT table parse driver
  clocksource: arm_arch_timer: simplify ACPI support code.
  acpi/arm64: Add memory-mapped timer support in GTDT driver
  clocksource: arm_arch_timer: add GTDT support for memory-mapped timer
  acpi/arm64: Add SBSA Generic Watchdog support in GTDT driver

 arch/arm64/Kconfig                   |   1 +
 drivers/acpi/arm64/Kconfig           |   3 +
 drivers/acpi/arm64/Makefile          |   1 +
 drivers/acpi/arm64/gtdt.c            | 406 +++++++++++++++++++++++++++++++++++
 drivers/clocksource/arm_arch_timer.c | 338 ++++++++++++++++++-----------
 include/clocksource/arm_arch_timer.h |  16 ++
 include/linux/acpi.h                 |   7 +
 7 files changed, 648 insertions(+), 124 deletions(-)
 create mode 100644 drivers/acpi/arm64/gtdt.c

-- 
2.9.3

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

* [PATCH v23 01/11] clocksource: arm_arch_timer: add MMIO CNTFRQ helper
  2017-03-31 17:50 ` fu.wei at linaro.org
@ 2017-03-31 17:50   ` fu.wei at linaro.org
  -1 siblings, 0 replies; 66+ messages in thread
From: fu.wei @ 2017-03-31 17:50 UTC (permalink / raw)
  To: rjw, lenb, daniel.lezcano, tglx, marc.zyngier, mark.rutland,
	lorenzo.pieralisi, sudeep.holla, hanjun.guo
  Cc: linux-arm-kernel, linaro-acpi, linux-kernel, linux-acpi,
	rruigrok, harba, cov, timur, graeme.gregory, al.stone, jcm, wei,
	arnd, catalin.marinas, will.deacon, Suravee.Suthikulpanit,
	leo.duran, wim, linux, linux-watchdog, tn, christoffer.dall,
	julien.grall, Fu Wei

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

We currently open-code the readl() for the MMIO time frequency. To avoid
duplicating the logic with future rework, this patch adds a helepr to
read the MMIO timer frequency, mirroring what we have for the sysreg
timer frequency.

Signed-off-by: Fu Wei <fu.wei@linaro.org>
[Mark: reword commit message]
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
---
 drivers/clocksource/arm_arch_timer.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index 3faed19..843f923 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -555,6 +555,11 @@ static int arch_timer_starting_cpu(unsigned int cpu)
 	return 0;
 }
 
+static u32 arch_timer_mem_get_cntfrq(void __iomem *cntbase)
+{
+	return readl_relaxed(cntbase + CNTFRQ);
+}
+
 static void
 arch_timer_detect_rate(void __iomem *cntbase, struct device_node *np)
 {
@@ -569,7 +574,7 @@ arch_timer_detect_rate(void __iomem *cntbase, struct device_node *np)
 	if (!acpi_disabled ||
 	    of_property_read_u32(np, "clock-frequency", &arch_timer_rate)) {
 		if (cntbase)
-			arch_timer_rate = readl_relaxed(cntbase + CNTFRQ);
+			arch_timer_rate = arch_timer_mem_get_cntfrq(cntbase);
 		else
 			arch_timer_rate = arch_timer_get_cntfrq();
 	}
-- 
2.9.3

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

* [PATCH v23 01/11] clocksource: arm_arch_timer: add MMIO CNTFRQ helper
@ 2017-03-31 17:50   ` fu.wei at linaro.org
  0 siblings, 0 replies; 66+ messages in thread
From: fu.wei at linaro.org @ 2017-03-31 17:50 UTC (permalink / raw)
  To: linux-arm-kernel

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

We currently open-code the readl() for the MMIO time frequency. To avoid
duplicating the logic with future rework, this patch adds a helepr to
read the MMIO timer frequency, mirroring what we have for the sysreg
timer frequency.

Signed-off-by: Fu Wei <fu.wei@linaro.org>
[Mark: reword commit message]
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
---
 drivers/clocksource/arm_arch_timer.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index 3faed19..843f923 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -555,6 +555,11 @@ static int arch_timer_starting_cpu(unsigned int cpu)
 	return 0;
 }
 
+static u32 arch_timer_mem_get_cntfrq(void __iomem *cntbase)
+{
+	return readl_relaxed(cntbase + CNTFRQ);
+}
+
 static void
 arch_timer_detect_rate(void __iomem *cntbase, struct device_node *np)
 {
@@ -569,7 +574,7 @@ arch_timer_detect_rate(void __iomem *cntbase, struct device_node *np)
 	if (!acpi_disabled ||
 	    of_property_read_u32(np, "clock-frequency", &arch_timer_rate)) {
 		if (cntbase)
-			arch_timer_rate = readl_relaxed(cntbase + CNTFRQ);
+			arch_timer_rate = arch_timer_mem_get_cntfrq(cntbase);
 		else
 			arch_timer_rate = arch_timer_get_cntfrq();
 	}
-- 
2.9.3

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

* [PATCH v23 02/11] clocksource: arm_arch_timer: split dt-only rate handling
  2017-03-31 17:50 ` fu.wei at linaro.org
@ 2017-03-31 17:50   ` fu.wei at linaro.org
  -1 siblings, 0 replies; 66+ messages in thread
From: fu.wei @ 2017-03-31 17:50 UTC (permalink / raw)
  To: rjw, lenb, daniel.lezcano, tglx, marc.zyngier, mark.rutland,
	lorenzo.pieralisi, sudeep.holla, hanjun.guo
  Cc: linux-arm-kernel, linaro-acpi, linux-kernel, linux-acpi,
	rruigrok, harba, cov, timur, graeme.gregory, al.stone, jcm, wei,
	arnd, catalin.marinas, will.deacon, Suravee.Suthikulpanit,
	leo.duran, wim, linux, linux-watchdog, tn, christoffer.dall,
	julien.grall, Fu Wei

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

Currently Currently arch_timer_detect_rate() tried to handle both the
sysreg timer and MMIO timer, with DT-specific fallback code. This gets
in the way of implementing deterministic and correct rate probing when
using ACPI.

This patch moves this logic out into the (DT-specific) probe functions,
allowing different logic to be used in the ACPI case, and making it
easier to see which CNTFRQ register is being read in each case.

Signed-off-by: Fu Wei <fu.wei@linaro.org>
[Mark: reword commit message, TODO: rework comments]
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
---
 drivers/clocksource/arm_arch_timer.c | 58 +++++++++++++++++++-----------------
 1 file changed, 30 insertions(+), 28 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index 843f923..1b6a7e6 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -560,30 +560,6 @@ static u32 arch_timer_mem_get_cntfrq(void __iomem *cntbase)
 	return readl_relaxed(cntbase + CNTFRQ);
 }
 
-static void
-arch_timer_detect_rate(void __iomem *cntbase, struct device_node *np)
-{
-	/* Who has more than one independent system counter? */
-	if (arch_timer_rate)
-		return;
-
-	/*
-	 * Try to determine the frequency from the device tree or CNTFRQ,
-	 * if ACPI is enabled, get the frequency from CNTFRQ ONLY.
-	 */
-	if (!acpi_disabled ||
-	    of_property_read_u32(np, "clock-frequency", &arch_timer_rate)) {
-		if (cntbase)
-			arch_timer_rate = arch_timer_mem_get_cntfrq(cntbase);
-		else
-			arch_timer_rate = arch_timer_get_cntfrq();
-	}
-
-	/* Check the timer frequency. */
-	if (arch_timer_rate == 0)
-		pr_warn("frequency not available\n");
-}
-
 static void arch_timer_banner(unsigned type)
 {
 	pr_info("%s%s%s timer(s) running at %lu.%02luMHz (%s%s%s).\n",
@@ -958,7 +934,17 @@ static int __init arch_timer_of_init(struct device_node *np)
 	for (i = ARCH_TIMER_PHYS_SECURE_PPI; i < ARCH_TIMER_MAX_TIMER_PPI; i++)
 		arch_timer_ppi[i] = irq_of_parse_and_map(np, i);
 
-	arch_timer_detect_rate(NULL, np);
+	/*
+	 * Determine the frequency of system counter:
+	 * Try to get the frequency from the device tree.
+	 * If fail, try the sysreg CNTFRQ. Then verify the frequency.
+	 */
+	if (of_property_read_u32(np, "clock-frequency", &arch_timer_rate))
+		arch_timer_rate = arch_timer_get_cntfrq();
+	if (!arch_timer_rate) {
+		pr_err(FW_BUG "frequency not available.\n");
+		return -EINVAL;
+	}
 
 	arch_timer_c3stop = !of_property_read_bool(np, "always-on");
 
@@ -1069,7 +1055,19 @@ static int __init arch_timer_mem_init(struct device_node *np)
 		goto out;
 	}
 
-	arch_timer_detect_rate(base, np);
+	/*
+	 * Try to determine the frequency from the device tree,
+	 * if fail, get the frequency from the CNTFRQ reg of MMIO timer.
+	 */
+	if (!arch_timer_rate &&
+	    of_property_read_u32(np, "clock-frequency", &arch_timer_rate))
+		arch_timer_rate = arch_timer_mem_get_cntfrq(base);
+	if (!arch_timer_rate) {
+		pr_err(FW_BUG "MMIO frequency not available.\n");
+		ret = -EINVAL;
+		goto out;
+	}
+
 	ret = arch_timer_mem_register(base, irq);
 	if (ret)
 		goto out;
@@ -1130,8 +1128,12 @@ static int __init arch_timer_acpi_init(struct acpi_table_header *table)
 		map_generic_timer_interrupt(gtdt->non_secure_el2_interrupt,
 		gtdt->non_secure_el2_flags);
 
-	/* Get the frequency from CNTFRQ */
-	arch_timer_detect_rate(NULL, NULL);
+	/* Get the frequency from the sysreg CNTFRQ */
+	arch_timer_rate = arch_timer_get_cntfrq();
+	if (!arch_timer_rate) {
+		pr_err(FW_BUG "frequency not available.\n");
+		return -EINVAL;
+	}
 
 	arch_timer_uses_ppi = arch_timer_select_ppi();
 	if (!arch_timer_ppi[arch_timer_uses_ppi]) {
-- 
2.9.3


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

* [PATCH v23 02/11] clocksource: arm_arch_timer: split dt-only rate handling
@ 2017-03-31 17:50   ` fu.wei at linaro.org
  0 siblings, 0 replies; 66+ messages in thread
From: fu.wei at linaro.org @ 2017-03-31 17:50 UTC (permalink / raw)
  To: linux-arm-kernel

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

Currently Currently arch_timer_detect_rate() tried to handle both the
sysreg timer and MMIO timer, with DT-specific fallback code. This gets
in the way of implementing deterministic and correct rate probing when
using ACPI.

This patch moves this logic out into the (DT-specific) probe functions,
allowing different logic to be used in the ACPI case, and making it
easier to see which CNTFRQ register is being read in each case.

Signed-off-by: Fu Wei <fu.wei@linaro.org>
[Mark: reword commit message, TODO: rework comments]
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
---
 drivers/clocksource/arm_arch_timer.c | 58 +++++++++++++++++++-----------------
 1 file changed, 30 insertions(+), 28 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index 843f923..1b6a7e6 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -560,30 +560,6 @@ static u32 arch_timer_mem_get_cntfrq(void __iomem *cntbase)
 	return readl_relaxed(cntbase + CNTFRQ);
 }
 
-static void
-arch_timer_detect_rate(void __iomem *cntbase, struct device_node *np)
-{
-	/* Who has more than one independent system counter? */
-	if (arch_timer_rate)
-		return;
-
-	/*
-	 * Try to determine the frequency from the device tree or CNTFRQ,
-	 * if ACPI is enabled, get the frequency from CNTFRQ ONLY.
-	 */
-	if (!acpi_disabled ||
-	    of_property_read_u32(np, "clock-frequency", &arch_timer_rate)) {
-		if (cntbase)
-			arch_timer_rate = arch_timer_mem_get_cntfrq(cntbase);
-		else
-			arch_timer_rate = arch_timer_get_cntfrq();
-	}
-
-	/* Check the timer frequency. */
-	if (arch_timer_rate == 0)
-		pr_warn("frequency not available\n");
-}
-
 static void arch_timer_banner(unsigned type)
 {
 	pr_info("%s%s%s timer(s) running at %lu.%02luMHz (%s%s%s).\n",
@@ -958,7 +934,17 @@ static int __init arch_timer_of_init(struct device_node *np)
 	for (i = ARCH_TIMER_PHYS_SECURE_PPI; i < ARCH_TIMER_MAX_TIMER_PPI; i++)
 		arch_timer_ppi[i] = irq_of_parse_and_map(np, i);
 
-	arch_timer_detect_rate(NULL, np);
+	/*
+	 * Determine the frequency of system counter:
+	 * Try to get the frequency from the device tree.
+	 * If fail, try the sysreg CNTFRQ. Then verify the frequency.
+	 */
+	if (of_property_read_u32(np, "clock-frequency", &arch_timer_rate))
+		arch_timer_rate = arch_timer_get_cntfrq();
+	if (!arch_timer_rate) {
+		pr_err(FW_BUG "frequency not available.\n");
+		return -EINVAL;
+	}
 
 	arch_timer_c3stop = !of_property_read_bool(np, "always-on");
 
@@ -1069,7 +1055,19 @@ static int __init arch_timer_mem_init(struct device_node *np)
 		goto out;
 	}
 
-	arch_timer_detect_rate(base, np);
+	/*
+	 * Try to determine the frequency from the device tree,
+	 * if fail, get the frequency from the CNTFRQ reg of MMIO timer.
+	 */
+	if (!arch_timer_rate &&
+	    of_property_read_u32(np, "clock-frequency", &arch_timer_rate))
+		arch_timer_rate = arch_timer_mem_get_cntfrq(base);
+	if (!arch_timer_rate) {
+		pr_err(FW_BUG "MMIO frequency not available.\n");
+		ret = -EINVAL;
+		goto out;
+	}
+
 	ret = arch_timer_mem_register(base, irq);
 	if (ret)
 		goto out;
@@ -1130,8 +1128,12 @@ static int __init arch_timer_acpi_init(struct acpi_table_header *table)
 		map_generic_timer_interrupt(gtdt->non_secure_el2_interrupt,
 		gtdt->non_secure_el2_flags);
 
-	/* Get the frequency from CNTFRQ */
-	arch_timer_detect_rate(NULL, NULL);
+	/* Get the frequency from the sysreg CNTFRQ */
+	arch_timer_rate = arch_timer_get_cntfrq();
+	if (!arch_timer_rate) {
+		pr_err(FW_BUG "frequency not available.\n");
+		return -EINVAL;
+	}
 
 	arch_timer_uses_ppi = arch_timer_select_ppi();
 	if (!arch_timer_ppi[arch_timer_uses_ppi]) {
-- 
2.9.3

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

* [PATCH v23 03/11] clocksource: arm_arch_timer: refactor arch_timer_needs_probing
  2017-03-31 17:50 ` fu.wei at linaro.org
@ 2017-03-31 17:50   ` fu.wei at linaro.org
  -1 siblings, 0 replies; 66+ messages in thread
From: fu.wei @ 2017-03-31 17:50 UTC (permalink / raw)
  To: rjw, lenb, daniel.lezcano, tglx, marc.zyngier, mark.rutland,
	lorenzo.pieralisi, sudeep.holla, hanjun.guo
  Cc: linux-arm-kernel, linaro-acpi, linux-kernel, linux-acpi,
	rruigrok, harba, cov, timur, graeme.gregory, al.stone, jcm, wei,
	arnd, catalin.marinas, will.deacon, Suravee.Suthikulpanit,
	leo.duran, wim, linux, linux-watchdog, tn, christoffer.dall,
	julien.grall, Fu Wei

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

When booting with DT, it's possible for timer nodes to be probed in any
order. Some common initialisation needs to occur after all nodes have
been probed, and arch_timer_common_init() has code to detect when this
has happened.

This logic is DT-specific, and it would be best to factor it out of the
common code that will be shared with ACPI.

This patch folds this into the existing arch_timer_needs_probing(),
which is renamed to arch_timer_needs_of_probing(), and no longer takes
any arguments. This is only called when using DT, and not when using
ACPI, which will have a deterministic probe order.

Signed-off-by: Fu Wei <fu.wei@linaro.org>
Reviewed-by: Hanjun Guo <hanjun.guo@linaro.org>
[Mark: reword commit message]
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
---
 drivers/clocksource/arm_arch_timer.c | 34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index 1b6a7e6..ed215d9 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -839,15 +839,28 @@ static const struct of_device_id arch_timer_mem_of_match[] __initconst = {
 	{},
 };
 
-static bool __init
-arch_timer_needs_probing(int type, const struct of_device_id *matches)
+static bool __init arch_timer_needs_of_probing(void)
 {
 	struct device_node *dn;
 	bool needs_probing = false;
+	unsigned int mask = ARCH_TIMER_TYPE_CP15 | ARCH_TIMER_TYPE_MEM;
 
-	dn = of_find_matching_node(NULL, matches);
-	if (dn && of_device_is_available(dn) && !(arch_timers_present & type))
+	/* We have two timers, and both device-tree nodes are probed. */
+	if ((arch_timers_present & mask) == mask)
+		return false;
+
+	/*
+	 * Only one type of timer is probed,
+	 * check if we have another type of timer node in device-tree.
+	 */
+	if (arch_timers_present & ARCH_TIMER_TYPE_CP15)
+		dn = of_find_matching_node(NULL, arch_timer_mem_of_match);
+	else
+		dn = of_find_matching_node(NULL, arch_timer_of_match);
+
+	if (dn && of_device_is_available(dn))
 		needs_probing = true;
+
 	of_node_put(dn);
 
 	return needs_probing;
@@ -855,17 +868,8 @@ arch_timer_needs_probing(int type, const struct of_device_id *matches)
 
 static int __init arch_timer_common_init(void)
 {
-	unsigned mask = ARCH_TIMER_TYPE_CP15 | ARCH_TIMER_TYPE_MEM;
-
-	/* Wait until both nodes are probed if we have two timers */
-	if ((arch_timers_present & mask) != mask) {
-		if (arch_timer_needs_probing(ARCH_TIMER_TYPE_MEM,
-					     arch_timer_mem_of_match))
-			return 0;
-		if (arch_timer_needs_probing(ARCH_TIMER_TYPE_CP15,
-					     arch_timer_of_match))
-			return 0;
-	}
+	if (acpi_disabled && arch_timer_needs_of_probing())
+		return 0;
 
 	arch_timer_banner(arch_timers_present);
 	arch_counter_register(arch_timers_present);
-- 
2.9.3


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

* [PATCH v23 03/11] clocksource: arm_arch_timer: refactor arch_timer_needs_probing
@ 2017-03-31 17:50   ` fu.wei at linaro.org
  0 siblings, 0 replies; 66+ messages in thread
From: fu.wei at linaro.org @ 2017-03-31 17:50 UTC (permalink / raw)
  To: linux-arm-kernel

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

When booting with DT, it's possible for timer nodes to be probed in any
order. Some common initialisation needs to occur after all nodes have
been probed, and arch_timer_common_init() has code to detect when this
has happened.

This logic is DT-specific, and it would be best to factor it out of the
common code that will be shared with ACPI.

This patch folds this into the existing arch_timer_needs_probing(),
which is renamed to arch_timer_needs_of_probing(), and no longer takes
any arguments. This is only called when using DT, and not when using
ACPI, which will have a deterministic probe order.

Signed-off-by: Fu Wei <fu.wei@linaro.org>
Reviewed-by: Hanjun Guo <hanjun.guo@linaro.org>
[Mark: reword commit message]
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
---
 drivers/clocksource/arm_arch_timer.c | 34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index 1b6a7e6..ed215d9 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -839,15 +839,28 @@ static const struct of_device_id arch_timer_mem_of_match[] __initconst = {
 	{},
 };
 
-static bool __init
-arch_timer_needs_probing(int type, const struct of_device_id *matches)
+static bool __init arch_timer_needs_of_probing(void)
 {
 	struct device_node *dn;
 	bool needs_probing = false;
+	unsigned int mask = ARCH_TIMER_TYPE_CP15 | ARCH_TIMER_TYPE_MEM;
 
-	dn = of_find_matching_node(NULL, matches);
-	if (dn && of_device_is_available(dn) && !(arch_timers_present & type))
+	/* We have two timers, and both device-tree nodes are probed. */
+	if ((arch_timers_present & mask) == mask)
+		return false;
+
+	/*
+	 * Only one type of timer is probed,
+	 * check if we have another type of timer node in device-tree.
+	 */
+	if (arch_timers_present & ARCH_TIMER_TYPE_CP15)
+		dn = of_find_matching_node(NULL, arch_timer_mem_of_match);
+	else
+		dn = of_find_matching_node(NULL, arch_timer_of_match);
+
+	if (dn && of_device_is_available(dn))
 		needs_probing = true;
+
 	of_node_put(dn);
 
 	return needs_probing;
@@ -855,17 +868,8 @@ arch_timer_needs_probing(int type, const struct of_device_id *matches)
 
 static int __init arch_timer_common_init(void)
 {
-	unsigned mask = ARCH_TIMER_TYPE_CP15 | ARCH_TIMER_TYPE_MEM;
-
-	/* Wait until both nodes are probed if we have two timers */
-	if ((arch_timers_present & mask) != mask) {
-		if (arch_timer_needs_probing(ARCH_TIMER_TYPE_MEM,
-					     arch_timer_mem_of_match))
-			return 0;
-		if (arch_timer_needs_probing(ARCH_TIMER_TYPE_CP15,
-					     arch_timer_of_match))
-			return 0;
-	}
+	if (acpi_disabled && arch_timer_needs_of_probing())
+		return 0;
 
 	arch_timer_banner(arch_timers_present);
 	arch_counter_register(arch_timers_present);
-- 
2.9.3

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

* [PATCH v23 04/11] clocksource: arm_arch_timer: move arch_timer_needs_of_probing into DT init call
  2017-03-31 17:50 ` fu.wei at linaro.org
@ 2017-03-31 17:50   ` fu.wei at linaro.org
  -1 siblings, 0 replies; 66+ messages in thread
From: fu.wei @ 2017-03-31 17:50 UTC (permalink / raw)
  To: rjw, lenb, daniel.lezcano, tglx, marc.zyngier, mark.rutland,
	lorenzo.pieralisi, sudeep.holla, hanjun.guo
  Cc: linux-arm-kernel, linaro-acpi, linux-kernel, linux-acpi,
	rruigrok, harba, cov, timur, graeme.gregory, al.stone, jcm, wei,
	arnd, catalin.marinas, will.deacon, Suravee.Suthikulpanit,
	leo.duran, wim, linux, linux-watchdog, tn, christoffer.dall,
	julien.grall, Fu Wei

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

To cleanly split code paths specific to ACPI or DT at a higher level,
this patch removes arch_timer_init(), folding the relevant
parts of its logic into existing callers.

This patches the way for further rework, and saves a few lines.

Signed-off-by: Fu Wei <fu.wei@linaro.org>
Reviewed-by: Hanjun Guo <hanjun.guo@linaro.org>
[Mark: reword commit message]
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
---
 drivers/clocksource/arm_arch_timer.c | 46 ++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 25 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index ed215d9..9433276 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -868,9 +868,6 @@ static bool __init arch_timer_needs_of_probing(void)
 
 static int __init arch_timer_common_init(void)
 {
-	if (acpi_disabled && arch_timer_needs_of_probing())
-		return 0;
-
 	arch_timer_banner(arch_timers_present);
 	arch_counter_register(arch_timers_present);
 	return arch_timer_arch_init();
@@ -908,26 +905,9 @@ static enum arch_timer_ppi_nr __init arch_timer_select_ppi(void)
 	return ARCH_TIMER_PHYS_SECURE_PPI;
 }
 
-static int __init arch_timer_init(void)
-{
-	int ret;
-
-	ret = arch_timer_register();
-	if (ret)
-		return ret;
-
-	ret = arch_timer_common_init();
-	if (ret)
-		return ret;
-
-	arch_timer_kvm_info.virtual_irq = arch_timer_ppi[ARCH_TIMER_VIRT_PPI];
-
-	return 0;
-}
-
 static int __init arch_timer_of_init(struct device_node *np)
 {
-	int i;
+	int i, ret;
 
 	if (arch_timers_present & ARCH_TIMER_TYPE_CP15) {
 		pr_warn("multiple nodes in dt, skipping\n");
@@ -938,6 +918,8 @@ static int __init arch_timer_of_init(struct device_node *np)
 	for (i = ARCH_TIMER_PHYS_SECURE_PPI; i < ARCH_TIMER_MAX_TIMER_PPI; i++)
 		arch_timer_ppi[i] = irq_of_parse_and_map(np, i);
 
+	arch_timer_kvm_info.virtual_irq = arch_timer_ppi[ARCH_TIMER_VIRT_PPI];
+
 	/*
 	 * Determine the frequency of system counter:
 	 * Try to get the frequency from the device tree.
@@ -983,7 +965,14 @@ static int __init arch_timer_of_init(struct device_node *np)
 	arch_counter_suspend_stop = of_property_read_bool(np,
 							 "arm,no-tick-in-suspend");
 
-	return arch_timer_init();
+	ret = arch_timer_register();
+	if (ret)
+		return ret;
+
+	if (arch_timer_needs_of_probing())
+		return 0;
+
+	return arch_timer_common_init();
 }
 CLOCKSOURCE_OF_DECLARE(armv7_arch_timer, "arm,armv7-timer", arch_timer_of_init);
 CLOCKSOURCE_OF_DECLARE(armv8_arch_timer, "arm,armv8-timer", arch_timer_of_init);
@@ -1076,7 +1065,8 @@ static int __init arch_timer_mem_init(struct device_node *np)
 	if (ret)
 		goto out;
 
-	return arch_timer_common_init();
+	if (!arch_timer_needs_of_probing())
+		ret = arch_timer_common_init();
 out:
 	iounmap(cntctlbase);
 	of_node_put(best_frame);
@@ -1105,6 +1095,7 @@ static int __init map_generic_timer_interrupt(u32 interrupt, u32 flags)
 /* Initialize per-processor generic timer */
 static int __init arch_timer_acpi_init(struct acpi_table_header *table)
 {
+	int ret;
 	struct acpi_table_gtdt *gtdt;
 
 	if (arch_timers_present & ARCH_TIMER_TYPE_CP15) {
@@ -1132,6 +1123,8 @@ static int __init arch_timer_acpi_init(struct acpi_table_header *table)
 		map_generic_timer_interrupt(gtdt->non_secure_el2_interrupt,
 		gtdt->non_secure_el2_flags);
 
+	arch_timer_kvm_info.virtual_irq = arch_timer_ppi[ARCH_TIMER_VIRT_PPI];
+
 	/* Get the frequency from the sysreg CNTFRQ */
 	arch_timer_rate = arch_timer_get_cntfrq();
 	if (!arch_timer_rate) {
@@ -1148,8 +1141,11 @@ static int __init arch_timer_acpi_init(struct acpi_table_header *table)
 	/* Always-on capability */
 	arch_timer_c3stop = !(gtdt->non_secure_el1_flags & ACPI_GTDT_ALWAYS_ON);
 
-	arch_timer_init();
-	return 0;
+	ret = arch_timer_register();
+	if (ret)
+		return ret;
+
+	return arch_timer_common_init();
 }
 CLOCKSOURCE_ACPI_DECLARE(arch_timer, ACPI_SIG_GTDT, arch_timer_acpi_init);
 #endif
-- 
2.9.3

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

* [PATCH v23 04/11] clocksource: arm_arch_timer: move arch_timer_needs_of_probing into DT init call
@ 2017-03-31 17:50   ` fu.wei at linaro.org
  0 siblings, 0 replies; 66+ messages in thread
From: fu.wei at linaro.org @ 2017-03-31 17:50 UTC (permalink / raw)
  To: linux-arm-kernel

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

To cleanly split code paths specific to ACPI or DT at a higher level,
this patch removes arch_timer_init(), folding the relevant
parts of its logic into existing callers.

This patches the way for further rework, and saves a few lines.

Signed-off-by: Fu Wei <fu.wei@linaro.org>
Reviewed-by: Hanjun Guo <hanjun.guo@linaro.org>
[Mark: reword commit message]
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
---
 drivers/clocksource/arm_arch_timer.c | 46 ++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 25 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index ed215d9..9433276 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -868,9 +868,6 @@ static bool __init arch_timer_needs_of_probing(void)
 
 static int __init arch_timer_common_init(void)
 {
-	if (acpi_disabled && arch_timer_needs_of_probing())
-		return 0;
-
 	arch_timer_banner(arch_timers_present);
 	arch_counter_register(arch_timers_present);
 	return arch_timer_arch_init();
@@ -908,26 +905,9 @@ static enum arch_timer_ppi_nr __init arch_timer_select_ppi(void)
 	return ARCH_TIMER_PHYS_SECURE_PPI;
 }
 
-static int __init arch_timer_init(void)
-{
-	int ret;
-
-	ret = arch_timer_register();
-	if (ret)
-		return ret;
-
-	ret = arch_timer_common_init();
-	if (ret)
-		return ret;
-
-	arch_timer_kvm_info.virtual_irq = arch_timer_ppi[ARCH_TIMER_VIRT_PPI];
-
-	return 0;
-}
-
 static int __init arch_timer_of_init(struct device_node *np)
 {
-	int i;
+	int i, ret;
 
 	if (arch_timers_present & ARCH_TIMER_TYPE_CP15) {
 		pr_warn("multiple nodes in dt, skipping\n");
@@ -938,6 +918,8 @@ static int __init arch_timer_of_init(struct device_node *np)
 	for (i = ARCH_TIMER_PHYS_SECURE_PPI; i < ARCH_TIMER_MAX_TIMER_PPI; i++)
 		arch_timer_ppi[i] = irq_of_parse_and_map(np, i);
 
+	arch_timer_kvm_info.virtual_irq = arch_timer_ppi[ARCH_TIMER_VIRT_PPI];
+
 	/*
 	 * Determine the frequency of system counter:
 	 * Try to get the frequency from the device tree.
@@ -983,7 +965,14 @@ static int __init arch_timer_of_init(struct device_node *np)
 	arch_counter_suspend_stop = of_property_read_bool(np,
 							 "arm,no-tick-in-suspend");
 
-	return arch_timer_init();
+	ret = arch_timer_register();
+	if (ret)
+		return ret;
+
+	if (arch_timer_needs_of_probing())
+		return 0;
+
+	return arch_timer_common_init();
 }
 CLOCKSOURCE_OF_DECLARE(armv7_arch_timer, "arm,armv7-timer", arch_timer_of_init);
 CLOCKSOURCE_OF_DECLARE(armv8_arch_timer, "arm,armv8-timer", arch_timer_of_init);
@@ -1076,7 +1065,8 @@ static int __init arch_timer_mem_init(struct device_node *np)
 	if (ret)
 		goto out;
 
-	return arch_timer_common_init();
+	if (!arch_timer_needs_of_probing())
+		ret = arch_timer_common_init();
 out:
 	iounmap(cntctlbase);
 	of_node_put(best_frame);
@@ -1105,6 +1095,7 @@ static int __init map_generic_timer_interrupt(u32 interrupt, u32 flags)
 /* Initialize per-processor generic timer */
 static int __init arch_timer_acpi_init(struct acpi_table_header *table)
 {
+	int ret;
 	struct acpi_table_gtdt *gtdt;
 
 	if (arch_timers_present & ARCH_TIMER_TYPE_CP15) {
@@ -1132,6 +1123,8 @@ static int __init arch_timer_acpi_init(struct acpi_table_header *table)
 		map_generic_timer_interrupt(gtdt->non_secure_el2_interrupt,
 		gtdt->non_secure_el2_flags);
 
+	arch_timer_kvm_info.virtual_irq = arch_timer_ppi[ARCH_TIMER_VIRT_PPI];
+
 	/* Get the frequency from the sysreg CNTFRQ */
 	arch_timer_rate = arch_timer_get_cntfrq();
 	if (!arch_timer_rate) {
@@ -1148,8 +1141,11 @@ static int __init arch_timer_acpi_init(struct acpi_table_header *table)
 	/* Always-on capability */
 	arch_timer_c3stop = !(gtdt->non_secure_el1_flags & ACPI_GTDT_ALWAYS_ON);
 
-	arch_timer_init();
-	return 0;
+	ret = arch_timer_register();
+	if (ret)
+		return ret;
+
+	return arch_timer_common_init();
 }
 CLOCKSOURCE_ACPI_DECLARE(arch_timer, ACPI_SIG_GTDT, arch_timer_acpi_init);
 #endif
-- 
2.9.3

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

* [PATCH v23 05/11] clocksource: arm_arch_timer: add structs to describe MMIO timer
  2017-03-31 17:50 ` fu.wei at linaro.org
@ 2017-03-31 17:50   ` fu.wei at linaro.org
  -1 siblings, 0 replies; 66+ messages in thread
From: fu.wei @ 2017-03-31 17:50 UTC (permalink / raw)
  To: rjw, lenb, daniel.lezcano, tglx, marc.zyngier, mark.rutland,
	lorenzo.pieralisi, sudeep.holla, hanjun.guo
  Cc: linux-arm-kernel, linaro-acpi, linux-kernel, linux-acpi,
	rruigrok, harba, cov, timur, graeme.gregory, al.stone, jcm, wei,
	arnd, catalin.marinas, will.deacon, Suravee.Suthikulpanit,
	leo.duran, wim, linux, linux-watchdog, tn, christoffer.dall,
	julien.grall, Fu Wei

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

In preparation for ACPI GTDT support, this patch adds structs to
describe the MMIO timers indepedent of the firmware interface.

Subsequent patches will use these to split the FW/HW probing logic, so
that the HW probing logic can be shared by ACPI and DT.

[Mark: reword commit message]

Signed-off-by: Fu Wei <fu.wei@linaro.org>
Reviewed-by: Hanjun Guo <hanjun.guo@linaro.org>
---
 include/clocksource/arm_arch_timer.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/include/clocksource/arm_arch_timer.h b/include/clocksource/arm_arch_timer.h
index 4a98c06..cc805b7 100644
--- a/include/clocksource/arm_arch_timer.h
+++ b/include/clocksource/arm_arch_timer.h
@@ -57,6 +57,8 @@ enum arch_timer_spi_nr {
 #define ARCH_TIMER_MEM_PHYS_ACCESS	2
 #define ARCH_TIMER_MEM_VIRT_ACCESS	3
 
+#define ARCH_TIMER_MEM_MAX_FRAMES	8
+
 #define ARCH_TIMER_USR_PCT_ACCESS_EN	(1 << 0) /* physical counter */
 #define ARCH_TIMER_USR_VCT_ACCESS_EN	(1 << 1) /* virtual counter */
 #define ARCH_TIMER_VIRT_EVT_EN		(1 << 2)
@@ -72,6 +74,20 @@ struct arch_timer_kvm_info {
 	int virtual_irq;
 };
 
+struct arch_timer_mem_frame {
+	bool valid;
+	phys_addr_t cntbase;
+	size_t size;
+	int phys_irq;
+	int virt_irq;
+};
+
+struct arch_timer_mem {
+	phys_addr_t cntctlbase;
+	size_t size;
+	struct arch_timer_mem_frame frame[ARCH_TIMER_MEM_MAX_FRAMES];
+};
+
 #ifdef CONFIG_ARM_ARCH_TIMER
 
 extern u32 arch_timer_get_rate(void);
-- 
2.9.3

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

* [PATCH v23 05/11] clocksource: arm_arch_timer: add structs to describe MMIO timer
@ 2017-03-31 17:50   ` fu.wei at linaro.org
  0 siblings, 0 replies; 66+ messages in thread
From: fu.wei at linaro.org @ 2017-03-31 17:50 UTC (permalink / raw)
  To: linux-arm-kernel

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

In preparation for ACPI GTDT support, this patch adds structs to
describe the MMIO timers indepedent of the firmware interface.

Subsequent patches will use these to split the FW/HW probing logic, so
that the HW probing logic can be shared by ACPI and DT.

[Mark: reword commit message]

Signed-off-by: Fu Wei <fu.wei@linaro.org>
Reviewed-by: Hanjun Guo <hanjun.guo@linaro.org>
---
 include/clocksource/arm_arch_timer.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/include/clocksource/arm_arch_timer.h b/include/clocksource/arm_arch_timer.h
index 4a98c06..cc805b7 100644
--- a/include/clocksource/arm_arch_timer.h
+++ b/include/clocksource/arm_arch_timer.h
@@ -57,6 +57,8 @@ enum arch_timer_spi_nr {
 #define ARCH_TIMER_MEM_PHYS_ACCESS	2
 #define ARCH_TIMER_MEM_VIRT_ACCESS	3
 
+#define ARCH_TIMER_MEM_MAX_FRAMES	8
+
 #define ARCH_TIMER_USR_PCT_ACCESS_EN	(1 << 0) /* physical counter */
 #define ARCH_TIMER_USR_VCT_ACCESS_EN	(1 << 1) /* virtual counter */
 #define ARCH_TIMER_VIRT_EVT_EN		(1 << 2)
@@ -72,6 +74,20 @@ struct arch_timer_kvm_info {
 	int virtual_irq;
 };
 
+struct arch_timer_mem_frame {
+	bool valid;
+	phys_addr_t cntbase;
+	size_t size;
+	int phys_irq;
+	int virt_irq;
+};
+
+struct arch_timer_mem {
+	phys_addr_t cntctlbase;
+	size_t size;
+	struct arch_timer_mem_frame frame[ARCH_TIMER_MEM_MAX_FRAMES];
+};
+
 #ifdef CONFIG_ARM_ARCH_TIMER
 
 extern u32 arch_timer_get_rate(void);
-- 
2.9.3

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

* [PATCH v23 06/11] clocksource: arm_arch_timer: refactor MMIO timer probing.
  2017-03-31 17:50 ` fu.wei at linaro.org
@ 2017-03-31 17:51   ` fu.wei at linaro.org
  -1 siblings, 0 replies; 66+ messages in thread
From: fu.wei @ 2017-03-31 17:51 UTC (permalink / raw)
  To: rjw, lenb, daniel.lezcano, tglx, marc.zyngier, mark.rutland,
	lorenzo.pieralisi, sudeep.holla, hanjun.guo
  Cc: linux-arm-kernel, linaro-acpi, linux-kernel, linux-acpi,
	rruigrok, harba, cov, timur, graeme.gregory, al.stone, jcm, wei,
	arnd, catalin.marinas, will.deacon, Suravee.Suthikulpanit,
	leo.duran, wim, linux, linux-watchdog, tn, christoffer.dall,
	julien.grall, Fu Wei

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

Currently the code to probe MMIO architected timers mixes DT parsing with
actual poking of hardware. This makes the code harder than necessary to
understand, and makes it difficult to add support for probing via ACPI.

This patch factors all the DT-specific logic out of arch_timer_mem_init(),
into a new function arch_timer_mem_of_init().
The former pokes the hardware and determines the suitablility of frames
based on a datastructure populated by the latter.

This cleanly separates the two and will make it possible to add probing
using the ACPI GTDT in subsequent patches.

Signed-off-by: Fu Wei <fu.wei@linaro.org>
Reviewed-by: Hanjun Guo <hanjun.guo@linaro.org>
---
 drivers/clocksource/arm_arch_timer.c | 170 +++++++++++++++++++++++++----------
 1 file changed, 122 insertions(+), 48 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index 9433276..4aaebe7 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -977,17 +977,17 @@ static int __init arch_timer_of_init(struct device_node *np)
 CLOCKSOURCE_OF_DECLARE(armv7_arch_timer, "arm,armv7-timer", arch_timer_of_init);
 CLOCKSOURCE_OF_DECLARE(armv8_arch_timer, "arm,armv8-timer", arch_timer_of_init);
 
-static int __init arch_timer_mem_init(struct device_node *np)
+static int __init arch_timer_mem_init(struct arch_timer_mem *timer_mem)
 {
-	struct device_node *frame, *best_frame = NULL;
+	struct arch_timer_mem_frame *best_frame = NULL;
+	u32 cnttidr, arch_timer_mem_freq;
 	void __iomem *cntctlbase, *base;
-	unsigned int irq, ret = -EINVAL;
-	u32 cnttidr;
+	unsigned int irq;
+	int i, ret;
 
-	arch_timers_present |= ARCH_TIMER_TYPE_MEM;
-	cntctlbase = of_iomap(np, 0);
+	cntctlbase = ioremap(timer_mem->cntctlbase, timer_mem->size);
 	if (!cntctlbase) {
-		pr_err("Can't find CNTCTLBase\n");
+		pr_err("Can't map CNTCTLBase.\n");
 		return -ENXIO;
 	}
 
@@ -997,25 +997,20 @@ static int __init arch_timer_mem_init(struct device_node *np)
 	 * Try to find a virtual capable frame. Otherwise fall back to a
 	 * physical capable frame.
 	 */
-	for_each_available_child_of_node(np, frame) {
-		int n;
-		u32 cntacr;
+	for (i = 0; i < ARCH_TIMER_MEM_MAX_FRAMES; i++) {
+		u32 cntacr = CNTACR_RFRQ | CNTACR_RWPT | CNTACR_RPCT |
+			     CNTACR_RWVT | CNTACR_RVOFF | CNTACR_RVCT;
+		struct arch_timer_mem_frame *frame = &timer_mem->frame[i];
 
-		if (of_property_read_u32(frame, "frame-number", &n)) {
-			pr_err("Missing frame-number\n");
-			of_node_put(frame);
-			goto out;
-		}
+		if (!frame->valid)
+			continue;
 
 		/* Try enabling everything, and see what sticks */
-		cntacr = CNTACR_RFRQ | CNTACR_RWPT | CNTACR_RPCT |
-			 CNTACR_RWVT | CNTACR_RVOFF | CNTACR_RVCT;
-		writel_relaxed(cntacr, cntctlbase + CNTACR(n));
-		cntacr = readl_relaxed(cntctlbase + CNTACR(n));
+		writel_relaxed(cntacr, cntctlbase + CNTACR(i));
+		cntacr = readl_relaxed(cntctlbase + CNTACR(i));
 
-		if ((cnttidr & CNTTIDR_VIRT(n)) &&
+		if ((cnttidr & CNTTIDR_VIRT(i)) &&
 		    !(~cntacr & (CNTACR_RWVT | CNTACR_RVCT))) {
-			of_node_put(best_frame);
 			best_frame = frame;
 			arch_timer_mem_use_virtual = true;
 			break;
@@ -1024,56 +1019,135 @@ static int __init arch_timer_mem_init(struct device_node *np)
 		if (~cntacr & (CNTACR_RWPT | CNTACR_RPCT))
 			continue;
 
-		of_node_put(best_frame);
-		best_frame = of_node_get(frame);
+		best_frame = frame;
 	}
+	iounmap(cntctlbase);
 
-	ret= -ENXIO;
-	base = arch_counter_base = of_io_request_and_map(best_frame, 0,
-							 "arch_mem_timer");
-	if (IS_ERR(base)) {
-		pr_err("Can't map frame's registers\n");
-		goto out;
+	if (!best_frame) {
+		pr_err("Can't find frame for register\n");
+		return -EINVAL;
 	}
 
 	if (arch_timer_mem_use_virtual)
-		irq = irq_of_parse_and_map(best_frame, ARCH_TIMER_VIRT_SPI);
+		irq = best_frame->virt_irq;
 	else
-		irq = irq_of_parse_and_map(best_frame, ARCH_TIMER_PHYS_SPI);
+		irq = best_frame->phys_irq;
 
-	ret = -EINVAL;
 	if (!irq) {
 		pr_err("Frame missing %s irq.\n",
 		       arch_timer_mem_use_virtual ? "virt" : "phys");
+		return -EINVAL;
+	}
+
+	if (!request_mem_region(best_frame->cntbase, best_frame->size,
+				"arch_mem_timer"))
+		return -EBUSY;
+
+	base = ioremap(best_frame->cntbase, best_frame->size);
+	if (!base) {
+		pr_err("Can't map frame's registers\n");
+		return -ENXIO;
+	}
+
+	arch_timer_mem_freq = arch_timer_mem_get_cntfrq(base);
+	if (!arch_timer_rate && arch_timer_mem_freq) {
+		arch_timer_rate = arch_timer_mem_freq;
+	} else if (!arch_timer_rate || arch_timer_rate != arch_timer_mem_freq) {
+		pr_err(FW_BUG "invalid MMIO frequency.\n");
+		iounmap(base);
+		return -EINVAL;
+	}
+
+	ret = arch_timer_mem_register(base, irq);
+	if (ret) {
+		iounmap(base);
+		return ret;
+	}
+
+	arch_counter_base = base;
+	arch_timers_present |= ARCH_TIMER_TYPE_MEM;
+
+	return 0;
+}
+
+static int __init arch_timer_mem_of_init(struct device_node *np)
+{
+	struct arch_timer_mem *timer_mem;
+	struct device_node *frame_node;
+	struct resource res;
+	int ret = -EINVAL;
+	int i = 0;
+
+	timer_mem = kzalloc(sizeof(*timer_mem), GFP_KERNEL);
+	if (!timer_mem)
+		return -ENOMEM;
+
+	if (of_address_to_resource(np, 0, &res))
+		goto out;
+	timer_mem->cntctlbase = res.start;
+	timer_mem->size = resource_size(&res);
+
+	for_each_available_child_of_node(np, frame_node) {
+		u32 n;
+		struct arch_timer_mem_frame *frame;
+
+		if (of_property_read_u32(frame_node, "frame-number", &n)) {
+			pr_err(FW_BUG "Missing frame-number.\n");
+			of_node_put(frame_node);
+			goto out;
+		}
+		if (n >= ARCH_TIMER_MEM_MAX_FRAMES) {
+			pr_err(FW_BUG "Wrong frame-number, only 0-%u are permitted.\n",
+			       ARCH_TIMER_MEM_MAX_FRAMES - 1);
+			of_node_put(frame_node);
+			goto out;
+		}
+		frame = &timer_mem->frame[n];
+
+		if (frame->valid) {
+			pr_err(FW_BUG "Duplicated frame-number.\n");
+			of_node_put(frame_node);
+			goto out;
+		}
+
+		if (of_address_to_resource(frame_node, 0, &res)) {
+			of_node_put(frame_node);
+			goto out;
+		}
+		frame->cntbase = res.start;
+		frame->size = resource_size(&res);
+
+		frame->virt_irq = irq_of_parse_and_map(frame_node,
+						       ARCH_TIMER_VIRT_SPI);
+		frame->phys_irq = irq_of_parse_and_map(frame_node,
+						       ARCH_TIMER_PHYS_SPI);
+
+		frame->valid = true;
+		i++;
+	}
+	if (!i) {
+		pr_err(FW_BUG "Missing timer frame.\n");
+		ret = -ENODEV;
 		goto out;
 	}
 
 	/*
-	 * Try to determine the frequency from the device tree,
-	 * if fail, get the frequency from the CNTFRQ reg of MMIO timer.
+	 * Try to get the frequency from the device tree,
+	 * if fail, we will try the CNTFRQ register in arch_timer_mem_init.
 	 */
-	if (!arch_timer_rate &&
-	    of_property_read_u32(np, "clock-frequency", &arch_timer_rate))
-		arch_timer_rate = arch_timer_mem_get_cntfrq(base);
 	if (!arch_timer_rate) {
-		pr_err(FW_BUG "MMIO frequency not available.\n");
-		ret = -EINVAL;
-		goto out;
+		of_property_read_u32(np, "clock-frequency", &arch_timer_rate);
 	}
 
-	ret = arch_timer_mem_register(base, irq);
-	if (ret)
-		goto out;
-
-	if (!arch_timer_needs_of_probing())
+	ret = arch_timer_mem_init(timer_mem);
+	if (!ret && !arch_timer_needs_of_probing())
 		ret = arch_timer_common_init();
 out:
-	iounmap(cntctlbase);
-	of_node_put(best_frame);
+	kfree(timer_mem);
 	return ret;
 }
 CLOCKSOURCE_OF_DECLARE(armv7_arch_timer_mem, "arm,armv7-timer-mem",
-		       arch_timer_mem_init);
+		       arch_timer_mem_of_init);
 
 #ifdef CONFIG_ACPI
 static int __init map_generic_timer_interrupt(u32 interrupt, u32 flags)
-- 
2.9.3


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

* [PATCH v23 06/11] clocksource: arm_arch_timer: refactor MMIO timer probing.
@ 2017-03-31 17:51   ` fu.wei at linaro.org
  0 siblings, 0 replies; 66+ messages in thread
From: fu.wei at linaro.org @ 2017-03-31 17:51 UTC (permalink / raw)
  To: linux-arm-kernel

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

Currently the code to probe MMIO architected timers mixes DT parsing with
actual poking of hardware. This makes the code harder than necessary to
understand, and makes it difficult to add support for probing via ACPI.

This patch factors all the DT-specific logic out of arch_timer_mem_init(),
into a new function arch_timer_mem_of_init().
The former pokes the hardware and determines the suitablility of frames
based on a datastructure populated by the latter.

This cleanly separates the two and will make it possible to add probing
using the ACPI GTDT in subsequent patches.

Signed-off-by: Fu Wei <fu.wei@linaro.org>
Reviewed-by: Hanjun Guo <hanjun.guo@linaro.org>
---
 drivers/clocksource/arm_arch_timer.c | 170 +++++++++++++++++++++++++----------
 1 file changed, 122 insertions(+), 48 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index 9433276..4aaebe7 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -977,17 +977,17 @@ static int __init arch_timer_of_init(struct device_node *np)
 CLOCKSOURCE_OF_DECLARE(armv7_arch_timer, "arm,armv7-timer", arch_timer_of_init);
 CLOCKSOURCE_OF_DECLARE(armv8_arch_timer, "arm,armv8-timer", arch_timer_of_init);
 
-static int __init arch_timer_mem_init(struct device_node *np)
+static int __init arch_timer_mem_init(struct arch_timer_mem *timer_mem)
 {
-	struct device_node *frame, *best_frame = NULL;
+	struct arch_timer_mem_frame *best_frame = NULL;
+	u32 cnttidr, arch_timer_mem_freq;
 	void __iomem *cntctlbase, *base;
-	unsigned int irq, ret = -EINVAL;
-	u32 cnttidr;
+	unsigned int irq;
+	int i, ret;
 
-	arch_timers_present |= ARCH_TIMER_TYPE_MEM;
-	cntctlbase = of_iomap(np, 0);
+	cntctlbase = ioremap(timer_mem->cntctlbase, timer_mem->size);
 	if (!cntctlbase) {
-		pr_err("Can't find CNTCTLBase\n");
+		pr_err("Can't map CNTCTLBase.\n");
 		return -ENXIO;
 	}
 
@@ -997,25 +997,20 @@ static int __init arch_timer_mem_init(struct device_node *np)
 	 * Try to find a virtual capable frame. Otherwise fall back to a
 	 * physical capable frame.
 	 */
-	for_each_available_child_of_node(np, frame) {
-		int n;
-		u32 cntacr;
+	for (i = 0; i < ARCH_TIMER_MEM_MAX_FRAMES; i++) {
+		u32 cntacr = CNTACR_RFRQ | CNTACR_RWPT | CNTACR_RPCT |
+			     CNTACR_RWVT | CNTACR_RVOFF | CNTACR_RVCT;
+		struct arch_timer_mem_frame *frame = &timer_mem->frame[i];
 
-		if (of_property_read_u32(frame, "frame-number", &n)) {
-			pr_err("Missing frame-number\n");
-			of_node_put(frame);
-			goto out;
-		}
+		if (!frame->valid)
+			continue;
 
 		/* Try enabling everything, and see what sticks */
-		cntacr = CNTACR_RFRQ | CNTACR_RWPT | CNTACR_RPCT |
-			 CNTACR_RWVT | CNTACR_RVOFF | CNTACR_RVCT;
-		writel_relaxed(cntacr, cntctlbase + CNTACR(n));
-		cntacr = readl_relaxed(cntctlbase + CNTACR(n));
+		writel_relaxed(cntacr, cntctlbase + CNTACR(i));
+		cntacr = readl_relaxed(cntctlbase + CNTACR(i));
 
-		if ((cnttidr & CNTTIDR_VIRT(n)) &&
+		if ((cnttidr & CNTTIDR_VIRT(i)) &&
 		    !(~cntacr & (CNTACR_RWVT | CNTACR_RVCT))) {
-			of_node_put(best_frame);
 			best_frame = frame;
 			arch_timer_mem_use_virtual = true;
 			break;
@@ -1024,56 +1019,135 @@ static int __init arch_timer_mem_init(struct device_node *np)
 		if (~cntacr & (CNTACR_RWPT | CNTACR_RPCT))
 			continue;
 
-		of_node_put(best_frame);
-		best_frame = of_node_get(frame);
+		best_frame = frame;
 	}
+	iounmap(cntctlbase);
 
-	ret= -ENXIO;
-	base = arch_counter_base = of_io_request_and_map(best_frame, 0,
-							 "arch_mem_timer");
-	if (IS_ERR(base)) {
-		pr_err("Can't map frame's registers\n");
-		goto out;
+	if (!best_frame) {
+		pr_err("Can't find frame for register\n");
+		return -EINVAL;
 	}
 
 	if (arch_timer_mem_use_virtual)
-		irq = irq_of_parse_and_map(best_frame, ARCH_TIMER_VIRT_SPI);
+		irq = best_frame->virt_irq;
 	else
-		irq = irq_of_parse_and_map(best_frame, ARCH_TIMER_PHYS_SPI);
+		irq = best_frame->phys_irq;
 
-	ret = -EINVAL;
 	if (!irq) {
 		pr_err("Frame missing %s irq.\n",
 		       arch_timer_mem_use_virtual ? "virt" : "phys");
+		return -EINVAL;
+	}
+
+	if (!request_mem_region(best_frame->cntbase, best_frame->size,
+				"arch_mem_timer"))
+		return -EBUSY;
+
+	base = ioremap(best_frame->cntbase, best_frame->size);
+	if (!base) {
+		pr_err("Can't map frame's registers\n");
+		return -ENXIO;
+	}
+
+	arch_timer_mem_freq = arch_timer_mem_get_cntfrq(base);
+	if (!arch_timer_rate && arch_timer_mem_freq) {
+		arch_timer_rate = arch_timer_mem_freq;
+	} else if (!arch_timer_rate || arch_timer_rate != arch_timer_mem_freq) {
+		pr_err(FW_BUG "invalid MMIO frequency.\n");
+		iounmap(base);
+		return -EINVAL;
+	}
+
+	ret = arch_timer_mem_register(base, irq);
+	if (ret) {
+		iounmap(base);
+		return ret;
+	}
+
+	arch_counter_base = base;
+	arch_timers_present |= ARCH_TIMER_TYPE_MEM;
+
+	return 0;
+}
+
+static int __init arch_timer_mem_of_init(struct device_node *np)
+{
+	struct arch_timer_mem *timer_mem;
+	struct device_node *frame_node;
+	struct resource res;
+	int ret = -EINVAL;
+	int i = 0;
+
+	timer_mem = kzalloc(sizeof(*timer_mem), GFP_KERNEL);
+	if (!timer_mem)
+		return -ENOMEM;
+
+	if (of_address_to_resource(np, 0, &res))
+		goto out;
+	timer_mem->cntctlbase = res.start;
+	timer_mem->size = resource_size(&res);
+
+	for_each_available_child_of_node(np, frame_node) {
+		u32 n;
+		struct arch_timer_mem_frame *frame;
+
+		if (of_property_read_u32(frame_node, "frame-number", &n)) {
+			pr_err(FW_BUG "Missing frame-number.\n");
+			of_node_put(frame_node);
+			goto out;
+		}
+		if (n >= ARCH_TIMER_MEM_MAX_FRAMES) {
+			pr_err(FW_BUG "Wrong frame-number, only 0-%u are permitted.\n",
+			       ARCH_TIMER_MEM_MAX_FRAMES - 1);
+			of_node_put(frame_node);
+			goto out;
+		}
+		frame = &timer_mem->frame[n];
+
+		if (frame->valid) {
+			pr_err(FW_BUG "Duplicated frame-number.\n");
+			of_node_put(frame_node);
+			goto out;
+		}
+
+		if (of_address_to_resource(frame_node, 0, &res)) {
+			of_node_put(frame_node);
+			goto out;
+		}
+		frame->cntbase = res.start;
+		frame->size = resource_size(&res);
+
+		frame->virt_irq = irq_of_parse_and_map(frame_node,
+						       ARCH_TIMER_VIRT_SPI);
+		frame->phys_irq = irq_of_parse_and_map(frame_node,
+						       ARCH_TIMER_PHYS_SPI);
+
+		frame->valid = true;
+		i++;
+	}
+	if (!i) {
+		pr_err(FW_BUG "Missing timer frame.\n");
+		ret = -ENODEV;
 		goto out;
 	}
 
 	/*
-	 * Try to determine the frequency from the device tree,
-	 * if fail, get the frequency from the CNTFRQ reg of MMIO timer.
+	 * Try to get the frequency from the device tree,
+	 * if fail, we will try the CNTFRQ register in arch_timer_mem_init.
 	 */
-	if (!arch_timer_rate &&
-	    of_property_read_u32(np, "clock-frequency", &arch_timer_rate))
-		arch_timer_rate = arch_timer_mem_get_cntfrq(base);
 	if (!arch_timer_rate) {
-		pr_err(FW_BUG "MMIO frequency not available.\n");
-		ret = -EINVAL;
-		goto out;
+		of_property_read_u32(np, "clock-frequency", &arch_timer_rate);
 	}
 
-	ret = arch_timer_mem_register(base, irq);
-	if (ret)
-		goto out;
-
-	if (!arch_timer_needs_of_probing())
+	ret = arch_timer_mem_init(timer_mem);
+	if (!ret && !arch_timer_needs_of_probing())
 		ret = arch_timer_common_init();
 out:
-	iounmap(cntctlbase);
-	of_node_put(best_frame);
+	kfree(timer_mem);
 	return ret;
 }
 CLOCKSOURCE_OF_DECLARE(armv7_arch_timer_mem, "arm,armv7-timer-mem",
-		       arch_timer_mem_init);
+		       arch_timer_mem_of_init);
 
 #ifdef CONFIG_ACPI
 static int __init map_generic_timer_interrupt(u32 interrupt, u32 flags)
-- 
2.9.3

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

* [PATCH v23 07/11] acpi/arm64: Add GTDT table parse driver
  2017-03-31 17:50 ` fu.wei at linaro.org
@ 2017-03-31 17:51   ` fu.wei at linaro.org
  -1 siblings, 0 replies; 66+ messages in thread
From: fu.wei @ 2017-03-31 17:51 UTC (permalink / raw)
  To: rjw, lenb, daniel.lezcano, tglx, marc.zyngier, mark.rutland,
	lorenzo.pieralisi, sudeep.holla, hanjun.guo
  Cc: linux-arm-kernel, linaro-acpi, linux-kernel, linux-acpi,
	rruigrok, harba, cov, timur, graeme.gregory, al.stone, jcm, wei,
	arnd, catalin.marinas, will.deacon, Suravee.Suthikulpanit,
	leo.duran, wim, linux, linux-watchdog, tn, christoffer.dall,
	julien.grall, Fu Wei

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

This patch adds support for parsing arch timer info in GTDT,
provides some kernel APIs to parse all the PPIs and
always-on info in GTDT and export them.

By this driver, we can simplify arm_arch_timer drivers, and
separate the ACPI GTDT knowledge from it.

Signed-off-by: Fu Wei <fu.wei@linaro.org>
Signed-off-by: Hanjun Guo <hanjun.guo@linaro.org>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
Reviewed-by: Hanjun Guo <hanjun.guo@linaro.org>
Tested-by: Hanjun Guo <hanjun.guo@linaro.org>
Acked-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
---
 arch/arm64/Kconfig          |   1 +
 drivers/acpi/arm64/Kconfig  |   3 +
 drivers/acpi/arm64/Makefile |   1 +
 drivers/acpi/arm64/gtdt.c   | 157 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/acpi.h        |   6 ++
 5 files changed, 168 insertions(+)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 3741859..7e2baec 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -2,6 +2,7 @@ config ARM64
 	def_bool y
 	select ACPI_CCA_REQUIRED if ACPI
 	select ACPI_GENERIC_GSI if ACPI
+	select ACPI_GTDT if ACPI
 	select ACPI_REDUCED_HARDWARE_ONLY if ACPI
 	select ACPI_MCFG if ACPI
 	select ACPI_SPCR_TABLE if ACPI
diff --git a/drivers/acpi/arm64/Kconfig b/drivers/acpi/arm64/Kconfig
index 4616da4..5a6f80f 100644
--- a/drivers/acpi/arm64/Kconfig
+++ b/drivers/acpi/arm64/Kconfig
@@ -4,3 +4,6 @@
 
 config ACPI_IORT
 	bool
+
+config ACPI_GTDT
+	bool
diff --git a/drivers/acpi/arm64/Makefile b/drivers/acpi/arm64/Makefile
index 72331f2..1017def 100644
--- a/drivers/acpi/arm64/Makefile
+++ b/drivers/acpi/arm64/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_ACPI_IORT) 	+= iort.o
+obj-$(CONFIG_ACPI_GTDT) 	+= gtdt.o
diff --git a/drivers/acpi/arm64/gtdt.c b/drivers/acpi/arm64/gtdt.c
new file mode 100644
index 0000000..3d95af8
--- /dev/null
+++ b/drivers/acpi/arm64/gtdt.c
@@ -0,0 +1,157 @@
+/*
+ * ARM Specific GTDT table Support
+ *
+ * Copyright (C) 2016, Linaro Ltd.
+ * Author: Daniel Lezcano <daniel.lezcano@linaro.org>
+ *         Fu Wei <fu.wei@linaro.org>
+ *         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.
+ */
+
+#include <linux/acpi.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+
+#include <clocksource/arm_arch_timer.h>
+
+#undef pr_fmt
+#define pr_fmt(fmt) "ACPI GTDT: " fmt
+
+/**
+ * struct acpi_gtdt_descriptor - Store the key info of GTDT for all functions
+ * @gtdt:	The pointer to the struct acpi_table_gtdt of GTDT table.
+ * @gtdt_end:	The pointer to the end of GTDT table.
+ * @platform_timer:	The pointer to the start of Platform Timer Structure
+ *
+ * The struct store the key info of GTDT table, it should be initialized by
+ * acpi_gtdt_init.
+ */
+struct acpi_gtdt_descriptor {
+	struct acpi_table_gtdt *gtdt;
+	void *gtdt_end;
+	void *platform_timer;
+};
+
+static struct acpi_gtdt_descriptor acpi_gtdt_desc __initdata;
+
+static int __init map_gt_gsi(u32 interrupt, u32 flags)
+{
+	int trigger, polarity;
+
+	trigger = (flags & ACPI_GTDT_INTERRUPT_MODE) ? ACPI_EDGE_SENSITIVE
+			: ACPI_LEVEL_SENSITIVE;
+
+	polarity = (flags & ACPI_GTDT_INTERRUPT_POLARITY) ? ACPI_ACTIVE_LOW
+			: ACPI_ACTIVE_HIGH;
+
+	return acpi_register_gsi(NULL, interrupt, trigger, polarity);
+}
+
+/**
+ * acpi_gtdt_map_ppi() - Map the PPIs of per-cpu arch_timer.
+ * @type:	the type of PPI.
+ *
+ * Note: Secure state is not managed by the kernel on ARM64 systems.
+ * So we only handle the non-secure timer PPIs,
+ * ARCH_TIMER_PHYS_SECURE_PPI is treated as invalid type.
+ *
+ * Return: the mapped PPI value, 0 if error.
+ */
+int __init acpi_gtdt_map_ppi(int type)
+{
+	struct acpi_table_gtdt *gtdt = acpi_gtdt_desc.gtdt;
+
+	switch (type) {
+	case ARCH_TIMER_PHYS_NONSECURE_PPI:
+		return map_gt_gsi(gtdt->non_secure_el1_interrupt,
+				  gtdt->non_secure_el1_flags);
+	case ARCH_TIMER_VIRT_PPI:
+		return map_gt_gsi(gtdt->virtual_timer_interrupt,
+				  gtdt->virtual_timer_flags);
+
+	case ARCH_TIMER_HYP_PPI:
+		return map_gt_gsi(gtdt->non_secure_el2_interrupt,
+				  gtdt->non_secure_el2_flags);
+	default:
+		pr_err("Failed to map timer interrupt: invalid type.\n");
+	}
+
+	return 0;
+}
+
+/**
+ * acpi_gtdt_c3stop() - Got c3stop info from GTDT according to the type of PPI.
+ * @type:	the type of PPI.
+ *
+ * Return: true if the timer HW state is lost when a CPU enters an idle state,
+ * false otherwise
+ */
+bool __init acpi_gtdt_c3stop(int type)
+{
+	struct acpi_table_gtdt *gtdt = acpi_gtdt_desc.gtdt;
+
+	switch (type) {
+	case ARCH_TIMER_PHYS_NONSECURE_PPI:
+		return !(gtdt->non_secure_el1_flags & ACPI_GTDT_ALWAYS_ON);
+
+	case ARCH_TIMER_VIRT_PPI:
+		return !(gtdt->virtual_timer_flags & ACPI_GTDT_ALWAYS_ON);
+
+	case ARCH_TIMER_HYP_PPI:
+		return !(gtdt->non_secure_el2_flags & ACPI_GTDT_ALWAYS_ON);
+
+	default:
+		pr_err("Failed to get c3stop info: invalid type.\n");
+	}
+
+	return false;
+}
+
+/**
+ * acpi_gtdt_init() - Get the info of GTDT table to prepare for further init.
+ * @table:			The pointer to GTDT table.
+ * @platform_timer_count:	It points to a integer variable which is used
+ *				for storing the number of platform timers.
+ *				This pointer could be NULL, if the caller
+ *				doesn't need this info.
+ *
+ * Return: 0 if success, -EINVAL if error.
+ */
+int __init acpi_gtdt_init(struct acpi_table_header *table,
+			  int *platform_timer_count)
+{
+	void *platform_timer;
+	struct acpi_table_gtdt *gtdt;
+
+	gtdt = container_of(table, struct acpi_table_gtdt, header);
+	acpi_gtdt_desc.gtdt = gtdt;
+	acpi_gtdt_desc.gtdt_end = (void *)table + table->length;
+	acpi_gtdt_desc.platform_timer = NULL;
+	if (platform_timer_count)
+		*platform_timer_count = 0;
+
+	if (table->revision < 2) {
+		pr_warn("Revision:%d doesn't support Platform Timers.\n",
+			table->revision);
+		return 0;
+	}
+
+	if (!gtdt->platform_timer_count) {
+		pr_debug("No Platform Timer.\n");
+		return 0;
+	}
+
+	platform_timer = (void *)gtdt + gtdt->platform_timer_offset;
+	if (platform_timer < (void *)table + sizeof(struct acpi_table_gtdt)) {
+		pr_err(FW_BUG "invalid timer data.\n");
+		return -EINVAL;
+	}
+	acpi_gtdt_desc.platform_timer = platform_timer;
+	if (platform_timer_count)
+		*platform_timer_count = gtdt->platform_timer_count;
+
+	return 0;
+}
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 9b05886..4b5c146 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -595,6 +595,12 @@ enum acpi_reconfig_event  {
 int acpi_reconfig_notifier_register(struct notifier_block *nb);
 int acpi_reconfig_notifier_unregister(struct notifier_block *nb);
 
+#ifdef CONFIG_ACPI_GTDT
+int acpi_gtdt_init(struct acpi_table_header *table, int *platform_timer_count);
+int acpi_gtdt_map_ppi(int type);
+bool acpi_gtdt_c3stop(int type);
+#endif
+
 #else	/* !CONFIG_ACPI */
 
 #define acpi_disabled 1
-- 
2.9.3

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

* [PATCH v23 07/11] acpi/arm64: Add GTDT table parse driver
@ 2017-03-31 17:51   ` fu.wei at linaro.org
  0 siblings, 0 replies; 66+ messages in thread
From: fu.wei at linaro.org @ 2017-03-31 17:51 UTC (permalink / raw)
  To: linux-arm-kernel

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

This patch adds support for parsing arch timer info in GTDT,
provides some kernel APIs to parse all the PPIs and
always-on info in GTDT and export them.

By this driver, we can simplify arm_arch_timer drivers, and
separate the ACPI GTDT knowledge from it.

Signed-off-by: Fu Wei <fu.wei@linaro.org>
Signed-off-by: Hanjun Guo <hanjun.guo@linaro.org>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
Reviewed-by: Hanjun Guo <hanjun.guo@linaro.org>
Tested-by: Hanjun Guo <hanjun.guo@linaro.org>
Acked-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
---
 arch/arm64/Kconfig          |   1 +
 drivers/acpi/arm64/Kconfig  |   3 +
 drivers/acpi/arm64/Makefile |   1 +
 drivers/acpi/arm64/gtdt.c   | 157 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/acpi.h        |   6 ++
 5 files changed, 168 insertions(+)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 3741859..7e2baec 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -2,6 +2,7 @@ config ARM64
 	def_bool y
 	select ACPI_CCA_REQUIRED if ACPI
 	select ACPI_GENERIC_GSI if ACPI
+	select ACPI_GTDT if ACPI
 	select ACPI_REDUCED_HARDWARE_ONLY if ACPI
 	select ACPI_MCFG if ACPI
 	select ACPI_SPCR_TABLE if ACPI
diff --git a/drivers/acpi/arm64/Kconfig b/drivers/acpi/arm64/Kconfig
index 4616da4..5a6f80f 100644
--- a/drivers/acpi/arm64/Kconfig
+++ b/drivers/acpi/arm64/Kconfig
@@ -4,3 +4,6 @@
 
 config ACPI_IORT
 	bool
+
+config ACPI_GTDT
+	bool
diff --git a/drivers/acpi/arm64/Makefile b/drivers/acpi/arm64/Makefile
index 72331f2..1017def 100644
--- a/drivers/acpi/arm64/Makefile
+++ b/drivers/acpi/arm64/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_ACPI_IORT) 	+= iort.o
+obj-$(CONFIG_ACPI_GTDT) 	+= gtdt.o
diff --git a/drivers/acpi/arm64/gtdt.c b/drivers/acpi/arm64/gtdt.c
new file mode 100644
index 0000000..3d95af8
--- /dev/null
+++ b/drivers/acpi/arm64/gtdt.c
@@ -0,0 +1,157 @@
+/*
+ * ARM Specific GTDT table Support
+ *
+ * Copyright (C) 2016, Linaro Ltd.
+ * Author: Daniel Lezcano <daniel.lezcano@linaro.org>
+ *         Fu Wei <fu.wei@linaro.org>
+ *         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.
+ */
+
+#include <linux/acpi.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+
+#include <clocksource/arm_arch_timer.h>
+
+#undef pr_fmt
+#define pr_fmt(fmt) "ACPI GTDT: " fmt
+
+/**
+ * struct acpi_gtdt_descriptor - Store the key info of GTDT for all functions
+ * @gtdt:	The pointer to the struct acpi_table_gtdt of GTDT table.
+ * @gtdt_end:	The pointer to the end of GTDT table.
+ * @platform_timer:	The pointer to the start of Platform Timer Structure
+ *
+ * The struct store the key info of GTDT table, it should be initialized by
+ * acpi_gtdt_init.
+ */
+struct acpi_gtdt_descriptor {
+	struct acpi_table_gtdt *gtdt;
+	void *gtdt_end;
+	void *platform_timer;
+};
+
+static struct acpi_gtdt_descriptor acpi_gtdt_desc __initdata;
+
+static int __init map_gt_gsi(u32 interrupt, u32 flags)
+{
+	int trigger, polarity;
+
+	trigger = (flags & ACPI_GTDT_INTERRUPT_MODE) ? ACPI_EDGE_SENSITIVE
+			: ACPI_LEVEL_SENSITIVE;
+
+	polarity = (flags & ACPI_GTDT_INTERRUPT_POLARITY) ? ACPI_ACTIVE_LOW
+			: ACPI_ACTIVE_HIGH;
+
+	return acpi_register_gsi(NULL, interrupt, trigger, polarity);
+}
+
+/**
+ * acpi_gtdt_map_ppi() - Map the PPIs of per-cpu arch_timer.
+ * @type:	the type of PPI.
+ *
+ * Note: Secure state is not managed by the kernel on ARM64 systems.
+ * So we only handle the non-secure timer PPIs,
+ * ARCH_TIMER_PHYS_SECURE_PPI is treated as invalid type.
+ *
+ * Return: the mapped PPI value, 0 if error.
+ */
+int __init acpi_gtdt_map_ppi(int type)
+{
+	struct acpi_table_gtdt *gtdt = acpi_gtdt_desc.gtdt;
+
+	switch (type) {
+	case ARCH_TIMER_PHYS_NONSECURE_PPI:
+		return map_gt_gsi(gtdt->non_secure_el1_interrupt,
+				  gtdt->non_secure_el1_flags);
+	case ARCH_TIMER_VIRT_PPI:
+		return map_gt_gsi(gtdt->virtual_timer_interrupt,
+				  gtdt->virtual_timer_flags);
+
+	case ARCH_TIMER_HYP_PPI:
+		return map_gt_gsi(gtdt->non_secure_el2_interrupt,
+				  gtdt->non_secure_el2_flags);
+	default:
+		pr_err("Failed to map timer interrupt: invalid type.\n");
+	}
+
+	return 0;
+}
+
+/**
+ * acpi_gtdt_c3stop() - Got c3stop info from GTDT according to the type of PPI.
+ * @type:	the type of PPI.
+ *
+ * Return: true if the timer HW state is lost when a CPU enters an idle state,
+ * false otherwise
+ */
+bool __init acpi_gtdt_c3stop(int type)
+{
+	struct acpi_table_gtdt *gtdt = acpi_gtdt_desc.gtdt;
+
+	switch (type) {
+	case ARCH_TIMER_PHYS_NONSECURE_PPI:
+		return !(gtdt->non_secure_el1_flags & ACPI_GTDT_ALWAYS_ON);
+
+	case ARCH_TIMER_VIRT_PPI:
+		return !(gtdt->virtual_timer_flags & ACPI_GTDT_ALWAYS_ON);
+
+	case ARCH_TIMER_HYP_PPI:
+		return !(gtdt->non_secure_el2_flags & ACPI_GTDT_ALWAYS_ON);
+
+	default:
+		pr_err("Failed to get c3stop info: invalid type.\n");
+	}
+
+	return false;
+}
+
+/**
+ * acpi_gtdt_init() - Get the info of GTDT table to prepare for further init.
+ * @table:			The pointer to GTDT table.
+ * @platform_timer_count:	It points to a integer variable which is used
+ *				for storing the number of platform timers.
+ *				This pointer could be NULL, if the caller
+ *				doesn't need this info.
+ *
+ * Return: 0 if success, -EINVAL if error.
+ */
+int __init acpi_gtdt_init(struct acpi_table_header *table,
+			  int *platform_timer_count)
+{
+	void *platform_timer;
+	struct acpi_table_gtdt *gtdt;
+
+	gtdt = container_of(table, struct acpi_table_gtdt, header);
+	acpi_gtdt_desc.gtdt = gtdt;
+	acpi_gtdt_desc.gtdt_end = (void *)table + table->length;
+	acpi_gtdt_desc.platform_timer = NULL;
+	if (platform_timer_count)
+		*platform_timer_count = 0;
+
+	if (table->revision < 2) {
+		pr_warn("Revision:%d doesn't support Platform Timers.\n",
+			table->revision);
+		return 0;
+	}
+
+	if (!gtdt->platform_timer_count) {
+		pr_debug("No Platform Timer.\n");
+		return 0;
+	}
+
+	platform_timer = (void *)gtdt + gtdt->platform_timer_offset;
+	if (platform_timer < (void *)table + sizeof(struct acpi_table_gtdt)) {
+		pr_err(FW_BUG "invalid timer data.\n");
+		return -EINVAL;
+	}
+	acpi_gtdt_desc.platform_timer = platform_timer;
+	if (platform_timer_count)
+		*platform_timer_count = gtdt->platform_timer_count;
+
+	return 0;
+}
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 9b05886..4b5c146 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -595,6 +595,12 @@ enum acpi_reconfig_event  {
 int acpi_reconfig_notifier_register(struct notifier_block *nb);
 int acpi_reconfig_notifier_unregister(struct notifier_block *nb);
 
+#ifdef CONFIG_ACPI_GTDT
+int acpi_gtdt_init(struct acpi_table_header *table, int *platform_timer_count);
+int acpi_gtdt_map_ppi(int type);
+bool acpi_gtdt_c3stop(int type);
+#endif
+
 #else	/* !CONFIG_ACPI */
 
 #define acpi_disabled 1
-- 
2.9.3

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

* [PATCH v23 08/11] clocksource: arm_arch_timer: simplify ACPI support code.
  2017-03-31 17:50 ` fu.wei at linaro.org
@ 2017-03-31 17:51   ` fu.wei at linaro.org
  -1 siblings, 0 replies; 66+ messages in thread
From: fu.wei @ 2017-03-31 17:51 UTC (permalink / raw)
  To: rjw, lenb, daniel.lezcano, tglx, marc.zyngier, mark.rutland,
	lorenzo.pieralisi, sudeep.holla, hanjun.guo
  Cc: linux-arm-kernel, linaro-acpi, linux-kernel, linux-acpi,
	rruigrok, harba, cov, timur, graeme.gregory, al.stone, jcm, wei,
	arnd, catalin.marinas, will.deacon, Suravee.Suthikulpanit,
	leo.duran, wim, linux, linux-watchdog, tn, christoffer.dall,
	julien.grall, Fu Wei

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

The patch update arm_arch_timer driver to use the function
provided by the new GTDT driver of ACPI.
By this way, arm_arch_timer.c can be simplified, and separate
all the ACPI GTDT knowledge from this timer driver.

Signed-off-by: Fu Wei <fu.wei@linaro.org>
Signed-off-by: Hanjun Guo <hanjun.guo@linaro.org>
Tested-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
Reviewed-by: Hanjun Guo <hanjun.guo@linaro.org>
Tested-by: Hanjun Guo <hanjun.guo@linaro.org>
---
 drivers/clocksource/arm_arch_timer.c | 54 ++++++++++++------------------------
 1 file changed, 17 insertions(+), 37 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index 4aaebe7..415e30a 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -1149,63 +1149,36 @@ static int __init arch_timer_mem_of_init(struct device_node *np)
 CLOCKSOURCE_OF_DECLARE(armv7_arch_timer_mem, "arm,armv7-timer-mem",
 		       arch_timer_mem_of_init);
 
-#ifdef CONFIG_ACPI
-static int __init map_generic_timer_interrupt(u32 interrupt, u32 flags)
-{
-	int trigger, polarity;
-
-	if (!interrupt)
-		return 0;
-
-	trigger = (flags & ACPI_GTDT_INTERRUPT_MODE) ? ACPI_EDGE_SENSITIVE
-			: ACPI_LEVEL_SENSITIVE;
-
-	polarity = (flags & ACPI_GTDT_INTERRUPT_POLARITY) ? ACPI_ACTIVE_LOW
-			: ACPI_ACTIVE_HIGH;
-
-	return acpi_register_gsi(NULL, interrupt, trigger, polarity);
-}
-
+#ifdef CONFIG_ACPI_GTDT
 /* Initialize per-processor generic timer */
 static int __init arch_timer_acpi_init(struct acpi_table_header *table)
 {
 	int ret;
-	struct acpi_table_gtdt *gtdt;
 
 	if (arch_timers_present & ARCH_TIMER_TYPE_CP15) {
 		pr_warn("already initialized, skipping\n");
 		return -EINVAL;
 	}
 
-	gtdt = container_of(table, struct acpi_table_gtdt, header);
-
 	arch_timers_present |= ARCH_TIMER_TYPE_CP15;
 
-	arch_timer_ppi[ARCH_TIMER_PHYS_SECURE_PPI] =
-		map_generic_timer_interrupt(gtdt->secure_el1_interrupt,
-		gtdt->secure_el1_flags);
+	ret = acpi_gtdt_init(table, NULL);
+	if (ret) {
+		pr_err("Failed to init GTDT table.\n");
+		return ret;
+	}
 
 	arch_timer_ppi[ARCH_TIMER_PHYS_NONSECURE_PPI] =
-		map_generic_timer_interrupt(gtdt->non_secure_el1_interrupt,
-		gtdt->non_secure_el1_flags);
+		acpi_gtdt_map_ppi(ARCH_TIMER_PHYS_NONSECURE_PPI);
 
 	arch_timer_ppi[ARCH_TIMER_VIRT_PPI] =
-		map_generic_timer_interrupt(gtdt->virtual_timer_interrupt,
-		gtdt->virtual_timer_flags);
+		acpi_gtdt_map_ppi(ARCH_TIMER_VIRT_PPI);
 
 	arch_timer_ppi[ARCH_TIMER_HYP_PPI] =
-		map_generic_timer_interrupt(gtdt->non_secure_el2_interrupt,
-		gtdt->non_secure_el2_flags);
+		acpi_gtdt_map_ppi(ARCH_TIMER_HYP_PPI);
 
 	arch_timer_kvm_info.virtual_irq = arch_timer_ppi[ARCH_TIMER_VIRT_PPI];
 
-	/* Get the frequency from the sysreg CNTFRQ */
-	arch_timer_rate = arch_timer_get_cntfrq();
-	if (!arch_timer_rate) {
-		pr_err(FW_BUG "frequency not available.\n");
-		return -EINVAL;
-	}
-
 	arch_timer_uses_ppi = arch_timer_select_ppi();
 	if (!arch_timer_ppi[arch_timer_uses_ppi]) {
 		pr_err("No interrupt available, giving up\n");
@@ -1213,7 +1186,14 @@ static int __init arch_timer_acpi_init(struct acpi_table_header *table)
 	}
 
 	/* Always-on capability */
-	arch_timer_c3stop = !(gtdt->non_secure_el1_flags & ACPI_GTDT_ALWAYS_ON);
+	arch_timer_c3stop = acpi_gtdt_c3stop(arch_timer_uses_ppi);
+
+	/* Get the frequency from the sysreg CNTFRQ */
+	arch_timer_rate = arch_timer_get_cntfrq();
+	if (!arch_timer_rate) {
+		pr_err(FW_BUG "frequency not available.\n");
+		return -EINVAL;
+	}
 
 	ret = arch_timer_register();
 	if (ret)
-- 
2.9.3

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

* [PATCH v23 08/11] clocksource: arm_arch_timer: simplify ACPI support code.
@ 2017-03-31 17:51   ` fu.wei at linaro.org
  0 siblings, 0 replies; 66+ messages in thread
From: fu.wei at linaro.org @ 2017-03-31 17:51 UTC (permalink / raw)
  To: linux-arm-kernel

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

The patch update arm_arch_timer driver to use the function
provided by the new GTDT driver of ACPI.
By this way, arm_arch_timer.c can be simplified, and separate
all the ACPI GTDT knowledge from this timer driver.

Signed-off-by: Fu Wei <fu.wei@linaro.org>
Signed-off-by: Hanjun Guo <hanjun.guo@linaro.org>
Tested-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
Reviewed-by: Hanjun Guo <hanjun.guo@linaro.org>
Tested-by: Hanjun Guo <hanjun.guo@linaro.org>
---
 drivers/clocksource/arm_arch_timer.c | 54 ++++++++++++------------------------
 1 file changed, 17 insertions(+), 37 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index 4aaebe7..415e30a 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -1149,63 +1149,36 @@ static int __init arch_timer_mem_of_init(struct device_node *np)
 CLOCKSOURCE_OF_DECLARE(armv7_arch_timer_mem, "arm,armv7-timer-mem",
 		       arch_timer_mem_of_init);
 
-#ifdef CONFIG_ACPI
-static int __init map_generic_timer_interrupt(u32 interrupt, u32 flags)
-{
-	int trigger, polarity;
-
-	if (!interrupt)
-		return 0;
-
-	trigger = (flags & ACPI_GTDT_INTERRUPT_MODE) ? ACPI_EDGE_SENSITIVE
-			: ACPI_LEVEL_SENSITIVE;
-
-	polarity = (flags & ACPI_GTDT_INTERRUPT_POLARITY) ? ACPI_ACTIVE_LOW
-			: ACPI_ACTIVE_HIGH;
-
-	return acpi_register_gsi(NULL, interrupt, trigger, polarity);
-}
-
+#ifdef CONFIG_ACPI_GTDT
 /* Initialize per-processor generic timer */
 static int __init arch_timer_acpi_init(struct acpi_table_header *table)
 {
 	int ret;
-	struct acpi_table_gtdt *gtdt;
 
 	if (arch_timers_present & ARCH_TIMER_TYPE_CP15) {
 		pr_warn("already initialized, skipping\n");
 		return -EINVAL;
 	}
 
-	gtdt = container_of(table, struct acpi_table_gtdt, header);
-
 	arch_timers_present |= ARCH_TIMER_TYPE_CP15;
 
-	arch_timer_ppi[ARCH_TIMER_PHYS_SECURE_PPI] =
-		map_generic_timer_interrupt(gtdt->secure_el1_interrupt,
-		gtdt->secure_el1_flags);
+	ret = acpi_gtdt_init(table, NULL);
+	if (ret) {
+		pr_err("Failed to init GTDT table.\n");
+		return ret;
+	}
 
 	arch_timer_ppi[ARCH_TIMER_PHYS_NONSECURE_PPI] =
-		map_generic_timer_interrupt(gtdt->non_secure_el1_interrupt,
-		gtdt->non_secure_el1_flags);
+		acpi_gtdt_map_ppi(ARCH_TIMER_PHYS_NONSECURE_PPI);
 
 	arch_timer_ppi[ARCH_TIMER_VIRT_PPI] =
-		map_generic_timer_interrupt(gtdt->virtual_timer_interrupt,
-		gtdt->virtual_timer_flags);
+		acpi_gtdt_map_ppi(ARCH_TIMER_VIRT_PPI);
 
 	arch_timer_ppi[ARCH_TIMER_HYP_PPI] =
-		map_generic_timer_interrupt(gtdt->non_secure_el2_interrupt,
-		gtdt->non_secure_el2_flags);
+		acpi_gtdt_map_ppi(ARCH_TIMER_HYP_PPI);
 
 	arch_timer_kvm_info.virtual_irq = arch_timer_ppi[ARCH_TIMER_VIRT_PPI];
 
-	/* Get the frequency from the sysreg CNTFRQ */
-	arch_timer_rate = arch_timer_get_cntfrq();
-	if (!arch_timer_rate) {
-		pr_err(FW_BUG "frequency not available.\n");
-		return -EINVAL;
-	}
-
 	arch_timer_uses_ppi = arch_timer_select_ppi();
 	if (!arch_timer_ppi[arch_timer_uses_ppi]) {
 		pr_err("No interrupt available, giving up\n");
@@ -1213,7 +1186,14 @@ static int __init arch_timer_acpi_init(struct acpi_table_header *table)
 	}
 
 	/* Always-on capability */
-	arch_timer_c3stop = !(gtdt->non_secure_el1_flags & ACPI_GTDT_ALWAYS_ON);
+	arch_timer_c3stop = acpi_gtdt_c3stop(arch_timer_uses_ppi);
+
+	/* Get the frequency from the sysreg CNTFRQ */
+	arch_timer_rate = arch_timer_get_cntfrq();
+	if (!arch_timer_rate) {
+		pr_err(FW_BUG "frequency not available.\n");
+		return -EINVAL;
+	}
 
 	ret = arch_timer_register();
 	if (ret)
-- 
2.9.3

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

* [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
  2017-03-31 17:50 ` fu.wei at linaro.org
@ 2017-03-31 17:51   ` fu.wei at linaro.org
  -1 siblings, 0 replies; 66+ messages in thread
From: fu.wei @ 2017-03-31 17:51 UTC (permalink / raw)
  To: rjw, lenb, daniel.lezcano, tglx, marc.zyngier, mark.rutland,
	lorenzo.pieralisi, sudeep.holla, hanjun.guo
  Cc: linux-arm-kernel, linaro-acpi, linux-kernel, linux-acpi,
	rruigrok, harba, cov, timur, graeme.gregory, al.stone, jcm, wei,
	arnd, catalin.marinas, will.deacon, Suravee.Suthikulpanit,
	leo.duran, wim, linux, linux-watchdog, tn, christoffer.dall,
	julien.grall, Fu Wei

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

On platforms booting with ACPI, architected memory-mapped timers'
configuration data is provided by firmware through the ACPI GTDT
static table.

The clocksource architected timer kernel driver requires a firmware
interface to collect timer configuration and configure its driver.
this infrastructure is present for device tree systems, but it is
missing on systems booting with ACPI.

Implement the kernel infrastructure required to parse the static
ACPI GTDT table so that the architected timer clocksource driver can
make use of it on systems booting with ACPI, therefore enabling
the corresponding timers configuration.

Signed-off-by: Fu Wei <fu.wei@linaro.org>
Signed-off-by: Hanjun Guo <hanjun.guo@linaro.org>
---
 drivers/acpi/arm64/gtdt.c | 146 ++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/acpi.h      |   1 +
 2 files changed, 147 insertions(+)

diff --git a/drivers/acpi/arm64/gtdt.c b/drivers/acpi/arm64/gtdt.c
index 3d95af8..3dd33f3 100644
--- a/drivers/acpi/arm64/gtdt.c
+++ b/drivers/acpi/arm64/gtdt.c
@@ -13,6 +13,7 @@
 
 #include <linux/acpi.h>
 #include <linux/init.h>
+#include <linux/irqdomain.h>
 #include <linux/kernel.h>
 
 #include <clocksource/arm_arch_timer.h>
@@ -37,6 +38,28 @@ struct acpi_gtdt_descriptor {
 
 static struct acpi_gtdt_descriptor acpi_gtdt_desc __initdata;
 
+static inline void *next_platform_timer(void *platform_timer)
+{
+	struct acpi_gtdt_header *gh = platform_timer;
+
+	platform_timer += gh->length;
+	if (platform_timer < acpi_gtdt_desc.gtdt_end)
+		return platform_timer;
+
+	return NULL;
+}
+
+#define for_each_platform_timer(_g)				\
+	for (_g = acpi_gtdt_desc.platform_timer; _g;	\
+	     _g = next_platform_timer(_g))
+
+static inline bool is_timer_block(void *platform_timer)
+{
+	struct acpi_gtdt_header *gh = platform_timer;
+
+	return gh->type == ACPI_GTDT_TYPE_TIMER_BLOCK;
+}
+
 static int __init map_gt_gsi(u32 interrupt, u32 flags)
 {
 	int trigger, polarity;
@@ -155,3 +178,126 @@ int __init acpi_gtdt_init(struct acpi_table_header *table,
 
 	return 0;
 }
+
+static int __init gtdt_parse_timer_block(struct acpi_gtdt_timer_block *block,
+					 struct arch_timer_mem *timer_mem)
+{
+	int i;
+	struct arch_timer_mem_frame *frame;
+	struct acpi_gtdt_timer_entry *gtdt_frame;
+
+	if (!block->timer_count) {
+		pr_err(FW_BUG "GT block present, but frame count is zero.");
+		return -ENODEV;
+	}
+
+	if (block->timer_count > ARCH_TIMER_MEM_MAX_FRAMES) {
+		pr_err(FW_BUG "GT block lists %d frames, ACPI spec only allows 8\n",
+		       block->timer_count);
+		return -EINVAL;
+	}
+
+	timer_mem->cntctlbase = (phys_addr_t)block->block_address;
+	/*
+	 * The CNTCTLBase frame is 4KB (register offsets 0x000 - 0xFFC).
+	 * See ARM DDI 0487A.k_iss10775, page I1-5129, Table I1-3
+	 * "CNTCTLBase memory map".
+	 */
+	timer_mem->size = SZ_4K;
+
+	gtdt_frame = (void *)block + block->timer_offset;
+	if (gtdt_frame + block->timer_count != (void *)block + block->header.length)
+		return -EINVAL;
+
+	/*
+	 * Get the GT timer Frame data for every GT Block Timer
+	 */
+	for (i = 0; i < block->timer_count; i++, gtdt_frame++) {
+		if (gtdt_frame->common_flags & ACPI_GTDT_GT_IS_SECURE_TIMER)
+			continue;
+
+		if (!gtdt_frame->base_address || !gtdt_frame->timer_interrupt)
+			goto error;
+
+		frame = &timer_mem->frame[gtdt_frame->frame_number];
+		frame->phys_irq = map_gt_gsi(gtdt_frame->timer_interrupt,
+					     gtdt_frame->timer_flags);
+		if (frame->phys_irq <= 0) {
+			pr_warn("failed to map physical timer irq in frame %d.\n",
+				gtdt_frame->frame_number);
+			goto error;
+		}
+
+		if (gtdt_frame->virtual_timer_interrupt) {
+			frame->virt_irq =
+				map_gt_gsi(gtdt_frame->virtual_timer_interrupt,
+					   gtdt_frame->virtual_timer_flags);
+			if (frame->virt_irq <= 0) {
+				pr_warn("failed to map virtual timer irq in frame %d.\n",
+					gtdt_frame->frame_number);
+				acpi_unregister_gsi(gtdt_frame->timer_interrupt);
+				goto error;
+			}
+		} else {
+			frame->virt_irq = 0;
+			pr_debug("virtual timer in frame %d not implemented.\n",
+				 gtdt_frame->frame_number);
+		}
+
+		frame->cntbase = gtdt_frame->base_address;
+		/*
+		 * The CNTBaseN frame is 4KB (register offsets 0x000 - 0xFFC).
+		 * See ARM DDI 0487A.k_iss10775, page I1-5130, Table I1-4
+		 * "CNTBaseN memory map".
+		 */
+		frame->size = SZ_4K;
+		frame->valid = true;
+	}
+
+	return 0;
+
+error:
+	for (i = 0; i < ARCH_TIMER_MEM_MAX_FRAMES; i++) {
+		frame = &timer_mem->frame[i];
+		if (!frame->valid)
+			continue;
+		irq_dispose_mapping(frame->phys_irq);
+		if (frame->virt_irq)
+			irq_dispose_mapping(frame->virt_irq);
+	}
+	return -EINVAL;
+}
+
+/**
+ * acpi_arch_timer_mem_init() - Get the info of all GT blocks in GTDT table.
+ * @timer_mem:	The pointer to the array of struct arch_timer_mem for returning
+ *		the result of parsing. The element number of this array should
+ *		be platform_timer_count(the total number of platform timers).
+ * @timer_count: It points to a integer variable which is used for storing the
+ *		number of GT blocks we have parsed.
+ *
+ * Return: 0 if success, -EINVAL/-ENODEV if error.
+ */
+int __init acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem,
+				    int *timer_count)
+{
+	int ret;
+	void *platform_timer;
+
+	*timer_count = 0;
+	for_each_platform_timer(platform_timer) {
+		if (is_timer_block(platform_timer)) {
+			ret = gtdt_parse_timer_block(platform_timer, timer_mem);
+			if (ret)
+				return ret;
+			timer_mem++;
+			(*timer_count)++;
+		}
+	}
+
+	if (*timer_count)
+		pr_info("found %d memory-mapped timer block(s).\n",
+			*timer_count);
+
+	return 0;
+}
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 4b5c146..3193724 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -599,6 +599,7 @@ int acpi_reconfig_notifier_unregister(struct notifier_block *nb);
 int acpi_gtdt_init(struct acpi_table_header *table, int *platform_timer_count);
 int acpi_gtdt_map_ppi(int type);
 bool acpi_gtdt_c3stop(int type);
+int acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem, int *timer_count);
 #endif
 
 #else	/* !CONFIG_ACPI */
-- 
2.9.3

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

* [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
@ 2017-03-31 17:51   ` fu.wei at linaro.org
  0 siblings, 0 replies; 66+ messages in thread
From: fu.wei at linaro.org @ 2017-03-31 17:51 UTC (permalink / raw)
  To: linux-arm-kernel

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

On platforms booting with ACPI, architected memory-mapped timers'
configuration data is provided by firmware through the ACPI GTDT
static table.

The clocksource architected timer kernel driver requires a firmware
interface to collect timer configuration and configure its driver.
this infrastructure is present for device tree systems, but it is
missing on systems booting with ACPI.

Implement the kernel infrastructure required to parse the static
ACPI GTDT table so that the architected timer clocksource driver can
make use of it on systems booting with ACPI, therefore enabling
the corresponding timers configuration.

Signed-off-by: Fu Wei <fu.wei@linaro.org>
Signed-off-by: Hanjun Guo <hanjun.guo@linaro.org>
---
 drivers/acpi/arm64/gtdt.c | 146 ++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/acpi.h      |   1 +
 2 files changed, 147 insertions(+)

diff --git a/drivers/acpi/arm64/gtdt.c b/drivers/acpi/arm64/gtdt.c
index 3d95af8..3dd33f3 100644
--- a/drivers/acpi/arm64/gtdt.c
+++ b/drivers/acpi/arm64/gtdt.c
@@ -13,6 +13,7 @@
 
 #include <linux/acpi.h>
 #include <linux/init.h>
+#include <linux/irqdomain.h>
 #include <linux/kernel.h>
 
 #include <clocksource/arm_arch_timer.h>
@@ -37,6 +38,28 @@ struct acpi_gtdt_descriptor {
 
 static struct acpi_gtdt_descriptor acpi_gtdt_desc __initdata;
 
+static inline void *next_platform_timer(void *platform_timer)
+{
+	struct acpi_gtdt_header *gh = platform_timer;
+
+	platform_timer += gh->length;
+	if (platform_timer < acpi_gtdt_desc.gtdt_end)
+		return platform_timer;
+
+	return NULL;
+}
+
+#define for_each_platform_timer(_g)				\
+	for (_g = acpi_gtdt_desc.platform_timer; _g;	\
+	     _g = next_platform_timer(_g))
+
+static inline bool is_timer_block(void *platform_timer)
+{
+	struct acpi_gtdt_header *gh = platform_timer;
+
+	return gh->type == ACPI_GTDT_TYPE_TIMER_BLOCK;
+}
+
 static int __init map_gt_gsi(u32 interrupt, u32 flags)
 {
 	int trigger, polarity;
@@ -155,3 +178,126 @@ int __init acpi_gtdt_init(struct acpi_table_header *table,
 
 	return 0;
 }
+
+static int __init gtdt_parse_timer_block(struct acpi_gtdt_timer_block *block,
+					 struct arch_timer_mem *timer_mem)
+{
+	int i;
+	struct arch_timer_mem_frame *frame;
+	struct acpi_gtdt_timer_entry *gtdt_frame;
+
+	if (!block->timer_count) {
+		pr_err(FW_BUG "GT block present, but frame count is zero.");
+		return -ENODEV;
+	}
+
+	if (block->timer_count > ARCH_TIMER_MEM_MAX_FRAMES) {
+		pr_err(FW_BUG "GT block lists %d frames, ACPI spec only allows 8\n",
+		       block->timer_count);
+		return -EINVAL;
+	}
+
+	timer_mem->cntctlbase = (phys_addr_t)block->block_address;
+	/*
+	 * The CNTCTLBase frame is 4KB (register offsets 0x000 - 0xFFC).
+	 * See ARM DDI 0487A.k_iss10775, page I1-5129, Table I1-3
+	 * "CNTCTLBase memory map".
+	 */
+	timer_mem->size = SZ_4K;
+
+	gtdt_frame = (void *)block + block->timer_offset;
+	if (gtdt_frame + block->timer_count != (void *)block + block->header.length)
+		return -EINVAL;
+
+	/*
+	 * Get the GT timer Frame data for every GT Block Timer
+	 */
+	for (i = 0; i < block->timer_count; i++, gtdt_frame++) {
+		if (gtdt_frame->common_flags & ACPI_GTDT_GT_IS_SECURE_TIMER)
+			continue;
+
+		if (!gtdt_frame->base_address || !gtdt_frame->timer_interrupt)
+			goto error;
+
+		frame = &timer_mem->frame[gtdt_frame->frame_number];
+		frame->phys_irq = map_gt_gsi(gtdt_frame->timer_interrupt,
+					     gtdt_frame->timer_flags);
+		if (frame->phys_irq <= 0) {
+			pr_warn("failed to map physical timer irq in frame %d.\n",
+				gtdt_frame->frame_number);
+			goto error;
+		}
+
+		if (gtdt_frame->virtual_timer_interrupt) {
+			frame->virt_irq =
+				map_gt_gsi(gtdt_frame->virtual_timer_interrupt,
+					   gtdt_frame->virtual_timer_flags);
+			if (frame->virt_irq <= 0) {
+				pr_warn("failed to map virtual timer irq in frame %d.\n",
+					gtdt_frame->frame_number);
+				acpi_unregister_gsi(gtdt_frame->timer_interrupt);
+				goto error;
+			}
+		} else {
+			frame->virt_irq = 0;
+			pr_debug("virtual timer in frame %d not implemented.\n",
+				 gtdt_frame->frame_number);
+		}
+
+		frame->cntbase = gtdt_frame->base_address;
+		/*
+		 * The CNTBaseN frame is 4KB (register offsets 0x000 - 0xFFC).
+		 * See ARM DDI 0487A.k_iss10775, page I1-5130, Table I1-4
+		 * "CNTBaseN memory map".
+		 */
+		frame->size = SZ_4K;
+		frame->valid = true;
+	}
+
+	return 0;
+
+error:
+	for (i = 0; i < ARCH_TIMER_MEM_MAX_FRAMES; i++) {
+		frame = &timer_mem->frame[i];
+		if (!frame->valid)
+			continue;
+		irq_dispose_mapping(frame->phys_irq);
+		if (frame->virt_irq)
+			irq_dispose_mapping(frame->virt_irq);
+	}
+	return -EINVAL;
+}
+
+/**
+ * acpi_arch_timer_mem_init() - Get the info of all GT blocks in GTDT table.
+ * @timer_mem:	The pointer to the array of struct arch_timer_mem for returning
+ *		the result of parsing. The element number of this array should
+ *		be platform_timer_count(the total number of platform timers).
+ * @timer_count: It points to a integer variable which is used for storing the
+ *		number of GT blocks we have parsed.
+ *
+ * Return: 0 if success, -EINVAL/-ENODEV if error.
+ */
+int __init acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem,
+				    int *timer_count)
+{
+	int ret;
+	void *platform_timer;
+
+	*timer_count = 0;
+	for_each_platform_timer(platform_timer) {
+		if (is_timer_block(platform_timer)) {
+			ret = gtdt_parse_timer_block(platform_timer, timer_mem);
+			if (ret)
+				return ret;
+			timer_mem++;
+			(*timer_count)++;
+		}
+	}
+
+	if (*timer_count)
+		pr_info("found %d memory-mapped timer block(s).\n",
+			*timer_count);
+
+	return 0;
+}
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 4b5c146..3193724 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -599,6 +599,7 @@ int acpi_reconfig_notifier_unregister(struct notifier_block *nb);
 int acpi_gtdt_init(struct acpi_table_header *table, int *platform_timer_count);
 int acpi_gtdt_map_ppi(int type);
 bool acpi_gtdt_c3stop(int type);
+int acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem, int *timer_count);
 #endif
 
 #else	/* !CONFIG_ACPI */
-- 
2.9.3

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

* [PATCH v23 10/11] clocksource: arm_arch_timer: add GTDT support for memory-mapped timer
  2017-03-31 17:50 ` fu.wei at linaro.org
@ 2017-03-31 17:51   ` fu.wei at linaro.org
  -1 siblings, 0 replies; 66+ messages in thread
From: fu.wei @ 2017-03-31 17:51 UTC (permalink / raw)
  To: rjw, lenb, daniel.lezcano, tglx, marc.zyngier, mark.rutland,
	lorenzo.pieralisi, sudeep.holla, hanjun.guo
  Cc: linux-arm-kernel, linaro-acpi, linux-kernel, linux-acpi,
	rruigrok, harba, cov, timur, graeme.gregory, al.stone, jcm, wei,
	arnd, catalin.marinas, will.deacon, Suravee.Suthikulpanit,
	leo.duran, wim, linux, linux-watchdog, tn, christoffer.dall,
	julien.grall, Fu Wei

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

The patch add memory-mapped timer register support by using the
information provided by the new GTDT driver of ACPI.

Signed-off-by: Fu Wei <fu.wei@linaro.org>
Reviewed-by: Hanjun Guo <hanjun.guo@linaro.org>
---
 drivers/clocksource/arm_arch_timer.c | 35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index 415e30a..c722bb5 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -1150,10 +1150,35 @@ CLOCKSOURCE_OF_DECLARE(armv7_arch_timer_mem, "arm,armv7-timer-mem",
 		       arch_timer_mem_of_init);
 
 #ifdef CONFIG_ACPI_GTDT
-/* Initialize per-processor generic timer */
+static int __init arch_timer_mem_acpi_init(int platform_timer_count)
+{
+	struct arch_timer_mem *timer_mem;
+	int timer_count, i, ret;
+
+	timer_mem = kcalloc(platform_timer_count, sizeof(*timer_mem),
+			    GFP_KERNEL);
+	if (!timer_mem)
+		return -ENOMEM;
+
+	ret = acpi_arch_timer_mem_init(timer_mem, &timer_count);
+	if (ret || !timer_count)
+		goto error;
+
+	for (i = 0; i < timer_count; i++) {
+		ret = arch_timer_mem_init(timer_mem + i);
+		if (!ret)
+			break;
+	}
+
+error:
+	kfree(timer_mem);
+	return ret;
+}
+
+/* Initialize per-processor generic timer and memory-mapped timer(if present) */
 static int __init arch_timer_acpi_init(struct acpi_table_header *table)
 {
-	int ret;
+	int ret, platform_timer_count;
 
 	if (arch_timers_present & ARCH_TIMER_TYPE_CP15) {
 		pr_warn("already initialized, skipping\n");
@@ -1162,7 +1187,7 @@ static int __init arch_timer_acpi_init(struct acpi_table_header *table)
 
 	arch_timers_present |= ARCH_TIMER_TYPE_CP15;
 
-	ret = acpi_gtdt_init(table, NULL);
+	ret = acpi_gtdt_init(table, &platform_timer_count);
 	if (ret) {
 		pr_err("Failed to init GTDT table.\n");
 		return ret;
@@ -1199,6 +1224,10 @@ static int __init arch_timer_acpi_init(struct acpi_table_header *table)
 	if (ret)
 		return ret;
 
+	if (platform_timer_count &&
+	    arch_timer_mem_acpi_init(platform_timer_count))
+		pr_err("Failed to initialize memory-mapped timer.\n");
+
 	return arch_timer_common_init();
 }
 CLOCKSOURCE_ACPI_DECLARE(arch_timer, ACPI_SIG_GTDT, arch_timer_acpi_init);
-- 
2.9.3

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

* [PATCH v23 10/11] clocksource: arm_arch_timer: add GTDT support for memory-mapped timer
@ 2017-03-31 17:51   ` fu.wei at linaro.org
  0 siblings, 0 replies; 66+ messages in thread
From: fu.wei at linaro.org @ 2017-03-31 17:51 UTC (permalink / raw)
  To: linux-arm-kernel

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

The patch add memory-mapped timer register support by using the
information provided by the new GTDT driver of ACPI.

Signed-off-by: Fu Wei <fu.wei@linaro.org>
Reviewed-by: Hanjun Guo <hanjun.guo@linaro.org>
---
 drivers/clocksource/arm_arch_timer.c | 35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index 415e30a..c722bb5 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -1150,10 +1150,35 @@ CLOCKSOURCE_OF_DECLARE(armv7_arch_timer_mem, "arm,armv7-timer-mem",
 		       arch_timer_mem_of_init);
 
 #ifdef CONFIG_ACPI_GTDT
-/* Initialize per-processor generic timer */
+static int __init arch_timer_mem_acpi_init(int platform_timer_count)
+{
+	struct arch_timer_mem *timer_mem;
+	int timer_count, i, ret;
+
+	timer_mem = kcalloc(platform_timer_count, sizeof(*timer_mem),
+			    GFP_KERNEL);
+	if (!timer_mem)
+		return -ENOMEM;
+
+	ret = acpi_arch_timer_mem_init(timer_mem, &timer_count);
+	if (ret || !timer_count)
+		goto error;
+
+	for (i = 0; i < timer_count; i++) {
+		ret = arch_timer_mem_init(timer_mem + i);
+		if (!ret)
+			break;
+	}
+
+error:
+	kfree(timer_mem);
+	return ret;
+}
+
+/* Initialize per-processor generic timer and memory-mapped timer(if present) */
 static int __init arch_timer_acpi_init(struct acpi_table_header *table)
 {
-	int ret;
+	int ret, platform_timer_count;
 
 	if (arch_timers_present & ARCH_TIMER_TYPE_CP15) {
 		pr_warn("already initialized, skipping\n");
@@ -1162,7 +1187,7 @@ static int __init arch_timer_acpi_init(struct acpi_table_header *table)
 
 	arch_timers_present |= ARCH_TIMER_TYPE_CP15;
 
-	ret = acpi_gtdt_init(table, NULL);
+	ret = acpi_gtdt_init(table, &platform_timer_count);
 	if (ret) {
 		pr_err("Failed to init GTDT table.\n");
 		return ret;
@@ -1199,6 +1224,10 @@ static int __init arch_timer_acpi_init(struct acpi_table_header *table)
 	if (ret)
 		return ret;
 
+	if (platform_timer_count &&
+	    arch_timer_mem_acpi_init(platform_timer_count))
+		pr_err("Failed to initialize memory-mapped timer.\n");
+
 	return arch_timer_common_init();
 }
 CLOCKSOURCE_ACPI_DECLARE(arch_timer, ACPI_SIG_GTDT, arch_timer_acpi_init);
-- 
2.9.3

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

* [PATCH v23 11/11] acpi/arm64: Add SBSA Generic Watchdog support in GTDT driver
  2017-03-31 17:50 ` fu.wei at linaro.org
  (?)
@ 2017-03-31 17:51   ` fu.wei
  -1 siblings, 0 replies; 66+ messages in thread
From: fu.wei @ 2017-03-31 17:51 UTC (permalink / raw)
  To: rjw, lenb, daniel.lezcano, tglx, marc.zyngier, mark.rutland,
	lorenzo.pieralisi, sudeep.holla, hanjun.guo
  Cc: linux-arm-kernel, linaro-acpi, linux-kernel, linux-acpi,
	rruigrok, harba, cov, timur, graeme.gregory, al.stone, jcm, wei,
	arnd, catalin.marinas, will.deacon, Suravee.Suthikulpanit,
	leo.duran, wim, linux, linux-watchdog, tn, christoffer.dall,
	julien.grall, Fu Wei

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

This driver adds support for parsing SBSA Generic Watchdog timer
in GTDT, parse all info in SBSA Generic Watchdog Structure in GTDT,
and creating a platform device with that information.

This allows the operating system to obtain device data from the
resource of platform device. The platform device named "sbsa-gwdt"
can be used by the ARM SBSA Generic Watchdog driver.

Signed-off-by: Fu Wei <fu.wei@linaro.org>
Signed-off-by: Hanjun Guo <hanjun.guo@linaro.org>
Tested-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
Reviewed-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
---
 drivers/acpi/arm64/gtdt.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 103 insertions(+)

diff --git a/drivers/acpi/arm64/gtdt.c b/drivers/acpi/arm64/gtdt.c
index 3dd33f3..d73bb16 100644
--- a/drivers/acpi/arm64/gtdt.c
+++ b/drivers/acpi/arm64/gtdt.c
@@ -15,6 +15,7 @@
 #include <linux/init.h>
 #include <linux/irqdomain.h>
 #include <linux/kernel.h>
+#include <linux/platform_device.h>
 
 #include <clocksource/arm_arch_timer.h>
 
@@ -60,6 +61,17 @@ static inline bool is_timer_block(void *platform_timer)
 	return gh->type == ACPI_GTDT_TYPE_TIMER_BLOCK;
 }
 
+static inline bool is_non_secure_watchdog(void *platform_timer)
+{
+	struct acpi_gtdt_header *gh = platform_timer;
+	struct acpi_gtdt_watchdog *wd = platform_timer;
+
+	if (gh->type != ACPI_GTDT_TYPE_WATCHDOG)
+		return false;
+
+	return !(wd->timer_flags & ACPI_GTDT_WATCHDOG_SECURE);
+}
+
 static int __init map_gt_gsi(u32 interrupt, u32 flags)
 {
 	int trigger, polarity;
@@ -301,3 +313,94 @@ int __init acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem,
 
 	return 0;
 }
+
+/*
+ * Initialize a SBSA generic Watchdog platform device info from GTDT
+ */
+static int __init gtdt_import_sbsa_gwdt(struct acpi_gtdt_watchdog *wd,
+					int index)
+{
+	struct platform_device *pdev;
+	int irq = map_gt_gsi(wd->timer_interrupt, wd->timer_flags);
+
+	/*
+	 * According to SBSA specification the size of refresh and control
+	 * frames of SBSA Generic Watchdog is SZ_4K(Offset 0x000 – 0xFFF).
+	 */
+	struct resource res[] = {
+		DEFINE_RES_MEM(wd->control_frame_address, SZ_4K),
+		DEFINE_RES_MEM(wd->refresh_frame_address, SZ_4K),
+		DEFINE_RES_IRQ(irq),
+	};
+	int nr_res = ARRAY_SIZE(res);
+
+	pr_debug("found a Watchdog (0x%llx/0x%llx gsi:%u flags:0x%x).\n",
+		 wd->refresh_frame_address, wd->control_frame_address,
+		 wd->timer_interrupt, wd->timer_flags);
+
+	if (!(wd->refresh_frame_address && wd->control_frame_address)) {
+		pr_err(FW_BUG "failed to get the Watchdog base address.\n");
+		acpi_unregister_gsi(wd->timer_interrupt);
+		return -EINVAL;
+	}
+
+	if (irq <= 0) {
+		pr_warn("failed to map the Watchdog interrupt.\n");
+		nr_res--;
+	}
+
+	/*
+	 * Add a platform device named "sbsa-gwdt" to match the platform driver.
+	 * "sbsa-gwdt": SBSA(Server Base System Architecture) Generic Watchdog
+	 * The platform driver can get device info below by matching this name.
+	 */
+	pdev = platform_device_register_simple("sbsa-gwdt", index, res, nr_res);
+	if (IS_ERR(pdev)) {
+		acpi_unregister_gsi(wd->timer_interrupt);
+		return PTR_ERR(pdev);
+	}
+
+	return 0;
+}
+
+static int __init gtdt_sbsa_gwdt_init(void)
+{
+	void *platform_timer;
+	struct acpi_table_header *table;
+	int ret, timer_count, gwdt_count = 0;
+
+	if (acpi_disabled)
+		return 0;
+
+	if (ACPI_FAILURE(acpi_get_table(ACPI_SIG_GTDT, 0, &table)))
+		return -EINVAL;
+
+	/*
+	 * Note: Even though the global variable acpi_gtdt_desc has been
+	 * initialized by acpi_gtdt_init() while initializing the arch timers,
+	 * when we call this function to get SBSA watchdogs info from GTDT, the
+	 * pointers stashed in it are stale (since they are early temporary
+	 * mappings carried out before acpi_permanent_mmap is set) and we need
+	 * to re-initialize them with permanent mapped pointer values to let the
+	 * GTDT parsing possible.
+	 */
+	ret = acpi_gtdt_init(table, &timer_count);
+	if (ret || !timer_count)
+		return ret;
+
+	for_each_platform_timer(platform_timer) {
+		if (is_non_secure_watchdog(platform_timer)) {
+			ret = gtdt_import_sbsa_gwdt(platform_timer, gwdt_count);
+			if (ret)
+				break;
+			gwdt_count++;
+		}
+	}
+
+	if (gwdt_count)
+		pr_info("found %d SBSA generic Watchdog(s).\n", gwdt_count);
+
+	return ret;
+}
+
+device_initcall(gtdt_sbsa_gwdt_init);
-- 
2.9.3

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

* [PATCH v23 11/11] acpi/arm64: Add SBSA Generic Watchdog support in GTDT driver
@ 2017-03-31 17:51   ` fu.wei
  0 siblings, 0 replies; 66+ messages in thread
From: fu.wei @ 2017-03-31 17:51 UTC (permalink / raw)
  To: rjw, lenb, daniel.lezcano, tglx, marc.zyngier, mark.rutland,
	lorenzo.pieralisi, sudeep.holla, hanjun.guo
  Cc: linux-arm-kernel, linaro-acpi, linux-kernel, linux-acpi,
	rruigrok, harba, cov, timur, graeme.gregory, al.stone, jcm, wei,
	arnd, catalin.marinas, will.deacon, Suravee.Suthikulpanit,
	leo.duran, wim, linux, linux-watchdog, tn, christoffer.dall,
	julien.grall, Fu Wei

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

This driver adds support for parsing SBSA Generic Watchdog timer
in GTDT, parse all info in SBSA Generic Watchdog Structure in GTDT,
and creating a platform device with that information.

This allows the operating system to obtain device data from the
resource of platform device. The platform device named "sbsa-gwdt"
can be used by the ARM SBSA Generic Watchdog driver.

Signed-off-by: Fu Wei <fu.wei@linaro.org>
Signed-off-by: Hanjun Guo <hanjun.guo@linaro.org>
Tested-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
Reviewed-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
---
 drivers/acpi/arm64/gtdt.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 103 insertions(+)

diff --git a/drivers/acpi/arm64/gtdt.c b/drivers/acpi/arm64/gtdt.c
index 3dd33f3..d73bb16 100644
--- a/drivers/acpi/arm64/gtdt.c
+++ b/drivers/acpi/arm64/gtdt.c
@@ -15,6 +15,7 @@
 #include <linux/init.h>
 #include <linux/irqdomain.h>
 #include <linux/kernel.h>
+#include <linux/platform_device.h>
 
 #include <clocksource/arm_arch_timer.h>
 
@@ -60,6 +61,17 @@ static inline bool is_timer_block(void *platform_timer)
 	return gh->type == ACPI_GTDT_TYPE_TIMER_BLOCK;
 }
 
+static inline bool is_non_secure_watchdog(void *platform_timer)
+{
+	struct acpi_gtdt_header *gh = platform_timer;
+	struct acpi_gtdt_watchdog *wd = platform_timer;
+
+	if (gh->type != ACPI_GTDT_TYPE_WATCHDOG)
+		return false;
+
+	return !(wd->timer_flags & ACPI_GTDT_WATCHDOG_SECURE);
+}
+
 static int __init map_gt_gsi(u32 interrupt, u32 flags)
 {
 	int trigger, polarity;
@@ -301,3 +313,94 @@ int __init acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem,
 
 	return 0;
 }
+
+/*
+ * Initialize a SBSA generic Watchdog platform device info from GTDT
+ */
+static int __init gtdt_import_sbsa_gwdt(struct acpi_gtdt_watchdog *wd,
+					int index)
+{
+	struct platform_device *pdev;
+	int irq = map_gt_gsi(wd->timer_interrupt, wd->timer_flags);
+
+	/*
+	 * According to SBSA specification the size of refresh and control
+	 * frames of SBSA Generic Watchdog is SZ_4K(Offset 0x000 – 0xFFF).
+	 */
+	struct resource res[] = {
+		DEFINE_RES_MEM(wd->control_frame_address, SZ_4K),
+		DEFINE_RES_MEM(wd->refresh_frame_address, SZ_4K),
+		DEFINE_RES_IRQ(irq),
+	};
+	int nr_res = ARRAY_SIZE(res);
+
+	pr_debug("found a Watchdog (0x%llx/0x%llx gsi:%u flags:0x%x).\n",
+		 wd->refresh_frame_address, wd->control_frame_address,
+		 wd->timer_interrupt, wd->timer_flags);
+
+	if (!(wd->refresh_frame_address && wd->control_frame_address)) {
+		pr_err(FW_BUG "failed to get the Watchdog base address.\n");
+		acpi_unregister_gsi(wd->timer_interrupt);
+		return -EINVAL;
+	}
+
+	if (irq <= 0) {
+		pr_warn("failed to map the Watchdog interrupt.\n");
+		nr_res--;
+	}
+
+	/*
+	 * Add a platform device named "sbsa-gwdt" to match the platform driver.
+	 * "sbsa-gwdt": SBSA(Server Base System Architecture) Generic Watchdog
+	 * The platform driver can get device info below by matching this name.
+	 */
+	pdev = platform_device_register_simple("sbsa-gwdt", index, res, nr_res);
+	if (IS_ERR(pdev)) {
+		acpi_unregister_gsi(wd->timer_interrupt);
+		return PTR_ERR(pdev);
+	}
+
+	return 0;
+}
+
+static int __init gtdt_sbsa_gwdt_init(void)
+{
+	void *platform_timer;
+	struct acpi_table_header *table;
+	int ret, timer_count, gwdt_count = 0;
+
+	if (acpi_disabled)
+		return 0;
+
+	if (ACPI_FAILURE(acpi_get_table(ACPI_SIG_GTDT, 0, &table)))
+		return -EINVAL;
+
+	/*
+	 * Note: Even though the global variable acpi_gtdt_desc has been
+	 * initialized by acpi_gtdt_init() while initializing the arch timers,
+	 * when we call this function to get SBSA watchdogs info from GTDT, the
+	 * pointers stashed in it are stale (since they are early temporary
+	 * mappings carried out before acpi_permanent_mmap is set) and we need
+	 * to re-initialize them with permanent mapped pointer values to let the
+	 * GTDT parsing possible.
+	 */
+	ret = acpi_gtdt_init(table, &timer_count);
+	if (ret || !timer_count)
+		return ret;
+
+	for_each_platform_timer(platform_timer) {
+		if (is_non_secure_watchdog(platform_timer)) {
+			ret = gtdt_import_sbsa_gwdt(platform_timer, gwdt_count);
+			if (ret)
+				break;
+			gwdt_count++;
+		}
+	}
+
+	if (gwdt_count)
+		pr_info("found %d SBSA generic Watchdog(s).\n", gwdt_count);
+
+	return ret;
+}
+
+device_initcall(gtdt_sbsa_gwdt_init);
-- 
2.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH v23 11/11] acpi/arm64: Add SBSA Generic Watchdog support in GTDT driver
@ 2017-03-31 17:51   ` fu.wei
  0 siblings, 0 replies; 66+ messages in thread
From: fu.wei at linaro.org @ 2017-03-31 17:51 UTC (permalink / raw)
  To: linux-arm-kernel

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

This driver adds support for parsing SBSA Generic Watchdog timer
in GTDT, parse all info in SBSA Generic Watchdog Structure in GTDT,
and creating a platform device with that information.

This allows the operating system to obtain device data from the
resource of platform device. The platform device named "sbsa-gwdt"
can be used by the ARM SBSA Generic Watchdog driver.

Signed-off-by: Fu Wei <fu.wei@linaro.org>
Signed-off-by: Hanjun Guo <hanjun.guo@linaro.org>
Tested-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
Reviewed-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
---
 drivers/acpi/arm64/gtdt.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 103 insertions(+)

diff --git a/drivers/acpi/arm64/gtdt.c b/drivers/acpi/arm64/gtdt.c
index 3dd33f3..d73bb16 100644
--- a/drivers/acpi/arm64/gtdt.c
+++ b/drivers/acpi/arm64/gtdt.c
@@ -15,6 +15,7 @@
 #include <linux/init.h>
 #include <linux/irqdomain.h>
 #include <linux/kernel.h>
+#include <linux/platform_device.h>
 
 #include <clocksource/arm_arch_timer.h>
 
@@ -60,6 +61,17 @@ static inline bool is_timer_block(void *platform_timer)
 	return gh->type == ACPI_GTDT_TYPE_TIMER_BLOCK;
 }
 
+static inline bool is_non_secure_watchdog(void *platform_timer)
+{
+	struct acpi_gtdt_header *gh = platform_timer;
+	struct acpi_gtdt_watchdog *wd = platform_timer;
+
+	if (gh->type != ACPI_GTDT_TYPE_WATCHDOG)
+		return false;
+
+	return !(wd->timer_flags & ACPI_GTDT_WATCHDOG_SECURE);
+}
+
 static int __init map_gt_gsi(u32 interrupt, u32 flags)
 {
 	int trigger, polarity;
@@ -301,3 +313,94 @@ int __init acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem,
 
 	return 0;
 }
+
+/*
+ * Initialize a SBSA generic Watchdog platform device info from GTDT
+ */
+static int __init gtdt_import_sbsa_gwdt(struct acpi_gtdt_watchdog *wd,
+					int index)
+{
+	struct platform_device *pdev;
+	int irq = map_gt_gsi(wd->timer_interrupt, wd->timer_flags);
+
+	/*
+	 * According to SBSA specification the size of refresh and control
+	 * frames of SBSA Generic Watchdog is SZ_4K(Offset 0x000 ? 0xFFF).
+	 */
+	struct resource res[] = {
+		DEFINE_RES_MEM(wd->control_frame_address, SZ_4K),
+		DEFINE_RES_MEM(wd->refresh_frame_address, SZ_4K),
+		DEFINE_RES_IRQ(irq),
+	};
+	int nr_res = ARRAY_SIZE(res);
+
+	pr_debug("found a Watchdog (0x%llx/0x%llx gsi:%u flags:0x%x).\n",
+		 wd->refresh_frame_address, wd->control_frame_address,
+		 wd->timer_interrupt, wd->timer_flags);
+
+	if (!(wd->refresh_frame_address && wd->control_frame_address)) {
+		pr_err(FW_BUG "failed to get the Watchdog base address.\n");
+		acpi_unregister_gsi(wd->timer_interrupt);
+		return -EINVAL;
+	}
+
+	if (irq <= 0) {
+		pr_warn("failed to map the Watchdog interrupt.\n");
+		nr_res--;
+	}
+
+	/*
+	 * Add a platform device named "sbsa-gwdt" to match the platform driver.
+	 * "sbsa-gwdt": SBSA(Server Base System Architecture) Generic Watchdog
+	 * The platform driver can get device info below by matching this name.
+	 */
+	pdev = platform_device_register_simple("sbsa-gwdt", index, res, nr_res);
+	if (IS_ERR(pdev)) {
+		acpi_unregister_gsi(wd->timer_interrupt);
+		return PTR_ERR(pdev);
+	}
+
+	return 0;
+}
+
+static int __init gtdt_sbsa_gwdt_init(void)
+{
+	void *platform_timer;
+	struct acpi_table_header *table;
+	int ret, timer_count, gwdt_count = 0;
+
+	if (acpi_disabled)
+		return 0;
+
+	if (ACPI_FAILURE(acpi_get_table(ACPI_SIG_GTDT, 0, &table)))
+		return -EINVAL;
+
+	/*
+	 * Note: Even though the global variable acpi_gtdt_desc has been
+	 * initialized by acpi_gtdt_init() while initializing the arch timers,
+	 * when we call this function to get SBSA watchdogs info from GTDT, the
+	 * pointers stashed in it are stale (since they are early temporary
+	 * mappings carried out before acpi_permanent_mmap is set) and we need
+	 * to re-initialize them with permanent mapped pointer values to let the
+	 * GTDT parsing possible.
+	 */
+	ret = acpi_gtdt_init(table, &timer_count);
+	if (ret || !timer_count)
+		return ret;
+
+	for_each_platform_timer(platform_timer) {
+		if (is_non_secure_watchdog(platform_timer)) {
+			ret = gtdt_import_sbsa_gwdt(platform_timer, gwdt_count);
+			if (ret)
+				break;
+			gwdt_count++;
+		}
+	}
+
+	if (gwdt_count)
+		pr_info("found %d SBSA generic Watchdog(s).\n", gwdt_count);
+
+	return ret;
+}
+
+device_initcall(gtdt_sbsa_gwdt_init);
-- 
2.9.3

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

* Re: [PATCH v23 00/11] acpi, clocksource: add GTDT driver and GTDT support in arm_arch_timer
  2017-03-31 17:50 ` fu.wei at linaro.org
  (?)
@ 2017-04-01  2:14   ` Xiongfeng Wang
  -1 siblings, 0 replies; 66+ messages in thread
From: Xiongfeng Wang @ 2017-04-01  2:14 UTC (permalink / raw)
  To: fu.wei, rjw, lenb, daniel.lezcano, tglx, marc.zyngier,
	mark.rutland, lorenzo.pieralisi, sudeep.holla, hanjun.guo
  Cc: linaro-acpi, catalin.marinas, will.deacon, linux-kernel, wim,
	wei, al.stone, tn, timur, linux-acpi, linux, harba, julien.grall,
	linux-watchdog, arnd, jcm, cov, linux-arm-kernel, graeme.gregory,
	rruigrok, leo.duran, Suravee.Suthikulpanit, christoffer.dall



On 2017/4/1 1:50, fu.wei@linaro.org wrote:
> From: Fu Wei <fu.wei@linaro.org>
> 
> This patchset:
>     (1)Preparation for adding GTDT support in arm_arch_timer:
>         1. Introduce a MMIO CNTFRQ helper.
>         2. separate out device-tree code from arch_timer_detect_rate
>         3. remove arch_timer_detect_rate use arch_timer_*get_cntfrq directly
>         4. Refactor arch_timer_needs_probing, and move it into DT init call
>         5. Introduce some new structs and refactor the MMIO timer init code
>         for reusing some common code.
> 
>     (2)Introduce ACPI GTDT parser: drivers/acpi/arm64/acpi_gtdt.c
>     Parse all kinds of timer in GTDT table of ACPI:arch timer,
>     memory-mapped timer and SBSA Generic Watchdog timer.
>     This driver can help to simplify all the relevant timer drivers,
>     and separate all the ACPI GTDT knowledge from them.
> 
>     (3)Simplify ACPI code for arm_arch_timer
> 
>     (4)Add GTDT support for ARM memory-mapped timer.
> 
> This patchset has been tested on the following platforms with ACPI enabled:
>     (1)ARM Foundation v8 model
> 

for arm_arch_timer(not memory-mapped) and sbsa watchdog part,  Tested-by: wangxiongfeng2@huawei.com





Thanks,

Wang Xiongfeng
.

> Changelog:
> v23: https://lkml.org/lkml/2017/3/31/
>      Rebase to git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arch-timer/cleanup
>      Improve the data struct of arch_timer_mem and arch_timer_mem_frame to
>      improve the parser of GT blocks and arch_timer_mem initualization.
>      Improve arch_timer_rate detection: sysreg frequency is primary in DT boot
>      Improve some comments in GTDT parser driver.
>      Improve acpi_gtdt_init function, and make a comment for the multiple calls.
>      Improve the unwinding for the irq of timers, when an error occurs.
>      Handle the case of virtual timer GSIV is 0.
> 
> v22: https://lkml.org/lkml/2017/3/21/523
>      Rebase to git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arch-timer/cleanup
>      Only Introduce arch_timer_mem_get_cntfrq to get the frequency from mmio.
>      Merged patch 2,3(about arch_timer_detect_rate).
>      Keep arch_timer_rate, do NOT split it for different types of timer.
>      Improve  memory-mapped timer support by comments and variable name:
>          data-->timer_mem
>          frame-->gtdt_frame
>      Delete zero check for SBSA watchdog irq.
>      Skip secure SBSA watchdog in GTDT driver.
>      Delete Kconfig modification for SBSA watchdog driver.
>      Delete no_irq, using nr_res instead.
> 
> v21: https://lkml.org/lkml/2017/2/6/734
>      Introduce two functions to get the frequency from mmio and sysreg.
>      Remove arch_timer_detect_rate use arch_timer_get_*_freq directly
>      Split arch_timer_rate for different types of timer.
>      Skip secure timer frame in GTDT driver.
>      Rebase to git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arch-timer/cleanup
>      (The first 6 patches in v20 have been merged into arch-timer/cleanup branch)
> 
> v20: https://lkml.org/lkml/2017/1/18/534
>      Reorder the first 4 patches and split the 4th patches.
>      Leave CNTHCTL_* as they originally were.
>      Fix the bug in arch_timer_select_ppi.
>      Split "Rework counter frequency detection" patch.
>      Rework the arch_timer_detect_rate function.
>      Improve the commit message of "Refactor MMIO timer probing".
>      Rebase to 4.10.0-rc4
> 
> v19: https://lkml.org/lkml/2016/12/21/25
>      Fix a '\n' missing in a error message in arch_timer_mem_init.
>      Add "request_mem_region" for ioremapping cntbase, according to
>      f947ee1 clocksource/drivers/arm_arch_timer: Map frame with of_io_request_and_map()
>      Rebase to 4.9.0-gfb779ff
> 
> v18: https://lkml.org/lkml/2016/12/8/446
>      Fix 8/15 patch problem of "int ret;" in arch_timer_acpi_init.
>      Rebase to 4.9.0-rc8-g9269898
> 
> v17: https://lkml.org/lkml/2016/11/25/140
>      Take out some cleanups from 4/15.
>      Merge 5/15 and 6/15, improve PPI determination code,
>      improve commit message.
>      Rework counter frequency detection.
>      Move arch_timer_needs_of_probing into DT init call.
>      Move Platform Timer scan loop back to timer init call to avoid allocating
>      and free memory.
>      Improve all the exported functions' comment.
> 
> v16: https://lkml.org/lkml/2016/11/16/268
>      Fix patchset problem about static enum ppi_nr of 01/13 in v15.
>      Refactor arch_timer_detect_rate.
>      Refactor arch_timer_needs_probing.
> 
> v15: https://lkml.org/lkml/2016/11/15/366
>      Re-order patches
>      Add arm_arch_timer refactoring patches to prepare for GTDT:
>          1. rename some  enums and defines, and some cleanups
>          2. separate out arch_timer_uses_ppi init code and fix a potential bug
>          3. Improve some new structs, refactor the timer init code.
>      Since the some structs have been changed, GTDT parser for memory-mapped
>      timer and SBSA Generic Watchdog timer have been update.
> 
> v14: https://lkml.org/lkml/2016/9/28/573
>      Separate memory-mapped timer GTDT support into two patches
>          1. Refactor the timer init code to prepare for GTDT
>          2. Add GTDT support for memory-mapped timer
> 
> v13: http://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1231717.html
>      Improve arm_arch_timer code for memory-mapped
>      timer GTDT support, refactor original memory-mapped timer
>      dt support for reusing some common code.
> 
> v12: https://lkml.org/lkml/2016/9/13/250
>      Rebase to latest Linux 4.8-rc6
>      Delete the confusing "skipping" in the error message.
> 
> V11: https://lkml.org/lkml/2016/9/6/354
>      Rebase to latest Linux 4.8-rc5
>      Delete typedef (suggested by checkpatch.pl)
> 
> V10: https://lkml.org/lkml/2016/7/26/215
>      Drop the "readq" patch.
>      Rebase to latest Linux 4.7.
> 
> V9: https://lkml.org/lkml/2016/7/25/345
>     Improve pr_err message in acpi gtdt driver.
>     Update Commit message for 7/9
>     shorten the irq mapping function name
>     Improve GTDT driver for memory-mapped timer
> 
> v8: https://lkml.org/lkml/2016/7/19/660
>     Improve "pr_fmt(fmt)" definition: add "ACPI" in front of "GTDT",
>     and also improve printk message.
>     Simplify is_timer_block and is_watchdog.
>     Merge acpi_gtdt_desc_init and gtdt_arch_timer_init into acpi_gtdt_init();
>     Delete __init in include/linux/acpi.h for GTDT API
>     Make ARM64 select GTDT.
>     Delete "#include <linux/module.h>" from acpi_gtdt.c
>     Simplify GT block parse code.
> 
> v7: https://lkml.org/lkml/2016/7/13/769
>     Move the GTDT driver to drivers/acpi/arm64
>     Add add the ARM64-specific ACPI Support maintainers in MAINTAINERS
>     Merge 3 patches of GTDT parser driver.
>     Fix the for_each_platform_timer bug.
> 
> v6: https://lkml.org/lkml/2016/6/29/580
>     split the GTDT driver to 4 parts: basic, arch_timer, memory-mapped timer,
>     and SBSA Generic Watchdog timer
>     Improve driver by suggestions and example code from Daniel Lezcano
> 
> v5: https://lkml.org/lkml/2016/5/24/356
>     Sorting out all patches, simplify the API of GTDT driver:
>     GTDT driver just fills the data struct for arm_arch_timer driver.
> 
> v4: https://lists.linaro.org/pipermail/linaro-acpi/2016-March/006667.html
>     Delete the kvm relevant patches
>     Separate two patches for sorting out the code for arm_arch_timer.
>     Improve irq info export code to allow missing irq info in GTDT table.
> 
> v3: https://lkml.org/lkml/2016/2/1/658
>     Improve GTDT driver code:
>       (1)improve pr_* by defining pr_fmt(fmt)
>       (2)simplify gtdt_sbsa_gwdt_init
>       (3)improve gtdt_arch_timer_data_init, if table is NULL, it will try
>       to get GTDT table.
>     Move enum ppi_nr to arm_arch_timer.h, and add enum spi_nr.
>     Add arm_arch_timer get ppi from DT and GTDT support for kvm.
> 
> v2: https://lkml.org/lkml/2015/12/2/10
>     Rebase to latest kernel version(4.4-rc3).
>     Fix the bug about the config problem,
>     use CONFIG_ACPI_GTDT instead of CONFIG_ACPI in arm_arch_timer.c
> 
> v1: The first upstreaming version: https://lkml.org/lkml/2015/10/28/553
> 
> Fu Wei (11):
>   clocksource: arm_arch_timer: add MMIO CNTFRQ helper
>   clocksource: arm_arch_timer: split dt-only rate handling
>   clocksource: arm_arch_timer: refactor arch_timer_needs_probing
>   clocksource: arm_arch_timer: move arch_timer_needs_of_probing into DT
>     init call
>   clocksource: arm_arch_timer: add structs to describe MMIO timer
>   clocksource: arm_arch_timer: refactor MMIO timer probing.
>   acpi/arm64: Add GTDT table parse driver
>   clocksource: arm_arch_timer: simplify ACPI support code.
>   acpi/arm64: Add memory-mapped timer support in GTDT driver
>   clocksource: arm_arch_timer: add GTDT support for memory-mapped timer
>   acpi/arm64: Add SBSA Generic Watchdog support in GTDT driver
> 
>  arch/arm64/Kconfig                   |   1 +
>  drivers/acpi/arm64/Kconfig           |   3 +
>  drivers/acpi/arm64/Makefile          |   1 +
>  drivers/acpi/arm64/gtdt.c            | 406 +++++++++++++++++++++++++++++++++++
>  drivers/clocksource/arm_arch_timer.c | 338 ++++++++++++++++++-----------
>  include/clocksource/arm_arch_timer.h |  16 ++
>  include/linux/acpi.h                 |   7 +
>  7 files changed, 648 insertions(+), 124 deletions(-)
>  create mode 100644 drivers/acpi/arm64/gtdt.c
> 


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

* Re: [PATCH v23 00/11] acpi, clocksource: add GTDT driver and GTDT support in arm_arch_timer
@ 2017-04-01  2:14   ` Xiongfeng Wang
  0 siblings, 0 replies; 66+ messages in thread
From: Xiongfeng Wang @ 2017-04-01  2:14 UTC (permalink / raw)
  To: fu.wei, rjw, lenb, daniel.lezcano, tglx, marc.zyngier,
	mark.rutland, lorenzo.pieralisi, sudeep.holla, hanjun.guo
  Cc: linaro-acpi, catalin.marinas, will.deacon, linux-kernel, wim,
	wei, al.stone, tn, timur, linux-acpi, linux, harba, julien.grall,
	linux-watchdog, arnd, jcm, cov, linux-arm-kernel, graeme.gregory,
	rruigrok, leo.duran, Suravee.Suthikulpanit, christoffer.dall



On 2017/4/1 1:50, fu.wei@linaro.org wrote:
> From: Fu Wei <fu.wei@linaro.org>
> 
> This patchset:
>     (1)Preparation for adding GTDT support in arm_arch_timer:
>         1. Introduce a MMIO CNTFRQ helper.
>         2. separate out device-tree code from arch_timer_detect_rate
>         3. remove arch_timer_detect_rate use arch_timer_*get_cntfrq directly
>         4. Refactor arch_timer_needs_probing, and move it into DT init call
>         5. Introduce some new structs and refactor the MMIO timer init code
>         for reusing some common code.
> 
>     (2)Introduce ACPI GTDT parser: drivers/acpi/arm64/acpi_gtdt.c
>     Parse all kinds of timer in GTDT table of ACPI:arch timer,
>     memory-mapped timer and SBSA Generic Watchdog timer.
>     This driver can help to simplify all the relevant timer drivers,
>     and separate all the ACPI GTDT knowledge from them.
> 
>     (3)Simplify ACPI code for arm_arch_timer
> 
>     (4)Add GTDT support for ARM memory-mapped timer.
> 
> This patchset has been tested on the following platforms with ACPI enabled:
>     (1)ARM Foundation v8 model
> 

for arm_arch_timer(not memory-mapped) and sbsa watchdog part,  Tested-by: wangxiongfeng2@huawei.com





Thanks,

Wang Xiongfeng
.

> Changelog:
> v23: https://lkml.org/lkml/2017/3/31/
>      Rebase to git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arch-timer/cleanup
>      Improve the data struct of arch_timer_mem and arch_timer_mem_frame to
>      improve the parser of GT blocks and arch_timer_mem initualization.
>      Improve arch_timer_rate detection: sysreg frequency is primary in DT boot
>      Improve some comments in GTDT parser driver.
>      Improve acpi_gtdt_init function, and make a comment for the multiple calls.
>      Improve the unwinding for the irq of timers, when an error occurs.
>      Handle the case of virtual timer GSIV is 0.
> 
> v22: https://lkml.org/lkml/2017/3/21/523
>      Rebase to git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arch-timer/cleanup
>      Only Introduce arch_timer_mem_get_cntfrq to get the frequency from mmio.
>      Merged patch 2,3(about arch_timer_detect_rate).
>      Keep arch_timer_rate, do NOT split it for different types of timer.
>      Improve  memory-mapped timer support by comments and variable name:
>          data-->timer_mem
>          frame-->gtdt_frame
>      Delete zero check for SBSA watchdog irq.
>      Skip secure SBSA watchdog in GTDT driver.
>      Delete Kconfig modification for SBSA watchdog driver.
>      Delete no_irq, using nr_res instead.
> 
> v21: https://lkml.org/lkml/2017/2/6/734
>      Introduce two functions to get the frequency from mmio and sysreg.
>      Remove arch_timer_detect_rate use arch_timer_get_*_freq directly
>      Split arch_timer_rate for different types of timer.
>      Skip secure timer frame in GTDT driver.
>      Rebase to git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arch-timer/cleanup
>      (The first 6 patches in v20 have been merged into arch-timer/cleanup branch)
> 
> v20: https://lkml.org/lkml/2017/1/18/534
>      Reorder the first 4 patches and split the 4th patches.
>      Leave CNTHCTL_* as they originally were.
>      Fix the bug in arch_timer_select_ppi.
>      Split "Rework counter frequency detection" patch.
>      Rework the arch_timer_detect_rate function.
>      Improve the commit message of "Refactor MMIO timer probing".
>      Rebase to 4.10.0-rc4
> 
> v19: https://lkml.org/lkml/2016/12/21/25
>      Fix a '\n' missing in a error message in arch_timer_mem_init.
>      Add "request_mem_region" for ioremapping cntbase, according to
>      f947ee1 clocksource/drivers/arm_arch_timer: Map frame with of_io_request_and_map()
>      Rebase to 4.9.0-gfb779ff
> 
> v18: https://lkml.org/lkml/2016/12/8/446
>      Fix 8/15 patch problem of "int ret;" in arch_timer_acpi_init.
>      Rebase to 4.9.0-rc8-g9269898
> 
> v17: https://lkml.org/lkml/2016/11/25/140
>      Take out some cleanups from 4/15.
>      Merge 5/15 and 6/15, improve PPI determination code,
>      improve commit message.
>      Rework counter frequency detection.
>      Move arch_timer_needs_of_probing into DT init call.
>      Move Platform Timer scan loop back to timer init call to avoid allocating
>      and free memory.
>      Improve all the exported functions' comment.
> 
> v16: https://lkml.org/lkml/2016/11/16/268
>      Fix patchset problem about static enum ppi_nr of 01/13 in v15.
>      Refactor arch_timer_detect_rate.
>      Refactor arch_timer_needs_probing.
> 
> v15: https://lkml.org/lkml/2016/11/15/366
>      Re-order patches
>      Add arm_arch_timer refactoring patches to prepare for GTDT:
>          1. rename some  enums and defines, and some cleanups
>          2. separate out arch_timer_uses_ppi init code and fix a potential bug
>          3. Improve some new structs, refactor the timer init code.
>      Since the some structs have been changed, GTDT parser for memory-mapped
>      timer and SBSA Generic Watchdog timer have been update.
> 
> v14: https://lkml.org/lkml/2016/9/28/573
>      Separate memory-mapped timer GTDT support into two patches
>          1. Refactor the timer init code to prepare for GTDT
>          2. Add GTDT support for memory-mapped timer
> 
> v13: http://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1231717.html
>      Improve arm_arch_timer code for memory-mapped
>      timer GTDT support, refactor original memory-mapped timer
>      dt support for reusing some common code.
> 
> v12: https://lkml.org/lkml/2016/9/13/250
>      Rebase to latest Linux 4.8-rc6
>      Delete the confusing "skipping" in the error message.
> 
> V11: https://lkml.org/lkml/2016/9/6/354
>      Rebase to latest Linux 4.8-rc5
>      Delete typedef (suggested by checkpatch.pl)
> 
> V10: https://lkml.org/lkml/2016/7/26/215
>      Drop the "readq" patch.
>      Rebase to latest Linux 4.7.
> 
> V9: https://lkml.org/lkml/2016/7/25/345
>     Improve pr_err message in acpi gtdt driver.
>     Update Commit message for 7/9
>     shorten the irq mapping function name
>     Improve GTDT driver for memory-mapped timer
> 
> v8: https://lkml.org/lkml/2016/7/19/660
>     Improve "pr_fmt(fmt)" definition: add "ACPI" in front of "GTDT",
>     and also improve printk message.
>     Simplify is_timer_block and is_watchdog.
>     Merge acpi_gtdt_desc_init and gtdt_arch_timer_init into acpi_gtdt_init();
>     Delete __init in include/linux/acpi.h for GTDT API
>     Make ARM64 select GTDT.
>     Delete "#include <linux/module.h>" from acpi_gtdt.c
>     Simplify GT block parse code.
> 
> v7: https://lkml.org/lkml/2016/7/13/769
>     Move the GTDT driver to drivers/acpi/arm64
>     Add add the ARM64-specific ACPI Support maintainers in MAINTAINERS
>     Merge 3 patches of GTDT parser driver.
>     Fix the for_each_platform_timer bug.
> 
> v6: https://lkml.org/lkml/2016/6/29/580
>     split the GTDT driver to 4 parts: basic, arch_timer, memory-mapped timer,
>     and SBSA Generic Watchdog timer
>     Improve driver by suggestions and example code from Daniel Lezcano
> 
> v5: https://lkml.org/lkml/2016/5/24/356
>     Sorting out all patches, simplify the API of GTDT driver:
>     GTDT driver just fills the data struct for arm_arch_timer driver.
> 
> v4: https://lists.linaro.org/pipermail/linaro-acpi/2016-March/006667.html
>     Delete the kvm relevant patches
>     Separate two patches for sorting out the code for arm_arch_timer.
>     Improve irq info export code to allow missing irq info in GTDT table.
> 
> v3: https://lkml.org/lkml/2016/2/1/658
>     Improve GTDT driver code:
>       (1)improve pr_* by defining pr_fmt(fmt)
>       (2)simplify gtdt_sbsa_gwdt_init
>       (3)improve gtdt_arch_timer_data_init, if table is NULL, it will try
>       to get GTDT table.
>     Move enum ppi_nr to arm_arch_timer.h, and add enum spi_nr.
>     Add arm_arch_timer get ppi from DT and GTDT support for kvm.
> 
> v2: https://lkml.org/lkml/2015/12/2/10
>     Rebase to latest kernel version(4.4-rc3).
>     Fix the bug about the config problem,
>     use CONFIG_ACPI_GTDT instead of CONFIG_ACPI in arm_arch_timer.c
> 
> v1: The first upstreaming version: https://lkml.org/lkml/2015/10/28/553
> 
> Fu Wei (11):
>   clocksource: arm_arch_timer: add MMIO CNTFRQ helper
>   clocksource: arm_arch_timer: split dt-only rate handling
>   clocksource: arm_arch_timer: refactor arch_timer_needs_probing
>   clocksource: arm_arch_timer: move arch_timer_needs_of_probing into DT
>     init call
>   clocksource: arm_arch_timer: add structs to describe MMIO timer
>   clocksource: arm_arch_timer: refactor MMIO timer probing.
>   acpi/arm64: Add GTDT table parse driver
>   clocksource: arm_arch_timer: simplify ACPI support code.
>   acpi/arm64: Add memory-mapped timer support in GTDT driver
>   clocksource: arm_arch_timer: add GTDT support for memory-mapped timer
>   acpi/arm64: Add SBSA Generic Watchdog support in GTDT driver
> 
>  arch/arm64/Kconfig                   |   1 +
>  drivers/acpi/arm64/Kconfig           |   3 +
>  drivers/acpi/arm64/Makefile          |   1 +
>  drivers/acpi/arm64/gtdt.c            | 406 +++++++++++++++++++++++++++++++++++
>  drivers/clocksource/arm_arch_timer.c | 338 ++++++++++++++++++-----------
>  include/clocksource/arm_arch_timer.h |  16 ++
>  include/linux/acpi.h                 |   7 +
>  7 files changed, 648 insertions(+), 124 deletions(-)
>  create mode 100644 drivers/acpi/arm64/gtdt.c
> 

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

* [PATCH v23 00/11] acpi, clocksource: add GTDT driver and GTDT support in arm_arch_timer
@ 2017-04-01  2:14   ` Xiongfeng Wang
  0 siblings, 0 replies; 66+ messages in thread
From: Xiongfeng Wang @ 2017-04-01  2:14 UTC (permalink / raw)
  To: linux-arm-kernel



On 2017/4/1 1:50, fu.wei at linaro.org wrote:
> From: Fu Wei <fu.wei@linaro.org>
> 
> This patchset:
>     (1)Preparation for adding GTDT support in arm_arch_timer:
>         1. Introduce a MMIO CNTFRQ helper.
>         2. separate out device-tree code from arch_timer_detect_rate
>         3. remove arch_timer_detect_rate use arch_timer_*get_cntfrq directly
>         4. Refactor arch_timer_needs_probing, and move it into DT init call
>         5. Introduce some new structs and refactor the MMIO timer init code
>         for reusing some common code.
> 
>     (2)Introduce ACPI GTDT parser: drivers/acpi/arm64/acpi_gtdt.c
>     Parse all kinds of timer in GTDT table of ACPI:arch timer,
>     memory-mapped timer and SBSA Generic Watchdog timer.
>     This driver can help to simplify all the relevant timer drivers,
>     and separate all the ACPI GTDT knowledge from them.
> 
>     (3)Simplify ACPI code for arm_arch_timer
> 
>     (4)Add GTDT support for ARM memory-mapped timer.
> 
> This patchset has been tested on the following platforms with ACPI enabled:
>     (1)ARM Foundation v8 model
> 

for arm_arch_timer(not memory-mapped) and sbsa watchdog part,  Tested-by: wangxiongfeng2 at huawei.com





Thanks,

Wang Xiongfeng
.

> Changelog:
> v23: https://lkml.org/lkml/2017/3/31/
>      Rebase to git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arch-timer/cleanup
>      Improve the data struct of arch_timer_mem and arch_timer_mem_frame to
>      improve the parser of GT blocks and arch_timer_mem initualization.
>      Improve arch_timer_rate detection: sysreg frequency is primary in DT boot
>      Improve some comments in GTDT parser driver.
>      Improve acpi_gtdt_init function, and make a comment for the multiple calls.
>      Improve the unwinding for the irq of timers, when an error occurs.
>      Handle the case of virtual timer GSIV is 0.
> 
> v22: https://lkml.org/lkml/2017/3/21/523
>      Rebase to git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arch-timer/cleanup
>      Only Introduce arch_timer_mem_get_cntfrq to get the frequency from mmio.
>      Merged patch 2,3(about arch_timer_detect_rate).
>      Keep arch_timer_rate, do NOT split it for different types of timer.
>      Improve  memory-mapped timer support by comments and variable name:
>          data-->timer_mem
>          frame-->gtdt_frame
>      Delete zero check for SBSA watchdog irq.
>      Skip secure SBSA watchdog in GTDT driver.
>      Delete Kconfig modification for SBSA watchdog driver.
>      Delete no_irq, using nr_res instead.
> 
> v21: https://lkml.org/lkml/2017/2/6/734
>      Introduce two functions to get the frequency from mmio and sysreg.
>      Remove arch_timer_detect_rate use arch_timer_get_*_freq directly
>      Split arch_timer_rate for different types of timer.
>      Skip secure timer frame in GTDT driver.
>      Rebase to git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arch-timer/cleanup
>      (The first 6 patches in v20 have been merged into arch-timer/cleanup branch)
> 
> v20: https://lkml.org/lkml/2017/1/18/534
>      Reorder the first 4 patches and split the 4th patches.
>      Leave CNTHCTL_* as they originally were.
>      Fix the bug in arch_timer_select_ppi.
>      Split "Rework counter frequency detection" patch.
>      Rework the arch_timer_detect_rate function.
>      Improve the commit message of "Refactor MMIO timer probing".
>      Rebase to 4.10.0-rc4
> 
> v19: https://lkml.org/lkml/2016/12/21/25
>      Fix a '\n' missing in a error message in arch_timer_mem_init.
>      Add "request_mem_region" for ioremapping cntbase, according to
>      f947ee1 clocksource/drivers/arm_arch_timer: Map frame with of_io_request_and_map()
>      Rebase to 4.9.0-gfb779ff
> 
> v18: https://lkml.org/lkml/2016/12/8/446
>      Fix 8/15 patch problem of "int ret;" in arch_timer_acpi_init.
>      Rebase to 4.9.0-rc8-g9269898
> 
> v17: https://lkml.org/lkml/2016/11/25/140
>      Take out some cleanups from 4/15.
>      Merge 5/15 and 6/15, improve PPI determination code,
>      improve commit message.
>      Rework counter frequency detection.
>      Move arch_timer_needs_of_probing into DT init call.
>      Move Platform Timer scan loop back to timer init call to avoid allocating
>      and free memory.
>      Improve all the exported functions' comment.
> 
> v16: https://lkml.org/lkml/2016/11/16/268
>      Fix patchset problem about static enum ppi_nr of 01/13 in v15.
>      Refactor arch_timer_detect_rate.
>      Refactor arch_timer_needs_probing.
> 
> v15: https://lkml.org/lkml/2016/11/15/366
>      Re-order patches
>      Add arm_arch_timer refactoring patches to prepare for GTDT:
>          1. rename some  enums and defines, and some cleanups
>          2. separate out arch_timer_uses_ppi init code and fix a potential bug
>          3. Improve some new structs, refactor the timer init code.
>      Since the some structs have been changed, GTDT parser for memory-mapped
>      timer and SBSA Generic Watchdog timer have been update.
> 
> v14: https://lkml.org/lkml/2016/9/28/573
>      Separate memory-mapped timer GTDT support into two patches
>          1. Refactor the timer init code to prepare for GTDT
>          2. Add GTDT support for memory-mapped timer
> 
> v13: http://www.mail-archive.com/linux-kernel at vger.kernel.org/msg1231717.html
>      Improve arm_arch_timer code for memory-mapped
>      timer GTDT support, refactor original memory-mapped timer
>      dt support for reusing some common code.
> 
> v12: https://lkml.org/lkml/2016/9/13/250
>      Rebase to latest Linux 4.8-rc6
>      Delete the confusing "skipping" in the error message.
> 
> V11: https://lkml.org/lkml/2016/9/6/354
>      Rebase to latest Linux 4.8-rc5
>      Delete typedef (suggested by checkpatch.pl)
> 
> V10: https://lkml.org/lkml/2016/7/26/215
>      Drop the "readq" patch.
>      Rebase to latest Linux 4.7.
> 
> V9: https://lkml.org/lkml/2016/7/25/345
>     Improve pr_err message in acpi gtdt driver.
>     Update Commit message for 7/9
>     shorten the irq mapping function name
>     Improve GTDT driver for memory-mapped timer
> 
> v8: https://lkml.org/lkml/2016/7/19/660
>     Improve "pr_fmt(fmt)" definition: add "ACPI" in front of "GTDT",
>     and also improve printk message.
>     Simplify is_timer_block and is_watchdog.
>     Merge acpi_gtdt_desc_init and gtdt_arch_timer_init into acpi_gtdt_init();
>     Delete __init in include/linux/acpi.h for GTDT API
>     Make ARM64 select GTDT.
>     Delete "#include <linux/module.h>" from acpi_gtdt.c
>     Simplify GT block parse code.
> 
> v7: https://lkml.org/lkml/2016/7/13/769
>     Move the GTDT driver to drivers/acpi/arm64
>     Add add the ARM64-specific ACPI Support maintainers in MAINTAINERS
>     Merge 3 patches of GTDT parser driver.
>     Fix the for_each_platform_timer bug.
> 
> v6: https://lkml.org/lkml/2016/6/29/580
>     split the GTDT driver to 4 parts: basic, arch_timer, memory-mapped timer,
>     and SBSA Generic Watchdog timer
>     Improve driver by suggestions and example code from Daniel Lezcano
> 
> v5: https://lkml.org/lkml/2016/5/24/356
>     Sorting out all patches, simplify the API of GTDT driver:
>     GTDT driver just fills the data struct for arm_arch_timer driver.
> 
> v4: https://lists.linaro.org/pipermail/linaro-acpi/2016-March/006667.html
>     Delete the kvm relevant patches
>     Separate two patches for sorting out the code for arm_arch_timer.
>     Improve irq info export code to allow missing irq info in GTDT table.
> 
> v3: https://lkml.org/lkml/2016/2/1/658
>     Improve GTDT driver code:
>       (1)improve pr_* by defining pr_fmt(fmt)
>       (2)simplify gtdt_sbsa_gwdt_init
>       (3)improve gtdt_arch_timer_data_init, if table is NULL, it will try
>       to get GTDT table.
>     Move enum ppi_nr to arm_arch_timer.h, and add enum spi_nr.
>     Add arm_arch_timer get ppi from DT and GTDT support for kvm.
> 
> v2: https://lkml.org/lkml/2015/12/2/10
>     Rebase to latest kernel version(4.4-rc3).
>     Fix the bug about the config problem,
>     use CONFIG_ACPI_GTDT instead of CONFIG_ACPI in arm_arch_timer.c
> 
> v1: The first upstreaming version: https://lkml.org/lkml/2015/10/28/553
> 
> Fu Wei (11):
>   clocksource: arm_arch_timer: add MMIO CNTFRQ helper
>   clocksource: arm_arch_timer: split dt-only rate handling
>   clocksource: arm_arch_timer: refactor arch_timer_needs_probing
>   clocksource: arm_arch_timer: move arch_timer_needs_of_probing into DT
>     init call
>   clocksource: arm_arch_timer: add structs to describe MMIO timer
>   clocksource: arm_arch_timer: refactor MMIO timer probing.
>   acpi/arm64: Add GTDT table parse driver
>   clocksource: arm_arch_timer: simplify ACPI support code.
>   acpi/arm64: Add memory-mapped timer support in GTDT driver
>   clocksource: arm_arch_timer: add GTDT support for memory-mapped timer
>   acpi/arm64: Add SBSA Generic Watchdog support in GTDT driver
> 
>  arch/arm64/Kconfig                   |   1 +
>  drivers/acpi/arm64/Kconfig           |   3 +
>  drivers/acpi/arm64/Makefile          |   1 +
>  drivers/acpi/arm64/gtdt.c            | 406 +++++++++++++++++++++++++++++++++++
>  drivers/clocksource/arm_arch_timer.c | 338 ++++++++++++++++++-----------
>  include/clocksource/arm_arch_timer.h |  16 ++
>  include/linux/acpi.h                 |   7 +
>  7 files changed, 648 insertions(+), 124 deletions(-)
>  create mode 100644 drivers/acpi/arm64/gtdt.c
> 

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

* Re: [PATCH v23 00/11] acpi, clocksource: add GTDT driver and GTDT support in arm_arch_timer
  2017-04-01  2:14   ` Xiongfeng Wang
  (?)
@ 2017-04-01  3:49       ` Fu Wei
  -1 siblings, 0 replies; 66+ messages in thread
From: Fu Wei @ 2017-04-01  3:49 UTC (permalink / raw)
  To: Xiongfeng Wang
  Cc: Rafael J. Wysocki, Len Brown, Daniel Lezcano, Thomas Gleixner,
	Marc Zyngier, Mark Rutland, Lorenzo Pieralisi, Sudeep Holla,
	Hanjun Guo, Linaro ACPI Mailman List, Catalin Marinas,
	Will Deacon, Linux Kernel Mailing List, Wim Van Sebroeck,
	Wei Huang, Al Stone, Tomasz Nowicki, Timur Tabi,
	ACPI Devel Maling List

Hi Xiongfeng Wang,

On 1 April 2017 at 10:14, Xiongfeng Wang <wangxiongfeng2-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> wrote:
>
>
> On 2017/4/1 1:50, fu.wei-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org wrote:
>> From: Fu Wei <fu.wei-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
>>
>> This patchset:
>>     (1)Preparation for adding GTDT support in arm_arch_timer:
>>         1. Introduce a MMIO CNTFRQ helper.
>>         2. separate out device-tree code from arch_timer_detect_rate
>>         3. remove arch_timer_detect_rate use arch_timer_*get_cntfrq directly
>>         4. Refactor arch_timer_needs_probing, and move it into DT init call
>>         5. Introduce some new structs and refactor the MMIO timer init code
>>         for reusing some common code.
>>
>>     (2)Introduce ACPI GTDT parser: drivers/acpi/arm64/acpi_gtdt.c
>>     Parse all kinds of timer in GTDT table of ACPI:arch timer,
>>     memory-mapped timer and SBSA Generic Watchdog timer.
>>     This driver can help to simplify all the relevant timer drivers,
>>     and separate all the ACPI GTDT knowledge from them.
>>
>>     (3)Simplify ACPI code for arm_arch_timer
>>
>>     (4)Add GTDT support for ARM memory-mapped timer.
>>
>> This patchset has been tested on the following platforms with ACPI enabled:
>>     (1)ARM Foundation v8 model
>>
>
> for arm_arch_timer(not memory-mapped) and sbsa watchdog part,  Tested-by: wangxiongfeng2-hv44wF8Li93QT0dZR+AlfA@public.gmane.org

Great thanks for your testing :-)

>
>
>
>
>
> Thanks,
>
> Wang Xiongfeng
> .
>
>> Changelog:
>> v23: https://lkml.org/lkml/2017/3/31/
>>      Rebase to git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arch-timer/cleanup
>>      Improve the data struct of arch_timer_mem and arch_timer_mem_frame to
>>      improve the parser of GT blocks and arch_timer_mem initualization.
>>      Improve arch_timer_rate detection: sysreg frequency is primary in DT boot
>>      Improve some comments in GTDT parser driver.
>>      Improve acpi_gtdt_init function, and make a comment for the multiple calls.
>>      Improve the unwinding for the irq of timers, when an error occurs.
>>      Handle the case of virtual timer GSIV is 0.
>>
>> v22: https://lkml.org/lkml/2017/3/21/523
>>      Rebase to git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arch-timer/cleanup
>>      Only Introduce arch_timer_mem_get_cntfrq to get the frequency from mmio.
>>      Merged patch 2,3(about arch_timer_detect_rate).
>>      Keep arch_timer_rate, do NOT split it for different types of timer.
>>      Improve  memory-mapped timer support by comments and variable name:
>>          data-->timer_mem
>>          frame-->gtdt_frame
>>      Delete zero check for SBSA watchdog irq.
>>      Skip secure SBSA watchdog in GTDT driver.
>>      Delete Kconfig modification for SBSA watchdog driver.
>>      Delete no_irq, using nr_res instead.
>>
>> v21: https://lkml.org/lkml/2017/2/6/734
>>      Introduce two functions to get the frequency from mmio and sysreg.
>>      Remove arch_timer_detect_rate use arch_timer_get_*_freq directly
>>      Split arch_timer_rate for different types of timer.
>>      Skip secure timer frame in GTDT driver.
>>      Rebase to git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arch-timer/cleanup
>>      (The first 6 patches in v20 have been merged into arch-timer/cleanup branch)
>>
>> v20: https://lkml.org/lkml/2017/1/18/534
>>      Reorder the first 4 patches and split the 4th patches.
>>      Leave CNTHCTL_* as they originally were.
>>      Fix the bug in arch_timer_select_ppi.
>>      Split "Rework counter frequency detection" patch.
>>      Rework the arch_timer_detect_rate function.
>>      Improve the commit message of "Refactor MMIO timer probing".
>>      Rebase to 4.10.0-rc4
>>
>> v19: https://lkml.org/lkml/2016/12/21/25
>>      Fix a '\n' missing in a error message in arch_timer_mem_init.
>>      Add "request_mem_region" for ioremapping cntbase, according to
>>      f947ee1 clocksource/drivers/arm_arch_timer: Map frame with of_io_request_and_map()
>>      Rebase to 4.9.0-gfb779ff
>>
>> v18: https://lkml.org/lkml/2016/12/8/446
>>      Fix 8/15 patch problem of "int ret;" in arch_timer_acpi_init.
>>      Rebase to 4.9.0-rc8-g9269898
>>
>> v17: https://lkml.org/lkml/2016/11/25/140
>>      Take out some cleanups from 4/15.
>>      Merge 5/15 and 6/15, improve PPI determination code,
>>      improve commit message.
>>      Rework counter frequency detection.
>>      Move arch_timer_needs_of_probing into DT init call.
>>      Move Platform Timer scan loop back to timer init call to avoid allocating
>>      and free memory.
>>      Improve all the exported functions' comment.
>>
>> v16: https://lkml.org/lkml/2016/11/16/268
>>      Fix patchset problem about static enum ppi_nr of 01/13 in v15.
>>      Refactor arch_timer_detect_rate.
>>      Refactor arch_timer_needs_probing.
>>
>> v15: https://lkml.org/lkml/2016/11/15/366
>>      Re-order patches
>>      Add arm_arch_timer refactoring patches to prepare for GTDT:
>>          1. rename some  enums and defines, and some cleanups
>>          2. separate out arch_timer_uses_ppi init code and fix a potential bug
>>          3. Improve some new structs, refactor the timer init code.
>>      Since the some structs have been changed, GTDT parser for memory-mapped
>>      timer and SBSA Generic Watchdog timer have been update.
>>
>> v14: https://lkml.org/lkml/2016/9/28/573
>>      Separate memory-mapped timer GTDT support into two patches
>>          1. Refactor the timer init code to prepare for GTDT
>>          2. Add GTDT support for memory-mapped timer
>>
>> v13: http://www.mail-archive.com/linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org/msg1231717.html
>>      Improve arm_arch_timer code for memory-mapped
>>      timer GTDT support, refactor original memory-mapped timer
>>      dt support for reusing some common code.
>>
>> v12: https://lkml.org/lkml/2016/9/13/250
>>      Rebase to latest Linux 4.8-rc6
>>      Delete the confusing "skipping" in the error message.
>>
>> V11: https://lkml.org/lkml/2016/9/6/354
>>      Rebase to latest Linux 4.8-rc5
>>      Delete typedef (suggested by checkpatch.pl)
>>
>> V10: https://lkml.org/lkml/2016/7/26/215
>>      Drop the "readq" patch.
>>      Rebase to latest Linux 4.7.
>>
>> V9: https://lkml.org/lkml/2016/7/25/345
>>     Improve pr_err message in acpi gtdt driver.
>>     Update Commit message for 7/9
>>     shorten the irq mapping function name
>>     Improve GTDT driver for memory-mapped timer
>>
>> v8: https://lkml.org/lkml/2016/7/19/660
>>     Improve "pr_fmt(fmt)" definition: add "ACPI" in front of "GTDT",
>>     and also improve printk message.
>>     Simplify is_timer_block and is_watchdog.
>>     Merge acpi_gtdt_desc_init and gtdt_arch_timer_init into acpi_gtdt_init();
>>     Delete __init in include/linux/acpi.h for GTDT API
>>     Make ARM64 select GTDT.
>>     Delete "#include <linux/module.h>" from acpi_gtdt.c
>>     Simplify GT block parse code.
>>
>> v7: https://lkml.org/lkml/2016/7/13/769
>>     Move the GTDT driver to drivers/acpi/arm64
>>     Add add the ARM64-specific ACPI Support maintainers in MAINTAINERS
>>     Merge 3 patches of GTDT parser driver.
>>     Fix the for_each_platform_timer bug.
>>
>> v6: https://lkml.org/lkml/2016/6/29/580
>>     split the GTDT driver to 4 parts: basic, arch_timer, memory-mapped timer,
>>     and SBSA Generic Watchdog timer
>>     Improve driver by suggestions and example code from Daniel Lezcano
>>
>> v5: https://lkml.org/lkml/2016/5/24/356
>>     Sorting out all patches, simplify the API of GTDT driver:
>>     GTDT driver just fills the data struct for arm_arch_timer driver.
>>
>> v4: https://lists.linaro.org/pipermail/linaro-acpi/2016-March/006667.html
>>     Delete the kvm relevant patches
>>     Separate two patches for sorting out the code for arm_arch_timer.
>>     Improve irq info export code to allow missing irq info in GTDT table.
>>
>> v3: https://lkml.org/lkml/2016/2/1/658
>>     Improve GTDT driver code:
>>       (1)improve pr_* by defining pr_fmt(fmt)
>>       (2)simplify gtdt_sbsa_gwdt_init
>>       (3)improve gtdt_arch_timer_data_init, if table is NULL, it will try
>>       to get GTDT table.
>>     Move enum ppi_nr to arm_arch_timer.h, and add enum spi_nr.
>>     Add arm_arch_timer get ppi from DT and GTDT support for kvm.
>>
>> v2: https://lkml.org/lkml/2015/12/2/10
>>     Rebase to latest kernel version(4.4-rc3).
>>     Fix the bug about the config problem,
>>     use CONFIG_ACPI_GTDT instead of CONFIG_ACPI in arm_arch_timer.c
>>
>> v1: The first upstreaming version: https://lkml.org/lkml/2015/10/28/553
>>
>> Fu Wei (11):
>>   clocksource: arm_arch_timer: add MMIO CNTFRQ helper
>>   clocksource: arm_arch_timer: split dt-only rate handling
>>   clocksource: arm_arch_timer: refactor arch_timer_needs_probing
>>   clocksource: arm_arch_timer: move arch_timer_needs_of_probing into DT
>>     init call
>>   clocksource: arm_arch_timer: add structs to describe MMIO timer
>>   clocksource: arm_arch_timer: refactor MMIO timer probing.
>>   acpi/arm64: Add GTDT table parse driver
>>   clocksource: arm_arch_timer: simplify ACPI support code.
>>   acpi/arm64: Add memory-mapped timer support in GTDT driver
>>   clocksource: arm_arch_timer: add GTDT support for memory-mapped timer
>>   acpi/arm64: Add SBSA Generic Watchdog support in GTDT driver
>>
>>  arch/arm64/Kconfig                   |   1 +
>>  drivers/acpi/arm64/Kconfig           |   3 +
>>  drivers/acpi/arm64/Makefile          |   1 +
>>  drivers/acpi/arm64/gtdt.c            | 406 +++++++++++++++++++++++++++++++++++
>>  drivers/clocksource/arm_arch_timer.c | 338 ++++++++++++++++++-----------
>>  include/clocksource/arm_arch_timer.h |  16 ++
>>  include/linux/acpi.h                 |   7 +
>>  7 files changed, 648 insertions(+), 124 deletions(-)
>>  create mode 100644 drivers/acpi/arm64/gtdt.c
>>
>



-- 
Best regards,

Fu Wei
Software Engineer
Red Hat
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v23 00/11] acpi, clocksource: add GTDT driver and GTDT support in arm_arch_timer
@ 2017-04-01  3:49       ` Fu Wei
  0 siblings, 0 replies; 66+ messages in thread
From: Fu Wei @ 2017-04-01  3:49 UTC (permalink / raw)
  To: Xiongfeng Wang
  Cc: Rafael J. Wysocki, Len Brown, Daniel Lezcano, Thomas Gleixner,
	Marc Zyngier, Mark Rutland, Lorenzo Pieralisi, Sudeep Holla,
	Hanjun Guo, Linaro ACPI Mailman List, Catalin Marinas,
	Will Deacon, Linux Kernel Mailing List, Wim Van Sebroeck,
	Wei Huang, Al Stone, Tomasz Nowicki, Timur Tabi,
	ACPI Devel Maling List, Guenter Roeck, Abdulhamid, Harb,
	Julien Grall, linux-watchdog, Arnd Bergmann, Jon Masters,
	Christopher Covington, linux-arm-kernel, G Gregory, rruigrok,
	Leo Duran, Suravee Suthikulpanit, Christoffer Dall

Hi Xiongfeng Wang,

On 1 April 2017 at 10:14, Xiongfeng Wang <wangxiongfeng2@huawei.com> wrote:
>
>
> On 2017/4/1 1:50, fu.wei@linaro.org wrote:
>> From: Fu Wei <fu.wei@linaro.org>
>>
>> This patchset:
>>     (1)Preparation for adding GTDT support in arm_arch_timer:
>>         1. Introduce a MMIO CNTFRQ helper.
>>         2. separate out device-tree code from arch_timer_detect_rate
>>         3. remove arch_timer_detect_rate use arch_timer_*get_cntfrq directly
>>         4. Refactor arch_timer_needs_probing, and move it into DT init call
>>         5. Introduce some new structs and refactor the MMIO timer init code
>>         for reusing some common code.
>>
>>     (2)Introduce ACPI GTDT parser: drivers/acpi/arm64/acpi_gtdt.c
>>     Parse all kinds of timer in GTDT table of ACPI:arch timer,
>>     memory-mapped timer and SBSA Generic Watchdog timer.
>>     This driver can help to simplify all the relevant timer drivers,
>>     and separate all the ACPI GTDT knowledge from them.
>>
>>     (3)Simplify ACPI code for arm_arch_timer
>>
>>     (4)Add GTDT support for ARM memory-mapped timer.
>>
>> This patchset has been tested on the following platforms with ACPI enabled:
>>     (1)ARM Foundation v8 model
>>
>
> for arm_arch_timer(not memory-mapped) and sbsa watchdog part,  Tested-by: wangxiongfeng2@huawei.com

Great thanks for your testing :-)

>
>
>
>
>
> Thanks,
>
> Wang Xiongfeng
> .
>
>> Changelog:
>> v23: https://lkml.org/lkml/2017/3/31/
>>      Rebase to git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arch-timer/cleanup
>>      Improve the data struct of arch_timer_mem and arch_timer_mem_frame to
>>      improve the parser of GT blocks and arch_timer_mem initualization.
>>      Improve arch_timer_rate detection: sysreg frequency is primary in DT boot
>>      Improve some comments in GTDT parser driver.
>>      Improve acpi_gtdt_init function, and make a comment for the multiple calls.
>>      Improve the unwinding for the irq of timers, when an error occurs.
>>      Handle the case of virtual timer GSIV is 0.
>>
>> v22: https://lkml.org/lkml/2017/3/21/523
>>      Rebase to git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arch-timer/cleanup
>>      Only Introduce arch_timer_mem_get_cntfrq to get the frequency from mmio.
>>      Merged patch 2,3(about arch_timer_detect_rate).
>>      Keep arch_timer_rate, do NOT split it for different types of timer.
>>      Improve  memory-mapped timer support by comments and variable name:
>>          data-->timer_mem
>>          frame-->gtdt_frame
>>      Delete zero check for SBSA watchdog irq.
>>      Skip secure SBSA watchdog in GTDT driver.
>>      Delete Kconfig modification for SBSA watchdog driver.
>>      Delete no_irq, using nr_res instead.
>>
>> v21: https://lkml.org/lkml/2017/2/6/734
>>      Introduce two functions to get the frequency from mmio and sysreg.
>>      Remove arch_timer_detect_rate use arch_timer_get_*_freq directly
>>      Split arch_timer_rate for different types of timer.
>>      Skip secure timer frame in GTDT driver.
>>      Rebase to git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arch-timer/cleanup
>>      (The first 6 patches in v20 have been merged into arch-timer/cleanup branch)
>>
>> v20: https://lkml.org/lkml/2017/1/18/534
>>      Reorder the first 4 patches and split the 4th patches.
>>      Leave CNTHCTL_* as they originally were.
>>      Fix the bug in arch_timer_select_ppi.
>>      Split "Rework counter frequency detection" patch.
>>      Rework the arch_timer_detect_rate function.
>>      Improve the commit message of "Refactor MMIO timer probing".
>>      Rebase to 4.10.0-rc4
>>
>> v19: https://lkml.org/lkml/2016/12/21/25
>>      Fix a '\n' missing in a error message in arch_timer_mem_init.
>>      Add "request_mem_region" for ioremapping cntbase, according to
>>      f947ee1 clocksource/drivers/arm_arch_timer: Map frame with of_io_request_and_map()
>>      Rebase to 4.9.0-gfb779ff
>>
>> v18: https://lkml.org/lkml/2016/12/8/446
>>      Fix 8/15 patch problem of "int ret;" in arch_timer_acpi_init.
>>      Rebase to 4.9.0-rc8-g9269898
>>
>> v17: https://lkml.org/lkml/2016/11/25/140
>>      Take out some cleanups from 4/15.
>>      Merge 5/15 and 6/15, improve PPI determination code,
>>      improve commit message.
>>      Rework counter frequency detection.
>>      Move arch_timer_needs_of_probing into DT init call.
>>      Move Platform Timer scan loop back to timer init call to avoid allocating
>>      and free memory.
>>      Improve all the exported functions' comment.
>>
>> v16: https://lkml.org/lkml/2016/11/16/268
>>      Fix patchset problem about static enum ppi_nr of 01/13 in v15.
>>      Refactor arch_timer_detect_rate.
>>      Refactor arch_timer_needs_probing.
>>
>> v15: https://lkml.org/lkml/2016/11/15/366
>>      Re-order patches
>>      Add arm_arch_timer refactoring patches to prepare for GTDT:
>>          1. rename some  enums and defines, and some cleanups
>>          2. separate out arch_timer_uses_ppi init code and fix a potential bug
>>          3. Improve some new structs, refactor the timer init code.
>>      Since the some structs have been changed, GTDT parser for memory-mapped
>>      timer and SBSA Generic Watchdog timer have been update.
>>
>> v14: https://lkml.org/lkml/2016/9/28/573
>>      Separate memory-mapped timer GTDT support into two patches
>>          1. Refactor the timer init code to prepare for GTDT
>>          2. Add GTDT support for memory-mapped timer
>>
>> v13: http://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1231717.html
>>      Improve arm_arch_timer code for memory-mapped
>>      timer GTDT support, refactor original memory-mapped timer
>>      dt support for reusing some common code.
>>
>> v12: https://lkml.org/lkml/2016/9/13/250
>>      Rebase to latest Linux 4.8-rc6
>>      Delete the confusing "skipping" in the error message.
>>
>> V11: https://lkml.org/lkml/2016/9/6/354
>>      Rebase to latest Linux 4.8-rc5
>>      Delete typedef (suggested by checkpatch.pl)
>>
>> V10: https://lkml.org/lkml/2016/7/26/215
>>      Drop the "readq" patch.
>>      Rebase to latest Linux 4.7.
>>
>> V9: https://lkml.org/lkml/2016/7/25/345
>>     Improve pr_err message in acpi gtdt driver.
>>     Update Commit message for 7/9
>>     shorten the irq mapping function name
>>     Improve GTDT driver for memory-mapped timer
>>
>> v8: https://lkml.org/lkml/2016/7/19/660
>>     Improve "pr_fmt(fmt)" definition: add "ACPI" in front of "GTDT",
>>     and also improve printk message.
>>     Simplify is_timer_block and is_watchdog.
>>     Merge acpi_gtdt_desc_init and gtdt_arch_timer_init into acpi_gtdt_init();
>>     Delete __init in include/linux/acpi.h for GTDT API
>>     Make ARM64 select GTDT.
>>     Delete "#include <linux/module.h>" from acpi_gtdt.c
>>     Simplify GT block parse code.
>>
>> v7: https://lkml.org/lkml/2016/7/13/769
>>     Move the GTDT driver to drivers/acpi/arm64
>>     Add add the ARM64-specific ACPI Support maintainers in MAINTAINERS
>>     Merge 3 patches of GTDT parser driver.
>>     Fix the for_each_platform_timer bug.
>>
>> v6: https://lkml.org/lkml/2016/6/29/580
>>     split the GTDT driver to 4 parts: basic, arch_timer, memory-mapped timer,
>>     and SBSA Generic Watchdog timer
>>     Improve driver by suggestions and example code from Daniel Lezcano
>>
>> v5: https://lkml.org/lkml/2016/5/24/356
>>     Sorting out all patches, simplify the API of GTDT driver:
>>     GTDT driver just fills the data struct for arm_arch_timer driver.
>>
>> v4: https://lists.linaro.org/pipermail/linaro-acpi/2016-March/006667.html
>>     Delete the kvm relevant patches
>>     Separate two patches for sorting out the code for arm_arch_timer.
>>     Improve irq info export code to allow missing irq info in GTDT table.
>>
>> v3: https://lkml.org/lkml/2016/2/1/658
>>     Improve GTDT driver code:
>>       (1)improve pr_* by defining pr_fmt(fmt)
>>       (2)simplify gtdt_sbsa_gwdt_init
>>       (3)improve gtdt_arch_timer_data_init, if table is NULL, it will try
>>       to get GTDT table.
>>     Move enum ppi_nr to arm_arch_timer.h, and add enum spi_nr.
>>     Add arm_arch_timer get ppi from DT and GTDT support for kvm.
>>
>> v2: https://lkml.org/lkml/2015/12/2/10
>>     Rebase to latest kernel version(4.4-rc3).
>>     Fix the bug about the config problem,
>>     use CONFIG_ACPI_GTDT instead of CONFIG_ACPI in arm_arch_timer.c
>>
>> v1: The first upstreaming version: https://lkml.org/lkml/2015/10/28/553
>>
>> Fu Wei (11):
>>   clocksource: arm_arch_timer: add MMIO CNTFRQ helper
>>   clocksource: arm_arch_timer: split dt-only rate handling
>>   clocksource: arm_arch_timer: refactor arch_timer_needs_probing
>>   clocksource: arm_arch_timer: move arch_timer_needs_of_probing into DT
>>     init call
>>   clocksource: arm_arch_timer: add structs to describe MMIO timer
>>   clocksource: arm_arch_timer: refactor MMIO timer probing.
>>   acpi/arm64: Add GTDT table parse driver
>>   clocksource: arm_arch_timer: simplify ACPI support code.
>>   acpi/arm64: Add memory-mapped timer support in GTDT driver
>>   clocksource: arm_arch_timer: add GTDT support for memory-mapped timer
>>   acpi/arm64: Add SBSA Generic Watchdog support in GTDT driver
>>
>>  arch/arm64/Kconfig                   |   1 +
>>  drivers/acpi/arm64/Kconfig           |   3 +
>>  drivers/acpi/arm64/Makefile          |   1 +
>>  drivers/acpi/arm64/gtdt.c            | 406 +++++++++++++++++++++++++++++++++++
>>  drivers/clocksource/arm_arch_timer.c | 338 ++++++++++++++++++-----------
>>  include/clocksource/arm_arch_timer.h |  16 ++
>>  include/linux/acpi.h                 |   7 +
>>  7 files changed, 648 insertions(+), 124 deletions(-)
>>  create mode 100644 drivers/acpi/arm64/gtdt.c
>>
>



-- 
Best regards,

Fu Wei
Software Engineer
Red Hat

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

* [PATCH v23 00/11] acpi, clocksource: add GTDT driver and GTDT support in arm_arch_timer
@ 2017-04-01  3:49       ` Fu Wei
  0 siblings, 0 replies; 66+ messages in thread
From: Fu Wei @ 2017-04-01  3:49 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Xiongfeng Wang,

On 1 April 2017 at 10:14, Xiongfeng Wang <wangxiongfeng2@huawei.com> wrote:
>
>
> On 2017/4/1 1:50, fu.wei at linaro.org wrote:
>> From: Fu Wei <fu.wei@linaro.org>
>>
>> This patchset:
>>     (1)Preparation for adding GTDT support in arm_arch_timer:
>>         1. Introduce a MMIO CNTFRQ helper.
>>         2. separate out device-tree code from arch_timer_detect_rate
>>         3. remove arch_timer_detect_rate use arch_timer_*get_cntfrq directly
>>         4. Refactor arch_timer_needs_probing, and move it into DT init call
>>         5. Introduce some new structs and refactor the MMIO timer init code
>>         for reusing some common code.
>>
>>     (2)Introduce ACPI GTDT parser: drivers/acpi/arm64/acpi_gtdt.c
>>     Parse all kinds of timer in GTDT table of ACPI:arch timer,
>>     memory-mapped timer and SBSA Generic Watchdog timer.
>>     This driver can help to simplify all the relevant timer drivers,
>>     and separate all the ACPI GTDT knowledge from them.
>>
>>     (3)Simplify ACPI code for arm_arch_timer
>>
>>     (4)Add GTDT support for ARM memory-mapped timer.
>>
>> This patchset has been tested on the following platforms with ACPI enabled:
>>     (1)ARM Foundation v8 model
>>
>
> for arm_arch_timer(not memory-mapped) and sbsa watchdog part,  Tested-by: wangxiongfeng2 at huawei.com

Great thanks for your testing :-)

>
>
>
>
>
> Thanks,
>
> Wang Xiongfeng
> .
>
>> Changelog:
>> v23: https://lkml.org/lkml/2017/3/31/
>>      Rebase to git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arch-timer/cleanup
>>      Improve the data struct of arch_timer_mem and arch_timer_mem_frame to
>>      improve the parser of GT blocks and arch_timer_mem initualization.
>>      Improve arch_timer_rate detection: sysreg frequency is primary in DT boot
>>      Improve some comments in GTDT parser driver.
>>      Improve acpi_gtdt_init function, and make a comment for the multiple calls.
>>      Improve the unwinding for the irq of timers, when an error occurs.
>>      Handle the case of virtual timer GSIV is 0.
>>
>> v22: https://lkml.org/lkml/2017/3/21/523
>>      Rebase to git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arch-timer/cleanup
>>      Only Introduce arch_timer_mem_get_cntfrq to get the frequency from mmio.
>>      Merged patch 2,3(about arch_timer_detect_rate).
>>      Keep arch_timer_rate, do NOT split it for different types of timer.
>>      Improve  memory-mapped timer support by comments and variable name:
>>          data-->timer_mem
>>          frame-->gtdt_frame
>>      Delete zero check for SBSA watchdog irq.
>>      Skip secure SBSA watchdog in GTDT driver.
>>      Delete Kconfig modification for SBSA watchdog driver.
>>      Delete no_irq, using nr_res instead.
>>
>> v21: https://lkml.org/lkml/2017/2/6/734
>>      Introduce two functions to get the frequency from mmio and sysreg.
>>      Remove arch_timer_detect_rate use arch_timer_get_*_freq directly
>>      Split arch_timer_rate for different types of timer.
>>      Skip secure timer frame in GTDT driver.
>>      Rebase to git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arch-timer/cleanup
>>      (The first 6 patches in v20 have been merged into arch-timer/cleanup branch)
>>
>> v20: https://lkml.org/lkml/2017/1/18/534
>>      Reorder the first 4 patches and split the 4th patches.
>>      Leave CNTHCTL_* as they originally were.
>>      Fix the bug in arch_timer_select_ppi.
>>      Split "Rework counter frequency detection" patch.
>>      Rework the arch_timer_detect_rate function.
>>      Improve the commit message of "Refactor MMIO timer probing".
>>      Rebase to 4.10.0-rc4
>>
>> v19: https://lkml.org/lkml/2016/12/21/25
>>      Fix a '\n' missing in a error message in arch_timer_mem_init.
>>      Add "request_mem_region" for ioremapping cntbase, according to
>>      f947ee1 clocksource/drivers/arm_arch_timer: Map frame with of_io_request_and_map()
>>      Rebase to 4.9.0-gfb779ff
>>
>> v18: https://lkml.org/lkml/2016/12/8/446
>>      Fix 8/15 patch problem of "int ret;" in arch_timer_acpi_init.
>>      Rebase to 4.9.0-rc8-g9269898
>>
>> v17: https://lkml.org/lkml/2016/11/25/140
>>      Take out some cleanups from 4/15.
>>      Merge 5/15 and 6/15, improve PPI determination code,
>>      improve commit message.
>>      Rework counter frequency detection.
>>      Move arch_timer_needs_of_probing into DT init call.
>>      Move Platform Timer scan loop back to timer init call to avoid allocating
>>      and free memory.
>>      Improve all the exported functions' comment.
>>
>> v16: https://lkml.org/lkml/2016/11/16/268
>>      Fix patchset problem about static enum ppi_nr of 01/13 in v15.
>>      Refactor arch_timer_detect_rate.
>>      Refactor arch_timer_needs_probing.
>>
>> v15: https://lkml.org/lkml/2016/11/15/366
>>      Re-order patches
>>      Add arm_arch_timer refactoring patches to prepare for GTDT:
>>          1. rename some  enums and defines, and some cleanups
>>          2. separate out arch_timer_uses_ppi init code and fix a potential bug
>>          3. Improve some new structs, refactor the timer init code.
>>      Since the some structs have been changed, GTDT parser for memory-mapped
>>      timer and SBSA Generic Watchdog timer have been update.
>>
>> v14: https://lkml.org/lkml/2016/9/28/573
>>      Separate memory-mapped timer GTDT support into two patches
>>          1. Refactor the timer init code to prepare for GTDT
>>          2. Add GTDT support for memory-mapped timer
>>
>> v13: http://www.mail-archive.com/linux-kernel at vger.kernel.org/msg1231717.html
>>      Improve arm_arch_timer code for memory-mapped
>>      timer GTDT support, refactor original memory-mapped timer
>>      dt support for reusing some common code.
>>
>> v12: https://lkml.org/lkml/2016/9/13/250
>>      Rebase to latest Linux 4.8-rc6
>>      Delete the confusing "skipping" in the error message.
>>
>> V11: https://lkml.org/lkml/2016/9/6/354
>>      Rebase to latest Linux 4.8-rc5
>>      Delete typedef (suggested by checkpatch.pl)
>>
>> V10: https://lkml.org/lkml/2016/7/26/215
>>      Drop the "readq" patch.
>>      Rebase to latest Linux 4.7.
>>
>> V9: https://lkml.org/lkml/2016/7/25/345
>>     Improve pr_err message in acpi gtdt driver.
>>     Update Commit message for 7/9
>>     shorten the irq mapping function name
>>     Improve GTDT driver for memory-mapped timer
>>
>> v8: https://lkml.org/lkml/2016/7/19/660
>>     Improve "pr_fmt(fmt)" definition: add "ACPI" in front of "GTDT",
>>     and also improve printk message.
>>     Simplify is_timer_block and is_watchdog.
>>     Merge acpi_gtdt_desc_init and gtdt_arch_timer_init into acpi_gtdt_init();
>>     Delete __init in include/linux/acpi.h for GTDT API
>>     Make ARM64 select GTDT.
>>     Delete "#include <linux/module.h>" from acpi_gtdt.c
>>     Simplify GT block parse code.
>>
>> v7: https://lkml.org/lkml/2016/7/13/769
>>     Move the GTDT driver to drivers/acpi/arm64
>>     Add add the ARM64-specific ACPI Support maintainers in MAINTAINERS
>>     Merge 3 patches of GTDT parser driver.
>>     Fix the for_each_platform_timer bug.
>>
>> v6: https://lkml.org/lkml/2016/6/29/580
>>     split the GTDT driver to 4 parts: basic, arch_timer, memory-mapped timer,
>>     and SBSA Generic Watchdog timer
>>     Improve driver by suggestions and example code from Daniel Lezcano
>>
>> v5: https://lkml.org/lkml/2016/5/24/356
>>     Sorting out all patches, simplify the API of GTDT driver:
>>     GTDT driver just fills the data struct for arm_arch_timer driver.
>>
>> v4: https://lists.linaro.org/pipermail/linaro-acpi/2016-March/006667.html
>>     Delete the kvm relevant patches
>>     Separate two patches for sorting out the code for arm_arch_timer.
>>     Improve irq info export code to allow missing irq info in GTDT table.
>>
>> v3: https://lkml.org/lkml/2016/2/1/658
>>     Improve GTDT driver code:
>>       (1)improve pr_* by defining pr_fmt(fmt)
>>       (2)simplify gtdt_sbsa_gwdt_init
>>       (3)improve gtdt_arch_timer_data_init, if table is NULL, it will try
>>       to get GTDT table.
>>     Move enum ppi_nr to arm_arch_timer.h, and add enum spi_nr.
>>     Add arm_arch_timer get ppi from DT and GTDT support for kvm.
>>
>> v2: https://lkml.org/lkml/2015/12/2/10
>>     Rebase to latest kernel version(4.4-rc3).
>>     Fix the bug about the config problem,
>>     use CONFIG_ACPI_GTDT instead of CONFIG_ACPI in arm_arch_timer.c
>>
>> v1: The first upstreaming version: https://lkml.org/lkml/2015/10/28/553
>>
>> Fu Wei (11):
>>   clocksource: arm_arch_timer: add MMIO CNTFRQ helper
>>   clocksource: arm_arch_timer: split dt-only rate handling
>>   clocksource: arm_arch_timer: refactor arch_timer_needs_probing
>>   clocksource: arm_arch_timer: move arch_timer_needs_of_probing into DT
>>     init call
>>   clocksource: arm_arch_timer: add structs to describe MMIO timer
>>   clocksource: arm_arch_timer: refactor MMIO timer probing.
>>   acpi/arm64: Add GTDT table parse driver
>>   clocksource: arm_arch_timer: simplify ACPI support code.
>>   acpi/arm64: Add memory-mapped timer support in GTDT driver
>>   clocksource: arm_arch_timer: add GTDT support for memory-mapped timer
>>   acpi/arm64: Add SBSA Generic Watchdog support in GTDT driver
>>
>>  arch/arm64/Kconfig                   |   1 +
>>  drivers/acpi/arm64/Kconfig           |   3 +
>>  drivers/acpi/arm64/Makefile          |   1 +
>>  drivers/acpi/arm64/gtdt.c            | 406 +++++++++++++++++++++++++++++++++++
>>  drivers/clocksource/arm_arch_timer.c | 338 ++++++++++++++++++-----------
>>  include/clocksource/arm_arch_timer.h |  16 ++
>>  include/linux/acpi.h                 |   7 +
>>  7 files changed, 648 insertions(+), 124 deletions(-)
>>  create mode 100644 drivers/acpi/arm64/gtdt.c
>>
>



-- 
Best regards,

Fu Wei
Software Engineer
Red Hat

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

* Re: [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
  2017-03-31 17:51   ` fu.wei at linaro.org
@ 2017-04-03  9:49     ` Will Deacon
  -1 siblings, 0 replies; 66+ messages in thread
From: Will Deacon @ 2017-04-03  9:49 UTC (permalink / raw)
  To: fu.wei
  Cc: rjw, lenb, daniel.lezcano, tglx, marc.zyngier, mark.rutland,
	lorenzo.pieralisi, sudeep.holla, hanjun.guo, linux-arm-kernel,
	linaro-acpi, linux-kernel, linux-acpi, rruigrok, harba, cov,
	timur, graeme.gregory, al.stone, jcm, wei, arnd, catalin.marinas,
	Suravee.Suthikulpanit, leo.duran, wim, linux, linux-watchdog, tn,
	christoffer.dall, julien.grall

On Sat, Apr 01, 2017 at 01:51:03AM +0800, fu.wei@linaro.org wrote:
> From: Fu Wei <fu.wei@linaro.org>
> 
> On platforms booting with ACPI, architected memory-mapped timers'
> configuration data is provided by firmware through the ACPI GTDT
> static table.
> 
> The clocksource architected timer kernel driver requires a firmware
> interface to collect timer configuration and configure its driver.
> this infrastructure is present for device tree systems, but it is
> missing on systems booting with ACPI.
> 
> Implement the kernel infrastructure required to parse the static
> ACPI GTDT table so that the architected timer clocksource driver can
> make use of it on systems booting with ACPI, therefore enabling
> the corresponding timers configuration.
> 
> Signed-off-by: Fu Wei <fu.wei@linaro.org>
> Signed-off-by: Hanjun Guo <hanjun.guo@linaro.org>
> ---
>  drivers/acpi/arm64/gtdt.c | 146 ++++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/acpi.h      |   1 +
>  2 files changed, 147 insertions(+)

We need Lorenzo's ack on this.

Will

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

* [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
@ 2017-04-03  9:49     ` Will Deacon
  0 siblings, 0 replies; 66+ messages in thread
From: Will Deacon @ 2017-04-03  9:49 UTC (permalink / raw)
  To: linux-arm-kernel

On Sat, Apr 01, 2017 at 01:51:03AM +0800, fu.wei at linaro.org wrote:
> From: Fu Wei <fu.wei@linaro.org>
> 
> On platforms booting with ACPI, architected memory-mapped timers'
> configuration data is provided by firmware through the ACPI GTDT
> static table.
> 
> The clocksource architected timer kernel driver requires a firmware
> interface to collect timer configuration and configure its driver.
> this infrastructure is present for device tree systems, but it is
> missing on systems booting with ACPI.
> 
> Implement the kernel infrastructure required to parse the static
> ACPI GTDT table so that the architected timer clocksource driver can
> make use of it on systems booting with ACPI, therefore enabling
> the corresponding timers configuration.
> 
> Signed-off-by: Fu Wei <fu.wei@linaro.org>
> Signed-off-by: Hanjun Guo <hanjun.guo@linaro.org>
> ---
>  drivers/acpi/arm64/gtdt.c | 146 ++++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/acpi.h      |   1 +
>  2 files changed, 147 insertions(+)

We need Lorenzo's ack on this.

Will

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

* Re: [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
  2017-03-31 17:51   ` fu.wei at linaro.org
  (?)
@ 2017-04-03 10:45       ` Lorenzo Pieralisi
  -1 siblings, 0 replies; 66+ messages in thread
From: Lorenzo Pieralisi @ 2017-04-03 10:45 UTC (permalink / raw)
  To: fu.wei-QSEj5FYQhm4dnm+yROfE0A
  Cc: rjw-LthD3rsA81gm4RdzfppkhA, lenb-DgEjT+Ai2ygdnm+yROfE0A,
	daniel.lezcano-QSEj5FYQhm4dnm+yROfE0A,
	tglx-hfZtesqFncYOwBW4kG4KsQ, marc.zyngier-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, sudeep.holla-5wv7dgnIgG8,
	hanjun.guo-QSEj5FYQhm4dnm+yROfE0A,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linaro-acpi-cunTk1MwBs8s++Sfvej+rw,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-acpi-u79uwXL29TY76Z2rM5mHXA,
	rruigrok-sgV2jX0FEOL9JmXXK+q4OQ, harba-sgV2jX0FEOL9JmXXK+q4OQ,
	cov-sgV2jX0FEOL9JmXXK+q4OQ, timur-sgV2jX0FEOL9JmXXK+q4OQ,
	graeme.gregory-QSEj5FYQhm4dnm+yROfE0A,
	al.stone-QSEj5FYQhm4dnm+yROfE0A, jcm-H+wXaHxf7aLQT0dZR+AlfA,
	wei-H+wXaHxf7aLQT0dZR+AlfA, arnd-r2nGTMty4D4,
	catalin.marinas-5wv7dgnIgG8, will.deacon-5wv7dgnIgG8,
	Suravee.Suthikulpanit-5C7GfCeVMHo, leo.duran-5C7GfCeVMHo,
	wim-IQzOog9fTRqzQB+pC5nmwQ, linux-0h96xk9xTtrk1uMJSBkQmQ,
	linux-watchdog-u79uwXL29TY76Z2rM5mHXA, tn-nYOzD4b6Jr9Wk0Htik3J/w,
	christoffer.dall-QSEj5FYQhm4dnm+yROfE0A,
	julien.grall-5wv7dgnIgG8

On Sat, Apr 01, 2017 at 01:51:03AM +0800, fu.wei-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org wrote:
> From: Fu Wei <fu.wei-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> 
> On platforms booting with ACPI, architected memory-mapped timers'
> configuration data is provided by firmware through the ACPI GTDT
> static table.
> 
> The clocksource architected timer kernel driver requires a firmware
> interface to collect timer configuration and configure its driver.
> this infrastructure is present for device tree systems, but it is
> missing on systems booting with ACPI.
> 
> Implement the kernel infrastructure required to parse the static
> ACPI GTDT table so that the architected timer clocksource driver can
> make use of it on systems booting with ACPI, therefore enabling
> the corresponding timers configuration.
> 
> Signed-off-by: Fu Wei <fu.wei-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> Signed-off-by: Hanjun Guo <hanjun.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> ---
>  drivers/acpi/arm64/gtdt.c | 146 ++++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/acpi.h      |   1 +
>  2 files changed, 147 insertions(+)
> 
> diff --git a/drivers/acpi/arm64/gtdt.c b/drivers/acpi/arm64/gtdt.c
> index 3d95af8..3dd33f3 100644
> --- a/drivers/acpi/arm64/gtdt.c
> +++ b/drivers/acpi/arm64/gtdt.c
> @@ -13,6 +13,7 @@
>  
>  #include <linux/acpi.h>
>  #include <linux/init.h>
> +#include <linux/irqdomain.h>
>  #include <linux/kernel.h>
>  
>  #include <clocksource/arm_arch_timer.h>
> @@ -37,6 +38,28 @@ struct acpi_gtdt_descriptor {
>  
>  static struct acpi_gtdt_descriptor acpi_gtdt_desc __initdata;
>  
> +static inline void *next_platform_timer(void *platform_timer)
> +{
> +	struct acpi_gtdt_header *gh = platform_timer;
> +
> +	platform_timer += gh->length;
> +	if (platform_timer < acpi_gtdt_desc.gtdt_end)
> +		return platform_timer;
> +
> +	return NULL;
> +}
> +
> +#define for_each_platform_timer(_g)				\
> +	for (_g = acpi_gtdt_desc.platform_timer; _g;	\
> +	     _g = next_platform_timer(_g))
> +
> +static inline bool is_timer_block(void *platform_timer)
> +{
> +	struct acpi_gtdt_header *gh = platform_timer;
> +
> +	return gh->type == ACPI_GTDT_TYPE_TIMER_BLOCK;
> +}
> +
>  static int __init map_gt_gsi(u32 interrupt, u32 flags)
>  {
>  	int trigger, polarity;
> @@ -155,3 +178,126 @@ int __init acpi_gtdt_init(struct acpi_table_header *table,
>  
>  	return 0;
>  }
> +
> +static int __init gtdt_parse_timer_block(struct acpi_gtdt_timer_block *block,
> +					 struct arch_timer_mem *timer_mem)
> +{
> +	int i;
> +	struct arch_timer_mem_frame *frame;
> +	struct acpi_gtdt_timer_entry *gtdt_frame;
> +
> +	if (!block->timer_count) {
> +		pr_err(FW_BUG "GT block present, but frame count is zero.");
> +		return -ENODEV;
> +	}
> +
> +	if (block->timer_count > ARCH_TIMER_MEM_MAX_FRAMES) {
> +		pr_err(FW_BUG "GT block lists %d frames, ACPI spec only allows 8\n",
> +		       block->timer_count);
> +		return -EINVAL;
> +	}
> +
> +	timer_mem->cntctlbase = (phys_addr_t)block->block_address;
> +	/*
> +	 * The CNTCTLBase frame is 4KB (register offsets 0x000 - 0xFFC).
> +	 * See ARM DDI 0487A.k_iss10775, page I1-5129, Table I1-3
> +	 * "CNTCTLBase memory map".
> +	 */
> +	timer_mem->size = SZ_4K;
> +
> +	gtdt_frame = (void *)block + block->timer_offset;
> +	if (gtdt_frame + block->timer_count != (void *)block + block->header.length)
> +		return -EINVAL;
> +
> +	/*
> +	 * Get the GT timer Frame data for every GT Block Timer
> +	 */
> +	for (i = 0; i < block->timer_count; i++, gtdt_frame++) {
> +		if (gtdt_frame->common_flags & ACPI_GTDT_GT_IS_SECURE_TIMER)
> +			continue;
> +
> +		if (!gtdt_frame->base_address || !gtdt_frame->timer_interrupt)
> +			goto error;
> +
> +		frame = &timer_mem->frame[gtdt_frame->frame_number];
> +		frame->phys_irq = map_gt_gsi(gtdt_frame->timer_interrupt,
> +					     gtdt_frame->timer_flags);
> +		if (frame->phys_irq <= 0) {
> +			pr_warn("failed to map physical timer irq in frame %d.\n",
> +				gtdt_frame->frame_number);
> +			goto error;
> +		}
> +
> +		if (gtdt_frame->virtual_timer_interrupt) {
> +			frame->virt_irq =
> +				map_gt_gsi(gtdt_frame->virtual_timer_interrupt,
> +					   gtdt_frame->virtual_timer_flags);
> +			if (frame->virt_irq <= 0) {
> +				pr_warn("failed to map virtual timer irq in frame %d.\n",
> +					gtdt_frame->frame_number);
> +				acpi_unregister_gsi(gtdt_frame->timer_interrupt);
> +				goto error;
> +			}
> +		} else {
> +			frame->virt_irq = 0;
> +			pr_debug("virtual timer in frame %d not implemented.\n",
> +				 gtdt_frame->frame_number);
> +		}
> +
> +		frame->cntbase = gtdt_frame->base_address;
> +		/*
> +		 * The CNTBaseN frame is 4KB (register offsets 0x000 - 0xFFC).
> +		 * See ARM DDI 0487A.k_iss10775, page I1-5130, Table I1-4
> +		 * "CNTBaseN memory map".
> +		 */
> +		frame->size = SZ_4K;
> +		frame->valid = true;
> +	}
> +
> +	return 0;
> +
> +error:
> +	for (i = 0; i < ARCH_TIMER_MEM_MAX_FRAMES; i++) {
> +		frame = &timer_mem->frame[i];
> +		if (!frame->valid)
> +			continue;
> +		irq_dispose_mapping(frame->phys_irq);
> +		if (frame->virt_irq)
> +			irq_dispose_mapping(frame->virt_irq);
> +	}

You should unregister GSIs with the same API you use to register GSIs,
I do not like code that assumes acpi_unregister_gsi() internal
implementation, it is wrong to do that.

Other than that patch is ok:

Acked-by: Lorenzo Pieralisi <lorenzo.pieralisi-5wv7dgnIgG8@public.gmane.org>

> +	return -EINVAL;
> +}
> +
> +/**
> + * acpi_arch_timer_mem_init() - Get the info of all GT blocks in GTDT table.
> + * @timer_mem:	The pointer to the array of struct arch_timer_mem for returning
> + *		the result of parsing. The element number of this array should
> + *		be platform_timer_count(the total number of platform timers).
> + * @timer_count: It points to a integer variable which is used for storing the
> + *		number of GT blocks we have parsed.
> + *
> + * Return: 0 if success, -EINVAL/-ENODEV if error.
> + */
> +int __init acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem,
> +				    int *timer_count)
> +{
> +	int ret;
> +	void *platform_timer;
> +
> +	*timer_count = 0;
> +	for_each_platform_timer(platform_timer) {
> +		if (is_timer_block(platform_timer)) {
> +			ret = gtdt_parse_timer_block(platform_timer, timer_mem);
> +			if (ret)
> +				return ret;
> +			timer_mem++;
> +			(*timer_count)++;
> +		}
> +	}
> +
> +	if (*timer_count)
> +		pr_info("found %d memory-mapped timer block(s).\n",
> +			*timer_count);
> +
> +	return 0;
> +}
> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
> index 4b5c146..3193724 100644
> --- a/include/linux/acpi.h
> +++ b/include/linux/acpi.h
> @@ -599,6 +599,7 @@ int acpi_reconfig_notifier_unregister(struct notifier_block *nb);
>  int acpi_gtdt_init(struct acpi_table_header *table, int *platform_timer_count);
>  int acpi_gtdt_map_ppi(int type);
>  bool acpi_gtdt_c3stop(int type);
> +int acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem, int *timer_count);
>  #endif
>  
>  #else	/* !CONFIG_ACPI */
> -- 
> 2.9.3
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
@ 2017-04-03 10:45       ` Lorenzo Pieralisi
  0 siblings, 0 replies; 66+ messages in thread
From: Lorenzo Pieralisi @ 2017-04-03 10:45 UTC (permalink / raw)
  To: fu.wei
  Cc: rjw, lenb, daniel.lezcano, tglx, marc.zyngier, mark.rutland,
	sudeep.holla, hanjun.guo, linux-arm-kernel, linaro-acpi,
	linux-kernel, linux-acpi, rruigrok, harba, cov, timur,
	graeme.gregory, al.stone, jcm, wei, arnd, catalin.marinas,
	will.deacon, Suravee.Suthikulpanit, leo.duran, wim, linux,
	linux-watchdog, tn, christoffer.dall, julien.grall

On Sat, Apr 01, 2017 at 01:51:03AM +0800, fu.wei@linaro.org wrote:
> From: Fu Wei <fu.wei@linaro.org>
> 
> On platforms booting with ACPI, architected memory-mapped timers'
> configuration data is provided by firmware through the ACPI GTDT
> static table.
> 
> The clocksource architected timer kernel driver requires a firmware
> interface to collect timer configuration and configure its driver.
> this infrastructure is present for device tree systems, but it is
> missing on systems booting with ACPI.
> 
> Implement the kernel infrastructure required to parse the static
> ACPI GTDT table so that the architected timer clocksource driver can
> make use of it on systems booting with ACPI, therefore enabling
> the corresponding timers configuration.
> 
> Signed-off-by: Fu Wei <fu.wei@linaro.org>
> Signed-off-by: Hanjun Guo <hanjun.guo@linaro.org>
> ---
>  drivers/acpi/arm64/gtdt.c | 146 ++++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/acpi.h      |   1 +
>  2 files changed, 147 insertions(+)
> 
> diff --git a/drivers/acpi/arm64/gtdt.c b/drivers/acpi/arm64/gtdt.c
> index 3d95af8..3dd33f3 100644
> --- a/drivers/acpi/arm64/gtdt.c
> +++ b/drivers/acpi/arm64/gtdt.c
> @@ -13,6 +13,7 @@
>  
>  #include <linux/acpi.h>
>  #include <linux/init.h>
> +#include <linux/irqdomain.h>
>  #include <linux/kernel.h>
>  
>  #include <clocksource/arm_arch_timer.h>
> @@ -37,6 +38,28 @@ struct acpi_gtdt_descriptor {
>  
>  static struct acpi_gtdt_descriptor acpi_gtdt_desc __initdata;
>  
> +static inline void *next_platform_timer(void *platform_timer)
> +{
> +	struct acpi_gtdt_header *gh = platform_timer;
> +
> +	platform_timer += gh->length;
> +	if (platform_timer < acpi_gtdt_desc.gtdt_end)
> +		return platform_timer;
> +
> +	return NULL;
> +}
> +
> +#define for_each_platform_timer(_g)				\
> +	for (_g = acpi_gtdt_desc.platform_timer; _g;	\
> +	     _g = next_platform_timer(_g))
> +
> +static inline bool is_timer_block(void *platform_timer)
> +{
> +	struct acpi_gtdt_header *gh = platform_timer;
> +
> +	return gh->type == ACPI_GTDT_TYPE_TIMER_BLOCK;
> +}
> +
>  static int __init map_gt_gsi(u32 interrupt, u32 flags)
>  {
>  	int trigger, polarity;
> @@ -155,3 +178,126 @@ int __init acpi_gtdt_init(struct acpi_table_header *table,
>  
>  	return 0;
>  }
> +
> +static int __init gtdt_parse_timer_block(struct acpi_gtdt_timer_block *block,
> +					 struct arch_timer_mem *timer_mem)
> +{
> +	int i;
> +	struct arch_timer_mem_frame *frame;
> +	struct acpi_gtdt_timer_entry *gtdt_frame;
> +
> +	if (!block->timer_count) {
> +		pr_err(FW_BUG "GT block present, but frame count is zero.");
> +		return -ENODEV;
> +	}
> +
> +	if (block->timer_count > ARCH_TIMER_MEM_MAX_FRAMES) {
> +		pr_err(FW_BUG "GT block lists %d frames, ACPI spec only allows 8\n",
> +		       block->timer_count);
> +		return -EINVAL;
> +	}
> +
> +	timer_mem->cntctlbase = (phys_addr_t)block->block_address;
> +	/*
> +	 * The CNTCTLBase frame is 4KB (register offsets 0x000 - 0xFFC).
> +	 * See ARM DDI 0487A.k_iss10775, page I1-5129, Table I1-3
> +	 * "CNTCTLBase memory map".
> +	 */
> +	timer_mem->size = SZ_4K;
> +
> +	gtdt_frame = (void *)block + block->timer_offset;
> +	if (gtdt_frame + block->timer_count != (void *)block + block->header.length)
> +		return -EINVAL;
> +
> +	/*
> +	 * Get the GT timer Frame data for every GT Block Timer
> +	 */
> +	for (i = 0; i < block->timer_count; i++, gtdt_frame++) {
> +		if (gtdt_frame->common_flags & ACPI_GTDT_GT_IS_SECURE_TIMER)
> +			continue;
> +
> +		if (!gtdt_frame->base_address || !gtdt_frame->timer_interrupt)
> +			goto error;
> +
> +		frame = &timer_mem->frame[gtdt_frame->frame_number];
> +		frame->phys_irq = map_gt_gsi(gtdt_frame->timer_interrupt,
> +					     gtdt_frame->timer_flags);
> +		if (frame->phys_irq <= 0) {
> +			pr_warn("failed to map physical timer irq in frame %d.\n",
> +				gtdt_frame->frame_number);
> +			goto error;
> +		}
> +
> +		if (gtdt_frame->virtual_timer_interrupt) {
> +			frame->virt_irq =
> +				map_gt_gsi(gtdt_frame->virtual_timer_interrupt,
> +					   gtdt_frame->virtual_timer_flags);
> +			if (frame->virt_irq <= 0) {
> +				pr_warn("failed to map virtual timer irq in frame %d.\n",
> +					gtdt_frame->frame_number);
> +				acpi_unregister_gsi(gtdt_frame->timer_interrupt);
> +				goto error;
> +			}
> +		} else {
> +			frame->virt_irq = 0;
> +			pr_debug("virtual timer in frame %d not implemented.\n",
> +				 gtdt_frame->frame_number);
> +		}
> +
> +		frame->cntbase = gtdt_frame->base_address;
> +		/*
> +		 * The CNTBaseN frame is 4KB (register offsets 0x000 - 0xFFC).
> +		 * See ARM DDI 0487A.k_iss10775, page I1-5130, Table I1-4
> +		 * "CNTBaseN memory map".
> +		 */
> +		frame->size = SZ_4K;
> +		frame->valid = true;
> +	}
> +
> +	return 0;
> +
> +error:
> +	for (i = 0; i < ARCH_TIMER_MEM_MAX_FRAMES; i++) {
> +		frame = &timer_mem->frame[i];
> +		if (!frame->valid)
> +			continue;
> +		irq_dispose_mapping(frame->phys_irq);
> +		if (frame->virt_irq)
> +			irq_dispose_mapping(frame->virt_irq);
> +	}

You should unregister GSIs with the same API you use to register GSIs,
I do not like code that assumes acpi_unregister_gsi() internal
implementation, it is wrong to do that.

Other than that patch is ok:

Acked-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>

> +	return -EINVAL;
> +}
> +
> +/**
> + * acpi_arch_timer_mem_init() - Get the info of all GT blocks in GTDT table.
> + * @timer_mem:	The pointer to the array of struct arch_timer_mem for returning
> + *		the result of parsing. The element number of this array should
> + *		be platform_timer_count(the total number of platform timers).
> + * @timer_count: It points to a integer variable which is used for storing the
> + *		number of GT blocks we have parsed.
> + *
> + * Return: 0 if success, -EINVAL/-ENODEV if error.
> + */
> +int __init acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem,
> +				    int *timer_count)
> +{
> +	int ret;
> +	void *platform_timer;
> +
> +	*timer_count = 0;
> +	for_each_platform_timer(platform_timer) {
> +		if (is_timer_block(platform_timer)) {
> +			ret = gtdt_parse_timer_block(platform_timer, timer_mem);
> +			if (ret)
> +				return ret;
> +			timer_mem++;
> +			(*timer_count)++;
> +		}
> +	}
> +
> +	if (*timer_count)
> +		pr_info("found %d memory-mapped timer block(s).\n",
> +			*timer_count);
> +
> +	return 0;
> +}
> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
> index 4b5c146..3193724 100644
> --- a/include/linux/acpi.h
> +++ b/include/linux/acpi.h
> @@ -599,6 +599,7 @@ int acpi_reconfig_notifier_unregister(struct notifier_block *nb);
>  int acpi_gtdt_init(struct acpi_table_header *table, int *platform_timer_count);
>  int acpi_gtdt_map_ppi(int type);
>  bool acpi_gtdt_c3stop(int type);
> +int acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem, int *timer_count);
>  #endif
>  
>  #else	/* !CONFIG_ACPI */
> -- 
> 2.9.3
> 

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

* [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
@ 2017-04-03 10:45       ` Lorenzo Pieralisi
  0 siblings, 0 replies; 66+ messages in thread
From: Lorenzo Pieralisi @ 2017-04-03 10:45 UTC (permalink / raw)
  To: linux-arm-kernel

On Sat, Apr 01, 2017 at 01:51:03AM +0800, fu.wei at linaro.org wrote:
> From: Fu Wei <fu.wei@linaro.org>
> 
> On platforms booting with ACPI, architected memory-mapped timers'
> configuration data is provided by firmware through the ACPI GTDT
> static table.
> 
> The clocksource architected timer kernel driver requires a firmware
> interface to collect timer configuration and configure its driver.
> this infrastructure is present for device tree systems, but it is
> missing on systems booting with ACPI.
> 
> Implement the kernel infrastructure required to parse the static
> ACPI GTDT table so that the architected timer clocksource driver can
> make use of it on systems booting with ACPI, therefore enabling
> the corresponding timers configuration.
> 
> Signed-off-by: Fu Wei <fu.wei@linaro.org>
> Signed-off-by: Hanjun Guo <hanjun.guo@linaro.org>
> ---
>  drivers/acpi/arm64/gtdt.c | 146 ++++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/acpi.h      |   1 +
>  2 files changed, 147 insertions(+)
> 
> diff --git a/drivers/acpi/arm64/gtdt.c b/drivers/acpi/arm64/gtdt.c
> index 3d95af8..3dd33f3 100644
> --- a/drivers/acpi/arm64/gtdt.c
> +++ b/drivers/acpi/arm64/gtdt.c
> @@ -13,6 +13,7 @@
>  
>  #include <linux/acpi.h>
>  #include <linux/init.h>
> +#include <linux/irqdomain.h>
>  #include <linux/kernel.h>
>  
>  #include <clocksource/arm_arch_timer.h>
> @@ -37,6 +38,28 @@ struct acpi_gtdt_descriptor {
>  
>  static struct acpi_gtdt_descriptor acpi_gtdt_desc __initdata;
>  
> +static inline void *next_platform_timer(void *platform_timer)
> +{
> +	struct acpi_gtdt_header *gh = platform_timer;
> +
> +	platform_timer += gh->length;
> +	if (platform_timer < acpi_gtdt_desc.gtdt_end)
> +		return platform_timer;
> +
> +	return NULL;
> +}
> +
> +#define for_each_platform_timer(_g)				\
> +	for (_g = acpi_gtdt_desc.platform_timer; _g;	\
> +	     _g = next_platform_timer(_g))
> +
> +static inline bool is_timer_block(void *platform_timer)
> +{
> +	struct acpi_gtdt_header *gh = platform_timer;
> +
> +	return gh->type == ACPI_GTDT_TYPE_TIMER_BLOCK;
> +}
> +
>  static int __init map_gt_gsi(u32 interrupt, u32 flags)
>  {
>  	int trigger, polarity;
> @@ -155,3 +178,126 @@ int __init acpi_gtdt_init(struct acpi_table_header *table,
>  
>  	return 0;
>  }
> +
> +static int __init gtdt_parse_timer_block(struct acpi_gtdt_timer_block *block,
> +					 struct arch_timer_mem *timer_mem)
> +{
> +	int i;
> +	struct arch_timer_mem_frame *frame;
> +	struct acpi_gtdt_timer_entry *gtdt_frame;
> +
> +	if (!block->timer_count) {
> +		pr_err(FW_BUG "GT block present, but frame count is zero.");
> +		return -ENODEV;
> +	}
> +
> +	if (block->timer_count > ARCH_TIMER_MEM_MAX_FRAMES) {
> +		pr_err(FW_BUG "GT block lists %d frames, ACPI spec only allows 8\n",
> +		       block->timer_count);
> +		return -EINVAL;
> +	}
> +
> +	timer_mem->cntctlbase = (phys_addr_t)block->block_address;
> +	/*
> +	 * The CNTCTLBase frame is 4KB (register offsets 0x000 - 0xFFC).
> +	 * See ARM DDI 0487A.k_iss10775, page I1-5129, Table I1-3
> +	 * "CNTCTLBase memory map".
> +	 */
> +	timer_mem->size = SZ_4K;
> +
> +	gtdt_frame = (void *)block + block->timer_offset;
> +	if (gtdt_frame + block->timer_count != (void *)block + block->header.length)
> +		return -EINVAL;
> +
> +	/*
> +	 * Get the GT timer Frame data for every GT Block Timer
> +	 */
> +	for (i = 0; i < block->timer_count; i++, gtdt_frame++) {
> +		if (gtdt_frame->common_flags & ACPI_GTDT_GT_IS_SECURE_TIMER)
> +			continue;
> +
> +		if (!gtdt_frame->base_address || !gtdt_frame->timer_interrupt)
> +			goto error;
> +
> +		frame = &timer_mem->frame[gtdt_frame->frame_number];
> +		frame->phys_irq = map_gt_gsi(gtdt_frame->timer_interrupt,
> +					     gtdt_frame->timer_flags);
> +		if (frame->phys_irq <= 0) {
> +			pr_warn("failed to map physical timer irq in frame %d.\n",
> +				gtdt_frame->frame_number);
> +			goto error;
> +		}
> +
> +		if (gtdt_frame->virtual_timer_interrupt) {
> +			frame->virt_irq =
> +				map_gt_gsi(gtdt_frame->virtual_timer_interrupt,
> +					   gtdt_frame->virtual_timer_flags);
> +			if (frame->virt_irq <= 0) {
> +				pr_warn("failed to map virtual timer irq in frame %d.\n",
> +					gtdt_frame->frame_number);
> +				acpi_unregister_gsi(gtdt_frame->timer_interrupt);
> +				goto error;
> +			}
> +		} else {
> +			frame->virt_irq = 0;
> +			pr_debug("virtual timer in frame %d not implemented.\n",
> +				 gtdt_frame->frame_number);
> +		}
> +
> +		frame->cntbase = gtdt_frame->base_address;
> +		/*
> +		 * The CNTBaseN frame is 4KB (register offsets 0x000 - 0xFFC).
> +		 * See ARM DDI 0487A.k_iss10775, page I1-5130, Table I1-4
> +		 * "CNTBaseN memory map".
> +		 */
> +		frame->size = SZ_4K;
> +		frame->valid = true;
> +	}
> +
> +	return 0;
> +
> +error:
> +	for (i = 0; i < ARCH_TIMER_MEM_MAX_FRAMES; i++) {
> +		frame = &timer_mem->frame[i];
> +		if (!frame->valid)
> +			continue;
> +		irq_dispose_mapping(frame->phys_irq);
> +		if (frame->virt_irq)
> +			irq_dispose_mapping(frame->virt_irq);
> +	}

You should unregister GSIs with the same API you use to register GSIs,
I do not like code that assumes acpi_unregister_gsi() internal
implementation, it is wrong to do that.

Other than that patch is ok:

Acked-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>

> +	return -EINVAL;
> +}
> +
> +/**
> + * acpi_arch_timer_mem_init() - Get the info of all GT blocks in GTDT table.
> + * @timer_mem:	The pointer to the array of struct arch_timer_mem for returning
> + *		the result of parsing. The element number of this array should
> + *		be platform_timer_count(the total number of platform timers).
> + * @timer_count: It points to a integer variable which is used for storing the
> + *		number of GT blocks we have parsed.
> + *
> + * Return: 0 if success, -EINVAL/-ENODEV if error.
> + */
> +int __init acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem,
> +				    int *timer_count)
> +{
> +	int ret;
> +	void *platform_timer;
> +
> +	*timer_count = 0;
> +	for_each_platform_timer(platform_timer) {
> +		if (is_timer_block(platform_timer)) {
> +			ret = gtdt_parse_timer_block(platform_timer, timer_mem);
> +			if (ret)
> +				return ret;
> +			timer_mem++;
> +			(*timer_count)++;
> +		}
> +	}
> +
> +	if (*timer_count)
> +		pr_info("found %d memory-mapped timer block(s).\n",
> +			*timer_count);
> +
> +	return 0;
> +}
> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
> index 4b5c146..3193724 100644
> --- a/include/linux/acpi.h
> +++ b/include/linux/acpi.h
> @@ -599,6 +599,7 @@ int acpi_reconfig_notifier_unregister(struct notifier_block *nb);
>  int acpi_gtdt_init(struct acpi_table_header *table, int *platform_timer_count);
>  int acpi_gtdt_map_ppi(int type);
>  bool acpi_gtdt_c3stop(int type);
> +int acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem, int *timer_count);
>  #endif
>  
>  #else	/* !CONFIG_ACPI */
> -- 
> 2.9.3
> 

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

* Re: [PATCH v23 00/11] acpi, clocksource: add GTDT driver and GTDT support in arm_arch_timer
  2017-03-31 17:50 ` fu.wei at linaro.org
@ 2017-04-04 20:39   ` Timur Tabi
  -1 siblings, 0 replies; 66+ messages in thread
From: Timur Tabi @ 2017-04-04 20:39 UTC (permalink / raw)
  To: fu.wei, rjw, lenb, daniel.lezcano, tglx, marc.zyngier,
	mark.rutland, lorenzo.pieralisi, sudeep.holla, hanjun.guo
  Cc: linux-arm-kernel, linaro-acpi, linux-kernel, linux-acpi,
	rruigrok, harba, cov, graeme.gregory, al.stone, jcm, wei, arnd,
	catalin.marinas, will.deacon, Suravee.Suthikulpanit, leo.duran,
	wim, linux, linux-watchdog, tn, christoffer.dall, julien.grall

On 03/31/2017 12:50 PM, fu.wei@linaro.org wrote:
> This patchset:
>     (1)Preparation for adding GTDT support in arm_arch_timer:
>         1. Introduce a MMIO CNTFRQ helper.
>         2. separate out device-tree code from arch_timer_detect_rate
>         3. remove arch_timer_detect_rate use arch_timer_*get_cntfrq directly
>         4. Refactor arch_timer_needs_probing, and move it into DT init call
>         5. Introduce some new structs and refactor the MMIO timer init code
>         for reusing some common code.
> 
>     (2)Introduce ACPI GTDT parser: drivers/acpi/arm64/acpi_gtdt.c
>     Parse all kinds of timer in GTDT table of ACPI:arch timer,
>     memory-mapped timer and SBSA Generic Watchdog timer.
>     This driver can help to simplify all the relevant timer drivers,
>     and separate all the ACPI GTDT knowledge from them.
> 
>     (3)Simplify ACPI code for arm_arch_timer
> 
>     (4)Add GTDT support for ARM memory-mapped timer.
> 
> This patchset has been tested on the following platforms with ACPI enabled:
>     (1)ARM Foundation v8 model
> 
> Changelog:
> v23: https://lkml.org/lkml/2017/3/31/

v23:

Tested-by: Timur Tabi <timur@codeaurora.org>

-- 
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm
Technologies, Inc.  Qualcomm Technologies, Inc. is a member of the
Code Aurora Forum, a Linux Foundation Collaborative Project.

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

* [PATCH v23 00/11] acpi, clocksource: add GTDT driver and GTDT support in arm_arch_timer
@ 2017-04-04 20:39   ` Timur Tabi
  0 siblings, 0 replies; 66+ messages in thread
From: Timur Tabi @ 2017-04-04 20:39 UTC (permalink / raw)
  To: linux-arm-kernel

On 03/31/2017 12:50 PM, fu.wei at linaro.org wrote:
> This patchset:
>     (1)Preparation for adding GTDT support in arm_arch_timer:
>         1. Introduce a MMIO CNTFRQ helper.
>         2. separate out device-tree code from arch_timer_detect_rate
>         3. remove arch_timer_detect_rate use arch_timer_*get_cntfrq directly
>         4. Refactor arch_timer_needs_probing, and move it into DT init call
>         5. Introduce some new structs and refactor the MMIO timer init code
>         for reusing some common code.
> 
>     (2)Introduce ACPI GTDT parser: drivers/acpi/arm64/acpi_gtdt.c
>     Parse all kinds of timer in GTDT table of ACPI:arch timer,
>     memory-mapped timer and SBSA Generic Watchdog timer.
>     This driver can help to simplify all the relevant timer drivers,
>     and separate all the ACPI GTDT knowledge from them.
> 
>     (3)Simplify ACPI code for arm_arch_timer
> 
>     (4)Add GTDT support for ARM memory-mapped timer.
> 
> This patchset has been tested on the following platforms with ACPI enabled:
>     (1)ARM Foundation v8 model
> 
> Changelog:
> v23: https://lkml.org/lkml/2017/3/31/

v23:

Tested-by: Timur Tabi <timur@codeaurora.org>

-- 
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm
Technologies, Inc.  Qualcomm Technologies, Inc. is a member of the
Code Aurora Forum, a Linux Foundation Collaborative Project.

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

* Re: [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
  2017-03-31 17:51   ` fu.wei at linaro.org
  (?)
@ 2017-04-05 18:38       ` Mark Rutland
  -1 siblings, 0 replies; 66+ messages in thread
From: Mark Rutland @ 2017-04-05 18:38 UTC (permalink / raw)
  To: fu.wei-QSEj5FYQhm4dnm+yROfE0A
  Cc: rjw-LthD3rsA81gm4RdzfppkhA, lenb-DgEjT+Ai2ygdnm+yROfE0A,
	daniel.lezcano-QSEj5FYQhm4dnm+yROfE0A,
	tglx-hfZtesqFncYOwBW4kG4KsQ, marc.zyngier-5wv7dgnIgG8,
	lorenzo.pieralisi-5wv7dgnIgG8, sudeep.holla-5wv7dgnIgG8,
	hanjun.guo-QSEj5FYQhm4dnm+yROfE0A,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linaro-acpi-cunTk1MwBs8s++Sfvej+rw,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-acpi-u79uwXL29TY76Z2rM5mHXA,
	rruigrok-sgV2jX0FEOL9JmXXK+q4OQ, harba-sgV2jX0FEOL9JmXXK+q4OQ,
	cov-sgV2jX0FEOL9JmXXK+q4OQ, timur-sgV2jX0FEOL9JmXXK+q4OQ,
	graeme.gregory-QSEj5FYQhm4dnm+yROfE0A,
	al.stone-QSEj5FYQhm4dnm+yROfE0A, jcm-H+wXaHxf7aLQT0dZR+AlfA,
	wei-H+wXaHxf7aLQT0dZR+AlfA, arnd-r2nGTMty4D4,
	catalin.marinas-5wv7dgnIgG8, will.deacon-5wv7dgnIgG8,
	Suravee.Suthikulpanit-5C7GfCeVMHo, leo.duran-5C7GfCeVMHo,
	wim-IQzOog9fTRqzQB+pC5nmwQ, linux-0h96xk9xTtrk1uMJSBkQmQ,
	linux-watchdog-u79uwXL29TY76Z2rM5mHXA, tn-nYOzD4b6Jr9Wk0Htik3J/w,
	christoffer.dall-QSEj5FYQhm4dnm+yROfE0A,
	julien.grall-5wv7dgnIgG8

Hi,

I tried to fix the issue that Lornzo raised, such that I could queue
these patches. From looking at this patch in more detail however, I
think there are further issues that need to be addressed.

On Sat, Apr 01, 2017 at 01:51:03AM +0800, fu.wei-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org wrote:
> +	/*
> +	 * Get the GT timer Frame data for every GT Block Timer
> +	 */
> +	for (i = 0; i < block->timer_count; i++, gtdt_frame++) {
> +		if (gtdt_frame->common_flags & ACPI_GTDT_GT_IS_SECURE_TIMER)
> +			continue;
> +
> +		if (!gtdt_frame->base_address || !gtdt_frame->timer_interrupt)
> +			goto error;
> +
> +		frame = &timer_mem->frame[gtdt_frame->frame_number];
> +		frame->phys_irq = map_gt_gsi(gtdt_frame->timer_interrupt,
> +					     gtdt_frame->timer_flags);
> +		if (frame->phys_irq <= 0) {
> +			pr_warn("failed to map physical timer irq in frame %d.\n",
> +				gtdt_frame->frame_number);
> +			goto error;
> +		}
> +
> +		if (gtdt_frame->virtual_timer_interrupt) {
> +			frame->virt_irq =
> +				map_gt_gsi(gtdt_frame->virtual_timer_interrupt,
> +					   gtdt_frame->virtual_timer_flags);
> +			if (frame->virt_irq <= 0) {
> +				pr_warn("failed to map virtual timer irq in frame %d.\n",
> +					gtdt_frame->frame_number);
> +				acpi_unregister_gsi(gtdt_frame->timer_interrupt);
> +				goto error;
> +			}
> +		} else {
> +			frame->virt_irq = 0;
> +			pr_debug("virtual timer in frame %d not implemented.\n",
> +				 gtdt_frame->frame_number);
> +		}
> +
> +		frame->cntbase = gtdt_frame->base_address;
> +		/*
> +		 * The CNTBaseN frame is 4KB (register offsets 0x000 - 0xFFC).
> +		 * See ARM DDI 0487A.k_iss10775, page I1-5130, Table I1-4
> +		 * "CNTBaseN memory map".
> +		 */
> +		frame->size = SZ_4K;
> +		frame->valid = true;
> +	}
> +
> +	return 0;
> +
> +error:
> +	for (i = 0; i < ARCH_TIMER_MEM_MAX_FRAMES; i++) {
> +		frame = &timer_mem->frame[i];
> +		if (!frame->valid)
> +			continue;
> +		irq_dispose_mapping(frame->phys_irq);
> +		if (frame->virt_irq)
> +			irq_dispose_mapping(frame->virt_irq);
> +	}

We assign interrupts and may goto error before setting valid, so here we
won't free the interrupts of the last frame we parsed.

> +	return -EINVAL;
> +}
> +
> +/**
> + * acpi_arch_timer_mem_init() - Get the info of all GT blocks in GTDT table.
> + * @timer_mem:	The pointer to the array of struct arch_timer_mem for returning
> + *		the result of parsing. The element number of this array should
> + *		be platform_timer_count(the total number of platform timers).
> + * @timer_count: It points to a integer variable which is used for storing the
> + *		number of GT blocks we have parsed.
> + *
> + * Return: 0 if success, -EINVAL/-ENODEV if error.
> + */
> +int __init acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem,
> +				    int *timer_count)
> +{
> +	int ret;
> +	void *platform_timer;
> +
> +	*timer_count = 0;
> +	for_each_platform_timer(platform_timer) {
> +		if (is_timer_block(platform_timer)) {
> +			ret = gtdt_parse_timer_block(platform_timer, timer_mem);
> +			if (ret)
> +				return ret;
> +			timer_mem++;
> +			(*timer_count)++;
> +		}
> +	}

If we were to have multiple GT blocks, this would leave timer_mem in an
inconsistent state. In gtdt_parse_timer_block we'll blat any existing
timer_mem->cntctlbase, and blat some arbitrary set of frames. however,
*some* frames may have been held over from a previous iteration.

My understanding was that the system level timer had a single CNTCTLBase
frame, and hence we should only have a single GT block.

Judging by ARM DDI 0487A.k_iss10775, I1.3 "Memory-mapped timer
components" and I3.4 "Generic Timer memory-mapped registers overview",
it does appear that the system should only have one CNTCTLBase frame.

What's going on here?

Thanks,
Mark.
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
@ 2017-04-05 18:38       ` Mark Rutland
  0 siblings, 0 replies; 66+ messages in thread
From: Mark Rutland @ 2017-04-05 18:38 UTC (permalink / raw)
  To: fu.wei
  Cc: rjw, lenb, daniel.lezcano, tglx, marc.zyngier, lorenzo.pieralisi,
	sudeep.holla, hanjun.guo, linux-arm-kernel, linaro-acpi,
	linux-kernel, linux-acpi, rruigrok, harba, cov, timur,
	graeme.gregory, al.stone, jcm, wei, arnd, catalin.marinas,
	will.deacon, Suravee.Suthikulpanit, leo.duran, wim, linux,
	linux-watchdog, tn, christoffer.dall, julien.grall

Hi,

I tried to fix the issue that Lornzo raised, such that I could queue
these patches. From looking at this patch in more detail however, I
think there are further issues that need to be addressed.

On Sat, Apr 01, 2017 at 01:51:03AM +0800, fu.wei@linaro.org wrote:
> +	/*
> +	 * Get the GT timer Frame data for every GT Block Timer
> +	 */
> +	for (i = 0; i < block->timer_count; i++, gtdt_frame++) {
> +		if (gtdt_frame->common_flags & ACPI_GTDT_GT_IS_SECURE_TIMER)
> +			continue;
> +
> +		if (!gtdt_frame->base_address || !gtdt_frame->timer_interrupt)
> +			goto error;
> +
> +		frame = &timer_mem->frame[gtdt_frame->frame_number];
> +		frame->phys_irq = map_gt_gsi(gtdt_frame->timer_interrupt,
> +					     gtdt_frame->timer_flags);
> +		if (frame->phys_irq <= 0) {
> +			pr_warn("failed to map physical timer irq in frame %d.\n",
> +				gtdt_frame->frame_number);
> +			goto error;
> +		}
> +
> +		if (gtdt_frame->virtual_timer_interrupt) {
> +			frame->virt_irq =
> +				map_gt_gsi(gtdt_frame->virtual_timer_interrupt,
> +					   gtdt_frame->virtual_timer_flags);
> +			if (frame->virt_irq <= 0) {
> +				pr_warn("failed to map virtual timer irq in frame %d.\n",
> +					gtdt_frame->frame_number);
> +				acpi_unregister_gsi(gtdt_frame->timer_interrupt);
> +				goto error;
> +			}
> +		} else {
> +			frame->virt_irq = 0;
> +			pr_debug("virtual timer in frame %d not implemented.\n",
> +				 gtdt_frame->frame_number);
> +		}
> +
> +		frame->cntbase = gtdt_frame->base_address;
> +		/*
> +		 * The CNTBaseN frame is 4KB (register offsets 0x000 - 0xFFC).
> +		 * See ARM DDI 0487A.k_iss10775, page I1-5130, Table I1-4
> +		 * "CNTBaseN memory map".
> +		 */
> +		frame->size = SZ_4K;
> +		frame->valid = true;
> +	}
> +
> +	return 0;
> +
> +error:
> +	for (i = 0; i < ARCH_TIMER_MEM_MAX_FRAMES; i++) {
> +		frame = &timer_mem->frame[i];
> +		if (!frame->valid)
> +			continue;
> +		irq_dispose_mapping(frame->phys_irq);
> +		if (frame->virt_irq)
> +			irq_dispose_mapping(frame->virt_irq);
> +	}

We assign interrupts and may goto error before setting valid, so here we
won't free the interrupts of the last frame we parsed.

> +	return -EINVAL;
> +}
> +
> +/**
> + * acpi_arch_timer_mem_init() - Get the info of all GT blocks in GTDT table.
> + * @timer_mem:	The pointer to the array of struct arch_timer_mem for returning
> + *		the result of parsing. The element number of this array should
> + *		be platform_timer_count(the total number of platform timers).
> + * @timer_count: It points to a integer variable which is used for storing the
> + *		number of GT blocks we have parsed.
> + *
> + * Return: 0 if success, -EINVAL/-ENODEV if error.
> + */
> +int __init acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem,
> +				    int *timer_count)
> +{
> +	int ret;
> +	void *platform_timer;
> +
> +	*timer_count = 0;
> +	for_each_platform_timer(platform_timer) {
> +		if (is_timer_block(platform_timer)) {
> +			ret = gtdt_parse_timer_block(platform_timer, timer_mem);
> +			if (ret)
> +				return ret;
> +			timer_mem++;
> +			(*timer_count)++;
> +		}
> +	}

If we were to have multiple GT blocks, this would leave timer_mem in an
inconsistent state. In gtdt_parse_timer_block we'll blat any existing
timer_mem->cntctlbase, and blat some arbitrary set of frames. however,
*some* frames may have been held over from a previous iteration.

My understanding was that the system level timer had a single CNTCTLBase
frame, and hence we should only have a single GT block.

Judging by ARM DDI 0487A.k_iss10775, I1.3 "Memory-mapped timer
components" and I3.4 "Generic Timer memory-mapped registers overview",
it does appear that the system should only have one CNTCTLBase frame.

What's going on here?

Thanks,
Mark.

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

* [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
@ 2017-04-05 18:38       ` Mark Rutland
  0 siblings, 0 replies; 66+ messages in thread
From: Mark Rutland @ 2017-04-05 18:38 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

I tried to fix the issue that Lornzo raised, such that I could queue
these patches. From looking at this patch in more detail however, I
think there are further issues that need to be addressed.

On Sat, Apr 01, 2017 at 01:51:03AM +0800, fu.wei at linaro.org wrote:
> +	/*
> +	 * Get the GT timer Frame data for every GT Block Timer
> +	 */
> +	for (i = 0; i < block->timer_count; i++, gtdt_frame++) {
> +		if (gtdt_frame->common_flags & ACPI_GTDT_GT_IS_SECURE_TIMER)
> +			continue;
> +
> +		if (!gtdt_frame->base_address || !gtdt_frame->timer_interrupt)
> +			goto error;
> +
> +		frame = &timer_mem->frame[gtdt_frame->frame_number];
> +		frame->phys_irq = map_gt_gsi(gtdt_frame->timer_interrupt,
> +					     gtdt_frame->timer_flags);
> +		if (frame->phys_irq <= 0) {
> +			pr_warn("failed to map physical timer irq in frame %d.\n",
> +				gtdt_frame->frame_number);
> +			goto error;
> +		}
> +
> +		if (gtdt_frame->virtual_timer_interrupt) {
> +			frame->virt_irq =
> +				map_gt_gsi(gtdt_frame->virtual_timer_interrupt,
> +					   gtdt_frame->virtual_timer_flags);
> +			if (frame->virt_irq <= 0) {
> +				pr_warn("failed to map virtual timer irq in frame %d.\n",
> +					gtdt_frame->frame_number);
> +				acpi_unregister_gsi(gtdt_frame->timer_interrupt);
> +				goto error;
> +			}
> +		} else {
> +			frame->virt_irq = 0;
> +			pr_debug("virtual timer in frame %d not implemented.\n",
> +				 gtdt_frame->frame_number);
> +		}
> +
> +		frame->cntbase = gtdt_frame->base_address;
> +		/*
> +		 * The CNTBaseN frame is 4KB (register offsets 0x000 - 0xFFC).
> +		 * See ARM DDI 0487A.k_iss10775, page I1-5130, Table I1-4
> +		 * "CNTBaseN memory map".
> +		 */
> +		frame->size = SZ_4K;
> +		frame->valid = true;
> +	}
> +
> +	return 0;
> +
> +error:
> +	for (i = 0; i < ARCH_TIMER_MEM_MAX_FRAMES; i++) {
> +		frame = &timer_mem->frame[i];
> +		if (!frame->valid)
> +			continue;
> +		irq_dispose_mapping(frame->phys_irq);
> +		if (frame->virt_irq)
> +			irq_dispose_mapping(frame->virt_irq);
> +	}

We assign interrupts and may goto error before setting valid, so here we
won't free the interrupts of the last frame we parsed.

> +	return -EINVAL;
> +}
> +
> +/**
> + * acpi_arch_timer_mem_init() - Get the info of all GT blocks in GTDT table.
> + * @timer_mem:	The pointer to the array of struct arch_timer_mem for returning
> + *		the result of parsing. The element number of this array should
> + *		be platform_timer_count(the total number of platform timers).
> + * @timer_count: It points to a integer variable which is used for storing the
> + *		number of GT blocks we have parsed.
> + *
> + * Return: 0 if success, -EINVAL/-ENODEV if error.
> + */
> +int __init acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem,
> +				    int *timer_count)
> +{
> +	int ret;
> +	void *platform_timer;
> +
> +	*timer_count = 0;
> +	for_each_platform_timer(platform_timer) {
> +		if (is_timer_block(platform_timer)) {
> +			ret = gtdt_parse_timer_block(platform_timer, timer_mem);
> +			if (ret)
> +				return ret;
> +			timer_mem++;
> +			(*timer_count)++;
> +		}
> +	}

If we were to have multiple GT blocks, this would leave timer_mem in an
inconsistent state. In gtdt_parse_timer_block we'll blat any existing
timer_mem->cntctlbase, and blat some arbitrary set of frames. however,
*some* frames may have been held over from a previous iteration.

My understanding was that the system level timer had a single CNTCTLBase
frame, and hence we should only have a single GT block.

Judging by ARM DDI 0487A.k_iss10775, I1.3 "Memory-mapped timer
components" and I3.4 "Generic Timer memory-mapped registers overview",
it does appear that the system should only have one CNTCTLBase frame.

What's going on here?

Thanks,
Mark.

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

* Re: [PATCH v23 06/11] clocksource: arm_arch_timer: refactor MMIO timer probing.
  2017-03-31 17:51   ` fu.wei at linaro.org
@ 2017-04-05 18:42     ` Mark Rutland
  -1 siblings, 0 replies; 66+ messages in thread
From: Mark Rutland @ 2017-04-05 18:42 UTC (permalink / raw)
  To: fu.wei
  Cc: rjw, lenb, daniel.lezcano, tglx, marc.zyngier, lorenzo.pieralisi,
	sudeep.holla, hanjun.guo, linux-arm-kernel, linaro-acpi,
	linux-kernel, linux-acpi, rruigrok, harba, cov, timur,
	graeme.gregory, al.stone, jcm, wei, arnd, catalin.marinas,
	will.deacon, Suravee.Suthikulpanit, leo.duran, wim, linux,
	linux-watchdog, tn, christoffer.dall, julien.grall

On Sat, Apr 01, 2017 at 01:51:00AM +0800, fu.wei@linaro.org wrote:
> +	arch_timer_mem_freq = arch_timer_mem_get_cntfrq(base);
> +	if (!arch_timer_rate && arch_timer_mem_freq) {
> +		arch_timer_rate = arch_timer_mem_freq;
> +	} else if (!arch_timer_rate || arch_timer_rate != arch_timer_mem_freq) {
> +		pr_err(FW_BUG "invalid MMIO frequency.\n");
> +		iounmap(base);
> +		return -EINVAL;
> +	}

I thought I had previously mentioned that this last check has the
potential to break DT systems, which may be inadvertently relying on the
probe order.

I agree we must do this check for ACPI, but I think that for DT it needs
to be relaxed.

I'm happy to rework that locally, if you can address my comments on
patch 9.

Thanks,
Mark.

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

* [PATCH v23 06/11] clocksource: arm_arch_timer: refactor MMIO timer probing.
@ 2017-04-05 18:42     ` Mark Rutland
  0 siblings, 0 replies; 66+ messages in thread
From: Mark Rutland @ 2017-04-05 18:42 UTC (permalink / raw)
  To: linux-arm-kernel

On Sat, Apr 01, 2017 at 01:51:00AM +0800, fu.wei at linaro.org wrote:
> +	arch_timer_mem_freq = arch_timer_mem_get_cntfrq(base);
> +	if (!arch_timer_rate && arch_timer_mem_freq) {
> +		arch_timer_rate = arch_timer_mem_freq;
> +	} else if (!arch_timer_rate || arch_timer_rate != arch_timer_mem_freq) {
> +		pr_err(FW_BUG "invalid MMIO frequency.\n");
> +		iounmap(base);
> +		return -EINVAL;
> +	}

I thought I had previously mentioned that this last check has the
potential to break DT systems, which may be inadvertently relying on the
probe order.

I agree we must do this check for ACPI, but I think that for DT it needs
to be relaxed.

I'm happy to rework that locally, if you can address my comments on
patch 9.

Thanks,
Mark.

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

* Re: [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
  2017-04-05 18:38       ` Mark Rutland
@ 2017-04-06 10:07         ` Mark Rutland
  -1 siblings, 0 replies; 66+ messages in thread
From: Mark Rutland @ 2017-04-06 10:07 UTC (permalink / raw)
  To: fu.wei
  Cc: linaro-acpi, catalin.marinas, will.deacon, rruigrok, wim, wei,
	lorenzo.pieralisi, al.stone, tn, timur, daniel.lezcano,
	linux-acpi, linux, lenb, harba, julien.grall, linux-watchdog,
	arnd, marc.zyngier, jcm, cov, tglx, linux-arm-kernel,
	graeme.gregory, rjw, linux-kernel, leo.duran, hanjun.guo,
	Suravee.Suthikulpanit, sudeep.holla, christoffer.dall

On Wed, Apr 05, 2017 at 07:38:09PM +0100, Mark Rutland wrote:
> I tried to fix the issue that Lornzo raised, such that I could queue
> these patches. From looking at this patch in more detail however, I
> think there are further issues that need to be addressed.

Looking again, I see that I was mistaken w.r.t. the multi GT block case.

> > +int __init acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem,
> > +				    int *timer_count)
> > +{
> > +	int ret;
> > +	void *platform_timer;
> > +
> > +	*timer_count = 0;
> > +	for_each_platform_timer(platform_timer) {
> > +		if (is_timer_block(platform_timer)) {
> > +			ret = gtdt_parse_timer_block(platform_timer, timer_mem);
> > +			if (ret)
> > +				return ret;
> > +			timer_mem++;
> > +			(*timer_count)++;
> > +		}
> > +	}
> 
> If we were to have multiple GT blocks, this would leave timer_mem in an
> inconsistent state. In gtdt_parse_timer_block we'll blat any existing
> timer_mem->cntctlbase, and blat some arbitrary set of frames. however,
> *some* frames may have been held over from a previous iteration.

This is not the case; I had somehow missed the timer_mem++.

Sorry for the noise.

Thanks,
Mark.

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

* [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
@ 2017-04-06 10:07         ` Mark Rutland
  0 siblings, 0 replies; 66+ messages in thread
From: Mark Rutland @ 2017-04-06 10:07 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Apr 05, 2017 at 07:38:09PM +0100, Mark Rutland wrote:
> I tried to fix the issue that Lornzo raised, such that I could queue
> these patches. From looking at this patch in more detail however, I
> think there are further issues that need to be addressed.

Looking again, I see that I was mistaken w.r.t. the multi GT block case.

> > +int __init acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem,
> > +				    int *timer_count)
> > +{
> > +	int ret;
> > +	void *platform_timer;
> > +
> > +	*timer_count = 0;
> > +	for_each_platform_timer(platform_timer) {
> > +		if (is_timer_block(platform_timer)) {
> > +			ret = gtdt_parse_timer_block(platform_timer, timer_mem);
> > +			if (ret)
> > +				return ret;
> > +			timer_mem++;
> > +			(*timer_count)++;
> > +		}
> > +	}
> 
> If we were to have multiple GT blocks, this would leave timer_mem in an
> inconsistent state. In gtdt_parse_timer_block we'll blat any existing
> timer_mem->cntctlbase, and blat some arbitrary set of frames. however,
> *some* frames may have been held over from a previous iteration.

This is not the case; I had somehow missed the timer_mem++.

Sorry for the noise.

Thanks,
Mark.

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

* Re: [PATCH v23 06/11] clocksource: arm_arch_timer: refactor MMIO timer probing.
  2017-04-05 18:42     ` Mark Rutland
  (?)
@ 2017-04-06 10:45       ` Fu Wei
  -1 siblings, 0 replies; 66+ messages in thread
From: Fu Wei @ 2017-04-06 10:45 UTC (permalink / raw)
  To: Mark Rutland
  Cc: Rafael J. Wysocki, Len Brown, Daniel Lezcano, Thomas Gleixner,
	Marc Zyngier, Lorenzo Pieralisi, Sudeep Holla, Hanjun Guo,
	linux-arm-kernel, Linaro ACPI Mailman List,
	Linux Kernel Mailing List, ACPI Devel Maling List, rruigrok,
	Abdulhamid, Harb, Christopher Covington, Timur Tabi, G Gregory,
	Al Stone, Jon Masters

Hi Mark,

On 6 April 2017 at 02:42, Mark Rutland <mark.rutland@arm.com> wrote:
> On Sat, Apr 01, 2017 at 01:51:00AM +0800, fu.wei@linaro.org wrote:
>> +     arch_timer_mem_freq = arch_timer_mem_get_cntfrq(base);
>> +     if (!arch_timer_rate && arch_timer_mem_freq) {
>> +             arch_timer_rate = arch_timer_mem_freq;
>> +     } else if (!arch_timer_rate || arch_timer_rate != arch_timer_mem_freq) {
>> +             pr_err(FW_BUG "invalid MMIO frequency.\n");
>> +             iounmap(base);
>> +             return -EINVAL;
>> +     }
>
> I thought I had previously mentioned that this last check has the
> potential to break DT systems, which may be inadvertently relying on the
> probe order.
>
> I agree we must do this check for ACPI, but I think that for DT it needs
> to be relaxed.
>
> I'm happy to rework that locally, if you can address my comments on
> patch 9.

yes, you suggested that we keep the current frequency probing approach for DT,
and use the new approach for ACPI.

Because we try to merge the common code for MMIO timer. this become a little
problem, sorry for that.

I thinks for this code, maybe we can do :

arch_timer_mem_freq = arch_timer_mem_get_cntfrq(base);
if (!arch_timer_rate && arch_timer_mem_freq) {
arch_timer_rate = arch_timer_mem_freq;
} else if (!acpi_disabled && arch_timer_rate != arch_timer_mem_freq) {
pr_err(FW_BUG "invalid MMIO frequency.\n");
iounmap(base);
return -EINVAL;
}

Please correct me, if I miss something.

Thanks :-)

>
> Thanks,
> Mark.



-- 
Best regards,

Fu Wei
Software Engineer
Red Hat

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

* Re: [PATCH v23 06/11] clocksource: arm_arch_timer: refactor MMIO timer probing.
@ 2017-04-06 10:45       ` Fu Wei
  0 siblings, 0 replies; 66+ messages in thread
From: Fu Wei @ 2017-04-06 10:45 UTC (permalink / raw)
  To: Mark Rutland
  Cc: Rafael J. Wysocki, Len Brown, Daniel Lezcano, Thomas Gleixner,
	Marc Zyngier, Lorenzo Pieralisi, Sudeep Holla, Hanjun Guo,
	linux-arm-kernel, Linaro ACPI Mailman List,
	Linux Kernel Mailing List, ACPI Devel Maling List, rruigrok,
	Abdulhamid, Harb, Christopher Covington, Timur Tabi, G Gregory,
	Al Stone, Jon Masters, Wei Huang, Arnd Bergmann, Catalin Marinas,
	Will Deacon, Suravee Suthikulpanit, Leo Duran, Wim Van Sebroeck,
	Guenter Roeck, linux-watchdog, Tomasz Nowicki, Christoffer Dall,
	Julien Grall

Hi Mark,

On 6 April 2017 at 02:42, Mark Rutland <mark.rutland@arm.com> wrote:
> On Sat, Apr 01, 2017 at 01:51:00AM +0800, fu.wei@linaro.org wrote:
>> +     arch_timer_mem_freq = arch_timer_mem_get_cntfrq(base);
>> +     if (!arch_timer_rate && arch_timer_mem_freq) {
>> +             arch_timer_rate = arch_timer_mem_freq;
>> +     } else if (!arch_timer_rate || arch_timer_rate != arch_timer_mem_freq) {
>> +             pr_err(FW_BUG "invalid MMIO frequency.\n");
>> +             iounmap(base);
>> +             return -EINVAL;
>> +     }
>
> I thought I had previously mentioned that this last check has the
> potential to break DT systems, which may be inadvertently relying on the
> probe order.
>
> I agree we must do this check for ACPI, but I think that for DT it needs
> to be relaxed.
>
> I'm happy to rework that locally, if you can address my comments on
> patch 9.

yes, you suggested that we keep the current frequency probing approach for DT,
and use the new approach for ACPI.

Because we try to merge the common code for MMIO timer. this become a little
problem, sorry for that.

I thinks for this code, maybe we can do :

arch_timer_mem_freq = arch_timer_mem_get_cntfrq(base);
if (!arch_timer_rate && arch_timer_mem_freq) {
arch_timer_rate = arch_timer_mem_freq;
} else if (!acpi_disabled && arch_timer_rate != arch_timer_mem_freq) {
pr_err(FW_BUG "invalid MMIO frequency.\n");
iounmap(base);
return -EINVAL;
}

Please correct me, if I miss something.

Thanks :-)

>
> Thanks,
> Mark.



-- 
Best regards,

Fu Wei
Software Engineer
Red Hat

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

* [PATCH v23 06/11] clocksource: arm_arch_timer: refactor MMIO timer probing.
@ 2017-04-06 10:45       ` Fu Wei
  0 siblings, 0 replies; 66+ messages in thread
From: Fu Wei @ 2017-04-06 10:45 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Mark,

On 6 April 2017 at 02:42, Mark Rutland <mark.rutland@arm.com> wrote:
> On Sat, Apr 01, 2017 at 01:51:00AM +0800, fu.wei at linaro.org wrote:
>> +     arch_timer_mem_freq = arch_timer_mem_get_cntfrq(base);
>> +     if (!arch_timer_rate && arch_timer_mem_freq) {
>> +             arch_timer_rate = arch_timer_mem_freq;
>> +     } else if (!arch_timer_rate || arch_timer_rate != arch_timer_mem_freq) {
>> +             pr_err(FW_BUG "invalid MMIO frequency.\n");
>> +             iounmap(base);
>> +             return -EINVAL;
>> +     }
>
> I thought I had previously mentioned that this last check has the
> potential to break DT systems, which may be inadvertently relying on the
> probe order.
>
> I agree we must do this check for ACPI, but I think that for DT it needs
> to be relaxed.
>
> I'm happy to rework that locally, if you can address my comments on
> patch 9.

yes, you suggested that we keep the current frequency probing approach for DT,
and use the new approach for ACPI.

Because we try to merge the common code for MMIO timer. this become a little
problem, sorry for that.

I thinks for this code, maybe we can do :

arch_timer_mem_freq = arch_timer_mem_get_cntfrq(base);
if (!arch_timer_rate && arch_timer_mem_freq) {
arch_timer_rate = arch_timer_mem_freq;
} else if (!acpi_disabled && arch_timer_rate != arch_timer_mem_freq) {
pr_err(FW_BUG "invalid MMIO frequency.\n");
iounmap(base);
return -EINVAL;
}

Please correct me, if I miss something.

Thanks :-)

>
> Thanks,
> Mark.



-- 
Best regards,

Fu Wei
Software Engineer
Red Hat

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

* Re: [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
  2017-04-05 18:38       ` Mark Rutland
  (?)
@ 2017-04-06 16:47         ` Fu Wei
  -1 siblings, 0 replies; 66+ messages in thread
From: Fu Wei @ 2017-04-06 16:47 UTC (permalink / raw)
  To: Mark Rutland
  Cc: Rafael J. Wysocki, Len Brown, Daniel Lezcano, Thomas Gleixner,
	Marc Zyngier, Lorenzo Pieralisi, Sudeep Holla, Hanjun Guo,
	linux-arm-kernel, Linaro ACPI Mailman List,
	Linux Kernel Mailing List, ACPI Devel Maling List, rruigrok,
	Abdulhamid, Harb, Christopher Covington, Timur Tabi, G Gregory,
	Al Stone, Jon Masters

Hi Mark,

On 6 April 2017 at 02:38, Mark Rutland <mark.rutland@arm.com> wrote:
> Hi,
>
> I tried to fix the issue that Lornzo raised, such that I could queue
> these patches. From looking at this patch in more detail however, I
> think there are further issues that need to be addressed.
>
> On Sat, Apr 01, 2017 at 01:51:03AM +0800, fu.wei@linaro.org wrote:
>> +     /*
>> +      * Get the GT timer Frame data for every GT Block Timer
>> +      */
>> +     for (i = 0; i < block->timer_count; i++, gtdt_frame++) {
>> +             if (gtdt_frame->common_flags & ACPI_GTDT_GT_IS_SECURE_TIMER)
>> +                     continue;
>> +
>> +             if (!gtdt_frame->base_address || !gtdt_frame->timer_interrupt)
>> +                     goto error;
>> +
>> +             frame = &timer_mem->frame[gtdt_frame->frame_number];
>> +             frame->phys_irq = map_gt_gsi(gtdt_frame->timer_interrupt,
>> +                                          gtdt_frame->timer_flags);
>> +             if (frame->phys_irq <= 0) {
>> +                     pr_warn("failed to map physical timer irq in frame %d.\n",
>> +                             gtdt_frame->frame_number);
>> +                     goto error;
>> +             }
>> +
>> +             if (gtdt_frame->virtual_timer_interrupt) {
>> +                     frame->virt_irq =
>> +                             map_gt_gsi(gtdt_frame->virtual_timer_interrupt,
>> +                                        gtdt_frame->virtual_timer_flags);
>> +                     if (frame->virt_irq <= 0) {
>> +                             pr_warn("failed to map virtual timer irq in frame %d.\n",
>> +                                     gtdt_frame->frame_number);
>> +                             acpi_unregister_gsi(gtdt_frame->timer_interrupt);
>> +                             goto error;
>> +                     }
>> +             } else {
>> +                     frame->virt_irq = 0;
>> +                     pr_debug("virtual timer in frame %d not implemented.\n",
>> +                              gtdt_frame->frame_number);
>> +             }
>> +
>> +             frame->cntbase = gtdt_frame->base_address;
>> +             /*
>> +              * The CNTBaseN frame is 4KB (register offsets 0x000 - 0xFFC).
>> +              * See ARM DDI 0487A.k_iss10775, page I1-5130, Table I1-4
>> +              * "CNTBaseN memory map".
>> +              */
>> +             frame->size = SZ_4K;
>> +             frame->valid = true;
>> +     }
>> +
>> +     return 0;
>> +
>> +error:
>> +     for (i = 0; i < ARCH_TIMER_MEM_MAX_FRAMES; i++) {
>> +             frame = &timer_mem->frame[i];
>> +             if (!frame->valid)
>> +                     continue;
>> +             irq_dispose_mapping(frame->phys_irq);
>> +             if (frame->virt_irq)
>> +                     irq_dispose_mapping(frame->virt_irq);
>> +     }
>
> We assign interrupts and may goto error before setting valid, so here we

yes, I mean to do it.(setting valid at the end of loop)

> won't free the interrupts of the last frame we parsed.

that won't  be a problem, we may assign two interrupts in a round:
First of all, if  the assignment goes  wrong, that means the current
interrupt haven't been successfully assigned.
(1)if the first goes wrong, the we goto error to unwind  the irqs
assigned in previous rounds.
(2)if the second one goes wrong , we acpi_unregister_gsi the first one
and then  goto error to unwind  the irqs assigned in previous rounds.
(3)If the two assignments are successful, set up valid flag

So we won't miss freeing the interrupts of the last frame we parsed.

Did I miss something?

Thanks!

>
>> +     return -EINVAL;
>> +}
>> +
>> +/**
>> + * acpi_arch_timer_mem_init() - Get the info of all GT blocks in GTDT table.
>> + * @timer_mem:       The pointer to the array of struct arch_timer_mem for returning
>> + *           the result of parsing. The element number of this array should
>> + *           be platform_timer_count(the total number of platform timers).
>> + * @timer_count: It points to a integer variable which is used for storing the
>> + *           number of GT blocks we have parsed.
>> + *
>> + * Return: 0 if success, -EINVAL/-ENODEV if error.
>> + */
>> +int __init acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem,
>> +                                 int *timer_count)
>> +{
>> +     int ret;
>> +     void *platform_timer;
>> +
>> +     *timer_count = 0;
>> +     for_each_platform_timer(platform_timer) {
>> +             if (is_timer_block(platform_timer)) {
>> +                     ret = gtdt_parse_timer_block(platform_timer, timer_mem);
>> +                     if (ret)
>> +                             return ret;
>> +                     timer_mem++;
>> +                     (*timer_count)++;
>> +             }
>> +     }
>
> If we were to have multiple GT blocks, this would leave timer_mem in an
> inconsistent state. In gtdt_parse_timer_block we'll blat any existing
> timer_mem->cntctlbase, and blat some arbitrary set of frames. however,
> *some* frames may have been held over from a previous iteration.
>
> My understanding was that the system level timer had a single CNTCTLBase
> frame, and hence we should only have a single GT block.
>
> Judging by ARM DDI 0487A.k_iss10775, I1.3 "Memory-mapped timer
> components" and I3.4 "Generic Timer memory-mapped registers overview",
> it does appear that the system should only have one CNTCTLBase frame.
>
> What's going on here?
>
> Thanks,
> Mark.



-- 
Best regards,

Fu Wei
Software Engineer
Red Hat

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

* Re: [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
@ 2017-04-06 16:47         ` Fu Wei
  0 siblings, 0 replies; 66+ messages in thread
From: Fu Wei @ 2017-04-06 16:47 UTC (permalink / raw)
  To: Mark Rutland
  Cc: Rafael J. Wysocki, Len Brown, Daniel Lezcano, Thomas Gleixner,
	Marc Zyngier, Lorenzo Pieralisi, Sudeep Holla, Hanjun Guo,
	linux-arm-kernel, Linaro ACPI Mailman List,
	Linux Kernel Mailing List, ACPI Devel Maling List, rruigrok,
	Abdulhamid, Harb, Christopher Covington, Timur Tabi, G Gregory,
	Al Stone, Jon Masters, Wei Huang, Arnd Bergmann, Catalin Marinas,
	Will Deacon, Suravee Suthikulpanit, Leo Duran, Wim Van Sebroeck,
	Guenter Roeck, linux-watchdog, Tomasz Nowicki, Christoffer Dall,
	Julien Grall

Hi Mark,

On 6 April 2017 at 02:38, Mark Rutland <mark.rutland@arm.com> wrote:
> Hi,
>
> I tried to fix the issue that Lornzo raised, such that I could queue
> these patches. From looking at this patch in more detail however, I
> think there are further issues that need to be addressed.
>
> On Sat, Apr 01, 2017 at 01:51:03AM +0800, fu.wei@linaro.org wrote:
>> +     /*
>> +      * Get the GT timer Frame data for every GT Block Timer
>> +      */
>> +     for (i = 0; i < block->timer_count; i++, gtdt_frame++) {
>> +             if (gtdt_frame->common_flags & ACPI_GTDT_GT_IS_SECURE_TIMER)
>> +                     continue;
>> +
>> +             if (!gtdt_frame->base_address || !gtdt_frame->timer_interrupt)
>> +                     goto error;
>> +
>> +             frame = &timer_mem->frame[gtdt_frame->frame_number];
>> +             frame->phys_irq = map_gt_gsi(gtdt_frame->timer_interrupt,
>> +                                          gtdt_frame->timer_flags);
>> +             if (frame->phys_irq <= 0) {
>> +                     pr_warn("failed to map physical timer irq in frame %d.\n",
>> +                             gtdt_frame->frame_number);
>> +                     goto error;
>> +             }
>> +
>> +             if (gtdt_frame->virtual_timer_interrupt) {
>> +                     frame->virt_irq =
>> +                             map_gt_gsi(gtdt_frame->virtual_timer_interrupt,
>> +                                        gtdt_frame->virtual_timer_flags);
>> +                     if (frame->virt_irq <= 0) {
>> +                             pr_warn("failed to map virtual timer irq in frame %d.\n",
>> +                                     gtdt_frame->frame_number);
>> +                             acpi_unregister_gsi(gtdt_frame->timer_interrupt);
>> +                             goto error;
>> +                     }
>> +             } else {
>> +                     frame->virt_irq = 0;
>> +                     pr_debug("virtual timer in frame %d not implemented.\n",
>> +                              gtdt_frame->frame_number);
>> +             }
>> +
>> +             frame->cntbase = gtdt_frame->base_address;
>> +             /*
>> +              * The CNTBaseN frame is 4KB (register offsets 0x000 - 0xFFC).
>> +              * See ARM DDI 0487A.k_iss10775, page I1-5130, Table I1-4
>> +              * "CNTBaseN memory map".
>> +              */
>> +             frame->size = SZ_4K;
>> +             frame->valid = true;
>> +     }
>> +
>> +     return 0;
>> +
>> +error:
>> +     for (i = 0; i < ARCH_TIMER_MEM_MAX_FRAMES; i++) {
>> +             frame = &timer_mem->frame[i];
>> +             if (!frame->valid)
>> +                     continue;
>> +             irq_dispose_mapping(frame->phys_irq);
>> +             if (frame->virt_irq)
>> +                     irq_dispose_mapping(frame->virt_irq);
>> +     }
>
> We assign interrupts and may goto error before setting valid, so here we

yes, I mean to do it.(setting valid at the end of loop)

> won't free the interrupts of the last frame we parsed.

that won't  be a problem, we may assign two interrupts in a round:
First of all, if  the assignment goes  wrong, that means the current
interrupt haven't been successfully assigned.
(1)if the first goes wrong, the we goto error to unwind  the irqs
assigned in previous rounds.
(2)if the second one goes wrong , we acpi_unregister_gsi the first one
and then  goto error to unwind  the irqs assigned in previous rounds.
(3)If the two assignments are successful, set up valid flag

So we won't miss freeing the interrupts of the last frame we parsed.

Did I miss something?

Thanks!

>
>> +     return -EINVAL;
>> +}
>> +
>> +/**
>> + * acpi_arch_timer_mem_init() - Get the info of all GT blocks in GTDT table.
>> + * @timer_mem:       The pointer to the array of struct arch_timer_mem for returning
>> + *           the result of parsing. The element number of this array should
>> + *           be platform_timer_count(the total number of platform timers).
>> + * @timer_count: It points to a integer variable which is used for storing the
>> + *           number of GT blocks we have parsed.
>> + *
>> + * Return: 0 if success, -EINVAL/-ENODEV if error.
>> + */
>> +int __init acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem,
>> +                                 int *timer_count)
>> +{
>> +     int ret;
>> +     void *platform_timer;
>> +
>> +     *timer_count = 0;
>> +     for_each_platform_timer(platform_timer) {
>> +             if (is_timer_block(platform_timer)) {
>> +                     ret = gtdt_parse_timer_block(platform_timer, timer_mem);
>> +                     if (ret)
>> +                             return ret;
>> +                     timer_mem++;
>> +                     (*timer_count)++;
>> +             }
>> +     }
>
> If we were to have multiple GT blocks, this would leave timer_mem in an
> inconsistent state. In gtdt_parse_timer_block we'll blat any existing
> timer_mem->cntctlbase, and blat some arbitrary set of frames. however,
> *some* frames may have been held over from a previous iteration.
>
> My understanding was that the system level timer had a single CNTCTLBase
> frame, and hence we should only have a single GT block.
>
> Judging by ARM DDI 0487A.k_iss10775, I1.3 "Memory-mapped timer
> components" and I3.4 "Generic Timer memory-mapped registers overview",
> it does appear that the system should only have one CNTCTLBase frame.
>
> What's going on here?
>
> Thanks,
> Mark.



-- 
Best regards,

Fu Wei
Software Engineer
Red Hat

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

* [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
@ 2017-04-06 16:47         ` Fu Wei
  0 siblings, 0 replies; 66+ messages in thread
From: Fu Wei @ 2017-04-06 16:47 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Mark,

On 6 April 2017 at 02:38, Mark Rutland <mark.rutland@arm.com> wrote:
> Hi,
>
> I tried to fix the issue that Lornzo raised, such that I could queue
> these patches. From looking at this patch in more detail however, I
> think there are further issues that need to be addressed.
>
> On Sat, Apr 01, 2017 at 01:51:03AM +0800, fu.wei at linaro.org wrote:
>> +     /*
>> +      * Get the GT timer Frame data for every GT Block Timer
>> +      */
>> +     for (i = 0; i < block->timer_count; i++, gtdt_frame++) {
>> +             if (gtdt_frame->common_flags & ACPI_GTDT_GT_IS_SECURE_TIMER)
>> +                     continue;
>> +
>> +             if (!gtdt_frame->base_address || !gtdt_frame->timer_interrupt)
>> +                     goto error;
>> +
>> +             frame = &timer_mem->frame[gtdt_frame->frame_number];
>> +             frame->phys_irq = map_gt_gsi(gtdt_frame->timer_interrupt,
>> +                                          gtdt_frame->timer_flags);
>> +             if (frame->phys_irq <= 0) {
>> +                     pr_warn("failed to map physical timer irq in frame %d.\n",
>> +                             gtdt_frame->frame_number);
>> +                     goto error;
>> +             }
>> +
>> +             if (gtdt_frame->virtual_timer_interrupt) {
>> +                     frame->virt_irq =
>> +                             map_gt_gsi(gtdt_frame->virtual_timer_interrupt,
>> +                                        gtdt_frame->virtual_timer_flags);
>> +                     if (frame->virt_irq <= 0) {
>> +                             pr_warn("failed to map virtual timer irq in frame %d.\n",
>> +                                     gtdt_frame->frame_number);
>> +                             acpi_unregister_gsi(gtdt_frame->timer_interrupt);
>> +                             goto error;
>> +                     }
>> +             } else {
>> +                     frame->virt_irq = 0;
>> +                     pr_debug("virtual timer in frame %d not implemented.\n",
>> +                              gtdt_frame->frame_number);
>> +             }
>> +
>> +             frame->cntbase = gtdt_frame->base_address;
>> +             /*
>> +              * The CNTBaseN frame is 4KB (register offsets 0x000 - 0xFFC).
>> +              * See ARM DDI 0487A.k_iss10775, page I1-5130, Table I1-4
>> +              * "CNTBaseN memory map".
>> +              */
>> +             frame->size = SZ_4K;
>> +             frame->valid = true;
>> +     }
>> +
>> +     return 0;
>> +
>> +error:
>> +     for (i = 0; i < ARCH_TIMER_MEM_MAX_FRAMES; i++) {
>> +             frame = &timer_mem->frame[i];
>> +             if (!frame->valid)
>> +                     continue;
>> +             irq_dispose_mapping(frame->phys_irq);
>> +             if (frame->virt_irq)
>> +                     irq_dispose_mapping(frame->virt_irq);
>> +     }
>
> We assign interrupts and may goto error before setting valid, so here we

yes, I mean to do it.(setting valid at the end of loop)

> won't free the interrupts of the last frame we parsed.

that won't  be a problem, we may assign two interrupts in a round:
First of all, if  the assignment goes  wrong, that means the current
interrupt haven't been successfully assigned.
(1)if the first goes wrong, the we goto error to unwind  the irqs
assigned in previous rounds.
(2)if the second one goes wrong , we acpi_unregister_gsi the first one
and then  goto error to unwind  the irqs assigned in previous rounds.
(3)If the two assignments are successful, set up valid flag

So we won't miss freeing the interrupts of the last frame we parsed.

Did I miss something?

Thanks!

>
>> +     return -EINVAL;
>> +}
>> +
>> +/**
>> + * acpi_arch_timer_mem_init() - Get the info of all GT blocks in GTDT table.
>> + * @timer_mem:       The pointer to the array of struct arch_timer_mem for returning
>> + *           the result of parsing. The element number of this array should
>> + *           be platform_timer_count(the total number of platform timers).
>> + * @timer_count: It points to a integer variable which is used for storing the
>> + *           number of GT blocks we have parsed.
>> + *
>> + * Return: 0 if success, -EINVAL/-ENODEV if error.
>> + */
>> +int __init acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem,
>> +                                 int *timer_count)
>> +{
>> +     int ret;
>> +     void *platform_timer;
>> +
>> +     *timer_count = 0;
>> +     for_each_platform_timer(platform_timer) {
>> +             if (is_timer_block(platform_timer)) {
>> +                     ret = gtdt_parse_timer_block(platform_timer, timer_mem);
>> +                     if (ret)
>> +                             return ret;
>> +                     timer_mem++;
>> +                     (*timer_count)++;
>> +             }
>> +     }
>
> If we were to have multiple GT blocks, this would leave timer_mem in an
> inconsistent state. In gtdt_parse_timer_block we'll blat any existing
> timer_mem->cntctlbase, and blat some arbitrary set of frames. however,
> *some* frames may have been held over from a previous iteration.
>
> My understanding was that the system level timer had a single CNTCTLBase
> frame, and hence we should only have a single GT block.
>
> Judging by ARM DDI 0487A.k_iss10775, I1.3 "Memory-mapped timer
> components" and I3.4 "Generic Timer memory-mapped registers overview",
> it does appear that the system should only have one CNTCTLBase frame.
>
> What's going on here?
>
> Thanks,
> Mark.



-- 
Best regards,

Fu Wei
Software Engineer
Red Hat

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

* Re: [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
  2017-04-03 10:45       ` Lorenzo Pieralisi
  (?)
@ 2017-04-06 17:11         ` Fu Wei
  -1 siblings, 0 replies; 66+ messages in thread
From: Fu Wei @ 2017-04-06 17:11 UTC (permalink / raw)
  To: Lorenzo Pieralisi
  Cc: Rafael J. Wysocki, Len Brown, Daniel Lezcano, Thomas Gleixner,
	Marc Zyngier, Mark Rutland, Sudeep Holla, Hanjun Guo,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	Linaro ACPI Mailman List, Linux Kernel Mailing List,
	ACPI Devel Maling List, rruigrok-sgV2jX0FEOL9JmXXK+q4OQ,
	Abdulhamid, Harb, Christopher Covington, Timur Tabi, G Gregory,
	Al Stone, Jon Masters, Wei

Hi Lorenzo,

On 3 April 2017 at 18:45, Lorenzo Pieralisi <lorenzo.pieralisi-5wv7dgnIgG8@public.gmane.org> wrote:
> On Sat, Apr 01, 2017 at 01:51:03AM +0800, fu.wei-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org wrote:
>> From: Fu Wei <fu.wei-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
>>
>> On platforms booting with ACPI, architected memory-mapped timers'
>> configuration data is provided by firmware through the ACPI GTDT
>> static table.
>>
>> The clocksource architected timer kernel driver requires a firmware
>> interface to collect timer configuration and configure its driver.
>> this infrastructure is present for device tree systems, but it is
>> missing on systems booting with ACPI.
>>
>> Implement the kernel infrastructure required to parse the static
>> ACPI GTDT table so that the architected timer clocksource driver can
>> make use of it on systems booting with ACPI, therefore enabling
>> the corresponding timers configuration.
>>
>> Signed-off-by: Fu Wei <fu.wei-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
>> Signed-off-by: Hanjun Guo <hanjun.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
>> ---
>>  drivers/acpi/arm64/gtdt.c | 146 ++++++++++++++++++++++++++++++++++++++++++++++
>>  include/linux/acpi.h      |   1 +
>>  2 files changed, 147 insertions(+)
>>
>> diff --git a/drivers/acpi/arm64/gtdt.c b/drivers/acpi/arm64/gtdt.c
>> index 3d95af8..3dd33f3 100644
>> --- a/drivers/acpi/arm64/gtdt.c
>> +++ b/drivers/acpi/arm64/gtdt.c
>> @@ -13,6 +13,7 @@
>>
>>  #include <linux/acpi.h>
>>  #include <linux/init.h>
>> +#include <linux/irqdomain.h>
>>  #include <linux/kernel.h>
>>
>>  #include <clocksource/arm_arch_timer.h>
>> @@ -37,6 +38,28 @@ struct acpi_gtdt_descriptor {
>>
>>  static struct acpi_gtdt_descriptor acpi_gtdt_desc __initdata;
>>
>> +static inline void *next_platform_timer(void *platform_timer)
>> +{
>> +     struct acpi_gtdt_header *gh = platform_timer;
>> +
>> +     platform_timer += gh->length;
>> +     if (platform_timer < acpi_gtdt_desc.gtdt_end)
>> +             return platform_timer;
>> +
>> +     return NULL;
>> +}
>> +
>> +#define for_each_platform_timer(_g)                          \
>> +     for (_g = acpi_gtdt_desc.platform_timer; _g;    \
>> +          _g = next_platform_timer(_g))
>> +
>> +static inline bool is_timer_block(void *platform_timer)
>> +{
>> +     struct acpi_gtdt_header *gh = platform_timer;
>> +
>> +     return gh->type == ACPI_GTDT_TYPE_TIMER_BLOCK;
>> +}
>> +
>>  static int __init map_gt_gsi(u32 interrupt, u32 flags)
>>  {
>>       int trigger, polarity;
>> @@ -155,3 +178,126 @@ int __init acpi_gtdt_init(struct acpi_table_header *table,
>>
>>       return 0;
>>  }
>> +
>> +static int __init gtdt_parse_timer_block(struct acpi_gtdt_timer_block *block,
>> +                                      struct arch_timer_mem *timer_mem)
>> +{
>> +     int i;
>> +     struct arch_timer_mem_frame *frame;
>> +     struct acpi_gtdt_timer_entry *gtdt_frame;
>> +
>> +     if (!block->timer_count) {
>> +             pr_err(FW_BUG "GT block present, but frame count is zero.");
>> +             return -ENODEV;
>> +     }
>> +
>> +     if (block->timer_count > ARCH_TIMER_MEM_MAX_FRAMES) {
>> +             pr_err(FW_BUG "GT block lists %d frames, ACPI spec only allows 8\n",
>> +                    block->timer_count);
>> +             return -EINVAL;
>> +     }
>> +
>> +     timer_mem->cntctlbase = (phys_addr_t)block->block_address;
>> +     /*
>> +      * The CNTCTLBase frame is 4KB (register offsets 0x000 - 0xFFC).
>> +      * See ARM DDI 0487A.k_iss10775, page I1-5129, Table I1-3
>> +      * "CNTCTLBase memory map".
>> +      */
>> +     timer_mem->size = SZ_4K;
>> +
>> +     gtdt_frame = (void *)block + block->timer_offset;
>> +     if (gtdt_frame + block->timer_count != (void *)block + block->header.length)
>> +             return -EINVAL;
>> +
>> +     /*
>> +      * Get the GT timer Frame data for every GT Block Timer
>> +      */
>> +     for (i = 0; i < block->timer_count; i++, gtdt_frame++) {
>> +             if (gtdt_frame->common_flags & ACPI_GTDT_GT_IS_SECURE_TIMER)
>> +                     continue;
>> +
>> +             if (!gtdt_frame->base_address || !gtdt_frame->timer_interrupt)
>> +                     goto error;
>> +
>> +             frame = &timer_mem->frame[gtdt_frame->frame_number];
>> +             frame->phys_irq = map_gt_gsi(gtdt_frame->timer_interrupt,
>> +                                          gtdt_frame->timer_flags);
>> +             if (frame->phys_irq <= 0) {
>> +                     pr_warn("failed to map physical timer irq in frame %d.\n",
>> +                             gtdt_frame->frame_number);
>> +                     goto error;
>> +             }
>> +
>> +             if (gtdt_frame->virtual_timer_interrupt) {
>> +                     frame->virt_irq =
>> +                             map_gt_gsi(gtdt_frame->virtual_timer_interrupt,
>> +                                        gtdt_frame->virtual_timer_flags);
>> +                     if (frame->virt_irq <= 0) {
>> +                             pr_warn("failed to map virtual timer irq in frame %d.\n",
>> +                                     gtdt_frame->frame_number);
>> +                             acpi_unregister_gsi(gtdt_frame->timer_interrupt);
>> +                             goto error;
>> +                     }
>> +             } else {
>> +                     frame->virt_irq = 0;
>> +                     pr_debug("virtual timer in frame %d not implemented.\n",
>> +                              gtdt_frame->frame_number);
>> +             }
>> +
>> +             frame->cntbase = gtdt_frame->base_address;
>> +             /*
>> +              * The CNTBaseN frame is 4KB (register offsets 0x000 - 0xFFC).
>> +              * See ARM DDI 0487A.k_iss10775, page I1-5130, Table I1-4
>> +              * "CNTBaseN memory map".
>> +              */
>> +             frame->size = SZ_4K;
>> +             frame->valid = true;
>> +     }
>> +
>> +     return 0;
>> +
>> +error:
>> +     for (i = 0; i < ARCH_TIMER_MEM_MAX_FRAMES; i++) {
>> +             frame = &timer_mem->frame[i];
>> +             if (!frame->valid)
>> +                     continue;
>> +             irq_dispose_mapping(frame->phys_irq);
>> +             if (frame->virt_irq)
>> +                     irq_dispose_mapping(frame->virt_irq);
>> +     }
>
> You should unregister GSIs with the same API you use to register GSIs,
> I do not like code that assumes acpi_unregister_gsi() internal
> implementation, it is wrong to do that.

Thanks for pointing it out, I have thought about it.
But the the same API I use to register GSIs is acpi_unregister_gsi(GSI);
that means we need GSI as the parameter. But when the register goes
wrong, and goto error, the info we have is the IRQ but not GSI. So I
use the  acpi_unregister_gsi() internal implementation.
If we try to use the same API, we may need to add this info into
struct arch_timer_mem_frame only for unwinding.

But yes, we do have another way to do, that is  registering GSI untill
we figure out which is the "best_frame". But this requires some bigger
change(like using the  irq_of_parse_and_map() internal implementation
to get GSI but don't map), and map GSI untill get the "best_frame" .

which way do you prefer?

But I will unify the API in v24

>
> Other than that patch is ok:
>
> Acked-by: Lorenzo Pieralisi <lorenzo.pieralisi-5wv7dgnIgG8@public.gmane.org>
>
>> +     return -EINVAL;
>> +}
>> +
>> +/**
>> + * acpi_arch_timer_mem_init() - Get the info of all GT blocks in GTDT table.
>> + * @timer_mem:       The pointer to the array of struct arch_timer_mem for returning
>> + *           the result of parsing. The element number of this array should
>> + *           be platform_timer_count(the total number of platform timers).
>> + * @timer_count: It points to a integer variable which is used for storing the
>> + *           number of GT blocks we have parsed.
>> + *
>> + * Return: 0 if success, -EINVAL/-ENODEV if error.
>> + */
>> +int __init acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem,
>> +                                 int *timer_count)
>> +{
>> +     int ret;
>> +     void *platform_timer;
>> +
>> +     *timer_count = 0;
>> +     for_each_platform_timer(platform_timer) {
>> +             if (is_timer_block(platform_timer)) {
>> +                     ret = gtdt_parse_timer_block(platform_timer, timer_mem);
>> +                     if (ret)
>> +                             return ret;
>> +                     timer_mem++;
>> +                     (*timer_count)++;
>> +             }
>> +     }
>> +
>> +     if (*timer_count)
>> +             pr_info("found %d memory-mapped timer block(s).\n",
>> +                     *timer_count);
>> +
>> +     return 0;
>> +}
>> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
>> index 4b5c146..3193724 100644
>> --- a/include/linux/acpi.h
>> +++ b/include/linux/acpi.h
>> @@ -599,6 +599,7 @@ int acpi_reconfig_notifier_unregister(struct notifier_block *nb);
>>  int acpi_gtdt_init(struct acpi_table_header *table, int *platform_timer_count);
>>  int acpi_gtdt_map_ppi(int type);
>>  bool acpi_gtdt_c3stop(int type);
>> +int acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem, int *timer_count);
>>  #endif
>>
>>  #else        /* !CONFIG_ACPI */
>> --
>> 2.9.3
>>



-- 
Best regards,

Fu Wei
Software Engineer
Red Hat
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
@ 2017-04-06 17:11         ` Fu Wei
  0 siblings, 0 replies; 66+ messages in thread
From: Fu Wei @ 2017-04-06 17:11 UTC (permalink / raw)
  To: Lorenzo Pieralisi
  Cc: Rafael J. Wysocki, Len Brown, Daniel Lezcano, Thomas Gleixner,
	Marc Zyngier, Mark Rutland, Sudeep Holla, Hanjun Guo,
	linux-arm-kernel, Linaro ACPI Mailman List,
	Linux Kernel Mailing List, ACPI Devel Maling List, rruigrok,
	Abdulhamid, Harb, Christopher Covington, Timur Tabi, G Gregory,
	Al Stone, Jon Masters, Wei Huang, Arnd Bergmann, Catalin Marinas,
	Will Deacon, Suravee Suthikulpanit, Leo Duran, Wim Van Sebroeck,
	Guenter Roeck, linux-watchdog, Tomasz Nowicki, Christoffer Dall,
	Julien Grall

Hi Lorenzo,

On 3 April 2017 at 18:45, Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> wrote:
> On Sat, Apr 01, 2017 at 01:51:03AM +0800, fu.wei@linaro.org wrote:
>> From: Fu Wei <fu.wei@linaro.org>
>>
>> On platforms booting with ACPI, architected memory-mapped timers'
>> configuration data is provided by firmware through the ACPI GTDT
>> static table.
>>
>> The clocksource architected timer kernel driver requires a firmware
>> interface to collect timer configuration and configure its driver.
>> this infrastructure is present for device tree systems, but it is
>> missing on systems booting with ACPI.
>>
>> Implement the kernel infrastructure required to parse the static
>> ACPI GTDT table so that the architected timer clocksource driver can
>> make use of it on systems booting with ACPI, therefore enabling
>> the corresponding timers configuration.
>>
>> Signed-off-by: Fu Wei <fu.wei@linaro.org>
>> Signed-off-by: Hanjun Guo <hanjun.guo@linaro.org>
>> ---
>>  drivers/acpi/arm64/gtdt.c | 146 ++++++++++++++++++++++++++++++++++++++++++++++
>>  include/linux/acpi.h      |   1 +
>>  2 files changed, 147 insertions(+)
>>
>> diff --git a/drivers/acpi/arm64/gtdt.c b/drivers/acpi/arm64/gtdt.c
>> index 3d95af8..3dd33f3 100644
>> --- a/drivers/acpi/arm64/gtdt.c
>> +++ b/drivers/acpi/arm64/gtdt.c
>> @@ -13,6 +13,7 @@
>>
>>  #include <linux/acpi.h>
>>  #include <linux/init.h>
>> +#include <linux/irqdomain.h>
>>  #include <linux/kernel.h>
>>
>>  #include <clocksource/arm_arch_timer.h>
>> @@ -37,6 +38,28 @@ struct acpi_gtdt_descriptor {
>>
>>  static struct acpi_gtdt_descriptor acpi_gtdt_desc __initdata;
>>
>> +static inline void *next_platform_timer(void *platform_timer)
>> +{
>> +     struct acpi_gtdt_header *gh = platform_timer;
>> +
>> +     platform_timer += gh->length;
>> +     if (platform_timer < acpi_gtdt_desc.gtdt_end)
>> +             return platform_timer;
>> +
>> +     return NULL;
>> +}
>> +
>> +#define for_each_platform_timer(_g)                          \
>> +     for (_g = acpi_gtdt_desc.platform_timer; _g;    \
>> +          _g = next_platform_timer(_g))
>> +
>> +static inline bool is_timer_block(void *platform_timer)
>> +{
>> +     struct acpi_gtdt_header *gh = platform_timer;
>> +
>> +     return gh->type == ACPI_GTDT_TYPE_TIMER_BLOCK;
>> +}
>> +
>>  static int __init map_gt_gsi(u32 interrupt, u32 flags)
>>  {
>>       int trigger, polarity;
>> @@ -155,3 +178,126 @@ int __init acpi_gtdt_init(struct acpi_table_header *table,
>>
>>       return 0;
>>  }
>> +
>> +static int __init gtdt_parse_timer_block(struct acpi_gtdt_timer_block *block,
>> +                                      struct arch_timer_mem *timer_mem)
>> +{
>> +     int i;
>> +     struct arch_timer_mem_frame *frame;
>> +     struct acpi_gtdt_timer_entry *gtdt_frame;
>> +
>> +     if (!block->timer_count) {
>> +             pr_err(FW_BUG "GT block present, but frame count is zero.");
>> +             return -ENODEV;
>> +     }
>> +
>> +     if (block->timer_count > ARCH_TIMER_MEM_MAX_FRAMES) {
>> +             pr_err(FW_BUG "GT block lists %d frames, ACPI spec only allows 8\n",
>> +                    block->timer_count);
>> +             return -EINVAL;
>> +     }
>> +
>> +     timer_mem->cntctlbase = (phys_addr_t)block->block_address;
>> +     /*
>> +      * The CNTCTLBase frame is 4KB (register offsets 0x000 - 0xFFC).
>> +      * See ARM DDI 0487A.k_iss10775, page I1-5129, Table I1-3
>> +      * "CNTCTLBase memory map".
>> +      */
>> +     timer_mem->size = SZ_4K;
>> +
>> +     gtdt_frame = (void *)block + block->timer_offset;
>> +     if (gtdt_frame + block->timer_count != (void *)block + block->header.length)
>> +             return -EINVAL;
>> +
>> +     /*
>> +      * Get the GT timer Frame data for every GT Block Timer
>> +      */
>> +     for (i = 0; i < block->timer_count; i++, gtdt_frame++) {
>> +             if (gtdt_frame->common_flags & ACPI_GTDT_GT_IS_SECURE_TIMER)
>> +                     continue;
>> +
>> +             if (!gtdt_frame->base_address || !gtdt_frame->timer_interrupt)
>> +                     goto error;
>> +
>> +             frame = &timer_mem->frame[gtdt_frame->frame_number];
>> +             frame->phys_irq = map_gt_gsi(gtdt_frame->timer_interrupt,
>> +                                          gtdt_frame->timer_flags);
>> +             if (frame->phys_irq <= 0) {
>> +                     pr_warn("failed to map physical timer irq in frame %d.\n",
>> +                             gtdt_frame->frame_number);
>> +                     goto error;
>> +             }
>> +
>> +             if (gtdt_frame->virtual_timer_interrupt) {
>> +                     frame->virt_irq =
>> +                             map_gt_gsi(gtdt_frame->virtual_timer_interrupt,
>> +                                        gtdt_frame->virtual_timer_flags);
>> +                     if (frame->virt_irq <= 0) {
>> +                             pr_warn("failed to map virtual timer irq in frame %d.\n",
>> +                                     gtdt_frame->frame_number);
>> +                             acpi_unregister_gsi(gtdt_frame->timer_interrupt);
>> +                             goto error;
>> +                     }
>> +             } else {
>> +                     frame->virt_irq = 0;
>> +                     pr_debug("virtual timer in frame %d not implemented.\n",
>> +                              gtdt_frame->frame_number);
>> +             }
>> +
>> +             frame->cntbase = gtdt_frame->base_address;
>> +             /*
>> +              * The CNTBaseN frame is 4KB (register offsets 0x000 - 0xFFC).
>> +              * See ARM DDI 0487A.k_iss10775, page I1-5130, Table I1-4
>> +              * "CNTBaseN memory map".
>> +              */
>> +             frame->size = SZ_4K;
>> +             frame->valid = true;
>> +     }
>> +
>> +     return 0;
>> +
>> +error:
>> +     for (i = 0; i < ARCH_TIMER_MEM_MAX_FRAMES; i++) {
>> +             frame = &timer_mem->frame[i];
>> +             if (!frame->valid)
>> +                     continue;
>> +             irq_dispose_mapping(frame->phys_irq);
>> +             if (frame->virt_irq)
>> +                     irq_dispose_mapping(frame->virt_irq);
>> +     }
>
> You should unregister GSIs with the same API you use to register GSIs,
> I do not like code that assumes acpi_unregister_gsi() internal
> implementation, it is wrong to do that.

Thanks for pointing it out, I have thought about it.
But the the same API I use to register GSIs is acpi_unregister_gsi(GSI);
that means we need GSI as the parameter. But when the register goes
wrong, and goto error, the info we have is the IRQ but not GSI. So I
use the  acpi_unregister_gsi() internal implementation.
If we try to use the same API, we may need to add this info into
struct arch_timer_mem_frame only for unwinding.

But yes, we do have another way to do, that is  registering GSI untill
we figure out which is the "best_frame". But this requires some bigger
change(like using the  irq_of_parse_and_map() internal implementation
to get GSI but don't map), and map GSI untill get the "best_frame" .

which way do you prefer?

But I will unify the API in v24

>
> Other than that patch is ok:
>
> Acked-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
>
>> +     return -EINVAL;
>> +}
>> +
>> +/**
>> + * acpi_arch_timer_mem_init() - Get the info of all GT blocks in GTDT table.
>> + * @timer_mem:       The pointer to the array of struct arch_timer_mem for returning
>> + *           the result of parsing. The element number of this array should
>> + *           be platform_timer_count(the total number of platform timers).
>> + * @timer_count: It points to a integer variable which is used for storing the
>> + *           number of GT blocks we have parsed.
>> + *
>> + * Return: 0 if success, -EINVAL/-ENODEV if error.
>> + */
>> +int __init acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem,
>> +                                 int *timer_count)
>> +{
>> +     int ret;
>> +     void *platform_timer;
>> +
>> +     *timer_count = 0;
>> +     for_each_platform_timer(platform_timer) {
>> +             if (is_timer_block(platform_timer)) {
>> +                     ret = gtdt_parse_timer_block(platform_timer, timer_mem);
>> +                     if (ret)
>> +                             return ret;
>> +                     timer_mem++;
>> +                     (*timer_count)++;
>> +             }
>> +     }
>> +
>> +     if (*timer_count)
>> +             pr_info("found %d memory-mapped timer block(s).\n",
>> +                     *timer_count);
>> +
>> +     return 0;
>> +}
>> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
>> index 4b5c146..3193724 100644
>> --- a/include/linux/acpi.h
>> +++ b/include/linux/acpi.h
>> @@ -599,6 +599,7 @@ int acpi_reconfig_notifier_unregister(struct notifier_block *nb);
>>  int acpi_gtdt_init(struct acpi_table_header *table, int *platform_timer_count);
>>  int acpi_gtdt_map_ppi(int type);
>>  bool acpi_gtdt_c3stop(int type);
>> +int acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem, int *timer_count);
>>  #endif
>>
>>  #else        /* !CONFIG_ACPI */
>> --
>> 2.9.3
>>



-- 
Best regards,

Fu Wei
Software Engineer
Red Hat

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

* [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
@ 2017-04-06 17:11         ` Fu Wei
  0 siblings, 0 replies; 66+ messages in thread
From: Fu Wei @ 2017-04-06 17:11 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Lorenzo,

On 3 April 2017 at 18:45, Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> wrote:
> On Sat, Apr 01, 2017 at 01:51:03AM +0800, fu.wei at linaro.org wrote:
>> From: Fu Wei <fu.wei@linaro.org>
>>
>> On platforms booting with ACPI, architected memory-mapped timers'
>> configuration data is provided by firmware through the ACPI GTDT
>> static table.
>>
>> The clocksource architected timer kernel driver requires a firmware
>> interface to collect timer configuration and configure its driver.
>> this infrastructure is present for device tree systems, but it is
>> missing on systems booting with ACPI.
>>
>> Implement the kernel infrastructure required to parse the static
>> ACPI GTDT table so that the architected timer clocksource driver can
>> make use of it on systems booting with ACPI, therefore enabling
>> the corresponding timers configuration.
>>
>> Signed-off-by: Fu Wei <fu.wei@linaro.org>
>> Signed-off-by: Hanjun Guo <hanjun.guo@linaro.org>
>> ---
>>  drivers/acpi/arm64/gtdt.c | 146 ++++++++++++++++++++++++++++++++++++++++++++++
>>  include/linux/acpi.h      |   1 +
>>  2 files changed, 147 insertions(+)
>>
>> diff --git a/drivers/acpi/arm64/gtdt.c b/drivers/acpi/arm64/gtdt.c
>> index 3d95af8..3dd33f3 100644
>> --- a/drivers/acpi/arm64/gtdt.c
>> +++ b/drivers/acpi/arm64/gtdt.c
>> @@ -13,6 +13,7 @@
>>
>>  #include <linux/acpi.h>
>>  #include <linux/init.h>
>> +#include <linux/irqdomain.h>
>>  #include <linux/kernel.h>
>>
>>  #include <clocksource/arm_arch_timer.h>
>> @@ -37,6 +38,28 @@ struct acpi_gtdt_descriptor {
>>
>>  static struct acpi_gtdt_descriptor acpi_gtdt_desc __initdata;
>>
>> +static inline void *next_platform_timer(void *platform_timer)
>> +{
>> +     struct acpi_gtdt_header *gh = platform_timer;
>> +
>> +     platform_timer += gh->length;
>> +     if (platform_timer < acpi_gtdt_desc.gtdt_end)
>> +             return platform_timer;
>> +
>> +     return NULL;
>> +}
>> +
>> +#define for_each_platform_timer(_g)                          \
>> +     for (_g = acpi_gtdt_desc.platform_timer; _g;    \
>> +          _g = next_platform_timer(_g))
>> +
>> +static inline bool is_timer_block(void *platform_timer)
>> +{
>> +     struct acpi_gtdt_header *gh = platform_timer;
>> +
>> +     return gh->type == ACPI_GTDT_TYPE_TIMER_BLOCK;
>> +}
>> +
>>  static int __init map_gt_gsi(u32 interrupt, u32 flags)
>>  {
>>       int trigger, polarity;
>> @@ -155,3 +178,126 @@ int __init acpi_gtdt_init(struct acpi_table_header *table,
>>
>>       return 0;
>>  }
>> +
>> +static int __init gtdt_parse_timer_block(struct acpi_gtdt_timer_block *block,
>> +                                      struct arch_timer_mem *timer_mem)
>> +{
>> +     int i;
>> +     struct arch_timer_mem_frame *frame;
>> +     struct acpi_gtdt_timer_entry *gtdt_frame;
>> +
>> +     if (!block->timer_count) {
>> +             pr_err(FW_BUG "GT block present, but frame count is zero.");
>> +             return -ENODEV;
>> +     }
>> +
>> +     if (block->timer_count > ARCH_TIMER_MEM_MAX_FRAMES) {
>> +             pr_err(FW_BUG "GT block lists %d frames, ACPI spec only allows 8\n",
>> +                    block->timer_count);
>> +             return -EINVAL;
>> +     }
>> +
>> +     timer_mem->cntctlbase = (phys_addr_t)block->block_address;
>> +     /*
>> +      * The CNTCTLBase frame is 4KB (register offsets 0x000 - 0xFFC).
>> +      * See ARM DDI 0487A.k_iss10775, page I1-5129, Table I1-3
>> +      * "CNTCTLBase memory map".
>> +      */
>> +     timer_mem->size = SZ_4K;
>> +
>> +     gtdt_frame = (void *)block + block->timer_offset;
>> +     if (gtdt_frame + block->timer_count != (void *)block + block->header.length)
>> +             return -EINVAL;
>> +
>> +     /*
>> +      * Get the GT timer Frame data for every GT Block Timer
>> +      */
>> +     for (i = 0; i < block->timer_count; i++, gtdt_frame++) {
>> +             if (gtdt_frame->common_flags & ACPI_GTDT_GT_IS_SECURE_TIMER)
>> +                     continue;
>> +
>> +             if (!gtdt_frame->base_address || !gtdt_frame->timer_interrupt)
>> +                     goto error;
>> +
>> +             frame = &timer_mem->frame[gtdt_frame->frame_number];
>> +             frame->phys_irq = map_gt_gsi(gtdt_frame->timer_interrupt,
>> +                                          gtdt_frame->timer_flags);
>> +             if (frame->phys_irq <= 0) {
>> +                     pr_warn("failed to map physical timer irq in frame %d.\n",
>> +                             gtdt_frame->frame_number);
>> +                     goto error;
>> +             }
>> +
>> +             if (gtdt_frame->virtual_timer_interrupt) {
>> +                     frame->virt_irq =
>> +                             map_gt_gsi(gtdt_frame->virtual_timer_interrupt,
>> +                                        gtdt_frame->virtual_timer_flags);
>> +                     if (frame->virt_irq <= 0) {
>> +                             pr_warn("failed to map virtual timer irq in frame %d.\n",
>> +                                     gtdt_frame->frame_number);
>> +                             acpi_unregister_gsi(gtdt_frame->timer_interrupt);
>> +                             goto error;
>> +                     }
>> +             } else {
>> +                     frame->virt_irq = 0;
>> +                     pr_debug("virtual timer in frame %d not implemented.\n",
>> +                              gtdt_frame->frame_number);
>> +             }
>> +
>> +             frame->cntbase = gtdt_frame->base_address;
>> +             /*
>> +              * The CNTBaseN frame is 4KB (register offsets 0x000 - 0xFFC).
>> +              * See ARM DDI 0487A.k_iss10775, page I1-5130, Table I1-4
>> +              * "CNTBaseN memory map".
>> +              */
>> +             frame->size = SZ_4K;
>> +             frame->valid = true;
>> +     }
>> +
>> +     return 0;
>> +
>> +error:
>> +     for (i = 0; i < ARCH_TIMER_MEM_MAX_FRAMES; i++) {
>> +             frame = &timer_mem->frame[i];
>> +             if (!frame->valid)
>> +                     continue;
>> +             irq_dispose_mapping(frame->phys_irq);
>> +             if (frame->virt_irq)
>> +                     irq_dispose_mapping(frame->virt_irq);
>> +     }
>
> You should unregister GSIs with the same API you use to register GSIs,
> I do not like code that assumes acpi_unregister_gsi() internal
> implementation, it is wrong to do that.

Thanks for pointing it out, I have thought about it.
But the the same API I use to register GSIs is acpi_unregister_gsi(GSI);
that means we need GSI as the parameter. But when the register goes
wrong, and goto error, the info we have is the IRQ but not GSI. So I
use the  acpi_unregister_gsi() internal implementation.
If we try to use the same API, we may need to add this info into
struct arch_timer_mem_frame only for unwinding.

But yes, we do have another way to do, that is  registering GSI untill
we figure out which is the "best_frame". But this requires some bigger
change(like using the  irq_of_parse_and_map() internal implementation
to get GSI but don't map), and map GSI untill get the "best_frame" .

which way do you prefer?

But I will unify the API in v24

>
> Other than that patch is ok:
>
> Acked-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
>
>> +     return -EINVAL;
>> +}
>> +
>> +/**
>> + * acpi_arch_timer_mem_init() - Get the info of all GT blocks in GTDT table.
>> + * @timer_mem:       The pointer to the array of struct arch_timer_mem for returning
>> + *           the result of parsing. The element number of this array should
>> + *           be platform_timer_count(the total number of platform timers).
>> + * @timer_count: It points to a integer variable which is used for storing the
>> + *           number of GT blocks we have parsed.
>> + *
>> + * Return: 0 if success, -EINVAL/-ENODEV if error.
>> + */
>> +int __init acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem,
>> +                                 int *timer_count)
>> +{
>> +     int ret;
>> +     void *platform_timer;
>> +
>> +     *timer_count = 0;
>> +     for_each_platform_timer(platform_timer) {
>> +             if (is_timer_block(platform_timer)) {
>> +                     ret = gtdt_parse_timer_block(platform_timer, timer_mem);
>> +                     if (ret)
>> +                             return ret;
>> +                     timer_mem++;
>> +                     (*timer_count)++;
>> +             }
>> +     }
>> +
>> +     if (*timer_count)
>> +             pr_info("found %d memory-mapped timer block(s).\n",
>> +                     *timer_count);
>> +
>> +     return 0;
>> +}
>> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
>> index 4b5c146..3193724 100644
>> --- a/include/linux/acpi.h
>> +++ b/include/linux/acpi.h
>> @@ -599,6 +599,7 @@ int acpi_reconfig_notifier_unregister(struct notifier_block *nb);
>>  int acpi_gtdt_init(struct acpi_table_header *table, int *platform_timer_count);
>>  int acpi_gtdt_map_ppi(int type);
>>  bool acpi_gtdt_c3stop(int type);
>> +int acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem, int *timer_count);
>>  #endif
>>
>>  #else        /* !CONFIG_ACPI */
>> --
>> 2.9.3
>>



-- 
Best regards,

Fu Wei
Software Engineer
Red Hat

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

* Re: [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
  2017-04-06 16:47         ` Fu Wei
  (?)
@ 2017-04-06 17:24             ` Mark Rutland
  -1 siblings, 0 replies; 66+ messages in thread
From: Mark Rutland @ 2017-04-06 17:24 UTC (permalink / raw)
  To: Fu Wei
  Cc: Rafael J. Wysocki, Len Brown, Daniel Lezcano, Thomas Gleixner,
	Marc Zyngier, Lorenzo Pieralisi, Sudeep Holla, Hanjun Guo,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	Linaro ACPI Mailman List, Linux Kernel Mailing List,
	ACPI Devel Maling List, rruigrok-sgV2jX0FEOL9JmXXK+q4OQ,
	Abdulhamid, Harb, Christopher Covington, Timur Tabi, G Gregory,
	Al Stone, Jon Masters

On Fri, Apr 07, 2017 at 12:47:47AM +0800, Fu Wei wrote:
> On 6 April 2017 at 02:38, Mark Rutland <mark.rutland-5wv7dgnIgG8@public.gmane.org> wrote:
> > On Sat, Apr 01, 2017 at 01:51:03AM +0800, fu.wei-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org wrote:
> >> +     /*
> >> +      * Get the GT timer Frame data for every GT Block Timer
> >> +      */
> >> +     for (i = 0; i < block->timer_count; i++, gtdt_frame++) {
> >> +             if (gtdt_frame->common_flags & ACPI_GTDT_GT_IS_SECURE_TIMER)
> >> +                     continue;
> >> +
> >> +             if (!gtdt_frame->base_address || !gtdt_frame->timer_interrupt)
> >> +                     goto error;
> >> +
> >> +             frame = &timer_mem->frame[gtdt_frame->frame_number];
> >> +             frame->phys_irq = map_gt_gsi(gtdt_frame->timer_interrupt,
> >> +                                          gtdt_frame->timer_flags);
> >> +             if (frame->phys_irq <= 0) {
> >> +                     pr_warn("failed to map physical timer irq in frame %d.\n",
> >> +                             gtdt_frame->frame_number);
> >> +                     goto error;
> >> +             }
> >> +
> >> +             if (gtdt_frame->virtual_timer_interrupt) {
> >> +                     frame->virt_irq =
> >> +                             map_gt_gsi(gtdt_frame->virtual_timer_interrupt,
> >> +                                        gtdt_frame->virtual_timer_flags);
> >> +                     if (frame->virt_irq <= 0) {
> >> +                             pr_warn("failed to map virtual timer irq in frame %d.\n",
> >> +                                     gtdt_frame->frame_number);
> >> +                             acpi_unregister_gsi(gtdt_frame->timer_interrupt);
> >> +                             goto error;
> >> +                     }
> >> +             } else {
> >> +                     frame->virt_irq = 0;
> >> +                     pr_debug("virtual timer in frame %d not implemented.\n",
> >> +                              gtdt_frame->frame_number);
> >> +             }
> >> +
> >> +             frame->cntbase = gtdt_frame->base_address;
> >> +             /*
> >> +              * The CNTBaseN frame is 4KB (register offsets 0x000 - 0xFFC).
> >> +              * See ARM DDI 0487A.k_iss10775, page I1-5130, Table I1-4
> >> +              * "CNTBaseN memory map".
> >> +              */
> >> +             frame->size = SZ_4K;
> >> +             frame->valid = true;
> >> +     }
> >> +
> >> +     return 0;
> >> +
> >> +error:
> >> +     for (i = 0; i < ARCH_TIMER_MEM_MAX_FRAMES; i++) {
> >> +             frame = &timer_mem->frame[i];
> >> +             if (!frame->valid)
> >> +                     continue;
> >> +             irq_dispose_mapping(frame->phys_irq);
> >> +             if (frame->virt_irq)
> >> +                     irq_dispose_mapping(frame->virt_irq);
> >> +     }
> >
> > We assign interrupts and may goto error before setting valid, so here we
> 
> yes, I mean to do it.(setting valid at the end of loop)
> 
> > won't free the interrupts of the last frame we parsed.
> 
> that won't  be a problem, we may assign two interrupts in a round:
> First of all, if  the assignment goes  wrong, that means the current
> interrupt haven't been successfully assigned.
> (1)if the first goes wrong, the we goto error to unwind  the irqs
> assigned in previous rounds.
> (2)if the second one goes wrong , we acpi_unregister_gsi the first one
> and then  goto error to unwind  the irqs assigned in previous rounds.
> (3)If the two assignments are successful, set up valid flag
> 
> So we won't miss freeing the interrupts of the last frame we parsed.
> 
> Did I miss something?

No; you are correct, and I was mistaken.

However, I would prefer to simplify this such that we only free the
IRQs in the error path.

We should be able to iterate over all freams, freeing any non-zero
interrupt, since !valid frames shouldn't have non-zero interrupts.

I can make that update locally; no need to respin.

Thanks,
Mark.
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
@ 2017-04-06 17:24             ` Mark Rutland
  0 siblings, 0 replies; 66+ messages in thread
From: Mark Rutland @ 2017-04-06 17:24 UTC (permalink / raw)
  To: Fu Wei
  Cc: Rafael J. Wysocki, Len Brown, Daniel Lezcano, Thomas Gleixner,
	Marc Zyngier, Lorenzo Pieralisi, Sudeep Holla, Hanjun Guo,
	linux-arm-kernel, Linaro ACPI Mailman List,
	Linux Kernel Mailing List, ACPI Devel Maling List, rruigrok,
	Abdulhamid, Harb, Christopher Covington, Timur Tabi, G Gregory,
	Al Stone, Jon Masters, Wei Huang, Arnd Bergmann, Catalin Marinas,
	Will Deacon, Suravee Suthikulpanit, Leo Duran, Wim Van Sebroeck,
	Guenter Roeck, linux-watchdog, Tomasz Nowicki, Christoffer Dall,
	Julien Grall

On Fri, Apr 07, 2017 at 12:47:47AM +0800, Fu Wei wrote:
> On 6 April 2017 at 02:38, Mark Rutland <mark.rutland@arm.com> wrote:
> > On Sat, Apr 01, 2017 at 01:51:03AM +0800, fu.wei@linaro.org wrote:
> >> +     /*
> >> +      * Get the GT timer Frame data for every GT Block Timer
> >> +      */
> >> +     for (i = 0; i < block->timer_count; i++, gtdt_frame++) {
> >> +             if (gtdt_frame->common_flags & ACPI_GTDT_GT_IS_SECURE_TIMER)
> >> +                     continue;
> >> +
> >> +             if (!gtdt_frame->base_address || !gtdt_frame->timer_interrupt)
> >> +                     goto error;
> >> +
> >> +             frame = &timer_mem->frame[gtdt_frame->frame_number];
> >> +             frame->phys_irq = map_gt_gsi(gtdt_frame->timer_interrupt,
> >> +                                          gtdt_frame->timer_flags);
> >> +             if (frame->phys_irq <= 0) {
> >> +                     pr_warn("failed to map physical timer irq in frame %d.\n",
> >> +                             gtdt_frame->frame_number);
> >> +                     goto error;
> >> +             }
> >> +
> >> +             if (gtdt_frame->virtual_timer_interrupt) {
> >> +                     frame->virt_irq =
> >> +                             map_gt_gsi(gtdt_frame->virtual_timer_interrupt,
> >> +                                        gtdt_frame->virtual_timer_flags);
> >> +                     if (frame->virt_irq <= 0) {
> >> +                             pr_warn("failed to map virtual timer irq in frame %d.\n",
> >> +                                     gtdt_frame->frame_number);
> >> +                             acpi_unregister_gsi(gtdt_frame->timer_interrupt);
> >> +                             goto error;
> >> +                     }
> >> +             } else {
> >> +                     frame->virt_irq = 0;
> >> +                     pr_debug("virtual timer in frame %d not implemented.\n",
> >> +                              gtdt_frame->frame_number);
> >> +             }
> >> +
> >> +             frame->cntbase = gtdt_frame->base_address;
> >> +             /*
> >> +              * The CNTBaseN frame is 4KB (register offsets 0x000 - 0xFFC).
> >> +              * See ARM DDI 0487A.k_iss10775, page I1-5130, Table I1-4
> >> +              * "CNTBaseN memory map".
> >> +              */
> >> +             frame->size = SZ_4K;
> >> +             frame->valid = true;
> >> +     }
> >> +
> >> +     return 0;
> >> +
> >> +error:
> >> +     for (i = 0; i < ARCH_TIMER_MEM_MAX_FRAMES; i++) {
> >> +             frame = &timer_mem->frame[i];
> >> +             if (!frame->valid)
> >> +                     continue;
> >> +             irq_dispose_mapping(frame->phys_irq);
> >> +             if (frame->virt_irq)
> >> +                     irq_dispose_mapping(frame->virt_irq);
> >> +     }
> >
> > We assign interrupts and may goto error before setting valid, so here we
> 
> yes, I mean to do it.(setting valid at the end of loop)
> 
> > won't free the interrupts of the last frame we parsed.
> 
> that won't  be a problem, we may assign two interrupts in a round:
> First of all, if  the assignment goes  wrong, that means the current
> interrupt haven't been successfully assigned.
> (1)if the first goes wrong, the we goto error to unwind  the irqs
> assigned in previous rounds.
> (2)if the second one goes wrong , we acpi_unregister_gsi the first one
> and then  goto error to unwind  the irqs assigned in previous rounds.
> (3)If the two assignments are successful, set up valid flag
> 
> So we won't miss freeing the interrupts of the last frame we parsed.
> 
> Did I miss something?

No; you are correct, and I was mistaken.

However, I would prefer to simplify this such that we only free the
IRQs in the error path.

We should be able to iterate over all freams, freeing any non-zero
interrupt, since !valid frames shouldn't have non-zero interrupts.

I can make that update locally; no need to respin.

Thanks,
Mark.

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

* [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
@ 2017-04-06 17:24             ` Mark Rutland
  0 siblings, 0 replies; 66+ messages in thread
From: Mark Rutland @ 2017-04-06 17:24 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Apr 07, 2017 at 12:47:47AM +0800, Fu Wei wrote:
> On 6 April 2017 at 02:38, Mark Rutland <mark.rutland@arm.com> wrote:
> > On Sat, Apr 01, 2017 at 01:51:03AM +0800, fu.wei at linaro.org wrote:
> >> +     /*
> >> +      * Get the GT timer Frame data for every GT Block Timer
> >> +      */
> >> +     for (i = 0; i < block->timer_count; i++, gtdt_frame++) {
> >> +             if (gtdt_frame->common_flags & ACPI_GTDT_GT_IS_SECURE_TIMER)
> >> +                     continue;
> >> +
> >> +             if (!gtdt_frame->base_address || !gtdt_frame->timer_interrupt)
> >> +                     goto error;
> >> +
> >> +             frame = &timer_mem->frame[gtdt_frame->frame_number];
> >> +             frame->phys_irq = map_gt_gsi(gtdt_frame->timer_interrupt,
> >> +                                          gtdt_frame->timer_flags);
> >> +             if (frame->phys_irq <= 0) {
> >> +                     pr_warn("failed to map physical timer irq in frame %d.\n",
> >> +                             gtdt_frame->frame_number);
> >> +                     goto error;
> >> +             }
> >> +
> >> +             if (gtdt_frame->virtual_timer_interrupt) {
> >> +                     frame->virt_irq =
> >> +                             map_gt_gsi(gtdt_frame->virtual_timer_interrupt,
> >> +                                        gtdt_frame->virtual_timer_flags);
> >> +                     if (frame->virt_irq <= 0) {
> >> +                             pr_warn("failed to map virtual timer irq in frame %d.\n",
> >> +                                     gtdt_frame->frame_number);
> >> +                             acpi_unregister_gsi(gtdt_frame->timer_interrupt);
> >> +                             goto error;
> >> +                     }
> >> +             } else {
> >> +                     frame->virt_irq = 0;
> >> +                     pr_debug("virtual timer in frame %d not implemented.\n",
> >> +                              gtdt_frame->frame_number);
> >> +             }
> >> +
> >> +             frame->cntbase = gtdt_frame->base_address;
> >> +             /*
> >> +              * The CNTBaseN frame is 4KB (register offsets 0x000 - 0xFFC).
> >> +              * See ARM DDI 0487A.k_iss10775, page I1-5130, Table I1-4
> >> +              * "CNTBaseN memory map".
> >> +              */
> >> +             frame->size = SZ_4K;
> >> +             frame->valid = true;
> >> +     }
> >> +
> >> +     return 0;
> >> +
> >> +error:
> >> +     for (i = 0; i < ARCH_TIMER_MEM_MAX_FRAMES; i++) {
> >> +             frame = &timer_mem->frame[i];
> >> +             if (!frame->valid)
> >> +                     continue;
> >> +             irq_dispose_mapping(frame->phys_irq);
> >> +             if (frame->virt_irq)
> >> +                     irq_dispose_mapping(frame->virt_irq);
> >> +     }
> >
> > We assign interrupts and may goto error before setting valid, so here we
> 
> yes, I mean to do it.(setting valid at the end of loop)
> 
> > won't free the interrupts of the last frame we parsed.
> 
> that won't  be a problem, we may assign two interrupts in a round:
> First of all, if  the assignment goes  wrong, that means the current
> interrupt haven't been successfully assigned.
> (1)if the first goes wrong, the we goto error to unwind  the irqs
> assigned in previous rounds.
> (2)if the second one goes wrong , we acpi_unregister_gsi the first one
> and then  goto error to unwind  the irqs assigned in previous rounds.
> (3)If the two assignments are successful, set up valid flag
> 
> So we won't miss freeing the interrupts of the last frame we parsed.
> 
> Did I miss something?

No; you are correct, and I was mistaken.

However, I would prefer to simplify this such that we only free the
IRQs in the error path.

We should be able to iterate over all freams, freeing any non-zero
interrupt, since !valid frames shouldn't have non-zero interrupts.

I can make that update locally; no need to respin.

Thanks,
Mark.

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

* Re: [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
  2017-04-06 17:24             ` Mark Rutland
  (?)
@ 2017-04-06 17:39               ` Fu Wei
  -1 siblings, 0 replies; 66+ messages in thread
From: Fu Wei @ 2017-04-06 17:39 UTC (permalink / raw)
  To: Mark Rutland
  Cc: Rafael J. Wysocki, Len Brown, Daniel Lezcano, Thomas Gleixner,
	Marc Zyngier, Lorenzo Pieralisi, Sudeep Holla, Hanjun Guo,
	linux-arm-kernel, Linaro ACPI Mailman List,
	Linux Kernel Mailing List, ACPI Devel Maling List, rruigrok,
	Abdulhamid, Harb, Christopher Covington, Timur Tabi, G Gregory,
	Al Stone, Jon Masters

Hi Mark

On 7 April 2017 at 01:24, Mark Rutland <mark.rutland@arm.com> wrote:
> On Fri, Apr 07, 2017 at 12:47:47AM +0800, Fu Wei wrote:
>> On 6 April 2017 at 02:38, Mark Rutland <mark.rutland@arm.com> wrote:
>> > On Sat, Apr 01, 2017 at 01:51:03AM +0800, fu.wei@linaro.org wrote:
>> >> +     /*
>> >> +      * Get the GT timer Frame data for every GT Block Timer
>> >> +      */
>> >> +     for (i = 0; i < block->timer_count; i++, gtdt_frame++) {
>> >> +             if (gtdt_frame->common_flags & ACPI_GTDT_GT_IS_SECURE_TIMER)
>> >> +                     continue;
>> >> +
>> >> +             if (!gtdt_frame->base_address || !gtdt_frame->timer_interrupt)
>> >> +                     goto error;
>> >> +
>> >> +             frame = &timer_mem->frame[gtdt_frame->frame_number];
>> >> +             frame->phys_irq = map_gt_gsi(gtdt_frame->timer_interrupt,
>> >> +                                          gtdt_frame->timer_flags);
>> >> +             if (frame->phys_irq <= 0) {
>> >> +                     pr_warn("failed to map physical timer irq in frame %d.\n",
>> >> +                             gtdt_frame->frame_number);
>> >> +                     goto error;
>> >> +             }
>> >> +
>> >> +             if (gtdt_frame->virtual_timer_interrupt) {
>> >> +                     frame->virt_irq =
>> >> +                             map_gt_gsi(gtdt_frame->virtual_timer_interrupt,
>> >> +                                        gtdt_frame->virtual_timer_flags);
>> >> +                     if (frame->virt_irq <= 0) {
>> >> +                             pr_warn("failed to map virtual timer irq in frame %d.\n",
>> >> +                                     gtdt_frame->frame_number);
>> >> +                             acpi_unregister_gsi(gtdt_frame->timer_interrupt);
>> >> +                             goto error;
>> >> +                     }
>> >> +             } else {
>> >> +                     frame->virt_irq = 0;
>> >> +                     pr_debug("virtual timer in frame %d not implemented.\n",
>> >> +                              gtdt_frame->frame_number);
>> >> +             }
>> >> +
>> >> +             frame->cntbase = gtdt_frame->base_address;
>> >> +             /*
>> >> +              * The CNTBaseN frame is 4KB (register offsets 0x000 - 0xFFC).
>> >> +              * See ARM DDI 0487A.k_iss10775, page I1-5130, Table I1-4
>> >> +              * "CNTBaseN memory map".
>> >> +              */
>> >> +             frame->size = SZ_4K;
>> >> +             frame->valid = true;
>> >> +     }
>> >> +
>> >> +     return 0;
>> >> +
>> >> +error:
>> >> +     for (i = 0; i < ARCH_TIMER_MEM_MAX_FRAMES; i++) {
>> >> +             frame = &timer_mem->frame[i];
>> >> +             if (!frame->valid)
>> >> +                     continue;
>> >> +             irq_dispose_mapping(frame->phys_irq);
>> >> +             if (frame->virt_irq)
>> >> +                     irq_dispose_mapping(frame->virt_irq);
>> >> +     }
>> >
>> > We assign interrupts and may goto error before setting valid, so here we
>>
>> yes, I mean to do it.(setting valid at the end of loop)
>>
>> > won't free the interrupts of the last frame we parsed.
>>
>> that won't  be a problem, we may assign two interrupts in a round:
>> First of all, if  the assignment goes  wrong, that means the current
>> interrupt haven't been successfully assigned.
>> (1)if the first goes wrong, the we goto error to unwind  the irqs
>> assigned in previous rounds.
>> (2)if the second one goes wrong , we acpi_unregister_gsi the first one
>> and then  goto error to unwind  the irqs assigned in previous rounds.
>> (3)If the two assignments are successful, set up valid flag
>>
>> So we won't miss freeing the interrupts of the last frame we parsed.
>>
>> Did I miss something?
>
> No; you are correct, and I was mistaken.
>
> However, I would prefer to simplify this such that we only free the
> IRQs in the error path.
>
> We should be able to iterate over all freams, freeing any non-zero
> interrupt, since !valid frames shouldn't have non-zero interrupts.

Yes, that is what I am doing :

 if (!frame->valid)
          continue;

phys_irq must be non-zero, otherwise it was registered incorrectly (an error)
but we need to check virt_irq, it maybe 0 because, this timer frame
may not implement virt timer.
Can we simplify it? any idear?

Lorenzo addressed the API issue, we may can fix it by getting GSI info
from DT, then register it until we figure the best frame.
It may need some big change in DT code

I can do it in V24 , any thought?

Great thanks for your review and help! :-)

>
> I can make that update locally; no need to respin.
>
> Thanks,
> Mark.



-- 
Best regards,

Fu Wei
Software Engineer
Red Hat

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

* Re: [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
@ 2017-04-06 17:39               ` Fu Wei
  0 siblings, 0 replies; 66+ messages in thread
From: Fu Wei @ 2017-04-06 17:39 UTC (permalink / raw)
  To: Mark Rutland
  Cc: Rafael J. Wysocki, Len Brown, Daniel Lezcano, Thomas Gleixner,
	Marc Zyngier, Lorenzo Pieralisi, Sudeep Holla, Hanjun Guo,
	linux-arm-kernel, Linaro ACPI Mailman List,
	Linux Kernel Mailing List, ACPI Devel Maling List, rruigrok,
	Abdulhamid, Harb, Christopher Covington, Timur Tabi, G Gregory,
	Al Stone, Jon Masters, Wei Huang, Arnd Bergmann, Catalin Marinas,
	Will Deacon, Suravee Suthikulpanit, Leo Duran, Wim Van Sebroeck,
	Guenter Roeck, linux-watchdog, Tomasz Nowicki, Christoffer Dall,
	Julien Grall

Hi Mark

On 7 April 2017 at 01:24, Mark Rutland <mark.rutland@arm.com> wrote:
> On Fri, Apr 07, 2017 at 12:47:47AM +0800, Fu Wei wrote:
>> On 6 April 2017 at 02:38, Mark Rutland <mark.rutland@arm.com> wrote:
>> > On Sat, Apr 01, 2017 at 01:51:03AM +0800, fu.wei@linaro.org wrote:
>> >> +     /*
>> >> +      * Get the GT timer Frame data for every GT Block Timer
>> >> +      */
>> >> +     for (i = 0; i < block->timer_count; i++, gtdt_frame++) {
>> >> +             if (gtdt_frame->common_flags & ACPI_GTDT_GT_IS_SECURE_TIMER)
>> >> +                     continue;
>> >> +
>> >> +             if (!gtdt_frame->base_address || !gtdt_frame->timer_interrupt)
>> >> +                     goto error;
>> >> +
>> >> +             frame = &timer_mem->frame[gtdt_frame->frame_number];
>> >> +             frame->phys_irq = map_gt_gsi(gtdt_frame->timer_interrupt,
>> >> +                                          gtdt_frame->timer_flags);
>> >> +             if (frame->phys_irq <= 0) {
>> >> +                     pr_warn("failed to map physical timer irq in frame %d.\n",
>> >> +                             gtdt_frame->frame_number);
>> >> +                     goto error;
>> >> +             }
>> >> +
>> >> +             if (gtdt_frame->virtual_timer_interrupt) {
>> >> +                     frame->virt_irq =
>> >> +                             map_gt_gsi(gtdt_frame->virtual_timer_interrupt,
>> >> +                                        gtdt_frame->virtual_timer_flags);
>> >> +                     if (frame->virt_irq <= 0) {
>> >> +                             pr_warn("failed to map virtual timer irq in frame %d.\n",
>> >> +                                     gtdt_frame->frame_number);
>> >> +                             acpi_unregister_gsi(gtdt_frame->timer_interrupt);
>> >> +                             goto error;
>> >> +                     }
>> >> +             } else {
>> >> +                     frame->virt_irq = 0;
>> >> +                     pr_debug("virtual timer in frame %d not implemented.\n",
>> >> +                              gtdt_frame->frame_number);
>> >> +             }
>> >> +
>> >> +             frame->cntbase = gtdt_frame->base_address;
>> >> +             /*
>> >> +              * The CNTBaseN frame is 4KB (register offsets 0x000 - 0xFFC).
>> >> +              * See ARM DDI 0487A.k_iss10775, page I1-5130, Table I1-4
>> >> +              * "CNTBaseN memory map".
>> >> +              */
>> >> +             frame->size = SZ_4K;
>> >> +             frame->valid = true;
>> >> +     }
>> >> +
>> >> +     return 0;
>> >> +
>> >> +error:
>> >> +     for (i = 0; i < ARCH_TIMER_MEM_MAX_FRAMES; i++) {
>> >> +             frame = &timer_mem->frame[i];
>> >> +             if (!frame->valid)
>> >> +                     continue;
>> >> +             irq_dispose_mapping(frame->phys_irq);
>> >> +             if (frame->virt_irq)
>> >> +                     irq_dispose_mapping(frame->virt_irq);
>> >> +     }
>> >
>> > We assign interrupts and may goto error before setting valid, so here we
>>
>> yes, I mean to do it.(setting valid at the end of loop)
>>
>> > won't free the interrupts of the last frame we parsed.
>>
>> that won't  be a problem, we may assign two interrupts in a round:
>> First of all, if  the assignment goes  wrong, that means the current
>> interrupt haven't been successfully assigned.
>> (1)if the first goes wrong, the we goto error to unwind  the irqs
>> assigned in previous rounds.
>> (2)if the second one goes wrong , we acpi_unregister_gsi the first one
>> and then  goto error to unwind  the irqs assigned in previous rounds.
>> (3)If the two assignments are successful, set up valid flag
>>
>> So we won't miss freeing the interrupts of the last frame we parsed.
>>
>> Did I miss something?
>
> No; you are correct, and I was mistaken.
>
> However, I would prefer to simplify this such that we only free the
> IRQs in the error path.
>
> We should be able to iterate over all freams, freeing any non-zero
> interrupt, since !valid frames shouldn't have non-zero interrupts.

Yes, that is what I am doing :

 if (!frame->valid)
          continue;

phys_irq must be non-zero, otherwise it was registered incorrectly (an error)
but we need to check virt_irq, it maybe 0 because, this timer frame
may not implement virt timer.
Can we simplify it? any idear?

Lorenzo addressed the API issue, we may can fix it by getting GSI info
from DT, then register it until we figure the best frame.
It may need some big change in DT code

I can do it in V24 , any thought?

Great thanks for your review and help! :-)

>
> I can make that update locally; no need to respin.
>
> Thanks,
> Mark.



-- 
Best regards,

Fu Wei
Software Engineer
Red Hat

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

* [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
@ 2017-04-06 17:39               ` Fu Wei
  0 siblings, 0 replies; 66+ messages in thread
From: Fu Wei @ 2017-04-06 17:39 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Mark

On 7 April 2017 at 01:24, Mark Rutland <mark.rutland@arm.com> wrote:
> On Fri, Apr 07, 2017 at 12:47:47AM +0800, Fu Wei wrote:
>> On 6 April 2017 at 02:38, Mark Rutland <mark.rutland@arm.com> wrote:
>> > On Sat, Apr 01, 2017 at 01:51:03AM +0800, fu.wei at linaro.org wrote:
>> >> +     /*
>> >> +      * Get the GT timer Frame data for every GT Block Timer
>> >> +      */
>> >> +     for (i = 0; i < block->timer_count; i++, gtdt_frame++) {
>> >> +             if (gtdt_frame->common_flags & ACPI_GTDT_GT_IS_SECURE_TIMER)
>> >> +                     continue;
>> >> +
>> >> +             if (!gtdt_frame->base_address || !gtdt_frame->timer_interrupt)
>> >> +                     goto error;
>> >> +
>> >> +             frame = &timer_mem->frame[gtdt_frame->frame_number];
>> >> +             frame->phys_irq = map_gt_gsi(gtdt_frame->timer_interrupt,
>> >> +                                          gtdt_frame->timer_flags);
>> >> +             if (frame->phys_irq <= 0) {
>> >> +                     pr_warn("failed to map physical timer irq in frame %d.\n",
>> >> +                             gtdt_frame->frame_number);
>> >> +                     goto error;
>> >> +             }
>> >> +
>> >> +             if (gtdt_frame->virtual_timer_interrupt) {
>> >> +                     frame->virt_irq =
>> >> +                             map_gt_gsi(gtdt_frame->virtual_timer_interrupt,
>> >> +                                        gtdt_frame->virtual_timer_flags);
>> >> +                     if (frame->virt_irq <= 0) {
>> >> +                             pr_warn("failed to map virtual timer irq in frame %d.\n",
>> >> +                                     gtdt_frame->frame_number);
>> >> +                             acpi_unregister_gsi(gtdt_frame->timer_interrupt);
>> >> +                             goto error;
>> >> +                     }
>> >> +             } else {
>> >> +                     frame->virt_irq = 0;
>> >> +                     pr_debug("virtual timer in frame %d not implemented.\n",
>> >> +                              gtdt_frame->frame_number);
>> >> +             }
>> >> +
>> >> +             frame->cntbase = gtdt_frame->base_address;
>> >> +             /*
>> >> +              * The CNTBaseN frame is 4KB (register offsets 0x000 - 0xFFC).
>> >> +              * See ARM DDI 0487A.k_iss10775, page I1-5130, Table I1-4
>> >> +              * "CNTBaseN memory map".
>> >> +              */
>> >> +             frame->size = SZ_4K;
>> >> +             frame->valid = true;
>> >> +     }
>> >> +
>> >> +     return 0;
>> >> +
>> >> +error:
>> >> +     for (i = 0; i < ARCH_TIMER_MEM_MAX_FRAMES; i++) {
>> >> +             frame = &timer_mem->frame[i];
>> >> +             if (!frame->valid)
>> >> +                     continue;
>> >> +             irq_dispose_mapping(frame->phys_irq);
>> >> +             if (frame->virt_irq)
>> >> +                     irq_dispose_mapping(frame->virt_irq);
>> >> +     }
>> >
>> > We assign interrupts and may goto error before setting valid, so here we
>>
>> yes, I mean to do it.(setting valid at the end of loop)
>>
>> > won't free the interrupts of the last frame we parsed.
>>
>> that won't  be a problem, we may assign two interrupts in a round:
>> First of all, if  the assignment goes  wrong, that means the current
>> interrupt haven't been successfully assigned.
>> (1)if the first goes wrong, the we goto error to unwind  the irqs
>> assigned in previous rounds.
>> (2)if the second one goes wrong , we acpi_unregister_gsi the first one
>> and then  goto error to unwind  the irqs assigned in previous rounds.
>> (3)If the two assignments are successful, set up valid flag
>>
>> So we won't miss freeing the interrupts of the last frame we parsed.
>>
>> Did I miss something?
>
> No; you are correct, and I was mistaken.
>
> However, I would prefer to simplify this such that we only free the
> IRQs in the error path.
>
> We should be able to iterate over all freams, freeing any non-zero
> interrupt, since !valid frames shouldn't have non-zero interrupts.

Yes, that is what I am doing :

 if (!frame->valid)
          continue;

phys_irq must be non-zero, otherwise it was registered incorrectly (an error)
but we need to check virt_irq, it maybe 0 because, this timer frame
may not implement virt timer.
Can we simplify it? any idear?

Lorenzo addressed the API issue, we may can fix it by getting GSI info
from DT, then register it until we figure the best frame.
It may need some big change in DT code

I can do it in V24 , any thought?

Great thanks for your review and help! :-)

>
> I can make that update locally; no need to respin.
>
> Thanks,
> Mark.



-- 
Best regards,

Fu Wei
Software Engineer
Red Hat

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

* Re: [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
  2017-04-06 17:39               ` Fu Wei
  (?)
@ 2017-04-06 17:52                 ` Mark Rutland
  -1 siblings, 0 replies; 66+ messages in thread
From: Mark Rutland @ 2017-04-06 17:52 UTC (permalink / raw)
  To: Fu Wei
  Cc: Rafael J. Wysocki, Len Brown, Daniel Lezcano, Thomas Gleixner,
	Marc Zyngier, Lorenzo Pieralisi, Sudeep Holla, Hanjun Guo,
	linux-arm-kernel, Linaro ACPI Mailman List,
	Linux Kernel Mailing List, ACPI Devel Maling List, rruigrok,
	Abdulhamid, Harb, Christopher Covington, Timur Tabi, G Gregory,
	Al Stone, Jon Masters

On Fri, Apr 07, 2017 at 01:39:09AM +0800, Fu Wei wrote:
> On 7 April 2017 at 01:24, Mark Rutland <mark.rutland@arm.com> wrote:
> > On Fri, Apr 07, 2017 at 12:47:47AM +0800, Fu Wei wrote:
> >> On 6 April 2017 at 02:38, Mark Rutland <mark.rutland@arm.com> wrote:
> >> > On Sat, Apr 01, 2017 at 01:51:03AM +0800, fu.wei@linaro.org wrote:

> > However, I would prefer to simplify this such that we only free the
> > IRQs in the error path.
> >
> > We should be able to iterate over all freams, freeing any non-zero
> > interrupt, since !valid frames shouldn't have non-zero interrupts.
> 
> Yes, that is what I am doing :
> 
>  if (!frame->valid)
>           continue;

What I meant was that we won't look at the frame->valid flag at all;
only the interrupts. e.g.

for (int i = 0; i < ARCH_TIMER_MEM_MAX_FRAMES; i++) {
	if (frame->phys_irq > 0)
		free_the_phys_irq_somehow();
	if (frame->virt_irq > 0)
		free_the_virt_irq_somehow();
}

... where we somehow figure out the GSI, or we introduce an api like
unregister_gsi_for_irq(irq).

Since the !valid frames should all have zero for their interrupt fields,
no special handling is necessary.

That way, we only free the IRQs in one place, it's obvious that we
consistently free all of them, etc.

> Lorenzo addressed the API issue, we may can fix it by getting GSI info
> from DT, then register it until we figure the best frame.
> It may need some big change in DT code

I'd prefer to keep this constrained to the ACPI code. ;)

Thanks,
Mark.

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

* Re: [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
@ 2017-04-06 17:52                 ` Mark Rutland
  0 siblings, 0 replies; 66+ messages in thread
From: Mark Rutland @ 2017-04-06 17:52 UTC (permalink / raw)
  To: Fu Wei
  Cc: Rafael J. Wysocki, Len Brown, Daniel Lezcano, Thomas Gleixner,
	Marc Zyngier, Lorenzo Pieralisi, Sudeep Holla, Hanjun Guo,
	linux-arm-kernel, Linaro ACPI Mailman List,
	Linux Kernel Mailing List, ACPI Devel Maling List, rruigrok,
	Abdulhamid, Harb, Christopher Covington, Timur Tabi, G Gregory,
	Al Stone, Jon Masters, Wei Huang, Arnd Bergmann, Catalin Marinas,
	Will Deacon, Suravee Suthikulpanit, Leo Duran, Wim Van Sebroeck,
	Guenter Roeck, linux-watchdog, Tomasz Nowicki, Christoffer Dall,
	Julien Grall

On Fri, Apr 07, 2017 at 01:39:09AM +0800, Fu Wei wrote:
> On 7 April 2017 at 01:24, Mark Rutland <mark.rutland@arm.com> wrote:
> > On Fri, Apr 07, 2017 at 12:47:47AM +0800, Fu Wei wrote:
> >> On 6 April 2017 at 02:38, Mark Rutland <mark.rutland@arm.com> wrote:
> >> > On Sat, Apr 01, 2017 at 01:51:03AM +0800, fu.wei@linaro.org wrote:

> > However, I would prefer to simplify this such that we only free the
> > IRQs in the error path.
> >
> > We should be able to iterate over all freams, freeing any non-zero
> > interrupt, since !valid frames shouldn't have non-zero interrupts.
> 
> Yes, that is what I am doing :
> 
>  if (!frame->valid)
>           continue;

What I meant was that we won't look at the frame->valid flag at all;
only the interrupts. e.g.

for (int i = 0; i < ARCH_TIMER_MEM_MAX_FRAMES; i++) {
	if (frame->phys_irq > 0)
		free_the_phys_irq_somehow();
	if (frame->virt_irq > 0)
		free_the_virt_irq_somehow();
}

... where we somehow figure out the GSI, or we introduce an api like
unregister_gsi_for_irq(irq).

Since the !valid frames should all have zero for their interrupt fields,
no special handling is necessary.

That way, we only free the IRQs in one place, it's obvious that we
consistently free all of them, etc.

> Lorenzo addressed the API issue, we may can fix it by getting GSI info
> from DT, then register it until we figure the best frame.
> It may need some big change in DT code

I'd prefer to keep this constrained to the ACPI code. ;)

Thanks,
Mark.

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

* [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
@ 2017-04-06 17:52                 ` Mark Rutland
  0 siblings, 0 replies; 66+ messages in thread
From: Mark Rutland @ 2017-04-06 17:52 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Apr 07, 2017 at 01:39:09AM +0800, Fu Wei wrote:
> On 7 April 2017 at 01:24, Mark Rutland <mark.rutland@arm.com> wrote:
> > On Fri, Apr 07, 2017 at 12:47:47AM +0800, Fu Wei wrote:
> >> On 6 April 2017 at 02:38, Mark Rutland <mark.rutland@arm.com> wrote:
> >> > On Sat, Apr 01, 2017 at 01:51:03AM +0800, fu.wei at linaro.org wrote:

> > However, I would prefer to simplify this such that we only free the
> > IRQs in the error path.
> >
> > We should be able to iterate over all freams, freeing any non-zero
> > interrupt, since !valid frames shouldn't have non-zero interrupts.
> 
> Yes, that is what I am doing :
> 
>  if (!frame->valid)
>           continue;

What I meant was that we won't look at the frame->valid flag at all;
only the interrupts. e.g.

for (int i = 0; i < ARCH_TIMER_MEM_MAX_FRAMES; i++) {
	if (frame->phys_irq > 0)
		free_the_phys_irq_somehow();
	if (frame->virt_irq > 0)
		free_the_virt_irq_somehow();
}

... where we somehow figure out the GSI, or we introduce an api like
unregister_gsi_for_irq(irq).

Since the !valid frames should all have zero for their interrupt fields,
no special handling is necessary.

That way, we only free the IRQs in one place, it's obvious that we
consistently free all of them, etc.

> Lorenzo addressed the API issue, we may can fix it by getting GSI info
> from DT, then register it until we figure the best frame.
> It may need some big change in DT code

I'd prefer to keep this constrained to the ACPI code. ;)

Thanks,
Mark.

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

* Re: [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
  2017-04-06 17:52                 ` Mark Rutland
  (?)
@ 2017-04-06 18:07                   ` Fu Wei
  -1 siblings, 0 replies; 66+ messages in thread
From: Fu Wei @ 2017-04-06 18:07 UTC (permalink / raw)
  To: Mark Rutland
  Cc: Rafael J. Wysocki, Len Brown, Daniel Lezcano, Thomas Gleixner,
	Marc Zyngier, Lorenzo Pieralisi, Sudeep Holla, Hanjun Guo,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	Linaro ACPI Mailman List, Linux Kernel Mailing List,
	ACPI Devel Maling List, rruigrok-sgV2jX0FEOL9JmXXK+q4OQ,
	Abdulhamid, Harb, Christopher Covington, Timur Tabi, G Gregory,
	Al Stone, Jon Masters

Hi Mark,

On 7 April 2017 at 01:52, Mark Rutland <mark.rutland-5wv7dgnIgG8@public.gmane.org> wrote:
> On Fri, Apr 07, 2017 at 01:39:09AM +0800, Fu Wei wrote:
>> On 7 April 2017 at 01:24, Mark Rutland <mark.rutland-5wv7dgnIgG8@public.gmane.org> wrote:
>> > On Fri, Apr 07, 2017 at 12:47:47AM +0800, Fu Wei wrote:
>> >> On 6 April 2017 at 02:38, Mark Rutland <mark.rutland-5wv7dgnIgG8@public.gmane.org> wrote:
>> >> > On Sat, Apr 01, 2017 at 01:51:03AM +0800, fu.wei-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org wrote:
>
>> > However, I would prefer to simplify this such that we only free the
>> > IRQs in the error path.
>> >
>> > We should be able to iterate over all freams, freeing any non-zero
>> > interrupt, since !valid frames shouldn't have non-zero interrupts.
>>
>> Yes, that is what I am doing :
>>
>>  if (!frame->valid)
>>           continue;
>
> What I meant was that we won't look at the frame->valid flag at all;
> only the interrupts. e.g.
>
> for (int i = 0; i < ARCH_TIMER_MEM_MAX_FRAMES; i++) {
>         if (frame->phys_irq > 0)
>                 free_the_phys_irq_somehow();
>         if (frame->virt_irq > 0)
>                 free_the_virt_irq_somehow();
> }

Since we use "kcalloc" to allocate struct arch_timer_mem, this should be OK.

>
> ... where we somehow figure out the GSI, or we introduce an api like
> unregister_gsi_for_irq(irq).

Yes, If you are OK with introducing a new API , this problem is solved :-)

>
> Since the !valid frames should all have zero for their interrupt fields,
> no special handling is necessary.
>
> That way, we only free the IRQs in one place, it's obvious that we
> consistently free all of them, etc.
>
>> Lorenzo addressed the API issue, we may can fix it by getting GSI info
>> from DT, then register it until we figure the best frame.
>> It may need some big change in DT code
>
> I'd prefer to keep this constrained to the ACPI code. ;)
>
> Thanks,
> Mark.



-- 
Best regards,

Fu Wei
Software Engineer
Red Hat
--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
@ 2017-04-06 18:07                   ` Fu Wei
  0 siblings, 0 replies; 66+ messages in thread
From: Fu Wei @ 2017-04-06 18:07 UTC (permalink / raw)
  To: Mark Rutland
  Cc: Rafael J. Wysocki, Len Brown, Daniel Lezcano, Thomas Gleixner,
	Marc Zyngier, Lorenzo Pieralisi, Sudeep Holla, Hanjun Guo,
	linux-arm-kernel, Linaro ACPI Mailman List,
	Linux Kernel Mailing List, ACPI Devel Maling List, rruigrok,
	Abdulhamid, Harb, Christopher Covington, Timur Tabi, G Gregory,
	Al Stone, Jon Masters, Wei Huang, Arnd Bergmann, Catalin Marinas,
	Will Deacon, Suravee Suthikulpanit, Leo Duran, Wim Van Sebroeck,
	Guenter Roeck, linux-watchdog, Tomasz Nowicki, Christoffer Dall,
	Julien Grall

Hi Mark,

On 7 April 2017 at 01:52, Mark Rutland <mark.rutland@arm.com> wrote:
> On Fri, Apr 07, 2017 at 01:39:09AM +0800, Fu Wei wrote:
>> On 7 April 2017 at 01:24, Mark Rutland <mark.rutland@arm.com> wrote:
>> > On Fri, Apr 07, 2017 at 12:47:47AM +0800, Fu Wei wrote:
>> >> On 6 April 2017 at 02:38, Mark Rutland <mark.rutland@arm.com> wrote:
>> >> > On Sat, Apr 01, 2017 at 01:51:03AM +0800, fu.wei@linaro.org wrote:
>
>> > However, I would prefer to simplify this such that we only free the
>> > IRQs in the error path.
>> >
>> > We should be able to iterate over all freams, freeing any non-zero
>> > interrupt, since !valid frames shouldn't have non-zero interrupts.
>>
>> Yes, that is what I am doing :
>>
>>  if (!frame->valid)
>>           continue;
>
> What I meant was that we won't look at the frame->valid flag at all;
> only the interrupts. e.g.
>
> for (int i = 0; i < ARCH_TIMER_MEM_MAX_FRAMES; i++) {
>         if (frame->phys_irq > 0)
>                 free_the_phys_irq_somehow();
>         if (frame->virt_irq > 0)
>                 free_the_virt_irq_somehow();
> }

Since we use "kcalloc" to allocate struct arch_timer_mem, this should be OK.

>
> ... where we somehow figure out the GSI, or we introduce an api like
> unregister_gsi_for_irq(irq).

Yes, If you are OK with introducing a new API , this problem is solved :-)

>
> Since the !valid frames should all have zero for their interrupt fields,
> no special handling is necessary.
>
> That way, we only free the IRQs in one place, it's obvious that we
> consistently free all of them, etc.
>
>> Lorenzo addressed the API issue, we may can fix it by getting GSI info
>> from DT, then register it until we figure the best frame.
>> It may need some big change in DT code
>
> I'd prefer to keep this constrained to the ACPI code. ;)
>
> Thanks,
> Mark.



-- 
Best regards,

Fu Wei
Software Engineer
Red Hat

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

* [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver
@ 2017-04-06 18:07                   ` Fu Wei
  0 siblings, 0 replies; 66+ messages in thread
From: Fu Wei @ 2017-04-06 18:07 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Mark,

On 7 April 2017 at 01:52, Mark Rutland <mark.rutland@arm.com> wrote:
> On Fri, Apr 07, 2017 at 01:39:09AM +0800, Fu Wei wrote:
>> On 7 April 2017 at 01:24, Mark Rutland <mark.rutland@arm.com> wrote:
>> > On Fri, Apr 07, 2017 at 12:47:47AM +0800, Fu Wei wrote:
>> >> On 6 April 2017 at 02:38, Mark Rutland <mark.rutland@arm.com> wrote:
>> >> > On Sat, Apr 01, 2017 at 01:51:03AM +0800, fu.wei at linaro.org wrote:
>
>> > However, I would prefer to simplify this such that we only free the
>> > IRQs in the error path.
>> >
>> > We should be able to iterate over all freams, freeing any non-zero
>> > interrupt, since !valid frames shouldn't have non-zero interrupts.
>>
>> Yes, that is what I am doing :
>>
>>  if (!frame->valid)
>>           continue;
>
> What I meant was that we won't look at the frame->valid flag at all;
> only the interrupts. e.g.
>
> for (int i = 0; i < ARCH_TIMER_MEM_MAX_FRAMES; i++) {
>         if (frame->phys_irq > 0)
>                 free_the_phys_irq_somehow();
>         if (frame->virt_irq > 0)
>                 free_the_virt_irq_somehow();
> }

Since we use "kcalloc" to allocate struct arch_timer_mem, this should be OK.

>
> ... where we somehow figure out the GSI, or we introduce an api like
> unregister_gsi_for_irq(irq).

Yes, If you are OK with introducing a new API , this problem is solved :-)

>
> Since the !valid frames should all have zero for their interrupt fields,
> no special handling is necessary.
>
> That way, we only free the IRQs in one place, it's obvious that we
> consistently free all of them, etc.
>
>> Lorenzo addressed the API issue, we may can fix it by getting GSI info
>> from DT, then register it until we figure the best frame.
>> It may need some big change in DT code
>
> I'd prefer to keep this constrained to the ACPI code. ;)
>
> Thanks,
> Mark.



-- 
Best regards,

Fu Wei
Software Engineer
Red Hat

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

end of thread, other threads:[~2017-04-06 18:07 UTC | newest]

Thread overview: 66+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-31 17:50 [PATCH v23 00/11] acpi, clocksource: add GTDT driver and GTDT support in arm_arch_timer fu.wei
2017-03-31 17:50 ` fu.wei at linaro.org
2017-03-31 17:50 ` [PATCH v23 01/11] clocksource: arm_arch_timer: add MMIO CNTFRQ helper fu.wei
2017-03-31 17:50   ` fu.wei at linaro.org
2017-03-31 17:50 ` [PATCH v23 02/11] clocksource: arm_arch_timer: split dt-only rate handling fu.wei
2017-03-31 17:50   ` fu.wei at linaro.org
2017-03-31 17:50 ` [PATCH v23 03/11] clocksource: arm_arch_timer: refactor arch_timer_needs_probing fu.wei
2017-03-31 17:50   ` fu.wei at linaro.org
2017-03-31 17:50 ` [PATCH v23 04/11] clocksource: arm_arch_timer: move arch_timer_needs_of_probing into DT init call fu.wei
2017-03-31 17:50   ` fu.wei at linaro.org
2017-03-31 17:50 ` [PATCH v23 05/11] clocksource: arm_arch_timer: add structs to describe MMIO timer fu.wei
2017-03-31 17:50   ` fu.wei at linaro.org
2017-03-31 17:51 ` [PATCH v23 06/11] clocksource: arm_arch_timer: refactor MMIO timer probing fu.wei
2017-03-31 17:51   ` fu.wei at linaro.org
2017-04-05 18:42   ` Mark Rutland
2017-04-05 18:42     ` Mark Rutland
2017-04-06 10:45     ` Fu Wei
2017-04-06 10:45       ` Fu Wei
2017-04-06 10:45       ` Fu Wei
2017-03-31 17:51 ` [PATCH v23 07/11] acpi/arm64: Add GTDT table parse driver fu.wei
2017-03-31 17:51   ` fu.wei at linaro.org
2017-03-31 17:51 ` [PATCH v23 08/11] clocksource: arm_arch_timer: simplify ACPI support code fu.wei
2017-03-31 17:51   ` fu.wei at linaro.org
2017-03-31 17:51 ` [PATCH v23 09/11] acpi/arm64: Add memory-mapped timer support in GTDT driver fu.wei
2017-03-31 17:51   ` fu.wei at linaro.org
2017-04-03  9:49   ` Will Deacon
2017-04-03  9:49     ` Will Deacon
     [not found]   ` <20170331175105.8370-10-fu.wei-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2017-04-03 10:45     ` Lorenzo Pieralisi
2017-04-03 10:45       ` Lorenzo Pieralisi
2017-04-03 10:45       ` Lorenzo Pieralisi
2017-04-06 17:11       ` Fu Wei
2017-04-06 17:11         ` Fu Wei
2017-04-06 17:11         ` Fu Wei
2017-04-05 18:38     ` Mark Rutland
2017-04-05 18:38       ` Mark Rutland
2017-04-05 18:38       ` Mark Rutland
2017-04-06 10:07       ` Mark Rutland
2017-04-06 10:07         ` Mark Rutland
2017-04-06 16:47       ` Fu Wei
2017-04-06 16:47         ` Fu Wei
2017-04-06 16:47         ` Fu Wei
     [not found]         ` <CADyBb7sz6ongbyqR0FzBZybJBYwnLvqV+NsX1+W=6tv0_vLt1g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-04-06 17:24           ` Mark Rutland
2017-04-06 17:24             ` Mark Rutland
2017-04-06 17:24             ` Mark Rutland
2017-04-06 17:39             ` Fu Wei
2017-04-06 17:39               ` Fu Wei
2017-04-06 17:39               ` Fu Wei
2017-04-06 17:52               ` Mark Rutland
2017-04-06 17:52                 ` Mark Rutland
2017-04-06 17:52                 ` Mark Rutland
2017-04-06 18:07                 ` Fu Wei
2017-04-06 18:07                   ` Fu Wei
2017-04-06 18:07                   ` Fu Wei
2017-03-31 17:51 ` [PATCH v23 10/11] clocksource: arm_arch_timer: add GTDT support for memory-mapped timer fu.wei
2017-03-31 17:51   ` fu.wei at linaro.org
2017-03-31 17:51 ` [PATCH v23 11/11] acpi/arm64: Add SBSA Generic Watchdog support in GTDT driver fu.wei
2017-03-31 17:51   ` fu.wei at linaro.org
2017-03-31 17:51   ` fu.wei
2017-04-01  2:14 ` [PATCH v23 00/11] acpi, clocksource: add GTDT driver and GTDT support in arm_arch_timer Xiongfeng Wang
2017-04-01  2:14   ` Xiongfeng Wang
2017-04-01  2:14   ` Xiongfeng Wang
     [not found]   ` <8c017a47-02d5-454d-f42c-a1b5bb29df1b-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2017-04-01  3:49     ` Fu Wei
2017-04-01  3:49       ` Fu Wei
2017-04-01  3:49       ` Fu Wei
2017-04-04 20:39 ` Timur Tabi
2017-04-04 20:39   ` Timur Tabi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.