aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/clocksource/arm_arch_timer.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/clocksource/arm_arch_timer.c')
-rw-r--r--drivers/clocksource/arm_arch_timer.c96
1 files changed, 59 insertions, 37 deletions
diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index f0dd9d42bc7b..5152b3898155 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -75,7 +75,7 @@ static int arch_timer_ppi[MAX_TIMER_PPI];
75 75
76static struct clock_event_device __percpu *arch_timer_evt; 76static struct clock_event_device __percpu *arch_timer_evt;
77 77
78static bool arch_timer_use_virtual = true; 78static enum ppi_nr arch_timer_uses_ppi = VIRT_PPI;
79static bool arch_timer_c3stop; 79static bool arch_timer_c3stop;
80static bool arch_timer_mem_use_virtual; 80static bool arch_timer_mem_use_virtual;
81 81
@@ -271,16 +271,22 @@ static void __arch_timer_setup(unsigned type,
271 clk->name = "arch_sys_timer"; 271 clk->name = "arch_sys_timer";
272 clk->rating = 450; 272 clk->rating = 450;
273 clk->cpumask = cpumask_of(smp_processor_id()); 273 clk->cpumask = cpumask_of(smp_processor_id());
274 if (arch_timer_use_virtual) { 274 clk->irq = arch_timer_ppi[arch_timer_uses_ppi];
275 clk->irq = arch_timer_ppi[VIRT_PPI]; 275 switch (arch_timer_uses_ppi) {
276 case VIRT_PPI:
276 clk->set_state_shutdown = arch_timer_shutdown_virt; 277 clk->set_state_shutdown = arch_timer_shutdown_virt;
277 clk->set_state_oneshot_stopped = arch_timer_shutdown_virt; 278 clk->set_state_oneshot_stopped = arch_timer_shutdown_virt;
278 clk->set_next_event = arch_timer_set_next_event_virt; 279 clk->set_next_event = arch_timer_set_next_event_virt;
279 } else { 280 break;
280 clk->irq = arch_timer_ppi[PHYS_SECURE_PPI]; 281 case PHYS_SECURE_PPI:
282 case PHYS_NONSECURE_PPI:
283 case HYP_PPI:
281 clk->set_state_shutdown = arch_timer_shutdown_phys; 284 clk->set_state_shutdown = arch_timer_shutdown_phys;
282 clk->set_state_oneshot_stopped = arch_timer_shutdown_phys; 285 clk->set_state_oneshot_stopped = arch_timer_shutdown_phys;
283 clk->set_next_event = arch_timer_set_next_event_phys; 286 clk->set_next_event = arch_timer_set_next_event_phys;
287 break;
288 default:
289 BUG();
284 } 290 }
285 } else { 291 } else {
286 clk->features |= CLOCK_EVT_FEAT_DYNIRQ; 292 clk->features |= CLOCK_EVT_FEAT_DYNIRQ;
@@ -350,17 +356,20 @@ static void arch_counter_set_user_access(void)
350 arch_timer_set_cntkctl(cntkctl); 356 arch_timer_set_cntkctl(cntkctl);
351} 357}
352 358
359static bool arch_timer_has_nonsecure_ppi(void)
360{
361 return (arch_timer_uses_ppi == PHYS_SECURE_PPI &&
362 arch_timer_ppi[PHYS_NONSECURE_PPI]);
363}
364
353static int arch_timer_setup(struct clock_event_device *clk) 365static int arch_timer_setup(struct clock_event_device *clk)
354{ 366{
355 __arch_timer_setup(ARCH_CP15_TIMER, clk); 367 __arch_timer_setup(ARCH_CP15_TIMER, clk);
356 368
357 if (arch_timer_use_virtual) 369 enable_percpu_irq(arch_timer_ppi[arch_timer_uses_ppi], 0);
358 enable_percpu_irq(arch_timer_ppi[VIRT_PPI], 0); 370
359 else { 371 if (arch_timer_has_nonsecure_ppi())
360 enable_percpu_irq(arch_timer_ppi[PHYS_SECURE_PPI], 0); 372 enable_percpu_irq(arch_timer_ppi[PHYS_NONSECURE_PPI], 0);
361 if (arch_timer_ppi[PHYS_NONSECURE_PPI])
362 enable_percpu_irq(arch_timer_ppi[PHYS_NONSECURE_PPI], 0);
363 }
364 373
365 arch_counter_set_user_access(); 374 arch_counter_set_user_access();
366 if (IS_ENABLED(CONFIG_ARM_ARCH_TIMER_EVTSTREAM)) 375 if (IS_ENABLED(CONFIG_ARM_ARCH_TIMER_EVTSTREAM))
@@ -402,7 +411,7 @@ static void arch_timer_banner(unsigned type)
402 (unsigned long)arch_timer_rate / 1000000, 411 (unsigned long)arch_timer_rate / 1000000,
403 (unsigned long)(arch_timer_rate / 10000) % 100, 412 (unsigned long)(arch_timer_rate / 10000) % 100,
404 type & ARCH_CP15_TIMER ? 413 type & ARCH_CP15_TIMER ?
405 arch_timer_use_virtual ? "virt" : "phys" : 414 (arch_timer_uses_ppi == VIRT_PPI) ? "virt" : "phys" :
406 "", 415 "",
407 type == (ARCH_CP15_TIMER | ARCH_MEM_TIMER) ? "/" : "", 416 type == (ARCH_CP15_TIMER | ARCH_MEM_TIMER) ? "/" : "",
408 type & ARCH_MEM_TIMER ? 417 type & ARCH_MEM_TIMER ?
@@ -472,7 +481,7 @@ static void __init arch_counter_register(unsigned type)
472 481
473 /* Register the CP15 based counter if we have one */ 482 /* Register the CP15 based counter if we have one */
474 if (type & ARCH_CP15_TIMER) { 483 if (type & ARCH_CP15_TIMER) {
475 if (IS_ENABLED(CONFIG_ARM64) || arch_timer_use_virtual) 484 if (IS_ENABLED(CONFIG_ARM64) || arch_timer_uses_ppi == VIRT_PPI)
476 arch_timer_read_counter = arch_counter_get_cntvct; 485 arch_timer_read_counter = arch_counter_get_cntvct;
477 else 486 else
478 arch_timer_read_counter = arch_counter_get_cntpct; 487 arch_timer_read_counter = arch_counter_get_cntpct;
@@ -502,13 +511,9 @@ static void arch_timer_stop(struct clock_event_device *clk)
502 pr_debug("arch_timer_teardown disable IRQ%d cpu #%d\n", 511 pr_debug("arch_timer_teardown disable IRQ%d cpu #%d\n",
503 clk->irq, smp_processor_id()); 512 clk->irq, smp_processor_id());
504 513
505 if (arch_timer_use_virtual) 514 disable_percpu_irq(arch_timer_ppi[arch_timer_uses_ppi]);
506 disable_percpu_irq(arch_timer_ppi[VIRT_PPI]); 515 if (arch_timer_has_nonsecure_ppi())
507 else { 516 disable_percpu_irq(arch_timer_ppi[PHYS_NONSECURE_PPI]);
508 disable_percpu_irq(arch_timer_ppi[PHYS_SECURE_PPI]);
509 if (arch_timer_ppi[PHYS_NONSECURE_PPI])
510 disable_percpu_irq(arch_timer_ppi[PHYS_NONSECURE_PPI]);
511 }
512 517
513 clk->set_state_shutdown(clk); 518 clk->set_state_shutdown(clk);
514} 519}
@@ -574,12 +579,14 @@ static int __init arch_timer_register(void)
574 goto out; 579 goto out;
575 } 580 }
576 581
577 if (arch_timer_use_virtual) { 582 ppi = arch_timer_ppi[arch_timer_uses_ppi];
578 ppi = arch_timer_ppi[VIRT_PPI]; 583 switch (arch_timer_uses_ppi) {
584 case VIRT_PPI:
579 err = request_percpu_irq(ppi, arch_timer_handler_virt, 585 err = request_percpu_irq(ppi, arch_timer_handler_virt,
580 "arch_timer", arch_timer_evt); 586 "arch_timer", arch_timer_evt);
581 } else { 587 break;
582 ppi = arch_timer_ppi[PHYS_SECURE_PPI]; 588 case PHYS_SECURE_PPI:
589 case PHYS_NONSECURE_PPI:
583 err = request_percpu_irq(ppi, arch_timer_handler_phys, 590 err = request_percpu_irq(ppi, arch_timer_handler_phys,
584 "arch_timer", arch_timer_evt); 591 "arch_timer", arch_timer_evt);
585 if (!err && arch_timer_ppi[PHYS_NONSECURE_PPI]) { 592 if (!err && arch_timer_ppi[PHYS_NONSECURE_PPI]) {
@@ -590,6 +597,13 @@ static int __init arch_timer_register(void)
590 free_percpu_irq(arch_timer_ppi[PHYS_SECURE_PPI], 597 free_percpu_irq(arch_timer_ppi[PHYS_SECURE_PPI],
591 arch_timer_evt); 598 arch_timer_evt);
592 } 599 }
600 break;
601 case HYP_PPI:
602 err = request_percpu_irq(ppi, arch_timer_handler_phys,
603 "arch_timer", arch_timer_evt);
604 break;
605 default:
606 BUG();
593 } 607 }
594 608
595 if (err) { 609 if (err) {
@@ -614,15 +628,10 @@ static int __init arch_timer_register(void)
614out_unreg_notify: 628out_unreg_notify:
615 unregister_cpu_notifier(&arch_timer_cpu_nb); 629 unregister_cpu_notifier(&arch_timer_cpu_nb);
616out_free_irq: 630out_free_irq:
617 if (arch_timer_use_virtual) 631 free_percpu_irq(arch_timer_ppi[arch_timer_uses_ppi], arch_timer_evt);
618 free_percpu_irq(arch_timer_ppi[VIRT_PPI], arch_timer_evt); 632 if (arch_timer_has_nonsecure_ppi())
619 else { 633 free_percpu_irq(arch_timer_ppi[PHYS_NONSECURE_PPI],
620 free_percpu_irq(arch_timer_ppi[PHYS_SECURE_PPI],
621 arch_timer_evt); 634 arch_timer_evt);
622 if (arch_timer_ppi[PHYS_NONSECURE_PPI])
623 free_percpu_irq(arch_timer_ppi[PHYS_NONSECURE_PPI],
624 arch_timer_evt);
625 }
626 635
627out_free: 636out_free:
628 free_percpu(arch_timer_evt); 637 free_percpu(arch_timer_evt);
@@ -709,12 +718,25 @@ static void __init arch_timer_init(void)
709 * 718 *
710 * If no interrupt provided for virtual timer, we'll have to 719 * If no interrupt provided for virtual timer, we'll have to
711 * stick to the physical timer. It'd better be accessible... 720 * stick to the physical timer. It'd better be accessible...
721 *
722 * On ARMv8.1 with VH extensions, the kernel runs in HYP. VHE
723 * accesses to CNTP_*_EL1 registers are silently redirected to
724 * their CNTHP_*_EL2 counterparts, and use a different PPI
725 * number.
712 */ 726 */
713 if (is_hyp_mode_available() || !arch_timer_ppi[VIRT_PPI]) { 727 if (is_hyp_mode_available() || !arch_timer_ppi[VIRT_PPI]) {
714 arch_timer_use_virtual = false; 728 bool has_ppi;
729
730 if (is_kernel_in_hyp_mode()) {
731 arch_timer_uses_ppi = HYP_PPI;
732 has_ppi = !!arch_timer_ppi[HYP_PPI];
733 } else {
734 arch_timer_uses_ppi = PHYS_SECURE_PPI;
735 has_ppi = (!!arch_timer_ppi[PHYS_SECURE_PPI] ||
736 !!arch_timer_ppi[PHYS_NONSECURE_PPI]);
737 }
715 738
716 if (!arch_timer_ppi[PHYS_SECURE_PPI] || 739 if (!has_ppi) {
717 !arch_timer_ppi[PHYS_NONSECURE_PPI]) {
718 pr_warn("arch_timer: No interrupt available, giving up\n"); 740 pr_warn("arch_timer: No interrupt available, giving up\n");
719 return; 741 return;
720 } 742 }
@@ -747,7 +769,7 @@ static void __init arch_timer_of_init(struct device_node *np)
747 */ 769 */
748 if (IS_ENABLED(CONFIG_ARM) && 770 if (IS_ENABLED(CONFIG_ARM) &&
749 of_property_read_bool(np, "arm,cpu-registers-not-fw-configured")) 771 of_property_read_bool(np, "arm,cpu-registers-not-fw-configured"))
750 arch_timer_use_virtual = false; 772 arch_timer_uses_ppi = PHYS_SECURE_PPI;
751 773
752 arch_timer_init(); 774 arch_timer_init();
753} 775}