2023-05-17 02:53:37

by Walter Chang (張維哲)

[permalink] [raw]
Subject: [PATCH v5 0/4] Support timer drivers as loadable modules

From: Walter Chang <[email protected]>

This set of patches aims to make SoC related timer drivers, such as
timer-mediatek.c become loadable modules for the Generic Kernel Image
(GKI).

This driver registers an always-on timer as tick_broadcast_device on
MediaTek SoCs. If the system does not load this module at startup,
system will also boot normally by using built-in `bc_hrtimer` instead.
Besides, the previous experiment [1] indicates that the SYST/GPT, in
combination with a loadable module, is fully operational.

The first three patches export functions and remove __init markings to
support loadable timer modules.

The fourth patch makes timer-mediatek.c become loadable module for GKI.

[1]
https://lore.kernel.org/all/[email protected]/#t

[v5]
- Add Signed-off-by tags in all patches
- Add Acked-by tags and Reviewed-by tags

[v4]
- Fix review comments pointed by Angelo

[v3]
- Rebase on linux-next

[v2]
- Convert timer-mediatek.c driver to loadable module

Chun-Hung Wu (4):
time/sched_clock: Export sched_clock_register()
clocksource/drivers/mmio: Export clocksource_mmio_init()
clocksource/drivers/timer-of: Remove __init markings
clocksource/drivers/timer-mediatek: Make timer-mediatek become
loadable module

drivers/clocksource/Kconfig | 2 +-
drivers/clocksource/mmio.c | 8 ++++---
drivers/clocksource/timer-mediatek.c | 33 ++++++++++++++++++++++++++++
drivers/clocksource/timer-of.c | 23 +++++++++----------
drivers/clocksource/timer-of.h | 6 ++---
kernel/time/sched_clock.c | 4 ++--
6 files changed, 56 insertions(+), 20 deletions(-)

--
2.18.0



2023-05-17 03:10:31

by Walter Chang (張維哲)

[permalink] [raw]
Subject: [PATCH v5 4/4] clocksource/drivers/timer-mediatek: Make timer-mediatek become loadable module

From: Chun-Hung Wu <[email protected]>

Make the timer-mediatek driver which can register
an always-on timer as tick_broadcast_device on
MediaTek SoCs become loadable module in GKI.

Signed-off-by: Chun-Hung Wu <[email protected]>
Signed-off-by: Walter Chang <[email protected]>
Tested-by: Walter Chang <[email protected]>
Reviewed-by: AngeloGioacchino Del Regno <[email protected]>
---
drivers/clocksource/Kconfig | 2 +-
drivers/clocksource/timer-mediatek.c | 33 ++++++++++++++++++++++++++++
2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index 526382dc7482..62103c0807f7 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -472,7 +472,7 @@ config SYS_SUPPORTS_SH_CMT
bool

config MTK_TIMER
- bool "Mediatek timer driver" if COMPILE_TEST
+ tristate "MediaTek timer driver"
depends on HAS_IOMEM
select TIMER_OF
select CLKSRC_MMIO
diff --git a/drivers/clocksource/timer-mediatek.c b/drivers/clocksource/timer-mediatek.c
index 7bcb4a3f26fb..afeacb509481 100644
--- a/drivers/clocksource/timer-mediatek.c
+++ b/drivers/clocksource/timer-mediatek.c
@@ -13,6 +13,9 @@
#include <linux/clocksource.h>
#include <linux/interrupt.h>
#include <linux/irqreturn.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
#include <linux/sched_clock.h>
#include <linux/slab.h>
#include "timer-of.h"
@@ -337,5 +340,35 @@ static int __init mtk_gpt_init(struct device_node *node)

return 0;
}
+
+#ifndef MODULE
TIMER_OF_DECLARE(mtk_mt6577, "mediatek,mt6577-timer", mtk_gpt_init);
TIMER_OF_DECLARE(mtk_mt6765, "mediatek,mt6765-timer", mtk_syst_init);
+#else
+static int mtk_timer_probe(struct platform_device *pdev)
+{
+ int (*timer_init)(struct device_node *node);
+ struct device_node *np = pdev->dev.of_node;
+
+ timer_init = of_device_get_match_data(&pdev->dev);
+ return timer_init(np);
+}
+
+static const struct of_device_id mtk_timer_match_table[] = {
+ { .compatible = "mediatek,mt6577-timer", .data = mtk_gpt_init },
+ { .compatible = "mediatek,mt6765-timer", .data = mtk_syst_init },
+ { /* sentinel */ }
+};
+
+static struct platform_driver mtk_timer_driver = {
+ .probe = mtk_timer_probe,
+ .driver = {
+ .name = "mediatek-timer",
+ .of_match_table = mtk_timer_match_table,
+ },
+};
+module_platform_driver(mtk_timer_driver);
+
+MODULE_DESCRIPTION("MediaTek Timer driver");
+MODULE_LICENSE("GPL v2");
+#endif
--
2.18.0


2023-05-17 03:15:28

by Walter Chang (張維哲)

[permalink] [raw]
Subject: [PATCH v5 1/4] time/sched_clock: Export sched_clock_register()

From: Chun-Hung Wu <[email protected]>

clocksource driver may use sched_clock_register()
to resigter itself as a sched_clock source.
Export it to support building such driver
as module, like timer-mediatek.c

Signed-off-by: Chun-Hung Wu <[email protected]>
Signed-off-by: Walter Chang <[email protected]>
Acked-by: John Stultz <[email protected]>
---
kernel/time/sched_clock.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/time/sched_clock.c b/kernel/time/sched_clock.c
index 8464c5acc913..8e49e87d1221 100644
--- a/kernel/time/sched_clock.c
+++ b/kernel/time/sched_clock.c
@@ -150,8 +150,7 @@ static enum hrtimer_restart sched_clock_poll(struct hrtimer *hrt)
return HRTIMER_RESTART;
}

-void __init
-sched_clock_register(u64 (*read)(void), int bits, unsigned long rate)
+void sched_clock_register(u64 (*read)(void), int bits, unsigned long rate)
{
u64 res, wrap, new_mask, new_epoch, cyc, ns;
u32 new_mult, new_shift;
@@ -223,6 +222,7 @@ sched_clock_register(u64 (*read)(void), int bits, unsigned long rate)

pr_debug("Registered %pS as sched_clock source\n", read);
}
+EXPORT_SYMBOL_GPL(sched_clock_register);

void __init generic_sched_clock_init(void)
{
--
2.18.0


2023-05-17 03:21:16

by Walter Chang (張維哲)

[permalink] [raw]
Subject: [PATCH v5 2/4] clocksource/drivers/mmio: Export clocksource_mmio_init()

From: Chun-Hung Wu <[email protected]>

Export clocksource_mmio_init() and clocksource_mmio_readl_up()
to support building clocksource driver as module,
such as timer-mediatek.c.

Signed-off-by: Chun-Hung Wu <[email protected]>
Signed-off-by: Walter Chang <[email protected]>
Acked-by: John Stultz <[email protected]>
---
drivers/clocksource/mmio.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/clocksource/mmio.c b/drivers/clocksource/mmio.c
index 9de751531831..b08b2f9d7a8b 100644
--- a/drivers/clocksource/mmio.c
+++ b/drivers/clocksource/mmio.c
@@ -21,6 +21,7 @@ u64 clocksource_mmio_readl_up(struct clocksource *c)
{
return (u64)readl_relaxed(to_mmio_clksrc(c)->reg);
}
+EXPORT_SYMBOL_GPL(clocksource_mmio_readl_up);

u64 clocksource_mmio_readl_down(struct clocksource *c)
{
@@ -46,9 +47,9 @@ u64 clocksource_mmio_readw_down(struct clocksource *c)
* @bits: Number of valid bits
* @read: One of clocksource_mmio_read*() above
*/
-int __init clocksource_mmio_init(void __iomem *base, const char *name,
- unsigned long hz, int rating, unsigned bits,
- u64 (*read)(struct clocksource *))
+int clocksource_mmio_init(void __iomem *base, const char *name,
+ unsigned long hz, int rating, unsigned bits,
+ u64 (*read)(struct clocksource *))
{
struct clocksource_mmio *cs;

@@ -68,3 +69,4 @@ int __init clocksource_mmio_init(void __iomem *base, const char *name,

return clocksource_register_hz(&cs->clksrc, hz);
}
+EXPORT_SYMBOL_GPL(clocksource_mmio_init);
--
2.18.0


2023-05-23 11:38:43

by Alexandre Mergnat

[permalink] [raw]
Subject: Re: [PATCH v5 4/4] clocksource/drivers/timer-mediatek: Make timer-mediatek become loadable module

On 17/05/2023 04:25, [email protected] wrote:
> Make the timer-mediatek driver which can register
> an always-on timer as tick_broadcast_device on
> MediaTek SoCs become loadable module in GKI.

Reviewed-by: Alexandre Mergnat <[email protected]>



2023-06-19 02:26:27

by Walter Chang (張維哲)

[permalink] [raw]
Subject: Re: [PATCH v5 0/4] Support timer drivers as loadable modules

On Wed, 2023-05-17 at 10:25 +0800, [email protected] wrote:
> From: Walter Chang <[email protected]>
>
> This set of patches aims to make SoC related timer drivers, such as
> timer-mediatek.c become loadable modules for the Generic Kernel Image
> (GKI).
>
> This driver registers an always-on timer as tick_broadcast_device on
> MediaTek SoCs. If the system does not load this module at startup,
> system will also boot normally by using built-in `bc_hrtimer`
> instead.
> Besides, the previous experiment [1] indicates that the SYST/GPT, in
> combination with a loadable module, is fully operational.
>
> The first three patches export functions and remove __init markings
> to
> support loadable timer modules.
>
> The fourth patch makes timer-mediatek.c become loadable module for
> GKI.
>
> [1]
>
https://lore.kernel.org/all/[email protected]/#t
>
> [v5]
> - Add Signed-off-by tags in all patches
> - Add Acked-by tags and Reviewed-by tags
>
> [v4]
> - Fix review comments pointed by Angelo
>
> [v3]
> - Rebase on linux-next
>
> [v2]
> - Convert timer-mediatek.c driver to loadable module
>
> Chun-Hung Wu (4):
> time/sched_clock: Export sched_clock_register()
> clocksource/drivers/mmio: Export clocksource_mmio_init()
> clocksource/drivers/timer-of: Remove __init markings
> clocksource/drivers/timer-mediatek: Make timer-mediatek become
> loadable module
>
> drivers/clocksource/Kconfig | 2 +-
> drivers/clocksource/mmio.c | 8 ++++---
> drivers/clocksource/timer-mediatek.c | 33
> ++++++++++++++++++++++++++++
> drivers/clocksource/timer-of.c | 23 +++++++++----------
> drivers/clocksource/timer-of.h | 6 ++---
> kernel/time/sched_clock.c | 4 ++--
> 6 files changed, 56 insertions(+), 20 deletions(-)
>

Gentle ping for this series.

Thanks,
Walter Chang

2023-06-19 16:57:01

by Daniel Lezcano

[permalink] [raw]
Subject: Re: [PATCH v5 0/4] Support timer drivers as loadable modules


As I already said, I'm not very comfortable with these changes and the
potential impact it can have on the overall time framework.

I will pick the series if Thomas gives its Acked-by

Thanks


On 17/05/2023 04:25, [email protected] wrote:
> From: Walter Chang <[email protected]>
>
> This set of patches aims to make SoC related timer drivers, such as
> timer-mediatek.c become loadable modules for the Generic Kernel Image
> (GKI).
>
> This driver registers an always-on timer as tick_broadcast_device on
> MediaTek SoCs. If the system does not load this module at startup,
> system will also boot normally by using built-in `bc_hrtimer` instead.
> Besides, the previous experiment [1] indicates that the SYST/GPT, in
> combination with a loadable module, is fully operational.
>
> The first three patches export functions and remove __init markings to
> support loadable timer modules.
>
> The fourth patch makes timer-mediatek.c become loadable module for GKI.
>
> [1]
> https://lore.kernel.org/all/[email protected]/#t
>
> [v5]
> - Add Signed-off-by tags in all patches
> - Add Acked-by tags and Reviewed-by tags
>
> [v4]
> - Fix review comments pointed by Angelo
>
> [v3]
> - Rebase on linux-next
>
> [v2]
> - Convert timer-mediatek.c driver to loadable module
>
> Chun-Hung Wu (4):
> time/sched_clock: Export sched_clock_register()
> clocksource/drivers/mmio: Export clocksource_mmio_init()
> clocksource/drivers/timer-of: Remove __init markings
> clocksource/drivers/timer-mediatek: Make timer-mediatek become
> loadable module
>
> drivers/clocksource/Kconfig | 2 +-
> drivers/clocksource/mmio.c | 8 ++++---
> drivers/clocksource/timer-mediatek.c | 33 ++++++++++++++++++++++++++++
> drivers/clocksource/timer-of.c | 23 +++++++++----------
> drivers/clocksource/timer-of.h | 6 ++---
> kernel/time/sched_clock.c | 4 ++--
> 6 files changed, 56 insertions(+), 20 deletions(-)
>

--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog


2023-07-06 01:18:08

by Walter Chang (張維哲)

[permalink] [raw]
Subject: Re: [PATCH v5 0/4] Support timer drivers as loadable modules

On Mon, 2023-06-19 at 18:44 +0200, Daniel Lezcano wrote:
>
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
>
> As I already said, I'm not very comfortable with these changes and
> the
> potential impact it can have on the overall time framework.
>
> I will pick the series if Thomas gives its Acked-by
>
> Thanks
>
>

Thanks for letting me know. I will wait for Thomas's response.

Thanks,
Walter Chang

2024-01-23 03:46:29

by Walter Chang (張維哲)

[permalink] [raw]
Subject: Re: [PATCH v5 0/4] Support timer drivers as loadable modules

On Mon, 2023-06-19 at 18:44 +0200, Daniel Lezcano wrote:
>
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
>
> As I already said, I'm not very comfortable with these changes and
> the
> potential impact it can have on the overall time framework.
>
> I will pick the series if Thomas gives its Acked-by
>
> Thanks
>

Hi Thomas,

Gentle ping for this series.

We would like to know your opinion on the time framework changes we've
discussed.

Thanks,
Walter Chang

2024-06-07 15:08:10

by Carlos Llamas

[permalink] [raw]
Subject: Re: [PATCH v5 1/4] time/sched_clock: Export sched_clock_register()

On Wed, May 17, 2023 at 10:25:45AM +0800, [email protected] wrote:
> From: Chun-Hung Wu <[email protected]>
>
> clocksource driver may use sched_clock_register()
> to resigter itself as a sched_clock source.

nit: typo s/resigter/register

> Export it to support building such driver
> as module, like timer-mediatek.c
>
> Signed-off-by: Chun-Hung Wu <[email protected]>
> Signed-off-by: Walter Chang <[email protected]>
> Acked-by: John Stultz <[email protected]>
> ---

Reviewed-by: Carlos Llamas <[email protected]>

Thanks