From: Yicong Yang <yangyicong@huawei.com>
To: <mark.rutland@arm.com>, <maz@kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>
Cc: <daniel.lezcano@linaro.org>, <tglx@linutronix.de>,
<jonathan.cameron@huawei.com>, <prime.zeng@huawei.com>,
<wanghuiqiang@huawei.com>, <wangwudi@hisilicon.com>,
<guohanjun@huawei.com>, <yangyicong@hisilicon.com>,
<linuxarm@huawei.com>
Subject: [RFC PATCH 2/3] clocksource/drivers/arm_arch_timer: Extend and export arch_timer_mem_register()
Date: Tue, 10 Oct 2023 20:30:32 +0800 [thread overview]
Message-ID: <20231010123033.23258-3-yangyicong@huawei.com> (raw)
In-Reply-To: <20231010123033.23258-1-yangyicong@huawei.com>
From: Yicong Yang <yangyicong@hisilicon.com>
Currently the memory-mapped timer will be probed by the GTDT table on
ACPI based systems, and the timer interrupt can only be the GSI (SPI
interrupt for arm64) per ACPI spec. However the generic timer
specification doesn't restrict the interrupt type and per BSA Spec
section 3.8.1 (DEN0094C 1.0C) the timer interrupt can also be a LPI
interrupt.
So this patch extends and exports the arch_timer_mem_register() function
to allow other drivers registers a generic timer using LPI interrupt
and probed by other means rather than GTDT. Note that the GTDT timer
still has a higher priority, if a GTDT timer is registered, we'll block
later registration of other timers.
Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
---
drivers/clocksource/arm_arch_timer.c | 26 +++++++++++++++++---------
include/clocksource/arm_arch_timer.h | 2 ++
2 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index 2e20a8ec50ca..6e9445192ca4 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -66,7 +66,7 @@ struct arch_timer {
struct clock_event_device evt;
};
-static struct arch_timer *arch_timer_mem __ro_after_init;
+static struct arch_timer *arch_timer_mem;
#define to_arch_timer(e) container_of(e, struct arch_timer, evt)
@@ -888,15 +888,16 @@ static void __arch_timer_setup_cp15(struct clock_event_device *clk)
clockevents_config_and_register(clk, arch_timer_rate, 0xf, max_delta);
}
-static void __arch_timer_setup_mem(struct clock_event_device *clk)
+static void __arch_timer_setup_mem(struct clock_event_device *clk,
+ bool irq_virtual, const char *name)
{
u64 max_delta;
clk->features = CLOCK_EVT_FEAT_ONESHOT | CLOCK_EVT_FEAT_DYNIRQ;
- clk->name = "arch_mem_timer";
+ clk->name = name;
clk->rating = 400;
clk->cpumask = cpu_possible_mask;
- if (arch_timer_mem_use_virtual) {
+ if (irq_virtual) {
clk->set_state_shutdown = arch_timer_shutdown_virt_mem;
clk->set_state_oneshot_stopped = arch_timer_shutdown_virt_mem;
clk->set_next_event =
@@ -1286,25 +1287,30 @@ static int __init arch_timer_register(void)
return err;
}
-static int __init arch_timer_mem_register(void __iomem *base, unsigned int irq)
+int arch_timer_mem_register(void __iomem *base, unsigned int irq,
+ bool irq_virtual, const char *name)
{
int ret;
irq_handler_t func;
+ /* If we've already register a memory timer, fail the registration */
+ if (arch_timer_mem)
+ return -EEXIST;
+
arch_timer_mem = kzalloc(sizeof(*arch_timer_mem), GFP_KERNEL);
if (!arch_timer_mem)
return -ENOMEM;
arch_timer_mem->base = base;
arch_timer_mem->evt.irq = irq;
- __arch_timer_setup_mem(&arch_timer_mem->evt);
+ __arch_timer_setup_mem(&arch_timer_mem->evt, irq_virtual, name);
- if (arch_timer_mem_use_virtual)
+ if (irq_virtual)
func = arch_timer_handler_virt_mem;
else
func = arch_timer_handler_phys_mem;
- ret = request_irq(irq, func, IRQF_TIMER, "arch_mem_timer", &arch_timer_mem->evt);
+ ret = request_irq(irq, func, IRQF_TIMER, name, &arch_timer_mem->evt);
if (ret) {
pr_err("Failed to request mem timer irq\n");
kfree(arch_timer_mem);
@@ -1313,6 +1319,7 @@ static int __init arch_timer_mem_register(void __iomem *base, unsigned int irq)
return ret;
}
+EXPORT_SYMBOL_GPL(arch_timer_mem_register);
static const struct of_device_id arch_timer_of_match[] __initconst = {
{ .compatible = "arm,armv7-timer", },
@@ -1560,7 +1567,8 @@ arch_timer_mem_frame_register(struct arch_timer_mem_frame *frame)
return -ENXIO;
}
- ret = arch_timer_mem_register(base, irq);
+ ret = arch_timer_mem_register(base, irq, arch_timer_mem_use_virtual,
+ "arch_mem_timer");
if (ret) {
iounmap(base);
return ret;
diff --git a/include/clocksource/arm_arch_timer.h b/include/clocksource/arm_arch_timer.h
index cbbc9a6dc571..d0fa2065586c 100644
--- a/include/clocksource/arm_arch_timer.h
+++ b/include/clocksource/arm_arch_timer.h
@@ -89,6 +89,8 @@ extern u32 arch_timer_get_rate(void);
extern u64 (*arch_timer_read_counter)(void);
extern struct arch_timer_kvm_info *arch_timer_get_kvm_info(void);
extern bool arch_timer_evtstrm_available(void);
+extern int arch_timer_mem_register(void __iomem *base, unsigned int irq,
+ bool irq_virtual, const char *name);
#else
--
2.24.0
next prev parent reply other threads:[~2023-10-10 12:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-10 12:30 [RFC PATCH 0/3] Add HiSilicon system timer driver Yicong Yang
2023-10-10 12:30 ` [RFC PATCH 1/3] clocksource/drivers/arm_arch_timer: Split the function of __arch_timer_setup() Yicong Yang
2023-10-10 12:30 ` Yicong Yang [this message]
2023-10-10 12:30 ` [RFC PATCH 3/3] clocksource/drivers: Add HiSilicon system timer driver Yicong Yang
2023-10-10 15:43 ` [RFC PATCH 0/3] " Mark Rutland
2023-10-11 2:07 ` Yicong Yang
2023-10-10 16:36 ` Marc Zyngier
2023-10-11 2:10 ` Yicong Yang
2023-10-11 10:38 ` Mark Rutland
2023-10-11 13:10 ` Yicong Yang
2024-01-23 9:35 ` Yicong Yang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231010123033.23258-3-yangyicong@huawei.com \
--to=yangyicong@huawei.com \
--cc=daniel.lezcano@linaro.org \
--cc=guohanjun@huawei.com \
--cc=jonathan.cameron@huawei.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=prime.zeng@huawei.com \
--cc=tglx@linutronix.de \
--cc=wanghuiqiang@huawei.com \
--cc=wangwudi@hisilicon.com \
--cc=yangyicong@hisilicon.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®