diff options
175 files changed, 2498 insertions, 3166 deletions
diff --git a/Documentation/devicetree/bindings/timer/faraday,fttmr010.txt b/Documentation/devicetree/bindings/timer/faraday,fttmr010.txt index b73ca6cd07f8..195792270414 100644 --- a/Documentation/devicetree/bindings/timer/faraday,fttmr010.txt +++ b/Documentation/devicetree/bindings/timer/faraday,fttmr010.txt | |||
@@ -7,7 +7,11 @@ Required properties: | |||
7 | 7 | ||
8 | - compatible : Must be one of | 8 | - compatible : Must be one of |
9 | "faraday,fttmr010" | 9 | "faraday,fttmr010" |
10 | "cortina,gemini-timer" | 10 | "cortina,gemini-timer", "faraday,fttmr010" |
11 | "moxa,moxart-timer", "faraday,fttmr010" | ||
12 | "aspeed,ast2400-timer" | ||
13 | "aspeed,ast2500-timer" | ||
14 | |||
11 | - reg : Should contain registers location and length | 15 | - reg : Should contain registers location and length |
12 | - interrupts : Should contain the three timer interrupts usually with | 16 | - interrupts : Should contain the three timer interrupts usually with |
13 | flags for falling edge | 17 | flags for falling edge |
diff --git a/Documentation/devicetree/bindings/timer/moxa,moxart-timer.txt b/Documentation/devicetree/bindings/timer/moxa,moxart-timer.txt deleted file mode 100644 index e207c11630af..000000000000 --- a/Documentation/devicetree/bindings/timer/moxa,moxart-timer.txt +++ /dev/null | |||
@@ -1,19 +0,0 @@ | |||
1 | MOXA ART timer | ||
2 | |||
3 | Required properties: | ||
4 | |||
5 | - compatible : Must be one of: | ||
6 | - "moxa,moxart-timer" | ||
7 | - "aspeed,ast2400-timer" | ||
8 | - reg : Should contain registers location and length | ||
9 | - interrupts : Should contain the timer interrupt number | ||
10 | - clocks : Should contain phandle for the clock that drives the counter | ||
11 | |||
12 | Example: | ||
13 | |||
14 | timer: timer@98400000 { | ||
15 | compatible = "moxa,moxart-timer"; | ||
16 | reg = <0x98400000 0x42>; | ||
17 | interrupts = <19 1>; | ||
18 | clocks = <&coreclk>; | ||
19 | }; | ||
diff --git a/arch/arc/include/asm/Kbuild b/arch/arc/include/asm/Kbuild index 7bee4e4799fd..3e74ca5e6402 100644 --- a/arch/arc/include/asm/Kbuild +++ b/arch/arc/include/asm/Kbuild | |||
@@ -36,7 +36,6 @@ generic-y += preempt.h | |||
36 | generic-y += resource.h | 36 | generic-y += resource.h |
37 | generic-y += sembuf.h | 37 | generic-y += sembuf.h |
38 | generic-y += shmbuf.h | 38 | generic-y += shmbuf.h |
39 | generic-y += siginfo.h | ||
40 | generic-y += socket.h | 39 | generic-y += socket.h |
41 | generic-y += sockios.h | 40 | generic-y += sockios.h |
42 | generic-y += stat.h | 41 | generic-y += stat.h |
diff --git a/arch/arc/include/uapi/asm/Kbuild b/arch/arc/include/uapi/asm/Kbuild index b15bf6bc0e94..b55fc2ae1e8c 100644 --- a/arch/arc/include/uapi/asm/Kbuild +++ b/arch/arc/include/uapi/asm/Kbuild | |||
@@ -1,2 +1,4 @@ | |||
1 | # UAPI Header export list | 1 | # UAPI Header export list |
2 | include include/uapi/asm-generic/Kbuild.asm | 2 | include include/uapi/asm-generic/Kbuild.asm |
3 | |||
4 | generic-y += siginfo.h | ||
diff --git a/arch/arc/kernel/setup.c b/arch/arc/kernel/setup.c index fc8211f338ad..666613fde91d 100644 --- a/arch/arc/kernel/setup.c +++ b/arch/arc/kernel/setup.c | |||
@@ -470,7 +470,7 @@ void __init setup_arch(char **cmdline_p) | |||
470 | void __init time_init(void) | 470 | void __init time_init(void) |
471 | { | 471 | { |
472 | of_clk_init(NULL); | 472 | of_clk_init(NULL); |
473 | clocksource_probe(); | 473 | timer_probe(); |
474 | } | 474 | } |
475 | 475 | ||
476 | static int __init customize_machine(void) | 476 | static int __init customize_machine(void) |
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 6491be556ddc..6281c3e5a673 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig | |||
@@ -337,7 +337,7 @@ config ARCH_MULTIPLATFORM | |||
337 | select ARM_HAS_SG_CHAIN | 337 | select ARM_HAS_SG_CHAIN |
338 | select ARM_PATCH_PHYS_VIRT | 338 | select ARM_PATCH_PHYS_VIRT |
339 | select AUTO_ZRELADDR | 339 | select AUTO_ZRELADDR |
340 | select CLKSRC_OF | 340 | select TIMER_OF |
341 | select COMMON_CLK | 341 | select COMMON_CLK |
342 | select GENERIC_CLOCKEVENTS | 342 | select GENERIC_CLOCKEVENTS |
343 | select MIGHT_HAVE_PCI | 343 | select MIGHT_HAVE_PCI |
@@ -351,7 +351,7 @@ config ARM_SINGLE_ARMV7M | |||
351 | depends on !MMU | 351 | depends on !MMU |
352 | select ARM_NVIC | 352 | select ARM_NVIC |
353 | select AUTO_ZRELADDR | 353 | select AUTO_ZRELADDR |
354 | select CLKSRC_OF | 354 | select TIMER_OF |
355 | select COMMON_CLK | 355 | select COMMON_CLK |
356 | select CPU_V7M | 356 | select CPU_V7M |
357 | select GENERIC_CLOCKEVENTS | 357 | select GENERIC_CLOCKEVENTS |
@@ -532,7 +532,7 @@ config ARCH_PXA | |||
532 | select CLKDEV_LOOKUP | 532 | select CLKDEV_LOOKUP |
533 | select CLKSRC_PXA | 533 | select CLKSRC_PXA |
534 | select CLKSRC_MMIO | 534 | select CLKSRC_MMIO |
535 | select CLKSRC_OF | 535 | select TIMER_OF |
536 | select CPU_XSCALE if !CPU_XSC3 | 536 | select CPU_XSCALE if !CPU_XSC3 |
537 | select GENERIC_CLOCKEVENTS | 537 | select GENERIC_CLOCKEVENTS |
538 | select GPIO_PXA | 538 | select GPIO_PXA |
@@ -571,7 +571,7 @@ config ARCH_SA1100 | |||
571 | select CLKDEV_LOOKUP | 571 | select CLKDEV_LOOKUP |
572 | select CLKSRC_MMIO | 572 | select CLKSRC_MMIO |
573 | select CLKSRC_PXA | 573 | select CLKSRC_PXA |
574 | select CLKSRC_OF if OF | 574 | select TIMER_OF if OF |
575 | select CPU_FREQ | 575 | select CPU_FREQ |
576 | select CPU_SA1100 | 576 | select CPU_SA1100 |
577 | select GENERIC_CLOCKEVENTS | 577 | select GENERIC_CLOCKEVENTS |
@@ -1357,7 +1357,7 @@ config HAVE_ARM_ARCH_TIMER | |||
1357 | 1357 | ||
1358 | config HAVE_ARM_TWD | 1358 | config HAVE_ARM_TWD |
1359 | bool | 1359 | bool |
1360 | select CLKSRC_OF if OF | 1360 | select TIMER_OF if OF |
1361 | help | 1361 | help |
1362 | This options enables support for the ARM timer and watchdog unit | 1362 | This options enables support for the ARM timer and watchdog unit |
1363 | 1363 | ||
diff --git a/arch/arm/boot/dts/aspeed-g4.dtsi b/arch/arm/boot/dts/aspeed-g4.dtsi index 8c6bc29eb7f6..3e74929d3289 100644 --- a/arch/arm/boot/dts/aspeed-g4.dtsi +++ b/arch/arm/boot/dts/aspeed-g4.dtsi | |||
@@ -893,6 +893,7 @@ | |||
893 | //interrupts = <16 17 18 35 36 37 38 39>; | 893 | //interrupts = <16 17 18 35 36 37 38 39>; |
894 | interrupts = <16>; | 894 | interrupts = <16>; |
895 | clocks = <&clk_apb>; | 895 | clocks = <&clk_apb>; |
896 | clock-names = "PCLK"; | ||
896 | }; | 897 | }; |
897 | 898 | ||
898 | wdt1: wdt@1e785000 { | 899 | wdt1: wdt@1e785000 { |
diff --git a/arch/arm/boot/dts/aspeed-g5.dtsi b/arch/arm/boot/dts/aspeed-g5.dtsi index a0bea4a6ec77..1e6c701da853 100644 --- a/arch/arm/boot/dts/aspeed-g5.dtsi +++ b/arch/arm/boot/dts/aspeed-g5.dtsi | |||
@@ -1000,6 +1000,7 @@ | |||
1000 | //interrupts = <16 17 18 35 36 37 38 39>; | 1000 | //interrupts = <16 17 18 35 36 37 38 39>; |
1001 | interrupts = <16>; | 1001 | interrupts = <16>; |
1002 | clocks = <&clk_apb>; | 1002 | clocks = <&clk_apb>; |
1003 | clock-names = "PCLK"; | ||
1003 | }; | 1004 | }; |
1004 | 1005 | ||
1005 | 1006 | ||
diff --git a/arch/arm/include/asm/Kbuild b/arch/arm/include/asm/Kbuild index 3a36d99ff836..d8360501c082 100644 --- a/arch/arm/include/asm/Kbuild +++ b/arch/arm/include/asm/Kbuild | |||
@@ -28,7 +28,6 @@ generic-y += segment.h | |||
28 | generic-y += sembuf.h | 28 | generic-y += sembuf.h |
29 | generic-y += serial.h | 29 | generic-y += serial.h |
30 | generic-y += shmbuf.h | 30 | generic-y += shmbuf.h |
31 | generic-y += siginfo.h | ||
32 | generic-y += simd.h | 31 | generic-y += simd.h |
33 | generic-y += sizes.h | 32 | generic-y += sizes.h |
34 | generic-y += socket.h | 33 | generic-y += socket.h |
diff --git a/arch/arm/include/uapi/asm/Kbuild b/arch/arm/include/uapi/asm/Kbuild index 607f702c2d62..e9b098d6b766 100644 --- a/arch/arm/include/uapi/asm/Kbuild +++ b/arch/arm/include/uapi/asm/Kbuild | |||
@@ -4,3 +4,5 @@ include include/uapi/asm-generic/Kbuild.asm | |||
4 | genhdr-y += unistd-common.h | 4 | genhdr-y += unistd-common.h |
5 | genhdr-y += unistd-oabi.h | 5 | genhdr-y += unistd-oabi.h |
6 | genhdr-y += unistd-eabi.h | 6 | genhdr-y += unistd-eabi.h |
7 | |||
8 | generic-y += siginfo.h | ||
diff --git a/arch/arm/kernel/smp_twd.c b/arch/arm/kernel/smp_twd.c index 895ae5197159..b30eafeef096 100644 --- a/arch/arm/kernel/smp_twd.c +++ b/arch/arm/kernel/smp_twd.c | |||
@@ -403,7 +403,7 @@ out: | |||
403 | WARN(err, "twd_local_timer_of_register failed (%d)\n", err); | 403 | WARN(err, "twd_local_timer_of_register failed (%d)\n", err); |
404 | return err; | 404 | return err; |
405 | } | 405 | } |
406 | CLOCKSOURCE_OF_DECLARE(arm_twd_a9, "arm,cortex-a9-twd-timer", twd_local_timer_of_register); | 406 | TIMER_OF_DECLARE(arm_twd_a9, "arm,cortex-a9-twd-timer", twd_local_timer_of_register); |
407 | CLOCKSOURCE_OF_DECLARE(arm_twd_a5, "arm,cortex-a5-twd-timer", twd_local_timer_of_register); | 407 | TIMER_OF_DECLARE(arm_twd_a5, "arm,cortex-a5-twd-timer", twd_local_timer_of_register); |
408 | CLOCKSOURCE_OF_DECLARE(arm_twd_11mp, "arm,arm11mp-twd-timer", twd_local_timer_of_register); | 408 | TIMER_OF_DECLARE(arm_twd_11mp, "arm,arm11mp-twd-timer", twd_local_timer_of_register); |
409 | #endif | 409 | #endif |
diff --git a/arch/arm/kernel/time.c b/arch/arm/kernel/time.c index 97b22fa7cb3a..629f8e9981f1 100644 --- a/arch/arm/kernel/time.c +++ b/arch/arm/kernel/time.c | |||
@@ -120,6 +120,6 @@ void __init time_init(void) | |||
120 | #ifdef CONFIG_COMMON_CLK | 120 | #ifdef CONFIG_COMMON_CLK |
121 | of_clk_init(NULL); | 121 | of_clk_init(NULL); |
122 | #endif | 122 | #endif |
123 | clocksource_probe(); | 123 | timer_probe(); |
124 | } | 124 | } |
125 | } | 125 | } |
diff --git a/arch/arm/mach-aspeed/Kconfig b/arch/arm/mach-aspeed/Kconfig index f3f8c5c658db..2d5570e6e186 100644 --- a/arch/arm/mach-aspeed/Kconfig +++ b/arch/arm/mach-aspeed/Kconfig | |||
@@ -4,7 +4,7 @@ menuconfig ARCH_ASPEED | |||
4 | select SRAM | 4 | select SRAM |
5 | select WATCHDOG | 5 | select WATCHDOG |
6 | select ASPEED_WATCHDOG | 6 | select ASPEED_WATCHDOG |
7 | select MOXART_TIMER | 7 | select FTTMR010_TIMER |
8 | select MFD_SYSCON | 8 | select MFD_SYSCON |
9 | select PINCTRL | 9 | select PINCTRL |
10 | help | 10 | help |
diff --git a/arch/arm/mach-bcm/Kconfig b/arch/arm/mach-bcm/Kconfig index f9389c5910e7..f23a23934162 100644 --- a/arch/arm/mach-bcm/Kconfig +++ b/arch/arm/mach-bcm/Kconfig | |||
@@ -150,7 +150,7 @@ config ARCH_BCM2835 | |||
150 | select ARM_ERRATA_411920 if ARCH_MULTI_V6 | 150 | select ARM_ERRATA_411920 if ARCH_MULTI_V6 |
151 | select ARM_TIMER_SP804 | 151 | select ARM_TIMER_SP804 |
152 | select HAVE_ARM_ARCH_TIMER if ARCH_MULTI_V7 | 152 | select HAVE_ARM_ARCH_TIMER if ARCH_MULTI_V7 |
153 | select CLKSRC_OF | 153 | select TIMER_OF |
154 | select BCM2835_TIMER | 154 | select BCM2835_TIMER |
155 | select PINCTRL | 155 | select PINCTRL |
156 | select PINCTRL_BCM2835 | 156 | select PINCTRL_BCM2835 |
diff --git a/arch/arm/mach-clps711x/Kconfig b/arch/arm/mach-clps711x/Kconfig index 61284b9389cf..f385b1fcafef 100644 --- a/arch/arm/mach-clps711x/Kconfig +++ b/arch/arm/mach-clps711x/Kconfig | |||
@@ -2,7 +2,7 @@ menuconfig ARCH_CLPS711X | |||
2 | bool "Cirrus Logic EP721x/EP731x-based" | 2 | bool "Cirrus Logic EP721x/EP731x-based" |
3 | depends on ARCH_MULTI_V4T | 3 | depends on ARCH_MULTI_V4T |
4 | select AUTO_ZRELADDR | 4 | select AUTO_ZRELADDR |
5 | select CLKSRC_OF | 5 | select TIMER_OF |
6 | select CLPS711X_TIMER | 6 | select CLPS711X_TIMER |
7 | select COMMON_CLK | 7 | select COMMON_CLK |
8 | select CPU_ARM720T | 8 | select CPU_ARM720T |
diff --git a/arch/arm/mach-mediatek/mediatek.c b/arch/arm/mach-mediatek/mediatek.c index a6e3c98b95ed..c3cf215773b2 100644 --- a/arch/arm/mach-mediatek/mediatek.c +++ b/arch/arm/mach-mediatek/mediatek.c | |||
@@ -41,7 +41,7 @@ static void __init mediatek_timer_init(void) | |||
41 | } | 41 | } |
42 | 42 | ||
43 | of_clk_init(NULL); | 43 | of_clk_init(NULL); |
44 | clocksource_probe(); | 44 | timer_probe(); |
45 | }; | 45 | }; |
46 | 46 | ||
47 | static const char * const mediatek_board_dt_compat[] = { | 47 | static const char * const mediatek_board_dt_compat[] = { |
diff --git a/arch/arm/mach-moxart/Kconfig b/arch/arm/mach-moxart/Kconfig index 70db2abf6163..a4a91f9a3301 100644 --- a/arch/arm/mach-moxart/Kconfig +++ b/arch/arm/mach-moxart/Kconfig | |||
@@ -4,7 +4,7 @@ menuconfig ARCH_MOXART | |||
4 | select CPU_FA526 | 4 | select CPU_FA526 |
5 | select ARM_DMA_MEM_BUFFERABLE | 5 | select ARM_DMA_MEM_BUFFERABLE |
6 | select FARADAY_FTINTC010 | 6 | select FARADAY_FTINTC010 |
7 | select MOXART_TIMER | 7 | select FTTMR010_TIMER |
8 | select GPIOLIB | 8 | select GPIOLIB |
9 | select PHYLIB if NETDEVICES | 9 | select PHYLIB if NETDEVICES |
10 | help | 10 | help |
diff --git a/arch/arm/mach-omap2/timer.c b/arch/arm/mach-omap2/timer.c index 07dd692c4737..ae4bb9fdc483 100644 --- a/arch/arm/mach-omap2/timer.c +++ b/arch/arm/mach-omap2/timer.c | |||
@@ -497,7 +497,7 @@ void __init omap_init_time(void) | |||
497 | __omap_sync32k_timer_init(1, "timer_32k_ck", "ti,timer-alwon", | 497 | __omap_sync32k_timer_init(1, "timer_32k_ck", "ti,timer-alwon", |
498 | 2, "timer_sys_ck", NULL, false); | 498 | 2, "timer_sys_ck", NULL, false); |
499 | 499 | ||
500 | clocksource_probe(); | 500 | timer_probe(); |
501 | } | 501 | } |
502 | 502 | ||
503 | #if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_SOC_AM43XX) | 503 | #if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_SOC_AM43XX) |
@@ -506,7 +506,7 @@ void __init omap3_secure_sync32k_timer_init(void) | |||
506 | __omap_sync32k_timer_init(12, "secure_32k_fck", "ti,timer-secure", | 506 | __omap_sync32k_timer_init(12, "secure_32k_fck", "ti,timer-secure", |
507 | 2, "timer_sys_ck", NULL, false); | 507 | 2, "timer_sys_ck", NULL, false); |
508 | 508 | ||
509 | clocksource_probe(); | 509 | timer_probe(); |
510 | } | 510 | } |
511 | #endif /* CONFIG_ARCH_OMAP3 */ | 511 | #endif /* CONFIG_ARCH_OMAP3 */ |
512 | 512 | ||
@@ -517,7 +517,7 @@ void __init omap3_gptimer_timer_init(void) | |||
517 | __omap_sync32k_timer_init(2, "timer_sys_ck", NULL, | 517 | __omap_sync32k_timer_init(2, "timer_sys_ck", NULL, |
518 | 1, "timer_sys_ck", "ti,timer-alwon", true); | 518 | 1, "timer_sys_ck", "ti,timer-alwon", true); |
519 | if (of_have_populated_dt()) | 519 | if (of_have_populated_dt()) |
520 | clocksource_probe(); | 520 | timer_probe(); |
521 | } | 521 | } |
522 | #endif | 522 | #endif |
523 | 523 | ||
@@ -532,7 +532,7 @@ static void __init omap4_sync32k_timer_init(void) | |||
532 | void __init omap4_local_timer_init(void) | 532 | void __init omap4_local_timer_init(void) |
533 | { | 533 | { |
534 | omap4_sync32k_timer_init(); | 534 | omap4_sync32k_timer_init(); |
535 | clocksource_probe(); | 535 | timer_probe(); |
536 | } | 536 | } |
537 | #endif | 537 | #endif |
538 | 538 | ||
@@ -656,7 +656,7 @@ void __init omap5_realtime_timer_init(void) | |||
656 | omap4_sync32k_timer_init(); | 656 | omap4_sync32k_timer_init(); |
657 | realtime_counter_init(); | 657 | realtime_counter_init(); |
658 | 658 | ||
659 | clocksource_probe(); | 659 | timer_probe(); |
660 | } | 660 | } |
661 | #endif /* CONFIG_SOC_OMAP5 || CONFIG_SOC_DRA7XX */ | 661 | #endif /* CONFIG_SOC_OMAP5 || CONFIG_SOC_DRA7XX */ |
662 | 662 | ||
diff --git a/arch/arm/mach-rockchip/rockchip.c b/arch/arm/mach-rockchip/rockchip.c index ef0500a4c8ad..5ab834ebcb49 100644 --- a/arch/arm/mach-rockchip/rockchip.c +++ b/arch/arm/mach-rockchip/rockchip.c | |||
@@ -55,7 +55,7 @@ static void __init rockchip_timer_init(void) | |||
55 | } | 55 | } |
56 | 56 | ||
57 | of_clk_init(NULL); | 57 | of_clk_init(NULL); |
58 | clocksource_probe(); | 58 | timer_probe(); |
59 | } | 59 | } |
60 | 60 | ||
61 | static void __init rockchip_dt_init(void) | 61 | static void __init rockchip_dt_init(void) |
diff --git a/arch/arm/mach-s3c24xx/Kconfig b/arch/arm/mach-s3c24xx/Kconfig index 4b1690acb6a5..f07da82ebfea 100644 --- a/arch/arm/mach-s3c24xx/Kconfig +++ b/arch/arm/mach-s3c24xx/Kconfig | |||
@@ -394,7 +394,7 @@ config MACH_SMDK2416 | |||
394 | 394 | ||
395 | config MACH_S3C2416_DT | 395 | config MACH_S3C2416_DT |
396 | bool "Samsung S3C2416 machine using devicetree" | 396 | bool "Samsung S3C2416 machine using devicetree" |
397 | select CLKSRC_OF | 397 | select TIMER_OF |
398 | select USE_OF | 398 | select USE_OF |
399 | select PINCTRL | 399 | select PINCTRL |
400 | select PINCTRL_S3C24XX | 400 | select PINCTRL_S3C24XX |
diff --git a/arch/arm/mach-s3c64xx/Kconfig b/arch/arm/mach-s3c64xx/Kconfig index 459214fa20b4..71a49343d711 100644 --- a/arch/arm/mach-s3c64xx/Kconfig +++ b/arch/arm/mach-s3c64xx/Kconfig | |||
@@ -336,7 +336,7 @@ config MACH_WLF_CRAGG_6410 | |||
336 | 336 | ||
337 | config MACH_S3C64XX_DT | 337 | config MACH_S3C64XX_DT |
338 | bool "Samsung S3C6400/S3C6410 machine using Device Tree" | 338 | bool "Samsung S3C6400/S3C6410 machine using Device Tree" |
339 | select CLKSRC_OF | 339 | select TIMER_OF |
340 | select CPU_S3C6400 | 340 | select CPU_S3C6400 |
341 | select CPU_S3C6410 | 341 | select CPU_S3C6410 |
342 | select PINCTRL | 342 | select PINCTRL |
diff --git a/arch/arm/mach-shmobile/setup-rcar-gen2.c b/arch/arm/mach-shmobile/setup-rcar-gen2.c index 52d466b75973..a6e74f481dea 100644 --- a/arch/arm/mach-shmobile/setup-rcar-gen2.c +++ b/arch/arm/mach-shmobile/setup-rcar-gen2.c | |||
@@ -113,7 +113,7 @@ void __init rcar_gen2_timer_init(void) | |||
113 | #endif /* CONFIG_ARM_ARCH_TIMER */ | 113 | #endif /* CONFIG_ARM_ARCH_TIMER */ |
114 | 114 | ||
115 | of_clk_init(NULL); | 115 | of_clk_init(NULL); |
116 | clocksource_probe(); | 116 | timer_probe(); |
117 | } | 117 | } |
118 | 118 | ||
119 | struct memory_reserve_config { | 119 | struct memory_reserve_config { |
diff --git a/arch/arm/mach-spear/spear13xx.c b/arch/arm/mach-spear/spear13xx.c index ca2f6a82a414..31c43cabf362 100644 --- a/arch/arm/mach-spear/spear13xx.c +++ b/arch/arm/mach-spear/spear13xx.c | |||
@@ -124,5 +124,5 @@ void __init spear13xx_timer_init(void) | |||
124 | clk_put(pclk); | 124 | clk_put(pclk); |
125 | 125 | ||
126 | spear_setup_of_timer(); | 126 | spear_setup_of_timer(); |
127 | clocksource_probe(); | 127 | timer_probe(); |
128 | } | 128 | } |
diff --git a/arch/arm/mach-sunxi/sunxi.c b/arch/arm/mach-sunxi/sunxi.c index f44e3acb5c90..7ab353fb25f2 100644 --- a/arch/arm/mach-sunxi/sunxi.c +++ b/arch/arm/mach-sunxi/sunxi.c | |||
@@ -42,7 +42,7 @@ static void __init sun6i_timer_init(void) | |||
42 | of_clk_init(NULL); | 42 | of_clk_init(NULL); |
43 | if (IS_ENABLED(CONFIG_RESET_CONTROLLER)) | 43 | if (IS_ENABLED(CONFIG_RESET_CONTROLLER)) |
44 | sun6i_reset_init(); | 44 | sun6i_reset_init(); |
45 | clocksource_probe(); | 45 | timer_probe(); |
46 | } | 46 | } |
47 | 47 | ||
48 | DT_MACHINE_START(SUN6I_DT, "Allwinner sun6i (A31) Family") | 48 | DT_MACHINE_START(SUN6I_DT, "Allwinner sun6i (A31) Family") |
diff --git a/arch/arm/mach-u300/core.c b/arch/arm/mach-u300/core.c index a4910ea6811a..048f15e8c669 100644 --- a/arch/arm/mach-u300/core.c +++ b/arch/arm/mach-u300/core.c | |||
@@ -407,7 +407,7 @@ static const char * u300_board_compat[] = { | |||
407 | DT_MACHINE_START(U300_DT, "U300 S335/B335 (Device Tree)") | 407 | DT_MACHINE_START(U300_DT, "U300 S335/B335 (Device Tree)") |
408 | .map_io = u300_map_io, | 408 | .map_io = u300_map_io, |
409 | .init_irq = u300_init_irq_dt, | 409 | .init_irq = u300_init_irq_dt, |
410 | .init_time = clocksource_probe, | 410 | .init_time = timer_probe, |
411 | .init_machine = u300_init_machine_dt, | 411 | .init_machine = u300_init_machine_dt, |
412 | .restart = u300_restart, | 412 | .restart = u300_restart, |
413 | .dt_compat = u300_board_compat, | 413 | .dt_compat = u300_board_compat, |
diff --git a/arch/arm/mach-zynq/common.c b/arch/arm/mach-zynq/common.c index ed118648313f..6aba9ebf8041 100644 --- a/arch/arm/mach-zynq/common.c +++ b/arch/arm/mach-zynq/common.c | |||
@@ -150,7 +150,7 @@ static void __init zynq_timer_init(void) | |||
150 | { | 150 | { |
151 | zynq_clock_init(); | 151 | zynq_clock_init(); |
152 | of_clk_init(NULL); | 152 | of_clk_init(NULL); |
153 | clocksource_probe(); | 153 | timer_probe(); |
154 | } | 154 | } |
155 | 155 | ||
156 | static struct map_desc zynq_cortex_a9_scu_map __initdata = { | 156 | static struct map_desc zynq_cortex_a9_scu_map __initdata = { |
diff --git a/arch/arm64/Kconfig.platforms b/arch/arm64/Kconfig.platforms index 73272f43ca01..9ed0a659046b 100644 --- a/arch/arm64/Kconfig.platforms +++ b/arch/arm64/Kconfig.platforms | |||
@@ -18,7 +18,7 @@ config ARCH_ALPINE | |||
18 | 18 | ||
19 | config ARCH_BCM2835 | 19 | config ARCH_BCM2835 |
20 | bool "Broadcom BCM2835 family" | 20 | bool "Broadcom BCM2835 family" |
21 | select CLKSRC_OF | 21 | select TIMER_OF |
22 | select GPIOLIB | 22 | select GPIOLIB |
23 | select PINCTRL | 23 | select PINCTRL |
24 | select PINCTRL_BCM2835 | 24 | select PINCTRL_BCM2835 |
@@ -178,7 +178,7 @@ config ARCH_TEGRA | |||
178 | select ARCH_HAS_RESET_CONTROLLER | 178 | select ARCH_HAS_RESET_CONTROLLER |
179 | select CLKDEV_LOOKUP | 179 | select CLKDEV_LOOKUP |
180 | select CLKSRC_MMIO | 180 | select CLKSRC_MMIO |
181 | select CLKSRC_OF | 181 | select TIMER_OF |
182 | select GENERIC_CLOCKEVENTS | 182 | select GENERIC_CLOCKEVENTS |
183 | select GPIOLIB | 183 | select GPIOLIB |
184 | select PINCTRL | 184 | select PINCTRL |
diff --git a/arch/arm64/kernel/time.c b/arch/arm64/kernel/time.c index 59779699a1a4..da33c90248e9 100644 --- a/arch/arm64/kernel/time.c +++ b/arch/arm64/kernel/time.c | |||
@@ -70,7 +70,7 @@ void __init time_init(void) | |||
70 | u32 arch_timer_rate; | 70 | u32 arch_timer_rate; |
71 | 71 | ||
72 | of_clk_init(NULL); | 72 | of_clk_init(NULL); |
73 | clocksource_probe(); | 73 | timer_probe(); |
74 | 74 | ||
75 | tick_setup_hrtimer_broadcast(); | 75 | tick_setup_hrtimer_broadcast(); |
76 | 76 | ||
diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c index d0cb007fa482..7492d9009610 100644 --- a/arch/arm64/kernel/vdso.c +++ b/arch/arm64/kernel/vdso.c | |||
@@ -220,10 +220,8 @@ void update_vsyscall(struct timekeeper *tk) | |||
220 | if (!use_syscall) { | 220 | if (!use_syscall) { |
221 | /* tkr_mono.cycle_last == tkr_raw.cycle_last */ | 221 | /* tkr_mono.cycle_last == tkr_raw.cycle_last */ |
222 | vdso_data->cs_cycle_last = tk->tkr_mono.cycle_last; | 222 | vdso_data->cs_cycle_last = tk->tkr_mono.cycle_last; |
223 | vdso_data->raw_time_sec = tk->raw_time.tv_sec; | 223 | vdso_data->raw_time_sec = tk->raw_sec; |
224 | vdso_data->raw_time_nsec = (tk->raw_time.tv_nsec << | 224 | vdso_data->raw_time_nsec = tk->tkr_raw.xtime_nsec; |
225 | tk->tkr_raw.shift) + | ||
226 | tk->tkr_raw.xtime_nsec; | ||
227 | vdso_data->xtime_clock_sec = tk->xtime_sec; | 225 | vdso_data->xtime_clock_sec = tk->xtime_sec; |
228 | vdso_data->xtime_clock_nsec = tk->tkr_mono.xtime_nsec; | 226 | vdso_data->xtime_clock_nsec = tk->tkr_mono.xtime_nsec; |
229 | vdso_data->cs_mono_mult = tk->tkr_mono.mult; | 227 | vdso_data->cs_mono_mult = tk->tkr_mono.mult; |
diff --git a/arch/c6x/include/asm/Kbuild b/arch/c6x/include/asm/Kbuild index f0eaf0475e7e..a3c8d05c4cc7 100644 --- a/arch/c6x/include/asm/Kbuild +++ b/arch/c6x/include/asm/Kbuild | |||
@@ -45,7 +45,6 @@ generic-y += sembuf.h | |||
45 | generic-y += serial.h | 45 | generic-y += serial.h |
46 | generic-y += shmbuf.h | 46 | generic-y += shmbuf.h |
47 | generic-y += shmparam.h | 47 | generic-y += shmparam.h |
48 | generic-y += siginfo.h | ||
49 | generic-y += signal.h | 48 | generic-y += signal.h |
50 | generic-y += socket.h | 49 | generic-y += socket.h |
51 | generic-y += sockios.h | 50 | generic-y += sockios.h |
diff --git a/arch/c6x/include/uapi/asm/Kbuild b/arch/c6x/include/uapi/asm/Kbuild index 13a97aa2285f..1c44d3b3eba0 100644 --- a/arch/c6x/include/uapi/asm/Kbuild +++ b/arch/c6x/include/uapi/asm/Kbuild | |||
@@ -2,3 +2,4 @@ | |||
2 | include include/uapi/asm-generic/Kbuild.asm | 2 | include include/uapi/asm-generic/Kbuild.asm |
3 | 3 | ||
4 | generic-y += kvm_para.h | 4 | generic-y += kvm_para.h |
5 | generic-y += siginfo.h | ||
diff --git a/arch/cris/include/asm/Kbuild b/arch/cris/include/asm/Kbuild index 2890099992a9..acc5781100c2 100644 --- a/arch/cris/include/asm/Kbuild +++ b/arch/cris/include/asm/Kbuild | |||
@@ -36,7 +36,6 @@ generic-y += resource.h | |||
36 | generic-y += sections.h | 36 | generic-y += sections.h |
37 | generic-y += sembuf.h | 37 | generic-y += sembuf.h |
38 | generic-y += shmbuf.h | 38 | generic-y += shmbuf.h |
39 | generic-y += siginfo.h | ||
40 | generic-y += socket.h | 39 | generic-y += socket.h |
41 | generic-y += sockios.h | 40 | generic-y += sockios.h |
42 | generic-y += statfs.h | 41 | generic-y += statfs.h |
diff --git a/arch/cris/include/uapi/asm/Kbuild b/arch/cris/include/uapi/asm/Kbuild index b15bf6bc0e94..b55fc2ae1e8c 100644 --- a/arch/cris/include/uapi/asm/Kbuild +++ b/arch/cris/include/uapi/asm/Kbuild | |||
@@ -1,2 +1,4 @@ | |||
1 | # UAPI Header export list | 1 | # UAPI Header export list |
2 | include include/uapi/asm-generic/Kbuild.asm | 2 | include include/uapi/asm-generic/Kbuild.asm |
3 | |||
4 | generic-y += siginfo.h | ||
diff --git a/arch/h8300/Kconfig b/arch/h8300/Kconfig index 3ae852507e57..6e3d36f37a02 100644 --- a/arch/h8300/Kconfig +++ b/arch/h8300/Kconfig | |||
@@ -15,7 +15,7 @@ config H8300 | |||
15 | select OF_IRQ | 15 | select OF_IRQ |
16 | select OF_EARLY_FLATTREE | 16 | select OF_EARLY_FLATTREE |
17 | select HAVE_MEMBLOCK | 17 | select HAVE_MEMBLOCK |
18 | select CLKSRC_OF | 18 | select TIMER_OF |
19 | select H8300_TMR8 | 19 | select H8300_TMR8 |
20 | select HAVE_KERNEL_GZIP | 20 | select HAVE_KERNEL_GZIP |
21 | select HAVE_KERNEL_LZO | 21 | select HAVE_KERNEL_LZO |
diff --git a/arch/h8300/include/asm/Kbuild b/arch/h8300/include/asm/Kbuild index 757cdeb24e6e..99c824608a31 100644 --- a/arch/h8300/include/asm/Kbuild +++ b/arch/h8300/include/asm/Kbuild | |||
@@ -54,7 +54,6 @@ generic-y += serial.h | |||
54 | generic-y += setup.h | 54 | generic-y += setup.h |
55 | generic-y += shmbuf.h | 55 | generic-y += shmbuf.h |
56 | generic-y += shmparam.h | 56 | generic-y += shmparam.h |
57 | generic-y += siginfo.h | ||
58 | generic-y += sizes.h | 57 | generic-y += sizes.h |
59 | generic-y += socket.h | 58 | generic-y += socket.h |
60 | generic-y += sockios.h | 59 | generic-y += sockios.h |
diff --git a/arch/h8300/include/uapi/asm/Kbuild b/arch/h8300/include/uapi/asm/Kbuild index b15bf6bc0e94..b55fc2ae1e8c 100644 --- a/arch/h8300/include/uapi/asm/Kbuild +++ b/arch/h8300/include/uapi/asm/Kbuild | |||
@@ -1,2 +1,4 @@ | |||
1 | # UAPI Header export list | 1 | # UAPI Header export list |
2 | include include/uapi/asm-generic/Kbuild.asm | 2 | include include/uapi/asm-generic/Kbuild.asm |
3 | |||
4 | generic-y += siginfo.h | ||
diff --git a/arch/h8300/kernel/setup.c b/arch/h8300/kernel/setup.c index c8c25a4e9e48..6be15d634650 100644 --- a/arch/h8300/kernel/setup.c +++ b/arch/h8300/kernel/setup.c | |||
@@ -246,5 +246,5 @@ void __init calibrate_delay(void) | |||
246 | void __init time_init(void) | 246 | void __init time_init(void) |
247 | { | 247 | { |
248 | of_clk_init(NULL); | 248 | of_clk_init(NULL); |
249 | clocksource_probe(); | 249 | timer_probe(); |
250 | } | 250 | } |
diff --git a/arch/hexagon/include/asm/Kbuild b/arch/hexagon/include/asm/Kbuild index 6b45ef79eb8f..0fc9cb04e6ad 100644 --- a/arch/hexagon/include/asm/Kbuild +++ b/arch/hexagon/include/asm/Kbuild | |||
@@ -41,7 +41,6 @@ generic-y += sembuf.h | |||
41 | generic-y += serial.h | 41 | generic-y += serial.h |
42 | generic-y += shmbuf.h | 42 | generic-y += shmbuf.h |
43 | generic-y += shmparam.h | 43 | generic-y += shmparam.h |
44 | generic-y += siginfo.h | ||
45 | generic-y += sizes.h | 44 | generic-y += sizes.h |
46 | generic-y += socket.h | 45 | generic-y += socket.h |
47 | generic-y += sockios.h | 46 | generic-y += sockios.h |
diff --git a/arch/hexagon/include/uapi/asm/Kbuild b/arch/hexagon/include/uapi/asm/Kbuild index b15bf6bc0e94..b55fc2ae1e8c 100644 --- a/arch/hexagon/include/uapi/asm/Kbuild +++ b/arch/hexagon/include/uapi/asm/Kbuild | |||
@@ -1,2 +1,4 @@ | |||
1 | # UAPI Header export list | 1 | # UAPI Header export list |
2 | include include/uapi/asm-generic/Kbuild.asm | 2 | include include/uapi/asm-generic/Kbuild.asm |
3 | |||
4 | generic-y += siginfo.h | ||
diff --git a/arch/ia64/include/asm/siginfo.h b/arch/ia64/include/asm/siginfo.h deleted file mode 100644 index 6f2e2dd0f28f..000000000000 --- a/arch/ia64/include/asm/siginfo.h +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | /* | ||
2 | * Based on <asm-i386/siginfo.h>. | ||
3 | * | ||
4 | * Modified 1998-2002 | ||
5 | * David Mosberger-Tang <davidm@hpl.hp.com>, Hewlett-Packard Co | ||
6 | */ | ||
7 | #ifndef _ASM_IA64_SIGINFO_H | ||
8 | #define _ASM_IA64_SIGINFO_H | ||
9 | |||
10 | #include <linux/string.h> | ||
11 | #include <uapi/asm/siginfo.h> | ||
12 | |||
13 | static inline void | ||
14 | copy_siginfo (siginfo_t *to, siginfo_t *from) | ||
15 | { | ||
16 | if (from->si_code < 0) | ||
17 | memcpy(to, from, sizeof(siginfo_t)); | ||
18 | else | ||
19 | /* _sigchld is currently the largest know union member */ | ||
20 | memcpy(to, from, 4*sizeof(int) + sizeof(from->_sifields._sigchld)); | ||
21 | } | ||
22 | |||
23 | #endif /* _ASM_IA64_SIGINFO_H */ | ||
diff --git a/arch/ia64/include/uapi/asm/siginfo.h b/arch/ia64/include/uapi/asm/siginfo.h index f72bf0172bb2..4694c64252d6 100644 --- a/arch/ia64/include/uapi/asm/siginfo.h +++ b/arch/ia64/include/uapi/asm/siginfo.h | |||
@@ -11,7 +11,6 @@ | |||
11 | #define __ARCH_SI_PREAMBLE_SIZE (4 * sizeof(int)) | 11 | #define __ARCH_SI_PREAMBLE_SIZE (4 * sizeof(int)) |
12 | 12 | ||
13 | #define HAVE_ARCH_SIGINFO_T | 13 | #define HAVE_ARCH_SIGINFO_T |
14 | #define HAVE_ARCH_COPY_SIGINFO | ||
15 | #define HAVE_ARCH_COPY_SIGINFO_TO_USER | 14 | #define HAVE_ARCH_COPY_SIGINFO_TO_USER |
16 | 15 | ||
17 | #include <asm-generic/siginfo.h> | 16 | #include <asm-generic/siginfo.h> |
diff --git a/arch/m32r/include/uapi/asm/Kbuild b/arch/m32r/include/uapi/asm/Kbuild index b15bf6bc0e94..c94ee54210bc 100644 --- a/arch/m32r/include/uapi/asm/Kbuild +++ b/arch/m32r/include/uapi/asm/Kbuild | |||
@@ -1,2 +1,4 @@ | |||
1 | # UAPI Header export list | 1 | # UAPI Header export list |
2 | include include/uapi/asm-generic/Kbuild.asm | 2 | include include/uapi/asm-generic/Kbuild.asm |
3 | |||
4 | generic-y += siginfo.h | ||
diff --git a/arch/m32r/include/uapi/asm/siginfo.h b/arch/m32r/include/uapi/asm/siginfo.h deleted file mode 100644 index 7d9cd9ebfd0e..000000000000 --- a/arch/m32r/include/uapi/asm/siginfo.h +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | #ifndef _M32R_SIGINFO_H | ||
2 | #define _M32R_SIGINFO_H | ||
3 | |||
4 | #include <asm-generic/siginfo.h> | ||
5 | |||
6 | #endif /* _M32R_SIGINFO_H */ | ||
diff --git a/arch/m68k/include/asm/Kbuild b/arch/m68k/include/asm/Kbuild index 82005d2ff717..5ecf4e47b2e2 100644 --- a/arch/m68k/include/asm/Kbuild +++ b/arch/m68k/include/asm/Kbuild | |||
@@ -25,7 +25,6 @@ generic-y += preempt.h | |||
25 | generic-y += resource.h | 25 | generic-y += resource.h |
26 | generic-y += sections.h | 26 | generic-y += sections.h |
27 | generic-y += shmparam.h | 27 | generic-y += shmparam.h |
28 | generic-y += siginfo.h | ||
29 | generic-y += spinlock.h | 28 | generic-y += spinlock.h |
30 | generic-y += statfs.h | 29 | generic-y += statfs.h |
31 | generic-y += termios.h | 30 | generic-y += termios.h |
diff --git a/arch/m68k/include/uapi/asm/Kbuild b/arch/m68k/include/uapi/asm/Kbuild index 64368077235a..68b45cc87e2c 100644 --- a/arch/m68k/include/uapi/asm/Kbuild +++ b/arch/m68k/include/uapi/asm/Kbuild | |||
@@ -5,6 +5,7 @@ generic-y += auxvec.h | |||
5 | generic-y += msgbuf.h | 5 | generic-y += msgbuf.h |
6 | generic-y += sembuf.h | 6 | generic-y += sembuf.h |
7 | generic-y += shmbuf.h | 7 | generic-y += shmbuf.h |
8 | generic-y += siginfo.h | ||
8 | generic-y += socket.h | 9 | generic-y += socket.h |
9 | generic-y += sockios.h | 10 | generic-y += sockios.h |
10 | generic-y += termbits.h | 11 | generic-y += termbits.h |
diff --git a/arch/microblaze/Kconfig b/arch/microblaze/Kconfig index 85885a501dce..8e47121b8b8b 100644 --- a/arch/microblaze/Kconfig +++ b/arch/microblaze/Kconfig | |||
@@ -4,7 +4,7 @@ config MICROBLAZE | |||
4 | select ARCH_MIGHT_HAVE_PC_PARPORT | 4 | select ARCH_MIGHT_HAVE_PC_PARPORT |
5 | select ARCH_WANT_IPC_PARSE_VERSION | 5 | select ARCH_WANT_IPC_PARSE_VERSION |
6 | select BUILDTIME_EXTABLE_SORT | 6 | select BUILDTIME_EXTABLE_SORT |
7 | select CLKSRC_OF | 7 | select TIMER_OF |
8 | select CLONE_BACKWARDS3 | 8 | select CLONE_BACKWARDS3 |
9 | select COMMON_CLK | 9 | select COMMON_CLK |
10 | select GENERIC_ATOMIC64 | 10 | select GENERIC_ATOMIC64 |
diff --git a/arch/microblaze/include/uapi/asm/Kbuild b/arch/microblaze/include/uapi/asm/Kbuild index 2178c78c7c1a..cb6784f4a427 100644 --- a/arch/microblaze/include/uapi/asm/Kbuild +++ b/arch/microblaze/include/uapi/asm/Kbuild | |||
@@ -2,3 +2,4 @@ | |||
2 | include include/uapi/asm-generic/Kbuild.asm | 2 | include include/uapi/asm-generic/Kbuild.asm |
3 | 3 | ||
4 | generic-y += types.h | 4 | generic-y += types.h |
5 | generic-y += siginfo.h | ||
diff --git a/arch/microblaze/kernel/setup.c b/arch/microblaze/kernel/setup.c index f31ebb5dc26c..be98ffe28ca8 100644 --- a/arch/microblaze/kernel/setup.c +++ b/arch/microblaze/kernel/setup.c | |||
@@ -192,7 +192,7 @@ void __init time_init(void) | |||
192 | { | 192 | { |
193 | of_clk_init(NULL); | 193 | of_clk_init(NULL); |
194 | setup_cpuinfo_clk(); | 194 | setup_cpuinfo_clk(); |
195 | clocksource_probe(); | 195 | timer_probe(); |
196 | } | 196 | } |
197 | 197 | ||
198 | #ifdef CONFIG_DEBUG_FS | 198 | #ifdef CONFIG_DEBUG_FS |
diff --git a/arch/microblaze/kernel/timer.c b/arch/microblaze/kernel/timer.c index 545ccd46edb3..ea2d83f1f4bb 100644 --- a/arch/microblaze/kernel/timer.c +++ b/arch/microblaze/kernel/timer.c | |||
@@ -335,5 +335,5 @@ static int __init xilinx_timer_init(struct device_node *timer) | |||
335 | return 0; | 335 | return 0; |
336 | } | 336 | } |
337 | 337 | ||
338 | CLOCKSOURCE_OF_DECLARE(xilinx_timer, "xlnx,xps-timer-1.00.a", | 338 | TIMER_OF_DECLARE(xilinx_timer, "xlnx,xps-timer-1.00.a", |
339 | xilinx_timer_init); | 339 | xilinx_timer_init); |
diff --git a/arch/mips/generic/init.c b/arch/mips/generic/init.c index 4af619215410..1231b5a17b37 100644 --- a/arch/mips/generic/init.c +++ b/arch/mips/generic/init.c | |||
@@ -161,7 +161,7 @@ void __init plat_time_init(void) | |||
161 | } | 161 | } |
162 | } | 162 | } |
163 | 163 | ||
164 | clocksource_probe(); | 164 | timer_probe(); |
165 | } | 165 | } |
166 | 166 | ||
167 | void __init arch_init_irq(void) | 167 | void __init arch_init_irq(void) |
diff --git a/arch/mips/mti-malta/malta-time.c b/arch/mips/mti-malta/malta-time.c index 289edcfadd7c..cea4ec909806 100644 --- a/arch/mips/mti-malta/malta-time.c +++ b/arch/mips/mti-malta/malta-time.c | |||
@@ -265,7 +265,7 @@ void __init plat_time_init(void) | |||
265 | (freq%1000000)*100/1000000); | 265 | (freq%1000000)*100/1000000); |
266 | #ifdef CONFIG_CLKSRC_MIPS_GIC | 266 | #ifdef CONFIG_CLKSRC_MIPS_GIC |
267 | update_gic_frequency_dt(); | 267 | update_gic_frequency_dt(); |
268 | clocksource_probe(); | 268 | timer_probe(); |
269 | #endif | 269 | #endif |
270 | } | 270 | } |
271 | #endif | 271 | #endif |
diff --git a/arch/mips/pic32/pic32mzda/time.c b/arch/mips/pic32/pic32mzda/time.c index 62a0a78b6c64..1894e50939b5 100644 --- a/arch/mips/pic32/pic32mzda/time.c +++ b/arch/mips/pic32/pic32mzda/time.c | |||
@@ -64,5 +64,5 @@ void __init plat_time_init(void) | |||
64 | pr_info("CPU Clock: %ldMHz\n", rate / 1000000); | 64 | pr_info("CPU Clock: %ldMHz\n", rate / 1000000); |
65 | mips_hpt_frequency = rate / 2; | 65 | mips_hpt_frequency = rate / 2; |
66 | 66 | ||
67 | clocksource_probe(); | 67 | timer_probe(); |
68 | } | 68 | } |
diff --git a/arch/mips/pistachio/time.c b/arch/mips/pistachio/time.c index 1022201b2beb..17a0f1dec05b 100644 --- a/arch/mips/pistachio/time.c +++ b/arch/mips/pistachio/time.c | |||
@@ -39,7 +39,7 @@ void __init plat_time_init(void) | |||
39 | struct clk *clk; | 39 | struct clk *clk; |
40 | 40 | ||
41 | of_clk_init(NULL); | 41 | of_clk_init(NULL); |
42 | clocksource_probe(); | 42 | timer_probe(); |
43 | 43 | ||
44 | np = of_get_cpu_node(0, NULL); | 44 | np = of_get_cpu_node(0, NULL); |
45 | if (!np) { | 45 | if (!np) { |
diff --git a/arch/mips/ralink/Kconfig b/arch/mips/ralink/Kconfig index 9825dee10bc1..710b04cf4851 100644 --- a/arch/mips/ralink/Kconfig +++ b/arch/mips/ralink/Kconfig | |||
@@ -4,7 +4,7 @@ config CLKEVT_RT3352 | |||
4 | bool | 4 | bool |
5 | depends on SOC_RT305X || SOC_MT7620 | 5 | depends on SOC_RT305X || SOC_MT7620 |
6 | default y | 6 | default y |
7 | select CLKSRC_OF | 7 | select TIMER_OF |
8 | select CLKSRC_MMIO | 8 | select CLKSRC_MMIO |
9 | 9 | ||
10 | config RALINK_ILL_ACC | 10 | config RALINK_ILL_ACC |
diff --git a/arch/mips/ralink/cevt-rt3352.c b/arch/mips/ralink/cevt-rt3352.c index b8a1376165b0..92f284d2b802 100644 --- a/arch/mips/ralink/cevt-rt3352.c +++ b/arch/mips/ralink/cevt-rt3352.c | |||
@@ -152,4 +152,4 @@ static int __init ralink_systick_init(struct device_node *np) | |||
152 | return 0; | 152 | return 0; |
153 | } | 153 | } |
154 | 154 | ||
155 | CLOCKSOURCE_OF_DECLARE(systick, "ralink,cevt-systick", ralink_systick_init); | 155 | TIMER_OF_DECLARE(systick, "ralink,cevt-systick", ralink_systick_init); |
diff --git a/arch/mips/ralink/clk.c b/arch/mips/ralink/clk.c index df795885eace..eb1c61917eb7 100644 --- a/arch/mips/ralink/clk.c +++ b/arch/mips/ralink/clk.c | |||
@@ -82,5 +82,5 @@ void __init plat_time_init(void) | |||
82 | pr_info("CPU Clock: %ldMHz\n", clk_get_rate(clk) / 1000000); | 82 | pr_info("CPU Clock: %ldMHz\n", clk_get_rate(clk) / 1000000); |
83 | mips_hpt_frequency = clk_get_rate(clk) / 2; | 83 | mips_hpt_frequency = clk_get_rate(clk) / 2; |
84 | clk_put(clk); | 84 | clk_put(clk); |
85 | clocksource_probe(); | 85 | timer_probe(); |
86 | } | 86 | } |
diff --git a/arch/mips/ralink/timer-gic.c b/arch/mips/ralink/timer-gic.c index 069771dbec42..b5f07d21fcf2 100644 --- a/arch/mips/ralink/timer-gic.c +++ b/arch/mips/ralink/timer-gic.c | |||
@@ -20,5 +20,5 @@ void __init plat_time_init(void) | |||
20 | ralink_of_remap(); | 20 | ralink_of_remap(); |
21 | 21 | ||
22 | of_clk_init(NULL); | 22 | of_clk_init(NULL); |
23 | clocksource_probe(); | 23 | timer_probe(); |
24 | } | 24 | } |
diff --git a/arch/mips/xilfpga/time.c b/arch/mips/xilfpga/time.c index cbb3fca7b6fa..36f3f1870ee2 100644 --- a/arch/mips/xilfpga/time.c +++ b/arch/mips/xilfpga/time.c | |||
@@ -22,7 +22,7 @@ void __init plat_time_init(void) | |||
22 | struct clk *clk; | 22 | struct clk *clk; |
23 | 23 | ||
24 | of_clk_init(NULL); | 24 | of_clk_init(NULL); |
25 | clocksource_probe(); | 25 | timer_probe(); |
26 | 26 | ||
27 | np = of_get_cpu_node(0, NULL); | 27 | np = of_get_cpu_node(0, NULL); |
28 | if (!np) { | 28 | if (!np) { |
diff --git a/arch/mn10300/include/uapi/asm/Kbuild b/arch/mn10300/include/uapi/asm/Kbuild index b15bf6bc0e94..c94ee54210bc 100644 --- a/arch/mn10300/include/uapi/asm/Kbuild +++ b/arch/mn10300/include/uapi/asm/Kbuild | |||
@@ -1,2 +1,4 @@ | |||
1 | # UAPI Header export list | 1 | # UAPI Header export list |
2 | include include/uapi/asm-generic/Kbuild.asm | 2 | include include/uapi/asm-generic/Kbuild.asm |
3 | |||
4 | generic-y += siginfo.h | ||
diff --git a/arch/mn10300/include/uapi/asm/siginfo.h b/arch/mn10300/include/uapi/asm/siginfo.h deleted file mode 100644 index 0815d29d82e5..000000000000 --- a/arch/mn10300/include/uapi/asm/siginfo.h +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | #include <asm-generic/siginfo.h> | ||
diff --git a/arch/nios2/Kconfig b/arch/nios2/Kconfig index a72d5f0de692..c587764b9c5a 100644 --- a/arch/nios2/Kconfig +++ b/arch/nios2/Kconfig | |||
@@ -1,6 +1,6 @@ | |||
1 | config NIOS2 | 1 | config NIOS2 |
2 | def_bool y | 2 | def_bool y |
3 | select CLKSRC_OF | 3 | select TIMER_OF |
4 | select GENERIC_ATOMIC64 | 4 | select GENERIC_ATOMIC64 |
5 | select GENERIC_CLOCKEVENTS | 5 | select GENERIC_CLOCKEVENTS |
6 | select GENERIC_CPU_DEVICES | 6 | select GENERIC_CPU_DEVICES |
diff --git a/arch/nios2/include/asm/Kbuild b/arch/nios2/include/asm/Kbuild index 727dbb333f60..e1a843def56f 100644 --- a/arch/nios2/include/asm/Kbuild +++ b/arch/nios2/include/asm/Kbuild | |||
@@ -47,7 +47,6 @@ generic-y += segment.h | |||
47 | generic-y += sembuf.h | 47 | generic-y += sembuf.h |
48 | generic-y += serial.h | 48 | generic-y += serial.h |
49 | generic-y += shmbuf.h | 49 | generic-y += shmbuf.h |
50 | generic-y += siginfo.h | ||
51 | generic-y += signal.h | 50 | generic-y += signal.h |
52 | generic-y += socket.h | 51 | generic-y += socket.h |
53 | generic-y += sockios.h | 52 | generic-y += sockios.h |
diff --git a/arch/nios2/include/uapi/asm/Kbuild b/arch/nios2/include/uapi/asm/Kbuild index 374bd123329f..51eff5bc2eb4 100644 --- a/arch/nios2/include/uapi/asm/Kbuild +++ b/arch/nios2/include/uapi/asm/Kbuild | |||
@@ -2,4 +2,5 @@ | |||
2 | include include/uapi/asm-generic/Kbuild.asm | 2 | include include/uapi/asm-generic/Kbuild.asm |
3 | 3 | ||
4 | generic-y += setup.h | 4 | generic-y += setup.h |
5 | generic-y += siginfo.h | ||
5 | generic-y += ucontext.h | 6 | generic-y += ucontext.h |
diff --git a/arch/nios2/kernel/time.c b/arch/nios2/kernel/time.c index 6e2bdc9b8530..645129aaa9a0 100644 --- a/arch/nios2/kernel/time.c +++ b/arch/nios2/kernel/time.c | |||
@@ -350,7 +350,7 @@ void __init time_init(void) | |||
350 | if (count < 2) | 350 | if (count < 2) |
351 | panic("%d timer is found, it needs 2 timers in system\n", count); | 351 | panic("%d timer is found, it needs 2 timers in system\n", count); |
352 | 352 | ||
353 | clocksource_probe(); | 353 | timer_probe(); |
354 | } | 354 | } |
355 | 355 | ||
356 | CLOCKSOURCE_OF_DECLARE(nios2_timer, ALTR_TIMER_COMPATIBLE, nios2_time_init); | 356 | TIMER_OF_DECLARE(nios2_timer, ALTR_TIMER_COMPATIBLE, nios2_time_init); |
diff --git a/arch/openrisc/include/asm/Kbuild b/arch/openrisc/include/asm/Kbuild index fdbcf0bf44a4..091585addb91 100644 --- a/arch/openrisc/include/asm/Kbuild +++ b/arch/openrisc/include/asm/Kbuild | |||
@@ -46,7 +46,6 @@ generic-y += sembuf.h | |||
46 | generic-y += setup.h | 46 | generic-y += setup.h |
47 | generic-y += shmbuf.h | 47 | generic-y += shmbuf.h |
48 | generic-y += shmparam.h | 48 | generic-y += shmparam.h |
49 | generic-y += siginfo.h | ||
50 | generic-y += signal.h | 49 | generic-y += signal.h |
51 | generic-y += socket.h | 50 | generic-y += socket.h |
52 | generic-y += sockios.h | 51 | generic-y += sockios.h |
diff --git a/arch/openrisc/include/uapi/asm/Kbuild b/arch/openrisc/include/uapi/asm/Kbuild index b15bf6bc0e94..b55fc2ae1e8c 100644 --- a/arch/openrisc/include/uapi/asm/Kbuild +++ b/arch/openrisc/include/uapi/asm/Kbuild | |||
@@ -1,2 +1,4 @@ | |||
1 | # UAPI Header export list | 1 | # UAPI Header export list |
2 | include include/uapi/asm-generic/Kbuild.asm | 2 | include include/uapi/asm-generic/Kbuild.asm |
3 | |||
4 | generic-y += siginfo.h | ||
diff --git a/arch/score/include/uapi/asm/Kbuild b/arch/score/include/uapi/asm/Kbuild index b15bf6bc0e94..c94ee54210bc 100644 --- a/arch/score/include/uapi/asm/Kbuild +++ b/arch/score/include/uapi/asm/Kbuild | |||
@@ -1,2 +1,4 @@ | |||
1 | # UAPI Header export list | 1 | # UAPI Header export list |
2 | include include/uapi/asm-generic/Kbuild.asm | 2 | include include/uapi/asm-generic/Kbuild.asm |
3 | |||
4 | generic-y += siginfo.h | ||
diff --git a/arch/score/include/uapi/asm/siginfo.h b/arch/score/include/uapi/asm/siginfo.h deleted file mode 100644 index 87ca35607a28..000000000000 --- a/arch/score/include/uapi/asm/siginfo.h +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | #ifndef _ASM_SCORE_SIGINFO_H | ||
2 | #define _ASM_SCORE_SIGINFO_H | ||
3 | |||
4 | #include <asm-generic/siginfo.h> | ||
5 | |||
6 | #endif /* _ASM_SCORE_SIGINFO_H */ | ||
diff --git a/arch/sh/boards/Kconfig b/arch/sh/boards/Kconfig index 4e21949593cf..3554fcaa023b 100644 --- a/arch/sh/boards/Kconfig +++ b/arch/sh/boards/Kconfig | |||
@@ -10,7 +10,7 @@ config SH_DEVICE_TREE | |||
10 | bool "Board Described by Device Tree" | 10 | bool "Board Described by Device Tree" |
11 | select OF | 11 | select OF |
12 | select OF_EARLY_FLATTREE | 12 | select OF_EARLY_FLATTREE |
13 | select CLKSRC_OF | 13 | select TIMER_OF |
14 | select COMMON_CLK | 14 | select COMMON_CLK |
15 | select GENERIC_CALIBRATE_DELAY | 15 | select GENERIC_CALIBRATE_DELAY |
16 | help | 16 | help |
diff --git a/arch/sh/boards/of-generic.c b/arch/sh/boards/of-generic.c index 1fb6d5714bae..4feb7c86f4ac 100644 --- a/arch/sh/boards/of-generic.c +++ b/arch/sh/boards/of-generic.c | |||
@@ -119,7 +119,7 @@ static void __init sh_of_mem_reserve(void) | |||
119 | static void __init sh_of_time_init(void) | 119 | static void __init sh_of_time_init(void) |
120 | { | 120 | { |
121 | pr_info("SH generic board support: scanning for clocksource devices\n"); | 121 | pr_info("SH generic board support: scanning for clocksource devices\n"); |
122 | clocksource_probe(); | 122 | timer_probe(); |
123 | } | 123 | } |
124 | 124 | ||
125 | static void __init sh_of_setup(char **cmdline_p) | 125 | static void __init sh_of_setup(char **cmdline_p) |
diff --git a/arch/sh/include/asm/Kbuild b/arch/sh/include/asm/Kbuild index cf2a75063b53..590c91ae7541 100644 --- a/arch/sh/include/asm/Kbuild +++ b/arch/sh/include/asm/Kbuild | |||
@@ -29,7 +29,6 @@ generic-y += rwsem.h | |||
29 | generic-y += sembuf.h | 29 | generic-y += sembuf.h |
30 | generic-y += serial.h | 30 | generic-y += serial.h |
31 | generic-y += shmbuf.h | 31 | generic-y += shmbuf.h |
32 | generic-y += siginfo.h | ||
33 | generic-y += sizes.h | 32 | generic-y += sizes.h |
34 | generic-y += socket.h | 33 | generic-y += socket.h |
35 | generic-y += statfs.h | 34 | generic-y += statfs.h |
diff --git a/arch/sh/include/uapi/asm/Kbuild b/arch/sh/include/uapi/asm/Kbuild index b15bf6bc0e94..b55fc2ae1e8c 100644 --- a/arch/sh/include/uapi/asm/Kbuild +++ b/arch/sh/include/uapi/asm/Kbuild | |||
@@ -1,2 +1,4 @@ | |||
1 | # UAPI Header export list | 1 | # UAPI Header export list |
2 | include include/uapi/asm-generic/Kbuild.asm | 2 | include include/uapi/asm-generic/Kbuild.asm |
3 | |||
4 | generic-y += siginfo.h | ||
diff --git a/arch/sparc/include/asm/siginfo.h b/arch/sparc/include/asm/siginfo.h deleted file mode 100644 index 48c34c19f810..000000000000 --- a/arch/sparc/include/asm/siginfo.h +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | #ifndef __SPARC_SIGINFO_H | ||
2 | #define __SPARC_SIGINFO_H | ||
3 | |||
4 | #include <uapi/asm/siginfo.h> | ||
5 | |||
6 | |||
7 | #ifdef CONFIG_COMPAT | ||
8 | |||
9 | struct compat_siginfo; | ||
10 | |||
11 | #endif /* CONFIG_COMPAT */ | ||
12 | |||
13 | #endif /* !(__SPARC_SIGINFO_H) */ | ||
diff --git a/arch/unicore32/include/asm/Kbuild b/arch/unicore32/include/asm/Kbuild index e9ad511c1043..7a53a55341de 100644 --- a/arch/unicore32/include/asm/Kbuild +++ b/arch/unicore32/include/asm/Kbuild | |||
@@ -44,7 +44,6 @@ generic-y += serial.h | |||
44 | generic-y += setup.h | 44 | generic-y += setup.h |
45 | generic-y += shmbuf.h | 45 | generic-y += shmbuf.h |
46 | generic-y += shmparam.h | 46 | generic-y += shmparam.h |
47 | generic-y += siginfo.h | ||
48 | generic-y += signal.h | 47 | generic-y += signal.h |
49 | generic-y += sizes.h | 48 | generic-y += sizes.h |
50 | generic-y += socket.h | 49 | generic-y += socket.h |
diff --git a/arch/unicore32/include/uapi/asm/Kbuild b/arch/unicore32/include/uapi/asm/Kbuild index 13a97aa2285f..1c44d3b3eba0 100644 --- a/arch/unicore32/include/uapi/asm/Kbuild +++ b/arch/unicore32/include/uapi/asm/Kbuild | |||
@@ -2,3 +2,4 @@ | |||
2 | include include/uapi/asm-generic/Kbuild.asm | 2 | include include/uapi/asm-generic/Kbuild.asm |
3 | 3 | ||
4 | generic-y += kvm_para.h | 4 | generic-y += kvm_para.h |
5 | generic-y += siginfo.h | ||
diff --git a/arch/xtensa/include/asm/Kbuild b/arch/xtensa/include/asm/Kbuild index cc23e9ecc6bb..30f6290109d4 100644 --- a/arch/xtensa/include/asm/Kbuild +++ b/arch/xtensa/include/asm/Kbuild | |||
@@ -25,7 +25,6 @@ generic-y += preempt.h | |||
25 | generic-y += resource.h | 25 | generic-y += resource.h |
26 | generic-y += rwsem.h | 26 | generic-y += rwsem.h |
27 | generic-y += sections.h | 27 | generic-y += sections.h |
28 | generic-y += siginfo.h | ||
29 | generic-y += statfs.h | 28 | generic-y += statfs.h |
30 | generic-y += termios.h | 29 | generic-y += termios.h |
31 | generic-y += topology.h | 30 | generic-y += topology.h |
diff --git a/arch/xtensa/include/uapi/asm/Kbuild b/arch/xtensa/include/uapi/asm/Kbuild index b15bf6bc0e94..4cb0d2f8868c 100644 --- a/arch/xtensa/include/uapi/asm/Kbuild +++ b/arch/xtensa/include/uapi/asm/Kbuild | |||
@@ -1,2 +1,3 @@ | |||
1 | # UAPI Header export list | 1 | # UAPI Header export list |
2 | include include/uapi/asm-generic/Kbuild.asm | 2 | include include/uapi/asm-generic/Kbuild.asm |
3 | generic-y += siginfo.h | ||
diff --git a/arch/xtensa/kernel/time.c b/arch/xtensa/kernel/time.c index 668c1056f9e4..fd524a54d2ab 100644 --- a/arch/xtensa/kernel/time.c +++ b/arch/xtensa/kernel/time.c | |||
@@ -187,7 +187,7 @@ void __init time_init(void) | |||
187 | local_timer_setup(0); | 187 | local_timer_setup(0); |
188 | setup_irq(this_cpu_ptr(&ccount_timer)->evt.irq, &timer_irqaction); | 188 | setup_irq(this_cpu_ptr(&ccount_timer)->evt.irq, &timer_irqaction); |
189 | sched_clock_register(ccount_sched_clock_read, 32, ccount_freq); | 189 | sched_clock_register(ccount_sched_clock_read, 32, ccount_freq); |
190 | clocksource_probe(); | 190 | timer_probe(); |
191 | } | 191 | } |
192 | 192 | ||
193 | /* | 193 | /* |
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig index 31adbebf812e..2af70014ee5a 100644 --- a/drivers/char/Kconfig +++ b/drivers/char/Kconfig | |||
@@ -539,15 +539,6 @@ config HANGCHECK_TIMER | |||
539 | out to lunch past a certain margin. It can reboot the system | 539 | out to lunch past a certain margin. It can reboot the system |
540 | or merely print a warning. | 540 | or merely print a warning. |
541 | 541 | ||
542 | config MMTIMER | ||
543 | tristate "MMTIMER Memory mapped RTC for SGI Altix" | ||
544 | depends on IA64_GENERIC || IA64_SGI_SN2 | ||
545 | depends on POSIX_TIMERS | ||
546 | default y | ||
547 | help | ||
548 | The mmtimer device allows direct userspace access to the | ||
549 | Altix system timer. | ||
550 | |||
551 | config UV_MMTIMER | 542 | config UV_MMTIMER |
552 | tristate "UV_MMTIMER Memory mapped RTC for SGI UV" | 543 | tristate "UV_MMTIMER Memory mapped RTC for SGI UV" |
553 | depends on X86_UV | 544 | depends on X86_UV |
diff --git a/drivers/char/Makefile b/drivers/char/Makefile index 6e6c244a66a0..53e33720818c 100644 --- a/drivers/char/Makefile +++ b/drivers/char/Makefile | |||
@@ -10,7 +10,6 @@ obj-$(CONFIG_VIRTIO_CONSOLE) += virtio_console.o | |||
10 | obj-$(CONFIG_RAW_DRIVER) += raw.o | 10 | obj-$(CONFIG_RAW_DRIVER) += raw.o |
11 | obj-$(CONFIG_SGI_SNSC) += snsc.o snsc_event.o | 11 | obj-$(CONFIG_SGI_SNSC) += snsc.o snsc_event.o |
12 | obj-$(CONFIG_MSPEC) += mspec.o | 12 | obj-$(CONFIG_MSPEC) += mspec.o |
13 | obj-$(CONFIG_MMTIMER) += mmtimer.o | ||
14 | obj-$(CONFIG_UV_MMTIMER) += uv_mmtimer.o | 13 | obj-$(CONFIG_UV_MMTIMER) += uv_mmtimer.o |
15 | obj-$(CONFIG_IBM_BSR) += bsr.o | 14 | obj-$(CONFIG_IBM_BSR) += bsr.o |
16 | obj-$(CONFIG_SGI_MBCS) += mbcs.o | 15 | obj-$(CONFIG_SGI_MBCS) += mbcs.o |
diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c deleted file mode 100644 index 0e7fcb04f01e..000000000000 --- a/drivers/char/mmtimer.c +++ /dev/null | |||
@@ -1,858 +0,0 @@ | |||
1 | /* | ||
2 | * Timer device implementation for SGI SN platforms. | ||
3 | * | ||
4 | * This file is subject to the terms and conditions of the GNU General Public | ||
5 | * License. See the file "COPYING" in the main directory of this archive | ||
6 | * for more details. | ||
7 | * | ||
8 | * Copyright (c) 2001-2006 Silicon Graphics, Inc. All rights reserved. | ||
9 | * | ||
10 | * This driver exports an API that should be supportable by any HPET or IA-PC | ||
11 | * multimedia timer. The code below is currently specific to the SGI Altix | ||
12 | * SHub RTC, however. | ||
13 | * | ||
14 | * 11/01/01 - jbarnes - initial revision | ||
15 | * 9/10/04 - Christoph Lameter - remove interrupt support for kernel inclusion | ||
16 | * 10/1/04 - Christoph Lameter - provide posix clock CLOCK_SGI_CYCLE | ||
17 | * 10/13/04 - Christoph Lameter, Dimitri Sivanich - provide timer interrupt | ||
18 | * support via the posix timer interface | ||
19 | */ | ||
20 | |||
21 | #include <linux/types.h> | ||
22 | #include <linux/kernel.h> | ||
23 | #include <linux/ioctl.h> | ||
24 | #include <linux/module.h> | ||
25 | #include <linux/init.h> | ||
26 | #include <linux/errno.h> | ||
27 | #include <linux/mm.h> | ||
28 | #include <linux/fs.h> | ||
29 | #include <linux/mmtimer.h> | ||
30 | #include <linux/miscdevice.h> | ||
31 | #include <linux/posix-timers.h> | ||
32 | #include <linux/interrupt.h> | ||
33 | #include <linux/time.h> | ||
34 | #include <linux/math64.h> | ||
35 | #include <linux/mutex.h> | ||
36 | #include <linux/slab.h> | ||
37 | |||
38 | #include <linux/uaccess.h> | ||
39 | #include <asm/sn/addrs.h> | ||
40 | #include <asm/sn/intr.h> | ||
41 | #include <asm/sn/shub_mmr.h> | ||
42 | #include <asm/sn/nodepda.h> | ||
43 | #include <asm/sn/shubio.h> | ||
44 | |||
45 | MODULE_AUTHOR("Jesse Barnes <jbarnes@sgi.com>"); | ||
46 | MODULE_DESCRIPTION("SGI Altix RTC Timer"); | ||
47 | MODULE_LICENSE("GPL"); | ||
48 | |||
49 | /* name of the device, usually in /dev */ | ||
50 | #define MMTIMER_NAME "mmtimer" | ||
51 | #define MMTIMER_DESC "SGI Altix RTC Timer" | ||
52 | #define MMTIMER_VERSION "2.1" | ||
53 | |||
54 | #define RTC_BITS 55 /* 55 bits for this implementation */ | ||
55 | |||
56 | static struct k_clock sgi_clock; | ||
57 | |||
58 | extern unsigned long sn_rtc_cycles_per_second; | ||
59 | |||
60 | #define RTC_COUNTER_ADDR ((long *)LOCAL_MMR_ADDR(SH_RTC)) | ||
61 | |||
62 | #define rtc_time() (*RTC_COUNTER_ADDR) | ||
63 | |||
64 | static DEFINE_MUTEX(mmtimer_mutex); | ||
65 | static long mmtimer_ioctl(struct file *file, unsigned int cmd, | ||
66 | unsigned long arg); | ||
67 | static int mmtimer_mmap(struct file *file, struct vm_area_struct *vma); | ||
68 | |||
69 | /* | ||
70 | * Period in femtoseconds (10^-15 s) | ||
71 | */ | ||
72 | static unsigned long mmtimer_femtoperiod = 0; | ||
73 | |||
74 | static const struct file_operations mmtimer_fops = { | ||
75 | .owner = THIS_MODULE, | ||
76 | .mmap = mmtimer_mmap, | ||
77 | .unlocked_ioctl = mmtimer_ioctl, | ||
78 | .llseek = noop_llseek, | ||
79 | }; | ||
80 | |||
81 | /* | ||
82 | * We only have comparison registers RTC1-4 currently available per | ||
83 | * node. RTC0 is used by SAL. | ||
84 | */ | ||
85 | /* Check for an RTC interrupt pending */ | ||
86 | static int mmtimer_int_pending(int comparator) | ||
87 | { | ||
88 | if (HUB_L((unsigned long *)LOCAL_MMR_ADDR(SH_EVENT_OCCURRED)) & | ||
89 | SH_EVENT_OCCURRED_RTC1_INT_MASK << comparator) | ||
90 | return 1; | ||
91 | else | ||
92 | return 0; | ||
93 | } | ||
94 | |||
95 | /* Clear the RTC interrupt pending bit */ | ||
96 | static void mmtimer_clr_int_pending(int comparator) | ||
97 | { | ||
98 | HUB_S((u64 *)LOCAL_MMR_ADDR(SH_EVENT_OCCURRED_ALIAS), | ||
99 | SH_EVENT_OCCURRED_RTC1_INT_MASK << comparator); | ||
100 | } | ||
101 | |||
102 | /* Setup timer on comparator RTC1 */ | ||
103 | static void mmtimer_setup_int_0(int cpu, u64 expires) | ||
104 | { | ||
105 | u64 val; | ||
106 | |||
107 | /* Disable interrupt */ | ||
108 | HUB_S((u64 *)LOCAL_MMR_ADDR(SH_RTC1_INT_ENABLE), 0UL); | ||
109 | |||
110 | /* Initialize comparator value */ | ||
111 | HUB_S((u64 *)LOCAL_MMR_ADDR(SH_INT_CMPB), -1L); | ||
112 | |||
113 | /* Clear pending bit */ | ||
114 | mmtimer_clr_int_pending(0); | ||
115 | |||
116 | val = ((u64)SGI_MMTIMER_VECTOR << SH_RTC1_INT_CONFIG_IDX_SHFT) | | ||
117 | ((u64)cpu_physical_id(cpu) << | ||
118 | SH_RTC1_INT_CONFIG_PID_SHFT); | ||
119 | |||
120 | /* Set configuration */ | ||
121 | HUB_S((u64 *)LOCAL_MMR_ADDR(SH_RTC1_INT_CONFIG), val); | ||
122 | |||
123 | /* Enable RTC interrupts */ | ||
124 | HUB_S((u64 *)LOCAL_MMR_ADDR(SH_RTC1_INT_ENABLE), 1UL); | ||
125 | |||
126 | /* Initialize comparator value */ | ||
127 | HUB_S((u64 *)LOCAL_MMR_ADDR(SH_INT_CMPB), expires); | ||
128 | |||
129 | |||
130 | } | ||
131 | |||
132 | /* Setup timer on comparator RTC2 */ | ||
133 | static void mmtimer_setup_int_1(int cpu, u64 expires) | ||
134 | { | ||
135 | u64 val; | ||
136 | |||
137 | HUB_S((u64 *)LOCAL_MMR_ADDR(SH_RTC2_INT_ENABLE), 0UL); | ||
138 | |||
139 | HUB_S((u64 *)LOCAL_MMR_ADDR(SH_INT_CMPC), -1L); | ||
140 | |||
141 | mmtimer_clr_int_pending(1); | ||
142 | |||
143 | val = ((u64)SGI_MMTIMER_VECTOR << SH_RTC2_INT_CONFIG_IDX_SHFT) | | ||
144 | ((u64)cpu_physical_id(cpu) << | ||
145 | SH_RTC2_INT_CONFIG_PID_SHFT); | ||
146 | |||
147 | HUB_S((u64 *)LOCAL_MMR_ADDR(SH_RTC2_INT_CONFIG), val); | ||
148 | |||
149 | HUB_S((u64 *)LOCAL_MMR_ADDR(SH_RTC2_INT_ENABLE), 1UL); | ||
150 | |||
151 | HUB_S((u64 *)LOCAL_MMR_ADDR(SH_INT_CMPC), expires); | ||
152 | } | ||
153 | |||
154 | /* Setup timer on comparator RTC3 */ | ||
155 | static void mmtimer_setup_int_2(int cpu, u64 expires) | ||
156 | { | ||
157 | u64 val; | ||
158 | |||
159 | HUB_S((u64 *)LOCAL_MMR_ADDR(SH_RTC3_INT_ENABLE), 0UL); | ||
160 | |||
161 | HUB_S((u64 *)LOCAL_MMR_ADDR(SH_INT_CMPD), -1L); | ||
162 | |||
163 | mmtimer_clr_int_pending(2); | ||
164 | |||
165 | val = ((u64)SGI_MMTIMER_VECTOR << SH_RTC3_INT_CONFIG_IDX_SHFT) | | ||
166 | ((u64)cpu_physical_id(cpu) << | ||
167 | SH_RTC3_INT_CONFIG_PID_SHFT); | ||
168 | |||
169 | HUB_S((u64 *)LOCAL_MMR_ADDR(SH_RTC3_INT_CONFIG), val); | ||
170 | |||
171 | HUB_S((u64 *)LOCAL_MMR_ADDR(SH_RTC3_INT_ENABLE), 1UL); | ||
172 | |||
173 | HUB_S((u64 *)LOCAL_MMR_ADDR(SH_INT_CMPD), expires); | ||
174 | } | ||
175 | |||
176 | /* | ||
177 | * This function must be called with interrupts disabled and preemption off | ||
178 | * in order to insure that the setup succeeds in a deterministic time frame. | ||
179 | * It will check if the interrupt setup succeeded. | ||
180 | */ | ||
181 | static int mmtimer_setup(int cpu, int comparator, unsigned long expires, | ||
182 | u64 *set_completion_time) | ||
183 | { | ||
184 | switch (comparator) { | ||
185 | case 0: | ||
186 | mmtimer_setup_int_0(cpu, expires); | ||
187 | break; | ||
188 | case 1: | ||
189 | mmtimer_setup_int_1(cpu, expires); | ||
190 | break; | ||
191 | case 2: | ||
192 | mmtimer_setup_int_2(cpu, expires); | ||
193 | break; | ||
194 | } | ||
195 | /* We might've missed our expiration time */ | ||
196 | *set_completion_time = rtc_time(); | ||
197 | if (*set_completion_time <= expires) | ||
198 | return 1; | ||
199 | |||
200 | /* | ||
201 | * If an interrupt is already pending then its okay | ||
202 | * if not then we failed | ||
203 | */ | ||
204 | return mmtimer_int_pending(comparator); | ||
205 | } | ||
206 | |||
207 | static int mmtimer_disable_int(long nasid, int comparator) | ||
208 | { | ||
209 | switch (comparator) { | ||
210 | case 0: | ||
211 | nasid == -1 ? HUB_S((u64 *)LOCAL_MMR_ADDR(SH_RTC1_INT_ENABLE), | ||
212 | 0UL) : REMOTE_HUB_S(nasid, SH_RTC1_INT_ENABLE, 0UL); | ||
213 | break; | ||
214 | case 1: | ||
215 | nasid == -1 ? HUB_S((u64 *)LOCAL_MMR_ADDR(SH_RTC2_INT_ENABLE), | ||
216 | 0UL) : REMOTE_HUB_S(nasid, SH_RTC2_INT_ENABLE, 0UL); | ||
217 | break; | ||
218 | case 2: | ||
219 | nasid == -1 ? HUB_S((u64 *)LOCAL_MMR_ADDR(SH_RTC3_INT_ENABLE), | ||
220 | 0UL) : REMOTE_HUB_S(nasid, SH_RTC3_INT_ENABLE, 0UL); | ||
221 | break; | ||
222 | default: | ||
223 | return -EFAULT; | ||
224 | } | ||
225 | return 0; | ||
226 | } | ||
227 | |||
228 | #define COMPARATOR 1 /* The comparator to use */ | ||
229 | |||
230 | #define TIMER_OFF 0xbadcabLL /* Timer is not setup */ | ||
231 | #define TIMER_SET 0 /* Comparator is set for this timer */ | ||
232 | |||
233 | #define MMTIMER_INTERVAL_RETRY_INCREMENT_DEFAULT 40 | ||
234 | |||
235 | /* There is one of these for each timer */ | ||
236 | struct mmtimer { | ||
237 | struct rb_node list; | ||
238 | struct k_itimer *timer; | ||
239 | int cpu; | ||
240 | }; | ||
241 | |||
242 | struct mmtimer_node { | ||
243 | spinlock_t lock ____cacheline_aligned; | ||
244 | struct rb_root timer_head; | ||
245 | struct rb_node *next; | ||
246 | struct tasklet_struct tasklet; | ||
247 | }; | ||
248 | static struct mmtimer_node *timers; | ||
249 | |||
250 | static unsigned mmtimer_interval_retry_increment = | ||
251 | MMTIMER_INTERVAL_RETRY_INCREMENT_DEFAULT; | ||
252 | module_param(mmtimer_interval_retry_increment, uint, 0644); | ||
253 | MODULE_PARM_DESC(mmtimer_interval_retry_increment, | ||
254 | "RTC ticks to add to expiration on interval retry (default 40)"); | ||
255 | |||
256 | /* | ||
257 | * Add a new mmtimer struct to the node's mmtimer list. | ||
258 | * This function assumes the struct mmtimer_node is locked. | ||
259 | */ | ||
260 | static void mmtimer_add_list(struct mmtimer *n) | ||
261 | { | ||
262 | int nodeid = n->timer->it.mmtimer.node; | ||
263 | unsigned long expires = n->timer->it.mmtimer.expires; | ||
264 | struct rb_node **link = &timers[nodeid].timer_head.rb_node; | ||
265 | struct rb_node *parent = NULL; | ||
266 | struct mmtimer *x; | ||
267 | |||
268 | /* | ||
269 | * Find the right place in the rbtree: | ||
270 | */ | ||
271 | while (*link) { | ||
272 | parent = *link; | ||
273 | x = rb_entry(parent, struct mmtimer, list); | ||
274 | |||
275 | if (expires < x->timer->it.mmtimer.expires) | ||
276 | link = &(*link)->rb_left; | ||
277 | else | ||
278 | link = &(*link)->rb_right; | ||
279 | } | ||
280 | |||
281 | /* | ||
282 | * Insert the timer to the rbtree and check whether it | ||
283 | * replaces the first pending timer | ||
284 | */ | ||
285 | rb_link_node(&n->list, parent, link); | ||
286 | rb_insert_color(&n->list, &timers[nodeid].timer_head); | ||
287 | |||
288 | if (!timers[nodeid].next || expires < rb_entry(timers[nodeid].next, | ||
289 | struct mmtimer, list)->timer->it.mmtimer.expires) | ||
290 | timers[nodeid].next = &n->list; | ||
291 | } | ||
292 | |||
293 | /* | ||
294 | * Set the comparator for the next timer. | ||
295 | * This function assumes the struct mmtimer_node is locked. | ||
296 | */ | ||
297 | static void mmtimer_set_next_timer(int nodeid) | ||
298 | { | ||
299 | struct mmtimer_node *n = &timers[nodeid]; | ||
300 | struct mmtimer *x; | ||
301 | struct k_itimer *t; | ||
302 | u64 expires, exp, set_completion_time; | ||
303 | int i; | ||
304 | |||
305 | restart: | ||
306 | if (n->next == NULL) | ||
307 | return; | ||
308 | |||
309 | x = rb_entry(n->next, struct mmtimer, list); | ||
310 | t = x->timer; | ||
311 | if (!t->it.mmtimer.incr) { | ||
312 | /* Not an interval timer */ | ||
313 | if (!mmtimer_setup(x->cpu, COMPARATOR, | ||
314 | t->it.mmtimer.expires, | ||
315 | &set_completion_time)) { | ||
316 | /* Late setup, fire now */ | ||
317 | tasklet_schedule(&n->tasklet); | ||
318 | } | ||
319 | return; | ||
320 | } | ||
321 | |||
322 | /* Interval timer */ | ||
323 | i = 0; | ||
324 | expires = exp = t->it.mmtimer.expires; | ||
325 | while (!mmtimer_setup(x->cpu, COMPARATOR, expires, | ||
326 | &set_completion_time)) { | ||
327 | int to; | ||
328 | |||
329 | i++; | ||
330 | expires = set_completion_time + | ||
331 | mmtimer_interval_retry_increment + (1 << i); | ||
332 | /* Calculate overruns as we go. */ | ||
333 | to = ((u64)(expires - exp) / t->it.mmtimer.incr); | ||
334 | if (to) { | ||
335 | t->it_overrun += to; | ||
336 | t->it.mmtimer.expires += t->it.mmtimer.incr * to; | ||
337 | exp = t->it.mmtimer.expires; | ||
338 | } | ||
339 | if (i > 20) { | ||
340 | printk(KERN_ALERT "mmtimer: cannot reschedule timer\n"); | ||
341 | t->it.mmtimer.clock = TIMER_OFF; | ||
342 | n->next = rb_next(&x->list); | ||
343 | rb_erase(&x->list, &n->timer_head); | ||
344 | kfree(x); | ||
345 | goto restart; | ||
346 | } | ||
347 | } | ||
348 | } | ||
349 | |||
350 | /** | ||
351 | * mmtimer_ioctl - ioctl interface for /dev/mmtimer | ||
352 | * @file: file structure for the device | ||
353 | * @cmd: command to execute | ||
354 | * @arg: optional argument to command | ||
355 | * | ||
356 | * Executes the command specified by @cmd. Returns 0 for success, < 0 for | ||
357 | * failure. | ||
358 | * | ||
359 | * Valid commands: | ||
360 | * | ||
361 | * %MMTIMER_GETOFFSET - Should return the offset (relative to the start | ||
362 | * of the page where the registers are mapped) for the counter in question. | ||
363 | * | ||
364 | * %MMTIMER_GETRES - Returns the resolution of the clock in femto (10^-15) | ||
365 | * seconds | ||
366 | * | ||
367 | * %MMTIMER_GETFREQ - Copies the frequency of the clock in Hz to the address | ||
368 | * specified by @arg | ||
369 | * | ||
370 | * %MMTIMER_GETBITS - Returns the number of bits in the clock's counter | ||
371 | * | ||
372 | * %MMTIMER_MMAPAVAIL - Returns 1 if the registers can be mmap'd into userspace | ||
373 | * | ||
374 | * %MMTIMER_GETCOUNTER - Gets the current value in the counter and places it | ||
375 | * in the address specified by @arg. | ||
376 | */ | ||
377 | static long mmtimer_ioctl(struct file *file, unsigned int cmd, | ||
378 | unsigned long arg) | ||
379 | { | ||
380 | int ret = 0; | ||
381 | |||
382 | mutex_lock(&mmtimer_mutex); | ||
383 | |||
384 | switch (cmd) { | ||
385 | case MMTIMER_GETOFFSET: /* offset of the counter */ | ||
386 | /* | ||
387 | * SN RTC registers are on their own 64k page | ||
388 | */ | ||
389 | if(PAGE_SIZE <= (1 << 16)) | ||
390 | ret = (((long)RTC_COUNTER_ADDR) & (PAGE_SIZE-1)) / 8; | ||
391 | else | ||
392 | ret = -ENOSYS; | ||
393 | break; | ||
394 | |||
395 | case MMTIMER_GETRES: /* resolution of the clock in 10^-15 s */ | ||
396 | if(copy_to_user((unsigned long __user *)arg, | ||
397 | &mmtimer_femtoperiod, sizeof(unsigned long))) | ||
398 | ret = -EFAULT; | ||
399 | break; | ||
400 | |||
401 | case MMTIMER_GETFREQ: /* frequency in Hz */ | ||
402 | if(copy_to_user((unsigned long __user *)arg, | ||
403 | &sn_rtc_cycles_per_second, | ||
404 | sizeof(unsigned long))) | ||
405 | ret = -EFAULT; | ||
406 | break; | ||
407 | |||
408 | case MMTIMER_GETBITS: /* number of bits in the clock */ | ||
409 | ret = RTC_BITS; | ||
410 | break; | ||
411 | |||
412 | case MMTIMER_MMAPAVAIL: /* can we mmap the clock into userspace? */ | ||
413 | ret = (PAGE_SIZE <= (1 << 16)) ? 1 : 0; | ||
414 | break; | ||
415 | |||
416 | case MMTIMER_GETCOUNTER: | ||
417 | if(copy_to_user((unsigned long __user *)arg, | ||
418 | RTC_COUNTER_ADDR, sizeof(unsigned long))) | ||
419 | ret = -EFAULT; | ||
420 | break; | ||
421 | default: | ||
422 | ret = -ENOTTY; | ||
423 | break; | ||
424 | } | ||
425 | mutex_unlock(&mmtimer_mutex); | ||
426 | return ret; | ||
427 | } | ||
428 | |||
429 | /** | ||
430 | * mmtimer_mmap - maps the clock's registers into userspace | ||
431 | * @file: file structure for the device | ||
432 | * @vma: VMA to map the registers into | ||
433 | * | ||
434 | * Calls remap_pfn_range() to map the clock's registers into | ||
435 | * the calling process' address space. | ||
436 | */ | ||
437 | static int mmtimer_mmap(struct file *file, struct vm_area_struct *vma) | ||
438 | { | ||
439 | unsigned long mmtimer_addr; | ||
440 | |||
441 | if (vma->vm_end - vma->vm_start != PAGE_SIZE) | ||
442 | return -EINVAL; | ||
443 | |||
444 | if (vma->vm_flags & VM_WRITE) | ||
445 | return -EPERM; | ||
446 | |||
447 | if (PAGE_SIZE > (1 << 16)) | ||
448 | return -ENOSYS; | ||
449 | |||
450 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); | ||
451 | |||
452 | mmtimer_addr = __pa(RTC_COUNTER_ADDR); | ||
453 | mmtimer_addr &= ~(PAGE_SIZE - 1); | ||
454 | mmtimer_addr &= 0xfffffffffffffffUL; | ||
455 | |||
456 | if (remap_pfn_range(vma, vma->vm_start, mmtimer_addr >> PAGE_SHIFT, | ||
457 | PAGE_SIZE, vma->vm_page_prot)) { | ||
458 | printk(KERN_ERR "remap_pfn_range failed in mmtimer.c\n"); | ||
459 | return -EAGAIN; | ||
460 | } | ||
461 | |||
462 | return 0; | ||
463 | } | ||
464 | |||
465 | static struct miscdevice mmtimer_miscdev = { | ||
466 | .minor = SGI_MMTIMER, | ||
467 | .name = MMTIMER_NAME, | ||
468 | .fops = &mmtimer_fops | ||
469 | }; | ||
470 | |||
471 | static struct timespec sgi_clock_offset; | ||
472 | static int sgi_clock_period; | ||
473 | |||
474 | /* | ||
475 | * Posix Timer Interface | ||
476 | */ | ||
477 | |||
478 | static struct timespec sgi_clock_offset; | ||
479 | static int sgi_clock_period; | ||
480 | |||
481 | static int sgi_clock_get(clockid_t clockid, struct timespec64 *tp) | ||
482 | { | ||
483 | u64 nsec; | ||
484 | |||
485 | nsec = rtc_time() * sgi_clock_period | ||
486 | + sgi_clock_offset.tv_nsec; | ||
487 | *tp = ns_to_timespec64(nsec); | ||
488 | tp->tv_sec += sgi_clock_offset.tv_sec; | ||
489 | return 0; | ||
490 | }; | ||
491 | |||
492 | static int sgi_clock_set(const clockid_t clockid, const struct timespec64 *tp) | ||
493 | { | ||
494 | |||
495 | u64 nsec; | ||
496 | u32 rem; | ||
497 | |||
498 | nsec = rtc_time() * sgi_clock_period; | ||
499 | |||
500 | sgi_clock_offset.tv_sec = tp->tv_sec - div_u64_rem(nsec, NSEC_PER_SEC, &rem); | ||
501 | |||
502 | if (rem <= tp->tv_nsec) | ||
503 | sgi_clock_offset.tv_nsec = tp->tv_sec - rem; | ||
504 | else { | ||
505 | sgi_clock_offset.tv_nsec = tp->tv_sec + NSEC_PER_SEC - rem; | ||
506 | sgi_clock_offset.tv_sec--; | ||
507 | } | ||
508 | return 0; | ||
509 | } | ||
510 | |||
511 | /** | ||
512 | * mmtimer_interrupt - timer interrupt handler | ||
513 | * @irq: irq received | ||
514 | * @dev_id: device the irq came from | ||
515 | * | ||
516 | * Called when one of the comarators matches the counter, This | ||
517 | * routine will send signals to processes that have requested | ||
518 | * them. | ||
519 | * | ||
520 | * This interrupt is run in an interrupt context | ||
521 | * by the SHUB. It is therefore safe to locally access SHub | ||
522 | * registers. | ||
523 | */ | ||
524 | static irqreturn_t | ||
525 | mmtimer_interrupt(int irq, void *dev_id) | ||
526 | { | ||
527 | unsigned long expires = 0; | ||
528 | int result = IRQ_NONE; | ||
529 | unsigned indx = cpu_to_node(smp_processor_id()); | ||
530 | struct mmtimer *base; | ||
531 | |||
532 | spin_lock(&timers[indx].lock); | ||
533 | base = rb_entry(timers[indx].next, struct mmtimer, list); | ||
534 | if (base == NULL) { | ||
535 | spin_unlock(&timers[indx].lock); | ||
536 | return result; | ||
537 | } | ||
538 | |||
539 | if (base->cpu == smp_processor_id()) { | ||
540 | if (base->timer) | ||
541 | expires = base->timer->it.mmtimer.expires; | ||
542 | /* expires test won't work with shared irqs */ | ||
543 | if ((mmtimer_int_pending(COMPARATOR) > 0) || | ||
544 | (expires && (expires <= rtc_time()))) { | ||
545 | mmtimer_clr_int_pending(COMPARATOR); | ||
546 | tasklet_schedule(&timers[indx].tasklet); | ||
547 | result = IRQ_HANDLED; | ||
548 | } | ||
549 | } | ||
550 | spin_unlock(&timers[indx].lock); | ||
551 | return result; | ||
552 | } | ||
553 | |||
554 | static void mmtimer_tasklet(unsigned long data) | ||
555 | { | ||
556 | int nodeid = data; | ||
557 | struct mmtimer_node *mn = &timers[nodeid]; | ||
558 | struct mmtimer *x; | ||
559 | struct k_itimer *t; | ||
560 | unsigned long flags; | ||
561 | |||
562 | /* Send signal and deal with periodic signals */ | ||
563 | spin_lock_irqsave(&mn->lock, flags); | ||
564 | if (!mn->next) | ||
565 | goto out; | ||
566 | |||
567 | x = rb_entry(mn->next, struct mmtimer, list); | ||
568 | t = x->timer; | ||
569 | |||
570 | if (t->it.mmtimer.clock == TIMER_OFF) | ||
571 | goto out; | ||
572 | |||
573 | t->it_overrun = 0; | ||
574 | |||
575 | mn->next = rb_next(&x->list); | ||
576 | rb_erase(&x->list, &mn->timer_head); | ||
577 | |||
578 | if (posix_timer_event(t, 0) != 0) | ||
579 | t->it_overrun++; | ||
580 | |||
581 | if(t->it.mmtimer.incr) { | ||
582 | t->it.mmtimer.expires += t->it.mmtimer.incr; | ||
583 | mmtimer_add_list(x); | ||
584 | } else { | ||
585 | /* Ensure we don't false trigger in mmtimer_interrupt */ | ||
586 | t->it.mmtimer.clock = TIMER_OFF; | ||
587 | t->it.mmtimer.expires = 0; | ||
588 | kfree(x); | ||
589 | } | ||
590 | /* Set comparator for next timer, if there is one */ | ||
591 | mmtimer_set_next_timer(nodeid); | ||
592 | |||
593 | t->it_overrun_last = t->it_overrun; | ||
594 | out: | ||
595 | spin_unlock_irqrestore(&mn->lock, flags); | ||
596 | } | ||
597 | |||
598 | static int sgi_timer_create(struct k_itimer *timer) | ||
599 | { | ||
600 | /* Insure that a newly created timer is off */ | ||
601 | timer->it.mmtimer.clock = TIMER_OFF; | ||
602 | return 0; | ||
603 | } | ||
604 | |||
605 | /* This does not really delete a timer. It just insures | ||
606 | * that the timer is not active | ||
607 | * | ||
608 | * Assumption: it_lock is already held with irq's disabled | ||
609 | */ | ||
610 | static int sgi_timer_del(struct k_itimer *timr) | ||
611 | { | ||
612 | cnodeid_t nodeid = timr->it.mmtimer.node; | ||
613 | unsigned long irqflags; | ||
614 | |||
615 | spin_lock_irqsave(&timers[nodeid].lock, irqflags); | ||
616 | if (timr->it.mmtimer.clock != TIMER_OFF) { | ||
617 | unsigned long expires = timr->it.mmtimer.expires; | ||
618 | struct rb_node *n = timers[nodeid].timer_head.rb_node; | ||
619 | struct mmtimer *uninitialized_var(t); | ||
620 | int r = 0; | ||
621 | |||
622 | timr->it.mmtimer.clock = TIMER_OFF; | ||
623 | timr->it.mmtimer.expires = 0; | ||
624 | |||
625 | while (n) { | ||
626 | t = rb_entry(n, struct mmtimer, list); | ||
627 | if (t->timer == timr) | ||
628 | break; | ||
629 | |||
630 | if (expires < t->timer->it.mmtimer.expires) | ||
631 | n = n->rb_left; | ||
632 | else | ||
633 | n = n->rb_right; | ||
634 | } | ||
635 | |||
636 | if (!n) { | ||
637 | spin_unlock_irqrestore(&timers[nodeid].lock, irqflags); | ||
638 | return 0; | ||
639 | } | ||
640 | |||
641 | if (timers[nodeid].next == n) { | ||
642 | timers[nodeid].next = rb_next(n); | ||
643 | r = 1; | ||
644 | } | ||
645 | |||
646 | rb_erase(n, &timers[nodeid].timer_head); | ||
647 | kfree(t); | ||
648 | |||
649 | if (r) { | ||
650 | mmtimer_disable_int(cnodeid_to_nasid(nodeid), | ||
651 | COMPARATOR); | ||
652 | mmtimer_set_next_timer(nodeid); | ||
653 | } | ||
654 | } | ||
655 | spin_unlock_irqrestore(&timers[nodeid].lock, irqflags); | ||
656 | return 0; | ||
657 | } | ||
658 | |||
659 | /* Assumption: it_lock is already held with irq's disabled */ | ||
660 | static void sgi_timer_get(struct k_itimer *timr, struct itimerspec64 *cur_setting) | ||
661 | { | ||
662 | |||
663 | if (timr->it.mmtimer.clock == TIMER_OFF) { | ||
664 | cur_setting->it_interval.tv_nsec = 0; | ||
665 | cur_setting->it_interval.tv_sec = 0; | ||
666 | cur_setting->it_value.tv_nsec = 0; | ||
667 | cur_setting->it_value.tv_sec =0; | ||
668 | return; | ||
669 | } | ||
670 | |||
671 | cur_setting->it_interval = ns_to_timespec64(timr->it.mmtimer.incr * sgi_clock_period); | ||
672 | cur_setting->it_value = ns_to_timespec64((timr->it.mmtimer.expires - rtc_time()) * sgi_clock_period); | ||
673 | } | ||
674 | |||
675 | |||
676 | static int sgi_timer_set(struct k_itimer *timr, int flags, | ||
677 | struct itimerspec64 *new_setting, | ||
678 | struct itimerspec64 *old_setting) | ||
679 | { | ||
680 | unsigned long when, period, irqflags; | ||
681 | int err = 0; | ||
682 | cnodeid_t nodeid; | ||
683 | struct mmtimer *base; | ||
684 | struct rb_node *n; | ||
685 | |||
686 | if (old_setting) | ||
687 | sgi_timer_get(timr, old_setting); | ||
688 | |||
689 | sgi_timer_del(timr); | ||
690 | when = timespec64_to_ns(&new_setting->it_value); | ||
691 | period = timespec64_to_ns(&new_setting->it_interval); | ||
692 | |||
693 | if (when == 0) | ||
694 | /* Clear timer */ | ||
695 | return 0; | ||
696 | |||
697 | base = kmalloc(sizeof(struct mmtimer), GFP_KERNEL); | ||
698 | if (base == NULL) | ||
699 | return -ENOMEM; | ||
700 | |||
701 | if (flags & TIMER_ABSTIME) { | ||
702 | struct timespec64 n; | ||
703 | unsigned long now; | ||
704 | |||
705 | getnstimeofday64(&n); | ||
706 | now = timespec64_to_ns(&n); | ||
707 | if (when > now) | ||
708 | when -= now; | ||
709 | else | ||
710 | /* Fire the timer immediately */ | ||
711 | when = 0; | ||
712 | } | ||
713 | |||
714 | /* | ||
715 | * Convert to sgi clock period. Need to keep rtc_time() as near as possible | ||
716 | * to getnstimeofday() in order to be as faithful as possible to the time | ||
717 | * specified. | ||
718 | */ | ||
719 | when = (when + sgi_clock_period - 1) / sgi_clock_period + rtc_time(); | ||
720 | period = (period + sgi_clock_period - 1) / sgi_clock_period; | ||
721 | |||
722 | /* | ||
723 | * We are allocating a local SHub comparator. If we would be moved to another | ||
724 | * cpu then another SHub may be local to us. Prohibit that by switching off | ||
725 | * preemption. | ||
726 | */ | ||
727 | preempt_disable(); | ||
728 | |||
729 | nodeid = cpu_to_node(smp_processor_id()); | ||
730 | |||
731 | /* Lock the node timer structure */ | ||
732 | spin_lock_irqsave(&timers[nodeid].lock, irqflags); | ||
733 | |||
734 | base->timer = timr; | ||
735 | base->cpu = smp_processor_id(); | ||
736 | |||
737 | timr->it.mmtimer.clock = TIMER_SET; | ||
738 | timr->it.mmtimer.node = nodeid; | ||
739 | timr->it.mmtimer.incr = period; | ||
740 | timr->it.mmtimer.expires = when; | ||
741 | |||
742 | n = timers[nodeid].next; | ||
743 | |||
744 | /* Add the new struct mmtimer to node's timer list */ | ||
745 | mmtimer_add_list(base); | ||
746 | |||
747 | if (timers[nodeid].next == n) { | ||
748 | /* No need to reprogram comparator for now */ | ||
749 | spin_unlock_irqrestore(&timers[nodeid].lock, irqflags); | ||
750 | preempt_enable(); | ||
751 | return err; | ||
752 | } | ||
753 | |||
754 | /* We need to reprogram the comparator */ | ||
755 | if (n) | ||
756 | mmtimer_disable_int(cnodeid_to_nasid(nodeid), COMPARATOR); | ||
757 | |||
758 | mmtimer_set_next_timer(nodeid); | ||
759 | |||
760 | /* Unlock the node timer structure */ | ||
761 | spin_unlock_irqrestore(&timers[nodeid].lock, irqflags); | ||
762 | |||
763 | preempt_enable(); | ||
764 | |||
765 | return err; | ||
766 | } | ||
767 | |||
768 | static int sgi_clock_getres(const clockid_t which_clock, struct timespec64 *tp) | ||
769 | { | ||
770 | tp->tv_sec = 0; | ||
771 | tp->tv_nsec = sgi_clock_period; | ||
772 | return 0; | ||
773 | } | ||
774 | |||
775 | static struct k_clock sgi_clock = { | ||
776 | .clock_set = sgi_clock_set, | ||
777 | .clock_get = sgi_clock_get, | ||
778 | .clock_getres = sgi_clock_getres, | ||
779 | .timer_create = sgi_timer_create, | ||
780 | .timer_set = sgi_timer_set, | ||
781 | .timer_del = sgi_timer_del, | ||
782 | .timer_get = sgi_timer_get | ||
783 | }; | ||
784 | |||
785 | /** | ||
786 | * mmtimer_init - device initialization routine | ||
787 | * | ||
788 | * Does initial setup for the mmtimer device. | ||
789 | */ | ||
790 | static int __init mmtimer_init(void) | ||
791 | { | ||
792 | cnodeid_t node, maxn = -1; | ||
793 | |||
794 | if (!ia64_platform_is("sn2")) | ||
795 | return 0; | ||
796 | |||
797 | /* | ||
798 | * Sanity check the cycles/sec variable | ||
799 | */ | ||
800 | if (sn_rtc_cycles_per_second < 100000) { | ||
801 | printk(KERN_ERR "%s: unable to determine clock frequency\n", | ||
802 | MMTIMER_NAME); | ||
803 | goto out1; | ||
804 | } | ||
805 | |||
806 | mmtimer_femtoperiod = ((unsigned long)1E15 + sn_rtc_cycles_per_second / | ||
807 | 2) / sn_rtc_cycles_per_second; | ||
808 | |||
809 | if (request_irq(SGI_MMTIMER_VECTOR, mmtimer_interrupt, IRQF_PERCPU, MMTIMER_NAME, NULL)) { | ||
810 | printk(KERN_WARNING "%s: unable to allocate interrupt.", | ||
811 | MMTIMER_NAME); | ||
812 | goto out1; | ||
813 | } | ||
814 | |||
815 | if (misc_register(&mmtimer_miscdev)) { | ||
816 | printk(KERN_ERR "%s: failed to register device\n", | ||
817 | MMTIMER_NAME); | ||
818 | goto out2; | ||
819 | } | ||
820 | |||
821 | /* Get max numbered node, calculate slots needed */ | ||
822 | for_each_online_node(node) { | ||
823 | maxn = node; | ||
824 | } | ||
825 | maxn++; | ||
826 | |||
827 | /* Allocate list of node ptrs to mmtimer_t's */ | ||
828 | timers = kzalloc(sizeof(struct mmtimer_node)*maxn, GFP_KERNEL); | ||
829 | if (!timers) { | ||
830 | printk(KERN_ERR "%s: failed to allocate memory for device\n", | ||
831 | MMTIMER_NAME); | ||
832 | goto out3; | ||
833 | } | ||
834 | |||
835 | /* Initialize struct mmtimer's for each online node */ | ||
836 | for_each_online_node(node) { | ||
837 | spin_lock_init(&timers[node].lock); | ||
838 | tasklet_init(&timers[node].tasklet, mmtimer_tasklet, | ||
839 | (unsigned long) node); | ||
840 | } | ||
841 | |||
842 | sgi_clock_period = NSEC_PER_SEC / sn_rtc_cycles_per_second; | ||
843 | posix_timers_register_clock(CLOCK_SGI_CYCLE, &sgi_clock); | ||
844 | |||
845 | printk(KERN_INFO "%s: v%s, %ld MHz\n", MMTIMER_DESC, MMTIMER_VERSION, | ||
846 | sn_rtc_cycles_per_second/(unsigned long)1E6); | ||
847 | |||
848 | return 0; | ||
849 | |||
850 | out3: | ||
851 | misc_deregister(&mmtimer_miscdev); | ||
852 | out2: | ||
853 | free_irq(SGI_MMTIMER_VECTOR, NULL); | ||
854 | out1: | ||
855 | return -1; | ||
856 | } | ||
857 | |||
858 | module_init(mmtimer_init); | ||
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig index 545d541ae20e..88818a43d6e9 100644 --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig | |||
@@ -1,22 +1,16 @@ | |||
1 | menu "Clock Source drivers" | 1 | menu "Clock Source drivers" |
2 | depends on !ARCH_USES_GETTIMEOFFSET | 2 | depends on !ARCH_USES_GETTIMEOFFSET |
3 | 3 | ||
4 | config CLKSRC_OF | 4 | config TIMER_OF |
5 | bool | 5 | bool |
6 | select CLKSRC_PROBE | 6 | depends on GENERIC_CLOCKEVENTS |
7 | 7 | select TIMER_PROBE | |
8 | config CLKEVT_OF | ||
9 | bool | ||
10 | select CLKEVT_PROBE | ||
11 | |||
12 | config CLKSRC_ACPI | ||
13 | bool | ||
14 | select CLKSRC_PROBE | ||
15 | 8 | ||
16 | config CLKSRC_PROBE | 9 | config TIMER_ACPI |
17 | bool | 10 | bool |
11 | select TIMER_PROBE | ||
18 | 12 | ||
19 | config CLKEVT_PROBE | 13 | config TIMER_PROBE |
20 | bool | 14 | bool |
21 | 15 | ||
22 | config CLKSRC_I8253 | 16 | config CLKSRC_I8253 |
@@ -65,14 +59,14 @@ config DW_APB_TIMER | |||
65 | config DW_APB_TIMER_OF | 59 | config DW_APB_TIMER_OF |
66 | bool | 60 | bool |
67 | select DW_APB_TIMER | 61 | select DW_APB_TIMER |
68 | select CLKSRC_OF | 62 | select TIMER_OF |
69 | 63 | ||
70 | config FTTMR010_TIMER | 64 | config FTTMR010_TIMER |
71 | bool "Faraday Technology timer driver" if COMPILE_TEST | 65 | bool "Faraday Technology timer driver" if COMPILE_TEST |
72 | depends on GENERIC_CLOCKEVENTS | 66 | depends on GENERIC_CLOCKEVENTS |
73 | depends on HAS_IOMEM | 67 | depends on HAS_IOMEM |
74 | select CLKSRC_MMIO | 68 | select CLKSRC_MMIO |
75 | select CLKSRC_OF | 69 | select TIMER_OF |
76 | select MFD_SYSCON | 70 | select MFD_SYSCON |
77 | help | 71 | help |
78 | Enables support for the Faraday Technology timer block | 72 | Enables support for the Faraday Technology timer block |
@@ -81,7 +75,7 @@ config FTTMR010_TIMER | |||
81 | config ROCKCHIP_TIMER | 75 | config ROCKCHIP_TIMER |
82 | bool "Rockchip timer driver" if COMPILE_TEST | 76 | bool "Rockchip timer driver" if COMPILE_TEST |
83 | depends on ARM || ARM64 | 77 | depends on ARM || ARM64 |
84 | select CLKSRC_OF | 78 | select TIMER_OF |
85 | select CLKSRC_MMIO | 79 | select CLKSRC_MMIO |
86 | help | 80 | help |
87 | Enables the support for the rockchip timer driver. | 81 | Enables the support for the rockchip timer driver. |
@@ -89,7 +83,7 @@ config ROCKCHIP_TIMER | |||
89 | config ARMADA_370_XP_TIMER | 83 | config ARMADA_370_XP_TIMER |
90 | bool "Armada 370 and XP timer driver" if COMPILE_TEST | 84 | bool "Armada 370 and XP timer driver" if COMPILE_TEST |
91 | depends on ARM | 85 | depends on ARM |
92 | select CLKSRC_OF | 86 | select TIMER_OF |
93 | select CLKSRC_MMIO | 87 | select CLKSRC_MMIO |
94 | help | 88 | help |
95 | Enables the support for the Armada 370 and XP timer driver. | 89 | Enables the support for the Armada 370 and XP timer driver. |
@@ -104,7 +98,7 @@ config MESON6_TIMER | |||
104 | config ORION_TIMER | 98 | config ORION_TIMER |
105 | bool "Orion timer driver" if COMPILE_TEST | 99 | bool "Orion timer driver" if COMPILE_TEST |
106 | depends on ARM | 100 | depends on ARM |
107 | select CLKSRC_OF | 101 | select TIMER_OF |
108 | select CLKSRC_MMIO | 102 | select CLKSRC_MMIO |
109 | help | 103 | help |
110 | Enables the support for the Orion timer driver | 104 | Enables the support for the Orion timer driver |
@@ -114,6 +108,7 @@ config SUN4I_TIMER | |||
114 | depends on GENERIC_CLOCKEVENTS | 108 | depends on GENERIC_CLOCKEVENTS |
115 | depends on HAS_IOMEM | 109 | depends on HAS_IOMEM |
116 | select CLKSRC_MMIO | 110 | select CLKSRC_MMIO |
111 | select TIMER_OF | ||
117 | help | 112 | help |
118 | Enables support for the Sun4i timer. | 113 | Enables support for the Sun4i timer. |
119 | 114 | ||
@@ -148,7 +143,7 @@ config ASM9260_TIMER | |||
148 | bool "ASM9260 timer driver" if COMPILE_TEST | 143 | bool "ASM9260 timer driver" if COMPILE_TEST |
149 | depends on GENERIC_CLOCKEVENTS | 144 | depends on GENERIC_CLOCKEVENTS |
150 | select CLKSRC_MMIO | 145 | select CLKSRC_MMIO |
151 | select CLKSRC_OF | 146 | select TIMER_OF |
152 | help | 147 | help |
153 | Enables support for the ASM9260 timer. | 148 | Enables support for the ASM9260 timer. |
154 | 149 | ||
@@ -188,13 +183,6 @@ config ATLAS7_TIMER | |||
188 | help | 183 | help |
189 | Enables support for the Atlas7 timer. | 184 | Enables support for the Atlas7 timer. |
190 | 185 | ||
191 | config MOXART_TIMER | ||
192 | bool "Moxart timer driver" if COMPILE_TEST | ||
193 | depends on GENERIC_CLOCKEVENTS | ||
194 | select CLKSRC_MMIO | ||
195 | help | ||
196 | Enables support for the Moxart timer. | ||
197 | |||
198 | config MXS_TIMER | 186 | config MXS_TIMER |
199 | bool "Mxs timer driver" if COMPILE_TEST | 187 | bool "Mxs timer driver" if COMPILE_TEST |
200 | depends on GENERIC_CLOCKEVENTS | 188 | depends on GENERIC_CLOCKEVENTS |
@@ -261,21 +249,21 @@ config CLKSRC_LPC32XX | |||
261 | depends on GENERIC_CLOCKEVENTS && HAS_IOMEM | 249 | depends on GENERIC_CLOCKEVENTS && HAS_IOMEM |
262 | depends on ARM | 250 | depends on ARM |
263 | select CLKSRC_MMIO | 251 | select CLKSRC_MMIO |
264 | select CLKSRC_OF | 252 | select TIMER_OF |
265 | help | 253 | help |
266 | Support for the LPC32XX clocksource. | 254 | Support for the LPC32XX clocksource. |
267 | 255 | ||
268 | config CLKSRC_PISTACHIO | 256 | config CLKSRC_PISTACHIO |
269 | bool "Clocksource for Pistachio SoC" if COMPILE_TEST | 257 | bool "Clocksource for Pistachio SoC" if COMPILE_TEST |
270 | depends on HAS_IOMEM | 258 | depends on HAS_IOMEM |
271 | select CLKSRC_OF | 259 | select TIMER_OF |
272 | help | 260 | help |
273 | Enables the clocksource for the Pistachio SoC. | 261 | Enables the clocksource for the Pistachio SoC. |
274 | 262 | ||
275 | config CLKSRC_TI_32K | 263 | config CLKSRC_TI_32K |
276 | bool "Texas Instruments 32.768 Hz Clocksource" if COMPILE_TEST | 264 | bool "Texas Instruments 32.768 Hz Clocksource" if COMPILE_TEST |
277 | depends on GENERIC_SCHED_CLOCK | 265 | depends on GENERIC_SCHED_CLOCK |
278 | select CLKSRC_OF if OF | 266 | select TIMER_OF if OF |
279 | help | 267 | help |
280 | This option enables support for Texas Instruments 32.768 Hz clocksource | 268 | This option enables support for Texas Instruments 32.768 Hz clocksource |
281 | available on many OMAP-like platforms. | 269 | available on many OMAP-like platforms. |
@@ -284,7 +272,7 @@ config CLKSRC_NPS | |||
284 | bool "NPS400 clocksource driver" if COMPILE_TEST | 272 | bool "NPS400 clocksource driver" if COMPILE_TEST |
285 | depends on !PHYS_ADDR_T_64BIT | 273 | depends on !PHYS_ADDR_T_64BIT |
286 | select CLKSRC_MMIO | 274 | select CLKSRC_MMIO |
287 | select CLKSRC_OF if OF | 275 | select TIMER_OF if OF |
288 | help | 276 | help |
289 | NPS400 clocksource support. | 277 | NPS400 clocksource support. |
290 | Got 64 bit counter with update rate up to 1000MHz. | 278 | Got 64 bit counter with update rate up to 1000MHz. |
@@ -299,12 +287,12 @@ config CLKSRC_MPS2 | |||
299 | bool "Clocksource for MPS2 SoCs" if COMPILE_TEST | 287 | bool "Clocksource for MPS2 SoCs" if COMPILE_TEST |
300 | depends on GENERIC_SCHED_CLOCK | 288 | depends on GENERIC_SCHED_CLOCK |
301 | select CLKSRC_MMIO | 289 | select CLKSRC_MMIO |
302 | select CLKSRC_OF | 290 | select TIMER_OF |
303 | 291 | ||
304 | config ARC_TIMERS | 292 | config ARC_TIMERS |
305 | bool "Support for 32-bit TIMERn counters in ARC Cores" if COMPILE_TEST | 293 | bool "Support for 32-bit TIMERn counters in ARC Cores" if COMPILE_TEST |
306 | depends on GENERIC_CLOCKEVENTS | 294 | depends on GENERIC_CLOCKEVENTS |
307 | select CLKSRC_OF | 295 | select TIMER_OF |
308 | help | 296 | help |
309 | These are legacy 32-bit TIMER0 and TIMER1 counters found on all ARC cores | 297 | These are legacy 32-bit TIMER0 and TIMER1 counters found on all ARC cores |
310 | (ARC700 as well as ARC HS38). | 298 | (ARC700 as well as ARC HS38). |
@@ -314,7 +302,7 @@ config ARC_TIMERS_64BIT | |||
314 | bool "Support for 64-bit counters in ARC HS38 cores" if COMPILE_TEST | 302 | bool "Support for 64-bit counters in ARC HS38 cores" if COMPILE_TEST |
315 | depends on GENERIC_CLOCKEVENTS | 303 | depends on GENERIC_CLOCKEVENTS |
316 | depends on ARC_TIMERS | 304 | depends on ARC_TIMERS |
317 | select CLKSRC_OF | 305 | select TIMER_OF |
318 | help | 306 | help |
319 | This enables 2 different 64-bit timers: RTC (for UP) and GFRC (for SMP) | 307 | This enables 2 different 64-bit timers: RTC (for UP) and GFRC (for SMP) |
320 | RTC is implemented inside the core, while GFRC sits outside the core in | 308 | RTC is implemented inside the core, while GFRC sits outside the core in |
@@ -323,8 +311,8 @@ config ARC_TIMERS_64BIT | |||
323 | 311 | ||
324 | config ARM_ARCH_TIMER | 312 | config ARM_ARCH_TIMER |
325 | bool | 313 | bool |
326 | select CLKSRC_OF if OF | 314 | select TIMER_OF if OF |
327 | select CLKSRC_ACPI if ACPI | 315 | select TIMER_ACPI if ACPI |
328 | 316 | ||
329 | config ARM_ARCH_TIMER_EVTSTREAM | 317 | config ARM_ARCH_TIMER_EVTSTREAM |
330 | bool "Enable ARM architected timer event stream generation by default" | 318 | bool "Enable ARM architected timer event stream generation by default" |
@@ -381,7 +369,7 @@ config ARM64_ERRATUM_858921 | |||
381 | 369 | ||
382 | config ARM_GLOBAL_TIMER | 370 | config ARM_GLOBAL_TIMER |
383 | bool "Support for the ARM global timer" if COMPILE_TEST | 371 | bool "Support for the ARM global timer" if COMPILE_TEST |
384 | select CLKSRC_OF if OF | 372 | select TIMER_OF if OF |
385 | depends on ARM | 373 | depends on ARM |
386 | help | 374 | help |
387 | This options enables support for the ARM global timer unit | 375 | This options enables support for the ARM global timer unit |
@@ -390,7 +378,7 @@ config ARM_TIMER_SP804 | |||
390 | bool "Support for Dual Timer SP804 module" | 378 | bool "Support for Dual Timer SP804 module" |
391 | depends on GENERIC_SCHED_CLOCK && CLKDEV_LOOKUP | 379 | depends on GENERIC_SCHED_CLOCK && CLKDEV_LOOKUP |
392 | select CLKSRC_MMIO | 380 | select CLKSRC_MMIO |
393 | select CLKSRC_OF if OF | 381 | select TIMER_OF if OF |
394 | 382 | ||
395 | config CLKSRC_ARM_GLOBAL_TIMER_SCHED_CLOCK | 383 | config CLKSRC_ARM_GLOBAL_TIMER_SCHED_CLOCK |
396 | bool | 384 | bool |
@@ -401,19 +389,19 @@ config CLKSRC_ARM_GLOBAL_TIMER_SCHED_CLOCK | |||
401 | 389 | ||
402 | config ARMV7M_SYSTICK | 390 | config ARMV7M_SYSTICK |
403 | bool "Support for the ARMv7M system time" if COMPILE_TEST | 391 | bool "Support for the ARMv7M system time" if COMPILE_TEST |
404 | select CLKSRC_OF if OF | 392 | select TIMER_OF if OF |
405 | select CLKSRC_MMIO | 393 | select CLKSRC_MMIO |
406 | help | 394 | help |
407 | This options enables support for the ARMv7M system timer unit | 395 | This options enables support for the ARMv7M system timer unit |
408 | 396 | ||
409 | config ATMEL_PIT | 397 | config ATMEL_PIT |
410 | select CLKSRC_OF if OF | 398 | select TIMER_OF if OF |
411 | def_bool SOC_AT91SAM9 || SOC_SAMA5 | 399 | def_bool SOC_AT91SAM9 || SOC_SAMA5 |
412 | 400 | ||
413 | config ATMEL_ST | 401 | config ATMEL_ST |
414 | bool "Atmel ST timer support" if COMPILE_TEST | 402 | bool "Atmel ST timer support" if COMPILE_TEST |
415 | depends on GENERIC_CLOCKEVENTS | 403 | depends on GENERIC_CLOCKEVENTS |
416 | select CLKSRC_OF | 404 | select TIMER_OF |
417 | select MFD_SYSCON | 405 | select MFD_SYSCON |
418 | help | 406 | help |
419 | Support for the Atmel ST timer. | 407 | Support for the Atmel ST timer. |
@@ -456,7 +444,7 @@ config VF_PIT_TIMER | |||
456 | config OXNAS_RPS_TIMER | 444 | config OXNAS_RPS_TIMER |
457 | bool "Oxford Semiconductor OXNAS RPS Timers driver" if COMPILE_TEST | 445 | bool "Oxford Semiconductor OXNAS RPS Timers driver" if COMPILE_TEST |
458 | depends on GENERIC_CLOCKEVENTS | 446 | depends on GENERIC_CLOCKEVENTS |
459 | select CLKSRC_OF | 447 | select TIMER_OF |
460 | select CLKSRC_MMIO | 448 | select CLKSRC_MMIO |
461 | help | 449 | help |
462 | This enables support for the Oxford Semiconductor OXNAS RPS timers. | 450 | This enables support for the Oxford Semiconductor OXNAS RPS timers. |
@@ -467,7 +455,7 @@ config SYS_SUPPORTS_SH_CMT | |||
467 | config MTK_TIMER | 455 | config MTK_TIMER |
468 | bool "Mediatek timer driver" if COMPILE_TEST | 456 | bool "Mediatek timer driver" if COMPILE_TEST |
469 | depends on GENERIC_CLOCKEVENTS && HAS_IOMEM | 457 | depends on GENERIC_CLOCKEVENTS && HAS_IOMEM |
470 | select CLKSRC_OF | 458 | select TIMER_OF |
471 | select CLKSRC_MMIO | 459 | select CLKSRC_MMIO |
472 | help | 460 | help |
473 | Support for Mediatek timer driver. | 461 | Support for Mediatek timer driver. |
@@ -540,7 +528,7 @@ config EM_TIMER_STI | |||
540 | config CLKSRC_QCOM | 528 | config CLKSRC_QCOM |
541 | bool "Qualcomm MSM timer" if COMPILE_TEST | 529 | bool "Qualcomm MSM timer" if COMPILE_TEST |
542 | depends on ARM | 530 | depends on ARM |
543 | select CLKSRC_OF | 531 | select TIMER_OF |
544 | help | 532 | help |
545 | This enables the clocksource and the per CPU clockevent driver for the | 533 | This enables the clocksource and the per CPU clockevent driver for the |
546 | Qualcomm SoCs. | 534 | Qualcomm SoCs. |
@@ -548,7 +536,7 @@ config CLKSRC_QCOM | |||
548 | config CLKSRC_VERSATILE | 536 | config CLKSRC_VERSATILE |
549 | bool "ARM Versatile (Express) reference platforms clock source" if COMPILE_TEST | 537 | bool "ARM Versatile (Express) reference platforms clock source" if COMPILE_TEST |
550 | depends on GENERIC_SCHED_CLOCK && !ARCH_USES_GETTIMEOFFSET | 538 | depends on GENERIC_SCHED_CLOCK && !ARCH_USES_GETTIMEOFFSET |
551 | select CLKSRC_OF | 539 | select TIMER_OF |
552 | default y if MFD_VEXPRESS_SYSREG | 540 | default y if MFD_VEXPRESS_SYSREG |
553 | help | 541 | help |
554 | This option enables clock source based on free running | 542 | This option enables clock source based on free running |
@@ -559,12 +547,12 @@ config CLKSRC_VERSATILE | |||
559 | config CLKSRC_MIPS_GIC | 547 | config CLKSRC_MIPS_GIC |
560 | bool | 548 | bool |
561 | depends on MIPS_GIC | 549 | depends on MIPS_GIC |
562 | select CLKSRC_OF | 550 | select TIMER_OF |
563 | 551 | ||
564 | config CLKSRC_TANGO_XTAL | 552 | config CLKSRC_TANGO_XTAL |
565 | bool "Clocksource for Tango SoC" if COMPILE_TEST | 553 | bool "Clocksource for Tango SoC" if COMPILE_TEST |
566 | depends on ARM | 554 | depends on ARM |
567 | select CLKSRC_OF | 555 | select TIMER_OF |
568 | select CLKSRC_MMIO | 556 | select CLKSRC_MMIO |
569 | help | 557 | help |
570 | This enables the clocksource for Tango SoC | 558 | This enables the clocksource for Tango SoC |
@@ -605,7 +593,7 @@ config CLKSRC_IMX_GPT | |||
605 | 593 | ||
606 | config CLKSRC_ST_LPC | 594 | config CLKSRC_ST_LPC |
607 | bool "Low power clocksource found in the LPC" if COMPILE_TEST | 595 | bool "Low power clocksource found in the LPC" if COMPILE_TEST |
608 | select CLKSRC_OF if OF | 596 | select TIMER_OF if OF |
609 | depends on HAS_IOMEM | 597 | depends on HAS_IOMEM |
610 | select CLKSRC_MMIO | 598 | select CLKSRC_MMIO |
611 | help | 599 | help |
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile index 2b5b56a6f00f..72bfd001cfbb 100644 --- a/drivers/clocksource/Makefile +++ b/drivers/clocksource/Makefile | |||
@@ -1,5 +1,5 @@ | |||
1 | obj-$(CONFIG_CLKSRC_PROBE) += clksrc-probe.o | 1 | obj-$(CONFIG_TIMER_OF) += timer-of.o |
2 | obj-$(CONFIG_CLKEVT_PROBE) += clkevt-probe.o | 2 | obj-$(CONFIG_TIMER_PROBE) += timer-probe.o |
3 | obj-$(CONFIG_ATMEL_PIT) += timer-atmel-pit.o | 3 | obj-$(CONFIG_ATMEL_PIT) += timer-atmel-pit.o |
4 | obj-$(CONFIG_ATMEL_ST) += timer-atmel-st.o | 4 | obj-$(CONFIG_ATMEL_ST) += timer-atmel-st.o |
5 | obj-$(CONFIG_ATMEL_TCB_CLKSRC) += tcb_clksrc.o | 5 | obj-$(CONFIG_ATMEL_TCB_CLKSRC) += tcb_clksrc.o |
@@ -26,7 +26,6 @@ obj-$(CONFIG_ORION_TIMER) += time-orion.o | |||
26 | obj-$(CONFIG_BCM2835_TIMER) += bcm2835_timer.o | 26 | obj-$(CONFIG_BCM2835_TIMER) += bcm2835_timer.o |
27 | obj-$(CONFIG_CLPS711X_TIMER) += clps711x-timer.o | 27 | obj-$(CONFIG_CLPS711X_TIMER) += clps711x-timer.o |
28 | obj-$(CONFIG_ATLAS7_TIMER) += timer-atlas7.o | 28 | obj-$(CONFIG_ATLAS7_TIMER) += timer-atlas7.o |
29 | obj-$(CONFIG_MOXART_TIMER) += moxart_timer.o | ||
30 | obj-$(CONFIG_MXS_TIMER) += mxs_timer.o | 29 | obj-$(CONFIG_MXS_TIMER) += mxs_timer.o |
31 | obj-$(CONFIG_CLKSRC_PXA) += pxa_timer.o | 30 | obj-$(CONFIG_CLKSRC_PXA) += pxa_timer.o |
32 | obj-$(CONFIG_PRIMA2_TIMER) += timer-prima2.o | 31 | obj-$(CONFIG_PRIMA2_TIMER) += timer-prima2.o |
diff --git a/drivers/clocksource/arc_timer.c b/drivers/clocksource/arc_timer.c index 21649733827d..4927355f9cbe 100644 --- a/drivers/clocksource/arc_timer.c +++ b/drivers/clocksource/arc_timer.c | |||
@@ -99,7 +99,7 @@ static int __init arc_cs_setup_gfrc(struct device_node *node) | |||
99 | 99 | ||
100 | return clocksource_register_hz(&arc_counter_gfrc, arc_timer_freq); | 100 | return clocksource_register_hz(&arc_counter_gfrc, arc_timer_freq); |
101 | } | 101 | } |
102 | CLOCKSOURCE_OF_DECLARE(arc_gfrc, "snps,archs-timer-gfrc", arc_cs_setup_gfrc); | 102 | TIMER_OF_DECLARE(arc_gfrc, "snps,archs-timer-gfrc", arc_cs_setup_gfrc); |
103 | 103 | ||
104 | #define AUX_RTC_CTRL 0x103 | 104 | #define AUX_RTC_CTRL 0x103 |
105 | #define AUX_RTC_LOW 0x104 | 105 | #define AUX_RTC_LOW 0x104 |
@@ -158,7 +158,7 @@ static int __init arc_cs_setup_rtc(struct device_node *node) | |||
158 | 158 | ||
159 | return clocksource_register_hz(&arc_counter_rtc, arc_timer_freq); | 159 | return clocksource_register_hz(&arc_counter_rtc, arc_timer_freq); |
160 | } | 160 | } |
161 | CLOCKSOURCE_OF_DECLARE(arc_rtc, "snps,archs-timer-rtc", arc_cs_setup_rtc); | 161 | TIMER_OF_DECLARE(arc_rtc, "snps,archs-timer-rtc", arc_cs_setup_rtc); |
162 | 162 | ||
163 | #endif | 163 | #endif |
164 | 164 | ||
@@ -333,4 +333,4 @@ static int __init arc_of_timer_init(struct device_node *np) | |||
333 | 333 | ||
334 | return ret; | 334 | return ret; |
335 | } | 335 | } |
336 | CLOCKSOURCE_OF_DECLARE(arc_clkevt, "snps,arc-timer", arc_of_timer_init); | 336 | TIMER_OF_DECLARE(arc_clkevt, "snps,arc-timer", arc_of_timer_init); |
diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c index 8b5c30062d99..aae87c4c546e 100644 --- a/drivers/clocksource/arm_arch_timer.c +++ b/drivers/clocksource/arm_arch_timer.c | |||
@@ -1194,8 +1194,8 @@ static int __init arch_timer_of_init(struct device_node *np) | |||
1194 | 1194 | ||
1195 | return arch_timer_common_init(); | 1195 | return arch_timer_common_init(); |
1196 | } | 1196 | } |
1197 | CLOCKSOURCE_OF_DECLARE(armv7_arch_timer, "arm,armv7-timer", arch_timer_of_init); | 1197 | TIMER_OF_DECLARE(armv7_arch_timer, "arm,armv7-timer", arch_timer_of_init); |
1198 | CLOCKSOURCE_OF_DECLARE(armv8_arch_timer, "arm,armv8-timer", arch_timer_of_init); | 1198 | TIMER_OF_DECLARE(armv8_arch_timer, "arm,armv8-timer", arch_timer_of_init); |
1199 | 1199 | ||
1200 | static u32 __init | 1200 | static u32 __init |
1201 | arch_timer_mem_frame_get_cntfrq(struct arch_timer_mem_frame *frame) | 1201 | arch_timer_mem_frame_get_cntfrq(struct arch_timer_mem_frame *frame) |
@@ -1382,7 +1382,7 @@ out: | |||
1382 | kfree(timer_mem); | 1382 | kfree(timer_mem); |
1383 | return ret; | 1383 | return ret; |
1384 | } | 1384 | } |
1385 | CLOCKSOURCE_OF_DECLARE(armv7_arch_timer_mem, "arm,armv7-timer-mem", | 1385 | TIMER_OF_DECLARE(armv7_arch_timer_mem, "arm,armv7-timer-mem", |
1386 | arch_timer_mem_of_init); | 1386 | arch_timer_mem_of_init); |
1387 | 1387 | ||
1388 | #ifdef CONFIG_ACPI_GTDT | 1388 | #ifdef CONFIG_ACPI_GTDT |
@@ -1516,5 +1516,5 @@ static int __init arch_timer_acpi_init(struct acpi_table_header *table) | |||
1516 | 1516 | ||
1517 | return arch_timer_common_init(); | 1517 | return arch_timer_common_init(); |
1518 | } | 1518 | } |
1519 | CLOCKSOURCE_ACPI_DECLARE(arch_timer, ACPI_SIG_GTDT, arch_timer_acpi_init); | 1519 | TIMER_ACPI_DECLARE(arch_timer, ACPI_SIG_GTDT, arch_timer_acpi_init); |
1520 | #endif | 1520 | #endif |
diff --git a/drivers/clocksource/arm_global_timer.c b/drivers/clocksource/arm_global_timer.c index 123ed20ac2ff..095bb965f621 100644 --- a/drivers/clocksource/arm_global_timer.c +++ b/drivers/clocksource/arm_global_timer.c | |||
@@ -339,5 +339,5 @@ out_unmap: | |||
339 | } | 339 | } |
340 | 340 | ||
341 | /* Only tested on r2p2 and r3p0 */ | 341 | /* Only tested on r2p2 and r3p0 */ |
342 | CLOCKSOURCE_OF_DECLARE(arm_gt, "arm,cortex-a9-global-timer", | 342 | TIMER_OF_DECLARE(arm_gt, "arm,cortex-a9-global-timer", |
343 | global_timer_of_register); | 343 | global_timer_of_register); |
diff --git a/drivers/clocksource/armv7m_systick.c b/drivers/clocksource/armv7m_systick.c index a315491b7047..ac046d6fb0bf 100644 --- a/drivers/clocksource/armv7m_systick.c +++ b/drivers/clocksource/armv7m_systick.c | |||
@@ -82,5 +82,5 @@ out_unmap: | |||
82 | return ret; | 82 | return ret; |
83 | } | 83 | } |
84 | 84 | ||
85 | CLOCKSOURCE_OF_DECLARE(arm_systick, "arm,armv7m-systick", | 85 | TIMER_OF_DECLARE(arm_systick, "arm,armv7m-systick", |
86 | system_timer_of_register); | 86 | system_timer_of_register); |
diff --git a/drivers/clocksource/asm9260_timer.c b/drivers/clocksource/asm9260_timer.c index c6780830b8ac..38cd2feb87c4 100644 --- a/drivers/clocksource/asm9260_timer.c +++ b/drivers/clocksource/asm9260_timer.c | |||
@@ -238,5 +238,5 @@ static int __init asm9260_timer_init(struct device_node *np) | |||
238 | 238 | ||
239 | return 0; | 239 | return 0; |
240 | } | 240 | } |
241 | CLOCKSOURCE_OF_DECLARE(asm9260_timer, "alphascale,asm9260-timer", | 241 | TIMER_OF_DECLARE(asm9260_timer, "alphascale,asm9260-timer", |
242 | asm9260_timer_init); | 242 | asm9260_timer_init); |
diff --git a/drivers/clocksource/bcm2835_timer.c b/drivers/clocksource/bcm2835_timer.c index dce44307469e..82828d3a4739 100644 --- a/drivers/clocksource/bcm2835_timer.c +++ b/drivers/clocksource/bcm2835_timer.c | |||
@@ -148,5 +148,5 @@ err_iounmap: | |||
148 | iounmap(base); | 148 | iounmap(base); |
149 | return ret; | 149 | return ret; |
150 | } | 150 | } |
151 | CLOCKSOURCE_OF_DECLARE(bcm2835, "brcm,bcm2835-system-timer", | 151 | TIMER_OF_DECLARE(bcm2835, "brcm,bcm2835-system-timer", |
152 | bcm2835_timer_init); | 152 | bcm2835_timer_init); |
diff --git a/drivers/clocksource/bcm_kona_timer.c b/drivers/clocksource/bcm_kona_timer.c index fda5e1476638..5c40be9880f5 100644 --- a/drivers/clocksource/bcm_kona_timer.c +++ b/drivers/clocksource/bcm_kona_timer.c | |||
@@ -198,9 +198,9 @@ static int __init kona_timer_init(struct device_node *node) | |||
198 | return 0; | 198 | return 0; |
199 | } | 199 | } |
200 | 200 | ||
201 | CLOCKSOURCE_OF_DECLARE(brcm_kona, "brcm,kona-timer", kona_timer_init); | 201 | TIMER_OF_DECLARE(brcm_kona, "brcm,kona-timer", kona_timer_init); |
202 | /* | 202 | /* |
203 | * bcm,kona-timer is deprecated by brcm,kona-timer | 203 | * bcm,kona-timer is deprecated by brcm,kona-timer |
204 | * being kept here for driver compatibility | 204 | * being kept here for driver compatibility |
205 | */ | 205 | */ |
206 | CLOCKSOURCE_OF_DECLARE(bcm_kona, "bcm,kona-timer", kona_timer_init); | 206 | TIMER_OF_DECLARE(bcm_kona, "bcm,kona-timer", kona_timer_init); |
diff --git a/drivers/clocksource/cadence_ttc_timer.c b/drivers/clocksource/cadence_ttc_timer.c index 8e64b8460f11..29d51755e18b 100644 --- a/drivers/clocksource/cadence_ttc_timer.c +++ b/drivers/clocksource/cadence_ttc_timer.c | |||
@@ -540,4 +540,4 @@ static int __init ttc_timer_init(struct device_node *timer) | |||
540 | return 0; | 540 | return 0; |
541 | } | 541 | } |
542 | 542 | ||
543 | CLOCKSOURCE_OF_DECLARE(ttc, "cdns,ttc", ttc_timer_init); | 543 | TIMER_OF_DECLARE(ttc, "cdns,ttc", ttc_timer_init); |
diff --git a/drivers/clocksource/clkevt-probe.c b/drivers/clocksource/clkevt-probe.c deleted file mode 100644 index eb89b502acbd..000000000000 --- a/drivers/clocksource/clkevt-probe.c +++ /dev/null | |||
@@ -1,56 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2016, Linaro Ltd. All rights reserved. | ||
3 | * Daniel Lezcano <daniel.lezcano@linaro.org> | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms and conditions of the GNU General Public License, | ||
7 | * version 2, as published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
12 | * more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include <linux/init.h> | ||
19 | #include <linux/of.h> | ||
20 | #include <linux/clockchips.h> | ||
21 | |||
22 | extern struct of_device_id __clkevt_of_table[]; | ||
23 | |||
24 | static const struct of_device_id __clkevt_of_table_sentinel | ||
25 | __used __section(__clkevt_of_table_end); | ||
26 | |||
27 | int __init clockevent_probe(void) | ||
28 | { | ||
29 | struct device_node *np; | ||
30 | const struct of_device_id *match; | ||
31 | of_init_fn_1_ret init_func; | ||
32 | int ret, clockevents = 0; | ||
33 | |||
34 | for_each_matching_node_and_match(np, __clkevt_of_table, &match) { | ||
35 | if (!of_device_is_available(np)) | ||
36 | continue; | ||
37 | |||
38 | init_func = match->data; | ||
39 | |||
40 | ret = init_func(np); | ||
41 | if (ret) { | ||
42 | pr_warn("Failed to initialize '%s' (%d)\n", | ||
43 | np->name, ret); | ||
44 | continue; | ||
45 | } | ||
46 | |||
47 | clockevents++; | ||
48 | } | ||
49 | |||
50 | if (!clockevents) { | ||
51 | pr_crit("%s: no matching clockevent found\n", __func__); | ||
52 | return -ENODEV; | ||
53 | } | ||
54 | |||
55 | return 0; | ||
56 | } | ||
diff --git a/drivers/clocksource/clksrc-dbx500-prcmu.c b/drivers/clocksource/clksrc-dbx500-prcmu.c index c69e2772658d..c1b96dc5f444 100644 --- a/drivers/clocksource/clksrc-dbx500-prcmu.c +++ b/drivers/clocksource/clksrc-dbx500-prcmu.c | |||
@@ -86,5 +86,5 @@ static int __init clksrc_dbx500_prcmu_init(struct device_node *node) | |||
86 | #endif | 86 | #endif |
87 | return clocksource_register_hz(&clocksource_dbx500_prcmu, RATE_32K); | 87 | return clocksource_register_hz(&clocksource_dbx500_prcmu, RATE_32K); |
88 | } | 88 | } |
89 | CLOCKSOURCE_OF_DECLARE(dbx500_prcmu, "stericsson,db8500-prcmu-timer-4", | 89 | TIMER_OF_DECLARE(dbx500_prcmu, "stericsson,db8500-prcmu-timer-4", |
90 | clksrc_dbx500_prcmu_init); | 90 | clksrc_dbx500_prcmu_init); |
diff --git a/drivers/clocksource/clksrc_st_lpc.c b/drivers/clocksource/clksrc_st_lpc.c index 03cc49217bb4..a1d01ebb81f5 100644 --- a/drivers/clocksource/clksrc_st_lpc.c +++ b/drivers/clocksource/clksrc_st_lpc.c | |||
@@ -132,4 +132,4 @@ static int __init st_clksrc_of_register(struct device_node *np) | |||
132 | 132 | ||
133 | return ret; | 133 | return ret; |
134 | } | 134 | } |
135 | CLOCKSOURCE_OF_DECLARE(ddata, "st,stih407-lpc", st_clksrc_of_register); | 135 | TIMER_OF_DECLARE(ddata, "st,stih407-lpc", st_clksrc_of_register); |
diff --git a/drivers/clocksource/clps711x-timer.c b/drivers/clocksource/clps711x-timer.c index 24db6d605549..a8dd80576c95 100644 --- a/drivers/clocksource/clps711x-timer.c +++ b/drivers/clocksource/clps711x-timer.c | |||
@@ -103,7 +103,7 @@ void __init clps711x_clksrc_init(void __iomem *tc1_base, void __iomem *tc2_base, | |||
103 | BUG_ON(_clps711x_clkevt_init(tc2, tc2_base, irq)); | 103 | BUG_ON(_clps711x_clkevt_init(tc2, tc2_base, irq)); |
104 | } | 104 | } |
105 | 105 | ||
106 | #ifdef CONFIG_CLKSRC_OF | 106 | #ifdef CONFIG_TIMER_OF |
107 | static int __init clps711x_timer_init(struct device_node *np) | 107 | static int __init clps711x_timer_init(struct device_node *np) |
108 | { | 108 | { |
109 | unsigned int irq = irq_of_parse_and_map(np, 0); | 109 | unsigned int irq = irq_of_parse_and_map(np, 0); |
@@ -119,5 +119,5 @@ static int __init clps711x_timer_init(struct device_node *np) | |||
119 | return -EINVAL; | 119 | return -EINVAL; |
120 | } | 120 | } |
121 | } | 121 | } |
122 | CLOCKSOURCE_OF_DECLARE(clps711x, "cirrus,ep7209-timer", clps711x_timer_init); | 122 | TIMER_OF_DECLARE(clps711x, "cirrus,ep7209-timer", clps711x_timer_init); |
123 | #endif | 123 | #endif |
diff --git a/drivers/clocksource/dw_apb_timer_of.c b/drivers/clocksource/dw_apb_timer_of.c index aee6c0d39a7c..69866cd8f4bb 100644 --- a/drivers/clocksource/dw_apb_timer_of.c +++ b/drivers/clocksource/dw_apb_timer_of.c | |||
@@ -167,7 +167,7 @@ static int __init dw_apb_timer_init(struct device_node *timer) | |||
167 | 167 | ||
168 | return 0; | 168 | return 0; |
169 | } | 169 | } |
170 | CLOCKSOURCE_OF_DECLARE(pc3x2_timer, "picochip,pc3x2-timer", dw_apb_timer_init); | 170 | TIMER_OF_DECLARE(pc3x2_timer, "picochip,pc3x2-timer", dw_apb_timer_init); |
171 | CLOCKSOURCE_OF_DECLARE(apb_timer_osc, "snps,dw-apb-timer-osc", dw_apb_timer_init); | 171 | TIMER_OF_DECLARE(apb_timer_osc, "snps,dw-apb-timer-osc", dw_apb_timer_init); |
172 | CLOCKSOURCE_OF_DECLARE(apb_timer_sp, "snps,dw-apb-timer-sp", dw_apb_timer_init); | 172 | TIMER_OF_DECLARE(apb_timer_sp, "snps,dw-apb-timer-sp", dw_apb_timer_init); |
173 | CLOCKSOURCE_OF_DECLARE(apb_timer, "snps,dw-apb-timer", dw_apb_timer_init); | 173 | TIMER_OF_DECLARE(apb_timer, "snps,dw-apb-timer", dw_apb_timer_init); |
diff --git a/drivers/clocksource/exynos_mct.c b/drivers/clocksource/exynos_mct.c index 670ff0f25b67..7a244b681876 100644 --- a/drivers/clocksource/exynos_mct.c +++ b/drivers/clocksource/exynos_mct.c | |||
@@ -610,5 +610,5 @@ static int __init mct_init_ppi(struct device_node *np) | |||
610 | { | 610 | { |
611 | return mct_init_dt(np, MCT_INT_PPI); | 611 | return mct_init_dt(np, MCT_INT_PPI); |
612 | } | 612 | } |
613 | CLOCKSOURCE_OF_DECLARE(exynos4210, "samsung,exynos4210-mct", mct_init_spi); | 613 | TIMER_OF_DECLARE(exynos4210, "samsung,exynos4210-mct", mct_init_spi); |
614 | CLOCKSOURCE_OF_DECLARE(exynos4412, "samsung,exynos4412-mct", mct_init_ppi); | 614 | TIMER_OF_DECLARE(exynos4412, "samsung,exynos4412-mct", mct_init_ppi); |
diff --git a/drivers/clocksource/fsl_ftm_timer.c b/drivers/clocksource/fsl_ftm_timer.c index 738515b89073..3ee7e6fea621 100644 --- a/drivers/clocksource/fsl_ftm_timer.c +++ b/drivers/clocksource/fsl_ftm_timer.c | |||
@@ -329,13 +329,13 @@ static int __init ftm_timer_init(struct device_node *np) | |||
329 | priv->clkevt_base = of_iomap(np, 0); | 329 | priv->clkevt_base = of_iomap(np, 0); |
330 | if (!priv->clkevt_base) { | 330 | if (!priv->clkevt_base) { |
331 | pr_err("ftm: unable to map event timer registers\n"); | 331 | pr_err("ftm: unable to map event timer registers\n"); |
332 | goto err; | 332 | goto err_clkevt; |
333 | } | 333 | } |
334 | 334 | ||
335 | priv->clksrc_base = of_iomap(np, 1); | 335 | priv->clksrc_base = of_iomap(np, 1); |
336 | if (!priv->clksrc_base) { | 336 | if (!priv->clksrc_base) { |
337 | pr_err("ftm: unable to map source timer registers\n"); | 337 | pr_err("ftm: unable to map source timer registers\n"); |
338 | goto err; | 338 | goto err_clksrc; |
339 | } | 339 | } |
340 | 340 | ||
341 | ret = -EINVAL; | 341 | ret = -EINVAL; |
@@ -366,7 +366,11 @@ static int __init ftm_timer_init(struct device_node *np) | |||
366 | return 0; | 366 | return 0; |
367 | 367 | ||
368 | err: | 368 | err: |
369 | iounmap(priv->clksrc_base); | ||
370 | err_clksrc: | ||
371 | iounmap(priv->clkevt_base); | ||
372 | err_clkevt: | ||
369 | kfree(priv); | 373 | kfree(priv); |
370 | return ret; | 374 | return ret; |
371 | } | 375 | } |
372 | CLOCKSOURCE_OF_DECLARE(flextimer, "fsl,ftm-timer", ftm_timer_init); | 376 | TIMER_OF_DECLARE(flextimer, "fsl,ftm-timer", ftm_timer_init); |
diff --git a/drivers/clocksource/h8300_timer16.c b/drivers/clocksource/h8300_timer16.c index 5b27fb9997c2..dfbd4f8051cb 100644 --- a/drivers/clocksource/h8300_timer16.c +++ b/drivers/clocksource/h8300_timer16.c | |||
@@ -187,5 +187,5 @@ free_clk: | |||
187 | return ret; | 187 | return ret; |
188 | } | 188 | } |
189 | 189 | ||
190 | CLOCKSOURCE_OF_DECLARE(h8300_16bit, "renesas,16bit-timer", | 190 | TIMER_OF_DECLARE(h8300_16bit, "renesas,16bit-timer", |
191 | h8300_16timer_init); | 191 | h8300_16timer_init); |
diff --git a/drivers/clocksource/h8300_timer8.c b/drivers/clocksource/h8300_timer8.c index 804c489531d6..f6ffb0cef091 100644 --- a/drivers/clocksource/h8300_timer8.c +++ b/drivers/clocksource/h8300_timer8.c | |||
@@ -207,4 +207,4 @@ free_clk: | |||
207 | return ret; | 207 | return ret; |
208 | } | 208 | } |
209 | 209 | ||
210 | CLOCKSOURCE_OF_DECLARE(h8300_8bit, "renesas,8bit-timer", h8300_8timer_init); | 210 | TIMER_OF_DECLARE(h8300_8bit, "renesas,8bit-timer", h8300_8timer_init); |
diff --git a/drivers/clocksource/h8300_tpu.c b/drivers/clocksource/h8300_tpu.c index 72e1cf2b3096..45a8d17dac1e 100644 --- a/drivers/clocksource/h8300_tpu.c +++ b/drivers/clocksource/h8300_tpu.c | |||
@@ -154,4 +154,4 @@ free_clk: | |||
154 | return ret; | 154 | return ret; |
155 | } | 155 | } |
156 | 156 | ||
157 | CLOCKSOURCE_OF_DECLARE(h8300_tpu, "renesas,tpu", h8300_tpu_init); | 157 | TIMER_OF_DECLARE(h8300_tpu, "renesas,tpu", h8300_tpu_init); |
diff --git a/drivers/clocksource/jcore-pit.c b/drivers/clocksource/jcore-pit.c index 7c61226f4359..5d3d88e0fc8c 100644 --- a/drivers/clocksource/jcore-pit.c +++ b/drivers/clocksource/jcore-pit.c | |||
@@ -246,4 +246,4 @@ static int __init jcore_pit_init(struct device_node *node) | |||
246 | return 0; | 246 | return 0; |
247 | } | 247 | } |
248 | 248 | ||
249 | CLOCKSOURCE_OF_DECLARE(jcore_pit, "jcore,pit", jcore_pit_init); | 249 | TIMER_OF_DECLARE(jcore_pit, "jcore,pit", jcore_pit_init); |
diff --git a/drivers/clocksource/meson6_timer.c b/drivers/clocksource/meson6_timer.c index 39d21f693a33..92f20991a937 100644 --- a/drivers/clocksource/meson6_timer.c +++ b/drivers/clocksource/meson6_timer.c | |||
@@ -174,5 +174,5 @@ static int __init meson6_timer_init(struct device_node *node) | |||
174 | 1, 0xfffe); | 174 | 1, 0xfffe); |
175 | return 0; | 175 | return 0; |
176 | } | 176 | } |
177 | CLOCKSOURCE_OF_DECLARE(meson6, "amlogic,meson6-timer", | 177 | TIMER_OF_DECLARE(meson6, "amlogic,meson6-timer", |
178 | meson6_timer_init); | 178 | meson6_timer_init); |
diff --git a/drivers/clocksource/mips-gic-timer.c b/drivers/clocksource/mips-gic-timer.c index 3f52ee219923..17b861ea2626 100644 --- a/drivers/clocksource/mips-gic-timer.c +++ b/drivers/clocksource/mips-gic-timer.c | |||
@@ -167,10 +167,11 @@ static int __init gic_clocksource_of_init(struct device_node *node) | |||
167 | 167 | ||
168 | clk = of_clk_get(node, 0); | 168 | clk = of_clk_get(node, 0); |
169 | if (!IS_ERR(clk)) { | 169 | if (!IS_ERR(clk)) { |
170 | if (clk_prepare_enable(clk) < 0) { | 170 | ret = clk_prepare_enable(clk); |
171 | if (ret < 0) { | ||
171 | pr_err("GIC failed to enable clock\n"); | 172 | pr_err("GIC failed to enable clock\n"); |
172 | clk_put(clk); | 173 | clk_put(clk); |
173 | return PTR_ERR(clk); | 174 | return ret; |
174 | } | 175 | } |
175 | 176 | ||
176 | gic_frequency = clk_get_rate(clk); | 177 | gic_frequency = clk_get_rate(clk); |
@@ -200,5 +201,5 @@ static int __init gic_clocksource_of_init(struct device_node *node) | |||
200 | 201 | ||
201 | return 0; | 202 | return 0; |
202 | } | 203 | } |
203 | CLOCKSOURCE_OF_DECLARE(mips_gic_timer, "mti,gic-timer", | 204 | TIMER_OF_DECLARE(mips_gic_timer, "mti,gic-timer", |
204 | gic_clocksource_of_init); | 205 | gic_clocksource_of_init); |
diff --git a/drivers/clocksource/moxart_timer.c b/drivers/clocksource/moxart_timer.c deleted file mode 100644 index 7f3430654fbd..000000000000 --- a/drivers/clocksource/moxart_timer.c +++ /dev/null | |||
@@ -1,256 +0,0 @@ | |||
1 | /* | ||
2 | * MOXA ART SoCs timer handling. | ||
3 | * | ||
4 | * Copyright (C) 2013 Jonas Jensen | ||
5 | * | ||
6 | * Jonas Jensen <jonas.jensen@gmail.com> | ||
7 | * | ||
8 | * This file is licensed under the terms of the GNU General Public | ||
9 | * License version 2. This program is licensed "as is" without any | ||
10 | * warranty of any kind, whether express or implied. | ||
11 | */ | ||
12 | |||
13 | #include <linux/clk.h> | ||
14 | #include <linux/clockchips.h> | ||
15 | #include <linux/interrupt.h> | ||
16 | #include <linux/irq.h> | ||
17 | #include <linux/irqreturn.h> | ||
18 | #include <linux/of.h> | ||
19 | #include <linux/of_address.h> | ||
20 | #include <linux/of_irq.h> | ||
21 | #include <linux/io.h> | ||
22 | #include <linux/clocksource.h> | ||
23 | #include <linux/bitops.h> | ||
24 | #include <linux/slab.h> | ||
25 | |||
26 | #define TIMER1_BASE 0x00 | ||
27 | #define TIMER2_BASE 0x10 | ||
28 | #define TIMER3_BASE 0x20 | ||
29 | |||
30 | #define REG_COUNT 0x0 /* writable */ | ||
31 | #define REG_LOAD 0x4 | ||
32 | #define REG_MATCH1 0x8 | ||
33 | #define REG_MATCH2 0xC | ||
34 | |||
35 | #define TIMER_CR 0x30 | ||
36 | #define TIMER_INTR_STATE 0x34 | ||
37 | #define TIMER_INTR_MASK 0x38 | ||
38 | |||
39 | /* | ||
40 | * Moxart TIMER_CR flags: | ||
41 | * | ||
42 | * MOXART_CR_*_CLOCK 0: PCLK, 1: EXT1CLK | ||
43 | * MOXART_CR_*_INT overflow interrupt enable bit | ||
44 | */ | ||
45 | #define MOXART_CR_1_ENABLE BIT(0) | ||
46 | #define MOXART_CR_1_CLOCK BIT(1) | ||
47 | #define MOXART_CR_1_INT BIT(2) | ||
48 | #define MOXART_CR_2_ENABLE BIT(3) | ||
49 | #define MOXART_CR_2_CLOCK BIT(4) | ||
50 | #define MOXART_CR_2_INT BIT(5) | ||
51 | #define MOXART_CR_3_ENABLE BIT(6) | ||
52 | #define MOXART_CR_3_CLOCK BIT(7) | ||
53 | #define MOXART_CR_3_INT BIT(8) | ||
54 | #define MOXART_CR_COUNT_UP BIT(9) | ||
55 | |||
56 | #define MOXART_TIMER1_ENABLE (MOXART_CR_2_ENABLE | MOXART_CR_1_ENABLE) | ||
57 | #define MOXART_TIMER1_DISABLE (MOXART_CR_2_ENABLE) | ||
58 | |||
59 | /* | ||
60 | * The ASpeed variant of the IP block has a different layout | ||
61 | * for the control register | ||
62 | */ | ||
63 | #define ASPEED_CR_1_ENABLE BIT(0) | ||
64 | #define ASPEED_CR_1_CLOCK BIT(1) | ||
65 | #define ASPEED_CR_1_INT BIT(2) | ||
66 | #define ASPEED_CR_2_ENABLE BIT(4) | ||
67 | #define ASPEED_CR_2_CLOCK BIT(5) | ||
68 | #define ASPEED_CR_2_INT BIT(6) | ||
69 | #define ASPEED_CR_3_ENABLE BIT(8) | ||
70 | #define ASPEED_CR_3_CLOCK BIT(9) | ||
71 | #define ASPEED_CR_3_INT BIT(10) | ||
72 | |||
73 | #define ASPEED_TIMER1_ENABLE (ASPEED_CR_2_ENABLE | ASPEED_CR_1_ENABLE) | ||
74 | #define ASPEED_TIMER1_DISABLE (ASPEED_CR_2_ENABLE) | ||
75 | |||
76 | struct moxart_timer { | ||
77 | void __iomem *base; | ||
78 | unsigned int t1_disable_val; | ||
79 | unsigned int t1_enable_val; | ||
80 | unsigned int count_per_tick; | ||
81 | struct clock_event_device clkevt; | ||
82 | }; | ||
83 | |||
84 | static inline struct moxart_timer *to_moxart(struct clock_event_device *evt) | ||
85 | { | ||
86 | return container_of(evt, struct moxart_timer, clkevt); | ||
87 | } | ||
88 | |||
89 | static inline void moxart_disable(struct clock_event_device *evt) | ||
90 | { | ||
91 | struct moxart_timer *timer = to_moxart(evt); | ||
92 | |||
93 | writel(timer->t1_disable_val, timer->base + TIMER_CR); | ||
94 | } | ||
95 | |||
96 | static inline void moxart_enable(struct clock_event_device *evt) | ||
97 | { | ||
98 | struct moxart_timer *timer = to_moxart(evt); | ||
99 | |||
100 | writel(timer->t1_enable_val, timer->base + TIMER_CR); | ||
101 | } | ||
102 | |||
103 | static int moxart_shutdown(struct clock_event_device *evt) | ||
104 | { | ||
105 | moxart_disable(evt); | ||
106 | return 0; | ||
107 | } | ||
108 | |||
109 | static int moxart_set_oneshot(struct clock_event_device *evt) | ||
110 | { | ||
111 | moxart_disable(evt); | ||
112 | writel(~0, to_moxart(evt)->base + TIMER1_BASE + REG_LOAD); | ||
113 | return 0; | ||
114 | } | ||
115 | |||
116 | static int moxart_set_periodic(struct clock_event_device *evt) | ||
117 | { | ||
118 | struct moxart_timer *timer = to_moxart(evt); | ||
119 | |||
120 | moxart_disable(evt); | ||
121 | writel(timer->count_per_tick, timer->base + TIMER1_BASE + REG_LOAD); | ||
122 | writel(0, timer->base + TIMER1_BASE + REG_MATCH1); | ||
123 | moxart_enable(evt); | ||
124 | return 0; | ||
125 | } | ||
126 | |||
127 | static int moxart_clkevt_next_event(unsigned long cycles, | ||
128 | struct clock_event_device *evt) | ||
129 | { | ||
130 | struct moxart_timer *timer = to_moxart(evt); | ||
131 | u32 u; | ||
132 | |||
133 | moxart_disable(evt); | ||
134 | |||
135 | u = readl(timer->base + TIMER1_BASE + REG_COUNT) - cycles; | ||
136 | writel(u, timer->base + TIMER1_BASE + REG_MATCH1); | ||
137 | |||
138 | moxart_enable(evt); | ||
139 | |||
140 | return 0; | ||
141 | } | ||
142 | |||
143 | static irqreturn_t moxart_timer_interrupt(int irq, void *dev_id) | ||
144 | { | ||
145 | struct clock_event_device *evt = dev_id; | ||
146 | evt->event_handler(evt); | ||
147 | return IRQ_HANDLED; | ||
148 | } | ||
149 | |||
150 | static int __init moxart_timer_init(struct device_node *node) | ||
151 | { | ||
152 | int ret, irq; | ||
153 | unsigned long pclk; | ||
154 | struct clk *clk; | ||
155 | struct moxart_timer *timer; | ||
156 | |||
157 | timer = kzalloc(sizeof(*timer), GFP_KERNEL); | ||
158 | if (!timer) | ||
159 | return -ENOMEM; | ||
160 | |||
161 | timer->base = of_iomap(node, 0); | ||
162 | if (!timer->base) { | ||
163 | pr_err("%s: of_iomap failed\n", node->full_name); | ||
164 | ret = -ENXIO; | ||
165 | goto out_free; | ||
166 | } | ||
167 | |||
168 | irq = irq_of_parse_and_map(node, 0); | ||
169 | if (irq <= 0) { | ||
170 | pr_err("%s: irq_of_parse_and_map failed\n", node->full_name); | ||
171 | ret = -EINVAL; | ||
172 | goto out_unmap; | ||
173 | } | ||
174 | |||
175 | clk = of_clk_get(node, 0); | ||
176 | if (IS_ERR(clk)) { | ||
177 | pr_err("%s: of_clk_get failed\n", node->full_name); | ||
178 | ret = PTR_ERR(clk); | ||
179 | goto out_unmap; | ||
180 | } | ||
181 | |||
182 | pclk = clk_get_rate(clk); | ||
183 | |||
184 | if (of_device_is_compatible(node, "moxa,moxart-timer")) { | ||
185 | timer->t1_enable_val = MOXART_TIMER1_ENABLE; | ||
186 | timer->t1_disable_val = MOXART_TIMER1_DISABLE; | ||
187 | } else if (of_device_is_compatible(node, "aspeed,ast2400-timer")) { | ||
188 | timer->t1_enable_val = ASPEED_TIMER1_ENABLE; | ||
189 | timer->t1_disable_val = ASPEED_TIMER1_DISABLE; | ||
190 | } else { | ||
191 | pr_err("%s: unknown platform\n", node->full_name); | ||
192 | ret = -EINVAL; | ||
193 | goto out_unmap; | ||
194 | } | ||
195 | |||
196 | timer->count_per_tick = DIV_ROUND_CLOSEST(pclk, HZ); | ||
197 | |||
198 | timer->clkevt.name = node->name; | ||
199 | timer->clkevt.rating = 200; | ||
200 | timer->clkevt.features = CLOCK_EVT_FEAT_PERIODIC | | ||
201 | CLOCK_EVT_FEAT_ONESHOT; | ||
202 | timer->clkevt.set_state_shutdown = moxart_shutdown; | ||
203 | timer->clkevt.set_state_periodic = moxart_set_periodic; | ||
204 | timer->clkevt.set_state_oneshot = moxart_set_oneshot; | ||
205 | timer->clkevt.tick_resume = moxart_set_oneshot; | ||
206 | timer->clkevt.set_next_event = moxart_clkevt_next_event; | ||
207 | timer->clkevt.cpumask = cpumask_of(0); | ||
208 | timer->clkevt.irq = irq; | ||
209 | |||
210 | ret = clocksource_mmio_init(timer->base + TIMER2_BASE + REG_COUNT, | ||
211 | "moxart_timer", pclk, 200, 32, | ||
212 | clocksource_mmio_readl_down); | ||
213 | if (ret) { | ||
214 | pr_err("%s: clocksource_mmio_init failed\n", node->full_name); | ||
215 | goto out_unmap; | ||
216 | } | ||
217 | |||
218 | ret = request_irq(irq, moxart_timer_interrupt, IRQF_TIMER, | ||
219 | node->name, &timer->clkevt); | ||
220 | if (ret) { | ||
221 | pr_err("%s: setup_irq failed\n", node->full_name); | ||
222 | goto out_unmap; | ||
223 | } | ||
224 | |||
225 | /* Clear match registers */ | ||
226 | writel(0, timer->base + TIMER1_BASE + REG_MATCH1); | ||
227 | writel(0, timer->base + TIMER1_BASE + REG_MATCH2); | ||
228 | writel(0, timer->base + TIMER2_BASE + REG_MATCH1); | ||
229 | writel(0, timer->base + TIMER2_BASE + REG_MATCH2); | ||
230 | |||
231 | /* | ||
232 | * Start timer 2 rolling as our main wall clock source, keep timer 1 | ||
233 | * disabled | ||
234 | */ | ||
235 | writel(0, timer->base + TIMER_CR); | ||
236 | writel(~0, timer->base + TIMER2_BASE + REG_LOAD); | ||
237 | writel(timer->t1_disable_val, timer->base + TIMER_CR); | ||
238 | |||
239 | /* | ||
240 | * documentation is not publicly available: | ||
241 | * min_delta / max_delta obtained by trial-and-error, | ||
242 | * max_delta 0xfffffffe should be ok because count | ||
243 | * register size is u32 | ||
244 | */ | ||
245 | clockevents_config_and_register(&timer->clkevt, pclk, 0x4, 0xfffffffe); | ||
246 | |||
247 | return 0; | ||
248 | |||
249 | out_unmap: | ||
250 | iounmap(timer->base); | ||
251 | out_free: | ||
252 | kfree(timer); | ||
253 | return ret; | ||
254 | } | ||
255 | CLOCKSOURCE_OF_DECLARE(moxart, "moxa,moxart-timer", moxart_timer_init); | ||
256 | CLOCKSOURCE_OF_DECLARE(aspeed, "aspeed,ast2400-timer", moxart_timer_init); | ||
diff --git a/drivers/clocksource/mps2-timer.c b/drivers/clocksource/mps2-timer.c index 3e4431ed9aa9..aa4d63af8706 100644 --- a/drivers/clocksource/mps2-timer.c +++ b/drivers/clocksource/mps2-timer.c | |||
@@ -274,4 +274,4 @@ static int __init mps2_timer_init(struct device_node *np) | |||
274 | return 0; | 274 | return 0; |
275 | } | 275 | } |
276 | 276 | ||
277 | CLOCKSOURCE_OF_DECLARE(mps2_timer, "arm,mps2-timer", mps2_timer_init); | 277 | TIMER_OF_DECLARE(mps2_timer, "arm,mps2-timer", mps2_timer_init); |
diff --git a/drivers/clocksource/mtk_timer.c b/drivers/clocksource/mtk_timer.c index 90659493c59c..f9b724fd9950 100644 --- a/drivers/clocksource/mtk_timer.c +++ b/drivers/clocksource/mtk_timer.c | |||
@@ -265,4 +265,4 @@ err_kzalloc: | |||
265 | 265 | ||
266 | return -EINVAL; | 266 | return -EINVAL; |
267 | } | 267 | } |
268 | CLOCKSOURCE_OF_DECLARE(mtk_mt6577, "mediatek,mt6577-timer", mtk_timer_init); | 268 | TIMER_OF_DECLARE(mtk_mt6577, "mediatek,mt6577-timer", mtk_timer_init); |
diff --git a/drivers/clocksource/mxs_timer.c b/drivers/clocksource/mxs_timer.c index 99b77aff0839..a03434e9fe8f 100644 --- a/drivers/clocksource/mxs_timer.c +++ b/drivers/clocksource/mxs_timer.c | |||
@@ -293,4 +293,4 @@ static int __init mxs_timer_init(struct device_node *np) | |||
293 | 293 | ||
294 | return setup_irq(irq, &mxs_timer_irq); | 294 | return setup_irq(irq, &mxs_timer_irq); |
295 | } | 295 | } |
296 | CLOCKSOURCE_OF_DECLARE(mxs, "fsl,timrot", mxs_timer_init); | 296 | TIMER_OF_DECLARE(mxs, "fsl,timrot", mxs_timer_init); |
diff --git a/drivers/clocksource/nomadik-mtu.c b/drivers/clocksource/nomadik-mtu.c index 7d44de304f37..8e4ddb9420c6 100644 --- a/drivers/clocksource/nomadik-mtu.c +++ b/drivers/clocksource/nomadik-mtu.c | |||
@@ -284,5 +284,5 @@ static int __init nmdk_timer_of_init(struct device_node *node) | |||
284 | 284 | ||
285 | return nmdk_timer_init(base, irq, pclk, clk); | 285 | return nmdk_timer_init(base, irq, pclk, clk); |
286 | } | 286 | } |
287 | CLOCKSOURCE_OF_DECLARE(nomadik_mtu, "st,nomadik-mtu", | 287 | TIMER_OF_DECLARE(nomadik_mtu, "st,nomadik-mtu", |
288 | nmdk_timer_of_init); | 288 | nmdk_timer_of_init); |
diff --git a/drivers/clocksource/pxa_timer.c b/drivers/clocksource/pxa_timer.c index a10fa667325f..08cd6eaf3795 100644 --- a/drivers/clocksource/pxa_timer.c +++ b/drivers/clocksource/pxa_timer.c | |||
@@ -216,7 +216,7 @@ static int __init pxa_timer_dt_init(struct device_node *np) | |||
216 | 216 | ||
217 | return pxa_timer_common_init(irq, clk_get_rate(clk)); | 217 | return pxa_timer_common_init(irq, clk_get_rate(clk)); |
218 | } | 218 | } |
219 | CLOCKSOURCE_OF_DECLARE(pxa_timer, "marvell,pxa-timer", pxa_timer_dt_init); | 219 | TIMER_OF_DECLARE(pxa_timer, "marvell,pxa-timer", pxa_timer_dt_init); |
220 | 220 | ||
221 | /* | 221 | /* |
222 | * Legacy timer init for non device-tree boards. | 222 | * Legacy timer init for non device-tree boards. |
diff --git a/drivers/clocksource/qcom-timer.c b/drivers/clocksource/qcom-timer.c index ee358cdf4a07..89816f89ff3f 100644 --- a/drivers/clocksource/qcom-timer.c +++ b/drivers/clocksource/qcom-timer.c | |||
@@ -254,5 +254,5 @@ static int __init msm_dt_timer_init(struct device_node *np) | |||
254 | 254 | ||
255 | return msm_timer_init(freq, 32, irq, !!percpu_offset); | 255 | return msm_timer_init(freq, 32, irq, !!percpu_offset); |
256 | } | 256 | } |
257 | CLOCKSOURCE_OF_DECLARE(kpss_timer, "qcom,kpss-timer", msm_dt_timer_init); | 257 | TIMER_OF_DECLARE(kpss_timer, "qcom,kpss-timer", msm_dt_timer_init); |
258 | CLOCKSOURCE_OF_DECLARE(scss_timer, "qcom,scss-timer", msm_dt_timer_init); | 258 | TIMER_OF_DECLARE(scss_timer, "qcom,scss-timer", msm_dt_timer_init); |
diff --git a/drivers/clocksource/renesas-ostm.c b/drivers/clocksource/renesas-ostm.c index c76f57668fb2..6cffd7c6001a 100644 --- a/drivers/clocksource/renesas-ostm.c +++ b/drivers/clocksource/renesas-ostm.c | |||
@@ -262,4 +262,4 @@ err: | |||
262 | return 0; | 262 | return 0; |
263 | } | 263 | } |
264 | 264 | ||
265 | CLOCKSOURCE_OF_DECLARE(ostm, "renesas,ostm", ostm_init); | 265 | TIMER_OF_DECLARE(ostm, "renesas,ostm", ostm_init); |
diff --git a/drivers/clocksource/rockchip_timer.c b/drivers/clocksource/rockchip_timer.c index 49c02be50eca..c27f4c850d83 100644 --- a/drivers/clocksource/rockchip_timer.c +++ b/drivers/clocksource/rockchip_timer.c | |||
@@ -303,5 +303,5 @@ static int __init rk_timer_init(struct device_node *np) | |||
303 | return -EINVAL; | 303 | return -EINVAL; |
304 | } | 304 | } |
305 | 305 | ||
306 | CLOCKSOURCE_OF_DECLARE(rk3288_timer, "rockchip,rk3288-timer", rk_timer_init); | 306 | TIMER_OF_DECLARE(rk3288_timer, "rockchip,rk3288-timer", rk_timer_init); |
307 | CLOCKSOURCE_OF_DECLARE(rk3399_timer, "rockchip,rk3399-timer", rk_timer_init); | 307 | TIMER_OF_DECLARE(rk3399_timer, "rockchip,rk3399-timer", rk_timer_init); |
diff --git a/drivers/clocksource/samsung_pwm_timer.c b/drivers/clocksource/samsung_pwm_timer.c index a68e6538c809..6d5d126357c2 100644 --- a/drivers/clocksource/samsung_pwm_timer.c +++ b/drivers/clocksource/samsung_pwm_timer.c | |||
@@ -418,7 +418,7 @@ void __init samsung_pwm_clocksource_init(void __iomem *base, | |||
418 | _samsung_pwm_clocksource_init(); | 418 | _samsung_pwm_clocksource_init(); |
419 | } | 419 | } |
420 | 420 | ||
421 | #ifdef CONFIG_CLKSRC_OF | 421 | #ifdef CONFIG_TIMER_OF |
422 | static int __init samsung_pwm_alloc(struct device_node *np, | 422 | static int __init samsung_pwm_alloc(struct device_node *np, |
423 | const struct samsung_pwm_variant *variant) | 423 | const struct samsung_pwm_variant *variant) |
424 | { | 424 | { |
@@ -466,7 +466,7 @@ static int __init s3c2410_pwm_clocksource_init(struct device_node *np) | |||
466 | { | 466 | { |
467 | return samsung_pwm_alloc(np, &s3c24xx_variant); | 467 | return samsung_pwm_alloc(np, &s3c24xx_variant); |
468 | } | 468 | } |
469 | CLOCKSOURCE_OF_DECLARE(s3c2410_pwm, "samsung,s3c2410-pwm", s3c2410_pwm_clocksource_init); | 469 | TIMER_OF_DECLARE(s3c2410_pwm, "samsung,s3c2410-pwm", s3c2410_pwm_clocksource_init); |
470 | 470 | ||
471 | static const struct samsung_pwm_variant s3c64xx_variant = { | 471 | static const struct samsung_pwm_variant s3c64xx_variant = { |
472 | .bits = 32, | 472 | .bits = 32, |
@@ -479,7 +479,7 @@ static int __init s3c64xx_pwm_clocksource_init(struct device_node *np) | |||
479 | { | 479 | { |
480 | return samsung_pwm_alloc(np, &s3c64xx_variant); | 480 | return samsung_pwm_alloc(np, &s3c64xx_variant); |
481 | } | 481 | } |
482 | CLOCKSOURCE_OF_DECLARE(s3c6400_pwm, "samsung,s3c6400-pwm", s3c64xx_pwm_clocksource_init); | 482 | TIMER_OF_DECLARE(s3c6400_pwm, "samsung,s3c6400-pwm", s3c64xx_pwm_clocksource_init); |
483 | 483 | ||
484 | static const struct samsung_pwm_variant s5p64x0_variant = { | 484 | static const struct samsung_pwm_variant s5p64x0_variant = { |
485 | .bits = 32, | 485 | .bits = 32, |
@@ -492,7 +492,7 @@ static int __init s5p64x0_pwm_clocksource_init(struct device_node *np) | |||
492 | { | 492 | { |
493 | return samsung_pwm_alloc(np, &s5p64x0_variant); | 493 | return samsung_pwm_alloc(np, &s5p64x0_variant); |
494 | } | 494 | } |
495 | CLOCKSOURCE_OF_DECLARE(s5p6440_pwm, "samsung,s5p6440-pwm", s5p64x0_pwm_clocksource_init); | 495 | TIMER_OF_DECLARE(s5p6440_pwm, "samsung,s5p6440-pwm", s5p64x0_pwm_clocksource_init); |
496 | 496 | ||
497 | static const struct samsung_pwm_variant s5p_variant = { | 497 | static const struct samsung_pwm_variant s5p_variant = { |
498 | .bits = 32, | 498 | .bits = 32, |
@@ -505,5 +505,5 @@ static int __init s5p_pwm_clocksource_init(struct device_node *np) | |||
505 | { | 505 | { |
506 | return samsung_pwm_alloc(np, &s5p_variant); | 506 | return samsung_pwm_alloc(np, &s5p_variant); |
507 | } | 507 | } |
508 | CLOCKSOURCE_OF_DECLARE(s5pc100_pwm, "samsung,s5pc100-pwm", s5p_pwm_clocksource_init); | 508 | TIMER_OF_DECLARE(s5pc100_pwm, "samsung,s5pc100-pwm", s5p_pwm_clocksource_init); |
509 | #endif | 509 | #endif |
diff --git a/drivers/clocksource/sun4i_timer.c b/drivers/clocksource/sun4i_timer.c index 4452d5c8f304..6e0180aaf784 100644 --- a/drivers/clocksource/sun4i_timer.c +++ b/drivers/clocksource/sun4i_timer.c | |||
@@ -24,6 +24,8 @@ | |||
24 | #include <linux/of_address.h> | 24 | #include <linux/of_address.h> |
25 | #include <linux/of_irq.h> | 25 | #include <linux/of_irq.h> |
26 | 26 | ||
27 | #include "timer-of.h" | ||
28 | |||
27 | #define TIMER_IRQ_EN_REG 0x00 | 29 | #define TIMER_IRQ_EN_REG 0x00 |
28 | #define TIMER_IRQ_EN(val) BIT(val) | 30 | #define TIMER_IRQ_EN(val) BIT(val) |
29 | #define TIMER_IRQ_ST_REG 0x04 | 31 | #define TIMER_IRQ_ST_REG 0x04 |
@@ -39,38 +41,37 @@ | |||
39 | 41 | ||
40 | #define TIMER_SYNC_TICKS 3 | 42 | #define TIMER_SYNC_TICKS 3 |
41 | 43 | ||
42 | static void __iomem *timer_base; | ||
43 | static u32 ticks_per_jiffy; | ||
44 | |||
45 | /* | 44 | /* |
46 | * When we disable a timer, we need to wait at least for 2 cycles of | 45 | * When we disable a timer, we need to wait at least for 2 cycles of |
47 | * the timer source clock. We will use for that the clocksource timer | 46 | * the timer source clock. We will use for that the clocksource timer |
48 | * that is already setup and runs at the same frequency than the other | 47 | * that is already setup and runs at the same frequency than the other |
49 | * timers, and we never will be disabled. | 48 | * timers, and we never will be disabled. |
50 | */ | 49 | */ |
51 | static void sun4i_clkevt_sync(void) | 50 | static void sun4i_clkevt_sync(void __iomem *base) |
52 | { | 51 | { |
53 | u32 old = readl(timer_base + TIMER_CNTVAL_REG(1)); | 52 | u32 old = readl(base + TIMER_CNTVAL_REG(1)); |
54 | 53 | ||
55 | while ((old - readl(timer_base + TIMER_CNTVAL_REG(1))) < TIMER_SYNC_TICKS) | 54 | while ((old - readl(base + TIMER_CNTVAL_REG(1))) < TIMER_SYNC_TICKS) |
56 | cpu_relax(); | 55 | cpu_relax(); |
57 | } | 56 | } |
58 | 57 | ||
59 | static void sun4i_clkevt_time_stop(u8 timer) | 58 | static void sun4i_clkevt_time_stop(void __iomem *base, u8 timer) |
60 | { | 59 | { |
61 | u32 val = readl(timer_base + TIMER_CTL_REG(timer)); | 60 | u32 val = readl(base + TIMER_CTL_REG(timer)); |
62 | writel(val & ~TIMER_CTL_ENABLE, timer_base + TIMER_CTL_REG(timer)); | 61 | writel(val & ~TIMER_CTL_ENABLE, base + TIMER_CTL_REG(timer)); |
63 | sun4i_clkevt_sync(); | 62 | sun4i_clkevt_sync(base); |
64 | } | 63 | } |
65 | 64 | ||
66 | static void sun4i_clkevt_time_setup(u8 timer, unsigned long delay) | 65 | static void sun4i_clkevt_time_setup(void __iomem *base, u8 timer, |
66 | unsigned long delay) | ||
67 | { | 67 | { |
68 | writel(delay, timer_base + TIMER_INTVAL_REG(timer)); | 68 | writel(delay, base + TIMER_INTVAL_REG(timer)); |
69 | } | 69 | } |
70 | 70 | ||
71 | static void sun4i_clkevt_time_start(u8 timer, bool periodic) | 71 | static void sun4i_clkevt_time_start(void __iomem *base, u8 timer, |
72 | bool periodic) | ||
72 | { | 73 | { |
73 | u32 val = readl(timer_base + TIMER_CTL_REG(timer)); | 74 | u32 val = readl(base + TIMER_CTL_REG(timer)); |
74 | 75 | ||
75 | if (periodic) | 76 | if (periodic) |
76 | val &= ~TIMER_CTL_ONESHOT; | 77 | val &= ~TIMER_CTL_ONESHOT; |
@@ -78,115 +79,106 @@ static void sun4i_clkevt_time_start(u8 timer, bool periodic) | |||
78 | val |= TIMER_CTL_ONESHOT; | 79 | val |= TIMER_CTL_ONESHOT; |
79 | 80 | ||
80 | writel(val | TIMER_CTL_ENABLE | TIMER_CTL_RELOAD, | 81 | writel(val | TIMER_CTL_ENABLE | TIMER_CTL_RELOAD, |
81 | timer_base + TIMER_CTL_REG(timer)); | 82 | base + TIMER_CTL_REG(timer)); |
82 | } | 83 | } |
83 | 84 | ||
84 | static int sun4i_clkevt_shutdown(struct clock_event_device *evt) | 85 | static int sun4i_clkevt_shutdown(struct clock_event_device *evt) |
85 | { | 86 | { |
86 | sun4i_clkevt_time_stop(0); | 87 | struct timer_of *to = to_timer_of(evt); |
88 | |||
89 | sun4i_clkevt_time_stop(timer_of_base(to), 0); | ||
90 | |||
87 | return 0; | 91 | return 0; |
88 | } | 92 | } |
89 | 93 | ||
90 | static int sun4i_clkevt_set_oneshot(struct clock_event_device *evt) | 94 | static int sun4i_clkevt_set_oneshot(struct clock_event_device *evt) |
91 | { | 95 | { |
92 | sun4i_clkevt_time_stop(0); | 96 | struct timer_of *to = to_timer_of(evt); |
93 | sun4i_clkevt_time_start(0, false); | 97 | |
98 | sun4i_clkevt_time_stop(timer_of_base(to), 0); | ||
99 | sun4i_clkevt_time_start(timer_of_base(to), 0, false); | ||
100 | |||
94 | return 0; | 101 | return 0; |
95 | } | 102 | } |
96 | 103 | ||
97 | static int sun4i_clkevt_set_periodic(struct clock_event_device *evt) | 104 | static int sun4i_clkevt_set_periodic(struct clock_event_device *evt) |
98 | { | 105 | { |
99 | sun4i_clkevt_time_stop(0); | 106 | struct timer_of *to = to_timer_of(evt); |
100 | sun4i_clkevt_time_setup(0, ticks_per_jiffy); | 107 | |
101 | sun4i_clkevt_time_start(0, true); | 108 | sun4i_clkevt_time_stop(timer_of_base(to), 0); |
109 | sun4i_clkevt_time_setup(timer_of_base(to), 0, timer_of_period(to)); | ||
110 | sun4i_clkevt_time_start(timer_of_base(to), 0, true); | ||
111 | |||
102 | return 0; | 112 | return 0; |
103 | } | 113 | } |
104 | 114 | ||
105 | static int sun4i_clkevt_next_event(unsigned long evt, | 115 | static int sun4i_clkevt_next_event(unsigned long evt, |
106 | struct clock_event_device *unused) | 116 | struct clock_event_device *clkevt) |
107 | { | 117 | { |
108 | sun4i_clkevt_time_stop(0); | 118 | struct timer_of *to = to_timer_of(clkevt); |
109 | sun4i_clkevt_time_setup(0, evt - TIMER_SYNC_TICKS); | 119 | |
110 | sun4i_clkevt_time_start(0, false); | 120 | sun4i_clkevt_time_stop(timer_of_base(to), 0); |
121 | sun4i_clkevt_time_setup(timer_of_base(to), 0, evt - TIMER_SYNC_TICKS); | ||
122 | sun4i_clkevt_time_start(timer_of_base(to), 0, false); | ||
111 | 123 | ||
112 | return 0; | 124 | return 0; |
113 | } | 125 | } |
114 | 126 | ||
115 | static struct clock_event_device sun4i_clockevent = { | 127 | static void sun4i_timer_clear_interrupt(void __iomem *base) |
116 | .name = "sun4i_tick", | ||
117 | .rating = 350, | ||
118 | .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT, | ||
119 | .set_state_shutdown = sun4i_clkevt_shutdown, | ||
120 | .set_state_periodic = sun4i_clkevt_set_periodic, | ||
121 | .set_state_oneshot = sun4i_clkevt_set_oneshot, | ||
122 | .tick_resume = sun4i_clkevt_shutdown, | ||
123 | .set_next_event = sun4i_clkevt_next_event, | ||
124 | }; | ||
125 | |||
126 | static void sun4i_timer_clear_interrupt(void) | ||
127 | { | 128 | { |
128 | writel(TIMER_IRQ_EN(0), timer_base + TIMER_IRQ_ST_REG); | 129 | writel(TIMER_IRQ_EN(0), base + TIMER_IRQ_ST_REG); |
129 | } | 130 | } |
130 | 131 | ||
131 | static irqreturn_t sun4i_timer_interrupt(int irq, void *dev_id) | 132 | static irqreturn_t sun4i_timer_interrupt(int irq, void *dev_id) |
132 | { | 133 | { |
133 | struct clock_event_device *evt = (struct clock_event_device *)dev_id; | 134 | struct clock_event_device *evt = (struct clock_event_device *)dev_id; |
135 | struct timer_of *to = to_timer_of(evt); | ||
134 | 136 | ||
135 | sun4i_timer_clear_interrupt(); | 137 | sun4i_timer_clear_interrupt(timer_of_base(to)); |
136 | evt->event_handler(evt); | 138 | evt->event_handler(evt); |
137 | 139 | ||
138 | return IRQ_HANDLED; | 140 | return IRQ_HANDLED; |
139 | } | 141 | } |
140 | 142 | ||
141 | static struct irqaction sun4i_timer_irq = { | 143 | static struct timer_of to = { |
142 | .name = "sun4i_timer0", | 144 | .flags = TIMER_OF_IRQ | TIMER_OF_CLOCK | TIMER_OF_BASE, |
143 | .flags = IRQF_TIMER | IRQF_IRQPOLL, | 145 | |
144 | .handler = sun4i_timer_interrupt, | 146 | .clkevt = { |
145 | .dev_id = &sun4i_clockevent, | 147 | .name = "sun4i_tick", |
148 | .rating = 350, | ||
149 | .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT, | ||
150 | .set_state_shutdown = sun4i_clkevt_shutdown, | ||
151 | .set_state_periodic = sun4i_clkevt_set_periodic, | ||
152 | .set_state_oneshot = sun4i_clkevt_set_oneshot, | ||
153 | .tick_resume = sun4i_clkevt_shutdown, | ||
154 | .set_next_event = sun4i_clkevt_next_event, | ||
155 | .cpumask = cpu_possible_mask, | ||
156 | }, | ||
157 | |||
158 | .of_irq = { | ||
159 | .handler = sun4i_timer_interrupt, | ||
160 | .flags = IRQF_TIMER | IRQF_IRQPOLL, | ||
161 | }, | ||
146 | }; | 162 | }; |
147 | 163 | ||
148 | static u64 notrace sun4i_timer_sched_read(void) | 164 | static u64 notrace sun4i_timer_sched_read(void) |
149 | { | 165 | { |
150 | return ~readl(timer_base + TIMER_CNTVAL_REG(1)); | 166 | return ~readl(timer_of_base(&to) + TIMER_CNTVAL_REG(1)); |
151 | } | 167 | } |
152 | 168 | ||
153 | static int __init sun4i_timer_init(struct device_node *node) | 169 | static int __init sun4i_timer_init(struct device_node *node) |
154 | { | 170 | { |
155 | unsigned long rate = 0; | 171 | int ret; |
156 | struct clk *clk; | ||
157 | int ret, irq; | ||
158 | u32 val; | 172 | u32 val; |
159 | 173 | ||
160 | timer_base = of_iomap(node, 0); | 174 | ret = timer_of_init(node, &to); |
161 | if (!timer_base) { | 175 | if (ret) |
162 | pr_crit("Can't map registers\n"); | ||
163 | return -ENXIO; | ||
164 | } | ||
165 | |||
166 | irq = irq_of_parse_and_map(node, 0); | ||
167 | if (irq <= 0) { | ||
168 | pr_crit("Can't parse IRQ\n"); | ||
169 | return -EINVAL; | ||
170 | } | ||
171 | |||
172 | clk = of_clk_get(node, 0); | ||
173 | if (IS_ERR(clk)) { | ||
174 | pr_crit("Can't get timer clock\n"); | ||
175 | return PTR_ERR(clk); | ||
176 | } | ||
177 | |||
178 | ret = clk_prepare_enable(clk); | ||
179 | if (ret) { | ||
180 | pr_err("Failed to prepare clock\n"); | ||
181 | return ret; | 176 | return ret; |
182 | } | ||
183 | |||
184 | rate = clk_get_rate(clk); | ||
185 | 177 | ||
186 | writel(~0, timer_base + TIMER_INTVAL_REG(1)); | 178 | writel(~0, timer_of_base(&to) + TIMER_INTVAL_REG(1)); |
187 | writel(TIMER_CTL_ENABLE | TIMER_CTL_RELOAD | | 179 | writel(TIMER_CTL_ENABLE | TIMER_CTL_RELOAD | |
188 | TIMER_CTL_CLK_SRC(TIMER_CTL_CLK_SRC_OSC24M), | 180 | TIMER_CTL_CLK_SRC(TIMER_CTL_CLK_SRC_OSC24M), |
189 | timer_base + TIMER_CTL_REG(1)); | 181 | timer_of_base(&to) + TIMER_CTL_REG(1)); |
190 | 182 | ||
191 | /* | 183 | /* |
192 | * sched_clock_register does not have priorities, and on sun6i and | 184 | * sched_clock_register does not have priorities, and on sun6i and |
@@ -195,43 +187,34 @@ static int __init sun4i_timer_init(struct device_node *node) | |||
195 | if (of_machine_is_compatible("allwinner,sun4i-a10") || | 187 | if (of_machine_is_compatible("allwinner,sun4i-a10") || |
196 | of_machine_is_compatible("allwinner,sun5i-a13") || | 188 | of_machine_is_compatible("allwinner,sun5i-a13") || |
197 | of_machine_is_compatible("allwinner,sun5i-a10s")) | 189 | of_machine_is_compatible("allwinner,sun5i-a10s")) |
198 | sched_clock_register(sun4i_timer_sched_read, 32, rate); | 190 | sched_clock_register(sun4i_timer_sched_read, 32, |
191 | timer_of_rate(&to)); | ||
199 | 192 | ||
200 | ret = clocksource_mmio_init(timer_base + TIMER_CNTVAL_REG(1), node->name, | 193 | ret = clocksource_mmio_init(timer_of_base(&to) + TIMER_CNTVAL_REG(1), |
201 | rate, 350, 32, clocksource_mmio_readl_down); | 194 | node->name, timer_of_rate(&to), 350, 32, |
195 | clocksource_mmio_readl_down); | ||
202 | if (ret) { | 196 | if (ret) { |
203 | pr_err("Failed to register clocksource\n"); | 197 | pr_err("Failed to register clocksource\n"); |
204 | return ret; | 198 | return ret; |
205 | } | 199 | } |
206 | 200 | ||
207 | ticks_per_jiffy = DIV_ROUND_UP(rate, HZ); | ||
208 | |||
209 | writel(TIMER_CTL_CLK_SRC(TIMER_CTL_CLK_SRC_OSC24M), | 201 | writel(TIMER_CTL_CLK_SRC(TIMER_CTL_CLK_SRC_OSC24M), |
210 | timer_base + TIMER_CTL_REG(0)); | 202 | timer_of_base(&to) + TIMER_CTL_REG(0)); |
211 | 203 | ||
212 | /* Make sure timer is stopped before playing with interrupts */ | 204 | /* Make sure timer is stopped before playing with interrupts */ |
213 | sun4i_clkevt_time_stop(0); | 205 | sun4i_clkevt_time_stop(timer_of_base(&to), 0); |
214 | 206 | ||
215 | /* clear timer0 interrupt */ | 207 | /* clear timer0 interrupt */ |
216 | sun4i_timer_clear_interrupt(); | 208 | sun4i_timer_clear_interrupt(timer_of_base(&to)); |
217 | |||
218 | sun4i_clockevent.cpumask = cpu_possible_mask; | ||
219 | sun4i_clockevent.irq = irq; | ||
220 | 209 | ||
221 | clockevents_config_and_register(&sun4i_clockevent, rate, | 210 | clockevents_config_and_register(&to.clkevt, timer_of_rate(&to), |
222 | TIMER_SYNC_TICKS, 0xffffffff); | 211 | TIMER_SYNC_TICKS, 0xffffffff); |
223 | 212 | ||
224 | ret = setup_irq(irq, &sun4i_timer_irq); | ||
225 | if (ret) { | ||
226 | pr_err("failed to setup irq %d\n", irq); | ||
227 | return ret; | ||
228 | } | ||
229 | |||
230 | /* Enable timer0 interrupt */ | 213 | /* Enable timer0 interrupt */ |
231 | val = readl(timer_base + TIMER_IRQ_EN_REG); | 214 | val = readl(timer_of_base(&to) + TIMER_IRQ_EN_REG); |
232 | writel(val | TIMER_IRQ_EN(0), timer_base + TIMER_IRQ_EN_REG); | 215 | writel(val | TIMER_IRQ_EN(0), timer_of_base(&to) + TIMER_IRQ_EN_REG); |
233 | 216 | ||
234 | return ret; | 217 | return ret; |
235 | } | 218 | } |
236 | CLOCKSOURCE_OF_DECLARE(sun4i, "allwinner,sun4i-a10-timer", | 219 | TIMER_OF_DECLARE(sun4i, "allwinner,sun4i-a10-timer", |
237 | sun4i_timer_init); | 220 | sun4i_timer_init); |
diff --git a/drivers/clocksource/tango_xtal.c b/drivers/clocksource/tango_xtal.c index 12fcef8cf2d3..c4e1c2e6046f 100644 --- a/drivers/clocksource/tango_xtal.c +++ b/drivers/clocksource/tango_xtal.c | |||
@@ -53,4 +53,4 @@ static int __init tango_clocksource_init(struct device_node *np) | |||
53 | return 0; | 53 | return 0; |
54 | } | 54 | } |
55 | 55 | ||
56 | CLOCKSOURCE_OF_DECLARE(tango, "sigma,tick-counter", tango_clocksource_init); | 56 | TIMER_OF_DECLARE(tango, "sigma,tick-counter", tango_clocksource_init); |
diff --git a/drivers/clocksource/tcb_clksrc.c b/drivers/clocksource/tcb_clksrc.c index d4ca9962a759..59e8aee0ec16 100644 --- a/drivers/clocksource/tcb_clksrc.c +++ b/drivers/clocksource/tcb_clksrc.c | |||
@@ -9,6 +9,7 @@ | |||
9 | #include <linux/ioport.h> | 9 | #include <linux/ioport.h> |
10 | #include <linux/io.h> | 10 | #include <linux/io.h> |
11 | #include <linux/platform_device.h> | 11 | #include <linux/platform_device.h> |
12 | #include <linux/syscore_ops.h> | ||
12 | #include <linux/atmel_tc.h> | 13 | #include <linux/atmel_tc.h> |
13 | 14 | ||
14 | 15 | ||
@@ -40,6 +41,14 @@ | |||
40 | */ | 41 | */ |
41 | 42 | ||
42 | static void __iomem *tcaddr; | 43 | static void __iomem *tcaddr; |
44 | static struct | ||
45 | { | ||
46 | u32 cmr; | ||
47 | u32 imr; | ||
48 | u32 rc; | ||
49 | bool clken; | ||
50 | } tcb_cache[3]; | ||
51 | static u32 bmr_cache; | ||
43 | 52 | ||
44 | static u64 tc_get_cycles(struct clocksource *cs) | 53 | static u64 tc_get_cycles(struct clocksource *cs) |
45 | { | 54 | { |
@@ -48,9 +57,9 @@ static u64 tc_get_cycles(struct clocksource *cs) | |||
48 | 57 | ||
49 | raw_local_irq_save(flags); | 58 | raw_local_irq_save(flags); |
50 | do { | 59 | do { |
51 | upper = __raw_readl(tcaddr + ATMEL_TC_REG(1, CV)); | 60 | upper = readl_relaxed(tcaddr + ATMEL_TC_REG(1, CV)); |
52 | lower = __raw_readl(tcaddr + ATMEL_TC_REG(0, CV)); | 61 | lower = readl_relaxed(tcaddr + ATMEL_TC_REG(0, CV)); |
53 | } while (upper != __raw_readl(tcaddr + ATMEL_TC_REG(1, CV))); | 62 | } while (upper != readl_relaxed(tcaddr + ATMEL_TC_REG(1, CV))); |
54 | 63 | ||
55 | raw_local_irq_restore(flags); | 64 | raw_local_irq_restore(flags); |
56 | return (upper << 16) | lower; | 65 | return (upper << 16) | lower; |
@@ -58,7 +67,47 @@ static u64 tc_get_cycles(struct clocksource *cs) | |||
58 | 67 | ||
59 | static u64 tc_get_cycles32(struct clocksource *cs) | 68 | static u64 tc_get_cycles32(struct clocksource *cs) |
60 | { | 69 | { |
61 | return __raw_readl(tcaddr + ATMEL_TC_REG(0, CV)); | 70 | return readl_relaxed(tcaddr + ATMEL_TC_REG(0, CV)); |
71 | } | ||
72 | |||
73 | void tc_clksrc_suspend(struct clocksource *cs) | ||
74 | { | ||
75 | int i; | ||
76 | |||
77 | for (i = 0; i < ARRAY_SIZE(tcb_cache); i++) { | ||
78 | tcb_cache[i].cmr = readl(tcaddr + ATMEL_TC_REG(i, CMR)); | ||
79 | tcb_cache[i].imr = readl(tcaddr + ATMEL_TC_REG(i, IMR)); | ||
80 | tcb_cache[i].rc = readl(tcaddr + ATMEL_TC_REG(i, RC)); | ||
81 | tcb_cache[i].clken = !!(readl(tcaddr + ATMEL_TC_REG(i, SR)) & | ||
82 | ATMEL_TC_CLKSTA); | ||
83 | } | ||
84 | |||
85 | bmr_cache = readl(tcaddr + ATMEL_TC_BMR); | ||
86 | } | ||
87 | |||
88 | void tc_clksrc_resume(struct clocksource *cs) | ||
89 | { | ||
90 | int i; | ||
91 | |||
92 | for (i = 0; i < ARRAY_SIZE(tcb_cache); i++) { | ||
93 | /* Restore registers for the channel, RA and RB are not used */ | ||
94 | writel(tcb_cache[i].cmr, tcaddr + ATMEL_TC_REG(i, CMR)); | ||
95 | writel(tcb_cache[i].rc, tcaddr + ATMEL_TC_REG(i, RC)); | ||
96 | writel(0, tcaddr + ATMEL_TC_REG(i, RA)); | ||
97 | writel(0, tcaddr + ATMEL_TC_REG(i, RB)); | ||
98 | /* Disable all the interrupts */ | ||
99 | writel(0xff, tcaddr + ATMEL_TC_REG(i, IDR)); | ||
100 | /* Reenable interrupts that were enabled before suspending */ | ||
101 | writel(tcb_cache[i].imr, tcaddr + ATMEL_TC_REG(i, IER)); | ||
102 | /* Start the clock if it was used */ | ||
103 | if (tcb_cache[i].clken) | ||
104 | writel(ATMEL_TC_CLKEN, tcaddr + ATMEL_TC_REG(i, CCR)); | ||
105 | } | ||
106 | |||
107 | /* Dual channel, chain channels */ | ||
108 | writel(bmr_cache, tcaddr + ATMEL_TC_BMR); | ||
109 | /* Finally, trigger all the channels*/ | ||
110 | writel(ATMEL_TC_SYNC, tcaddr + ATMEL_TC_BCR); | ||
62 | } | 111 | } |
63 | 112 | ||
64 | static struct clocksource clksrc = { | 113 | static struct clocksource clksrc = { |
@@ -67,6 +116,8 @@ static struct clocksource clksrc = { | |||
67 | .read = tc_get_cycles, | 116 | .read = tc_get_cycles, |
68 | .mask = CLOCKSOURCE_MASK(32), | 117 | .mask = CLOCKSOURCE_MASK(32), |
69 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, | 118 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, |
119 | .suspend = tc_clksrc_suspend, | ||
120 | .resume = tc_clksrc_resume, | ||
70 | }; | 121 | }; |
71 | 122 | ||
72 | #ifdef CONFIG_GENERIC_CLOCKEVENTS | 123 | #ifdef CONFIG_GENERIC_CLOCKEVENTS |
@@ -96,8 +147,8 @@ static int tc_shutdown(struct clock_event_device *d) | |||
96 | struct tc_clkevt_device *tcd = to_tc_clkevt(d); | 147 | struct tc_clkevt_device *tcd = to_tc_clkevt(d); |
97 | void __iomem *regs = tcd->regs; | 148 | void __iomem *regs = tcd->regs; |
98 | 149 | ||
99 | __raw_writel(0xff, regs + ATMEL_TC_REG(2, IDR)); | 150 | writel(0xff, regs + ATMEL_TC_REG(2, IDR)); |
100 | __raw_writel(ATMEL_TC_CLKDIS, regs + ATMEL_TC_REG(2, CCR)); | 151 | writel(ATMEL_TC_CLKDIS, regs + ATMEL_TC_REG(2, CCR)); |
101 | if (!clockevent_state_detached(d)) | 152 | if (!clockevent_state_detached(d)) |
102 | clk_disable(tcd->clk); | 153 | clk_disable(tcd->clk); |
103 | 154 | ||
@@ -115,9 +166,9 @@ static int tc_set_oneshot(struct clock_event_device *d) | |||
115 | clk_enable(tcd->clk); | 166 | clk_enable(tcd->clk); |
116 | 167 | ||
117 | /* slow clock, count up to RC, then irq and stop */ | 168 | /* slow clock, count up to RC, then irq and stop */ |
118 | __raw_writel(timer_clock | ATMEL_TC_CPCSTOP | ATMEL_TC_WAVE | | 169 | writel(timer_clock | ATMEL_TC_CPCSTOP | ATMEL_TC_WAVE | |
119 | ATMEL_TC_WAVESEL_UP_AUTO, regs + ATMEL_TC_REG(2, CMR)); | 170 | ATMEL_TC_WAVESEL_UP_AUTO, regs + ATMEL_TC_REG(2, CMR)); |
120 | __raw_writel(ATMEL_TC_CPCS, regs + ATMEL_TC_REG(2, IER)); | 171 | writel(ATMEL_TC_CPCS, regs + ATMEL_TC_REG(2, IER)); |
121 | 172 | ||
122 | /* set_next_event() configures and starts the timer */ | 173 | /* set_next_event() configures and starts the timer */ |
123 | return 0; | 174 | return 0; |
@@ -137,25 +188,25 @@ static int tc_set_periodic(struct clock_event_device *d) | |||
137 | clk_enable(tcd->clk); | 188 | clk_enable(tcd->clk); |
138 | 189 | ||
139 | /* slow clock, count up to RC, then irq and restart */ | 190 | /* slow clock, count up to RC, then irq and restart */ |
140 | __raw_writel(timer_clock | ATMEL_TC_WAVE | ATMEL_TC_WAVESEL_UP_AUTO, | 191 | writel(timer_clock | ATMEL_TC_WAVE | ATMEL_TC_WAVESEL_UP_AUTO, |
141 | regs + ATMEL_TC_REG(2, CMR)); | 192 | regs + ATMEL_TC_REG(2, CMR)); |
142 | __raw_writel((32768 + HZ / 2) / HZ, tcaddr + ATMEL_TC_REG(2, RC)); | 193 | writel((32768 + HZ / 2) / HZ, tcaddr + ATMEL_TC_REG(2, RC)); |
143 | 194 | ||
144 | /* Enable clock and interrupts on RC compare */ | 195 | /* Enable clock and interrupts on RC compare */ |
145 | __raw_writel(ATMEL_TC_CPCS, regs + ATMEL_TC_REG(2, IER)); | 196 | writel(ATMEL_TC_CPCS, regs + ATMEL_TC_REG(2, IER)); |
146 | 197 | ||
147 | /* go go gadget! */ | 198 | /* go go gadget! */ |
148 | __raw_writel(ATMEL_TC_CLKEN | ATMEL_TC_SWTRG, regs + | 199 | writel(ATMEL_TC_CLKEN | ATMEL_TC_SWTRG, regs + |
149 | ATMEL_TC_REG(2, CCR)); | 200 | ATMEL_TC_REG(2, CCR)); |
150 | return 0; | 201 | return 0; |
151 | } | 202 | } |
152 | 203 | ||
153 | static int tc_next_event(unsigned long delta, struct clock_event_device *d) | 204 | static int tc_next_event(unsigned long delta, struct clock_event_device *d) |
154 | { | 205 | { |
155 | __raw_writel(delta, tcaddr + ATMEL_TC_REG(2, RC)); | 206 | writel_relaxed(delta, tcaddr + ATMEL_TC_REG(2, RC)); |
156 | 207 | ||
157 | /* go go gadget! */ | 208 | /* go go gadget! */ |
158 | __raw_writel(ATMEL_TC_CLKEN | ATMEL_TC_SWTRG, | 209 | writel_relaxed(ATMEL_TC_CLKEN | ATMEL_TC_SWTRG, |
159 | tcaddr + ATMEL_TC_REG(2, CCR)); | 210 | tcaddr + ATMEL_TC_REG(2, CCR)); |
160 | return 0; | 211 | return 0; |
161 | } | 212 | } |
@@ -179,7 +230,7 @@ static irqreturn_t ch2_irq(int irq, void *handle) | |||
179 | struct tc_clkevt_device *dev = handle; | 230 | struct tc_clkevt_device *dev = handle; |
180 | unsigned int sr; | 231 | unsigned int sr; |
181 | 232 | ||
182 | sr = __raw_readl(dev->regs + ATMEL_TC_REG(2, SR)); | 233 | sr = readl_relaxed(dev->regs + ATMEL_TC_REG(2, SR)); |
183 | if (sr & ATMEL_TC_CPCS) { | 234 | if (sr & ATMEL_TC_CPCS) { |
184 | dev->clkevt.event_handler(&dev->clkevt); | 235 | dev->clkevt.event_handler(&dev->clkevt); |
185 | return IRQ_HANDLED; | 236 | return IRQ_HANDLED; |
@@ -239,43 +290,43 @@ static int __init setup_clkevents(struct atmel_tc *tc, int clk32k_divisor_idx) | |||
239 | static void __init tcb_setup_dual_chan(struct atmel_tc *tc, int mck_divisor_idx) | 290 | static void __init tcb_setup_dual_chan(struct atmel_tc *tc, int mck_divisor_idx) |
240 | { | 291 | { |
241 | /* channel 0: waveform mode, input mclk/8, clock TIOA0 on overflow */ | 292 | /* channel 0: waveform mode, input mclk/8, clock TIOA0 on overflow */ |
242 | __raw_writel(mck_divisor_idx /* likely divide-by-8 */ | 293 | writel(mck_divisor_idx /* likely divide-by-8 */ |
243 | | ATMEL_TC_WAVE | 294 | | ATMEL_TC_WAVE |
244 | | ATMEL_TC_WAVESEL_UP /* free-run */ | 295 | | ATMEL_TC_WAVESEL_UP /* free-run */ |
245 | | ATMEL_TC_ACPA_SET /* TIOA0 rises at 0 */ | 296 | | ATMEL_TC_ACPA_SET /* TIOA0 rises at 0 */ |
246 | | ATMEL_TC_ACPC_CLEAR, /* (duty cycle 50%) */ | 297 | | ATMEL_TC_ACPC_CLEAR, /* (duty cycle 50%) */ |
247 | tcaddr + ATMEL_TC_REG(0, CMR)); | 298 | tcaddr + ATMEL_TC_REG(0, CMR)); |
248 | __raw_writel(0x0000, tcaddr + ATMEL_TC_REG(0, RA)); | 299 | writel(0x0000, tcaddr + ATMEL_TC_REG(0, RA)); |
249 | __raw_writel(0x8000, tcaddr + ATMEL_TC_REG(0, RC)); | 300 | writel(0x8000, tcaddr + ATMEL_TC_REG(0, RC)); |
250 | __raw_writel(0xff, tcaddr + ATMEL_TC_REG(0, IDR)); /* no irqs */ | 301 | writel(0xff, tcaddr + ATMEL_TC_REG(0, IDR)); /* no irqs */ |
251 | __raw_writel(ATMEL_TC_CLKEN, tcaddr + ATMEL_TC_REG(0, CCR)); | 302 | writel(ATMEL_TC_CLKEN, tcaddr + ATMEL_TC_REG(0, CCR)); |
252 | 303 | ||
253 | /* channel 1: waveform mode, input TIOA0 */ | 304 | /* channel 1: waveform mode, input TIOA0 */ |
254 | __raw_writel(ATMEL_TC_XC1 /* input: TIOA0 */ | 305 | writel(ATMEL_TC_XC1 /* input: TIOA0 */ |
255 | | ATMEL_TC_WAVE | 306 | | ATMEL_TC_WAVE |
256 | | ATMEL_TC_WAVESEL_UP, /* free-run */ | 307 | | ATMEL_TC_WAVESEL_UP, /* free-run */ |
257 | tcaddr + ATMEL_TC_REG(1, CMR)); | 308 | tcaddr + ATMEL_TC_REG(1, CMR)); |
258 | __raw_writel(0xff, tcaddr + ATMEL_TC_REG(1, IDR)); /* no irqs */ | 309 | writel(0xff, tcaddr + ATMEL_TC_REG(1, IDR)); /* no irqs */ |
259 | __raw_writel(ATMEL_TC_CLKEN, tcaddr + ATMEL_TC_REG(1, CCR)); | 310 | writel(ATMEL_TC_CLKEN, tcaddr + ATMEL_TC_REG(1, CCR)); |
260 | 311 | ||
261 | /* chain channel 0 to channel 1*/ | 312 | /* chain channel 0 to channel 1*/ |
262 | __raw_writel(ATMEL_TC_TC1XC1S_TIOA0, tcaddr + ATMEL_TC_BMR); | 313 | writel(ATMEL_TC_TC1XC1S_TIOA0, tcaddr + ATMEL_TC_BMR); |
263 | /* then reset all the timers */ | 314 | /* then reset all the timers */ |
264 | __raw_writel(ATMEL_TC_SYNC, tcaddr + ATMEL_TC_BCR); | 315 | writel(ATMEL_TC_SYNC, tcaddr + ATMEL_TC_BCR); |
265 | } | 316 | } |
266 | 317 | ||
267 | static void __init tcb_setup_single_chan(struct atmel_tc *tc, int mck_divisor_idx) | 318 | static void __init tcb_setup_single_chan(struct atmel_tc *tc, int mck_divisor_idx) |
268 | { | 319 | { |
269 | /* channel 0: waveform mode, input mclk/8 */ | 320 | /* channel 0: waveform mode, input mclk/8 */ |
270 | __raw_writel(mck_divisor_idx /* likely divide-by-8 */ | 321 | writel(mck_divisor_idx /* likely divide-by-8 */ |
271 | | ATMEL_TC_WAVE | 322 | | ATMEL_TC_WAVE |
272 | | ATMEL_TC_WAVESEL_UP, /* free-run */ | 323 | | ATMEL_TC_WAVESEL_UP, /* free-run */ |
273 | tcaddr + ATMEL_TC_REG(0, CMR)); | 324 | tcaddr + ATMEL_TC_REG(0, CMR)); |
274 | __raw_writel(0xff, tcaddr + ATMEL_TC_REG(0, IDR)); /* no irqs */ | 325 | writel(0xff, tcaddr + ATMEL_TC_REG(0, IDR)); /* no irqs */ |
275 | __raw_writel(ATMEL_TC_CLKEN, tcaddr + ATMEL_TC_REG(0, CCR)); | 326 | writel(ATMEL_TC_CLKEN, tcaddr + ATMEL_TC_REG(0, CCR)); |
276 | 327 | ||
277 | /* then reset all the timers */ | 328 | /* then reset all the timers */ |
278 | __raw_writel(ATMEL_TC_SYNC, tcaddr + ATMEL_TC_BCR); | 329 | writel(ATMEL_TC_SYNC, tcaddr + ATMEL_TC_BCR); |
279 | } | 330 | } |
280 | 331 | ||
281 | static int __init tcb_clksrc_init(void) | 332 | static int __init tcb_clksrc_init(void) |
diff --git a/drivers/clocksource/tegra20_timer.c b/drivers/clocksource/tegra20_timer.c index b9990b9c98c5..c337a8100a7b 100644 --- a/drivers/clocksource/tegra20_timer.c +++ b/drivers/clocksource/tegra20_timer.c | |||
@@ -237,7 +237,7 @@ static int __init tegra20_init_timer(struct device_node *np) | |||
237 | 237 | ||
238 | return 0; | 238 | return 0; |
239 | } | 239 | } |
240 | CLOCKSOURCE_OF_DECLARE(tegra20_timer, "nvidia,tegra20-timer", tegra20_init_timer); | 240 | TIMER_OF_DECLARE(tegra20_timer, "nvidia,tegra20-timer", tegra20_init_timer); |
241 | 241 | ||
242 | static int __init tegra20_init_rtc(struct device_node *np) | 242 | static int __init tegra20_init_rtc(struct device_node *np) |
243 | { | 243 | { |
@@ -261,4 +261,4 @@ static int __init tegra20_init_rtc(struct device_node *np) | |||
261 | 261 | ||
262 | return register_persistent_clock(NULL, tegra_read_persistent_clock64); | 262 | return register_persistent_clock(NULL, tegra_read_persistent_clock64); |
263 | } | 263 | } |
264 | CLOCKSOURCE_OF_DECLARE(tegra20_rtc, "nvidia,tegra20-rtc", tegra20_init_rtc); | 264 | TIMER_OF_DECLARE(tegra20_rtc, "nvidia,tegra20-rtc", tegra20_init_rtc); |
diff --git a/drivers/clocksource/time-armada-370-xp.c b/drivers/clocksource/time-armada-370-xp.c index aea4380129ea..edf1a46269f1 100644 --- a/drivers/clocksource/time-armada-370-xp.c +++ b/drivers/clocksource/time-armada-370-xp.c | |||
@@ -351,7 +351,7 @@ static int __init armada_xp_timer_init(struct device_node *np) | |||
351 | 351 | ||
352 | return armada_370_xp_timer_common_init(np); | 352 | return armada_370_xp_timer_common_init(np); |
353 | } | 353 | } |
354 | CLOCKSOURCE_OF_DECLARE(armada_xp, "marvell,armada-xp-timer", | 354 | TIMER_OF_DECLARE(armada_xp, "marvell,armada-xp-timer", |
355 | armada_xp_timer_init); | 355 | armada_xp_timer_init); |
356 | 356 | ||
357 | static int __init armada_375_timer_init(struct device_node *np) | 357 | static int __init armada_375_timer_init(struct device_node *np) |
@@ -389,7 +389,7 @@ static int __init armada_375_timer_init(struct device_node *np) | |||
389 | 389 | ||
390 | return armada_370_xp_timer_common_init(np); | 390 | return armada_370_xp_timer_common_init(np); |
391 | } | 391 | } |
392 | CLOCKSOURCE_OF_DECLARE(armada_375, "marvell,armada-375-timer", | 392 | TIMER_OF_DECLARE(armada_375, "marvell,armada-375-timer", |
393 | armada_375_timer_init); | 393 | armada_375_timer_init); |
394 | 394 | ||
395 | static int __init armada_370_timer_init(struct device_node *np) | 395 | static int __init armada_370_timer_init(struct device_node *np) |
@@ -412,5 +412,5 @@ static int __init armada_370_timer_init(struct device_node *np) | |||
412 | 412 | ||
413 | return armada_370_xp_timer_common_init(np); | 413 | return armada_370_xp_timer_common_init(np); |
414 | } | 414 | } |
415 | CLOCKSOURCE_OF_DECLARE(armada_370, "marvell,armada-370-timer", | 415 | TIMER_OF_DECLARE(armada_370, "marvell,armada-370-timer", |
416 | armada_370_timer_init); | 416 | armada_370_timer_init); |
diff --git a/drivers/clocksource/time-efm32.c b/drivers/clocksource/time-efm32.c index ce0f97b4e5db..257e810ec1ad 100644 --- a/drivers/clocksource/time-efm32.c +++ b/drivers/clocksource/time-efm32.c | |||
@@ -283,5 +283,5 @@ static int __init efm32_timer_init(struct device_node *np) | |||
283 | 283 | ||
284 | return ret; | 284 | return ret; |
285 | } | 285 | } |
286 | CLOCKSOURCE_OF_DECLARE(efm32compat, "efm32,timer", efm32_timer_init); | 286 | TIMER_OF_DECLARE(efm32compat, "efm32,timer", efm32_timer_init); |
287 | CLOCKSOURCE_OF_DECLARE(efm32, "energymicro,efm32-timer", efm32_timer_init); | 287 | TIMER_OF_DECLARE(efm32, "energymicro,efm32-timer", efm32_timer_init); |
diff --git a/drivers/clocksource/time-lpc32xx.c b/drivers/clocksource/time-lpc32xx.c index 9649cfdb9213..d51a62a79ef7 100644 --- a/drivers/clocksource/time-lpc32xx.c +++ b/drivers/clocksource/time-lpc32xx.c | |||
@@ -311,4 +311,4 @@ static int __init lpc32xx_timer_init(struct device_node *np) | |||
311 | 311 | ||
312 | return ret; | 312 | return ret; |
313 | } | 313 | } |
314 | CLOCKSOURCE_OF_DECLARE(lpc32xx_timer, "nxp,lpc3220-timer", lpc32xx_timer_init); | 314 | TIMER_OF_DECLARE(lpc32xx_timer, "nxp,lpc3220-timer", lpc32xx_timer_init); |
diff --git a/drivers/clocksource/time-orion.c b/drivers/clocksource/time-orion.c index b9b97f630c4d..12202067fe4b 100644 --- a/drivers/clocksource/time-orion.c +++ b/drivers/clocksource/time-orion.c | |||
@@ -189,4 +189,4 @@ static int __init orion_timer_init(struct device_node *np) | |||
189 | 189 | ||
190 | return 0; | 190 | return 0; |
191 | } | 191 | } |
192 | CLOCKSOURCE_OF_DECLARE(orion_timer, "marvell,orion-timer", orion_timer_init); | 192 | TIMER_OF_DECLARE(orion_timer, "marvell,orion-timer", orion_timer_init); |
diff --git a/drivers/clocksource/time-pistachio.c b/drivers/clocksource/time-pistachio.c index 3710e4d9dcba..a2dd85d0c1d7 100644 --- a/drivers/clocksource/time-pistachio.c +++ b/drivers/clocksource/time-pistachio.c | |||
@@ -214,5 +214,5 @@ static int __init pistachio_clksrc_of_init(struct device_node *node) | |||
214 | sched_clock_register(pistachio_read_sched_clock, 32, rate); | 214 | sched_clock_register(pistachio_read_sched_clock, 32, rate); |
215 | return clocksource_register_hz(&pcs_gpt.cs, rate); | 215 | return clocksource_register_hz(&pcs_gpt.cs, rate); |
216 | } | 216 | } |
217 | CLOCKSOURCE_OF_DECLARE(pistachio_gptimer, "img,pistachio-gptimer", | 217 | TIMER_OF_DECLARE(pistachio_gptimer, "img,pistachio-gptimer", |
218 | pistachio_clksrc_of_init); | 218 | pistachio_clksrc_of_init); |
diff --git a/drivers/clocksource/timer-atlas7.c b/drivers/clocksource/timer-atlas7.c index 50300eec4a39..62c4bbc55a7e 100644 --- a/drivers/clocksource/timer-atlas7.c +++ b/drivers/clocksource/timer-atlas7.c | |||
@@ -283,4 +283,4 @@ static int __init sirfsoc_of_timer_init(struct device_node *np) | |||
283 | 283 | ||
284 | return sirfsoc_atlas7_timer_init(np); | 284 | return sirfsoc_atlas7_timer_init(np); |
285 | } | 285 | } |
286 | CLOCKSOURCE_OF_DECLARE(sirfsoc_atlas7_timer, "sirf,atlas7-tick", sirfsoc_of_timer_init); | 286 | TIMER_OF_DECLARE(sirfsoc_atlas7_timer, "sirf,atlas7-tick", sirfsoc_of_timer_init); |
diff --git a/drivers/clocksource/timer-atmel-pit.c b/drivers/clocksource/timer-atmel-pit.c index cc112351dc70..ec8a4376f74f 100644 --- a/drivers/clocksource/timer-atmel-pit.c +++ b/drivers/clocksource/timer-atmel-pit.c | |||
@@ -255,5 +255,5 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node) | |||
255 | 255 | ||
256 | return 0; | 256 | return 0; |
257 | } | 257 | } |
258 | CLOCKSOURCE_OF_DECLARE(at91sam926x_pit, "atmel,at91sam9260-pit", | 258 | TIMER_OF_DECLARE(at91sam926x_pit, "atmel,at91sam9260-pit", |
259 | at91sam926x_pit_dt_init); | 259 | at91sam926x_pit_dt_init); |
diff --git a/drivers/clocksource/timer-atmel-st.c b/drivers/clocksource/timer-atmel-st.c index be4ac7604136..d2e660f475af 100644 --- a/drivers/clocksource/timer-atmel-st.c +++ b/drivers/clocksource/timer-atmel-st.c | |||
@@ -260,5 +260,5 @@ static int __init atmel_st_timer_init(struct device_node *node) | |||
260 | /* register clocksource */ | 260 | /* register clocksource */ |
261 | return clocksource_register_hz(&clk32k, sclk_rate); | 261 | return clocksource_register_hz(&clk32k, sclk_rate); |
262 | } | 262 | } |
263 | CLOCKSOURCE_OF_DECLARE(atmel_st_timer, "atmel,at91rm9200-st", | 263 | TIMER_OF_DECLARE(atmel_st_timer, "atmel,at91rm9200-st", |
264 | atmel_st_timer_init); | 264 | atmel_st_timer_init); |
diff --git a/drivers/clocksource/timer-digicolor.c b/drivers/clocksource/timer-digicolor.c index 94a161eb9cce..1e984a4d8ad0 100644 --- a/drivers/clocksource/timer-digicolor.c +++ b/drivers/clocksource/timer-digicolor.c | |||
@@ -203,5 +203,5 @@ static int __init digicolor_timer_init(struct device_node *node) | |||
203 | 203 | ||
204 | return 0; | 204 | return 0; |
205 | } | 205 | } |
206 | CLOCKSOURCE_OF_DECLARE(conexant_digicolor, "cnxt,cx92755-timer", | 206 | TIMER_OF_DECLARE(conexant_digicolor, "cnxt,cx92755-timer", |
207 | digicolor_timer_init); | 207 | digicolor_timer_init); |
diff --git a/drivers/clocksource/timer-fttmr010.c b/drivers/clocksource/timer-fttmr010.c index b4a6f1e4bc54..66dd909960c6 100644 --- a/drivers/clocksource/timer-fttmr010.c +++ b/drivers/clocksource/timer-fttmr010.c | |||
@@ -11,12 +11,13 @@ | |||
11 | #include <linux/of.h> | 11 | #include <linux/of.h> |
12 | #include <linux/of_address.h> | 12 | #include <linux/of_address.h> |
13 | #include <linux/of_irq.h> | 13 | #include <linux/of_irq.h> |
14 | #include <linux/mfd/syscon.h> | ||
15 | #include <linux/regmap.h> | ||
16 | #include <linux/clockchips.h> | 14 | #include <linux/clockchips.h> |
17 | #include <linux/clocksource.h> | 15 | #include <linux/clocksource.h> |
18 | #include <linux/sched_clock.h> | 16 | #include <linux/sched_clock.h> |
19 | #include <linux/clk.h> | 17 | #include <linux/clk.h> |
18 | #include <linux/slab.h> | ||
19 | #include <linux/bitops.h> | ||
20 | #include <linux/delay.h> | ||
20 | 21 | ||
21 | /* | 22 | /* |
22 | * Register definitions for the timers | 23 | * Register definitions for the timers |
@@ -37,267 +38,368 @@ | |||
37 | #define TIMER_INTR_STATE (0x34) | 38 | #define TIMER_INTR_STATE (0x34) |
38 | #define TIMER_INTR_MASK (0x38) | 39 | #define TIMER_INTR_MASK (0x38) |
39 | 40 | ||
40 | #define TIMER_1_CR_ENABLE (1 << 0) | 41 | #define TIMER_1_CR_ENABLE BIT(0) |
41 | #define TIMER_1_CR_CLOCK (1 << 1) | 42 | #define TIMER_1_CR_CLOCK BIT(1) |
42 | #define TIMER_1_CR_INT (1 << 2) | 43 | #define TIMER_1_CR_INT BIT(2) |
43 | #define TIMER_2_CR_ENABLE (1 << 3) | 44 | #define TIMER_2_CR_ENABLE BIT(3) |
44 | #define TIMER_2_CR_CLOCK (1 << 4) | 45 | #define TIMER_2_CR_CLOCK BIT(4) |
45 | #define TIMER_2_CR_INT (1 << 5) | 46 | #define TIMER_2_CR_INT BIT(5) |
46 | #define TIMER_3_CR_ENABLE (1 << 6) | 47 | #define TIMER_3_CR_ENABLE BIT(6) |
47 | #define TIMER_3_CR_CLOCK (1 << 7) | 48 | #define TIMER_3_CR_CLOCK BIT(7) |
48 | #define TIMER_3_CR_INT (1 << 8) | 49 | #define TIMER_3_CR_INT BIT(8) |
49 | #define TIMER_1_CR_UPDOWN (1 << 9) | 50 | #define TIMER_1_CR_UPDOWN BIT(9) |
50 | #define TIMER_2_CR_UPDOWN (1 << 10) | 51 | #define TIMER_2_CR_UPDOWN BIT(10) |
51 | #define TIMER_3_CR_UPDOWN (1 << 11) | 52 | #define TIMER_3_CR_UPDOWN BIT(11) |
52 | #define TIMER_DEFAULT_FLAGS (TIMER_1_CR_UPDOWN | \ | 53 | |
53 | TIMER_3_CR_ENABLE | \ | 54 | /* |
54 | TIMER_3_CR_UPDOWN) | 55 | * The Aspeed AST2400 moves bits around in the control register |
55 | 56 | * and lacks bits for setting the timer to count upwards. | |
56 | #define TIMER_1_INT_MATCH1 (1 << 0) | 57 | */ |
57 | #define TIMER_1_INT_MATCH2 (1 << 1) | 58 | #define TIMER_1_CR_ASPEED_ENABLE BIT(0) |
58 | #define TIMER_1_INT_OVERFLOW (1 << 2) | 59 | #define TIMER_1_CR_ASPEED_CLOCK BIT(1) |
59 | #define TIMER_2_INT_MATCH1 (1 << 3) | 60 | #define TIMER_1_CR_ASPEED_INT BIT(2) |
60 | #define TIMER_2_INT_MATCH2 (1 << 4) | 61 | #define TIMER_2_CR_ASPEED_ENABLE BIT(4) |
61 | #define TIMER_2_INT_OVERFLOW (1 << 5) | 62 | #define TIMER_2_CR_ASPEED_CLOCK BIT(5) |
62 | #define TIMER_3_INT_MATCH1 (1 << 6) | 63 | #define TIMER_2_CR_ASPEED_INT BIT(6) |
63 | #define TIMER_3_INT_MATCH2 (1 << 7) | 64 | #define TIMER_3_CR_ASPEED_ENABLE BIT(8) |
64 | #define TIMER_3_INT_OVERFLOW (1 << 8) | 65 | #define TIMER_3_CR_ASPEED_CLOCK BIT(9) |
66 | #define TIMER_3_CR_ASPEED_INT BIT(10) | ||
67 | |||
68 | #define TIMER_1_INT_MATCH1 BIT(0) | ||
69 | #define TIMER_1_INT_MATCH2 BIT(1) | ||
70 | #define TIMER_1_INT_OVERFLOW BIT(2) | ||
71 | #define TIMER_2_INT_MATCH1 BIT(3) | ||
72 | #define TIMER_2_INT_MATCH2 BIT(4) | ||
73 | #define TIMER_2_INT_OVERFLOW BIT(5) | ||
74 | #define TIMER_3_INT_MATCH1 BIT(6) | ||
75 | #define TIMER_3_INT_MATCH2 BIT(7) | ||
76 | #define TIMER_3_INT_OVERFLOW BIT(8) | ||
65 | #define TIMER_INT_ALL_MASK 0x1ff | 77 | #define TIMER_INT_ALL_MASK 0x1ff |
66 | 78 | ||
67 | static unsigned int tick_rate; | 79 | struct fttmr010 { |
68 | static void __iomem *base; | 80 | void __iomem *base; |
81 | unsigned int tick_rate; | ||
82 | bool count_down; | ||
83 | u32 t1_enable_val; | ||
84 | struct clock_event_device clkevt; | ||
85 | #ifdef CONFIG_ARM | ||
86 | struct delay_timer delay_timer; | ||
87 | #endif | ||
88 | }; | ||
89 | |||
90 | /* | ||
91 | * A local singleton used by sched_clock and delay timer reads, which are | ||
92 | * fast and stateless | ||
93 | */ | ||
94 | static struct fttmr010 *local_fttmr; | ||
95 | |||
96 | static inline struct fttmr010 *to_fttmr010(struct clock_event_device *evt) | ||
97 | { | ||
98 | return container_of(evt, struct fttmr010, clkevt); | ||
99 | } | ||
100 | |||
101 | static unsigned long fttmr010_read_current_timer_up(void) | ||
102 | { | ||
103 | return readl(local_fttmr->base + TIMER2_COUNT); | ||
104 | } | ||
105 | |||
106 | static unsigned long fttmr010_read_current_timer_down(void) | ||
107 | { | ||
108 | return ~readl(local_fttmr->base + TIMER2_COUNT); | ||
109 | } | ||
110 | |||
111 | static u64 notrace fttmr010_read_sched_clock_up(void) | ||
112 | { | ||
113 | return fttmr010_read_current_timer_up(); | ||
114 | } | ||
69 | 115 | ||
70 | static u64 notrace fttmr010_read_sched_clock(void) | 116 | static u64 notrace fttmr010_read_sched_clock_down(void) |
71 | { | 117 | { |
72 | return readl(base + TIMER3_COUNT); | 118 | return fttmr010_read_current_timer_down(); |
73 | } | 119 | } |
74 | 120 | ||
75 | static int fttmr010_timer_set_next_event(unsigned long cycles, | 121 | static int fttmr010_timer_set_next_event(unsigned long cycles, |
76 | struct clock_event_device *evt) | 122 | struct clock_event_device *evt) |
77 | { | 123 | { |
124 | struct fttmr010 *fttmr010 = to_fttmr010(evt); | ||
78 | u32 cr; | 125 | u32 cr; |
79 | 126 | ||
80 | /* Setup the match register */ | 127 | /* Stop */ |
81 | cr = readl(base + TIMER1_COUNT); | 128 | cr = readl(fttmr010->base + TIMER_CR); |
82 | writel(cr + cycles, base + TIMER1_MATCH1); | 129 | cr &= ~fttmr010->t1_enable_val; |
83 | if (readl(base + TIMER1_COUNT) - cr > cycles) | 130 | writel(cr, fttmr010->base + TIMER_CR); |
84 | return -ETIME; | 131 | |
132 | /* Setup the match register forward/backward in time */ | ||
133 | cr = readl(fttmr010->base + TIMER1_COUNT); | ||
134 | if (fttmr010->count_down) | ||
135 | cr -= cycles; | ||
136 | else | ||
137 | cr += cycles; | ||
138 | writel(cr, fttmr010->base + TIMER1_MATCH1); | ||
139 | |||
140 | /* Start */ | ||
141 | cr = readl(fttmr010->base + TIMER_CR); | ||
142 | cr |= fttmr010->t1_enable_val; | ||
143 | writel(cr, fttmr010->base + TIMER_CR); | ||
85 | 144 | ||
86 | return 0; | 145 | return 0; |
87 | } | 146 | } |
88 | 147 | ||
89 | static int fttmr010_timer_shutdown(struct clock_event_device *evt) | 148 | static int fttmr010_timer_shutdown(struct clock_event_device *evt) |
90 | { | 149 | { |
150 | struct fttmr010 *fttmr010 = to_fttmr010(evt); | ||
91 | u32 cr; | 151 | u32 cr; |
92 | 152 | ||
93 | /* | 153 | /* Stop */ |
94 | * Disable also for oneshot: the set_next() call will arm the timer | 154 | cr = readl(fttmr010->base + TIMER_CR); |
95 | * instead. | 155 | cr &= ~fttmr010->t1_enable_val; |
96 | */ | 156 | writel(cr, fttmr010->base + TIMER_CR); |
97 | /* Stop timer and interrupt. */ | 157 | |
98 | cr = readl(base + TIMER_CR); | 158 | return 0; |
99 | cr &= ~(TIMER_1_CR_ENABLE | TIMER_1_CR_INT); | 159 | } |
100 | writel(cr, base + TIMER_CR); | 160 | |
161 | static int fttmr010_timer_set_oneshot(struct clock_event_device *evt) | ||
162 | { | ||
163 | struct fttmr010 *fttmr010 = to_fttmr010(evt); | ||
164 | u32 cr; | ||
165 | |||
166 | /* Stop */ | ||
167 | cr = readl(fttmr010->base + TIMER_CR); | ||
168 | cr &= ~fttmr010->t1_enable_val; | ||
169 | writel(cr, fttmr010->base + TIMER_CR); | ||
101 | 170 | ||
102 | /* Setup counter start from 0 */ | 171 | /* Setup counter start from 0 or ~0 */ |
103 | writel(0, base + TIMER1_COUNT); | 172 | writel(0, fttmr010->base + TIMER1_COUNT); |
104 | writel(0, base + TIMER1_LOAD); | 173 | if (fttmr010->count_down) |
174 | writel(~0, fttmr010->base + TIMER1_LOAD); | ||
175 | else | ||
176 | writel(0, fttmr010->base + TIMER1_LOAD); | ||
105 | 177 | ||
106 | /* enable interrupt */ | 178 | /* Enable interrupt */ |
107 | cr = readl(base + TIMER_INTR_MASK); | 179 | cr = readl(fttmr010->base + TIMER_INTR_MASK); |
108 | cr &= ~(TIMER_1_INT_OVERFLOW | TIMER_1_INT_MATCH2); | 180 | cr &= ~(TIMER_1_INT_OVERFLOW | TIMER_1_INT_MATCH2); |
109 | cr |= TIMER_1_INT_MATCH1; | 181 | cr |= TIMER_1_INT_MATCH1; |
110 | writel(cr, base + TIMER_INTR_MASK); | 182 | writel(cr, fttmr010->base + TIMER_INTR_MASK); |
111 | |||
112 | /* start the timer */ | ||
113 | cr = readl(base + TIMER_CR); | ||
114 | cr |= TIMER_1_CR_ENABLE; | ||
115 | writel(cr, base + TIMER_CR); | ||
116 | 183 | ||
117 | return 0; | 184 | return 0; |
118 | } | 185 | } |
119 | 186 | ||
120 | static int fttmr010_timer_set_periodic(struct clock_event_device *evt) | 187 | static int fttmr010_timer_set_periodic(struct clock_event_device *evt) |
121 | { | 188 | { |
122 | u32 period = DIV_ROUND_CLOSEST(tick_rate, HZ); | 189 | struct fttmr010 *fttmr010 = to_fttmr010(evt); |
190 | u32 period = DIV_ROUND_CLOSEST(fttmr010->tick_rate, HZ); | ||
123 | u32 cr; | 191 | u32 cr; |
124 | 192 | ||
125 | /* Stop timer and interrupt */ | 193 | /* Stop */ |
126 | cr = readl(base + TIMER_CR); | 194 | cr = readl(fttmr010->base + TIMER_CR); |
127 | cr &= ~(TIMER_1_CR_ENABLE | TIMER_1_CR_INT); | 195 | cr &= ~fttmr010->t1_enable_val; |
128 | writel(cr, base + TIMER_CR); | 196 | writel(cr, fttmr010->base + TIMER_CR); |
129 | 197 | ||
130 | /* Setup timer to fire at 1/HT intervals. */ | 198 | /* Setup timer to fire at 1/HZ intervals. */ |
131 | cr = 0xffffffff - (period - 1); | 199 | if (fttmr010->count_down) { |
132 | writel(cr, base + TIMER1_COUNT); | 200 | writel(period, fttmr010->base + TIMER1_LOAD); |
133 | writel(cr, base + TIMER1_LOAD); | 201 | writel(0, fttmr010->base + TIMER1_MATCH1); |
134 | 202 | } else { | |
135 | /* enable interrupt on overflow */ | 203 | cr = 0xffffffff - (period - 1); |
136 | cr = readl(base + TIMER_INTR_MASK); | 204 | writel(cr, fttmr010->base + TIMER1_COUNT); |
137 | cr &= ~(TIMER_1_INT_MATCH1 | TIMER_1_INT_MATCH2); | 205 | writel(cr, fttmr010->base + TIMER1_LOAD); |
138 | cr |= TIMER_1_INT_OVERFLOW; | 206 | |
139 | writel(cr, base + TIMER_INTR_MASK); | 207 | /* Enable interrupt on overflow */ |
208 | cr = readl(fttmr010->base + TIMER_INTR_MASK); | ||
209 | cr &= ~(TIMER_1_INT_MATCH1 | TIMER_1_INT_MATCH2); | ||
210 | cr |= TIMER_1_INT_OVERFLOW; | ||
211 | writel(cr, fttmr010->base + TIMER_INTR_MASK); | ||
212 | } | ||
140 | 213 | ||
141 | /* Start the timer */ | 214 | /* Start the timer */ |
142 | cr = readl(base + TIMER_CR); | 215 | cr = readl(fttmr010->base + TIMER_CR); |
143 | cr |= TIMER_1_CR_ENABLE; | 216 | cr |= fttmr010->t1_enable_val; |
144 | cr |= TIMER_1_CR_INT; | 217 | writel(cr, fttmr010->base + TIMER_CR); |
145 | writel(cr, base + TIMER_CR); | ||
146 | 218 | ||
147 | return 0; | 219 | return 0; |
148 | } | 220 | } |
149 | 221 | ||
150 | /* Use TIMER1 as clock event */ | ||
151 | static struct clock_event_device fttmr010_clockevent = { | ||
152 | .name = "TIMER1", | ||
153 | /* Reasonably fast and accurate clock event */ | ||
154 | .rating = 300, | ||
155 | .shift = 32, | ||
156 | .features = CLOCK_EVT_FEAT_PERIODIC | | ||
157 | CLOCK_EVT_FEAT_ONESHOT, | ||
158 | .set_next_event = fttmr010_timer_set_next_event, | ||
159 | .set_state_shutdown = fttmr010_timer_shutdown, | ||
160 | .set_state_periodic = fttmr010_timer_set_periodic, | ||
161 | .set_state_oneshot = fttmr010_timer_shutdown, | ||
162 | .tick_resume = fttmr010_timer_shutdown, | ||
163 | }; | ||
164 | |||
165 | /* | 222 | /* |
166 | * IRQ handler for the timer | 223 | * IRQ handler for the timer |
167 | */ | 224 | */ |
168 | static irqreturn_t fttmr010_timer_interrupt(int irq, void *dev_id) | 225 | static irqreturn_t fttmr010_timer_interrupt(int irq, void *dev_id) |
169 | { | 226 | { |
170 | struct clock_event_device *evt = &fttmr010_clockevent; | 227 | struct clock_event_device *evt = dev_id; |
171 | 228 | ||
172 | evt->event_handler(evt); | 229 | evt->event_handler(evt); |
173 | return IRQ_HANDLED; | 230 | return IRQ_HANDLED; |
174 | } | 231 | } |
175 | 232 | ||
176 | static struct irqaction fttmr010_timer_irq = { | 233 | static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed) |
177 | .name = "Faraday FTTMR010 Timer Tick", | ||
178 | .flags = IRQF_TIMER, | ||
179 | .handler = fttmr010_timer_interrupt, | ||
180 | }; | ||
181 | |||
182 | static int __init fttmr010_timer_common_init(struct device_node *np) | ||
183 | { | 234 | { |
235 | struct fttmr010 *fttmr010; | ||
184 | int irq; | 236 | int irq; |
237 | struct clk *clk; | ||
238 | int ret; | ||
239 | u32 val; | ||
240 | |||
241 | /* | ||
242 | * These implementations require a clock reference. | ||
243 | * FIXME: we currently only support clocking using PCLK | ||
244 | * and using EXTCLK is not supported in the driver. | ||
245 | */ | ||
246 | clk = of_clk_get_by_name(np, "PCLK"); | ||
247 | if (IS_ERR(clk)) { | ||
248 | pr_err("could not get PCLK\n"); | ||
249 | return PTR_ERR(clk); | ||
250 | } | ||
251 | ret = clk_prepare_enable(clk); | ||
252 | if (ret) { | ||
253 | pr_err("failed to enable PCLK\n"); | ||
254 | return ret; | ||
255 | } | ||
185 | 256 | ||
186 | base = of_iomap(np, 0); | 257 | fttmr010 = kzalloc(sizeof(*fttmr010), GFP_KERNEL); |
187 | if (!base) { | 258 | if (!fttmr010) { |
259 | ret = -ENOMEM; | ||
260 | goto out_disable_clock; | ||
261 | } | ||
262 | fttmr010->tick_rate = clk_get_rate(clk); | ||
263 | |||
264 | fttmr010->base = of_iomap(np, 0); | ||
265 | if (!fttmr010->base) { | ||
188 | pr_err("Can't remap registers"); | 266 | pr_err("Can't remap registers"); |
189 | return -ENXIO; | 267 | ret = -ENXIO; |
268 | goto out_free; | ||
190 | } | 269 | } |
191 | /* IRQ for timer 1 */ | 270 | /* IRQ for timer 1 */ |
192 | irq = irq_of_parse_and_map(np, 0); | 271 | irq = irq_of_parse_and_map(np, 0); |
193 | if (irq <= 0) { | 272 | if (irq <= 0) { |
194 | pr_err("Can't parse IRQ"); | 273 | pr_err("Can't parse IRQ"); |
195 | return -EINVAL; | 274 | ret = -EINVAL; |
275 | goto out_unmap; | ||
276 | } | ||
277 | |||
278 | /* | ||
279 | * The Aspeed AST2400 moves bits around in the control register, | ||
280 | * otherwise it works the same. | ||
281 | */ | ||
282 | if (is_aspeed) { | ||
283 | fttmr010->t1_enable_val = TIMER_1_CR_ASPEED_ENABLE | | ||
284 | TIMER_1_CR_ASPEED_INT; | ||
285 | /* Downward not available */ | ||
286 | fttmr010->count_down = true; | ||
287 | } else { | ||
288 | fttmr010->t1_enable_val = TIMER_1_CR_ENABLE | TIMER_1_CR_INT; | ||
196 | } | 289 | } |
197 | 290 | ||
198 | /* | 291 | /* |
199 | * Reset the interrupt mask and status | 292 | * Reset the interrupt mask and status |
200 | */ | 293 | */ |
201 | writel(TIMER_INT_ALL_MASK, base + TIMER_INTR_MASK); | 294 | writel(TIMER_INT_ALL_MASK, fttmr010->base + TIMER_INTR_MASK); |
202 | writel(0, base + TIMER_INTR_STATE); | 295 | writel(0, fttmr010->base + TIMER_INTR_STATE); |
203 | writel(TIMER_DEFAULT_FLAGS, base + TIMER_CR); | 296 | |
297 | /* | ||
298 | * Enable timer 1 count up, timer 2 count up, except on Aspeed, | ||
299 | * where everything just counts down. | ||
300 | */ | ||
301 | if (is_aspeed) | ||
302 | val = TIMER_2_CR_ASPEED_ENABLE; | ||
303 | else { | ||
304 | val = TIMER_2_CR_ENABLE; | ||
305 | if (!fttmr010->count_down) | ||
306 | val |= TIMER_1_CR_UPDOWN | TIMER_2_CR_UPDOWN; | ||
307 | } | ||
308 | writel(val, fttmr010->base + TIMER_CR); | ||
204 | 309 | ||
205 | /* | 310 | /* |
206 | * Setup free-running clocksource timer (interrupts | 311 | * Setup free-running clocksource timer (interrupts |
207 | * disabled.) | 312 | * disabled.) |
208 | */ | 313 | */ |
209 | writel(0, base + TIMER3_COUNT); | 314 | local_fttmr = fttmr010; |
210 | writel(0, base + TIMER3_LOAD); | 315 | writel(0, fttmr010->base + TIMER2_COUNT); |
211 | writel(0, base + TIMER3_MATCH1); | 316 | writel(0, fttmr010->base + TIMER2_MATCH1); |
212 | writel(0, base + TIMER3_MATCH2); | 317 | writel(0, fttmr010->base + TIMER2_MATCH2); |
213 | clocksource_mmio_init(base + TIMER3_COUNT, | 318 | |
214 | "fttmr010_clocksource", tick_rate, | 319 | if (fttmr010->count_down) { |
215 | 300, 32, clocksource_mmio_readl_up); | 320 | writel(~0, fttmr010->base + TIMER2_LOAD); |
216 | sched_clock_register(fttmr010_read_sched_clock, 32, tick_rate); | 321 | clocksource_mmio_init(fttmr010->base + TIMER2_COUNT, |
322 | "FTTMR010-TIMER2", | ||
323 | fttmr010->tick_rate, | ||
324 | 300, 32, clocksource_mmio_readl_down); | ||
325 | sched_clock_register(fttmr010_read_sched_clock_down, 32, | ||
326 | fttmr010->tick_rate); | ||
327 | } else { | ||
328 | writel(0, fttmr010->base + TIMER2_LOAD); | ||
329 | clocksource_mmio_init(fttmr010->base + TIMER2_COUNT, | ||
330 | "FTTMR010-TIMER2", | ||
331 | fttmr010->tick_rate, | ||
332 | 300, 32, clocksource_mmio_readl_up); | ||
333 | sched_clock_register(fttmr010_read_sched_clock_up, 32, | ||
334 | fttmr010->tick_rate); | ||
335 | } | ||
217 | 336 | ||
218 | /* | 337 | /* |
219 | * Setup clockevent timer (interrupt-driven.) | 338 | * Setup clockevent timer (interrupt-driven) on timer 1. |
220 | */ | 339 | */ |
221 | writel(0, base + TIMER1_COUNT); | 340 | writel(0, fttmr010->base + TIMER1_COUNT); |
222 | writel(0, base + TIMER1_LOAD); | 341 | writel(0, fttmr010->base + TIMER1_LOAD); |
223 | writel(0, base + TIMER1_MATCH1); | 342 | writel(0, fttmr010->base + TIMER1_MATCH1); |
224 | writel(0, base + TIMER1_MATCH2); | 343 | writel(0, fttmr010->base + TIMER1_MATCH2); |
225 | setup_irq(irq, &fttmr010_timer_irq); | 344 | ret = request_irq(irq, fttmr010_timer_interrupt, IRQF_TIMER, |
226 | fttmr010_clockevent.cpumask = cpumask_of(0); | 345 | "FTTMR010-TIMER1", &fttmr010->clkevt); |
227 | clockevents_config_and_register(&fttmr010_clockevent, tick_rate, | 346 | if (ret) { |
347 | pr_err("FTTMR010-TIMER1 no IRQ\n"); | ||
348 | goto out_unmap; | ||
349 | } | ||
350 | |||
351 | fttmr010->clkevt.name = "FTTMR010-TIMER1"; | ||
352 | /* Reasonably fast and accurate clock event */ | ||
353 | fttmr010->clkevt.rating = 300; | ||
354 | fttmr010->clkevt.features = CLOCK_EVT_FEAT_PERIODIC | | ||
355 | CLOCK_EVT_FEAT_ONESHOT; | ||
356 | fttmr010->clkevt.set_next_event = fttmr010_timer_set_next_event; | ||
357 | fttmr010->clkevt.set_state_shutdown = fttmr010_timer_shutdown; | ||
358 | fttmr010->clkevt.set_state_periodic = fttmr010_timer_set_periodic; | ||
359 | fttmr010->clkevt.set_state_oneshot = fttmr010_timer_set_oneshot; | ||
360 | fttmr010->clkevt.tick_resume = fttmr010_timer_shutdown; | ||
361 | fttmr010->clkevt.cpumask = cpumask_of(0); | ||
362 | fttmr010->clkevt.irq = irq; | ||
363 | clockevents_config_and_register(&fttmr010->clkevt, | ||
364 | fttmr010->tick_rate, | ||
228 | 1, 0xffffffff); | 365 | 1, 0xffffffff); |
229 | 366 | ||
230 | return 0; | 367 | #ifdef CONFIG_ARM |
231 | } | 368 | /* Also use this timer for delays */ |
369 | if (fttmr010->count_down) | ||
370 | fttmr010->delay_timer.read_current_timer = | ||
371 | fttmr010_read_current_timer_down; | ||
372 | else | ||
373 | fttmr010->delay_timer.read_current_timer = | ||
374 | fttmr010_read_current_timer_up; | ||
375 | fttmr010->delay_timer.freq = fttmr010->tick_rate; | ||
376 | register_current_timer_delay(&fttmr010->delay_timer); | ||
377 | #endif | ||
232 | 378 | ||
233 | static int __init fttmr010_timer_of_init(struct device_node *np) | 379 | return 0; |
234 | { | ||
235 | /* | ||
236 | * These implementations require a clock reference. | ||
237 | * FIXME: we currently only support clocking using PCLK | ||
238 | * and using EXTCLK is not supported in the driver. | ||
239 | */ | ||
240 | struct clk *clk; | ||
241 | 380 | ||
242 | clk = of_clk_get_by_name(np, "PCLK"); | 381 | out_unmap: |
243 | if (IS_ERR(clk)) { | 382 | iounmap(fttmr010->base); |
244 | pr_err("could not get PCLK"); | 383 | out_free: |
245 | return PTR_ERR(clk); | 384 | kfree(fttmr010); |
246 | } | 385 | out_disable_clock: |
247 | tick_rate = clk_get_rate(clk); | 386 | clk_disable_unprepare(clk); |
248 | 387 | ||
249 | return fttmr010_timer_common_init(np); | 388 | return ret; |
250 | } | 389 | } |
251 | CLOCKSOURCE_OF_DECLARE(fttmr010, "faraday,fttmr010", fttmr010_timer_of_init); | ||
252 | 390 | ||
253 | /* | 391 | static __init int aspeed_timer_init(struct device_node *np) |
254 | * Gemini-specific: relevant registers in the global syscon | ||
255 | */ | ||
256 | #define GLOBAL_STATUS 0x04 | ||
257 | #define CPU_AHB_RATIO_MASK (0x3 << 18) | ||
258 | #define CPU_AHB_1_1 (0x0 << 18) | ||
259 | #define CPU_AHB_3_2 (0x1 << 18) | ||
260 | #define CPU_AHB_24_13 (0x2 << 18) | ||
261 | #define CPU_AHB_2_1 (0x3 << 18) | ||
262 | #define REG_TO_AHB_SPEED(reg) ((((reg) >> 15) & 0x7) * 10 + 130) | ||
263 | |||
264 | static int __init gemini_timer_of_init(struct device_node *np) | ||
265 | { | 392 | { |
266 | static struct regmap *map; | 393 | return fttmr010_common_init(np, true); |
267 | int ret; | 394 | } |
268 | u32 val; | ||
269 | |||
270 | map = syscon_regmap_lookup_by_phandle(np, "syscon"); | ||
271 | if (IS_ERR(map)) { | ||
272 | pr_err("Can't get regmap for syscon handle\n"); | ||
273 | return -ENODEV; | ||
274 | } | ||
275 | ret = regmap_read(map, GLOBAL_STATUS, &val); | ||
276 | if (ret) { | ||
277 | pr_err("Can't read syscon status register\n"); | ||
278 | return -ENXIO; | ||
279 | } | ||
280 | |||
281 | tick_rate = REG_TO_AHB_SPEED(val) * 1000000; | ||
282 | pr_info("Bus: %dMHz ", tick_rate / 1000000); | ||
283 | |||
284 | tick_rate /= 6; /* APB bus run AHB*(1/6) */ | ||
285 | |||
286 | switch (val & CPU_AHB_RATIO_MASK) { | ||
287 | case CPU_AHB_1_1: | ||
288 | pr_cont("(1/1)\n"); | ||
289 | break; | ||
290 | case CPU_AHB_3_2: | ||
291 | pr_cont("(3/2)\n"); | ||
292 | break; | ||
293 | case CPU_AHB_24_13: | ||
294 | pr_cont("(24/13)\n"); | ||
295 | break; | ||
296 | case CPU_AHB_2_1: | ||
297 | pr_cont("(2/1)\n"); | ||
298 | break; | ||
299 | } | ||
300 | 395 | ||
301 | return fttmr010_timer_common_init(np); | 396 | static __init int fttmr010_timer_init(struct device_node *np) |
397 | { | ||
398 | return fttmr010_common_init(np, false); | ||
302 | } | 399 | } |
303 | CLOCKSOURCE_OF_DECLARE(gemini, "cortina,gemini-timer", gemini_timer_of_init); | 400 | |
401 | TIMER_OF_DECLARE(fttmr010, "faraday,fttmr010", fttmr010_timer_init); | ||
402 | TIMER_OF_DECLARE(gemini, "cortina,gemini-timer", fttmr010_timer_init); | ||
403 | TIMER_OF_DECLARE(moxart, "moxa,moxart-timer", fttmr010_timer_init); | ||
404 | TIMER_OF_DECLARE(ast2400, "aspeed,ast2400-timer", aspeed_timer_init); | ||
405 | TIMER_OF_DECLARE(ast2500, "aspeed,ast2500-timer", aspeed_timer_init); | ||
diff --git a/drivers/clocksource/timer-imx-gpt.c b/drivers/clocksource/timer-imx-gpt.c index f595460bfc58..6ec6d79b237c 100644 --- a/drivers/clocksource/timer-imx-gpt.c +++ b/drivers/clocksource/timer-imx-gpt.c | |||
@@ -545,15 +545,15 @@ static int __init imx6dl_timer_init_dt(struct device_node *np) | |||
545 | return mxc_timer_init_dt(np, GPT_TYPE_IMX6DL); | 545 | return mxc_timer_init_dt(np, GPT_TYPE_IMX6DL); |
546 | } | 546 | } |
547 | 547 | ||
548 | CLOCKSOURCE_OF_DECLARE(imx1_timer, "fsl,imx1-gpt", imx1_timer_init_dt); | 548 | TIMER_OF_DECLARE(imx1_timer, "fsl,imx1-gpt", imx1_timer_init_dt); |
549 | CLOCKSOURCE_OF_DECLARE(imx21_timer, "fsl,imx21-gpt", imx21_timer_init_dt); | 549 | TIMER_OF_DECLARE(imx21_timer, "fsl,imx21-gpt", imx21_timer_init_dt); |
550 | CLOCKSOURCE_OF_DECLARE(imx27_timer, "fsl,imx27-gpt", imx21_timer_init_dt); | 550 | TIMER_OF_DECLARE(imx27_timer, "fsl,imx27-gpt", imx21_timer_init_dt); |
551 | CLOCKSOURCE_OF_DECLARE(imx31_timer, "fsl,imx31-gpt", imx31_timer_init_dt); | 551 | TIMER_OF_DECLARE(imx31_timer, "fsl,imx31-gpt", imx31_timer_init_dt); |
552 | CLOCKSOURCE_OF_DECLARE(imx25_timer, "fsl,imx25-gpt", imx31_timer_init_dt); | 552 | TIMER_OF_DECLARE(imx25_timer, "fsl,imx25-gpt", imx31_timer_init_dt); |
553 | CLOCKSOURCE_OF_DECLARE(imx50_timer, "fsl,imx50-gpt", imx31_timer_init_dt); | 553 | TIMER_OF_DECLARE(imx50_timer, "fsl,imx50-gpt", imx31_timer_init_dt); |
554 | CLOCKSOURCE_OF_DECLARE(imx51_timer, "fsl,imx51-gpt", imx31_timer_init_dt); | 554 | TIMER_OF_DECLARE(imx51_timer, "fsl,imx51-gpt", imx31_timer_init_dt); |
555 | CLOCKSOURCE_OF_DECLARE(imx53_timer, "fsl,imx53-gpt", imx31_timer_init_dt); | 555 | TIMER_OF_DECLARE(imx53_timer, "fsl,imx53-gpt", imx31_timer_init_dt); |
556 | CLOCKSOURCE_OF_DECLARE(imx6q_timer, "fsl,imx6q-gpt", imx31_timer_init_dt); | 556 | TIMER_OF_DECLARE(imx6q_timer, "fsl,imx6q-gpt", imx31_timer_init_dt); |
557 | CLOCKSOURCE_OF_DECLARE(imx6dl_timer, "fsl,imx6dl-gpt", imx6dl_timer_init_dt); | 557 | TIMER_OF_DECLARE(imx6dl_timer, "fsl,imx6dl-gpt", imx6dl_timer_init_dt); |
558 | CLOCKSOURCE_OF_DECLARE(imx6sl_timer, "fsl,imx6sl-gpt", imx6dl_timer_init_dt); | 558 | TIMER_OF_DECLARE(imx6sl_timer, "fsl,imx6sl-gpt", imx6dl_timer_init_dt); |
559 | CLOCKSOURCE_OF_DECLARE(imx6sx_timer, "fsl,imx6sx-gpt", imx6dl_timer_init_dt); | 559 | TIMER_OF_DECLARE(imx6sx_timer, "fsl,imx6sx-gpt", imx6dl_timer_init_dt); |
diff --git a/drivers/clocksource/timer-integrator-ap.c b/drivers/clocksource/timer-integrator-ap.c index 04ad3066e190..2ff64d9d4fb3 100644 --- a/drivers/clocksource/timer-integrator-ap.c +++ b/drivers/clocksource/timer-integrator-ap.c | |||
@@ -232,5 +232,5 @@ static int __init integrator_ap_timer_init_of(struct device_node *node) | |||
232 | return 0; | 232 | return 0; |
233 | } | 233 | } |
234 | 234 | ||
235 | CLOCKSOURCE_OF_DECLARE(integrator_ap_timer, "arm,integrator-timer", | 235 | TIMER_OF_DECLARE(integrator_ap_timer, "arm,integrator-timer", |
236 | integrator_ap_timer_init_of); | 236 | integrator_ap_timer_init_of); |
diff --git a/drivers/clocksource/timer-keystone.c b/drivers/clocksource/timer-keystone.c index ab68a47ab3b4..0eee03250cfc 100644 --- a/drivers/clocksource/timer-keystone.c +++ b/drivers/clocksource/timer-keystone.c | |||
@@ -226,5 +226,5 @@ err: | |||
226 | return error; | 226 | return error; |
227 | } | 227 | } |
228 | 228 | ||
229 | CLOCKSOURCE_OF_DECLARE(keystone_timer, "ti,keystone-timer", | 229 | TIMER_OF_DECLARE(keystone_timer, "ti,keystone-timer", |
230 | keystone_timer_init); | 230 | keystone_timer_init); |
diff --git a/drivers/clocksource/timer-nps.c b/drivers/clocksource/timer-nps.c index e74ea1722ad3..7b6bb0df96ae 100644 --- a/drivers/clocksource/timer-nps.c +++ b/drivers/clocksource/timer-nps.c | |||
@@ -110,9 +110,9 @@ static int __init nps_setup_clocksource(struct device_node *node) | |||
110 | return ret; | 110 | return ret; |
111 | } | 111 | } |
112 | 112 | ||
113 | CLOCKSOURCE_OF_DECLARE(ezchip_nps400_clksrc, "ezchip,nps400-timer", | 113 | TIMER_OF_DECLARE(ezchip_nps400_clksrc, "ezchip,nps400-timer", |
114 | nps_setup_clocksource); | 114 | nps_setup_clocksource); |
115 | CLOCKSOURCE_OF_DECLARE(ezchip_nps400_clk_src, "ezchip,nps400-timer1", | 115 | TIMER_OF_DECLARE(ezchip_nps400_clk_src, "ezchip,nps400-timer1", |
116 | nps_setup_clocksource); | 116 | nps_setup_clocksource); |
117 | 117 | ||
118 | #ifdef CONFIG_EZNPS_MTM_EXT | 118 | #ifdef CONFIG_EZNPS_MTM_EXT |
@@ -279,6 +279,6 @@ static int __init nps_setup_clockevent(struct device_node *node) | |||
279 | return 0; | 279 | return 0; |
280 | } | 280 | } |
281 | 281 | ||
282 | CLOCKSOURCE_OF_DECLARE(ezchip_nps400_clk_evt, "ezchip,nps400-timer0", | 282 | TIMER_OF_DECLARE(ezchip_nps400_clk_evt, "ezchip,nps400-timer0", |
283 | nps_setup_clockevent); | 283 | nps_setup_clockevent); |
284 | #endif /* CONFIG_EZNPS_MTM_EXT */ | 284 | #endif /* CONFIG_EZNPS_MTM_EXT */ |
diff --git a/drivers/clocksource/timer-of.c b/drivers/clocksource/timer-of.c new file mode 100644 index 000000000000..f6e7491c873c --- /dev/null +++ b/drivers/clocksource/timer-of.c | |||
@@ -0,0 +1,171 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2017, Linaro Ltd. All rights reserved. | ||
3 | * | ||
4 | * Author: Daniel Lezcano <daniel.lezcano@linaro.org> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms and conditions of the GNU General Public License, | ||
8 | * version 2, as published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | * more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | #include <linux/clk.h> | ||
19 | #include <linux/interrupt.h> | ||
20 | #include <linux/of.h> | ||
21 | #include <linux/of_address.h> | ||
22 | #include <linux/of_irq.h> | ||
23 | #include <linux/slab.h> | ||
24 | |||
25 | #include "timer-of.h" | ||
26 | |||
27 | static __init void timer_irq_exit(struct of_timer_irq *of_irq) | ||
28 | { | ||
29 | struct timer_of *to = container_of(of_irq, struct timer_of, of_irq); | ||
30 | |||
31 | struct clock_event_device *clkevt = &to->clkevt; | ||
32 | |||
33 | of_irq->percpu ? free_percpu_irq(of_irq->irq, clkevt) : | ||
34 | free_irq(of_irq->irq, clkevt); | ||
35 | } | ||
36 | |||
37 | static __init int timer_irq_init(struct device_node *np, | ||
38 | struct of_timer_irq *of_irq) | ||
39 | { | ||
40 | int ret; | ||
41 | struct timer_of *to = container_of(of_irq, struct timer_of, of_irq); | ||
42 | struct clock_event_device *clkevt = &to->clkevt; | ||
43 | |||
44 | of_irq->irq = of_irq->name ? of_irq_get_byname(np, of_irq->name): | ||
45 | irq_of_parse_and_map(np, of_irq->index); | ||
46 | if (!of_irq->irq) { | ||
47 | pr_err("Failed to map interrupt for %s\n", np->full_name); | ||
48 | return -EINVAL; | ||
49 | } | ||
50 | |||
51 | ret = of_irq->percpu ? | ||
52 | request_percpu_irq(of_irq->irq, of_irq->handler, | ||
53 | np->full_name, clkevt) : | ||
54 | request_irq(of_irq->irq, of_irq->handler, | ||
55 | of_irq->flags ? of_irq->flags : IRQF_TIMER, | ||
56 | np->full_name, clkevt); | ||
57 | if (ret) { | ||
58 | pr_err("Failed to request irq %d for %s\n", of_irq->irq, | ||
59 | np->full_name); | ||
60 | return ret; | ||
61 | } | ||
62 | |||
63 | clkevt->irq = of_irq->irq; | ||
64 | |||
65 | return 0; | ||
66 | } | ||
67 | |||
68 | static __init void timer_clk_exit(struct of_timer_clk *of_clk) | ||
69 | { | ||
70 | of_clk->rate = 0; | ||
71 | clk_disable_unprepare(of_clk->clk); | ||
72 | clk_put(of_clk->clk); | ||
73 | } | ||
74 | |||
75 | static __init int timer_clk_init(struct device_node *np, | ||
76 | struct of_timer_clk *of_clk) | ||
77 | { | ||
78 | int ret; | ||
79 | |||
80 | of_clk->clk = of_clk->name ? of_clk_get_by_name(np, of_clk->name) : | ||
81 | of_clk_get(np, of_clk->index); | ||
82 | if (IS_ERR(of_clk->clk)) { | ||
83 | pr_err("Failed to get clock for %s\n", np->full_name); | ||
84 | return PTR_ERR(of_clk->clk); | ||
85 | } | ||
86 | |||
87 | ret = clk_prepare_enable(of_clk->clk); | ||
88 | if (ret) { | ||
89 | pr_err("Failed for enable clock for %s\n", np->full_name); | ||
90 | goto out_clk_put; | ||
91 | } | ||
92 | |||
93 | of_clk->rate = clk_get_rate(of_clk->clk); | ||
94 | if (!of_clk->rate) { | ||
95 | ret = -EINVAL; | ||
96 | pr_err("Failed to get clock rate for %s\n", np->full_name); | ||
97 | goto out_clk_disable; | ||
98 | } | ||
99 | |||
100 | of_clk->period = DIV_ROUND_UP(of_clk->rate, HZ); | ||
101 | out: | ||
102 | return ret; | ||
103 | |||
104 | out_clk_disable: | ||
105 | clk_disable_unprepare(of_clk->clk); | ||
106 | out_clk_put: | ||
107 | clk_put(of_clk->clk); | ||
108 | |||
109 | goto out; | ||
110 | } | ||
111 | |||
112 | static __init void timer_base_exit(struct of_timer_base *of_base) | ||
113 | { | ||
114 | iounmap(of_base->base); | ||
115 | } | ||
116 | |||
117 | static __init int timer_base_init(struct device_node *np, | ||
118 | struct of_timer_base *of_base) | ||
119 | { | ||
120 | const char *name = of_base->name ? of_base->name : np->full_name; | ||
121 | |||
122 | of_base->base = of_io_request_and_map(np, of_base->index, name); | ||
123 | if (!of_base->base) { | ||
124 | pr_err("Failed to iomap (%s)\n", name); | ||
125 | return -ENXIO; | ||
126 | } | ||
127 | |||
128 | return 0; | ||
129 | } | ||
130 | |||
131 | int __init timer_of_init(struct device_node *np, struct timer_of *to) | ||
132 | { | ||
133 | int ret = -EINVAL; | ||
134 | int flags = 0; | ||
135 | |||
136 | if (to->flags & TIMER_OF_BASE) { | ||
137 | ret = timer_base_init(np, &to->of_base); | ||
138 | if (ret) | ||
139 | goto out_fail; | ||
140 | flags |= TIMER_OF_BASE; | ||
141 | } | ||
142 | |||
143 | if (to->flags & TIMER_OF_CLOCK) { | ||
144 | ret = timer_clk_init(np, &to->of_clk); | ||
145 | if (ret) | ||
146 | goto out_fail; | ||
147 | flags |= TIMER_OF_CLOCK; | ||
148 | } | ||
149 | |||
150 | if (to->flags & TIMER_OF_IRQ) { | ||
151 | ret = timer_irq_init(np, &to->of_irq); | ||
152 | if (ret) | ||
153 | goto out_fail; | ||
154 | flags |= TIMER_OF_IRQ; | ||
155 | } | ||
156 | |||
157 | if (!to->clkevt.name) | ||
158 | to->clkevt.name = np->name; | ||
159 | return ret; | ||
160 | |||
161 | out_fail: | ||
162 | if (flags & TIMER_OF_IRQ) | ||
163 | timer_irq_exit(&to->of_irq); | ||
164 | |||
165 | if (flags & TIMER_OF_CLOCK) | ||
166 | timer_clk_exit(&to->of_clk); | ||
167 | |||
168 | if (flags & TIMER_OF_BASE) | ||
169 | timer_base_exit(&to->of_base); | ||
170 | return ret; | ||
171 | } | ||
diff --git a/drivers/clocksource/timer-of.h b/drivers/clocksource/timer-of.h new file mode 100644 index 000000000000..e0d727255f72 --- /dev/null +++ b/drivers/clocksource/timer-of.h | |||
@@ -0,0 +1,69 @@ | |||
1 | #ifndef __TIMER_OF_H__ | ||
2 | #define __TIMER_OF_H__ | ||
3 | |||
4 | #include <linux/clockchips.h> | ||
5 | |||
6 | #define TIMER_OF_BASE 0x1 | ||
7 | #define TIMER_OF_CLOCK 0x2 | ||
8 | #define TIMER_OF_IRQ 0x4 | ||
9 | |||
10 | struct of_timer_irq { | ||
11 | int irq; | ||
12 | int index; | ||
13 | int percpu; | ||
14 | const char *name; | ||
15 | unsigned long flags; | ||
16 | irq_handler_t handler; | ||
17 | }; | ||
18 | |||
19 | struct of_timer_base { | ||
20 | void __iomem *base; | ||
21 | const char *name; | ||
22 | int index; | ||
23 | }; | ||
24 | |||
25 | struct of_timer_clk { | ||
26 | struct clk *clk; | ||
27 | const char *name; | ||
28 | int index; | ||
29 | unsigned long rate; | ||
30 | unsigned long period; | ||
31 | }; | ||
32 | |||
33 | struct timer_of { | ||
34 | unsigned int flags; | ||
35 | struct clock_event_device clkevt; | ||
36 | struct of_timer_base of_base; | ||
37 | struct of_timer_irq of_irq; | ||
38 | struct of_timer_clk of_clk; | ||
39 | void *private_data; | ||
40 | }; | ||
41 | |||
42 | static inline struct timer_of *to_timer_of(struct clock_event_device *clkevt) | ||
43 | { | ||
44 | return container_of(clkevt, struct timer_of, clkevt); | ||
45 | } | ||
46 | |||
47 | static inline void __iomem *timer_of_base(struct timer_of *to) | ||
48 | { | ||
49 | return to->of_base.base; | ||
50 | } | ||
51 | |||
52 | static inline int timer_of_irq(struct timer_of *to) | ||
53 | { | ||
54 | return to->of_irq.irq; | ||
55 | } | ||
56 | |||
57 | static inline unsigned long timer_of_rate(struct timer_of *to) | ||
58 | { | ||
59 | return to->of_clk.rate; | ||
60 | } | ||
61 | |||
62 | static inline unsigned long timer_of_period(struct timer_of *to) | ||
63 | { | ||
64 | return to->of_clk.period; | ||
65 | } | ||
66 | |||
67 | extern int __init timer_of_init(struct device_node *np, | ||
68 | struct timer_of *to); | ||
69 | #endif | ||
diff --git a/drivers/clocksource/timer-oxnas-rps.c b/drivers/clocksource/timer-oxnas-rps.c index d630bf417773..eed6feff8b5f 100644 --- a/drivers/clocksource/timer-oxnas-rps.c +++ b/drivers/clocksource/timer-oxnas-rps.c | |||
@@ -293,7 +293,7 @@ err_alloc: | |||
293 | return ret; | 293 | return ret; |
294 | } | 294 | } |
295 | 295 | ||
296 | CLOCKSOURCE_OF_DECLARE(ox810se_rps, | 296 | TIMER_OF_DECLARE(ox810se_rps, |
297 | "oxsemi,ox810se-rps-timer", oxnas_rps_timer_init); | 297 | "oxsemi,ox810se-rps-timer", oxnas_rps_timer_init); |
298 | CLOCKSOURCE_OF_DECLARE(ox820_rps, | 298 | TIMER_OF_DECLARE(ox820_rps, |
299 | "oxsemi,ox820se-rps-timer", oxnas_rps_timer_init); | 299 | "oxsemi,ox820se-rps-timer", oxnas_rps_timer_init); |
diff --git a/drivers/clocksource/timer-prima2.c b/drivers/clocksource/timer-prima2.c index b4122ed1accb..20ff33b698df 100644 --- a/drivers/clocksource/timer-prima2.c +++ b/drivers/clocksource/timer-prima2.c | |||
@@ -245,5 +245,5 @@ static int __init sirfsoc_prima2_timer_init(struct device_node *np) | |||
245 | 245 | ||
246 | return 0; | 246 | return 0; |
247 | } | 247 | } |
248 | CLOCKSOURCE_OF_DECLARE(sirfsoc_prima2_timer, | 248 | TIMER_OF_DECLARE(sirfsoc_prima2_timer, |
249 | "sirf,prima2-tick", sirfsoc_prima2_timer_init); | 249 | "sirf,prima2-tick", sirfsoc_prima2_timer_init); |
diff --git a/drivers/clocksource/clksrc-probe.c b/drivers/clocksource/timer-probe.c index ac701ffb8d59..da81e5de74fe 100644 --- a/drivers/clocksource/clksrc-probe.c +++ b/drivers/clocksource/timer-probe.c | |||
@@ -19,20 +19,20 @@ | |||
19 | #include <linux/of.h> | 19 | #include <linux/of.h> |
20 | #include <linux/clocksource.h> | 20 | #include <linux/clocksource.h> |
21 | 21 | ||
22 | extern struct of_device_id __clksrc_of_table[]; | 22 | extern struct of_device_id __timer_of_table[]; |
23 | 23 | ||
24 | static const struct of_device_id __clksrc_of_table_sentinel | 24 | static const struct of_device_id __timer_of_table_sentinel |
25 | __used __section(__clksrc_of_table_end); | 25 | __used __section(__timer_of_table_end); |
26 | 26 | ||
27 | void __init clocksource_probe(void) | 27 | void __init timer_probe(void) |
28 | { | 28 | { |
29 | struct device_node *np; | 29 | struct device_node *np; |
30 | const struct of_device_id *match; | 30 | const struct of_device_id *match; |
31 | of_init_fn_1_ret init_func_ret; | 31 | of_init_fn_1_ret init_func_ret; |
32 | unsigned clocksources = 0; | 32 | unsigned timers = 0; |
33 | int ret; | 33 | int ret; |
34 | 34 | ||
35 | for_each_matching_node_and_match(np, __clksrc_of_table, &match) { | 35 | for_each_matching_node_and_match(np, __timer_of_table, &match) { |
36 | if (!of_device_is_available(np)) | 36 | if (!of_device_is_available(np)) |
37 | continue; | 37 | continue; |
38 | 38 | ||
@@ -45,11 +45,11 @@ void __init clocksource_probe(void) | |||
45 | continue; | 45 | continue; |
46 | } | 46 | } |
47 | 47 | ||
48 | clocksources++; | 48 | timers++; |
49 | } | 49 | } |
50 | 50 | ||
51 | clocksources += acpi_probe_device_table(clksrc); | 51 | timers += acpi_probe_device_table(timer); |
52 | 52 | ||
53 | if (!clocksources) | 53 | if (!timers) |
54 | pr_crit("%s: no matching clocksources found\n", __func__); | 54 | pr_crit("%s: no matching timers found\n", __func__); |
55 | } | 55 | } |
diff --git a/drivers/clocksource/timer-sp804.c b/drivers/clocksource/timer-sp804.c index 2d575a8c0939..3ac9dec9a038 100644 --- a/drivers/clocksource/timer-sp804.c +++ b/drivers/clocksource/timer-sp804.c | |||
@@ -287,7 +287,7 @@ err: | |||
287 | iounmap(base); | 287 | iounmap(base); |
288 | return ret; | 288 | return ret; |
289 | } | 289 | } |
290 | CLOCKSOURCE_OF_DECLARE(sp804, "arm,sp804", sp804_of_init); | 290 | TIMER_OF_DECLARE(sp804, "arm,sp804", sp804_of_init); |
291 | 291 | ||
292 | static int __init integrator_cp_of_init(struct device_node *np) | 292 | static int __init integrator_cp_of_init(struct device_node *np) |
293 | { | 293 | { |
@@ -335,4 +335,4 @@ err: | |||
335 | iounmap(base); | 335 | iounmap(base); |
336 | return ret; | 336 | return ret; |
337 | } | 337 | } |
338 | CLOCKSOURCE_OF_DECLARE(intcp, "arm,integrator-cp-timer", integrator_cp_of_init); | 338 | TIMER_OF_DECLARE(intcp, "arm,integrator-cp-timer", integrator_cp_of_init); |
diff --git a/drivers/clocksource/timer-stm32.c b/drivers/clocksource/timer-stm32.c index 1b2574c4fb97..174d1243ea93 100644 --- a/drivers/clocksource/timer-stm32.c +++ b/drivers/clocksource/timer-stm32.c | |||
@@ -187,4 +187,4 @@ err_clk_get: | |||
187 | return ret; | 187 | return ret; |
188 | } | 188 | } |
189 | 189 | ||
190 | CLOCKSOURCE_OF_DECLARE(stm32, "st,stm32-timer", stm32_clockevent_init); | 190 | TIMER_OF_DECLARE(stm32, "st,stm32-timer", stm32_clockevent_init); |
diff --git a/drivers/clocksource/timer-sun5i.c b/drivers/clocksource/timer-sun5i.c index c4656c4d44a6..2a3fe83ec337 100644 --- a/drivers/clocksource/timer-sun5i.c +++ b/drivers/clocksource/timer-sun5i.c | |||
@@ -359,7 +359,7 @@ static int __init sun5i_timer_init(struct device_node *node) | |||
359 | 359 | ||
360 | return sun5i_setup_clockevent(node, timer_base, clk, irq); | 360 | return sun5i_setup_clockevent(node, timer_base, clk, irq); |
361 | } | 361 | } |
362 | CLOCKSOURCE_OF_DECLARE(sun5i_a13, "allwinner,sun5i-a13-hstimer", | 362 | TIMER_OF_DECLARE(sun5i_a13, "allwinner,sun5i-a13-hstimer", |
363 | sun5i_timer_init); | 363 | sun5i_timer_init); |
364 | CLOCKSOURCE_OF_DECLARE(sun7i_a20, "allwinner,sun7i-a20-hstimer", | 364 | TIMER_OF_DECLARE(sun7i_a20, "allwinner,sun7i-a20-hstimer", |
365 | sun5i_timer_init); | 365 | sun5i_timer_init); |
diff --git a/drivers/clocksource/timer-ti-32k.c b/drivers/clocksource/timer-ti-32k.c index 624067712ef0..880a861ab3c8 100644 --- a/drivers/clocksource/timer-ti-32k.c +++ b/drivers/clocksource/timer-ti-32k.c | |||
@@ -124,5 +124,5 @@ static int __init ti_32k_timer_init(struct device_node *np) | |||
124 | 124 | ||
125 | return 0; | 125 | return 0; |
126 | } | 126 | } |
127 | CLOCKSOURCE_OF_DECLARE(ti_32k_timer, "ti,omap-counter32k", | 127 | TIMER_OF_DECLARE(ti_32k_timer, "ti,omap-counter32k", |
128 | ti_32k_timer_init); | 128 | ti_32k_timer_init); |
diff --git a/drivers/clocksource/timer-u300.c b/drivers/clocksource/timer-u300.c index 704e40c6f151..be34b116d4d2 100644 --- a/drivers/clocksource/timer-u300.c +++ b/drivers/clocksource/timer-u300.c | |||
@@ -458,5 +458,5 @@ static int __init u300_timer_init_of(struct device_node *np) | |||
458 | return 0; | 458 | return 0; |
459 | } | 459 | } |
460 | 460 | ||
461 | CLOCKSOURCE_OF_DECLARE(u300_timer, "stericsson,u300-apptimer", | 461 | TIMER_OF_DECLARE(u300_timer, "stericsson,u300-apptimer", |
462 | u300_timer_init_of); | 462 | u300_timer_init_of); |
diff --git a/drivers/clocksource/versatile.c b/drivers/clocksource/versatile.c index 220b490a8142..39725d38aede 100644 --- a/drivers/clocksource/versatile.c +++ b/drivers/clocksource/versatile.c | |||
@@ -38,7 +38,7 @@ static int __init versatile_sched_clock_init(struct device_node *node) | |||
38 | 38 | ||
39 | return 0; | 39 | return 0; |
40 | } | 40 | } |
41 | CLOCKSOURCE_OF_DECLARE(vexpress, "arm,vexpress-sysreg", | 41 | TIMER_OF_DECLARE(vexpress, "arm,vexpress-sysreg", |
42 | versatile_sched_clock_init); | 42 | versatile_sched_clock_init); |
43 | CLOCKSOURCE_OF_DECLARE(versatile, "arm,versatile-sysreg", | 43 | TIMER_OF_DECLARE(versatile, "arm,versatile-sysreg", |
44 | versatile_sched_clock_init); | 44 | versatile_sched_clock_init); |
diff --git a/drivers/clocksource/vf_pit_timer.c b/drivers/clocksource/vf_pit_timer.c index e0849e20a307..0f92089ec08c 100644 --- a/drivers/clocksource/vf_pit_timer.c +++ b/drivers/clocksource/vf_pit_timer.c | |||
@@ -201,4 +201,4 @@ static int __init pit_timer_init(struct device_node *np) | |||
201 | 201 | ||
202 | return pit_clockevent_init(clk_rate, irq); | 202 | return pit_clockevent_init(clk_rate, irq); |
203 | } | 203 | } |
204 | CLOCKSOURCE_OF_DECLARE(vf610, "fsl,vf610-pit", pit_timer_init); | 204 | TIMER_OF_DECLARE(vf610, "fsl,vf610-pit", pit_timer_init); |
diff --git a/drivers/clocksource/vt8500_timer.c b/drivers/clocksource/vt8500_timer.c index d02b51075ad1..e0f7489cfc8e 100644 --- a/drivers/clocksource/vt8500_timer.c +++ b/drivers/clocksource/vt8500_timer.c | |||
@@ -165,4 +165,4 @@ static int __init vt8500_timer_init(struct device_node *np) | |||
165 | return 0; | 165 | return 0; |
166 | } | 166 | } |
167 | 167 | ||
168 | CLOCKSOURCE_OF_DECLARE(vt8500, "via,vt8500-timer", vt8500_timer_init); | 168 | TIMER_OF_DECLARE(vt8500, "via,vt8500-timer", vt8500_timer_init); |
diff --git a/drivers/clocksource/zevio-timer.c b/drivers/clocksource/zevio-timer.c index 9a53f5ef6157..a6a0338eea77 100644 --- a/drivers/clocksource/zevio-timer.c +++ b/drivers/clocksource/zevio-timer.c | |||
@@ -215,4 +215,4 @@ static int __init zevio_timer_init(struct device_node *node) | |||
215 | return zevio_timer_add(node); | 215 | return zevio_timer_add(node); |
216 | } | 216 | } |
217 | 217 | ||
218 | CLOCKSOURCE_OF_DECLARE(zevio_timer, "lsi,zevio-timer", zevio_timer_init); | 218 | TIMER_OF_DECLARE(zevio_timer, "lsi,zevio-timer", zevio_timer_init); |
diff --git a/include/asm-generic/siginfo.h b/include/asm-generic/siginfo.h deleted file mode 100644 index a2508a8f9a9c..000000000000 --- a/include/asm-generic/siginfo.h +++ /dev/null | |||
@@ -1,22 +0,0 @@ | |||
1 | #ifndef _ASM_GENERIC_SIGINFO_H | ||
2 | #define _ASM_GENERIC_SIGINFO_H | ||
3 | |||
4 | #include <uapi/asm-generic/siginfo.h> | ||
5 | |||
6 | #define __SI_MASK 0xffff0000u | ||
7 | #define __SI_KILL (0 << 16) | ||
8 | #define __SI_TIMER (1 << 16) | ||
9 | #define __SI_POLL (2 << 16) | ||
10 | #define __SI_FAULT (3 << 16) | ||
11 | #define __SI_CHLD (4 << 16) | ||
12 | #define __SI_RT (5 << 16) | ||
13 | #define __SI_MESGQ (6 << 16) | ||
14 | #define __SI_SYS (7 << 16) | ||
15 | #define __SI_CODE(T,N) ((T) | ((N) & 0xffff)) | ||
16 | |||
17 | struct siginfo; | ||
18 | void do_schedule_next_timer(struct siginfo *info); | ||
19 | |||
20 | extern int copy_siginfo_to_user(struct siginfo __user *to, const struct siginfo *from); | ||
21 | |||
22 | #endif | ||
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 314a0b9219c6..0d64658a224f 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h | |||
@@ -172,8 +172,7 @@ | |||
172 | KEEP(*(__##name##_of_table)) \ | 172 | KEEP(*(__##name##_of_table)) \ |
173 | KEEP(*(__##name##_of_table_end)) | 173 | KEEP(*(__##name##_of_table_end)) |
174 | 174 | ||
175 | #define CLKSRC_OF_TABLES() OF_TABLE(CONFIG_CLKSRC_OF, clksrc) | 175 | #define TIMER_OF_TABLES() OF_TABLE(CONFIG_TIMER_OF, timer) |
176 | #define CLKEVT_OF_TABLES() OF_TABLE(CONFIG_CLKEVT_OF, clkevt) | ||
177 | #define IRQCHIP_OF_MATCH_TABLE() OF_TABLE(CONFIG_IRQCHIP, irqchip) | 176 | #define IRQCHIP_OF_MATCH_TABLE() OF_TABLE(CONFIG_IRQCHIP, irqchip) |
178 | #define CLK_OF_TABLES() OF_TABLE(CONFIG_COMMON_CLK, clk) | 177 | #define CLK_OF_TABLES() OF_TABLE(CONFIG_COMMON_CLK, clk) |
179 | #define IOMMU_OF_TABLES() OF_TABLE(CONFIG_OF_IOMMU, iommu) | 178 | #define IOMMU_OF_TABLES() OF_TABLE(CONFIG_OF_IOMMU, iommu) |
@@ -557,15 +556,15 @@ | |||
557 | MEM_DISCARD(init.rodata) \ | 556 | MEM_DISCARD(init.rodata) \ |
558 | CLK_OF_TABLES() \ | 557 | CLK_OF_TABLES() \ |
559 | RESERVEDMEM_OF_TABLES() \ | 558 | RESERVEDMEM_OF_TABLES() \ |
560 | CLKSRC_OF_TABLES() \ | 559 | TIMER_OF_TABLES() \ |
561 | CLKEVT_OF_TABLES() \ | ||
562 | IOMMU_OF_TABLES() \ | 560 | IOMMU_OF_TABLES() \ |
563 | CPU_METHOD_OF_TABLES() \ | 561 | CPU_METHOD_OF_TABLES() \ |
564 | CPUIDLE_METHOD_OF_TABLES() \ | 562 | CPUIDLE_METHOD_OF_TABLES() \ |
565 | KERNEL_DTB() \ | 563 | KERNEL_DTB() \ |
566 | IRQCHIP_OF_MATCH_TABLE() \ | 564 | IRQCHIP_OF_MATCH_TABLE() \ |
567 | ACPI_PROBE_TABLE(irqchip) \ | 565 | ACPI_PROBE_TABLE(irqchip) \ |
568 | ACPI_PROBE_TABLE(clksrc) \ | 566 | ACPI_PROBE_TABLE(timer) \ |
567 | ACPI_PROBE_TABLE(iort) \ | ||
569 | EARLYCON_TABLE() | 568 | EARLYCON_TABLE() |
570 | 569 | ||
571 | #define INIT_TEXT \ | 570 | #define INIT_TEXT \ |
diff --git a/include/linux/clockchips.h b/include/linux/clockchips.h index acc9ce05e5f0..a116926598fd 100644 --- a/include/linux/clockchips.h +++ b/include/linux/clockchips.h | |||
@@ -223,13 +223,4 @@ static inline void tick_setup_hrtimer_broadcast(void) { } | |||
223 | 223 | ||
224 | #endif /* !CONFIG_GENERIC_CLOCKEVENTS */ | 224 | #endif /* !CONFIG_GENERIC_CLOCKEVENTS */ |
225 | 225 | ||
226 | #define CLOCKEVENT_OF_DECLARE(name, compat, fn) \ | ||
227 | OF_DECLARE_1_RET(clkevt, name, compat, fn) | ||
228 | |||
229 | #ifdef CONFIG_CLKEVT_PROBE | ||
230 | extern int clockevent_probe(void); | ||
231 | #else | ||
232 | static inline int clockevent_probe(void) { return 0; } | ||
233 | #endif | ||
234 | |||
235 | #endif /* _LINUX_CLOCKCHIPS_H */ | 226 | #endif /* _LINUX_CLOCKCHIPS_H */ |
diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h index 81490456c242..a78cb1848e65 100644 --- a/include/linux/clocksource.h +++ b/include/linux/clocksource.h | |||
@@ -250,16 +250,19 @@ extern int clocksource_mmio_init(void __iomem *, const char *, | |||
250 | 250 | ||
251 | extern int clocksource_i8253_init(void); | 251 | extern int clocksource_i8253_init(void); |
252 | 252 | ||
253 | #define TIMER_OF_DECLARE(name, compat, fn) \ | ||
254 | OF_DECLARE_1_RET(timer, name, compat, fn) | ||
255 | |||
253 | #define CLOCKSOURCE_OF_DECLARE(name, compat, fn) \ | 256 | #define CLOCKSOURCE_OF_DECLARE(name, compat, fn) \ |
254 | OF_DECLARE_1_RET(clksrc, name, compat, fn) | 257 | TIMER_OF_DECLARE(name, compat, fn) |
255 | 258 | ||
256 | #ifdef CONFIG_CLKSRC_PROBE | 259 | #ifdef CONFIG_TIMER_PROBE |
257 | extern void clocksource_probe(void); | 260 | extern void timer_probe(void); |
258 | #else | 261 | #else |
259 | static inline void clocksource_probe(void) {} | 262 | static inline void timer_probe(void) {} |
260 | #endif | 263 | #endif |
261 | 264 | ||
262 | #define CLOCKSOURCE_ACPI_DECLARE(name, table_id, fn) \ | 265 | #define TIMER_ACPI_DECLARE(name, table_id, fn) \ |
263 | ACPI_DECLARE_PROBE_ENTRY(clksrc, name, table_id, 0, NULL, 0, fn) | 266 | ACPI_DECLARE_PROBE_ENTRY(timer, name, table_id, 0, NULL, 0, fn) |
264 | 267 | ||
265 | #endif /* _LINUX_CLOCKSOURCE_H */ | 268 | #endif /* _LINUX_CLOCKSOURCE_H */ |
diff --git a/include/linux/compat.h b/include/linux/compat.h index 1c5f3152cbb5..425563c7647b 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h | |||
@@ -94,6 +94,10 @@ struct compat_itimerval { | |||
94 | struct compat_timeval it_value; | 94 | struct compat_timeval it_value; |
95 | }; | 95 | }; |
96 | 96 | ||
97 | struct itimerval; | ||
98 | int get_compat_itimerval(struct itimerval *, const struct compat_itimerval __user *); | ||
99 | int put_compat_itimerval(struct compat_itimerval __user *, const struct itimerval *); | ||
100 | |||
97 | struct compat_tms { | 101 | struct compat_tms { |
98 | compat_clock_t tms_utime; | 102 | compat_clock_t tms_utime; |
99 | compat_clock_t tms_stime; | 103 | compat_clock_t tms_stime; |
@@ -128,6 +132,10 @@ struct compat_timex { | |||
128 | compat_int_t:32; compat_int_t:32; compat_int_t:32; | 132 | compat_int_t:32; compat_int_t:32; compat_int_t:32; |
129 | }; | 133 | }; |
130 | 134 | ||
135 | struct timex; | ||
136 | int compat_get_timex(struct timex *, const struct compat_timex __user *); | ||
137 | int compat_put_timex(struct compat_timex __user *, const struct timex *); | ||
138 | |||
131 | #define _COMPAT_NSIG_WORDS (_COMPAT_NSIG / _COMPAT_NSIG_BPW) | 139 | #define _COMPAT_NSIG_WORDS (_COMPAT_NSIG / _COMPAT_NSIG_BPW) |
132 | 140 | ||
133 | typedef struct { | 141 | typedef struct { |
diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h index 8c5b10eb7265..255edd5e7a74 100644 --- a/include/linux/hrtimer.h +++ b/include/linux/hrtimer.h | |||
@@ -452,11 +452,11 @@ static inline u64 hrtimer_forward_now(struct hrtimer *timer, | |||
452 | } | 452 | } |
453 | 453 | ||
454 | /* Precise sleep: */ | 454 | /* Precise sleep: */ |
455 | extern long hrtimer_nanosleep(struct timespec64 *rqtp, | 455 | |
456 | struct timespec __user *rmtp, | 456 | extern int nanosleep_copyout(struct restart_block *, struct timespec *); |
457 | extern long hrtimer_nanosleep(const struct timespec64 *rqtp, | ||
457 | const enum hrtimer_mode mode, | 458 | const enum hrtimer_mode mode, |
458 | const clockid_t clockid); | 459 | const clockid_t clockid); |
459 | extern long hrtimer_nanosleep_restart(struct restart_block *restart_block); | ||
460 | 460 | ||
461 | extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, | 461 | extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, |
462 | struct task_struct *tsk); | 462 | struct task_struct *tsk); |
diff --git a/include/linux/posix-clock.h b/include/linux/posix-clock.h index 83b22ae9ae12..38d8225510f1 100644 --- a/include/linux/posix-clock.h +++ b/include/linux/posix-clock.h | |||
@@ -42,12 +42,6 @@ struct posix_clock; | |||
42 | * @clock_gettime: Read the current time | 42 | * @clock_gettime: Read the current time |
43 | * @clock_getres: Get the clock resolution | 43 | * @clock_getres: Get the clock resolution |
44 | * @clock_settime: Set the current time value | 44 | * @clock_settime: Set the current time value |
45 | * @timer_create: Create a new timer | ||
46 | * @timer_delete: Remove a previously created timer | ||
47 | * @timer_gettime: Get remaining time and interval of a timer | ||
48 | * @timer_settime: Set a timer's initial expiration and interval | ||
49 | * @fasync: Optional character device fasync method | ||
50 | * @mmap: Optional character device mmap method | ||
51 | * @open: Optional character device open method | 45 | * @open: Optional character device open method |
52 | * @release: Optional character device release method | 46 | * @release: Optional character device release method |
53 | * @ioctl: Optional character device ioctl method | 47 | * @ioctl: Optional character device ioctl method |
@@ -66,28 +60,12 @@ struct posix_clock_operations { | |||
66 | int (*clock_settime)(struct posix_clock *pc, | 60 | int (*clock_settime)(struct posix_clock *pc, |
67 | const struct timespec64 *ts); | 61 | const struct timespec64 *ts); |
68 | 62 | ||
69 | int (*timer_create) (struct posix_clock *pc, struct k_itimer *kit); | ||
70 | |||
71 | int (*timer_delete) (struct posix_clock *pc, struct k_itimer *kit); | ||
72 | |||
73 | void (*timer_gettime)(struct posix_clock *pc, | ||
74 | struct k_itimer *kit, struct itimerspec64 *tsp); | ||
75 | |||
76 | int (*timer_settime)(struct posix_clock *pc, | ||
77 | struct k_itimer *kit, int flags, | ||
78 | struct itimerspec64 *tsp, struct itimerspec64 *old); | ||
79 | /* | 63 | /* |
80 | * Optional character device methods: | 64 | * Optional character device methods: |
81 | */ | 65 | */ |
82 | int (*fasync) (struct posix_clock *pc, | ||
83 | int fd, struct file *file, int on); | ||
84 | |||
85 | long (*ioctl) (struct posix_clock *pc, | 66 | long (*ioctl) (struct posix_clock *pc, |
86 | unsigned int cmd, unsigned long arg); | 67 | unsigned int cmd, unsigned long arg); |
87 | 68 | ||
88 | int (*mmap) (struct posix_clock *pc, | ||
89 | struct vm_area_struct *vma); | ||
90 | |||
91 | int (*open) (struct posix_clock *pc, fmode_t f_mode); | 69 | int (*open) (struct posix_clock *pc, fmode_t f_mode); |
92 | 70 | ||
93 | uint (*poll) (struct posix_clock *pc, | 71 | uint (*poll) (struct posix_clock *pc, |
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h index 8c1e43ab14a9..29f1b7f09ced 100644 --- a/include/linux/posix-timers.h +++ b/include/linux/posix-timers.h | |||
@@ -7,6 +7,7 @@ | |||
7 | #include <linux/timex.h> | 7 | #include <linux/timex.h> |
8 | #include <linux/alarmtimer.h> | 8 | #include <linux/alarmtimer.h> |
9 | 9 | ||
10 | struct siginfo; | ||
10 | 11 | ||
11 | struct cpu_timer_list { | 12 | struct cpu_timer_list { |
12 | struct list_head entry; | 13 | struct list_head entry; |
@@ -48,81 +49,69 @@ struct cpu_timer_list { | |||
48 | #define FD_TO_CLOCKID(fd) ((~(clockid_t) (fd) << 3) | CLOCKFD) | 49 | #define FD_TO_CLOCKID(fd) ((~(clockid_t) (fd) << 3) | CLOCKFD) |
49 | #define CLOCKID_TO_FD(clk) ((unsigned int) ~((clk) >> 3)) | 50 | #define CLOCKID_TO_FD(clk) ((unsigned int) ~((clk) >> 3)) |
50 | 51 | ||
51 | /* POSIX.1b interval timer structure. */ | ||
52 | struct k_itimer { | ||
53 | struct list_head list; /* free/ allocate list */ | ||
54 | struct hlist_node t_hash; | ||
55 | spinlock_t it_lock; | ||
56 | clockid_t it_clock; /* which timer type */ | ||
57 | timer_t it_id; /* timer id */ | ||
58 | int it_overrun; /* overrun on pending signal */ | ||
59 | int it_overrun_last; /* overrun on last delivered signal */ | ||
60 | int it_requeue_pending; /* waiting to requeue this timer */ | ||
61 | #define REQUEUE_PENDING 1 | 52 | #define REQUEUE_PENDING 1 |
62 | int it_sigev_notify; /* notify word of sigevent struct */ | 53 | |
63 | struct signal_struct *it_signal; | 54 | /** |
55 | * struct k_itimer - POSIX.1b interval timer structure. | ||
56 | * @list: List head for binding the timer to signals->posix_timers | ||
57 | * @t_hash: Entry in the posix timer hash table | ||
58 | * @it_lock: Lock protecting the timer | ||
59 | * @kclock: Pointer to the k_clock struct handling this timer | ||
60 | * @it_clock: The posix timer clock id | ||
61 | * @it_id: The posix timer id for identifying the timer | ||
62 | * @it_active: Marker that timer is active | ||
63 | * @it_overrun: The overrun counter for pending signals | ||
64 | * @it_overrun_last: The overrun at the time of the last delivered signal | ||
65 | * @it_requeue_pending: Indicator that timer waits for being requeued on | ||
66 | * signal delivery | ||
67 | * @it_sigev_notify: The notify word of sigevent struct for signal delivery | ||
68 | * @it_interval: The interval for periodic timers | ||
69 | * @it_signal: Pointer to the creators signal struct | ||
70 | * @it_pid: The pid of the process/task targeted by the signal | ||
71 | * @it_process: The task to wakeup on clock_nanosleep (CPU timers) | ||
72 | * @sigq: Pointer to preallocated sigqueue | ||
73 | * @it: Union representing the various posix timer type | ||
74 | * internals. Also used for rcu freeing the timer. | ||
75 | */ | ||
76 | struct k_itimer { | ||
77 | struct list_head list; | ||
78 | struct hlist_node t_hash; | ||
79 | spinlock_t it_lock; | ||
80 | const struct k_clock *kclock; | ||
81 | clockid_t it_clock; | ||
82 | timer_t it_id; | ||
83 | int it_active; | ||
84 | int it_overrun; | ||
85 | int it_overrun_last; | ||
86 | int it_requeue_pending; | ||
87 | int it_sigev_notify; | ||
88 | ktime_t it_interval; | ||
89 | struct signal_struct *it_signal; | ||
64 | union { | 90 | union { |
65 | struct pid *it_pid; /* pid of process to send signal to */ | 91 | struct pid *it_pid; |
66 | struct task_struct *it_process; /* for clock_nanosleep */ | 92 | struct task_struct *it_process; |
67 | }; | 93 | }; |
68 | struct sigqueue *sigq; /* signal queue entry. */ | 94 | struct sigqueue *sigq; |
69 | union { | 95 | union { |
70 | struct { | 96 | struct { |
71 | struct hrtimer timer; | 97 | struct hrtimer timer; |
72 | ktime_t interval; | ||
73 | } real; | 98 | } real; |
74 | struct cpu_timer_list cpu; | 99 | struct cpu_timer_list cpu; |
75 | struct { | 100 | struct { |
76 | unsigned int clock; | 101 | struct alarm alarmtimer; |
77 | unsigned int node; | ||
78 | unsigned long incr; | ||
79 | unsigned long expires; | ||
80 | } mmtimer; | ||
81 | struct { | ||
82 | struct alarm alarmtimer; | ||
83 | ktime_t interval; | ||
84 | } alarm; | 102 | } alarm; |
85 | struct rcu_head rcu; | 103 | struct rcu_head rcu; |
86 | } it; | 104 | } it; |
87 | }; | 105 | }; |
88 | 106 | ||
89 | struct k_clock { | ||
90 | int (*clock_getres) (const clockid_t which_clock, struct timespec64 *tp); | ||
91 | int (*clock_set) (const clockid_t which_clock, | ||
92 | const struct timespec64 *tp); | ||
93 | int (*clock_get) (const clockid_t which_clock, struct timespec64 *tp); | ||
94 | int (*clock_adj) (const clockid_t which_clock, struct timex *tx); | ||
95 | int (*timer_create) (struct k_itimer *timer); | ||
96 | int (*nsleep) (const clockid_t which_clock, int flags, | ||
97 | struct timespec64 *, struct timespec __user *); | ||
98 | long (*nsleep_restart) (struct restart_block *restart_block); | ||
99 | int (*timer_set) (struct k_itimer *timr, int flags, | ||
100 | struct itimerspec64 *new_setting, | ||
101 | struct itimerspec64 *old_setting); | ||
102 | int (*timer_del) (struct k_itimer *timr); | ||
103 | #define TIMER_RETRY 1 | ||
104 | void (*timer_get) (struct k_itimer *timr, | ||
105 | struct itimerspec64 *cur_setting); | ||
106 | }; | ||
107 | |||
108 | extern struct k_clock clock_posix_cpu; | ||
109 | extern struct k_clock clock_posix_dynamic; | ||
110 | |||
111 | void posix_timers_register_clock(const clockid_t clock_id, struct k_clock *new_clock); | ||
112 | |||
113 | /* function to call to trigger timer event */ | ||
114 | int posix_timer_event(struct k_itimer *timr, int si_private); | ||
115 | |||
116 | void posix_cpu_timer_schedule(struct k_itimer *timer); | ||
117 | |||
118 | void run_posix_cpu_timers(struct task_struct *task); | 107 | void run_posix_cpu_timers(struct task_struct *task); |
119 | void posix_cpu_timers_exit(struct task_struct *task); | 108 | void posix_cpu_timers_exit(struct task_struct *task); |
120 | void posix_cpu_timers_exit_group(struct task_struct *task); | 109 | void posix_cpu_timers_exit_group(struct task_struct *task); |
121 | void set_process_cpu_timer(struct task_struct *task, unsigned int clock_idx, | 110 | void set_process_cpu_timer(struct task_struct *task, unsigned int clock_idx, |
122 | u64 *newval, u64 *oldval); | 111 | u64 *newval, u64 *oldval); |
123 | 112 | ||
124 | long clock_nanosleep_restart(struct restart_block *restart_block); | ||
125 | |||
126 | void update_rlimit_cpu(struct task_struct *task, unsigned long rlim_new); | 113 | void update_rlimit_cpu(struct task_struct *task, unsigned long rlim_new); |
127 | 114 | ||
115 | void posixtimer_rearm(struct siginfo *info); | ||
116 | |||
128 | #endif | 117 | #endif |
diff --git a/include/linux/restart_block.h b/include/linux/restart_block.h index 0d905d8ec553..19df8422606c 100644 --- a/include/linux/restart_block.h +++ b/include/linux/restart_block.h | |||
@@ -11,6 +11,14 @@ struct timespec; | |||
11 | struct compat_timespec; | 11 | struct compat_timespec; |
12 | struct pollfd; | 12 | struct pollfd; |
13 | 13 | ||
14 | enum timespec_type { | ||
15 | TT_NONE = 0, | ||
16 | TT_NATIVE = 1, | ||
17 | #ifdef CONFIG_COMPAT | ||
18 | TT_COMPAT = 2, | ||
19 | #endif | ||
20 | }; | ||
21 | |||
14 | /* | 22 | /* |
15 | * System call restart block. | 23 | * System call restart block. |
16 | */ | 24 | */ |
@@ -29,10 +37,13 @@ struct restart_block { | |||
29 | /* For nanosleep */ | 37 | /* For nanosleep */ |
30 | struct { | 38 | struct { |
31 | clockid_t clockid; | 39 | clockid_t clockid; |
32 | struct timespec __user *rmtp; | 40 | enum timespec_type type; |
41 | union { | ||
42 | struct timespec __user *rmtp; | ||
33 | #ifdef CONFIG_COMPAT | 43 | #ifdef CONFIG_COMPAT |
34 | struct compat_timespec __user *compat_rmtp; | 44 | struct compat_timespec __user *compat_rmtp; |
35 | #endif | 45 | #endif |
46 | }; | ||
36 | u64 expires; | 47 | u64 expires; |
37 | } nanosleep; | 48 | } nanosleep; |
38 | /* For poll */ | 49 | /* For poll */ |
diff --git a/include/linux/signal.h b/include/linux/signal.h index 1f5a16620693..a39feddd71ba 100644 --- a/include/linux/signal.h +++ b/include/linux/signal.h | |||
@@ -3,16 +3,13 @@ | |||
3 | 3 | ||
4 | #include <linux/bug.h> | 4 | #include <linux/bug.h> |
5 | #include <linux/signal_types.h> | 5 | #include <linux/signal_types.h> |
6 | #include <linux/string.h> | ||
6 | 7 | ||
7 | struct task_struct; | 8 | struct task_struct; |
8 | 9 | ||
9 | /* for sysctl */ | 10 | /* for sysctl */ |
10 | extern int print_fatal_signals; | 11 | extern int print_fatal_signals; |
11 | 12 | ||
12 | #ifndef HAVE_ARCH_COPY_SIGINFO | ||
13 | |||
14 | #include <linux/string.h> | ||
15 | |||
16 | static inline void copy_siginfo(struct siginfo *to, struct siginfo *from) | 13 | static inline void copy_siginfo(struct siginfo *to, struct siginfo *from) |
17 | { | 14 | { |
18 | if (from->si_code < 0) | 15 | if (from->si_code < 0) |
@@ -22,7 +19,7 @@ static inline void copy_siginfo(struct siginfo *to, struct siginfo *from) | |||
22 | memcpy(to, from, __ARCH_SI_PREAMBLE_SIZE + sizeof(from->_sifields._sigchld)); | 19 | memcpy(to, from, __ARCH_SI_PREAMBLE_SIZE + sizeof(from->_sifields._sigchld)); |
23 | } | 20 | } |
24 | 21 | ||
25 | #endif | 22 | int copy_siginfo_to_user(struct siginfo __user *to, const struct siginfo *from); |
26 | 23 | ||
27 | /* | 24 | /* |
28 | * Define some primitives to manipulate sigset_t. | 25 | * Define some primitives to manipulate sigset_t. |
diff --git a/include/linux/timekeeper_internal.h b/include/linux/timekeeper_internal.h index f7043ccca81c..0a0a53daf2a2 100644 --- a/include/linux/timekeeper_internal.h +++ b/include/linux/timekeeper_internal.h | |||
@@ -51,7 +51,7 @@ struct tk_read_base { | |||
51 | * @clock_was_set_seq: The sequence number of clock was set events | 51 | * @clock_was_set_seq: The sequence number of clock was set events |
52 | * @cs_was_changed_seq: The sequence number of clocksource change events | 52 | * @cs_was_changed_seq: The sequence number of clocksource change events |
53 | * @next_leap_ktime: CLOCK_MONOTONIC time value of a pending leap-second | 53 | * @next_leap_ktime: CLOCK_MONOTONIC time value of a pending leap-second |
54 | * @raw_time: Monotonic raw base time in timespec64 format | 54 | * @raw_sec: CLOCK_MONOTONIC_RAW time in seconds |
55 | * @cycle_interval: Number of clock cycles in one NTP interval | 55 | * @cycle_interval: Number of clock cycles in one NTP interval |
56 | * @xtime_interval: Number of clock shifted nano seconds in one NTP | 56 | * @xtime_interval: Number of clock shifted nano seconds in one NTP |
57 | * interval. | 57 | * interval. |
@@ -93,7 +93,7 @@ struct timekeeper { | |||
93 | unsigned int clock_was_set_seq; | 93 | unsigned int clock_was_set_seq; |
94 | u8 cs_was_changed_seq; | 94 | u8 cs_was_changed_seq; |
95 | ktime_t next_leap_ktime; | 95 | ktime_t next_leap_ktime; |
96 | struct timespec64 raw_time; | 96 | u64 raw_sec; |
97 | 97 | ||
98 | /* The following members are for timekeeping internal use */ | 98 | /* The following members are for timekeeping internal use */ |
99 | u64 cycle_interval; | 99 | u64 cycle_interval; |
diff --git a/include/uapi/asm-generic/siginfo.h b/include/uapi/asm-generic/siginfo.h index 1abaf62c86fc..9c4eca6b374a 100644 --- a/include/uapi/asm-generic/siginfo.h +++ b/include/uapi/asm-generic/siginfo.h | |||
@@ -151,7 +151,18 @@ typedef struct siginfo { | |||
151 | #define si_arch _sifields._sigsys._arch | 151 | #define si_arch _sifields._sigsys._arch |
152 | #endif | 152 | #endif |
153 | 153 | ||
154 | #ifndef __KERNEL__ | 154 | #ifdef __KERNEL__ |
155 | #define __SI_MASK 0xffff0000u | ||
156 | #define __SI_KILL (0 << 16) | ||
157 | #define __SI_TIMER (1 << 16) | ||
158 | #define __SI_POLL (2 << 16) | ||
159 | #define __SI_FAULT (3 << 16) | ||
160 | #define __SI_CHLD (4 << 16) | ||
161 | #define __SI_RT (5 << 16) | ||
162 | #define __SI_MESGQ (6 << 16) | ||
163 | #define __SI_SYS (7 << 16) | ||
164 | #define __SI_CODE(T,N) ((T) | ((N) & 0xffff)) | ||
165 | #else /* __KERNEL__ */ | ||
155 | #define __SI_KILL 0 | 166 | #define __SI_KILL 0 |
156 | #define __SI_TIMER 0 | 167 | #define __SI_TIMER 0 |
157 | #define __SI_POLL 0 | 168 | #define __SI_POLL 0 |
@@ -161,7 +172,7 @@ typedef struct siginfo { | |||
161 | #define __SI_MESGQ 0 | 172 | #define __SI_MESGQ 0 |
162 | #define __SI_SYS 0 | 173 | #define __SI_SYS 0 |
163 | #define __SI_CODE(T,N) (N) | 174 | #define __SI_CODE(T,N) (N) |
164 | #endif | 175 | #endif /* __KERNEL__ */ |
165 | 176 | ||
166 | /* | 177 | /* |
167 | * si_code values | 178 | * si_code values |
diff --git a/include/uapi/linux/time.h b/include/uapi/linux/time.h index e75e1b6ff27f..09299fcb842a 100644 --- a/include/uapi/linux/time.h +++ b/include/uapi/linux/time.h | |||
@@ -54,7 +54,11 @@ struct itimerval { | |||
54 | #define CLOCK_BOOTTIME 7 | 54 | #define CLOCK_BOOTTIME 7 |
55 | #define CLOCK_REALTIME_ALARM 8 | 55 | #define CLOCK_REALTIME_ALARM 8 |
56 | #define CLOCK_BOOTTIME_ALARM 9 | 56 | #define CLOCK_BOOTTIME_ALARM 9 |
57 | #define CLOCK_SGI_CYCLE 10 /* Hardware specific */ | 57 | /* |
58 | * The driver implementing this got removed. The clock ID is kept as a | ||
59 | * place holder. Do not reuse! | ||
60 | */ | ||
61 | #define CLOCK_SGI_CYCLE 10 | ||
58 | #define CLOCK_TAI 11 | 62 | #define CLOCK_TAI 11 |
59 | 63 | ||
60 | #define MAX_CLOCKS 16 | 64 | #define MAX_CLOCKS 16 |
diff --git a/kernel/compat.c b/kernel/compat.c index 933bcb31ae10..ebd8bdc3fd68 100644 --- a/kernel/compat.c +++ b/kernel/compat.c | |||
@@ -30,100 +30,66 @@ | |||
30 | 30 | ||
31 | #include <linux/uaccess.h> | 31 | #include <linux/uaccess.h> |
32 | 32 | ||
33 | static int compat_get_timex(struct timex *txc, struct compat_timex __user *utp) | 33 | int compat_get_timex(struct timex *txc, const struct compat_timex __user *utp) |
34 | { | 34 | { |
35 | memset(txc, 0, sizeof(struct timex)); | 35 | struct compat_timex tx32; |
36 | |||
37 | if (!access_ok(VERIFY_READ, utp, sizeof(struct compat_timex)) || | ||
38 | __get_user(txc->modes, &utp->modes) || | ||
39 | __get_user(txc->offset, &utp->offset) || | ||
40 | __get_user(txc->freq, &utp->freq) || | ||
41 | __get_user(txc->maxerror, &utp->maxerror) || | ||
42 | __get_user(txc->esterror, &utp->esterror) || | ||
43 | __get_user(txc->status, &utp->status) || | ||
44 | __get_user(txc->constant, &utp->constant) || | ||
45 | __get_user(txc->precision, &utp->precision) || | ||
46 | __get_user(txc->tolerance, &utp->tolerance) || | ||
47 | __get_user(txc->time.tv_sec, &utp->time.tv_sec) || | ||
48 | __get_user(txc->time.tv_usec, &utp->time.tv_usec) || | ||
49 | __get_user(txc->tick, &utp->tick) || | ||
50 | __get_user(txc->ppsfreq, &utp->ppsfreq) || | ||
51 | __get_user(txc->jitter, &utp->jitter) || | ||
52 | __get_user(txc->shift, &utp->shift) || | ||
53 | __get_user(txc->stabil, &utp->stabil) || | ||
54 | __get_user(txc->jitcnt, &utp->jitcnt) || | ||
55 | __get_user(txc->calcnt, &utp->calcnt) || | ||
56 | __get_user(txc->errcnt, &utp->errcnt) || | ||
57 | __get_user(txc->stbcnt, &utp->stbcnt)) | ||
58 | return -EFAULT; | ||
59 | 36 | ||
60 | return 0; | 37 | if (copy_from_user(&tx32, utp, sizeof(struct compat_timex))) |
61 | } | ||
62 | |||
63 | static int compat_put_timex(struct compat_timex __user *utp, struct timex *txc) | ||
64 | { | ||
65 | if (!access_ok(VERIFY_WRITE, utp, sizeof(struct compat_timex)) || | ||
66 | __put_user(txc->modes, &utp->modes) || | ||
67 | __put_user(txc->offset, &utp->offset) || | ||
68 | __put_user(txc->freq, &utp->freq) || | ||
69 | __put_user(txc->maxerror, &utp->maxerror) || | ||
70 | __put_user(txc->esterror, &utp->esterror) || | ||
71 | __put_user(txc->status, &utp->status) || | ||
72 | __put_user(txc->constant, &utp->constant) || | ||
73 | __put_user(txc->precision, &utp->precision) || | ||
74 | __put_user(txc->tolerance, &utp->tolerance) || | ||
75 | __put_user(txc->time.tv_sec, &utp->time.tv_sec) || | ||
76 | __put_user(txc->time.tv_usec, &utp->time.tv_usec) || | ||
77 | __put_user(txc->tick, &utp->tick) || | ||
78 | __put_user(txc->ppsfreq, &utp->ppsfreq) || | ||
79 | __put_user(txc->jitter, &utp->jitter) || | ||
80 | __put_user(txc->shift, &utp->shift) || | ||
81 | __put_user(txc->stabil, &utp->stabil) || | ||
82 | __put_user(txc->jitcnt, &utp->jitcnt) || | ||
83 | __put_user(txc->calcnt, &utp->calcnt) || | ||
84 | __put_user(txc->errcnt, &utp->errcnt) || | ||
85 | __put_user(txc->stbcnt, &utp->stbcnt) || | ||
86 | __put_user(txc->tai, &utp->tai)) | ||
87 | return -EFAULT; | 38 | return -EFAULT; |
88 | return 0; | ||
89 | } | ||
90 | 39 | ||
91 | COMPAT_SYSCALL_DEFINE2(gettimeofday, struct compat_timeval __user *, tv, | 40 | txc->modes = tx32.modes; |
92 | struct timezone __user *, tz) | 41 | txc->offset = tx32.offset; |
93 | { | 42 | txc->freq = tx32.freq; |
94 | if (tv) { | 43 | txc->maxerror = tx32.maxerror; |
95 | struct timeval ktv; | 44 | txc->esterror = tx32.esterror; |
96 | do_gettimeofday(&ktv); | 45 | txc->status = tx32.status; |
97 | if (compat_put_timeval(&ktv, tv)) | 46 | txc->constant = tx32.constant; |
98 | return -EFAULT; | 47 | txc->precision = tx32.precision; |
99 | } | 48 | txc->tolerance = tx32.tolerance; |
100 | if (tz) { | 49 | txc->time.tv_sec = tx32.time.tv_sec; |
101 | if (copy_to_user(tz, &sys_tz, sizeof(sys_tz))) | 50 | txc->time.tv_usec = tx32.time.tv_usec; |
102 | return -EFAULT; | 51 | txc->tick = tx32.tick; |
103 | } | 52 | txc->ppsfreq = tx32.ppsfreq; |
53 | txc->jitter = tx32.jitter; | ||
54 | txc->shift = tx32.shift; | ||
55 | txc->stabil = tx32.stabil; | ||
56 | txc->jitcnt = tx32.jitcnt; | ||
57 | txc->calcnt = tx32.calcnt; | ||
58 | txc->errcnt = tx32.errcnt; | ||
59 | txc->stbcnt = tx32.stbcnt; | ||
104 | 60 | ||
105 | return 0; | 61 | return 0; |
106 | } | 62 | } |
107 | 63 | ||
108 | COMPAT_SYSCALL_DEFINE2(settimeofday, struct compat_timeval __user *, tv, | 64 | int compat_put_timex(struct compat_timex __user *utp, const struct timex *txc) |
109 | struct timezone __user *, tz) | 65 | { |
110 | { | 66 | struct compat_timex tx32; |
111 | struct timespec64 new_ts; | 67 | |
112 | struct timeval user_tv; | 68 | memset(&tx32, 0, sizeof(struct compat_timex)); |
113 | struct timezone new_tz; | 69 | tx32.modes = txc->modes; |
114 | 70 | tx32.offset = txc->offset; | |
115 | if (tv) { | 71 | tx32.freq = txc->freq; |
116 | if (compat_get_timeval(&user_tv, tv)) | 72 | tx32.maxerror = txc->maxerror; |
117 | return -EFAULT; | 73 | tx32.esterror = txc->esterror; |
118 | new_ts.tv_sec = user_tv.tv_sec; | 74 | tx32.status = txc->status; |
119 | new_ts.tv_nsec = user_tv.tv_usec * NSEC_PER_USEC; | 75 | tx32.constant = txc->constant; |
120 | } | 76 | tx32.precision = txc->precision; |
121 | if (tz) { | 77 | tx32.tolerance = txc->tolerance; |
122 | if (copy_from_user(&new_tz, tz, sizeof(*tz))) | 78 | tx32.time.tv_sec = txc->time.tv_sec; |
123 | return -EFAULT; | 79 | tx32.time.tv_usec = txc->time.tv_usec; |
124 | } | 80 | tx32.tick = txc->tick; |
125 | 81 | tx32.ppsfreq = txc->ppsfreq; | |
126 | return do_sys_settimeofday64(tv ? &new_ts : NULL, tz ? &new_tz : NULL); | 82 | tx32.jitter = txc->jitter; |
83 | tx32.shift = txc->shift; | ||
84 | tx32.stabil = txc->stabil; | ||
85 | tx32.jitcnt = txc->jitcnt; | ||
86 | tx32.calcnt = txc->calcnt; | ||
87 | tx32.errcnt = txc->errcnt; | ||
88 | tx32.stbcnt = txc->stbcnt; | ||
89 | tx32.tai = txc->tai; | ||
90 | if (copy_to_user(utp, &tx32, sizeof(struct compat_timex))) | ||
91 | return -EFAULT; | ||
92 | return 0; | ||
127 | } | 93 | } |
128 | 94 | ||
129 | static int __compat_get_timeval(struct timeval *tv, const struct compat_timeval __user *ctv) | 95 | static int __compat_get_timeval(struct timeval *tv, const struct compat_timeval __user *ctv) |
@@ -213,141 +179,28 @@ int compat_convert_timespec(struct timespec __user **kts, | |||
213 | return 0; | 179 | return 0; |
214 | } | 180 | } |
215 | 181 | ||
216 | static long compat_nanosleep_restart(struct restart_block *restart) | 182 | int get_compat_itimerval(struct itimerval *o, const struct compat_itimerval __user *i) |
217 | { | ||
218 | struct compat_timespec __user *rmtp; | ||
219 | struct timespec rmt; | ||
220 | mm_segment_t oldfs; | ||
221 | long ret; | ||
222 | |||
223 | restart->nanosleep.rmtp = (struct timespec __user *) &rmt; | ||
224 | oldfs = get_fs(); | ||
225 | set_fs(KERNEL_DS); | ||
226 | ret = hrtimer_nanosleep_restart(restart); | ||
227 | set_fs(oldfs); | ||
228 | |||
229 | if (ret == -ERESTART_RESTARTBLOCK) { | ||
230 | rmtp = restart->nanosleep.compat_rmtp; | ||
231 | |||
232 | if (rmtp && compat_put_timespec(&rmt, rmtp)) | ||
233 | return -EFAULT; | ||
234 | } | ||
235 | |||
236 | return ret; | ||
237 | } | ||
238 | |||
239 | COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp, | ||
240 | struct compat_timespec __user *, rmtp) | ||
241 | { | 183 | { |
242 | struct timespec tu, rmt; | 184 | struct compat_itimerval v32; |
243 | struct timespec64 tu64; | ||
244 | mm_segment_t oldfs; | ||
245 | long ret; | ||
246 | 185 | ||
247 | if (compat_get_timespec(&tu, rqtp)) | 186 | if (copy_from_user(&v32, i, sizeof(struct compat_itimerval))) |
248 | return -EFAULT; | 187 | return -EFAULT; |
249 | 188 | o->it_interval.tv_sec = v32.it_interval.tv_sec; | |
250 | tu64 = timespec_to_timespec64(tu); | 189 | o->it_interval.tv_usec = v32.it_interval.tv_usec; |
251 | if (!timespec64_valid(&tu64)) | 190 | o->it_value.tv_sec = v32.it_value.tv_sec; |
252 | return -EINVAL; | 191 | o->it_value.tv_usec = v32.it_value.tv_usec; |
253 | 192 | return 0; | |
254 | oldfs = get_fs(); | ||
255 | set_fs(KERNEL_DS); | ||
256 | ret = hrtimer_nanosleep(&tu64, | ||
257 | rmtp ? (struct timespec __user *)&rmt : NULL, | ||
258 | HRTIMER_MODE_REL, CLOCK_MONOTONIC); | ||
259 | set_fs(oldfs); | ||
260 | |||
261 | /* | ||
262 | * hrtimer_nanosleep() can only return 0 or | ||
263 | * -ERESTART_RESTARTBLOCK here because: | ||
264 | * | ||
265 | * - we call it with HRTIMER_MODE_REL and therefor exclude the | ||
266 | * -ERESTARTNOHAND return path. | ||
267 | * | ||
268 | * - we supply the rmtp argument from the task stack (due to | ||
269 | * the necessary compat conversion. So the update cannot | ||
270 | * fail, which excludes the -EFAULT return path as well. If | ||
271 | * it fails nevertheless we have a bigger problem and wont | ||
272 | * reach this place anymore. | ||
273 | * | ||
274 | * - if the return value is 0, we do not have to update rmtp | ||
275 | * because there is no remaining time. | ||
276 | * | ||
277 | * We check for -ERESTART_RESTARTBLOCK nevertheless if the | ||
278 | * core implementation decides to return random nonsense. | ||
279 | */ | ||
280 | if (ret == -ERESTART_RESTARTBLOCK) { | ||
281 | struct restart_block *restart = ¤t->restart_block; | ||
282 | |||
283 | restart->fn = compat_nanosleep_restart; | ||
284 | restart->nanosleep.compat_rmtp = rmtp; | ||
285 | |||
286 | if (rmtp && compat_put_timespec(&rmt, rmtp)) | ||
287 | return -EFAULT; | ||
288 | } | ||
289 | return ret; | ||
290 | } | ||
291 | |||
292 | static inline long get_compat_itimerval(struct itimerval *o, | ||
293 | struct compat_itimerval __user *i) | ||
294 | { | ||
295 | return (!access_ok(VERIFY_READ, i, sizeof(*i)) || | ||
296 | (__get_user(o->it_interval.tv_sec, &i->it_interval.tv_sec) | | ||
297 | __get_user(o->it_interval.tv_usec, &i->it_interval.tv_usec) | | ||
298 | __get_user(o->it_value.tv_sec, &i->it_value.tv_sec) | | ||
299 | __get_user(o->it_value.tv_usec, &i->it_value.tv_usec))); | ||
300 | } | ||
301 | |||
302 | static inline long put_compat_itimerval(struct compat_itimerval __user *o, | ||
303 | struct itimerval *i) | ||
304 | { | ||
305 | return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) || | ||
306 | (__put_user(i->it_interval.tv_sec, &o->it_interval.tv_sec) | | ||
307 | __put_user(i->it_interval.tv_usec, &o->it_interval.tv_usec) | | ||
308 | __put_user(i->it_value.tv_sec, &o->it_value.tv_sec) | | ||
309 | __put_user(i->it_value.tv_usec, &o->it_value.tv_usec))); | ||
310 | } | ||
311 | |||
312 | asmlinkage long sys_ni_posix_timers(void); | ||
313 | |||
314 | COMPAT_SYSCALL_DEFINE2(getitimer, int, which, | ||
315 | struct compat_itimerval __user *, it) | ||
316 | { | ||
317 | struct itimerval kit; | ||
318 | int error; | ||
319 | |||
320 | if (!IS_ENABLED(CONFIG_POSIX_TIMERS)) | ||
321 | return sys_ni_posix_timers(); | ||
322 | |||
323 | error = do_getitimer(which, &kit); | ||
324 | if (!error && put_compat_itimerval(it, &kit)) | ||
325 | error = -EFAULT; | ||
326 | return error; | ||
327 | } | 193 | } |
328 | 194 | ||
329 | COMPAT_SYSCALL_DEFINE3(setitimer, int, which, | 195 | int put_compat_itimerval(struct compat_itimerval __user *o, const struct itimerval *i) |
330 | struct compat_itimerval __user *, in, | ||
331 | struct compat_itimerval __user *, out) | ||
332 | { | 196 | { |
333 | struct itimerval kin, kout; | 197 | struct compat_itimerval v32; |
334 | int error; | ||
335 | |||
336 | if (!IS_ENABLED(CONFIG_POSIX_TIMERS)) | ||
337 | return sys_ni_posix_timers(); | ||
338 | 198 | ||
339 | if (in) { | 199 | v32.it_interval.tv_sec = i->it_interval.tv_sec; |
340 | if (get_compat_itimerval(&kin, in)) | 200 | v32.it_interval.tv_usec = i->it_interval.tv_usec; |
341 | return -EFAULT; | 201 | v32.it_value.tv_sec = i->it_value.tv_sec; |
342 | } else | 202 | v32.it_value.tv_usec = i->it_value.tv_usec; |
343 | memset(&kin, 0, sizeof(kin)); | 203 | return copy_to_user(o, &v32, sizeof(struct compat_itimerval)) ? -EFAULT : 0; |
344 | |||
345 | error = do_setitimer(which, &kin, out ? &kout : NULL); | ||
346 | if (error || !out) | ||
347 | return error; | ||
348 | if (put_compat_itimerval(out, &kout)) | ||
349 | return -EFAULT; | ||
350 | return 0; | ||
351 | } | 204 | } |
352 | 205 | ||
353 | static compat_clock_t clock_t_to_compat_clock_t(clock_t x) | 206 | static compat_clock_t clock_t_to_compat_clock_t(clock_t x) |
@@ -689,193 +542,6 @@ int put_compat_itimerspec(struct compat_itimerspec __user *dst, | |||
689 | return 0; | 542 | return 0; |
690 | } | 543 | } |
691 | 544 | ||
692 | COMPAT_SYSCALL_DEFINE3(timer_create, clockid_t, which_clock, | ||
693 | struct compat_sigevent __user *, timer_event_spec, | ||
694 | timer_t __user *, created_timer_id) | ||
695 | { | ||
696 | struct sigevent __user *event = NULL; | ||
697 | |||
698 | if (timer_event_spec) { | ||
699 | struct sigevent kevent; | ||
700 | |||
701 | event = compat_alloc_user_space(sizeof(*event)); | ||
702 | if (get_compat_sigevent(&kevent, timer_event_spec) || | ||
703 | copy_to_user(event, &kevent, sizeof(*event))) | ||
704 | return -EFAULT; | ||
705 | } | ||
706 | |||
707 | return sys_timer_create(which_clock, event, created_timer_id); | ||
708 | } | ||
709 | |||
710 | COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags, | ||
711 | struct compat_itimerspec __user *, new, | ||
712 | struct compat_itimerspec __user *, old) | ||
713 | { | ||
714 | long err; | ||
715 | mm_segment_t oldfs; | ||
716 | struct itimerspec newts, oldts; | ||
717 | |||
718 | if (!new) | ||
719 | return -EINVAL; | ||
720 | if (get_compat_itimerspec(&newts, new)) | ||
721 | return -EFAULT; | ||
722 | oldfs = get_fs(); | ||
723 | set_fs(KERNEL_DS); | ||
724 | err = sys_timer_settime(timer_id, flags, | ||
725 | (struct itimerspec __user *) &newts, | ||
726 | (struct itimerspec __user *) &oldts); | ||
727 | set_fs(oldfs); | ||
728 | if (!err && old && put_compat_itimerspec(old, &oldts)) | ||
729 | return -EFAULT; | ||
730 | return err; | ||
731 | } | ||
732 | |||
733 | COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id, | ||
734 | struct compat_itimerspec __user *, setting) | ||
735 | { | ||
736 | long err; | ||
737 | mm_segment_t oldfs; | ||
738 | struct itimerspec ts; | ||
739 | |||
740 | oldfs = get_fs(); | ||
741 | set_fs(KERNEL_DS); | ||
742 | err = sys_timer_gettime(timer_id, | ||
743 | (struct itimerspec __user *) &ts); | ||
744 | set_fs(oldfs); | ||
745 | if (!err && put_compat_itimerspec(setting, &ts)) | ||
746 | return -EFAULT; | ||
747 | return err; | ||
748 | } | ||
749 | |||
750 | COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock, | ||
751 | struct compat_timespec __user *, tp) | ||
752 | { | ||
753 | long err; | ||
754 | mm_segment_t oldfs; | ||
755 | struct timespec ts; | ||
756 | |||
757 | if (compat_get_timespec(&ts, tp)) | ||
758 | return -EFAULT; | ||
759 | oldfs = get_fs(); | ||
760 | set_fs(KERNEL_DS); | ||
761 | err = sys_clock_settime(which_clock, | ||
762 | (struct timespec __user *) &ts); | ||
763 | set_fs(oldfs); | ||
764 | return err; | ||
765 | } | ||
766 | |||
767 | COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock, | ||
768 | struct compat_timespec __user *, tp) | ||
769 | { | ||
770 | long err; | ||
771 | mm_segment_t oldfs; | ||
772 | struct timespec ts; | ||
773 | |||
774 | oldfs = get_fs(); | ||
775 | set_fs(KERNEL_DS); | ||
776 | err = sys_clock_gettime(which_clock, | ||
777 | (struct timespec __user *) &ts); | ||
778 | set_fs(oldfs); | ||
779 | if (!err && compat_put_timespec(&ts, tp)) | ||
780 | return -EFAULT; | ||
781 | return err; | ||
782 | } | ||
783 | |||
784 | COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock, | ||
785 | struct compat_timex __user *, utp) | ||
786 | { | ||
787 | struct timex txc; | ||
788 | mm_segment_t oldfs; | ||
789 | int err, ret; | ||
790 | |||
791 | err = compat_get_timex(&txc, utp); | ||
792 | if (err) | ||
793 | return err; | ||
794 | |||
795 | oldfs = get_fs(); | ||
796 | set_fs(KERNEL_DS); | ||
797 | ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc); | ||
798 | set_fs(oldfs); | ||
799 | |||
800 | err = compat_put_timex(utp, &txc); | ||
801 | if (err) | ||
802 | return err; | ||
803 | |||
804 | return ret; | ||
805 | } | ||
806 | |||
807 | COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock, | ||
808 | struct compat_timespec __user *, tp) | ||
809 | { | ||
810 | long err; | ||
811 | mm_segment_t oldfs; | ||
812 | struct timespec ts; | ||
813 | |||
814 | oldfs = get_fs(); | ||
815 | set_fs(KERNEL_DS); | ||
816 | err = sys_clock_getres(which_clock, | ||
817 | (struct timespec __user *) &ts); | ||
818 | set_fs(oldfs); | ||
819 | if (!err && tp && compat_put_timespec(&ts, tp)) | ||
820 | return -EFAULT; | ||
821 | return err; | ||
822 | } | ||
823 | |||
824 | static long compat_clock_nanosleep_restart(struct restart_block *restart) | ||
825 | { | ||
826 | long err; | ||
827 | mm_segment_t oldfs; | ||
828 | struct timespec tu; | ||
829 | struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp; | ||
830 | |||
831 | restart->nanosleep.rmtp = (struct timespec __user *) &tu; | ||
832 | oldfs = get_fs(); | ||
833 | set_fs(KERNEL_DS); | ||
834 | err = clock_nanosleep_restart(restart); | ||
835 | set_fs(oldfs); | ||
836 | |||
837 | if ((err == -ERESTART_RESTARTBLOCK) && rmtp && | ||
838 | compat_put_timespec(&tu, rmtp)) | ||
839 | return -EFAULT; | ||
840 | |||
841 | if (err == -ERESTART_RESTARTBLOCK) { | ||
842 | restart->fn = compat_clock_nanosleep_restart; | ||
843 | restart->nanosleep.compat_rmtp = rmtp; | ||
844 | } | ||
845 | return err; | ||
846 | } | ||
847 | |||
848 | COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags, | ||
849 | struct compat_timespec __user *, rqtp, | ||
850 | struct compat_timespec __user *, rmtp) | ||
851 | { | ||
852 | long err; | ||
853 | mm_segment_t oldfs; | ||
854 | struct timespec in, out; | ||
855 | struct restart_block *restart; | ||
856 | |||
857 | if (compat_get_timespec(&in, rqtp)) | ||
858 | return -EFAULT; | ||
859 | |||
860 | oldfs = get_fs(); | ||
861 | set_fs(KERNEL_DS); | ||
862 | err = sys_clock_nanosleep(which_clock, flags, | ||
863 | (struct timespec __user *) &in, | ||
864 | (struct timespec __user *) &out); | ||
865 | set_fs(oldfs); | ||
866 | |||
867 | if ((err == -ERESTART_RESTARTBLOCK) && rmtp && | ||
868 | compat_put_timespec(&out, rmtp)) | ||
869 | return -EFAULT; | ||
870 | |||
871 | if (err == -ERESTART_RESTARTBLOCK) { | ||
872 | restart = ¤t->restart_block; | ||
873 | restart->fn = compat_clock_nanosleep_restart; | ||
874 | restart->nanosleep.compat_rmtp = rmtp; | ||
875 | } | ||
876 | return err; | ||
877 | } | ||
878 | |||
879 | /* | 545 | /* |
880 | * We currently only need the following fields from the sigevent | 546 | * We currently only need the following fields from the sigevent |
881 | * structure: sigev_value, sigev_signo, sig_notify and (sometimes | 547 | * structure: sigev_value, sigev_signo, sig_notify and (sometimes |
@@ -1035,64 +701,6 @@ COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait, compat_sigset_t __user *, uthese, | |||
1035 | return ret; | 701 | return ret; |
1036 | } | 702 | } |
1037 | 703 | ||
1038 | #ifdef __ARCH_WANT_COMPAT_SYS_TIME | ||
1039 | |||
1040 | /* compat_time_t is a 32 bit "long" and needs to get converted. */ | ||
1041 | |||
1042 | COMPAT_SYSCALL_DEFINE1(time, compat_time_t __user *, tloc) | ||
1043 | { | ||
1044 | compat_time_t i; | ||
1045 | struct timeval tv; | ||
1046 | |||
1047 | do_gettimeofday(&tv); | ||
1048 | i = tv.tv_sec; | ||
1049 | |||
1050 | if (tloc) { | ||
1051 | if (put_user(i,tloc)) | ||
1052 | return -EFAULT; | ||
1053 | } | ||
1054 | force_successful_syscall_return(); | ||
1055 | return i; | ||
1056 | } | ||
1057 | |||
1058 | COMPAT_SYSCALL_DEFINE1(stime, compat_time_t __user *, tptr) | ||
1059 | { | ||
1060 | struct timespec tv; | ||
1061 | int err; | ||
1062 | |||
1063 | if (get_user(tv.tv_sec, tptr)) | ||
1064 | return -EFAULT; | ||
1065 | |||
1066 | tv.tv_nsec = 0; | ||
1067 | |||
1068 | err = security_settime(&tv, NULL); | ||
1069 | if (err) | ||
1070 | return err; | ||
1071 | |||
1072 | do_settimeofday(&tv); | ||
1073 | return 0; | ||
1074 | } | ||
1075 | |||
1076 | #endif /* __ARCH_WANT_COMPAT_SYS_TIME */ | ||
1077 | |||
1078 | COMPAT_SYSCALL_DEFINE1(adjtimex, struct compat_timex __user *, utp) | ||
1079 | { | ||
1080 | struct timex txc; | ||
1081 | int err, ret; | ||
1082 | |||
1083 | err = compat_get_timex(&txc, utp); | ||
1084 | if (err) | ||
1085 | return err; | ||
1086 | |||
1087 | ret = do_adjtimex(&txc); | ||
1088 | |||
1089 | err = compat_put_timex(utp, &txc); | ||
1090 | if (err) | ||
1091 | return err; | ||
1092 | |||
1093 | return ret; | ||
1094 | } | ||
1095 | |||
1096 | #ifdef CONFIG_NUMA | 704 | #ifdef CONFIG_NUMA |
1097 | COMPAT_SYSCALL_DEFINE6(move_pages, pid_t, pid, compat_ulong_t, nr_pages, | 705 | COMPAT_SYSCALL_DEFINE6(move_pages, pid_t, pid, compat_ulong_t, nr_pages, |
1098 | compat_uptr_t __user *, pages32, | 706 | compat_uptr_t __user *, pages32, |
diff --git a/kernel/signal.c b/kernel/signal.c index 9b28954e058f..35a570f71f07 100644 --- a/kernel/signal.c +++ b/kernel/signal.c | |||
@@ -39,6 +39,7 @@ | |||
39 | #include <linux/compat.h> | 39 | #include <linux/compat.h> |
40 | #include <linux/cn_proc.h> | 40 | #include <linux/cn_proc.h> |
41 | #include <linux/compiler.h> | 41 | #include <linux/compiler.h> |
42 | #include <linux/posix-timers.h> | ||
42 | 43 | ||
43 | #define CREATE_TRACE_POINTS | 44 | #define CREATE_TRACE_POINTS |
44 | #include <trace/events/signal.h> | 45 | #include <trace/events/signal.h> |
@@ -637,7 +638,7 @@ int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info) | |||
637 | * about to disable them again anyway. | 638 | * about to disable them again anyway. |
638 | */ | 639 | */ |
639 | spin_unlock(&tsk->sighand->siglock); | 640 | spin_unlock(&tsk->sighand->siglock); |
640 | do_schedule_next_timer(info); | 641 | posixtimer_rearm(info); |
641 | spin_lock(&tsk->sighand->siglock); | 642 | spin_lock(&tsk->sighand->siglock); |
642 | } | 643 | } |
643 | #endif | 644 | #endif |
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c index ee2f4202d82a..c991cf212c6d 100644 --- a/kernel/time/alarmtimer.c +++ b/kernel/time/alarmtimer.c | |||
@@ -27,6 +27,9 @@ | |||
27 | #include <linux/posix-timers.h> | 27 | #include <linux/posix-timers.h> |
28 | #include <linux/workqueue.h> | 28 | #include <linux/workqueue.h> |
29 | #include <linux/freezer.h> | 29 | #include <linux/freezer.h> |
30 | #include <linux/compat.h> | ||
31 | |||
32 | #include "posix-timers.h" | ||
30 | 33 | ||
31 | #define CREATE_TRACE_POINTS | 34 | #define CREATE_TRACE_POINTS |
32 | #include <trace/events/alarmtimer.h> | 35 | #include <trace/events/alarmtimer.h> |
@@ -45,11 +48,13 @@ static struct alarm_base { | |||
45 | clockid_t base_clockid; | 48 | clockid_t base_clockid; |
46 | } alarm_bases[ALARM_NUMTYPE]; | 49 | } alarm_bases[ALARM_NUMTYPE]; |
47 | 50 | ||
51 | #if defined(CONFIG_POSIX_TIMERS) || defined(CONFIG_RTC_CLASS) | ||
48 | /* freezer information to handle clock_nanosleep triggered wakeups */ | 52 | /* freezer information to handle clock_nanosleep triggered wakeups */ |
49 | static enum alarmtimer_type freezer_alarmtype; | 53 | static enum alarmtimer_type freezer_alarmtype; |
50 | static ktime_t freezer_expires; | 54 | static ktime_t freezer_expires; |
51 | static ktime_t freezer_delta; | 55 | static ktime_t freezer_delta; |
52 | static DEFINE_SPINLOCK(freezer_delta_lock); | 56 | static DEFINE_SPINLOCK(freezer_delta_lock); |
57 | #endif | ||
53 | 58 | ||
54 | static struct wakeup_source *ws; | 59 | static struct wakeup_source *ws; |
55 | 60 | ||
@@ -307,38 +312,6 @@ static int alarmtimer_resume(struct device *dev) | |||
307 | } | 312 | } |
308 | #endif | 313 | #endif |
309 | 314 | ||
310 | static void alarmtimer_freezerset(ktime_t absexp, enum alarmtimer_type type) | ||
311 | { | ||
312 | struct alarm_base *base; | ||
313 | unsigned long flags; | ||
314 | ktime_t delta; | ||
315 | |||
316 | switch(type) { | ||
317 | case ALARM_REALTIME: | ||
318 | base = &alarm_bases[ALARM_REALTIME]; | ||
319 | type = ALARM_REALTIME_FREEZER; | ||
320 | break; | ||
321 | case ALARM_BOOTTIME: | ||
322 | base = &alarm_bases[ALARM_BOOTTIME]; | ||
323 | type = ALARM_BOOTTIME_FREEZER; | ||
324 | break; | ||
325 | default: | ||
326 | WARN_ONCE(1, "Invalid alarm type: %d\n", type); | ||
327 | return; | ||
328 | } | ||
329 | |||
330 | delta = ktime_sub(absexp, base->gettime()); | ||
331 | |||
332 | spin_lock_irqsave(&freezer_delta_lock, flags); | ||
333 | if (!freezer_delta || (delta < freezer_delta)) { | ||
334 | freezer_delta = delta; | ||
335 | freezer_expires = absexp; | ||
336 | freezer_alarmtype = type; | ||
337 | } | ||
338 | spin_unlock_irqrestore(&freezer_delta_lock, flags); | ||
339 | } | ||
340 | |||
341 | |||
342 | /** | 315 | /** |
343 | * alarm_init - Initialize an alarm structure | 316 | * alarm_init - Initialize an alarm structure |
344 | * @alarm: ptr to alarm to be initialized | 317 | * @alarm: ptr to alarm to be initialized |
@@ -488,6 +461,38 @@ u64 alarm_forward_now(struct alarm *alarm, ktime_t interval) | |||
488 | } | 461 | } |
489 | EXPORT_SYMBOL_GPL(alarm_forward_now); | 462 | EXPORT_SYMBOL_GPL(alarm_forward_now); |
490 | 463 | ||
464 | #ifdef CONFIG_POSIX_TIMERS | ||
465 | |||
466 | static void alarmtimer_freezerset(ktime_t absexp, enum alarmtimer_type type) | ||
467 | { | ||
468 | struct alarm_base *base; | ||
469 | unsigned long flags; | ||
470 | ktime_t delta; | ||
471 | |||
472 | switch(type) { | ||
473 | case ALARM_REALTIME: | ||
474 | base = &alarm_bases[ALARM_REALTIME]; | ||
475 | type = ALARM_REALTIME_FREEZER; | ||
476 | break; | ||
477 | case ALARM_BOOTTIME: | ||
478 | base = &alarm_bases[ALARM_BOOTTIME]; | ||
479 | type = ALARM_BOOTTIME_FREEZER; | ||
480 | break; | ||
481 | default: | ||
482 | WARN_ONCE(1, "Invalid alarm type: %d\n", type); | ||
483 | return; | ||
484 | } | ||
485 | |||
486 | delta = ktime_sub(absexp, base->gettime()); | ||
487 | |||
488 | spin_lock_irqsave(&freezer_delta_lock, flags); | ||
489 | if (!freezer_delta || (delta < freezer_delta)) { | ||
490 | freezer_delta = delta; | ||
491 | freezer_expires = absexp; | ||
492 | freezer_alarmtype = type; | ||
493 | } | ||
494 | spin_unlock_irqrestore(&freezer_delta_lock, flags); | ||
495 | } | ||
491 | 496 | ||
492 | /** | 497 | /** |
493 | * clock2alarm - helper that converts from clockid to alarmtypes | 498 | * clock2alarm - helper that converts from clockid to alarmtypes |
@@ -511,22 +516,26 @@ static enum alarmtimer_type clock2alarm(clockid_t clockid) | |||
511 | static enum alarmtimer_restart alarm_handle_timer(struct alarm *alarm, | 516 | static enum alarmtimer_restart alarm_handle_timer(struct alarm *alarm, |
512 | ktime_t now) | 517 | ktime_t now) |
513 | { | 518 | { |
514 | unsigned long flags; | ||
515 | struct k_itimer *ptr = container_of(alarm, struct k_itimer, | 519 | struct k_itimer *ptr = container_of(alarm, struct k_itimer, |
516 | it.alarm.alarmtimer); | 520 | it.alarm.alarmtimer); |
517 | enum alarmtimer_restart result = ALARMTIMER_NORESTART; | 521 | enum alarmtimer_restart result = ALARMTIMER_NORESTART; |
522 | unsigned long flags; | ||
523 | int si_private = 0; | ||
518 | 524 | ||
519 | spin_lock_irqsave(&ptr->it_lock, flags); | 525 | spin_lock_irqsave(&ptr->it_lock, flags); |
520 | if ((ptr->it_sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_NONE) { | ||
521 | if (IS_ENABLED(CONFIG_POSIX_TIMERS) && | ||
522 | posix_timer_event(ptr, 0) != 0) | ||
523 | ptr->it_overrun++; | ||
524 | } | ||
525 | 526 | ||
526 | /* Re-add periodic timers */ | 527 | ptr->it_active = 0; |
527 | if (ptr->it.alarm.interval) { | 528 | if (ptr->it_interval) |
528 | ptr->it_overrun += alarm_forward(alarm, now, | 529 | si_private = ++ptr->it_requeue_pending; |
529 | ptr->it.alarm.interval); | 530 | |
531 | if (posix_timer_event(ptr, si_private) && ptr->it_interval) { | ||
532 | /* | ||
533 | * Handle ignored signals and rearm the timer. This will go | ||
534 | * away once we handle ignored signals proper. | ||
535 | */ | ||
536 | ptr->it_overrun += alarm_forward_now(alarm, ptr->it_interval); | ||
537 | ++ptr->it_requeue_pending; | ||
538 | ptr->it_active = 1; | ||
530 | result = ALARMTIMER_RESTART; | 539 | result = ALARMTIMER_RESTART; |
531 | } | 540 | } |
532 | spin_unlock_irqrestore(&ptr->it_lock, flags); | 541 | spin_unlock_irqrestore(&ptr->it_lock, flags); |
@@ -535,6 +544,72 @@ static enum alarmtimer_restart alarm_handle_timer(struct alarm *alarm, | |||
535 | } | 544 | } |
536 | 545 | ||
537 | /** | 546 | /** |
547 | * alarm_timer_rearm - Posix timer callback for rearming timer | ||
548 | * @timr: Pointer to the posixtimer data struct | ||
549 | */ | ||
550 | static void alarm_timer_rearm(struct k_itimer *timr) | ||
551 | { | ||
552 | struct alarm *alarm = &timr->it.alarm.alarmtimer; | ||
553 | |||
554 | timr->it_overrun += alarm_forward_now(alarm, timr->it_interval); | ||
555 | alarm_start(alarm, alarm->node.expires); | ||
556 | } | ||
557 | |||
558 | /** | ||
559 | * alarm_timer_forward - Posix timer callback for forwarding timer | ||
560 | * @timr: Pointer to the posixtimer data struct | ||
561 | * @now: Current time to forward the timer against | ||
562 | */ | ||
563 | static int alarm_timer_forward(struct k_itimer *timr, ktime_t now) | ||
564 | { | ||
565 | struct alarm *alarm = &timr->it.alarm.alarmtimer; | ||
566 | |||
567 | return (int) alarm_forward(alarm, timr->it_interval, now); | ||
568 | } | ||
569 | |||
570 | /** | ||
571 | * alarm_timer_remaining - Posix timer callback to retrieve remaining time | ||
572 | * @timr: Pointer to the posixtimer data struct | ||
573 | * @now: Current time to calculate against | ||
574 | */ | ||
575 | static ktime_t alarm_timer_remaining(struct k_itimer *timr, ktime_t now) | ||
576 | { | ||
577 | struct alarm *alarm = &timr->it.alarm.alarmtimer; | ||
578 | |||
579 | return ktime_sub(now, alarm->node.expires); | ||
580 | } | ||
581 | |||
582 | /** | ||
583 | * alarm_timer_try_to_cancel - Posix timer callback to cancel a timer | ||
584 | * @timr: Pointer to the posixtimer data struct | ||
585 | */ | ||
586 | static int alarm_timer_try_to_cancel(struct k_itimer *timr) | ||
587 | { | ||
588 | return alarm_try_to_cancel(&timr->it.alarm.alarmtimer); | ||
589 | } | ||
590 | |||
591 | /** | ||
592 | * alarm_timer_arm - Posix timer callback to arm a timer | ||
593 | * @timr: Pointer to the posixtimer data struct | ||
594 | * @expires: The new expiry time | ||
595 | * @absolute: Expiry value is absolute time | ||
596 | * @sigev_none: Posix timer does not deliver signals | ||
597 | */ | ||
598 | static void alarm_timer_arm(struct k_itimer *timr, ktime_t expires, | ||
599 | bool absolute, bool sigev_none) | ||
600 | { | ||
601 | struct alarm *alarm = &timr->it.alarm.alarmtimer; | ||
602 | struct alarm_base *base = &alarm_bases[alarm->type]; | ||
603 | |||
604 | if (!absolute) | ||
605 | expires = ktime_add_safe(expires, base->gettime()); | ||
606 | if (sigev_none) | ||
607 | alarm->node.expires = expires; | ||
608 | else | ||
609 | alarm_start(&timr->it.alarm.alarmtimer, expires); | ||
610 | } | ||
611 | |||
612 | /** | ||
538 | * alarm_clock_getres - posix getres interface | 613 | * alarm_clock_getres - posix getres interface |
539 | * @which_clock: clockid | 614 | * @which_clock: clockid |
540 | * @tp: timespec to fill | 615 | * @tp: timespec to fill |
@@ -591,97 +666,6 @@ static int alarm_timer_create(struct k_itimer *new_timer) | |||
591 | } | 666 | } |
592 | 667 | ||
593 | /** | 668 | /** |
594 | * alarm_timer_get - posix timer_get interface | ||
595 | * @new_timer: k_itimer pointer | ||
596 | * @cur_setting: itimerspec data to fill | ||
597 | * | ||
598 | * Copies out the current itimerspec data | ||
599 | */ | ||
600 | static void alarm_timer_get(struct k_itimer *timr, | ||
601 | struct itimerspec64 *cur_setting) | ||
602 | { | ||
603 | ktime_t relative_expiry_time = | ||
604 | alarm_expires_remaining(&(timr->it.alarm.alarmtimer)); | ||
605 | |||
606 | if (ktime_to_ns(relative_expiry_time) > 0) { | ||
607 | cur_setting->it_value = ktime_to_timespec64(relative_expiry_time); | ||
608 | } else { | ||
609 | cur_setting->it_value.tv_sec = 0; | ||
610 | cur_setting->it_value.tv_nsec = 0; | ||
611 | } | ||
612 | |||
613 | cur_setting->it_interval = ktime_to_timespec64(timr->it.alarm.interval); | ||
614 | } | ||
615 | |||
616 | /** | ||
617 | * alarm_timer_del - posix timer_del interface | ||
618 | * @timr: k_itimer pointer to be deleted | ||
619 | * | ||
620 | * Cancels any programmed alarms for the given timer. | ||
621 | */ | ||
622 | static int alarm_timer_del(struct k_itimer *timr) | ||
623 | { | ||
624 | if (!rtcdev) | ||
625 | return -ENOTSUPP; | ||
626 | |||
627 | if (alarm_try_to_cancel(&timr->it.alarm.alarmtimer) < 0) | ||
628 | return TIMER_RETRY; | ||
629 | |||
630 | return 0; | ||
631 | } | ||
632 | |||
633 | /** | ||
634 | * alarm_timer_set - posix timer_set interface | ||
635 | * @timr: k_itimer pointer to be deleted | ||
636 | * @flags: timer flags | ||
637 | * @new_setting: itimerspec to be used | ||
638 | * @old_setting: itimerspec being replaced | ||
639 | * | ||
640 | * Sets the timer to new_setting, and starts the timer. | ||
641 | */ | ||
642 | static int alarm_timer_set(struct k_itimer *timr, int flags, | ||
643 | struct itimerspec64 *new_setting, | ||
644 | struct itimerspec64 *old_setting) | ||
645 | { | ||
646 | ktime_t exp; | ||
647 | |||
648 | if (!rtcdev) | ||
649 | return -ENOTSUPP; | ||
650 | |||
651 | if (flags & ~TIMER_ABSTIME) | ||
652 | return -EINVAL; | ||
653 | |||
654 | if (old_setting) | ||
655 | alarm_timer_get(timr, old_setting); | ||
656 | |||
657 | /* If the timer was already set, cancel it */ | ||
658 | if (alarm_try_to_cancel(&timr->it.alarm.alarmtimer) < 0) | ||
659 | return TIMER_RETRY; | ||
660 | |||
661 | /* start the timer */ | ||
662 | timr->it.alarm.interval = timespec64_to_ktime(new_setting->it_interval); | ||
663 | |||
664 | /* | ||
665 | * Rate limit to the tick as a hot fix to prevent DOS. Will be | ||
666 | * mopped up later. | ||
667 | */ | ||
668 | if (timr->it.alarm.interval < TICK_NSEC) | ||
669 | timr->it.alarm.interval = TICK_NSEC; | ||
670 | |||
671 | exp = timespec64_to_ktime(new_setting->it_value); | ||
672 | /* Convert (if necessary) to absolute time */ | ||
673 | if (flags != TIMER_ABSTIME) { | ||
674 | ktime_t now; | ||
675 | |||
676 | now = alarm_bases[timr->it.alarm.alarmtimer.type].gettime(); | ||
677 | exp = ktime_add_safe(now, exp); | ||
678 | } | ||
679 | |||
680 | alarm_start(&timr->it.alarm.alarmtimer, exp); | ||
681 | return 0; | ||
682 | } | ||
683 | |||
684 | /** | ||
685 | * alarmtimer_nsleep_wakeup - Wakeup function for alarm_timer_nsleep | 669 | * alarmtimer_nsleep_wakeup - Wakeup function for alarm_timer_nsleep |
686 | * @alarm: ptr to alarm that fired | 670 | * @alarm: ptr to alarm that fired |
687 | * | 671 | * |
@@ -705,8 +689,10 @@ static enum alarmtimer_restart alarmtimer_nsleep_wakeup(struct alarm *alarm, | |||
705 | * | 689 | * |
706 | * Sets the alarm timer and sleeps until it is fired or interrupted. | 690 | * Sets the alarm timer and sleeps until it is fired or interrupted. |
707 | */ | 691 | */ |
708 | static int alarmtimer_do_nsleep(struct alarm *alarm, ktime_t absexp) | 692 | static int alarmtimer_do_nsleep(struct alarm *alarm, ktime_t absexp, |
693 | enum alarmtimer_type type) | ||
709 | { | 694 | { |
695 | struct restart_block *restart; | ||
710 | alarm->data = (void *)current; | 696 | alarm->data = (void *)current; |
711 | do { | 697 | do { |
712 | set_current_state(TASK_INTERRUPTIBLE); | 698 | set_current_state(TASK_INTERRUPTIBLE); |
@@ -719,36 +705,25 @@ static int alarmtimer_do_nsleep(struct alarm *alarm, ktime_t absexp) | |||
719 | 705 | ||
720 | __set_current_state(TASK_RUNNING); | 706 | __set_current_state(TASK_RUNNING); |
721 | 707 | ||
722 | return (alarm->data == NULL); | 708 | if (!alarm->data) |
723 | } | ||
724 | |||
725 | |||
726 | /** | ||
727 | * update_rmtp - Update remaining timespec value | ||
728 | * @exp: expiration time | ||
729 | * @type: timer type | ||
730 | * @rmtp: user pointer to remaining timepsec value | ||
731 | * | ||
732 | * Helper function that fills in rmtp value with time between | ||
733 | * now and the exp value | ||
734 | */ | ||
735 | static int update_rmtp(ktime_t exp, enum alarmtimer_type type, | ||
736 | struct timespec __user *rmtp) | ||
737 | { | ||
738 | struct timespec rmt; | ||
739 | ktime_t rem; | ||
740 | |||
741 | rem = ktime_sub(exp, alarm_bases[type].gettime()); | ||
742 | |||
743 | if (rem <= 0) | ||
744 | return 0; | 709 | return 0; |
745 | rmt = ktime_to_timespec(rem); | ||
746 | 710 | ||
747 | if (copy_to_user(rmtp, &rmt, sizeof(*rmtp))) | 711 | if (freezing(current)) |
748 | return -EFAULT; | 712 | alarmtimer_freezerset(absexp, type); |
713 | restart = ¤t->restart_block; | ||
714 | if (restart->nanosleep.type != TT_NONE) { | ||
715 | struct timespec rmt; | ||
716 | ktime_t rem; | ||
717 | |||
718 | rem = ktime_sub(absexp, alarm_bases[type].gettime()); | ||
749 | 719 | ||
750 | return 1; | 720 | if (rem <= 0) |
721 | return 0; | ||
722 | rmt = ktime_to_timespec(rem); | ||
751 | 723 | ||
724 | return nanosleep_copyout(restart, &rmt); | ||
725 | } | ||
726 | return -ERESTART_RESTARTBLOCK; | ||
752 | } | 727 | } |
753 | 728 | ||
754 | /** | 729 | /** |
@@ -760,32 +735,12 @@ static int update_rmtp(ktime_t exp, enum alarmtimer_type type, | |||
760 | static long __sched alarm_timer_nsleep_restart(struct restart_block *restart) | 735 | static long __sched alarm_timer_nsleep_restart(struct restart_block *restart) |
761 | { | 736 | { |
762 | enum alarmtimer_type type = restart->nanosleep.clockid; | 737 | enum alarmtimer_type type = restart->nanosleep.clockid; |
763 | ktime_t exp; | 738 | ktime_t exp = restart->nanosleep.expires; |
764 | struct timespec __user *rmtp; | ||
765 | struct alarm alarm; | 739 | struct alarm alarm; |
766 | int ret = 0; | ||
767 | 740 | ||
768 | exp = restart->nanosleep.expires; | ||
769 | alarm_init(&alarm, type, alarmtimer_nsleep_wakeup); | 741 | alarm_init(&alarm, type, alarmtimer_nsleep_wakeup); |
770 | 742 | ||
771 | if (alarmtimer_do_nsleep(&alarm, exp)) | 743 | return alarmtimer_do_nsleep(&alarm, exp, type); |
772 | goto out; | ||
773 | |||
774 | if (freezing(current)) | ||
775 | alarmtimer_freezerset(exp, type); | ||
776 | |||
777 | rmtp = restart->nanosleep.rmtp; | ||
778 | if (rmtp) { | ||
779 | ret = update_rmtp(exp, type, rmtp); | ||
780 | if (ret <= 0) | ||
781 | goto out; | ||
782 | } | ||
783 | |||
784 | |||
785 | /* The other values in restart are already filled in */ | ||
786 | ret = -ERESTART_RESTARTBLOCK; | ||
787 | out: | ||
788 | return ret; | ||
789 | } | 744 | } |
790 | 745 | ||
791 | /** | 746 | /** |
@@ -798,11 +753,10 @@ out: | |||
798 | * Handles clock_nanosleep calls against _ALARM clockids | 753 | * Handles clock_nanosleep calls against _ALARM clockids |
799 | */ | 754 | */ |
800 | static int alarm_timer_nsleep(const clockid_t which_clock, int flags, | 755 | static int alarm_timer_nsleep(const clockid_t which_clock, int flags, |
801 | struct timespec64 *tsreq, | 756 | const struct timespec64 *tsreq) |
802 | struct timespec __user *rmtp) | ||
803 | { | 757 | { |
804 | enum alarmtimer_type type = clock2alarm(which_clock); | 758 | enum alarmtimer_type type = clock2alarm(which_clock); |
805 | struct restart_block *restart; | 759 | struct restart_block *restart = ¤t->restart_block; |
806 | struct alarm alarm; | 760 | struct alarm alarm; |
807 | ktime_t exp; | 761 | ktime_t exp; |
808 | int ret = 0; | 762 | int ret = 0; |
@@ -825,35 +779,36 @@ static int alarm_timer_nsleep(const clockid_t which_clock, int flags, | |||
825 | exp = ktime_add(now, exp); | 779 | exp = ktime_add(now, exp); |
826 | } | 780 | } |
827 | 781 | ||
828 | if (alarmtimer_do_nsleep(&alarm, exp)) | 782 | ret = alarmtimer_do_nsleep(&alarm, exp, type); |
829 | goto out; | 783 | if (ret != -ERESTART_RESTARTBLOCK) |
830 | 784 | return ret; | |
831 | if (freezing(current)) | ||
832 | alarmtimer_freezerset(exp, type); | ||
833 | 785 | ||
834 | /* abs timers don't set remaining time or restart */ | 786 | /* abs timers don't set remaining time or restart */ |
835 | if (flags == TIMER_ABSTIME) { | 787 | if (flags == TIMER_ABSTIME) |
836 | ret = -ERESTARTNOHAND; | 788 | return -ERESTARTNOHAND; |
837 | goto out; | ||
838 | } | ||
839 | 789 | ||
840 | if (rmtp) { | ||
841 | ret = update_rmtp(exp, type, rmtp); | ||
842 | if (ret <= 0) | ||
843 | goto out; | ||
844 | } | ||
845 | |||
846 | restart = ¤t->restart_block; | ||
847 | restart->fn = alarm_timer_nsleep_restart; | 790 | restart->fn = alarm_timer_nsleep_restart; |
848 | restart->nanosleep.clockid = type; | 791 | restart->nanosleep.clockid = type; |
849 | restart->nanosleep.expires = exp; | 792 | restart->nanosleep.expires = exp; |
850 | restart->nanosleep.rmtp = rmtp; | ||
851 | ret = -ERESTART_RESTARTBLOCK; | ||
852 | |||
853 | out: | ||
854 | return ret; | 793 | return ret; |
855 | } | 794 | } |
856 | 795 | ||
796 | const struct k_clock alarm_clock = { | ||
797 | .clock_getres = alarm_clock_getres, | ||
798 | .clock_get = alarm_clock_get, | ||
799 | .timer_create = alarm_timer_create, | ||
800 | .timer_set = common_timer_set, | ||
801 | .timer_del = common_timer_del, | ||
802 | .timer_get = common_timer_get, | ||
803 | .timer_arm = alarm_timer_arm, | ||
804 | .timer_rearm = alarm_timer_rearm, | ||
805 | .timer_forward = alarm_timer_forward, | ||
806 | .timer_remaining = alarm_timer_remaining, | ||
807 | .timer_try_to_cancel = alarm_timer_try_to_cancel, | ||
808 | .nsleep = alarm_timer_nsleep, | ||
809 | }; | ||
810 | #endif /* CONFIG_POSIX_TIMERS */ | ||
811 | |||
857 | 812 | ||
858 | /* Suspend hook structures */ | 813 | /* Suspend hook structures */ |
859 | static const struct dev_pm_ops alarmtimer_pm_ops = { | 814 | static const struct dev_pm_ops alarmtimer_pm_ops = { |
@@ -879,23 +834,9 @@ static int __init alarmtimer_init(void) | |||
879 | struct platform_device *pdev; | 834 | struct platform_device *pdev; |
880 | int error = 0; | 835 | int error = 0; |
881 | int i; | 836 | int i; |
882 | struct k_clock alarm_clock = { | ||
883 | .clock_getres = alarm_clock_getres, | ||
884 | .clock_get = alarm_clock_get, | ||
885 | .timer_create = alarm_timer_create, | ||
886 | .timer_set = alarm_timer_set, | ||
887 | .timer_del = alarm_timer_del, | ||
888 | .timer_get = alarm_timer_get, | ||
889 | .nsleep = alarm_timer_nsleep, | ||
890 | }; | ||
891 | 837 | ||
892 | alarmtimer_rtc_timer_init(); | 838 | alarmtimer_rtc_timer_init(); |
893 | 839 | ||
894 | if (IS_ENABLED(CONFIG_POSIX_TIMERS)) { | ||
895 | posix_timers_register_clock(CLOCK_REALTIME_ALARM, &alarm_clock); | ||
896 | posix_timers_register_clock(CLOCK_BOOTTIME_ALARM, &alarm_clock); | ||
897 | } | ||
898 | |||
899 | /* Initialize alarm bases */ | 840 | /* Initialize alarm bases */ |
900 | alarm_bases[ALARM_REALTIME].base_clockid = CLOCK_REALTIME; | 841 | alarm_bases[ALARM_REALTIME].base_clockid = CLOCK_REALTIME; |
901 | alarm_bases[ALARM_REALTIME].gettime = &ktime_get_real; | 842 | alarm_bases[ALARM_REALTIME].gettime = &ktime_get_real; |
diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c index ac053bb5296e..81da124f1115 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c | |||
@@ -51,6 +51,7 @@ | |||
51 | #include <linux/sched/debug.h> | 51 | #include <linux/sched/debug.h> |
52 | #include <linux/timer.h> | 52 | #include <linux/timer.h> |
53 | #include <linux/freezer.h> | 53 | #include <linux/freezer.h> |
54 | #include <linux/compat.h> | ||
54 | 55 | ||
55 | #include <linux/uaccess.h> | 56 | #include <linux/uaccess.h> |
56 | 57 | ||
@@ -1439,8 +1440,29 @@ void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, struct task_struct *task) | |||
1439 | } | 1440 | } |
1440 | EXPORT_SYMBOL_GPL(hrtimer_init_sleeper); | 1441 | EXPORT_SYMBOL_GPL(hrtimer_init_sleeper); |
1441 | 1442 | ||
1443 | int nanosleep_copyout(struct restart_block *restart, struct timespec *ts) | ||
1444 | { | ||
1445 | switch(restart->nanosleep.type) { | ||
1446 | #ifdef CONFIG_COMPAT | ||
1447 | case TT_COMPAT: | ||
1448 | if (compat_put_timespec(ts, restart->nanosleep.compat_rmtp)) | ||
1449 | return -EFAULT; | ||
1450 | break; | ||
1451 | #endif | ||
1452 | case TT_NATIVE: | ||
1453 | if (copy_to_user(restart->nanosleep.rmtp, ts, sizeof(struct timespec))) | ||
1454 | return -EFAULT; | ||
1455 | break; | ||
1456 | default: | ||
1457 | BUG(); | ||
1458 | } | ||
1459 | return -ERESTART_RESTARTBLOCK; | ||
1460 | } | ||
1461 | |||
1442 | static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mode) | 1462 | static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mode) |
1443 | { | 1463 | { |
1464 | struct restart_block *restart; | ||
1465 | |||
1444 | hrtimer_init_sleeper(t, current); | 1466 | hrtimer_init_sleeper(t, current); |
1445 | 1467 | ||
1446 | do { | 1468 | do { |
@@ -1457,53 +1479,38 @@ static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mod | |||
1457 | 1479 | ||
1458 | __set_current_state(TASK_RUNNING); | 1480 | __set_current_state(TASK_RUNNING); |
1459 | 1481 | ||
1460 | return t->task == NULL; | 1482 | if (!t->task) |
1461 | } | ||
1462 | |||
1463 | static int update_rmtp(struct hrtimer *timer, struct timespec __user *rmtp) | ||
1464 | { | ||
1465 | struct timespec rmt; | ||
1466 | ktime_t rem; | ||
1467 | |||
1468 | rem = hrtimer_expires_remaining(timer); | ||
1469 | if (rem <= 0) | ||
1470 | return 0; | 1483 | return 0; |
1471 | rmt = ktime_to_timespec(rem); | ||
1472 | 1484 | ||
1473 | if (copy_to_user(rmtp, &rmt, sizeof(*rmtp))) | 1485 | restart = ¤t->restart_block; |
1474 | return -EFAULT; | 1486 | if (restart->nanosleep.type != TT_NONE) { |
1487 | ktime_t rem = hrtimer_expires_remaining(&t->timer); | ||
1488 | struct timespec rmt; | ||
1475 | 1489 | ||
1476 | return 1; | 1490 | if (rem <= 0) |
1491 | return 0; | ||
1492 | rmt = ktime_to_timespec(rem); | ||
1493 | |||
1494 | return nanosleep_copyout(restart, &rmt); | ||
1495 | } | ||
1496 | return -ERESTART_RESTARTBLOCK; | ||
1477 | } | 1497 | } |
1478 | 1498 | ||
1479 | long __sched hrtimer_nanosleep_restart(struct restart_block *restart) | 1499 | static long __sched hrtimer_nanosleep_restart(struct restart_block *restart) |
1480 | { | 1500 | { |
1481 | struct hrtimer_sleeper t; | 1501 | struct hrtimer_sleeper t; |
1482 | struct timespec __user *rmtp; | 1502 | int ret; |
1483 | int ret = 0; | ||
1484 | 1503 | ||
1485 | hrtimer_init_on_stack(&t.timer, restart->nanosleep.clockid, | 1504 | hrtimer_init_on_stack(&t.timer, restart->nanosleep.clockid, |
1486 | HRTIMER_MODE_ABS); | 1505 | HRTIMER_MODE_ABS); |
1487 | hrtimer_set_expires_tv64(&t.timer, restart->nanosleep.expires); | 1506 | hrtimer_set_expires_tv64(&t.timer, restart->nanosleep.expires); |
1488 | 1507 | ||
1489 | if (do_nanosleep(&t, HRTIMER_MODE_ABS)) | 1508 | ret = do_nanosleep(&t, HRTIMER_MODE_ABS); |
1490 | goto out; | ||
1491 | |||
1492 | rmtp = restart->nanosleep.rmtp; | ||
1493 | if (rmtp) { | ||
1494 | ret = update_rmtp(&t.timer, rmtp); | ||
1495 | if (ret <= 0) | ||
1496 | goto out; | ||
1497 | } | ||
1498 | |||
1499 | /* The other values in restart are already filled in */ | ||
1500 | ret = -ERESTART_RESTARTBLOCK; | ||
1501 | out: | ||
1502 | destroy_hrtimer_on_stack(&t.timer); | 1509 | destroy_hrtimer_on_stack(&t.timer); |
1503 | return ret; | 1510 | return ret; |
1504 | } | 1511 | } |
1505 | 1512 | ||
1506 | long hrtimer_nanosleep(struct timespec64 *rqtp, struct timespec __user *rmtp, | 1513 | long hrtimer_nanosleep(const struct timespec64 *rqtp, |
1507 | const enum hrtimer_mode mode, const clockid_t clockid) | 1514 | const enum hrtimer_mode mode, const clockid_t clockid) |
1508 | { | 1515 | { |
1509 | struct restart_block *restart; | 1516 | struct restart_block *restart; |
@@ -1517,7 +1524,8 @@ long hrtimer_nanosleep(struct timespec64 *rqtp, struct timespec __user *rmtp, | |||
1517 | 1524 | ||
1518 | hrtimer_init_on_stack(&t.timer, clockid, mode); | 1525 | hrtimer_init_on_stack(&t.timer, clockid, mode); |
1519 | hrtimer_set_expires_range_ns(&t.timer, timespec64_to_ktime(*rqtp), slack); | 1526 | hrtimer_set_expires_range_ns(&t.timer, timespec64_to_ktime(*rqtp), slack); |
1520 | if (do_nanosleep(&t, mode)) | 1527 | ret = do_nanosleep(&t, mode); |
1528 | if (ret != -ERESTART_RESTARTBLOCK) | ||
1521 | goto out; | 1529 | goto out; |
1522 | 1530 | ||
1523 | /* Absolute timers do not update the rmtp value and restart: */ | 1531 | /* Absolute timers do not update the rmtp value and restart: */ |
@@ -1526,19 +1534,10 @@ long hrtimer_nanosleep(struct timespec64 *rqtp, struct timespec __user *rmtp, | |||
1526 | goto out; | 1534 | goto out; |
1527 | } | 1535 | } |
1528 | 1536 | ||
1529 | if (rmtp) { | ||
1530 | ret = update_rmtp(&t.timer, rmtp); | ||
1531 | if (ret <= 0) | ||
1532 | goto out; | ||
1533 | } | ||
1534 | |||
1535 | restart = ¤t->restart_block; | 1537 | restart = ¤t->restart_block; |
1536 | restart->fn = hrtimer_nanosleep_restart; | 1538 | restart->fn = hrtimer_nanosleep_restart; |
1537 | restart->nanosleep.clockid = t.timer.base->clockid; | 1539 | restart->nanosleep.clockid = t.timer.base->clockid; |
1538 | restart->nanosleep.rmtp = rmtp; | ||
1539 | restart->nanosleep.expires = hrtimer_get_expires_tv64(&t.timer); | 1540 | restart->nanosleep.expires = hrtimer_get_expires_tv64(&t.timer); |
1540 | |||
1541 | ret = -ERESTART_RESTARTBLOCK; | ||
1542 | out: | 1541 | out: |
1543 | destroy_hrtimer_on_stack(&t.timer); | 1542 | destroy_hrtimer_on_stack(&t.timer); |
1544 | return ret; | 1543 | return ret; |
@@ -1557,8 +1556,31 @@ SYSCALL_DEFINE2(nanosleep, struct timespec __user *, rqtp, | |||
1557 | if (!timespec64_valid(&tu64)) | 1556 | if (!timespec64_valid(&tu64)) |
1558 | return -EINVAL; | 1557 | return -EINVAL; |
1559 | 1558 | ||
1560 | return hrtimer_nanosleep(&tu64, rmtp, HRTIMER_MODE_REL, CLOCK_MONOTONIC); | 1559 | current->restart_block.nanosleep.type = rmtp ? TT_NATIVE : TT_NONE; |
1560 | current->restart_block.nanosleep.rmtp = rmtp; | ||
1561 | return hrtimer_nanosleep(&tu64, HRTIMER_MODE_REL, CLOCK_MONOTONIC); | ||
1562 | } | ||
1563 | |||
1564 | #ifdef CONFIG_COMPAT | ||
1565 | |||
1566 | COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp, | ||
1567 | struct compat_timespec __user *, rmtp) | ||
1568 | { | ||
1569 | struct timespec64 tu64; | ||
1570 | struct timespec tu; | ||
1571 | |||
1572 | if (compat_get_timespec(&tu, rqtp)) | ||
1573 | return -EFAULT; | ||
1574 | |||
1575 | tu64 = timespec_to_timespec64(tu); | ||
1576 | if (!timespec64_valid(&tu64)) | ||
1577 | return -EINVAL; | ||
1578 | |||
1579 | current->restart_block.nanosleep.type = rmtp ? TT_COMPAT : TT_NONE; | ||
1580 | current->restart_block.nanosleep.compat_rmtp = rmtp; | ||
1581 | return hrtimer_nanosleep(&tu64, HRTIMER_MODE_REL, CLOCK_MONOTONIC); | ||
1561 | } | 1582 | } |
1583 | #endif | ||
1562 | 1584 | ||
1563 | /* | 1585 | /* |
1564 | * Functions related to boot-time initialization: | 1586 | * Functions related to boot-time initialization: |
diff --git a/kernel/time/itimer.c b/kernel/time/itimer.c index 087d6a1279b8..2ef98a02376a 100644 --- a/kernel/time/itimer.c +++ b/kernel/time/itimer.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/posix-timers.h> | 15 | #include <linux/posix-timers.h> |
16 | #include <linux/hrtimer.h> | 16 | #include <linux/hrtimer.h> |
17 | #include <trace/events/timer.h> | 17 | #include <trace/events/timer.h> |
18 | #include <linux/compat.h> | ||
18 | 19 | ||
19 | #include <linux/uaccess.h> | 20 | #include <linux/uaccess.h> |
20 | 21 | ||
@@ -116,6 +117,19 @@ SYSCALL_DEFINE2(getitimer, int, which, struct itimerval __user *, value) | |||
116 | return error; | 117 | return error; |
117 | } | 118 | } |
118 | 119 | ||
120 | #ifdef CONFIG_COMPAT | ||
121 | COMPAT_SYSCALL_DEFINE2(getitimer, int, which, | ||
122 | struct compat_itimerval __user *, it) | ||
123 | { | ||
124 | struct itimerval kit; | ||
125 | int error = do_getitimer(which, &kit); | ||
126 | |||
127 | if (!error && put_compat_itimerval(it, &kit)) | ||
128 | error = -EFAULT; | ||
129 | return error; | ||
130 | } | ||
131 | #endif | ||
132 | |||
119 | 133 | ||
120 | /* | 134 | /* |
121 | * The timer is automagically restarted, when interval != 0 | 135 | * The timer is automagically restarted, when interval != 0 |
@@ -138,8 +152,12 @@ static void set_cpu_itimer(struct task_struct *tsk, unsigned int clock_id, | |||
138 | u64 oval, nval, ointerval, ninterval; | 152 | u64 oval, nval, ointerval, ninterval; |
139 | struct cpu_itimer *it = &tsk->signal->it[clock_id]; | 153 | struct cpu_itimer *it = &tsk->signal->it[clock_id]; |
140 | 154 | ||
141 | nval = timeval_to_ns(&value->it_value); | 155 | /* |
142 | ninterval = timeval_to_ns(&value->it_interval); | 156 | * Use the to_ktime conversion because that clamps the maximum |
157 | * value to KTIME_MAX and avoid multiplication overflows. | ||
158 | */ | ||
159 | nval = ktime_to_ns(timeval_to_ktime(value->it_value)); | ||
160 | ninterval = ktime_to_ns(timeval_to_ktime(value->it_interval)); | ||
143 | 161 | ||
144 | spin_lock_irq(&tsk->sighand->siglock); | 162 | spin_lock_irq(&tsk->sighand->siglock); |
145 | 163 | ||
@@ -294,3 +312,27 @@ SYSCALL_DEFINE3(setitimer, int, which, struct itimerval __user *, value, | |||
294 | return -EFAULT; | 312 | return -EFAULT; |
295 | return 0; | 313 | return 0; |
296 | } | 314 | } |
315 | |||
316 | #ifdef CONFIG_COMPAT | ||
317 | COMPAT_SYSCALL_DEFINE3(setitimer, int, which, | ||
318 | struct compat_itimerval __user *, in, | ||
319 | struct compat_itimerval __user *, out) | ||
320 | { | ||
321 | struct itimerval kin, kout; | ||
322 | int error; | ||
323 | |||
324 | if (in) { | ||
325 | if (get_compat_itimerval(&kin, in)) | ||
326 | return -EFAULT; | ||
327 | } else { | ||
328 | memset(&kin, 0, sizeof(kin)); | ||
329 | } | ||
330 | |||
331 | error = do_setitimer(which, &kin, out ? &kout : NULL); | ||
332 | if (error || !out) | ||
333 | return error; | ||
334 | if (put_compat_itimerval(out, &kout)) | ||
335 | return -EFAULT; | ||
336 | return 0; | ||
337 | } | ||
338 | #endif | ||
diff --git a/kernel/time/posix-clock.c b/kernel/time/posix-clock.c index 31d588d37a17..17cdc554c9fe 100644 --- a/kernel/time/posix-clock.c +++ b/kernel/time/posix-clock.c | |||
@@ -25,6 +25,8 @@ | |||
25 | #include <linux/syscalls.h> | 25 | #include <linux/syscalls.h> |
26 | #include <linux/uaccess.h> | 26 | #include <linux/uaccess.h> |
27 | 27 | ||
28 | #include "posix-timers.h" | ||
29 | |||
28 | static void delete_clock(struct kref *kref); | 30 | static void delete_clock(struct kref *kref); |
29 | 31 | ||
30 | /* | 32 | /* |
@@ -82,38 +84,6 @@ static unsigned int posix_clock_poll(struct file *fp, poll_table *wait) | |||
82 | return result; | 84 | return result; |
83 | } | 85 | } |
84 | 86 | ||
85 | static int posix_clock_fasync(int fd, struct file *fp, int on) | ||
86 | { | ||
87 | struct posix_clock *clk = get_posix_clock(fp); | ||
88 | int err = 0; | ||
89 | |||
90 | if (!clk) | ||
91 | return -ENODEV; | ||
92 | |||
93 | if (clk->ops.fasync) | ||
94 | err = clk->ops.fasync(clk, fd, fp, on); | ||
95 | |||
96 | put_posix_clock(clk); | ||
97 | |||
98 | return err; | ||
99 | } | ||
100 | |||
101 | static int posix_clock_mmap(struct file *fp, struct vm_area_struct *vma) | ||
102 | { | ||
103 | struct posix_clock *clk = get_posix_clock(fp); | ||
104 | int err = -ENODEV; | ||
105 | |||
106 | if (!clk) | ||
107 | return -ENODEV; | ||
108 | |||
109 | if (clk->ops.mmap) | ||
110 | err = clk->ops.mmap(clk, vma); | ||
111 | |||
112 | put_posix_clock(clk); | ||
113 | |||
114 | return err; | ||
115 | } | ||
116 | |||
117 | static long posix_clock_ioctl(struct file *fp, | 87 | static long posix_clock_ioctl(struct file *fp, |
118 | unsigned int cmd, unsigned long arg) | 88 | unsigned int cmd, unsigned long arg) |
119 | { | 89 | { |
@@ -199,8 +169,6 @@ static const struct file_operations posix_clock_file_operations = { | |||
199 | .unlocked_ioctl = posix_clock_ioctl, | 169 | .unlocked_ioctl = posix_clock_ioctl, |
200 | .open = posix_clock_open, | 170 | .open = posix_clock_open, |
201 | .release = posix_clock_release, | 171 | .release = posix_clock_release, |
202 | .fasync = posix_clock_fasync, | ||
203 | .mmap = posix_clock_mmap, | ||
204 | #ifdef CONFIG_COMPAT | 172 | #ifdef CONFIG_COMPAT |
205 | .compat_ioctl = posix_clock_compat_ioctl, | 173 | .compat_ioctl = posix_clock_compat_ioctl, |
206 | #endif | 174 | #endif |
@@ -359,88 +327,9 @@ out: | |||
359 | return err; | 327 | return err; |
360 | } | 328 | } |
361 | 329 | ||
362 | static int pc_timer_create(struct k_itimer *kit) | 330 | const struct k_clock clock_posix_dynamic = { |
363 | { | ||
364 | clockid_t id = kit->it_clock; | ||
365 | struct posix_clock_desc cd; | ||
366 | int err; | ||
367 | |||
368 | err = get_clock_desc(id, &cd); | ||
369 | if (err) | ||
370 | return err; | ||
371 | |||
372 | if (cd.clk->ops.timer_create) | ||
373 | err = cd.clk->ops.timer_create(cd.clk, kit); | ||
374 | else | ||
375 | err = -EOPNOTSUPP; | ||
376 | |||
377 | put_clock_desc(&cd); | ||
378 | |||
379 | return err; | ||
380 | } | ||
381 | |||
382 | static int pc_timer_delete(struct k_itimer *kit) | ||
383 | { | ||
384 | clockid_t id = kit->it_clock; | ||
385 | struct posix_clock_desc cd; | ||
386 | int err; | ||
387 | |||
388 | err = get_clock_desc(id, &cd); | ||
389 | if (err) | ||
390 | return err; | ||
391 | |||
392 | if (cd.clk->ops.timer_delete) | ||
393 | err = cd.clk->ops.timer_delete(cd.clk, kit); | ||
394 | else | ||
395 | err = -EOPNOTSUPP; | ||
396 | |||
397 | put_clock_desc(&cd); | ||
398 | |||
399 | return err; | ||
400 | } | ||
401 | |||
402 | static void pc_timer_gettime(struct k_itimer *kit, struct itimerspec64 *ts) | ||
403 | { | ||
404 | clockid_t id = kit->it_clock; | ||
405 | struct posix_clock_desc cd; | ||
406 | |||
407 | if (get_clock_desc(id, &cd)) | ||
408 | return; | ||
409 | |||
410 | if (cd.clk->ops.timer_gettime) | ||
411 | cd.clk->ops.timer_gettime(cd.clk, kit, ts); | ||
412 | |||
413 | put_clock_desc(&cd); | ||
414 | } | ||
415 | |||
416 | static int pc_timer_settime(struct k_itimer *kit, int flags, | ||
417 | struct itimerspec64 *ts, struct itimerspec64 *old) | ||
418 | { | ||
419 | clockid_t id = kit->it_clock; | ||
420 | struct posix_clock_desc cd; | ||
421 | int err; | ||
422 | |||
423 | err = get_clock_desc(id, &cd); | ||
424 | if (err) | ||
425 | return err; | ||
426 | |||
427 | if (cd.clk->ops.timer_settime) | ||
428 | err = cd.clk->ops.timer_settime(cd.clk, kit, flags, ts, old); | ||
429 | else | ||
430 | err = -EOPNOTSUPP; | ||
431 | |||
432 | put_clock_desc(&cd); | ||
433 | |||
434 | return err; | ||
435 | } | ||
436 | |||
437 | struct k_clock clock_posix_dynamic = { | ||
438 | .clock_getres = pc_clock_getres, | 331 | .clock_getres = pc_clock_getres, |
439 | .clock_set = pc_clock_settime, | 332 | .clock_set = pc_clock_settime, |
440 | .clock_get = pc_clock_gettime, | 333 | .clock_get = pc_clock_gettime, |
441 | .clock_adj = pc_clock_adjtime, | 334 | .clock_adj = pc_clock_adjtime, |
442 | .timer_create = pc_timer_create, | ||
443 | .timer_set = pc_timer_settime, | ||
444 | .timer_del = pc_timer_delete, | ||
445 | .timer_get = pc_timer_gettime, | ||
446 | }; | 335 | }; |
diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c index d2a1e6dd0291..60cb24ac9ebc 100644 --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c | |||
@@ -12,6 +12,11 @@ | |||
12 | #include <trace/events/timer.h> | 12 | #include <trace/events/timer.h> |
13 | #include <linux/tick.h> | 13 | #include <linux/tick.h> |
14 | #include <linux/workqueue.h> | 14 | #include <linux/workqueue.h> |
15 | #include <linux/compat.h> | ||
16 | |||
17 | #include "posix-timers.h" | ||
18 | |||
19 | static void posix_cpu_timer_rearm(struct k_itimer *timer); | ||
15 | 20 | ||
16 | /* | 21 | /* |
17 | * Called after updating RLIMIT_CPU to run cpu timer and update | 22 | * Called after updating RLIMIT_CPU to run cpu timer and update |
@@ -322,6 +327,8 @@ static int posix_cpu_timer_create(struct k_itimer *new_timer) | |||
322 | if (CPUCLOCK_WHICH(new_timer->it_clock) >= CPUCLOCK_MAX) | 327 | if (CPUCLOCK_WHICH(new_timer->it_clock) >= CPUCLOCK_MAX) |
323 | return -EINVAL; | 328 | return -EINVAL; |
324 | 329 | ||
330 | new_timer->kclock = &clock_posix_cpu; | ||
331 | |||
325 | INIT_LIST_HEAD(&new_timer->it.cpu.entry); | 332 | INIT_LIST_HEAD(&new_timer->it.cpu.entry); |
326 | 333 | ||
327 | rcu_read_lock(); | 334 | rcu_read_lock(); |
@@ -524,7 +531,8 @@ static void cpu_timer_fire(struct k_itimer *timer) | |||
524 | * reload the timer. But we need to keep it | 531 | * reload the timer. But we need to keep it |
525 | * ticking in case the signal is deliverable next time. | 532 | * ticking in case the signal is deliverable next time. |
526 | */ | 533 | */ |
527 | posix_cpu_timer_schedule(timer); | 534 | posix_cpu_timer_rearm(timer); |
535 | ++timer->it_requeue_pending; | ||
528 | } | 536 | } |
529 | } | 537 | } |
530 | 538 | ||
@@ -572,7 +580,11 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags, | |||
572 | 580 | ||
573 | WARN_ON_ONCE(p == NULL); | 581 | WARN_ON_ONCE(p == NULL); |
574 | 582 | ||
575 | new_expires = timespec64_to_ns(&new->it_value); | 583 | /* |
584 | * Use the to_ktime conversion because that clamps the maximum | ||
585 | * value to KTIME_MAX and avoid multiplication overflows. | ||
586 | */ | ||
587 | new_expires = ktime_to_ns(timespec64_to_ktime(new->it_value)); | ||
576 | 588 | ||
577 | /* | 589 | /* |
578 | * Protect against sighand release/switch in exit/exec and p->cpu_timers | 590 | * Protect against sighand release/switch in exit/exec and p->cpu_timers |
@@ -712,10 +724,8 @@ static void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec64 *itp | |||
712 | */ | 724 | */ |
713 | itp->it_interval = ns_to_timespec64(timer->it.cpu.incr); | 725 | itp->it_interval = ns_to_timespec64(timer->it.cpu.incr); |
714 | 726 | ||
715 | if (timer->it.cpu.expires == 0) { /* Timer not armed at all. */ | 727 | if (!timer->it.cpu.expires) |
716 | itp->it_value.tv_sec = itp->it_value.tv_nsec = 0; | ||
717 | return; | 728 | return; |
718 | } | ||
719 | 729 | ||
720 | /* | 730 | /* |
721 | * Sample the clock to take the difference with the expiry time. | 731 | * Sample the clock to take the difference with the expiry time. |
@@ -739,7 +749,6 @@ static void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec64 *itp | |||
739 | * Call the timer disarmed, nothing else to do. | 749 | * Call the timer disarmed, nothing else to do. |
740 | */ | 750 | */ |
741 | timer->it.cpu.expires = 0; | 751 | timer->it.cpu.expires = 0; |
742 | itp->it_value = ns_to_timespec64(timer->it.cpu.expires); | ||
743 | return; | 752 | return; |
744 | } else { | 753 | } else { |
745 | cpu_timer_sample_group(timer->it_clock, p, &now); | 754 | cpu_timer_sample_group(timer->it_clock, p, &now); |
@@ -976,10 +985,10 @@ static void check_process_timers(struct task_struct *tsk, | |||
976 | } | 985 | } |
977 | 986 | ||
978 | /* | 987 | /* |
979 | * This is called from the signal code (via do_schedule_next_timer) | 988 | * This is called from the signal code (via posixtimer_rearm) |
980 | * when the last timer signal was delivered and we have to reload the timer. | 989 | * when the last timer signal was delivered and we have to reload the timer. |
981 | */ | 990 | */ |
982 | void posix_cpu_timer_schedule(struct k_itimer *timer) | 991 | static void posix_cpu_timer_rearm(struct k_itimer *timer) |
983 | { | 992 | { |
984 | struct sighand_struct *sighand; | 993 | struct sighand_struct *sighand; |
985 | unsigned long flags; | 994 | unsigned long flags; |
@@ -995,12 +1004,12 @@ void posix_cpu_timer_schedule(struct k_itimer *timer) | |||
995 | cpu_clock_sample(timer->it_clock, p, &now); | 1004 | cpu_clock_sample(timer->it_clock, p, &now); |
996 | bump_cpu_timer(timer, now); | 1005 | bump_cpu_timer(timer, now); |
997 | if (unlikely(p->exit_state)) | 1006 | if (unlikely(p->exit_state)) |
998 | goto out; | 1007 | return; |
999 | 1008 | ||
1000 | /* Protect timer list r/w in arm_timer() */ | 1009 | /* Protect timer list r/w in arm_timer() */ |
1001 | sighand = lock_task_sighand(p, &flags); | 1010 | sighand = lock_task_sighand(p, &flags); |
1002 | if (!sighand) | 1011 | if (!sighand) |
1003 | goto out; | 1012 | return; |
1004 | } else { | 1013 | } else { |
1005 | /* | 1014 | /* |
1006 | * Protect arm_timer() and timer sampling in case of call to | 1015 | * Protect arm_timer() and timer sampling in case of call to |
@@ -1013,11 +1022,10 @@ void posix_cpu_timer_schedule(struct k_itimer *timer) | |||
1013 | * We can't even collect a sample any more. | 1022 | * We can't even collect a sample any more. |
1014 | */ | 1023 | */ |
1015 | timer->it.cpu.expires = 0; | 1024 | timer->it.cpu.expires = 0; |
1016 | goto out; | 1025 | return; |
1017 | } else if (unlikely(p->exit_state) && thread_group_empty(p)) { | 1026 | } else if (unlikely(p->exit_state) && thread_group_empty(p)) { |
1018 | unlock_task_sighand(p, &flags); | 1027 | /* If the process is dying, no need to rearm */ |
1019 | /* Optimizations: if the process is dying, no need to rearm */ | 1028 | goto unlock; |
1020 | goto out; | ||
1021 | } | 1029 | } |
1022 | cpu_timer_sample_group(timer->it_clock, p, &now); | 1030 | cpu_timer_sample_group(timer->it_clock, p, &now); |
1023 | bump_cpu_timer(timer, now); | 1031 | bump_cpu_timer(timer, now); |
@@ -1029,12 +1037,8 @@ void posix_cpu_timer_schedule(struct k_itimer *timer) | |||
1029 | */ | 1037 | */ |
1030 | WARN_ON_ONCE(!irqs_disabled()); | 1038 | WARN_ON_ONCE(!irqs_disabled()); |
1031 | arm_timer(timer); | 1039 | arm_timer(timer); |
1040 | unlock: | ||
1032 | unlock_task_sighand(p, &flags); | 1041 | unlock_task_sighand(p, &flags); |
1033 | |||
1034 | out: | ||
1035 | timer->it_overrun_last = timer->it_overrun; | ||
1036 | timer->it_overrun = -1; | ||
1037 | ++timer->it_requeue_pending; | ||
1038 | } | 1042 | } |
1039 | 1043 | ||
1040 | /** | 1044 | /** |
@@ -1227,9 +1231,11 @@ void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx, | |||
1227 | } | 1231 | } |
1228 | 1232 | ||
1229 | static int do_cpu_nanosleep(const clockid_t which_clock, int flags, | 1233 | static int do_cpu_nanosleep(const clockid_t which_clock, int flags, |
1230 | struct timespec64 *rqtp, struct itimerspec64 *it) | 1234 | const struct timespec64 *rqtp) |
1231 | { | 1235 | { |
1236 | struct itimerspec64 it; | ||
1232 | struct k_itimer timer; | 1237 | struct k_itimer timer; |
1238 | u64 expires; | ||
1233 | int error; | 1239 | int error; |
1234 | 1240 | ||
1235 | /* | 1241 | /* |
@@ -1243,12 +1249,13 @@ static int do_cpu_nanosleep(const clockid_t which_clock, int flags, | |||
1243 | timer.it_process = current; | 1249 | timer.it_process = current; |
1244 | if (!error) { | 1250 | if (!error) { |
1245 | static struct itimerspec64 zero_it; | 1251 | static struct itimerspec64 zero_it; |
1252 | struct restart_block *restart; | ||
1246 | 1253 | ||
1247 | memset(it, 0, sizeof *it); | 1254 | memset(&it, 0, sizeof(it)); |
1248 | it->it_value = *rqtp; | 1255 | it.it_value = *rqtp; |
1249 | 1256 | ||
1250 | spin_lock_irq(&timer.it_lock); | 1257 | spin_lock_irq(&timer.it_lock); |
1251 | error = posix_cpu_timer_set(&timer, flags, it, NULL); | 1258 | error = posix_cpu_timer_set(&timer, flags, &it, NULL); |
1252 | if (error) { | 1259 | if (error) { |
1253 | spin_unlock_irq(&timer.it_lock); | 1260 | spin_unlock_irq(&timer.it_lock); |
1254 | return error; | 1261 | return error; |
@@ -1277,8 +1284,8 @@ static int do_cpu_nanosleep(const clockid_t which_clock, int flags, | |||
1277 | /* | 1284 | /* |
1278 | * We were interrupted by a signal. | 1285 | * We were interrupted by a signal. |
1279 | */ | 1286 | */ |
1280 | *rqtp = ns_to_timespec64(timer.it.cpu.expires); | 1287 | expires = timer.it.cpu.expires; |
1281 | error = posix_cpu_timer_set(&timer, 0, &zero_it, it); | 1288 | error = posix_cpu_timer_set(&timer, 0, &zero_it, &it); |
1282 | if (!error) { | 1289 | if (!error) { |
1283 | /* | 1290 | /* |
1284 | * Timer is now unarmed, deletion can not fail. | 1291 | * Timer is now unarmed, deletion can not fail. |
@@ -1298,7 +1305,7 @@ static int do_cpu_nanosleep(const clockid_t which_clock, int flags, | |||
1298 | spin_unlock_irq(&timer.it_lock); | 1305 | spin_unlock_irq(&timer.it_lock); |
1299 | } | 1306 | } |
1300 | 1307 | ||
1301 | if ((it->it_value.tv_sec | it->it_value.tv_nsec) == 0) { | 1308 | if ((it.it_value.tv_sec | it.it_value.tv_nsec) == 0) { |
1302 | /* | 1309 | /* |
1303 | * It actually did fire already. | 1310 | * It actually did fire already. |
1304 | */ | 1311 | */ |
@@ -1306,6 +1313,17 @@ static int do_cpu_nanosleep(const clockid_t which_clock, int flags, | |||
1306 | } | 1313 | } |
1307 | 1314 | ||
1308 | error = -ERESTART_RESTARTBLOCK; | 1315 | error = -ERESTART_RESTARTBLOCK; |
1316 | /* | ||
1317 | * Report back to the user the time still remaining. | ||
1318 | */ | ||
1319 | restart = ¤t->restart_block; | ||
1320 | restart->nanosleep.expires = expires; | ||
1321 | if (restart->nanosleep.type != TT_NONE) { | ||
1322 | struct timespec ts; | ||
1323 | |||
1324 | ts = timespec64_to_timespec(it.it_value); | ||
1325 | error = nanosleep_copyout(restart, &ts); | ||
1326 | } | ||
1309 | } | 1327 | } |
1310 | 1328 | ||
1311 | return error; | 1329 | return error; |
@@ -1314,11 +1332,9 @@ static int do_cpu_nanosleep(const clockid_t which_clock, int flags, | |||
1314 | static long posix_cpu_nsleep_restart(struct restart_block *restart_block); | 1332 | static long posix_cpu_nsleep_restart(struct restart_block *restart_block); |
1315 | 1333 | ||
1316 | static int posix_cpu_nsleep(const clockid_t which_clock, int flags, | 1334 | static int posix_cpu_nsleep(const clockid_t which_clock, int flags, |
1317 | struct timespec64 *rqtp, struct timespec __user *rmtp) | 1335 | const struct timespec64 *rqtp) |
1318 | { | 1336 | { |
1319 | struct restart_block *restart_block = ¤t->restart_block; | 1337 | struct restart_block *restart_block = ¤t->restart_block; |
1320 | struct itimerspec64 it; | ||
1321 | struct timespec ts; | ||
1322 | int error; | 1338 | int error; |
1323 | 1339 | ||
1324 | /* | 1340 | /* |
@@ -1329,23 +1345,15 @@ static int posix_cpu_nsleep(const clockid_t which_clock, int flags, | |||
1329 | CPUCLOCK_PID(which_clock) == task_pid_vnr(current))) | 1345 | CPUCLOCK_PID(which_clock) == task_pid_vnr(current))) |
1330 | return -EINVAL; | 1346 | return -EINVAL; |
1331 | 1347 | ||
1332 | error = do_cpu_nanosleep(which_clock, flags, rqtp, &it); | 1348 | error = do_cpu_nanosleep(which_clock, flags, rqtp); |
1333 | 1349 | ||
1334 | if (error == -ERESTART_RESTARTBLOCK) { | 1350 | if (error == -ERESTART_RESTARTBLOCK) { |
1335 | 1351 | ||
1336 | if (flags & TIMER_ABSTIME) | 1352 | if (flags & TIMER_ABSTIME) |
1337 | return -ERESTARTNOHAND; | 1353 | return -ERESTARTNOHAND; |
1338 | /* | ||
1339 | * Report back to the user the time still remaining. | ||
1340 | */ | ||
1341 | ts = timespec64_to_timespec(it.it_value); | ||
1342 | if (rmtp && copy_to_user(rmtp, &ts, sizeof(*rmtp))) | ||
1343 | return -EFAULT; | ||
1344 | 1354 | ||
1345 | restart_block->fn = posix_cpu_nsleep_restart; | 1355 | restart_block->fn = posix_cpu_nsleep_restart; |
1346 | restart_block->nanosleep.clockid = which_clock; | 1356 | restart_block->nanosleep.clockid = which_clock; |
1347 | restart_block->nanosleep.rmtp = rmtp; | ||
1348 | restart_block->nanosleep.expires = timespec64_to_ns(rqtp); | ||
1349 | } | 1357 | } |
1350 | return error; | 1358 | return error; |
1351 | } | 1359 | } |
@@ -1353,28 +1361,11 @@ static int posix_cpu_nsleep(const clockid_t which_clock, int flags, | |||
1353 | static long posix_cpu_nsleep_restart(struct restart_block *restart_block) | 1361 | static long posix_cpu_nsleep_restart(struct restart_block *restart_block) |
1354 | { | 1362 | { |
1355 | clockid_t which_clock = restart_block->nanosleep.clockid; | 1363 | clockid_t which_clock = restart_block->nanosleep.clockid; |
1356 | struct itimerspec64 it; | ||
1357 | struct timespec64 t; | 1364 | struct timespec64 t; |
1358 | struct timespec tmp; | ||
1359 | int error; | ||
1360 | 1365 | ||
1361 | t = ns_to_timespec64(restart_block->nanosleep.expires); | 1366 | t = ns_to_timespec64(restart_block->nanosleep.expires); |
1362 | 1367 | ||
1363 | error = do_cpu_nanosleep(which_clock, TIMER_ABSTIME, &t, &it); | 1368 | return do_cpu_nanosleep(which_clock, TIMER_ABSTIME, &t); |
1364 | |||
1365 | if (error == -ERESTART_RESTARTBLOCK) { | ||
1366 | struct timespec __user *rmtp = restart_block->nanosleep.rmtp; | ||
1367 | /* | ||
1368 | * Report back to the user the time still remaining. | ||
1369 | */ | ||
1370 | tmp = timespec64_to_timespec(it.it_value); | ||
1371 | if (rmtp && copy_to_user(rmtp, &tmp, sizeof(*rmtp))) | ||
1372 | return -EFAULT; | ||
1373 | |||
1374 | restart_block->nanosleep.expires = timespec64_to_ns(&t); | ||
1375 | } | ||
1376 | return error; | ||
1377 | |||
1378 | } | 1369 | } |
1379 | 1370 | ||
1380 | #define PROCESS_CLOCK MAKE_PROCESS_CPUCLOCK(0, CPUCLOCK_SCHED) | 1371 | #define PROCESS_CLOCK MAKE_PROCESS_CPUCLOCK(0, CPUCLOCK_SCHED) |
@@ -1396,14 +1387,9 @@ static int process_cpu_timer_create(struct k_itimer *timer) | |||
1396 | return posix_cpu_timer_create(timer); | 1387 | return posix_cpu_timer_create(timer); |
1397 | } | 1388 | } |
1398 | static int process_cpu_nsleep(const clockid_t which_clock, int flags, | 1389 | static int process_cpu_nsleep(const clockid_t which_clock, int flags, |
1399 | struct timespec64 *rqtp, | 1390 | const struct timespec64 *rqtp) |
1400 | struct timespec __user *rmtp) | ||
1401 | { | ||
1402 | return posix_cpu_nsleep(PROCESS_CLOCK, flags, rqtp, rmtp); | ||
1403 | } | ||
1404 | static long process_cpu_nsleep_restart(struct restart_block *restart_block) | ||
1405 | { | 1391 | { |
1406 | return -EINVAL; | 1392 | return posix_cpu_nsleep(PROCESS_CLOCK, flags, rqtp); |
1407 | } | 1393 | } |
1408 | static int thread_cpu_clock_getres(const clockid_t which_clock, | 1394 | static int thread_cpu_clock_getres(const clockid_t which_clock, |
1409 | struct timespec64 *tp) | 1395 | struct timespec64 *tp) |
@@ -1421,36 +1407,27 @@ static int thread_cpu_timer_create(struct k_itimer *timer) | |||
1421 | return posix_cpu_timer_create(timer); | 1407 | return posix_cpu_timer_create(timer); |
1422 | } | 1408 | } |
1423 | 1409 | ||
1424 | struct k_clock clock_posix_cpu = { | 1410 | const struct k_clock clock_posix_cpu = { |
1425 | .clock_getres = posix_cpu_clock_getres, | 1411 | .clock_getres = posix_cpu_clock_getres, |
1426 | .clock_set = posix_cpu_clock_set, | 1412 | .clock_set = posix_cpu_clock_set, |
1427 | .clock_get = posix_cpu_clock_get, | 1413 | .clock_get = posix_cpu_clock_get, |
1428 | .timer_create = posix_cpu_timer_create, | 1414 | .timer_create = posix_cpu_timer_create, |
1429 | .nsleep = posix_cpu_nsleep, | 1415 | .nsleep = posix_cpu_nsleep, |
1430 | .nsleep_restart = posix_cpu_nsleep_restart, | ||
1431 | .timer_set = posix_cpu_timer_set, | 1416 | .timer_set = posix_cpu_timer_set, |
1432 | .timer_del = posix_cpu_timer_del, | 1417 | .timer_del = posix_cpu_timer_del, |
1433 | .timer_get = posix_cpu_timer_get, | 1418 | .timer_get = posix_cpu_timer_get, |
1419 | .timer_rearm = posix_cpu_timer_rearm, | ||
1434 | }; | 1420 | }; |
1435 | 1421 | ||
1436 | static __init int init_posix_cpu_timers(void) | 1422 | const struct k_clock clock_process = { |
1437 | { | 1423 | .clock_getres = process_cpu_clock_getres, |
1438 | struct k_clock process = { | 1424 | .clock_get = process_cpu_clock_get, |
1439 | .clock_getres = process_cpu_clock_getres, | 1425 | .timer_create = process_cpu_timer_create, |
1440 | .clock_get = process_cpu_clock_get, | 1426 | .nsleep = process_cpu_nsleep, |
1441 | .timer_create = process_cpu_timer_create, | 1427 | }; |
1442 | .nsleep = process_cpu_nsleep, | ||
1443 | .nsleep_restart = process_cpu_nsleep_restart, | ||
1444 | }; | ||
1445 | struct k_clock thread = { | ||
1446 | .clock_getres = thread_cpu_clock_getres, | ||
1447 | .clock_get = thread_cpu_clock_get, | ||
1448 | .timer_create = thread_cpu_timer_create, | ||
1449 | }; | ||
1450 | |||
1451 | posix_timers_register_clock(CLOCK_PROCESS_CPUTIME_ID, &process); | ||
1452 | posix_timers_register_clock(CLOCK_THREAD_CPUTIME_ID, &thread); | ||
1453 | 1428 | ||
1454 | return 0; | 1429 | const struct k_clock clock_thread = { |
1455 | } | 1430 | .clock_getres = thread_cpu_clock_getres, |
1456 | __initcall(init_posix_cpu_timers); | 1431 | .clock_get = thread_cpu_clock_get, |
1432 | .timer_create = thread_cpu_timer_create, | ||
1433 | }; | ||
diff --git a/kernel/time/posix-stubs.c b/kernel/time/posix-stubs.c index c0cd53eb018a..38f3b20efa29 100644 --- a/kernel/time/posix-stubs.c +++ b/kernel/time/posix-stubs.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/ktime.h> | 17 | #include <linux/ktime.h> |
18 | #include <linux/timekeeping.h> | 18 | #include <linux/timekeeping.h> |
19 | #include <linux/posix-timers.h> | 19 | #include <linux/posix-timers.h> |
20 | #include <linux/compat.h> | ||
20 | 21 | ||
21 | asmlinkage long sys_ni_posix_timers(void) | 22 | asmlinkage long sys_ni_posix_timers(void) |
22 | { | 23 | { |
@@ -27,6 +28,7 @@ asmlinkage long sys_ni_posix_timers(void) | |||
27 | } | 28 | } |
28 | 29 | ||
29 | #define SYS_NI(name) SYSCALL_ALIAS(sys_##name, sys_ni_posix_timers) | 30 | #define SYS_NI(name) SYSCALL_ALIAS(sys_##name, sys_ni_posix_timers) |
31 | #define COMPAT_SYS_NI(name) SYSCALL_ALIAS(compat_sys_##name, sys_ni_posix_timers) | ||
30 | 32 | ||
31 | SYS_NI(timer_create); | 33 | SYS_NI(timer_create); |
32 | SYS_NI(timer_gettime); | 34 | SYS_NI(timer_gettime); |
@@ -39,6 +41,12 @@ SYS_NI(setitimer); | |||
39 | #ifdef __ARCH_WANT_SYS_ALARM | 41 | #ifdef __ARCH_WANT_SYS_ALARM |
40 | SYS_NI(alarm); | 42 | SYS_NI(alarm); |
41 | #endif | 43 | #endif |
44 | COMPAT_SYS_NI(timer_create); | ||
45 | COMPAT_SYS_NI(clock_adjtime); | ||
46 | COMPAT_SYS_NI(timer_settime); | ||
47 | COMPAT_SYS_NI(timer_gettime); | ||
48 | COMPAT_SYS_NI(getitimer); | ||
49 | COMPAT_SYS_NI(setitimer); | ||
42 | 50 | ||
43 | /* | 51 | /* |
44 | * We preserve minimal support for CLOCK_REALTIME and CLOCK_MONOTONIC | 52 | * We preserve minimal support for CLOCK_REALTIME and CLOCK_MONOTONIC |
@@ -110,22 +118,106 @@ SYSCALL_DEFINE4(clock_nanosleep, const clockid_t, which_clock, int, flags, | |||
110 | case CLOCK_REALTIME: | 118 | case CLOCK_REALTIME: |
111 | case CLOCK_MONOTONIC: | 119 | case CLOCK_MONOTONIC: |
112 | case CLOCK_BOOTTIME: | 120 | case CLOCK_BOOTTIME: |
113 | if (copy_from_user(&t, rqtp, sizeof (struct timespec))) | 121 | break; |
114 | return -EFAULT; | ||
115 | t64 = timespec_to_timespec64(t); | ||
116 | if (!timespec64_valid(&t64)) | ||
117 | return -EINVAL; | ||
118 | return hrtimer_nanosleep(&t64, rmtp, flags & TIMER_ABSTIME ? | ||
119 | HRTIMER_MODE_ABS : HRTIMER_MODE_REL, | ||
120 | which_clock); | ||
121 | default: | 122 | default: |
122 | return -EINVAL; | 123 | return -EINVAL; |
123 | } | 124 | } |
125 | |||
126 | if (copy_from_user(&t, rqtp, sizeof (struct timespec))) | ||
127 | return -EFAULT; | ||
128 | t64 = timespec_to_timespec64(t); | ||
129 | if (!timespec64_valid(&t64)) | ||
130 | return -EINVAL; | ||
131 | if (flags & TIMER_ABSTIME) | ||
132 | rmtp = NULL; | ||
133 | current->restart_block.nanosleep.type = rmtp ? TT_NATIVE : TT_NONE; | ||
134 | current->restart_block.nanosleep.rmtp = rmtp; | ||
135 | return hrtimer_nanosleep(&t64, flags & TIMER_ABSTIME ? | ||
136 | HRTIMER_MODE_ABS : HRTIMER_MODE_REL, | ||
137 | which_clock); | ||
124 | } | 138 | } |
125 | 139 | ||
126 | #ifdef CONFIG_COMPAT | 140 | #ifdef CONFIG_COMPAT |
127 | long clock_nanosleep_restart(struct restart_block *restart_block) | 141 | COMPAT_SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock, |
142 | struct compat_timespec __user *, tp) | ||
143 | { | ||
144 | struct timespec64 new_tp64; | ||
145 | struct timespec new_tp; | ||
146 | |||
147 | if (which_clock != CLOCK_REALTIME) | ||
148 | return -EINVAL; | ||
149 | if (compat_get_timespec(&new_tp, tp)) | ||
150 | return -EFAULT; | ||
151 | |||
152 | new_tp64 = timespec_to_timespec64(new_tp); | ||
153 | return do_sys_settimeofday64(&new_tp64, NULL); | ||
154 | } | ||
155 | |||
156 | COMPAT_SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock, | ||
157 | struct compat_timespec __user *,tp) | ||
128 | { | 158 | { |
129 | return hrtimer_nanosleep_restart(restart_block); | 159 | struct timespec64 kernel_tp64; |
160 | struct timespec kernel_tp; | ||
161 | |||
162 | switch (which_clock) { | ||
163 | case CLOCK_REALTIME: ktime_get_real_ts64(&kernel_tp64); break; | ||
164 | case CLOCK_MONOTONIC: ktime_get_ts64(&kernel_tp64); break; | ||
165 | case CLOCK_BOOTTIME: get_monotonic_boottime64(&kernel_tp64); break; | ||
166 | default: return -EINVAL; | ||
167 | } | ||
168 | |||
169 | kernel_tp = timespec64_to_timespec(kernel_tp64); | ||
170 | if (compat_put_timespec(&kernel_tp, tp)) | ||
171 | return -EFAULT; | ||
172 | return 0; | ||
173 | } | ||
174 | |||
175 | COMPAT_SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock, | ||
176 | struct compat_timespec __user *, tp) | ||
177 | { | ||
178 | struct timespec rtn_tp = { | ||
179 | .tv_sec = 0, | ||
180 | .tv_nsec = hrtimer_resolution, | ||
181 | }; | ||
182 | |||
183 | switch (which_clock) { | ||
184 | case CLOCK_REALTIME: | ||
185 | case CLOCK_MONOTONIC: | ||
186 | case CLOCK_BOOTTIME: | ||
187 | if (compat_put_timespec(&rtn_tp, tp)) | ||
188 | return -EFAULT; | ||
189 | return 0; | ||
190 | default: | ||
191 | return -EINVAL; | ||
192 | } | ||
193 | } | ||
194 | COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags, | ||
195 | struct compat_timespec __user *, rqtp, | ||
196 | struct compat_timespec __user *, rmtp) | ||
197 | { | ||
198 | struct timespec64 t64; | ||
199 | struct timespec t; | ||
200 | |||
201 | switch (which_clock) { | ||
202 | case CLOCK_REALTIME: | ||
203 | case CLOCK_MONOTONIC: | ||
204 | case CLOCK_BOOTTIME: | ||
205 | break; | ||
206 | default: | ||
207 | return -EINVAL; | ||
208 | } | ||
209 | |||
210 | if (compat_get_timespec(&t, rqtp)) | ||
211 | return -EFAULT; | ||
212 | t64 = timespec_to_timespec64(t); | ||
213 | if (!timespec64_valid(&t64)) | ||
214 | return -EINVAL; | ||
215 | if (flags & TIMER_ABSTIME) | ||
216 | rmtp = NULL; | ||
217 | current->restart_block.nanosleep.type = rmtp ? TT_COMPAT : TT_NONE; | ||
218 | current->restart_block.nanosleep.compat_rmtp = rmtp; | ||
219 | return hrtimer_nanosleep(&t64, flags & TIMER_ABSTIME ? | ||
220 | HRTIMER_MODE_ABS : HRTIMER_MODE_REL, | ||
221 | which_clock); | ||
130 | } | 222 | } |
131 | #endif | 223 | #endif |
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c index 4d7b2ce09c27..82d67be7d9d1 100644 --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c | |||
@@ -49,8 +49,10 @@ | |||
49 | #include <linux/workqueue.h> | 49 | #include <linux/workqueue.h> |
50 | #include <linux/export.h> | 50 | #include <linux/export.h> |
51 | #include <linux/hashtable.h> | 51 | #include <linux/hashtable.h> |
52 | #include <linux/compat.h> | ||
52 | 53 | ||
53 | #include "timekeeping.h" | 54 | #include "timekeeping.h" |
55 | #include "posix-timers.h" | ||
54 | 56 | ||
55 | /* | 57 | /* |
56 | * Management arrays for POSIX timers. Timers are now kept in static hash table | 58 | * Management arrays for POSIX timers. Timers are now kept in static hash table |
@@ -69,6 +71,10 @@ static struct kmem_cache *posix_timers_cache; | |||
69 | static DEFINE_HASHTABLE(posix_timers_hashtable, 9); | 71 | static DEFINE_HASHTABLE(posix_timers_hashtable, 9); |
70 | static DEFINE_SPINLOCK(hash_lock); | 72 | static DEFINE_SPINLOCK(hash_lock); |
71 | 73 | ||
74 | static const struct k_clock * const posix_clocks[]; | ||
75 | static const struct k_clock *clockid_to_kclock(const clockid_t id); | ||
76 | static const struct k_clock clock_realtime, clock_monotonic; | ||
77 | |||
72 | /* | 78 | /* |
73 | * we assume that the new SIGEV_THREAD_ID shares no bits with the other | 79 | * we assume that the new SIGEV_THREAD_ID shares no bits with the other |
74 | * SIGEV values. Here we put out an error if this assumption fails. | 80 | * SIGEV values. Here we put out an error if this assumption fails. |
@@ -124,22 +130,6 @@ static DEFINE_SPINLOCK(hash_lock); | |||
124 | * have is CLOCK_REALTIME and its high res counter part, both of | 130 | * have is CLOCK_REALTIME and its high res counter part, both of |
125 | * which we beg off on and pass to do_sys_settimeofday(). | 131 | * which we beg off on and pass to do_sys_settimeofday(). |
126 | */ | 132 | */ |
127 | |||
128 | static struct k_clock posix_clocks[MAX_CLOCKS]; | ||
129 | |||
130 | /* | ||
131 | * These ones are defined below. | ||
132 | */ | ||
133 | static int common_nsleep(const clockid_t, int flags, struct timespec64 *t, | ||
134 | struct timespec __user *rmtp); | ||
135 | static int common_timer_create(struct k_itimer *new_timer); | ||
136 | static void common_timer_get(struct k_itimer *, struct itimerspec64 *); | ||
137 | static int common_timer_set(struct k_itimer *, int, | ||
138 | struct itimerspec64 *, struct itimerspec64 *); | ||
139 | static int common_timer_del(struct k_itimer *timer); | ||
140 | |||
141 | static enum hrtimer_restart posix_timer_fn(struct hrtimer *data); | ||
142 | |||
143 | static struct k_itimer *__lock_timer(timer_t timer_id, unsigned long *flags); | 133 | static struct k_itimer *__lock_timer(timer_t timer_id, unsigned long *flags); |
144 | 134 | ||
145 | #define lock_timer(tid, flags) \ | 135 | #define lock_timer(tid, flags) \ |
@@ -285,91 +275,23 @@ static int posix_get_hrtimer_res(clockid_t which_clock, struct timespec64 *tp) | |||
285 | */ | 275 | */ |
286 | static __init int init_posix_timers(void) | 276 | static __init int init_posix_timers(void) |
287 | { | 277 | { |
288 | struct k_clock clock_realtime = { | ||
289 | .clock_getres = posix_get_hrtimer_res, | ||
290 | .clock_get = posix_clock_realtime_get, | ||
291 | .clock_set = posix_clock_realtime_set, | ||
292 | .clock_adj = posix_clock_realtime_adj, | ||
293 | .nsleep = common_nsleep, | ||
294 | .nsleep_restart = hrtimer_nanosleep_restart, | ||
295 | .timer_create = common_timer_create, | ||
296 | .timer_set = common_timer_set, | ||
297 | .timer_get = common_timer_get, | ||
298 | .timer_del = common_timer_del, | ||
299 | }; | ||
300 | struct k_clock clock_monotonic = { | ||
301 | .clock_getres = posix_get_hrtimer_res, | ||
302 | .clock_get = posix_ktime_get_ts, | ||
303 | .nsleep = common_nsleep, | ||
304 | .nsleep_restart = hrtimer_nanosleep_restart, | ||
305 | .timer_create = common_timer_create, | ||
306 | .timer_set = common_timer_set, | ||
307 | .timer_get = common_timer_get, | ||
308 | .timer_del = common_timer_del, | ||
309 | }; | ||
310 | struct k_clock clock_monotonic_raw = { | ||
311 | .clock_getres = posix_get_hrtimer_res, | ||
312 | .clock_get = posix_get_monotonic_raw, | ||
313 | }; | ||
314 | struct k_clock clock_realtime_coarse = { | ||
315 | .clock_getres = posix_get_coarse_res, | ||
316 | .clock_get = posix_get_realtime_coarse, | ||
317 | }; | ||
318 | struct k_clock clock_monotonic_coarse = { | ||
319 | .clock_getres = posix_get_coarse_res, | ||
320 | .clock_get = posix_get_monotonic_coarse, | ||
321 | }; | ||
322 | struct k_clock clock_tai = { | ||
323 | .clock_getres = posix_get_hrtimer_res, | ||
324 | .clock_get = posix_get_tai, | ||
325 | .nsleep = common_nsleep, | ||
326 | .nsleep_restart = hrtimer_nanosleep_restart, | ||
327 | .timer_create = common_timer_create, | ||
328 | .timer_set = common_timer_set, | ||
329 | .timer_get = common_timer_get, | ||
330 | .timer_del = common_timer_del, | ||
331 | }; | ||
332 | struct k_clock clock_boottime = { | ||
333 | .clock_getres = posix_get_hrtimer_res, | ||
334 | .clock_get = posix_get_boottime, | ||
335 | .nsleep = common_nsleep, | ||
336 | .nsleep_restart = hrtimer_nanosleep_restart, | ||
337 | .timer_create = common_timer_create, | ||
338 | .timer_set = common_timer_set, | ||
339 | .timer_get = common_timer_get, | ||
340 | .timer_del = common_timer_del, | ||
341 | }; | ||
342 | |||
343 | posix_timers_register_clock(CLOCK_REALTIME, &clock_realtime); | ||
344 | posix_timers_register_clock(CLOCK_MONOTONIC, &clock_monotonic); | ||
345 | posix_timers_register_clock(CLOCK_MONOTONIC_RAW, &clock_monotonic_raw); | ||
346 | posix_timers_register_clock(CLOCK_REALTIME_COARSE, &clock_realtime_coarse); | ||
347 | posix_timers_register_clock(CLOCK_MONOTONIC_COARSE, &clock_monotonic_coarse); | ||
348 | posix_timers_register_clock(CLOCK_BOOTTIME, &clock_boottime); | ||
349 | posix_timers_register_clock(CLOCK_TAI, &clock_tai); | ||
350 | |||
351 | posix_timers_cache = kmem_cache_create("posix_timers_cache", | 278 | posix_timers_cache = kmem_cache_create("posix_timers_cache", |
352 | sizeof (struct k_itimer), 0, SLAB_PANIC, | 279 | sizeof (struct k_itimer), 0, SLAB_PANIC, |
353 | NULL); | 280 | NULL); |
354 | return 0; | 281 | return 0; |
355 | } | 282 | } |
356 | |||
357 | __initcall(init_posix_timers); | 283 | __initcall(init_posix_timers); |
358 | 284 | ||
359 | static void schedule_next_timer(struct k_itimer *timr) | 285 | static void common_hrtimer_rearm(struct k_itimer *timr) |
360 | { | 286 | { |
361 | struct hrtimer *timer = &timr->it.real.timer; | 287 | struct hrtimer *timer = &timr->it.real.timer; |
362 | 288 | ||
363 | if (timr->it.real.interval == 0) | 289 | if (!timr->it_interval) |
364 | return; | 290 | return; |
365 | 291 | ||
366 | timr->it_overrun += (unsigned int) hrtimer_forward(timer, | 292 | timr->it_overrun += (unsigned int) hrtimer_forward(timer, |
367 | timer->base->get_time(), | 293 | timer->base->get_time(), |
368 | timr->it.real.interval); | 294 | timr->it_interval); |
369 | |||
370 | timr->it_overrun_last = timr->it_overrun; | ||
371 | timr->it_overrun = -1; | ||
372 | ++timr->it_requeue_pending; | ||
373 | hrtimer_restart(timer); | 295 | hrtimer_restart(timer); |
374 | } | 296 | } |
375 | 297 | ||
@@ -384,24 +306,27 @@ static void schedule_next_timer(struct k_itimer *timr) | |||
384 | * To protect against the timer going away while the interrupt is queued, | 306 | * To protect against the timer going away while the interrupt is queued, |
385 | * we require that the it_requeue_pending flag be set. | 307 | * we require that the it_requeue_pending flag be set. |
386 | */ | 308 | */ |
387 | void do_schedule_next_timer(struct siginfo *info) | 309 | void posixtimer_rearm(struct siginfo *info) |
388 | { | 310 | { |
389 | struct k_itimer *timr; | 311 | struct k_itimer *timr; |
390 | unsigned long flags; | 312 | unsigned long flags; |
391 | 313 | ||
392 | timr = lock_timer(info->si_tid, &flags); | 314 | timr = lock_timer(info->si_tid, &flags); |
315 | if (!timr) | ||
316 | return; | ||
393 | 317 | ||
394 | if (timr && timr->it_requeue_pending == info->si_sys_private) { | 318 | if (timr->it_requeue_pending == info->si_sys_private) { |
395 | if (timr->it_clock < 0) | 319 | timr->kclock->timer_rearm(timr); |
396 | posix_cpu_timer_schedule(timr); | 320 | |
397 | else | 321 | timr->it_active = 1; |
398 | schedule_next_timer(timr); | 322 | timr->it_overrun_last = timr->it_overrun; |
323 | timr->it_overrun = -1; | ||
324 | ++timr->it_requeue_pending; | ||
399 | 325 | ||
400 | info->si_overrun += timr->it_overrun_last; | 326 | info->si_overrun += timr->it_overrun_last; |
401 | } | 327 | } |
402 | 328 | ||
403 | if (timr) | 329 | unlock_timer(timr, flags); |
404 | unlock_timer(timr, flags); | ||
405 | } | 330 | } |
406 | 331 | ||
407 | int posix_timer_event(struct k_itimer *timr, int si_private) | 332 | int posix_timer_event(struct k_itimer *timr, int si_private) |
@@ -410,12 +335,12 @@ int posix_timer_event(struct k_itimer *timr, int si_private) | |||
410 | int shared, ret = -1; | 335 | int shared, ret = -1; |
411 | /* | 336 | /* |
412 | * FIXME: if ->sigq is queued we can race with | 337 | * FIXME: if ->sigq is queued we can race with |
413 | * dequeue_signal()->do_schedule_next_timer(). | 338 | * dequeue_signal()->posixtimer_rearm(). |
414 | * | 339 | * |
415 | * If dequeue_signal() sees the "right" value of | 340 | * If dequeue_signal() sees the "right" value of |
416 | * si_sys_private it calls do_schedule_next_timer(). | 341 | * si_sys_private it calls posixtimer_rearm(). |
417 | * We re-queue ->sigq and drop ->it_lock(). | 342 | * We re-queue ->sigq and drop ->it_lock(). |
418 | * do_schedule_next_timer() locks the timer | 343 | * posixtimer_rearm() locks the timer |
419 | * and re-schedules it while ->sigq is pending. | 344 | * and re-schedules it while ->sigq is pending. |
420 | * Not really bad, but not that we want. | 345 | * Not really bad, but not that we want. |
421 | */ | 346 | */ |
@@ -431,7 +356,6 @@ int posix_timer_event(struct k_itimer *timr, int si_private) | |||
431 | /* If we failed to send the signal the timer stops. */ | 356 | /* If we failed to send the signal the timer stops. */ |
432 | return ret > 0; | 357 | return ret > 0; |
433 | } | 358 | } |
434 | EXPORT_SYMBOL_GPL(posix_timer_event); | ||
435 | 359 | ||
436 | /* | 360 | /* |
437 | * This function gets called when a POSIX.1b interval timer expires. It | 361 | * This function gets called when a POSIX.1b interval timer expires. It |
@@ -450,7 +374,8 @@ static enum hrtimer_restart posix_timer_fn(struct hrtimer *timer) | |||
450 | timr = container_of(timer, struct k_itimer, it.real.timer); | 374 | timr = container_of(timer, struct k_itimer, it.real.timer); |
451 | spin_lock_irqsave(&timr->it_lock, flags); | 375 | spin_lock_irqsave(&timr->it_lock, flags); |
452 | 376 | ||
453 | if (timr->it.real.interval != 0) | 377 | timr->it_active = 0; |
378 | if (timr->it_interval != 0) | ||
454 | si_private = ++timr->it_requeue_pending; | 379 | si_private = ++timr->it_requeue_pending; |
455 | 380 | ||
456 | if (posix_timer_event(timr, si_private)) { | 381 | if (posix_timer_event(timr, si_private)) { |
@@ -459,7 +384,7 @@ static enum hrtimer_restart posix_timer_fn(struct hrtimer *timer) | |||
459 | * we will not get a call back to restart it AND | 384 | * we will not get a call back to restart it AND |
460 | * it should be restarted. | 385 | * it should be restarted. |
461 | */ | 386 | */ |
462 | if (timr->it.real.interval != 0) { | 387 | if (timr->it_interval != 0) { |
463 | ktime_t now = hrtimer_cb_get_time(timer); | 388 | ktime_t now = hrtimer_cb_get_time(timer); |
464 | 389 | ||
465 | /* | 390 | /* |
@@ -488,15 +413,16 @@ static enum hrtimer_restart posix_timer_fn(struct hrtimer *timer) | |||
488 | { | 413 | { |
489 | ktime_t kj = NSEC_PER_SEC / HZ; | 414 | ktime_t kj = NSEC_PER_SEC / HZ; |
490 | 415 | ||
491 | if (timr->it.real.interval < kj) | 416 | if (timr->it_interval < kj) |
492 | now = ktime_add(now, kj); | 417 | now = ktime_add(now, kj); |
493 | } | 418 | } |
494 | #endif | 419 | #endif |
495 | timr->it_overrun += (unsigned int) | 420 | timr->it_overrun += (unsigned int) |
496 | hrtimer_forward(timer, now, | 421 | hrtimer_forward(timer, now, |
497 | timr->it.real.interval); | 422 | timr->it_interval); |
498 | ret = HRTIMER_RESTART; | 423 | ret = HRTIMER_RESTART; |
499 | ++timr->it_requeue_pending; | 424 | ++timr->it_requeue_pending; |
425 | timr->it_active = 1; | ||
500 | } | 426 | } |
501 | } | 427 | } |
502 | 428 | ||
@@ -521,30 +447,6 @@ static struct pid *good_sigevent(sigevent_t * event) | |||
521 | return task_pid(rtn); | 447 | return task_pid(rtn); |
522 | } | 448 | } |
523 | 449 | ||
524 | void posix_timers_register_clock(const clockid_t clock_id, | ||
525 | struct k_clock *new_clock) | ||
526 | { | ||
527 | if ((unsigned) clock_id >= MAX_CLOCKS) { | ||
528 | printk(KERN_WARNING "POSIX clock register failed for clock_id %d\n", | ||
529 | clock_id); | ||
530 | return; | ||
531 | } | ||
532 | |||
533 | if (!new_clock->clock_get) { | ||
534 | printk(KERN_WARNING "POSIX clock id %d lacks clock_get()\n", | ||
535 | clock_id); | ||
536 | return; | ||
537 | } | ||
538 | if (!new_clock->clock_getres) { | ||
539 | printk(KERN_WARNING "POSIX clock id %d lacks clock_getres()\n", | ||
540 | clock_id); | ||
541 | return; | ||
542 | } | ||
543 | |||
544 | posix_clocks[clock_id] = *new_clock; | ||
545 | } | ||
546 | EXPORT_SYMBOL_GPL(posix_timers_register_clock); | ||
547 | |||
548 | static struct k_itimer * alloc_posix_timer(void) | 450 | static struct k_itimer * alloc_posix_timer(void) |
549 | { | 451 | { |
550 | struct k_itimer *tmr; | 452 | struct k_itimer *tmr; |
@@ -581,17 +483,6 @@ static void release_posix_timer(struct k_itimer *tmr, int it_id_set) | |||
581 | call_rcu(&tmr->it.rcu, k_itimer_rcu_free); | 483 | call_rcu(&tmr->it.rcu, k_itimer_rcu_free); |
582 | } | 484 | } |
583 | 485 | ||
584 | static struct k_clock *clockid_to_kclock(const clockid_t id) | ||
585 | { | ||
586 | if (id < 0) | ||
587 | return (id & CLOCKFD_MASK) == CLOCKFD ? | ||
588 | &clock_posix_dynamic : &clock_posix_cpu; | ||
589 | |||
590 | if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres) | ||
591 | return NULL; | ||
592 | return &posix_clocks[id]; | ||
593 | } | ||
594 | |||
595 | static int common_timer_create(struct k_itimer *new_timer) | 486 | static int common_timer_create(struct k_itimer *new_timer) |
596 | { | 487 | { |
597 | hrtimer_init(&new_timer->it.real.timer, new_timer->it_clock, 0); | 488 | hrtimer_init(&new_timer->it.real.timer, new_timer->it_clock, 0); |
@@ -599,15 +490,12 @@ static int common_timer_create(struct k_itimer *new_timer) | |||
599 | } | 490 | } |
600 | 491 | ||
601 | /* Create a POSIX.1b interval timer. */ | 492 | /* Create a POSIX.1b interval timer. */ |
602 | 493 | static int do_timer_create(clockid_t which_clock, struct sigevent *event, | |
603 | SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock, | 494 | timer_t __user *created_timer_id) |
604 | struct sigevent __user *, timer_event_spec, | ||
605 | timer_t __user *, created_timer_id) | ||
606 | { | 495 | { |
607 | struct k_clock *kc = clockid_to_kclock(which_clock); | 496 | const struct k_clock *kc = clockid_to_kclock(which_clock); |
608 | struct k_itimer *new_timer; | 497 | struct k_itimer *new_timer; |
609 | int error, new_timer_id; | 498 | int error, new_timer_id; |
610 | sigevent_t event; | ||
611 | int it_id_set = IT_ID_NOT_SET; | 499 | int it_id_set = IT_ID_NOT_SET; |
612 | 500 | ||
613 | if (!kc) | 501 | if (!kc) |
@@ -629,31 +517,28 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock, | |||
629 | it_id_set = IT_ID_SET; | 517 | it_id_set = IT_ID_SET; |
630 | new_timer->it_id = (timer_t) new_timer_id; | 518 | new_timer->it_id = (timer_t) new_timer_id; |
631 | new_timer->it_clock = which_clock; | 519 | new_timer->it_clock = which_clock; |
520 | new_timer->kclock = kc; | ||
632 | new_timer->it_overrun = -1; | 521 | new_timer->it_overrun = -1; |
633 | 522 | ||
634 | if (timer_event_spec) { | 523 | if (event) { |
635 | if (copy_from_user(&event, timer_event_spec, sizeof (event))) { | ||
636 | error = -EFAULT; | ||
637 | goto out; | ||
638 | } | ||
639 | rcu_read_lock(); | 524 | rcu_read_lock(); |
640 | new_timer->it_pid = get_pid(good_sigevent(&event)); | 525 | new_timer->it_pid = get_pid(good_sigevent(event)); |
641 | rcu_read_unlock(); | 526 | rcu_read_unlock(); |
642 | if (!new_timer->it_pid) { | 527 | if (!new_timer->it_pid) { |
643 | error = -EINVAL; | 528 | error = -EINVAL; |
644 | goto out; | 529 | goto out; |
645 | } | 530 | } |
531 | new_timer->it_sigev_notify = event->sigev_notify; | ||
532 | new_timer->sigq->info.si_signo = event->sigev_signo; | ||
533 | new_timer->sigq->info.si_value = event->sigev_value; | ||
646 | } else { | 534 | } else { |
647 | memset(&event.sigev_value, 0, sizeof(event.sigev_value)); | 535 | new_timer->it_sigev_notify = SIGEV_SIGNAL; |
648 | event.sigev_notify = SIGEV_SIGNAL; | 536 | new_timer->sigq->info.si_signo = SIGALRM; |
649 | event.sigev_signo = SIGALRM; | 537 | memset(&new_timer->sigq->info.si_value, 0, sizeof(sigval_t)); |
650 | event.sigev_value.sival_int = new_timer->it_id; | 538 | new_timer->sigq->info.si_value.sival_int = new_timer->it_id; |
651 | new_timer->it_pid = get_pid(task_tgid(current)); | 539 | new_timer->it_pid = get_pid(task_tgid(current)); |
652 | } | 540 | } |
653 | 541 | ||
654 | new_timer->it_sigev_notify = event.sigev_notify; | ||
655 | new_timer->sigq->info.si_signo = event.sigev_signo; | ||
656 | new_timer->sigq->info.si_value = event.sigev_value; | ||
657 | new_timer->sigq->info.si_tid = new_timer->it_id; | 542 | new_timer->sigq->info.si_tid = new_timer->it_id; |
658 | new_timer->sigq->info.si_code = SI_TIMER; | 543 | new_timer->sigq->info.si_code = SI_TIMER; |
659 | 544 | ||
@@ -684,6 +569,36 @@ out: | |||
684 | return error; | 569 | return error; |
685 | } | 570 | } |
686 | 571 | ||
572 | SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock, | ||
573 | struct sigevent __user *, timer_event_spec, | ||
574 | timer_t __user *, created_timer_id) | ||
575 | { | ||
576 | if (timer_event_spec) { | ||
577 | sigevent_t event; | ||
578 | |||
579 | if (copy_from_user(&event, timer_event_spec, sizeof (event))) | ||
580 | return -EFAULT; | ||
581 | return do_timer_create(which_clock, &event, created_timer_id); | ||
582 | } | ||
583 | return do_timer_create(which_clock, NULL, created_timer_id); | ||
584 | } | ||
585 | |||
586 | #ifdef CONFIG_COMPAT | ||
587 | COMPAT_SYSCALL_DEFINE3(timer_create, clockid_t, which_clock, | ||
588 | struct compat_sigevent __user *, timer_event_spec, | ||
589 | timer_t __user *, created_timer_id) | ||
590 | { | ||
591 | if (timer_event_spec) { | ||
592 | sigevent_t event; | ||
593 | |||
594 | if (get_compat_sigevent(&event, timer_event_spec)) | ||
595 | return -EFAULT; | ||
596 | return do_timer_create(which_clock, &event, created_timer_id); | ||
597 | } | ||
598 | return do_timer_create(which_clock, NULL, created_timer_id); | ||
599 | } | ||
600 | #endif | ||
601 | |||
687 | /* | 602 | /* |
688 | * Locking issues: We need to protect the result of the id look up until | 603 | * Locking issues: We need to protect the result of the id look up until |
689 | * we get the timer locked down so it is not deleted under us. The | 604 | * we get the timer locked down so it is not deleted under us. The |
@@ -717,6 +632,20 @@ static struct k_itimer *__lock_timer(timer_t timer_id, unsigned long *flags) | |||
717 | return NULL; | 632 | return NULL; |
718 | } | 633 | } |
719 | 634 | ||
635 | static ktime_t common_hrtimer_remaining(struct k_itimer *timr, ktime_t now) | ||
636 | { | ||
637 | struct hrtimer *timer = &timr->it.real.timer; | ||
638 | |||
639 | return __hrtimer_expires_remaining_adjusted(timer, now); | ||
640 | } | ||
641 | |||
642 | static int common_hrtimer_forward(struct k_itimer *timr, ktime_t now) | ||
643 | { | ||
644 | struct hrtimer *timer = &timr->it.real.timer; | ||
645 | |||
646 | return (int)hrtimer_forward(timer, now, timr->it_interval); | ||
647 | } | ||
648 | |||
720 | /* | 649 | /* |
721 | * Get the time remaining on a POSIX.1b interval timer. This function | 650 | * Get the time remaining on a POSIX.1b interval timer. This function |
722 | * is ALWAYS called with spin_lock_irq on the timer, thus it must not | 651 | * is ALWAYS called with spin_lock_irq on the timer, thus it must not |
@@ -733,55 +662,61 @@ static struct k_itimer *__lock_timer(timer_t timer_id, unsigned long *flags) | |||
733 | * it is the same as a requeue pending timer WRT to what we should | 662 | * it is the same as a requeue pending timer WRT to what we should |
734 | * report. | 663 | * report. |
735 | */ | 664 | */ |
736 | static void | 665 | void common_timer_get(struct k_itimer *timr, struct itimerspec64 *cur_setting) |
737 | common_timer_get(struct k_itimer *timr, struct itimerspec64 *cur_setting) | ||
738 | { | 666 | { |
667 | const struct k_clock *kc = timr->kclock; | ||
739 | ktime_t now, remaining, iv; | 668 | ktime_t now, remaining, iv; |
740 | struct hrtimer *timer = &timr->it.real.timer; | 669 | struct timespec64 ts64; |
670 | bool sig_none; | ||
741 | 671 | ||
742 | memset(cur_setting, 0, sizeof(*cur_setting)); | 672 | sig_none = (timr->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE; |
743 | 673 | iv = timr->it_interval; | |
744 | iv = timr->it.real.interval; | ||
745 | 674 | ||
746 | /* interval timer ? */ | 675 | /* interval timer ? */ |
747 | if (iv) | 676 | if (iv) { |
748 | cur_setting->it_interval = ktime_to_timespec64(iv); | 677 | cur_setting->it_interval = ktime_to_timespec64(iv); |
749 | else if (!hrtimer_active(timer) && | 678 | } else if (!timr->it_active) { |
750 | (timr->it_sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_NONE) | 679 | /* |
751 | return; | 680 | * SIGEV_NONE oneshot timers are never queued. Check them |
681 | * below. | ||
682 | */ | ||
683 | if (!sig_none) | ||
684 | return; | ||
685 | } | ||
752 | 686 | ||
753 | now = timer->base->get_time(); | 687 | /* |
688 | * The timespec64 based conversion is suboptimal, but it's not | ||
689 | * worth to implement yet another callback. | ||
690 | */ | ||
691 | kc->clock_get(timr->it_clock, &ts64); | ||
692 | now = timespec64_to_ktime(ts64); | ||
754 | 693 | ||
755 | /* | 694 | /* |
756 | * When a requeue is pending or this is a SIGEV_NONE | 695 | * When a requeue is pending or this is a SIGEV_NONE timer move the |
757 | * timer move the expiry time forward by intervals, so | 696 | * expiry time forward by intervals, so expiry is > now. |
758 | * expiry is > now. | ||
759 | */ | 697 | */ |
760 | if (iv && (timr->it_requeue_pending & REQUEUE_PENDING || | 698 | if (iv && (timr->it_requeue_pending & REQUEUE_PENDING || sig_none)) |
761 | (timr->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE)) | 699 | timr->it_overrun += kc->timer_forward(timr, now); |
762 | timr->it_overrun += (unsigned int) hrtimer_forward(timer, now, iv); | ||
763 | 700 | ||
764 | remaining = __hrtimer_expires_remaining_adjusted(timer, now); | 701 | remaining = kc->timer_remaining(timr, now); |
765 | /* Return 0 only, when the timer is expired and not pending */ | 702 | /* Return 0 only, when the timer is expired and not pending */ |
766 | if (remaining <= 0) { | 703 | if (remaining <= 0) { |
767 | /* | 704 | /* |
768 | * A single shot SIGEV_NONE timer must return 0, when | 705 | * A single shot SIGEV_NONE timer must return 0, when |
769 | * it is expired ! | 706 | * it is expired ! |
770 | */ | 707 | */ |
771 | if ((timr->it_sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_NONE) | 708 | if (!sig_none) |
772 | cur_setting->it_value.tv_nsec = 1; | 709 | cur_setting->it_value.tv_nsec = 1; |
773 | } else | 710 | } else { |
774 | cur_setting->it_value = ktime_to_timespec64(remaining); | 711 | cur_setting->it_value = ktime_to_timespec64(remaining); |
712 | } | ||
775 | } | 713 | } |
776 | 714 | ||
777 | /* Get the time remaining on a POSIX.1b interval timer. */ | 715 | /* Get the time remaining on a POSIX.1b interval timer. */ |
778 | SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id, | 716 | static int do_timer_gettime(timer_t timer_id, struct itimerspec64 *setting) |
779 | struct itimerspec __user *, setting) | ||
780 | { | 717 | { |
781 | struct itimerspec64 cur_setting64; | ||
782 | struct itimerspec cur_setting; | ||
783 | struct k_itimer *timr; | 718 | struct k_itimer *timr; |
784 | struct k_clock *kc; | 719 | const struct k_clock *kc; |
785 | unsigned long flags; | 720 | unsigned long flags; |
786 | int ret = 0; | 721 | int ret = 0; |
787 | 722 | ||
@@ -789,20 +724,49 @@ SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id, | |||
789 | if (!timr) | 724 | if (!timr) |
790 | return -EINVAL; | 725 | return -EINVAL; |
791 | 726 | ||
792 | kc = clockid_to_kclock(timr->it_clock); | 727 | memset(setting, 0, sizeof(*setting)); |
728 | kc = timr->kclock; | ||
793 | if (WARN_ON_ONCE(!kc || !kc->timer_get)) | 729 | if (WARN_ON_ONCE(!kc || !kc->timer_get)) |
794 | ret = -EINVAL; | 730 | ret = -EINVAL; |
795 | else | 731 | else |
796 | kc->timer_get(timr, &cur_setting64); | 732 | kc->timer_get(timr, setting); |
797 | 733 | ||
798 | unlock_timer(timr, flags); | 734 | unlock_timer(timr, flags); |
735 | return ret; | ||
736 | } | ||
799 | 737 | ||
800 | cur_setting = itimerspec64_to_itimerspec(&cur_setting64); | 738 | /* Get the time remaining on a POSIX.1b interval timer. */ |
801 | if (!ret && copy_to_user(setting, &cur_setting, sizeof (cur_setting))) | 739 | SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id, |
802 | return -EFAULT; | 740 | struct itimerspec __user *, setting) |
741 | { | ||
742 | struct itimerspec64 cur_setting64; | ||
803 | 743 | ||
744 | int ret = do_timer_gettime(timer_id, &cur_setting64); | ||
745 | if (!ret) { | ||
746 | struct itimerspec cur_setting; | ||
747 | cur_setting = itimerspec64_to_itimerspec(&cur_setting64); | ||
748 | if (copy_to_user(setting, &cur_setting, sizeof (cur_setting))) | ||
749 | ret = -EFAULT; | ||
750 | } | ||
751 | return ret; | ||
752 | } | ||
753 | |||
754 | #ifdef CONFIG_COMPAT | ||
755 | COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id, | ||
756 | struct compat_itimerspec __user *, setting) | ||
757 | { | ||
758 | struct itimerspec64 cur_setting64; | ||
759 | |||
760 | int ret = do_timer_gettime(timer_id, &cur_setting64); | ||
761 | if (!ret) { | ||
762 | struct itimerspec cur_setting; | ||
763 | cur_setting = itimerspec64_to_itimerspec(&cur_setting64); | ||
764 | if (put_compat_itimerspec(setting, &cur_setting)) | ||
765 | ret = -EFAULT; | ||
766 | } | ||
804 | return ret; | 767 | return ret; |
805 | } | 768 | } |
769 | #endif | ||
806 | 770 | ||
807 | /* | 771 | /* |
808 | * Get the number of overruns of a POSIX.1b interval timer. This is to | 772 | * Get the number of overruns of a POSIX.1b interval timer. This is to |
@@ -810,7 +774,7 @@ SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id, | |||
810 | * accumulating overruns on the next timer. The overrun is frozen when | 774 | * accumulating overruns on the next timer. The overrun is frozen when |
811 | * the signal is delivered, either at the notify time (if the info block | 775 | * the signal is delivered, either at the notify time (if the info block |
812 | * is not queued) or at the actual delivery time (as we are informed by | 776 | * is not queued) or at the actual delivery time (as we are informed by |
813 | * the call back to do_schedule_next_timer(). So all we need to do is | 777 | * the call back to posixtimer_rearm(). So all we need to do is |
814 | * to pick up the frozen overrun. | 778 | * to pick up the frozen overrun. |
815 | */ | 779 | */ |
816 | SYSCALL_DEFINE1(timer_getoverrun, timer_t, timer_id) | 780 | SYSCALL_DEFINE1(timer_getoverrun, timer_t, timer_id) |
@@ -829,117 +793,183 @@ SYSCALL_DEFINE1(timer_getoverrun, timer_t, timer_id) | |||
829 | return overrun; | 793 | return overrun; |
830 | } | 794 | } |
831 | 795 | ||
832 | /* Set a POSIX.1b interval timer. */ | 796 | static void common_hrtimer_arm(struct k_itimer *timr, ktime_t expires, |
833 | /* timr->it_lock is taken. */ | 797 | bool absolute, bool sigev_none) |
834 | static int | ||
835 | common_timer_set(struct k_itimer *timr, int flags, | ||
836 | struct itimerspec64 *new_setting, struct itimerspec64 *old_setting) | ||
837 | { | 798 | { |
838 | struct hrtimer *timer = &timr->it.real.timer; | 799 | struct hrtimer *timer = &timr->it.real.timer; |
839 | enum hrtimer_mode mode; | 800 | enum hrtimer_mode mode; |
840 | 801 | ||
802 | mode = absolute ? HRTIMER_MODE_ABS : HRTIMER_MODE_REL; | ||
803 | /* | ||
804 | * Posix magic: Relative CLOCK_REALTIME timers are not affected by | ||
805 | * clock modifications, so they become CLOCK_MONOTONIC based under the | ||
806 | * hood. See hrtimer_init(). Update timr->kclock, so the generic | ||
807 | * functions which use timr->kclock->clock_get() work. | ||
808 | * | ||
809 | * Note: it_clock stays unmodified, because the next timer_set() might | ||
810 | * use ABSTIME, so it needs to switch back. | ||
811 | */ | ||
812 | if (timr->it_clock == CLOCK_REALTIME) | ||
813 | timr->kclock = absolute ? &clock_realtime : &clock_monotonic; | ||
814 | |||
815 | hrtimer_init(&timr->it.real.timer, timr->it_clock, mode); | ||
816 | timr->it.real.timer.function = posix_timer_fn; | ||
817 | |||
818 | if (!absolute) | ||
819 | expires = ktime_add_safe(expires, timer->base->get_time()); | ||
820 | hrtimer_set_expires(timer, expires); | ||
821 | |||
822 | if (!sigev_none) | ||
823 | hrtimer_start_expires(timer, HRTIMER_MODE_ABS); | ||
824 | } | ||
825 | |||
826 | static int common_hrtimer_try_to_cancel(struct k_itimer *timr) | ||
827 | { | ||
828 | return hrtimer_try_to_cancel(&timr->it.real.timer); | ||
829 | } | ||
830 | |||
831 | /* Set a POSIX.1b interval timer. */ | ||
832 | int common_timer_set(struct k_itimer *timr, int flags, | ||
833 | struct itimerspec64 *new_setting, | ||
834 | struct itimerspec64 *old_setting) | ||
835 | { | ||
836 | const struct k_clock *kc = timr->kclock; | ||
837 | bool sigev_none; | ||
838 | ktime_t expires; | ||
839 | |||
841 | if (old_setting) | 840 | if (old_setting) |
842 | common_timer_get(timr, old_setting); | 841 | common_timer_get(timr, old_setting); |
843 | 842 | ||
844 | /* disable the timer */ | 843 | /* Prevent rearming by clearing the interval */ |
845 | timr->it.real.interval = 0; | 844 | timr->it_interval = 0; |
846 | /* | 845 | /* |
847 | * careful here. If smp we could be in the "fire" routine which will | 846 | * Careful here. On SMP systems the timer expiry function could be |
848 | * be spinning as we hold the lock. But this is ONLY an SMP issue. | 847 | * active and spinning on timr->it_lock. |
849 | */ | 848 | */ |
850 | if (hrtimer_try_to_cancel(timer) < 0) | 849 | if (kc->timer_try_to_cancel(timr) < 0) |
851 | return TIMER_RETRY; | 850 | return TIMER_RETRY; |
852 | 851 | ||
853 | timr->it_requeue_pending = (timr->it_requeue_pending + 2) & | 852 | timr->it_active = 0; |
853 | timr->it_requeue_pending = (timr->it_requeue_pending + 2) & | ||
854 | ~REQUEUE_PENDING; | 854 | ~REQUEUE_PENDING; |
855 | timr->it_overrun_last = 0; | 855 | timr->it_overrun_last = 0; |
856 | 856 | ||
857 | /* switch off the timer when it_value is zero */ | 857 | /* Switch off the timer when it_value is zero */ |
858 | if (!new_setting->it_value.tv_sec && !new_setting->it_value.tv_nsec) | 858 | if (!new_setting->it_value.tv_sec && !new_setting->it_value.tv_nsec) |
859 | return 0; | 859 | return 0; |
860 | 860 | ||
861 | mode = flags & TIMER_ABSTIME ? HRTIMER_MODE_ABS : HRTIMER_MODE_REL; | 861 | timr->it_interval = timespec64_to_ktime(new_setting->it_interval); |
862 | hrtimer_init(&timr->it.real.timer, timr->it_clock, mode); | 862 | expires = timespec64_to_ktime(new_setting->it_value); |
863 | timr->it.real.timer.function = posix_timer_fn; | 863 | sigev_none = (timr->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE; |
864 | |||
865 | hrtimer_set_expires(timer, timespec64_to_ktime(new_setting->it_value)); | ||
866 | |||
867 | /* Convert interval */ | ||
868 | timr->it.real.interval = timespec64_to_ktime(new_setting->it_interval); | ||
869 | |||
870 | /* SIGEV_NONE timers are not queued ! See common_timer_get */ | ||
871 | if (((timr->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE)) { | ||
872 | /* Setup correct expiry time for relative timers */ | ||
873 | if (mode == HRTIMER_MODE_REL) { | ||
874 | hrtimer_add_expires(timer, timer->base->get_time()); | ||
875 | } | ||
876 | return 0; | ||
877 | } | ||
878 | 864 | ||
879 | hrtimer_start_expires(timer, mode); | 865 | kc->timer_arm(timr, expires, flags & TIMER_ABSTIME, sigev_none); |
866 | timr->it_active = !sigev_none; | ||
880 | return 0; | 867 | return 0; |
881 | } | 868 | } |
882 | 869 | ||
883 | /* Set a POSIX.1b interval timer */ | 870 | static int do_timer_settime(timer_t timer_id, int flags, |
884 | SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags, | 871 | struct itimerspec64 *new_spec64, |
885 | const struct itimerspec __user *, new_setting, | 872 | struct itimerspec64 *old_spec64) |
886 | struct itimerspec __user *, old_setting) | ||
887 | { | 873 | { |
888 | struct itimerspec64 new_spec64, old_spec64; | 874 | const struct k_clock *kc; |
889 | struct itimerspec64 *rtn = old_setting ? &old_spec64 : NULL; | ||
890 | struct itimerspec new_spec, old_spec; | ||
891 | struct k_itimer *timr; | 875 | struct k_itimer *timr; |
892 | unsigned long flag; | 876 | unsigned long flag; |
893 | struct k_clock *kc; | ||
894 | int error = 0; | 877 | int error = 0; |
895 | 878 | ||
896 | if (!new_setting) | 879 | if (!timespec64_valid(&new_spec64->it_interval) || |
880 | !timespec64_valid(&new_spec64->it_value)) | ||
897 | return -EINVAL; | 881 | return -EINVAL; |
898 | 882 | ||
899 | if (copy_from_user(&new_spec, new_setting, sizeof (new_spec))) | 883 | if (old_spec64) |
900 | return -EFAULT; | 884 | memset(old_spec64, 0, sizeof(*old_spec64)); |
901 | new_spec64 = itimerspec_to_itimerspec64(&new_spec); | ||
902 | |||
903 | if (!timespec64_valid(&new_spec64.it_interval) || | ||
904 | !timespec64_valid(&new_spec64.it_value)) | ||
905 | return -EINVAL; | ||
906 | retry: | 885 | retry: |
907 | timr = lock_timer(timer_id, &flag); | 886 | timr = lock_timer(timer_id, &flag); |
908 | if (!timr) | 887 | if (!timr) |
909 | return -EINVAL; | 888 | return -EINVAL; |
910 | 889 | ||
911 | kc = clockid_to_kclock(timr->it_clock); | 890 | kc = timr->kclock; |
912 | if (WARN_ON_ONCE(!kc || !kc->timer_set)) | 891 | if (WARN_ON_ONCE(!kc || !kc->timer_set)) |
913 | error = -EINVAL; | 892 | error = -EINVAL; |
914 | else | 893 | else |
915 | error = kc->timer_set(timr, flags, &new_spec64, rtn); | 894 | error = kc->timer_set(timr, flags, new_spec64, old_spec64); |
916 | 895 | ||
917 | unlock_timer(timr, flag); | 896 | unlock_timer(timr, flag); |
918 | if (error == TIMER_RETRY) { | 897 | if (error == TIMER_RETRY) { |
919 | rtn = NULL; // We already got the old time... | 898 | old_spec64 = NULL; // We already got the old time... |
920 | goto retry; | 899 | goto retry; |
921 | } | 900 | } |
922 | 901 | ||
923 | old_spec = itimerspec64_to_itimerspec(&old_spec64); | 902 | return error; |
924 | if (old_setting && !error && | 903 | } |
925 | copy_to_user(old_setting, &old_spec, sizeof (old_spec))) | 904 | |
926 | error = -EFAULT; | 905 | /* Set a POSIX.1b interval timer */ |
906 | SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags, | ||
907 | const struct itimerspec __user *, new_setting, | ||
908 | struct itimerspec __user *, old_setting) | ||
909 | { | ||
910 | struct itimerspec64 new_spec64, old_spec64; | ||
911 | struct itimerspec64 *rtn = old_setting ? &old_spec64 : NULL; | ||
912 | struct itimerspec new_spec; | ||
913 | int error = 0; | ||
914 | |||
915 | if (!new_setting) | ||
916 | return -EINVAL; | ||
917 | |||
918 | if (copy_from_user(&new_spec, new_setting, sizeof (new_spec))) | ||
919 | return -EFAULT; | ||
920 | new_spec64 = itimerspec_to_itimerspec64(&new_spec); | ||
921 | |||
922 | error = do_timer_settime(timer_id, flags, &new_spec64, rtn); | ||
923 | if (!error && old_setting) { | ||
924 | struct itimerspec old_spec; | ||
925 | old_spec = itimerspec64_to_itimerspec(&old_spec64); | ||
926 | if (copy_to_user(old_setting, &old_spec, sizeof (old_spec))) | ||
927 | error = -EFAULT; | ||
928 | } | ||
929 | return error; | ||
930 | } | ||
931 | |||
932 | #ifdef CONFIG_COMPAT | ||
933 | COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags, | ||
934 | struct compat_itimerspec __user *, new, | ||
935 | struct compat_itimerspec __user *, old) | ||
936 | { | ||
937 | struct itimerspec64 new_spec64, old_spec64; | ||
938 | struct itimerspec64 *rtn = old ? &old_spec64 : NULL; | ||
939 | struct itimerspec new_spec; | ||
940 | int error = 0; | ||
941 | |||
942 | if (!new) | ||
943 | return -EINVAL; | ||
944 | if (get_compat_itimerspec(&new_spec, new)) | ||
945 | return -EFAULT; | ||
927 | 946 | ||
947 | new_spec64 = itimerspec_to_itimerspec64(&new_spec); | ||
948 | error = do_timer_settime(timer_id, flags, &new_spec64, rtn); | ||
949 | if (!error && old) { | ||
950 | struct itimerspec old_spec; | ||
951 | old_spec = itimerspec64_to_itimerspec(&old_spec64); | ||
952 | if (put_compat_itimerspec(old, &old_spec)) | ||
953 | error = -EFAULT; | ||
954 | } | ||
928 | return error; | 955 | return error; |
929 | } | 956 | } |
957 | #endif | ||
930 | 958 | ||
931 | static int common_timer_del(struct k_itimer *timer) | 959 | int common_timer_del(struct k_itimer *timer) |
932 | { | 960 | { |
933 | timer->it.real.interval = 0; | 961 | const struct k_clock *kc = timer->kclock; |
934 | 962 | ||
935 | if (hrtimer_try_to_cancel(&timer->it.real.timer) < 0) | 963 | timer->it_interval = 0; |
964 | if (kc->timer_try_to_cancel(timer) < 0) | ||
936 | return TIMER_RETRY; | 965 | return TIMER_RETRY; |
966 | timer->it_active = 0; | ||
937 | return 0; | 967 | return 0; |
938 | } | 968 | } |
939 | 969 | ||
940 | static inline int timer_delete_hook(struct k_itimer *timer) | 970 | static inline int timer_delete_hook(struct k_itimer *timer) |
941 | { | 971 | { |
942 | struct k_clock *kc = clockid_to_kclock(timer->it_clock); | 972 | const struct k_clock *kc = timer->kclock; |
943 | 973 | ||
944 | if (WARN_ON_ONCE(!kc || !kc->timer_del)) | 974 | if (WARN_ON_ONCE(!kc || !kc->timer_del)) |
945 | return -EINVAL; | 975 | return -EINVAL; |
@@ -1018,7 +1048,7 @@ void exit_itimers(struct signal_struct *sig) | |||
1018 | SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock, | 1048 | SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock, |
1019 | const struct timespec __user *, tp) | 1049 | const struct timespec __user *, tp) |
1020 | { | 1050 | { |
1021 | struct k_clock *kc = clockid_to_kclock(which_clock); | 1051 | const struct k_clock *kc = clockid_to_kclock(which_clock); |
1022 | struct timespec64 new_tp64; | 1052 | struct timespec64 new_tp64; |
1023 | struct timespec new_tp; | 1053 | struct timespec new_tp; |
1024 | 1054 | ||
@@ -1035,7 +1065,7 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock, | |||
1035 | SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock, | 1065 | SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock, |
1036 | struct timespec __user *,tp) | 1066 | struct timespec __user *,tp) |
1037 | { | 1067 | { |
1038 | struct k_clock *kc = clockid_to_kclock(which_clock); | 1068 | const struct k_clock *kc = clockid_to_kclock(which_clock); |
1039 | struct timespec64 kernel_tp64; | 1069 | struct timespec64 kernel_tp64; |
1040 | struct timespec kernel_tp; | 1070 | struct timespec kernel_tp; |
1041 | int error; | 1071 | int error; |
@@ -1055,7 +1085,7 @@ SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock, | |||
1055 | SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock, | 1085 | SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock, |
1056 | struct timex __user *, utx) | 1086 | struct timex __user *, utx) |
1057 | { | 1087 | { |
1058 | struct k_clock *kc = clockid_to_kclock(which_clock); | 1088 | const struct k_clock *kc = clockid_to_kclock(which_clock); |
1059 | struct timex ktx; | 1089 | struct timex ktx; |
1060 | int err; | 1090 | int err; |
1061 | 1091 | ||
@@ -1078,7 +1108,7 @@ SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock, | |||
1078 | SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock, | 1108 | SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock, |
1079 | struct timespec __user *, tp) | 1109 | struct timespec __user *, tp) |
1080 | { | 1110 | { |
1081 | struct k_clock *kc = clockid_to_kclock(which_clock); | 1111 | const struct k_clock *kc = clockid_to_kclock(which_clock); |
1082 | struct timespec64 rtn_tp64; | 1112 | struct timespec64 rtn_tp64; |
1083 | struct timespec rtn_tp; | 1113 | struct timespec rtn_tp; |
1084 | int error; | 1114 | int error; |
@@ -1095,13 +1125,98 @@ SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock, | |||
1095 | return error; | 1125 | return error; |
1096 | } | 1126 | } |
1097 | 1127 | ||
1128 | #ifdef CONFIG_COMPAT | ||
1129 | |||
1130 | COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock, | ||
1131 | struct compat_timespec __user *, tp) | ||
1132 | { | ||
1133 | const struct k_clock *kc = clockid_to_kclock(which_clock); | ||
1134 | struct timespec64 new_tp64; | ||
1135 | struct timespec new_tp; | ||
1136 | |||
1137 | if (!kc || !kc->clock_set) | ||
1138 | return -EINVAL; | ||
1139 | |||
1140 | if (compat_get_timespec(&new_tp, tp)) | ||
1141 | return -EFAULT; | ||
1142 | |||
1143 | new_tp64 = timespec_to_timespec64(new_tp); | ||
1144 | |||
1145 | return kc->clock_set(which_clock, &new_tp64); | ||
1146 | } | ||
1147 | |||
1148 | COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock, | ||
1149 | struct compat_timespec __user *, tp) | ||
1150 | { | ||
1151 | const struct k_clock *kc = clockid_to_kclock(which_clock); | ||
1152 | struct timespec64 kernel_tp64; | ||
1153 | struct timespec kernel_tp; | ||
1154 | int error; | ||
1155 | |||
1156 | if (!kc) | ||
1157 | return -EINVAL; | ||
1158 | |||
1159 | error = kc->clock_get(which_clock, &kernel_tp64); | ||
1160 | kernel_tp = timespec64_to_timespec(kernel_tp64); | ||
1161 | |||
1162 | if (!error && compat_put_timespec(&kernel_tp, tp)) | ||
1163 | error = -EFAULT; | ||
1164 | |||
1165 | return error; | ||
1166 | } | ||
1167 | |||
1168 | COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock, | ||
1169 | struct compat_timex __user *, utp) | ||
1170 | { | ||
1171 | const struct k_clock *kc = clockid_to_kclock(which_clock); | ||
1172 | struct timex ktx; | ||
1173 | int err; | ||
1174 | |||
1175 | if (!kc) | ||
1176 | return -EINVAL; | ||
1177 | if (!kc->clock_adj) | ||
1178 | return -EOPNOTSUPP; | ||
1179 | |||
1180 | err = compat_get_timex(&ktx, utp); | ||
1181 | if (err) | ||
1182 | return err; | ||
1183 | |||
1184 | err = kc->clock_adj(which_clock, &ktx); | ||
1185 | |||
1186 | if (err >= 0) | ||
1187 | err = compat_put_timex(utp, &ktx); | ||
1188 | |||
1189 | return err; | ||
1190 | } | ||
1191 | |||
1192 | COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock, | ||
1193 | struct compat_timespec __user *, tp) | ||
1194 | { | ||
1195 | const struct k_clock *kc = clockid_to_kclock(which_clock); | ||
1196 | struct timespec64 rtn_tp64; | ||
1197 | struct timespec rtn_tp; | ||
1198 | int error; | ||
1199 | |||
1200 | if (!kc) | ||
1201 | return -EINVAL; | ||
1202 | |||
1203 | error = kc->clock_getres(which_clock, &rtn_tp64); | ||
1204 | rtn_tp = timespec64_to_timespec(rtn_tp64); | ||
1205 | |||
1206 | if (!error && tp && compat_put_timespec(&rtn_tp, tp)) | ||
1207 | error = -EFAULT; | ||
1208 | |||
1209 | return error; | ||
1210 | } | ||
1211 | #endif | ||
1212 | |||
1098 | /* | 1213 | /* |
1099 | * nanosleep for monotonic and realtime clocks | 1214 | * nanosleep for monotonic and realtime clocks |
1100 | */ | 1215 | */ |
1101 | static int common_nsleep(const clockid_t which_clock, int flags, | 1216 | static int common_nsleep(const clockid_t which_clock, int flags, |
1102 | struct timespec64 *tsave, struct timespec __user *rmtp) | 1217 | const struct timespec64 *rqtp) |
1103 | { | 1218 | { |
1104 | return hrtimer_nanosleep(tsave, rmtp, flags & TIMER_ABSTIME ? | 1219 | return hrtimer_nanosleep(rqtp, flags & TIMER_ABSTIME ? |
1105 | HRTIMER_MODE_ABS : HRTIMER_MODE_REL, | 1220 | HRTIMER_MODE_ABS : HRTIMER_MODE_REL, |
1106 | which_clock); | 1221 | which_clock); |
1107 | } | 1222 | } |
@@ -1110,7 +1225,7 @@ SYSCALL_DEFINE4(clock_nanosleep, const clockid_t, which_clock, int, flags, | |||
1110 | const struct timespec __user *, rqtp, | 1225 | const struct timespec __user *, rqtp, |
1111 | struct timespec __user *, rmtp) | 1226 | struct timespec __user *, rmtp) |
1112 | { | 1227 | { |
1113 | struct k_clock *kc = clockid_to_kclock(which_clock); | 1228 | const struct k_clock *kc = clockid_to_kclock(which_clock); |
1114 | struct timespec64 t64; | 1229 | struct timespec64 t64; |
1115 | struct timespec t; | 1230 | struct timespec t; |
1116 | 1231 | ||
@@ -1125,21 +1240,141 @@ SYSCALL_DEFINE4(clock_nanosleep, const clockid_t, which_clock, int, flags, | |||
1125 | t64 = timespec_to_timespec64(t); | 1240 | t64 = timespec_to_timespec64(t); |
1126 | if (!timespec64_valid(&t64)) | 1241 | if (!timespec64_valid(&t64)) |
1127 | return -EINVAL; | 1242 | return -EINVAL; |
1243 | if (flags & TIMER_ABSTIME) | ||
1244 | rmtp = NULL; | ||
1245 | current->restart_block.nanosleep.type = rmtp ? TT_NATIVE : TT_NONE; | ||
1246 | current->restart_block.nanosleep.rmtp = rmtp; | ||
1128 | 1247 | ||
1129 | return kc->nsleep(which_clock, flags, &t64, rmtp); | 1248 | return kc->nsleep(which_clock, flags, &t64); |
1130 | } | 1249 | } |
1131 | 1250 | ||
1132 | /* | 1251 | #ifdef CONFIG_COMPAT |
1133 | * This will restart clock_nanosleep. This is required only by | 1252 | COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags, |
1134 | * compat_clock_nanosleep_restart for now. | 1253 | struct compat_timespec __user *, rqtp, |
1135 | */ | 1254 | struct compat_timespec __user *, rmtp) |
1136 | long clock_nanosleep_restart(struct restart_block *restart_block) | ||
1137 | { | 1255 | { |
1138 | clockid_t which_clock = restart_block->nanosleep.clockid; | 1256 | const struct k_clock *kc = clockid_to_kclock(which_clock); |
1139 | struct k_clock *kc = clockid_to_kclock(which_clock); | 1257 | struct timespec64 t64; |
1258 | struct timespec t; | ||
1140 | 1259 | ||
1141 | if (WARN_ON_ONCE(!kc || !kc->nsleep_restart)) | 1260 | if (!kc) |
1142 | return -EINVAL; | 1261 | return -EINVAL; |
1262 | if (!kc->nsleep) | ||
1263 | return -ENANOSLEEP_NOTSUP; | ||
1143 | 1264 | ||
1144 | return kc->nsleep_restart(restart_block); | 1265 | if (compat_get_timespec(&t, rqtp)) |
1266 | return -EFAULT; | ||
1267 | |||
1268 | t64 = timespec_to_timespec64(t); | ||
1269 | if (!timespec64_valid(&t64)) | ||
1270 | return -EINVAL; | ||
1271 | if (flags & TIMER_ABSTIME) | ||
1272 | rmtp = NULL; | ||
1273 | current->restart_block.nanosleep.type = rmtp ? TT_COMPAT : TT_NONE; | ||
1274 | current->restart_block.nanosleep.compat_rmtp = rmtp; | ||
1275 | |||
1276 | return kc->nsleep(which_clock, flags, &t64); | ||
1277 | } | ||
1278 | #endif | ||
1279 | |||
1280 | static const struct k_clock clock_realtime = { | ||
1281 | .clock_getres = posix_get_hrtimer_res, | ||
1282 | .clock_get = posix_clock_realtime_get, | ||
1283 | .clock_set = posix_clock_realtime_set, | ||
1284 | .clock_adj = posix_clock_realtime_adj, | ||
1285 | .nsleep = common_nsleep, | ||
1286 | .timer_create = common_timer_create, | ||
1287 | .timer_set = common_timer_set, | ||
1288 | .timer_get = common_timer_get, | ||
1289 | .timer_del = common_timer_del, | ||
1290 | .timer_rearm = common_hrtimer_rearm, | ||
1291 | .timer_forward = common_hrtimer_forward, | ||
1292 | .timer_remaining = common_hrtimer_remaining, | ||
1293 | .timer_try_to_cancel = common_hrtimer_try_to_cancel, | ||
1294 | .timer_arm = common_hrtimer_arm, | ||
1295 | }; | ||
1296 | |||
1297 | static const struct k_clock clock_monotonic = { | ||
1298 | .clock_getres = posix_get_hrtimer_res, | ||
1299 | .clock_get = posix_ktime_get_ts, | ||
1300 | .nsleep = common_nsleep, | ||
1301 | .timer_create = common_timer_create, | ||
1302 | .timer_set = common_timer_set, | ||
1303 | .timer_get = common_timer_get, | ||
1304 | .timer_del = common_timer_del, | ||
1305 | .timer_rearm = common_hrtimer_rearm, | ||
1306 | .timer_forward = common_hrtimer_forward, | ||
1307 | .timer_remaining = common_hrtimer_remaining, | ||
1308 | .timer_try_to_cancel = common_hrtimer_try_to_cancel, | ||
1309 | .timer_arm = common_hrtimer_arm, | ||
1310 | }; | ||
1311 | |||
1312 | static const struct k_clock clock_monotonic_raw = { | ||
1313 | .clock_getres = posix_get_hrtimer_res, | ||
1314 | .clock_get = posix_get_monotonic_raw, | ||
1315 | }; | ||
1316 | |||
1317 | static const struct k_clock clock_realtime_coarse = { | ||
1318 | .clock_getres = posix_get_coarse_res, | ||
1319 | .clock_get = posix_get_realtime_coarse, | ||
1320 | }; | ||
1321 | |||
1322 | static const struct k_clock clock_monotonic_coarse = { | ||
1323 | .clock_getres = posix_get_coarse_res, | ||
1324 | .clock_get = posix_get_monotonic_coarse, | ||
1325 | }; | ||
1326 | |||
1327 | static const struct k_clock clock_tai = { | ||
1328 | .clock_getres = posix_get_hrtimer_res, | ||
1329 | .clock_get = posix_get_tai, | ||
1330 | .nsleep = common_nsleep, | ||
1331 | .timer_create = common_timer_create, | ||
1332 | .timer_set = common_timer_set, | ||
1333 | .timer_get = common_timer_get, | ||
1334 | .timer_del = common_timer_del, | ||
1335 | .timer_rearm = common_hrtimer_rearm, | ||
1336 | .timer_forward = common_hrtimer_forward, | ||
1337 | .timer_remaining = common_hrtimer_remaining, | ||
1338 | .timer_try_to_cancel = common_hrtimer_try_to_cancel, | ||
1339 | .timer_arm = common_hrtimer_arm, | ||
1340 | }; | ||
1341 | |||
1342 | static const struct k_clock clock_boottime = { | ||
1343 | .clock_getres = posix_get_hrtimer_res, | ||
1344 | .clock_get = posix_get_boottime, | ||
1345 | .nsleep = common_nsleep, | ||
1346 | .timer_create = common_timer_create, | ||
1347 | .timer_set = common_timer_set, | ||
1348 | .timer_get = common_timer_get, | ||
1349 | .timer_del = common_timer_del, | ||
1350 | .timer_rearm = common_hrtimer_rearm, | ||
1351 | .timer_forward = common_hrtimer_forward, | ||
1352 | .timer_remaining = common_hrtimer_remaining, | ||
1353 | .timer_try_to_cancel = common_hrtimer_try_to_cancel, | ||
1354 | .timer_arm = common_hrtimer_arm, | ||
1355 | }; | ||
1356 | |||
1357 | static const struct k_clock * const posix_clocks[] = { | ||
1358 | [CLOCK_REALTIME] = &clock_realtime, | ||
1359 | [CLOCK_MONOTONIC] = &clock_monotonic, | ||
1360 | [CLOCK_PROCESS_CPUTIME_ID] = &clock_process, | ||
1361 | [CLOCK_THREAD_CPUTIME_ID] = &clock_thread, | ||
1362 | [CLOCK_MONOTONIC_RAW] = &clock_monotonic_raw, | ||
1363 | [CLOCK_REALTIME_COARSE] = &clock_realtime_coarse, | ||
1364 | [CLOCK_MONOTONIC_COARSE] = &clock_monotonic_coarse, | ||
1365 | [CLOCK_BOOTTIME] = &clock_boottime, | ||
1366 | [CLOCK_REALTIME_ALARM] = &alarm_clock, | ||
1367 | [CLOCK_BOOTTIME_ALARM] = &alarm_clock, | ||
1368 | [CLOCK_TAI] = &clock_tai, | ||
1369 | }; | ||
1370 | |||
1371 | static const struct k_clock *clockid_to_kclock(const clockid_t id) | ||
1372 | { | ||
1373 | if (id < 0) | ||
1374 | return (id & CLOCKFD_MASK) == CLOCKFD ? | ||
1375 | &clock_posix_dynamic : &clock_posix_cpu; | ||
1376 | |||
1377 | if (id >= ARRAY_SIZE(posix_clocks) || !posix_clocks[id]) | ||
1378 | return NULL; | ||
1379 | return posix_clocks[id]; | ||
1145 | } | 1380 | } |
diff --git a/kernel/time/posix-timers.h b/kernel/time/posix-timers.h new file mode 100644 index 000000000000..fb303c3be4d3 --- /dev/null +++ b/kernel/time/posix-timers.h | |||
@@ -0,0 +1,40 @@ | |||
1 | #define TIMER_RETRY 1 | ||
2 | |||
3 | struct k_clock { | ||
4 | int (*clock_getres)(const clockid_t which_clock, | ||
5 | struct timespec64 *tp); | ||
6 | int (*clock_set)(const clockid_t which_clock, | ||
7 | const struct timespec64 *tp); | ||
8 | int (*clock_get)(const clockid_t which_clock, | ||
9 | struct timespec64 *tp); | ||
10 | int (*clock_adj)(const clockid_t which_clock, struct timex *tx); | ||
11 | int (*timer_create)(struct k_itimer *timer); | ||
12 | int (*nsleep)(const clockid_t which_clock, int flags, | ||
13 | const struct timespec64 *); | ||
14 | int (*timer_set)(struct k_itimer *timr, int flags, | ||
15 | struct itimerspec64 *new_setting, | ||
16 | struct itimerspec64 *old_setting); | ||
17 | int (*timer_del)(struct k_itimer *timr); | ||
18 | void (*timer_get)(struct k_itimer *timr, | ||
19 | struct itimerspec64 *cur_setting); | ||
20 | void (*timer_rearm)(struct k_itimer *timr); | ||
21 | int (*timer_forward)(struct k_itimer *timr, ktime_t now); | ||
22 | ktime_t (*timer_remaining)(struct k_itimer *timr, ktime_t now); | ||
23 | int (*timer_try_to_cancel)(struct k_itimer *timr); | ||
24 | void (*timer_arm)(struct k_itimer *timr, ktime_t expires, | ||
25 | bool absolute, bool sigev_none); | ||
26 | }; | ||
27 | |||
28 | extern const struct k_clock clock_posix_cpu; | ||
29 | extern const struct k_clock clock_posix_dynamic; | ||
30 | extern const struct k_clock clock_process; | ||
31 | extern const struct k_clock clock_thread; | ||
32 | extern const struct k_clock alarm_clock; | ||
33 | |||
34 | int posix_timer_event(struct k_itimer *timr, int si_private); | ||
35 | |||
36 | void common_timer_get(struct k_itimer *timr, struct itimerspec64 *cur_setting); | ||
37 | int common_timer_set(struct k_itimer *timr, int flags, | ||
38 | struct itimerspec64 *new_setting, | ||
39 | struct itimerspec64 *old_setting); | ||
40 | int common_timer_del(struct k_itimer *timer); | ||
diff --git a/kernel/time/time.c b/kernel/time/time.c index 49c73c6ed648..7c89e437c4d7 100644 --- a/kernel/time/time.c +++ b/kernel/time/time.c | |||
@@ -39,6 +39,7 @@ | |||
39 | #include <linux/ptrace.h> | 39 | #include <linux/ptrace.h> |
40 | 40 | ||
41 | #include <linux/uaccess.h> | 41 | #include <linux/uaccess.h> |
42 | #include <linux/compat.h> | ||
42 | #include <asm/unistd.h> | 43 | #include <asm/unistd.h> |
43 | 44 | ||
44 | #include <generated/timeconst.h> | 45 | #include <generated/timeconst.h> |
@@ -99,6 +100,47 @@ SYSCALL_DEFINE1(stime, time_t __user *, tptr) | |||
99 | 100 | ||
100 | #endif /* __ARCH_WANT_SYS_TIME */ | 101 | #endif /* __ARCH_WANT_SYS_TIME */ |
101 | 102 | ||
103 | #ifdef CONFIG_COMPAT | ||
104 | #ifdef __ARCH_WANT_COMPAT_SYS_TIME | ||
105 | |||
106 | /* compat_time_t is a 32 bit "long" and needs to get converted. */ | ||
107 | COMPAT_SYSCALL_DEFINE1(time, compat_time_t __user *, tloc) | ||
108 | { | ||
109 | struct timeval tv; | ||
110 | compat_time_t i; | ||
111 | |||
112 | do_gettimeofday(&tv); | ||
113 | i = tv.tv_sec; | ||
114 | |||
115 | if (tloc) { | ||
116 | if (put_user(i,tloc)) | ||
117 | return -EFAULT; | ||
118 | } | ||
119 | force_successful_syscall_return(); | ||
120 | return i; | ||
121 | } | ||
122 | |||
123 | COMPAT_SYSCALL_DEFINE1(stime, compat_time_t __user *, tptr) | ||
124 | { | ||
125 | struct timespec tv; | ||
126 | int err; | ||
127 | |||
128 | if (get_user(tv.tv_sec, tptr)) | ||
129 | return -EFAULT; | ||
130 | |||
131 | tv.tv_nsec = 0; | ||
132 | |||
133 | err = security_settime(&tv, NULL); | ||
134 | if (err) | ||
135 | return err; | ||
136 | |||
137 | do_settimeofday(&tv); | ||
138 | return 0; | ||
139 | } | ||
140 | |||
141 | #endif /* __ARCH_WANT_COMPAT_SYS_TIME */ | ||
142 | #endif | ||
143 | |||
102 | SYSCALL_DEFINE2(gettimeofday, struct timeval __user *, tv, | 144 | SYSCALL_DEFINE2(gettimeofday, struct timeval __user *, tv, |
103 | struct timezone __user *, tz) | 145 | struct timezone __user *, tz) |
104 | { | 146 | { |
@@ -215,6 +257,47 @@ SYSCALL_DEFINE2(settimeofday, struct timeval __user *, tv, | |||
215 | return do_sys_settimeofday64(tv ? &new_ts : NULL, tz ? &new_tz : NULL); | 257 | return do_sys_settimeofday64(tv ? &new_ts : NULL, tz ? &new_tz : NULL); |
216 | } | 258 | } |
217 | 259 | ||
260 | #ifdef CONFIG_COMPAT | ||
261 | COMPAT_SYSCALL_DEFINE2(gettimeofday, struct compat_timeval __user *, tv, | ||
262 | struct timezone __user *, tz) | ||
263 | { | ||
264 | if (tv) { | ||
265 | struct timeval ktv; | ||
266 | |||
267 | do_gettimeofday(&ktv); | ||
268 | if (compat_put_timeval(&ktv, tv)) | ||
269 | return -EFAULT; | ||
270 | } | ||
271 | if (tz) { | ||
272 | if (copy_to_user(tz, &sys_tz, sizeof(sys_tz))) | ||
273 | return -EFAULT; | ||
274 | } | ||
275 | |||
276 | return 0; | ||
277 | } | ||
278 | |||
279 | COMPAT_SYSCALL_DEFINE2(settimeofday, struct compat_timeval __user *, tv, | ||
280 | struct timezone __user *, tz) | ||
281 | { | ||
282 | struct timespec64 new_ts; | ||
283 | struct timeval user_tv; | ||
284 | struct timezone new_tz; | ||
285 | |||
286 | if (tv) { | ||
287 | if (compat_get_timeval(&user_tv, tv)) | ||
288 | return -EFAULT; | ||
289 | new_ts.tv_sec = user_tv.tv_sec; | ||
290 | new_ts.tv_nsec = user_tv.tv_usec * NSEC_PER_USEC; | ||
291 | } | ||
292 | if (tz) { | ||
293 | if (copy_from_user(&new_tz, tz, sizeof(*tz))) | ||
294 | return -EFAULT; | ||
295 | } | ||
296 | |||
297 | return do_sys_settimeofday64(tv ? &new_ts : NULL, tz ? &new_tz : NULL); | ||
298 | } | ||
299 | #endif | ||
300 | |||
218 | SYSCALL_DEFINE1(adjtimex, struct timex __user *, txc_p) | 301 | SYSCALL_DEFINE1(adjtimex, struct timex __user *, txc_p) |
219 | { | 302 | { |
220 | struct timex txc; /* Local copy of parameter */ | 303 | struct timex txc; /* Local copy of parameter */ |
@@ -224,12 +307,33 @@ SYSCALL_DEFINE1(adjtimex, struct timex __user *, txc_p) | |||
224 | * structure. But bear in mind that the structures | 307 | * structure. But bear in mind that the structures |
225 | * may change | 308 | * may change |
226 | */ | 309 | */ |
227 | if(copy_from_user(&txc, txc_p, sizeof(struct timex))) | 310 | if (copy_from_user(&txc, txc_p, sizeof(struct timex))) |
228 | return -EFAULT; | 311 | return -EFAULT; |
229 | ret = do_adjtimex(&txc); | 312 | ret = do_adjtimex(&txc); |
230 | return copy_to_user(txc_p, &txc, sizeof(struct timex)) ? -EFAULT : ret; | 313 | return copy_to_user(txc_p, &txc, sizeof(struct timex)) ? -EFAULT : ret; |
231 | } | 314 | } |
232 | 315 | ||
316 | #ifdef CONFIG_COMPAT | ||
317 | |||
318 | COMPAT_SYSCALL_DEFINE1(adjtimex, struct compat_timex __user *, utp) | ||
319 | { | ||
320 | struct timex txc; | ||
321 | int err, ret; | ||
322 | |||
323 | err = compat_get_timex(&txc, utp); | ||
324 | if (err) | ||
325 | return err; | ||
326 | |||
327 | ret = do_adjtimex(&txc); | ||
328 | |||
329 | err = compat_put_timex(utp, &txc); | ||
330 | if (err) | ||
331 | return err; | ||
332 | |||
333 | return ret; | ||
334 | } | ||
335 | #endif | ||
336 | |||
233 | /* | 337 | /* |
234 | * Convert jiffies to milliseconds and back. | 338 | * Convert jiffies to milliseconds and back. |
235 | * | 339 | * |
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index b602c48cb841..cedafa008de5 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c | |||
@@ -72,6 +72,10 @@ static inline void tk_normalize_xtime(struct timekeeper *tk) | |||
72 | tk->tkr_mono.xtime_nsec -= (u64)NSEC_PER_SEC << tk->tkr_mono.shift; | 72 | tk->tkr_mono.xtime_nsec -= (u64)NSEC_PER_SEC << tk->tkr_mono.shift; |
73 | tk->xtime_sec++; | 73 | tk->xtime_sec++; |
74 | } | 74 | } |
75 | while (tk->tkr_raw.xtime_nsec >= ((u64)NSEC_PER_SEC << tk->tkr_raw.shift)) { | ||
76 | tk->tkr_raw.xtime_nsec -= (u64)NSEC_PER_SEC << tk->tkr_raw.shift; | ||
77 | tk->raw_sec++; | ||
78 | } | ||
75 | } | 79 | } |
76 | 80 | ||
77 | static inline struct timespec64 tk_xtime(struct timekeeper *tk) | 81 | static inline struct timespec64 tk_xtime(struct timekeeper *tk) |
@@ -285,12 +289,14 @@ static void tk_setup_internals(struct timekeeper *tk, struct clocksource *clock) | |||
285 | /* if changing clocks, convert xtime_nsec shift units */ | 289 | /* if changing clocks, convert xtime_nsec shift units */ |
286 | if (old_clock) { | 290 | if (old_clock) { |
287 | int shift_change = clock->shift - old_clock->shift; | 291 | int shift_change = clock->shift - old_clock->shift; |
288 | if (shift_change < 0) | 292 | if (shift_change < 0) { |
289 | tk->tkr_mono.xtime_nsec >>= -shift_change; | 293 | tk->tkr_mono.xtime_nsec >>= -shift_change; |
290 | else | 294 | tk->tkr_raw.xtime_nsec >>= -shift_change; |
295 | } else { | ||
291 | tk->tkr_mono.xtime_nsec <<= shift_change; | 296 | tk->tkr_mono.xtime_nsec <<= shift_change; |
297 | tk->tkr_raw.xtime_nsec <<= shift_change; | ||
298 | } | ||
292 | } | 299 | } |
293 | tk->tkr_raw.xtime_nsec = 0; | ||
294 | 300 | ||
295 | tk->tkr_mono.shift = clock->shift; | 301 | tk->tkr_mono.shift = clock->shift; |
296 | tk->tkr_raw.shift = clock->shift; | 302 | tk->tkr_raw.shift = clock->shift; |
@@ -510,6 +516,7 @@ static void halt_fast_timekeeper(struct timekeeper *tk) | |||
510 | } | 516 | } |
511 | 517 | ||
512 | #ifdef CONFIG_GENERIC_TIME_VSYSCALL_OLD | 518 | #ifdef CONFIG_GENERIC_TIME_VSYSCALL_OLD |
519 | #warning Please contact your maintainers, as GENERIC_TIME_VSYSCALL_OLD compatibity will disappear soon. | ||
513 | 520 | ||
514 | static inline void update_vsyscall(struct timekeeper *tk) | 521 | static inline void update_vsyscall(struct timekeeper *tk) |
515 | { | 522 | { |
@@ -619,9 +626,6 @@ static inline void tk_update_ktime_data(struct timekeeper *tk) | |||
619 | nsec = (u32) tk->wall_to_monotonic.tv_nsec; | 626 | nsec = (u32) tk->wall_to_monotonic.tv_nsec; |
620 | tk->tkr_mono.base = ns_to_ktime(seconds * NSEC_PER_SEC + nsec); | 627 | tk->tkr_mono.base = ns_to_ktime(seconds * NSEC_PER_SEC + nsec); |
621 | 628 | ||
622 | /* Update the monotonic raw base */ | ||
623 | tk->tkr_raw.base = timespec64_to_ktime(tk->raw_time); | ||
624 | |||
625 | /* | 629 | /* |
626 | * The sum of the nanoseconds portions of xtime and | 630 | * The sum of the nanoseconds portions of xtime and |
627 | * wall_to_monotonic can be greater/equal one second. Take | 631 | * wall_to_monotonic can be greater/equal one second. Take |
@@ -631,6 +635,11 @@ static inline void tk_update_ktime_data(struct timekeeper *tk) | |||
631 | if (nsec >= NSEC_PER_SEC) | 635 | if (nsec >= NSEC_PER_SEC) |
632 | seconds++; | 636 | seconds++; |
633 | tk->ktime_sec = seconds; | 637 | tk->ktime_sec = seconds; |
638 | |||
639 | /* Update the monotonic raw base */ | ||
640 | seconds = tk->raw_sec; | ||
641 | nsec = (u32)(tk->tkr_raw.xtime_nsec >> tk->tkr_raw.shift); | ||
642 | tk->tkr_raw.base = ns_to_ktime(seconds * NSEC_PER_SEC + nsec); | ||
634 | } | 643 | } |
635 | 644 | ||
636 | /* must hold timekeeper_lock */ | 645 | /* must hold timekeeper_lock */ |
@@ -672,7 +681,6 @@ static void timekeeping_update(struct timekeeper *tk, unsigned int action) | |||
672 | static void timekeeping_forward_now(struct timekeeper *tk) | 681 | static void timekeeping_forward_now(struct timekeeper *tk) |
673 | { | 682 | { |
674 | u64 cycle_now, delta; | 683 | u64 cycle_now, delta; |
675 | u64 nsec; | ||
676 | 684 | ||
677 | cycle_now = tk_clock_read(&tk->tkr_mono); | 685 | cycle_now = tk_clock_read(&tk->tkr_mono); |
678 | delta = clocksource_delta(cycle_now, tk->tkr_mono.cycle_last, tk->tkr_mono.mask); | 686 | delta = clocksource_delta(cycle_now, tk->tkr_mono.cycle_last, tk->tkr_mono.mask); |
@@ -684,10 +692,13 @@ static void timekeeping_forward_now(struct timekeeper *tk) | |||
684 | /* If arch requires, add in get_arch_timeoffset() */ | 692 | /* If arch requires, add in get_arch_timeoffset() */ |
685 | tk->tkr_mono.xtime_nsec += (u64)arch_gettimeoffset() << tk->tkr_mono.shift; | 693 | tk->tkr_mono.xtime_nsec += (u64)arch_gettimeoffset() << tk->tkr_mono.shift; |
686 | 694 | ||
687 | tk_normalize_xtime(tk); | ||
688 | 695 | ||
689 | nsec = clocksource_cyc2ns(delta, tk->tkr_raw.mult, tk->tkr_raw.shift); | 696 | tk->tkr_raw.xtime_nsec += delta * tk->tkr_raw.mult; |
690 | timespec64_add_ns(&tk->raw_time, nsec); | 697 | |
698 | /* If arch requires, add in get_arch_timeoffset() */ | ||
699 | tk->tkr_raw.xtime_nsec += (u64)arch_gettimeoffset() << tk->tkr_raw.shift; | ||
700 | |||
701 | tk_normalize_xtime(tk); | ||
691 | } | 702 | } |
692 | 703 | ||
693 | /** | 704 | /** |
@@ -1373,19 +1384,18 @@ int timekeeping_notify(struct clocksource *clock) | |||
1373 | void getrawmonotonic64(struct timespec64 *ts) | 1384 | void getrawmonotonic64(struct timespec64 *ts) |
1374 | { | 1385 | { |
1375 | struct timekeeper *tk = &tk_core.timekeeper; | 1386 | struct timekeeper *tk = &tk_core.timekeeper; |
1376 | struct timespec64 ts64; | ||
1377 | unsigned long seq; | 1387 | unsigned long seq; |
1378 | u64 nsecs; | 1388 | u64 nsecs; |
1379 | 1389 | ||
1380 | do { | 1390 | do { |
1381 | seq = read_seqcount_begin(&tk_core.seq); | 1391 | seq = read_seqcount_begin(&tk_core.seq); |
1392 | ts->tv_sec = tk->raw_sec; | ||
1382 | nsecs = timekeeping_get_ns(&tk->tkr_raw); | 1393 | nsecs = timekeeping_get_ns(&tk->tkr_raw); |
1383 | ts64 = tk->raw_time; | ||
1384 | 1394 | ||
1385 | } while (read_seqcount_retry(&tk_core.seq, seq)); | 1395 | } while (read_seqcount_retry(&tk_core.seq, seq)); |
1386 | 1396 | ||
1387 | timespec64_add_ns(&ts64, nsecs); | 1397 | ts->tv_nsec = 0; |
1388 | *ts = ts64; | 1398 | timespec64_add_ns(ts, nsecs); |
1389 | } | 1399 | } |
1390 | EXPORT_SYMBOL(getrawmonotonic64); | 1400 | EXPORT_SYMBOL(getrawmonotonic64); |
1391 | 1401 | ||
@@ -1509,8 +1519,7 @@ void __init timekeeping_init(void) | |||
1509 | tk_setup_internals(tk, clock); | 1519 | tk_setup_internals(tk, clock); |
1510 | 1520 | ||
1511 | tk_set_xtime(tk, &now); | 1521 | tk_set_xtime(tk, &now); |
1512 | tk->raw_time.tv_sec = 0; | 1522 | tk->raw_sec = 0; |
1513 | tk->raw_time.tv_nsec = 0; | ||
1514 | if (boot.tv_sec == 0 && boot.tv_nsec == 0) | 1523 | if (boot.tv_sec == 0 && boot.tv_nsec == 0) |
1515 | boot = tk_xtime(tk); | 1524 | boot = tk_xtime(tk); |
1516 | 1525 | ||
@@ -2011,15 +2020,12 @@ static u64 logarithmic_accumulation(struct timekeeper *tk, u64 offset, | |||
2011 | *clock_set |= accumulate_nsecs_to_secs(tk); | 2020 | *clock_set |= accumulate_nsecs_to_secs(tk); |
2012 | 2021 | ||
2013 | /* Accumulate raw time */ | 2022 | /* Accumulate raw time */ |
2014 | tk->tkr_raw.xtime_nsec += (u64)tk->raw_time.tv_nsec << tk->tkr_raw.shift; | ||
2015 | tk->tkr_raw.xtime_nsec += tk->raw_interval << shift; | 2023 | tk->tkr_raw.xtime_nsec += tk->raw_interval << shift; |
2016 | snsec_per_sec = (u64)NSEC_PER_SEC << tk->tkr_raw.shift; | 2024 | snsec_per_sec = (u64)NSEC_PER_SEC << tk->tkr_raw.shift; |
2017 | while (tk->tkr_raw.xtime_nsec >= snsec_per_sec) { | 2025 | while (tk->tkr_raw.xtime_nsec >= snsec_per_sec) { |
2018 | tk->tkr_raw.xtime_nsec -= snsec_per_sec; | 2026 | tk->tkr_raw.xtime_nsec -= snsec_per_sec; |
2019 | tk->raw_time.tv_sec++; | 2027 | tk->raw_sec++; |
2020 | } | 2028 | } |
2021 | tk->raw_time.tv_nsec = tk->tkr_raw.xtime_nsec >> tk->tkr_raw.shift; | ||
2022 | tk->tkr_raw.xtime_nsec -= (u64)tk->raw_time.tv_nsec << tk->tkr_raw.shift; | ||
2023 | 2029 | ||
2024 | /* Accumulate error between NTP and clock interval */ | 2030 | /* Accumulate error between NTP and clock interval */ |
2025 | tk->ntp_error += tk->ntp_tick << shift; | 2031 | tk->ntp_error += tk->ntp_tick << shift; |
diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 152a706ef8b8..71ce3f4eead3 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c | |||
@@ -195,7 +195,7 @@ EXPORT_SYMBOL(jiffies_64); | |||
195 | #endif | 195 | #endif |
196 | 196 | ||
197 | struct timer_base { | 197 | struct timer_base { |
198 | spinlock_t lock; | 198 | raw_spinlock_t lock; |
199 | struct timer_list *running_timer; | 199 | struct timer_list *running_timer; |
200 | unsigned long clk; | 200 | unsigned long clk; |
201 | unsigned long next_expiry; | 201 | unsigned long next_expiry; |
@@ -913,10 +913,10 @@ static struct timer_base *lock_timer_base(struct timer_list *timer, | |||
913 | 913 | ||
914 | if (!(tf & TIMER_MIGRATING)) { | 914 | if (!(tf & TIMER_MIGRATING)) { |
915 | base = get_timer_base(tf); | 915 | base = get_timer_base(tf); |
916 | spin_lock_irqsave(&base->lock, *flags); | 916 | raw_spin_lock_irqsave(&base->lock, *flags); |
917 | if (timer->flags == tf) | 917 | if (timer->flags == tf) |
918 | return base; | 918 | return base; |
919 | spin_unlock_irqrestore(&base->lock, *flags); | 919 | raw_spin_unlock_irqrestore(&base->lock, *flags); |
920 | } | 920 | } |
921 | cpu_relax(); | 921 | cpu_relax(); |
922 | } | 922 | } |
@@ -986,9 +986,9 @@ __mod_timer(struct timer_list *timer, unsigned long expires, bool pending_only) | |||
986 | /* See the comment in lock_timer_base() */ | 986 | /* See the comment in lock_timer_base() */ |
987 | timer->flags |= TIMER_MIGRATING; | 987 | timer->flags |= TIMER_MIGRATING; |
988 | 988 | ||
989 | spin_unlock(&base->lock); | 989 | raw_spin_unlock(&base->lock); |
990 | base = new_base; | 990 | base = new_base; |
991 | spin_lock(&base->lock); | 991 | raw_spin_lock(&base->lock); |
992 | WRITE_ONCE(timer->flags, | 992 | WRITE_ONCE(timer->flags, |
993 | (timer->flags & ~TIMER_BASEMASK) | base->cpu); | 993 | (timer->flags & ~TIMER_BASEMASK) | base->cpu); |
994 | } | 994 | } |
@@ -1013,7 +1013,7 @@ __mod_timer(struct timer_list *timer, unsigned long expires, bool pending_only) | |||
1013 | } | 1013 | } |
1014 | 1014 | ||
1015 | out_unlock: | 1015 | out_unlock: |
1016 | spin_unlock_irqrestore(&base->lock, flags); | 1016 | raw_spin_unlock_irqrestore(&base->lock, flags); |
1017 | 1017 | ||
1018 | return ret; | 1018 | return ret; |
1019 | } | 1019 | } |
@@ -1106,16 +1106,16 @@ void add_timer_on(struct timer_list *timer, int cpu) | |||
1106 | if (base != new_base) { | 1106 | if (base != new_base) { |
1107 | timer->flags |= TIMER_MIGRATING; | 1107 | timer->flags |= TIMER_MIGRATING; |
1108 | 1108 | ||
1109 | spin_unlock(&base->lock); | 1109 | raw_spin_unlock(&base->lock); |
1110 | base = new_base; | 1110 | base = new_base; |
1111 | spin_lock(&base->lock); | 1111 | raw_spin_lock(&base->lock); |
1112 | WRITE_ONCE(timer->flags, | 1112 | WRITE_ONCE(timer->flags, |
1113 | (timer->flags & ~TIMER_BASEMASK) | cpu); | 1113 | (timer->flags & ~TIMER_BASEMASK) | cpu); |
1114 | } | 1114 | } |
1115 | 1115 | ||
1116 | debug_activate(timer, timer->expires); | 1116 | debug_activate(timer, timer->expires); |
1117 | internal_add_timer(base, timer); | 1117 | internal_add_timer(base, timer); |
1118 | spin_unlock_irqrestore(&base->lock, flags); | 1118 | raw_spin_unlock_irqrestore(&base->lock, flags); |
1119 | } | 1119 | } |
1120 | EXPORT_SYMBOL_GPL(add_timer_on); | 1120 | EXPORT_SYMBOL_GPL(add_timer_on); |
1121 | 1121 | ||
@@ -1141,7 +1141,7 @@ int del_timer(struct timer_list *timer) | |||
1141 | if (timer_pending(timer)) { | 1141 | if (timer_pending(timer)) { |
1142 | base = lock_timer_base(timer, &flags); | 1142 | base = lock_timer_base(timer, &flags); |
1143 | ret = detach_if_pending(timer, base, true); | 1143 | ret = detach_if_pending(timer, base, true); |
1144 | spin_unlock_irqrestore(&base->lock, flags); | 1144 | raw_spin_unlock_irqrestore(&base->lock, flags); |
1145 | } | 1145 | } |
1146 | 1146 | ||
1147 | return ret; | 1147 | return ret; |
@@ -1150,7 +1150,7 @@ EXPORT_SYMBOL(del_timer); | |||
1150 | 1150 | ||
1151 | /** | 1151 | /** |
1152 | * try_to_del_timer_sync - Try to deactivate a timer | 1152 | * try_to_del_timer_sync - Try to deactivate a timer |
1153 | * @timer: timer do del | 1153 | * @timer: timer to delete |
1154 | * | 1154 | * |
1155 | * This function tries to deactivate a timer. Upon successful (ret >= 0) | 1155 | * This function tries to deactivate a timer. Upon successful (ret >= 0) |
1156 | * exit the timer is not queued and the handler is not running on any CPU. | 1156 | * exit the timer is not queued and the handler is not running on any CPU. |
@@ -1168,7 +1168,7 @@ int try_to_del_timer_sync(struct timer_list *timer) | |||
1168 | if (base->running_timer != timer) | 1168 | if (base->running_timer != timer) |
1169 | ret = detach_if_pending(timer, base, true); | 1169 | ret = detach_if_pending(timer, base, true); |
1170 | 1170 | ||
1171 | spin_unlock_irqrestore(&base->lock, flags); | 1171 | raw_spin_unlock_irqrestore(&base->lock, flags); |
1172 | 1172 | ||
1173 | return ret; | 1173 | return ret; |
1174 | } | 1174 | } |
@@ -1299,13 +1299,13 @@ static void expire_timers(struct timer_base *base, struct hlist_head *head) | |||
1299 | data = timer->data; | 1299 | data = timer->data; |
1300 | 1300 | ||
1301 | if (timer->flags & TIMER_IRQSAFE) { | 1301 | if (timer->flags & TIMER_IRQSAFE) { |
1302 | spin_unlock(&base->lock); | 1302 | raw_spin_unlock(&base->lock); |
1303 | call_timer_fn(timer, fn, data); | 1303 | call_timer_fn(timer, fn, data); |
1304 | spin_lock(&base->lock); | 1304 | raw_spin_lock(&base->lock); |
1305 | } else { | 1305 | } else { |
1306 | spin_unlock_irq(&base->lock); | 1306 | raw_spin_unlock_irq(&base->lock); |
1307 | call_timer_fn(timer, fn, data); | 1307 | call_timer_fn(timer, fn, data); |
1308 | spin_lock_irq(&base->lock); | 1308 | raw_spin_lock_irq(&base->lock); |
1309 | } | 1309 | } |
1310 | } | 1310 | } |
1311 | } | 1311 | } |
@@ -1474,7 +1474,7 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem) | |||
1474 | if (cpu_is_offline(smp_processor_id())) | 1474 | if (cpu_is_offline(smp_processor_id())) |
1475 | return expires; | 1475 | return expires; |
1476 | 1476 | ||
1477 | spin_lock(&base->lock); | 1477 | raw_spin_lock(&base->lock); |
1478 | nextevt = __next_timer_interrupt(base); | 1478 | nextevt = __next_timer_interrupt(base); |
1479 | is_max_delta = (nextevt == base->clk + NEXT_TIMER_MAX_DELTA); | 1479 | is_max_delta = (nextevt == base->clk + NEXT_TIMER_MAX_DELTA); |
1480 | base->next_expiry = nextevt; | 1480 | base->next_expiry = nextevt; |
@@ -1502,7 +1502,7 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem) | |||
1502 | if ((expires - basem) > TICK_NSEC) | 1502 | if ((expires - basem) > TICK_NSEC) |
1503 | base->is_idle = true; | 1503 | base->is_idle = true; |
1504 | } | 1504 | } |
1505 | spin_unlock(&base->lock); | 1505 | raw_spin_unlock(&base->lock); |
1506 | 1506 | ||
1507 | return cmp_next_hrtimer_event(basem, expires); | 1507 | return cmp_next_hrtimer_event(basem, expires); |
1508 | } | 1508 | } |
@@ -1590,7 +1590,7 @@ static inline void __run_timers(struct timer_base *base) | |||
1590 | if (!time_after_eq(jiffies, base->clk)) | 1590 | if (!time_after_eq(jiffies, base->clk)) |
1591 | return; | 1591 | return; |
1592 | 1592 | ||
1593 | spin_lock_irq(&base->lock); | 1593 | raw_spin_lock_irq(&base->lock); |
1594 | 1594 | ||
1595 | while (time_after_eq(jiffies, base->clk)) { | 1595 | while (time_after_eq(jiffies, base->clk)) { |
1596 | 1596 | ||
@@ -1601,7 +1601,7 @@ static inline void __run_timers(struct timer_base *base) | |||
1601 | expire_timers(base, heads + levels); | 1601 | expire_timers(base, heads + levels); |
1602 | } | 1602 | } |
1603 | base->running_timer = NULL; | 1603 | base->running_timer = NULL; |
1604 | spin_unlock_irq(&base->lock); | 1604 | raw_spin_unlock_irq(&base->lock); |
1605 | } | 1605 | } |
1606 | 1606 | ||
1607 | /* | 1607 | /* |
@@ -1786,16 +1786,16 @@ int timers_dead_cpu(unsigned int cpu) | |||
1786 | * The caller is globally serialized and nobody else | 1786 | * The caller is globally serialized and nobody else |
1787 | * takes two locks at once, deadlock is not possible. | 1787 | * takes two locks at once, deadlock is not possible. |
1788 | */ | 1788 | */ |
1789 | spin_lock_irq(&new_base->lock); | 1789 | raw_spin_lock_irq(&new_base->lock); |
1790 | spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING); | 1790 | raw_spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING); |
1791 | 1791 | ||
1792 | BUG_ON(old_base->running_timer); | 1792 | BUG_ON(old_base->running_timer); |
1793 | 1793 | ||
1794 | for (i = 0; i < WHEEL_SIZE; i++) | 1794 | for (i = 0; i < WHEEL_SIZE; i++) |
1795 | migrate_timer_list(new_base, old_base->vectors + i); | 1795 | migrate_timer_list(new_base, old_base->vectors + i); |
1796 | 1796 | ||
1797 | spin_unlock(&old_base->lock); | 1797 | raw_spin_unlock(&old_base->lock); |
1798 | spin_unlock_irq(&new_base->lock); | 1798 | raw_spin_unlock_irq(&new_base->lock); |
1799 | put_cpu_ptr(&timer_bases); | 1799 | put_cpu_ptr(&timer_bases); |
1800 | } | 1800 | } |
1801 | return 0; | 1801 | return 0; |
@@ -1811,7 +1811,7 @@ static void __init init_timer_cpu(int cpu) | |||
1811 | for (i = 0; i < NR_BASES; i++) { | 1811 | for (i = 0; i < NR_BASES; i++) { |
1812 | base = per_cpu_ptr(&timer_bases[i], cpu); | 1812 | base = per_cpu_ptr(&timer_bases[i], cpu); |
1813 | base->cpu = cpu; | 1813 | base->cpu = cpu; |
1814 | spin_lock_init(&base->lock); | 1814 | raw_spin_lock_init(&base->lock); |
1815 | base->clk = jiffies; | 1815 | base->clk = jiffies; |
1816 | } | 1816 | } |
1817 | } | 1817 | } |
diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile index 5fa1d7e9a915..5801bbefbe89 100644 --- a/tools/testing/selftests/timers/Makefile +++ b/tools/testing/selftests/timers/Makefile | |||
@@ -1,6 +1,6 @@ | |||
1 | BUILD_FLAGS = -DKTEST | 1 | BUILD_FLAGS = -DKTEST |
2 | CFLAGS += -O3 -Wl,-no-as-needed -Wall $(BUILD_FLAGS) | 2 | CFLAGS += -O3 -Wl,-no-as-needed -Wall $(BUILD_FLAGS) |
3 | LDFLAGS += -lrt -lpthread | 3 | LDFLAGS += -lrt -lpthread -lm |
4 | 4 | ||
5 | # these are all "safe" tests that don't modify | 5 | # these are all "safe" tests that don't modify |
6 | # system time or require escalated privileges | 6 | # system time or require escalated privileges |
@@ -8,7 +8,7 @@ TEST_GEN_PROGS = posix_timers nanosleep nsleep-lat set-timer-lat mqueue-lat \ | |||
8 | inconsistency-check raw_skew threadtest rtctest | 8 | inconsistency-check raw_skew threadtest rtctest |
9 | 9 | ||
10 | TEST_GEN_PROGS_EXTENDED = alarmtimer-suspend valid-adjtimex adjtick change_skew \ | 10 | TEST_GEN_PROGS_EXTENDED = alarmtimer-suspend valid-adjtimex adjtick change_skew \ |
11 | skew_consistency clocksource-switch leap-a-day \ | 11 | skew_consistency clocksource-switch freq-step leap-a-day \ |
12 | leapcrash set-tai set-2038 set-tz | 12 | leapcrash set-tai set-2038 set-tz |
13 | 13 | ||
14 | 14 | ||
@@ -24,6 +24,7 @@ run_destructive_tests: run_tests | |||
24 | ./change_skew | 24 | ./change_skew |
25 | ./skew_consistency | 25 | ./skew_consistency |
26 | ./clocksource-switch | 26 | ./clocksource-switch |
27 | ./freq-step | ||
27 | ./leap-a-day -s -i 10 | 28 | ./leap-a-day -s -i 10 |
28 | ./leapcrash | 29 | ./leapcrash |
29 | ./set-tz | 30 | ./set-tz |
diff --git a/tools/testing/selftests/timers/freq-step.c b/tools/testing/selftests/timers/freq-step.c new file mode 100644 index 000000000000..e8c61830825a --- /dev/null +++ b/tools/testing/selftests/timers/freq-step.c | |||
@@ -0,0 +1,268 @@ | |||
1 | /* | ||
2 | * This test checks the response of the system clock to frequency | ||
3 | * steps made with adjtimex(). The frequency error and stability of | ||
4 | * the CLOCK_MONOTONIC clock relative to the CLOCK_MONOTONIC_RAW clock | ||
5 | * is measured in two intervals following the step. The test fails if | ||
6 | * values from the second interval exceed specified limits. | ||
7 | * | ||
8 | * Copyright (C) Miroslav Lichvar <mlichvar@redhat.com> 2017 | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of version 2 of the GNU General Public License as | ||
12 | * published by the Free Software Foundation. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, but | ||
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | * General Public License for more details. | ||
18 | */ | ||
19 | |||
20 | #include <math.h> | ||
21 | #include <stdio.h> | ||
22 | #include <sys/timex.h> | ||
23 | #include <time.h> | ||
24 | #include <unistd.h> | ||
25 | |||
26 | #include "../kselftest.h" | ||
27 | |||
28 | #define SAMPLES 100 | ||
29 | #define SAMPLE_READINGS 10 | ||
30 | #define MEAN_SAMPLE_INTERVAL 0.1 | ||
31 | #define STEP_INTERVAL 1.0 | ||
32 | #define MAX_PRECISION 100e-9 | ||
33 | #define MAX_FREQ_ERROR 10e-6 | ||
34 | #define MAX_STDDEV 1000e-9 | ||
35 | |||
36 | struct sample { | ||
37 | double offset; | ||
38 | double time; | ||
39 | }; | ||
40 | |||
41 | static time_t mono_raw_base; | ||
42 | static time_t mono_base; | ||
43 | static long user_hz; | ||
44 | static double precision; | ||
45 | static double mono_freq_offset; | ||
46 | |||
47 | static double diff_timespec(struct timespec *ts1, struct timespec *ts2) | ||
48 | { | ||
49 | return ts1->tv_sec - ts2->tv_sec + (ts1->tv_nsec - ts2->tv_nsec) / 1e9; | ||
50 | } | ||
51 | |||
52 | static double get_sample(struct sample *sample) | ||
53 | { | ||
54 | double delay, mindelay = 0.0; | ||
55 | struct timespec ts1, ts2, ts3; | ||
56 | int i; | ||
57 | |||
58 | for (i = 0; i < SAMPLE_READINGS; i++) { | ||
59 | clock_gettime(CLOCK_MONOTONIC_RAW, &ts1); | ||
60 | clock_gettime(CLOCK_MONOTONIC, &ts2); | ||
61 | clock_gettime(CLOCK_MONOTONIC_RAW, &ts3); | ||
62 | |||
63 | ts1.tv_sec -= mono_raw_base; | ||
64 | ts2.tv_sec -= mono_base; | ||
65 | ts3.tv_sec -= mono_raw_base; | ||
66 | |||
67 | delay = diff_timespec(&ts3, &ts1); | ||
68 | if (delay <= 1e-9) { | ||
69 | i--; | ||
70 | continue; | ||
71 | } | ||
72 | |||
73 | if (!i || delay < mindelay) { | ||
74 | sample->offset = diff_timespec(&ts2, &ts1); | ||
75 | sample->offset -= delay / 2.0; | ||
76 | sample->time = ts1.tv_sec + ts1.tv_nsec / 1e9; | ||
77 | mindelay = delay; | ||
78 | } | ||
79 | } | ||
80 | |||
81 | return mindelay; | ||
82 | } | ||
83 | |||
84 | static void reset_ntp_error(void) | ||
85 | { | ||
86 | struct timex txc; | ||
87 | |||
88 | txc.modes = ADJ_SETOFFSET; | ||
89 | txc.time.tv_sec = 0; | ||
90 | txc.time.tv_usec = 0; | ||
91 | |||
92 | if (adjtimex(&txc) < 0) { | ||
93 | perror("[FAIL] adjtimex"); | ||
94 | ksft_exit_fail(); | ||
95 | } | ||
96 | } | ||
97 | |||
98 | static void set_frequency(double freq) | ||
99 | { | ||
100 | struct timex txc; | ||
101 | int tick_offset; | ||
102 | |||
103 | tick_offset = 1e6 * freq / user_hz; | ||
104 | |||
105 | txc.modes = ADJ_TICK | ADJ_FREQUENCY; | ||
106 | txc.tick = 1000000 / user_hz + tick_offset; | ||
107 | txc.freq = (1e6 * freq - user_hz * tick_offset) * (1 << 16); | ||
108 | |||
109 | if (adjtimex(&txc) < 0) { | ||
110 | perror("[FAIL] adjtimex"); | ||
111 | ksft_exit_fail(); | ||
112 | } | ||
113 | } | ||
114 | |||
115 | static void regress(struct sample *samples, int n, double *intercept, | ||
116 | double *slope, double *r_stddev, double *r_max) | ||
117 | { | ||
118 | double x, y, r, x_sum, y_sum, xy_sum, x2_sum, r2_sum; | ||
119 | int i; | ||
120 | |||
121 | x_sum = 0.0, y_sum = 0.0, xy_sum = 0.0, x2_sum = 0.0; | ||
122 | |||
123 | for (i = 0; i < n; i++) { | ||
124 | x = samples[i].time; | ||
125 | y = samples[i].offset; | ||
126 | |||
127 | x_sum += x; | ||
128 | y_sum += y; | ||
129 | xy_sum += x * y; | ||
130 | x2_sum += x * x; | ||
131 | } | ||
132 | |||
133 | *slope = (xy_sum - x_sum * y_sum / n) / (x2_sum - x_sum * x_sum / n); | ||
134 | *intercept = (y_sum - *slope * x_sum) / n; | ||
135 | |||
136 | *r_max = 0.0, r2_sum = 0.0; | ||
137 | |||
138 | for (i = 0; i < n; i++) { | ||
139 | x = samples[i].time; | ||
140 | y = samples[i].offset; | ||
141 | r = fabs(x * *slope + *intercept - y); | ||
142 | if (*r_max < r) | ||
143 | *r_max = r; | ||
144 | r2_sum += r * r; | ||
145 | } | ||
146 | |||
147 | *r_stddev = sqrt(r2_sum / n); | ||
148 | } | ||
149 | |||
150 | static int run_test(int calibration, double freq_base, double freq_step) | ||
151 | { | ||
152 | struct sample samples[SAMPLES]; | ||
153 | double intercept, slope, stddev1, max1, stddev2, max2; | ||
154 | double freq_error1, freq_error2; | ||
155 | int i; | ||
156 | |||
157 | set_frequency(freq_base); | ||
158 | |||
159 | for (i = 0; i < 10; i++) | ||
160 | usleep(1e6 * MEAN_SAMPLE_INTERVAL / 10); | ||
161 | |||
162 | reset_ntp_error(); | ||
163 | |||
164 | set_frequency(freq_base + freq_step); | ||
165 | |||
166 | for (i = 0; i < 10; i++) | ||
167 | usleep(rand() % 2000000 * STEP_INTERVAL / 10); | ||
168 | |||
169 | set_frequency(freq_base); | ||
170 | |||
171 | for (i = 0; i < SAMPLES; i++) { | ||
172 | usleep(rand() % 2000000 * MEAN_SAMPLE_INTERVAL); | ||
173 | get_sample(&samples[i]); | ||
174 | } | ||
175 | |||
176 | if (calibration) { | ||
177 | regress(samples, SAMPLES, &intercept, &slope, &stddev1, &max1); | ||
178 | mono_freq_offset = slope; | ||
179 | printf("CLOCK_MONOTONIC_RAW frequency offset: %11.3f ppm\n", | ||
180 | 1e6 * mono_freq_offset); | ||
181 | return 0; | ||
182 | } | ||
183 | |||
184 | regress(samples, SAMPLES / 2, &intercept, &slope, &stddev1, &max1); | ||
185 | freq_error1 = slope * (1.0 - mono_freq_offset) - mono_freq_offset - | ||
186 | freq_base; | ||
187 | |||
188 | regress(samples + SAMPLES / 2, SAMPLES / 2, &intercept, &slope, | ||
189 | &stddev2, &max2); | ||
190 | freq_error2 = slope * (1.0 - mono_freq_offset) - mono_freq_offset - | ||
191 | freq_base; | ||
192 | |||
193 | printf("%6.0f %+10.3f %6.0f %7.0f %+10.3f %6.0f %7.0f\t", | ||
194 | 1e6 * freq_step, | ||
195 | 1e6 * freq_error1, 1e9 * stddev1, 1e9 * max1, | ||
196 | 1e6 * freq_error2, 1e9 * stddev2, 1e9 * max2); | ||
197 | |||
198 | if (fabs(freq_error2) > MAX_FREQ_ERROR || stddev2 > MAX_STDDEV) { | ||
199 | printf("[FAIL]\n"); | ||
200 | return 1; | ||
201 | } | ||
202 | |||
203 | printf("[OK]\n"); | ||
204 | return 0; | ||
205 | } | ||
206 | |||
207 | static void init_test(void) | ||
208 | { | ||
209 | struct timespec ts; | ||
210 | struct sample sample; | ||
211 | |||
212 | if (clock_gettime(CLOCK_MONOTONIC_RAW, &ts)) { | ||
213 | perror("[FAIL] clock_gettime(CLOCK_MONOTONIC_RAW)"); | ||
214 | ksft_exit_fail(); | ||
215 | } | ||
216 | |||
217 | mono_raw_base = ts.tv_sec; | ||
218 | |||
219 | if (clock_gettime(CLOCK_MONOTONIC, &ts)) { | ||
220 | perror("[FAIL] clock_gettime(CLOCK_MONOTONIC)"); | ||
221 | ksft_exit_fail(); | ||
222 | } | ||
223 | |||
224 | mono_base = ts.tv_sec; | ||
225 | |||
226 | user_hz = sysconf(_SC_CLK_TCK); | ||
227 | |||
228 | precision = get_sample(&sample) / 2.0; | ||
229 | printf("CLOCK_MONOTONIC_RAW+CLOCK_MONOTONIC precision: %.0f ns\t\t", | ||
230 | 1e9 * precision); | ||
231 | |||
232 | if (precision > MAX_PRECISION) { | ||
233 | printf("[SKIP]\n"); | ||
234 | ksft_exit_skip(); | ||
235 | } | ||
236 | |||
237 | printf("[OK]\n"); | ||
238 | srand(ts.tv_sec ^ ts.tv_nsec); | ||
239 | |||
240 | run_test(1, 0.0, 0.0); | ||
241 | } | ||
242 | |||
243 | int main(int argc, char **argv) | ||
244 | { | ||
245 | double freq_base, freq_step; | ||
246 | int i, j, fails = 0; | ||
247 | |||
248 | init_test(); | ||
249 | |||
250 | printf("Checking response to frequency step:\n"); | ||
251 | printf(" Step 1st interval 2nd interval\n"); | ||
252 | printf(" Freq Dev Max Freq Dev Max\n"); | ||
253 | |||
254 | for (i = 2; i >= 0; i--) { | ||
255 | for (j = 0; j < 5; j++) { | ||
256 | freq_base = (rand() % (1 << 24) - (1 << 23)) / 65536e6; | ||
257 | freq_step = 10e-6 * (1 << (6 * i)); | ||
258 | fails += run_test(0, freq_base, freq_step); | ||
259 | } | ||
260 | } | ||
261 | |||
262 | set_frequency(0.0); | ||
263 | |||
264 | if (fails) | ||
265 | ksft_exit_fail(); | ||
266 | |||
267 | ksft_exit_pass(); | ||
268 | } | ||
diff --git a/tools/testing/selftests/timers/inconsistency-check.c b/tools/testing/selftests/timers/inconsistency-check.c index caf1bc9257c4..74c60e8759a0 100644 --- a/tools/testing/selftests/timers/inconsistency-check.c +++ b/tools/testing/selftests/timers/inconsistency-check.c | |||
@@ -118,7 +118,7 @@ int consistency_test(int clock_type, unsigned long seconds) | |||
118 | start_str = ctime(&t); | 118 | start_str = ctime(&t); |
119 | 119 | ||
120 | while (seconds == -1 || now - then < seconds) { | 120 | while (seconds == -1 || now - then < seconds) { |
121 | inconsistent = 0; | 121 | inconsistent = -1; |
122 | 122 | ||
123 | /* Fill list */ | 123 | /* Fill list */ |
124 | for (i = 0; i < CALLS_PER_LOOP; i++) | 124 | for (i = 0; i < CALLS_PER_LOOP; i++) |
@@ -130,7 +130,7 @@ int consistency_test(int clock_type, unsigned long seconds) | |||
130 | inconsistent = i; | 130 | inconsistent = i; |
131 | 131 | ||
132 | /* display inconsistency */ | 132 | /* display inconsistency */ |
133 | if (inconsistent) { | 133 | if (inconsistent >= 0) { |
134 | unsigned long long delta; | 134 | unsigned long long delta; |
135 | 135 | ||
136 | printf("\%s\n", start_str); | 136 | printf("\%s\n", start_str); |