| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Common time prototypes and such for all ppc machines. |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Written by Cort Dougan (cort@cs.nmt.edu) to merge |
|---|
| 5 | 6 | * Paul Mackerras' version and mine for PReP and Pmac. |
|---|
| 6 | | - * |
|---|
| 7 | | - * This program is free software; you can redistribute it and/or |
|---|
| 8 | | - * modify it under the terms of the GNU General Public License |
|---|
| 9 | | - * as published by the Free Software Foundation; either version |
|---|
| 10 | | - * 2 of the License, or (at your option) any later version. |
|---|
| 11 | 7 | */ |
|---|
| 12 | 8 | |
|---|
| 13 | 9 | #ifndef __POWERPC_TIME_H |
|---|
| .. | .. |
|---|
| 28 | 24 | |
|---|
| 29 | 25 | |
|---|
| 30 | 26 | extern void generic_calibrate_decr(void); |
|---|
| 31 | | -extern void hdec_interrupt(struct pt_regs *regs); |
|---|
| 32 | 27 | |
|---|
| 33 | 28 | /* Some sane defaults: 125 MHz timebase, 1GHz processor */ |
|---|
| 34 | 29 | extern unsigned long ppc_proc_freq; |
|---|
| .. | .. |
|---|
| 36 | 31 | extern unsigned long ppc_tb_freq; |
|---|
| 37 | 32 | #define DEFAULT_TB_FREQ 125000000UL |
|---|
| 38 | 33 | |
|---|
| 34 | +extern bool tb_invalid; |
|---|
| 35 | + |
|---|
| 39 | 36 | struct div_result { |
|---|
| 40 | 37 | u64 result_high; |
|---|
| 41 | 38 | u64 result_low; |
|---|
| 42 | 39 | }; |
|---|
| 43 | 40 | |
|---|
| 44 | | -/* Accessor functions for the timebase (RTC on 601) registers. */ |
|---|
| 45 | | -/* If one day CONFIG_POWER is added just define __USE_RTC as 1 */ |
|---|
| 46 | | -#ifdef CONFIG_6xx |
|---|
| 47 | | -#define __USE_RTC() (cpu_has_feature(CPU_FTR_USE_RTC)) |
|---|
| 48 | | -#else |
|---|
| 49 | | -#define __USE_RTC() 0 |
|---|
| 50 | | -#endif |
|---|
| 51 | | - |
|---|
| 52 | | -#ifdef CONFIG_PPC64 |
|---|
| 53 | | - |
|---|
| 54 | 41 | /* For compatibility, get_tbl() is defined as get_tb() on ppc64 */ |
|---|
| 55 | | -#define get_tbl get_tb |
|---|
| 56 | | - |
|---|
| 57 | | -#else |
|---|
| 58 | | - |
|---|
| 59 | 42 | static inline unsigned long get_tbl(void) |
|---|
| 60 | 43 | { |
|---|
| 61 | | -#if defined(CONFIG_403GCX) |
|---|
| 62 | | - unsigned long tbl; |
|---|
| 63 | | - asm volatile("mfspr %0, 0x3dd" : "=r" (tbl)); |
|---|
| 64 | | - return tbl; |
|---|
| 65 | | -#else |
|---|
| 66 | | - return mftbl(); |
|---|
| 67 | | -#endif |
|---|
| 68 | | -} |
|---|
| 69 | | - |
|---|
| 70 | | -static inline unsigned int get_tbu(void) |
|---|
| 71 | | -{ |
|---|
| 72 | | -#ifdef CONFIG_403GCX |
|---|
| 73 | | - unsigned int tbu; |
|---|
| 74 | | - asm volatile("mfspr %0, 0x3dc" : "=r" (tbu)); |
|---|
| 75 | | - return tbu; |
|---|
| 76 | | -#else |
|---|
| 77 | | - return mftbu(); |
|---|
| 78 | | -#endif |
|---|
| 79 | | -} |
|---|
| 80 | | -#endif /* !CONFIG_PPC64 */ |
|---|
| 81 | | - |
|---|
| 82 | | -static inline unsigned int get_rtcl(void) |
|---|
| 83 | | -{ |
|---|
| 84 | | - unsigned int rtcl; |
|---|
| 85 | | - |
|---|
| 86 | | - asm volatile("mfrtcl %0" : "=r" (rtcl)); |
|---|
| 87 | | - return rtcl; |
|---|
| 88 | | -} |
|---|
| 89 | | - |
|---|
| 90 | | -static inline u64 get_rtc(void) |
|---|
| 91 | | -{ |
|---|
| 92 | | - unsigned int hi, lo, hi2; |
|---|
| 93 | | - |
|---|
| 94 | | - do { |
|---|
| 95 | | - asm volatile("mfrtcu %0; mfrtcl %1; mfrtcu %2" |
|---|
| 96 | | - : "=r" (hi), "=r" (lo), "=r" (hi2)); |
|---|
| 97 | | - } while (hi2 != hi); |
|---|
| 98 | | - return (u64)hi * 1000000000 + lo; |
|---|
| 44 | + return mftb(); |
|---|
| 99 | 45 | } |
|---|
| 100 | 46 | |
|---|
| 101 | 47 | static inline u64 get_vtb(void) |
|---|
| .. | .. |
|---|
| 107 | 53 | return 0; |
|---|
| 108 | 54 | } |
|---|
| 109 | 55 | |
|---|
| 110 | | -#ifdef CONFIG_PPC64 |
|---|
| 111 | | -static inline u64 get_tb(void) |
|---|
| 112 | | -{ |
|---|
| 113 | | - return mftb(); |
|---|
| 114 | | -} |
|---|
| 115 | | -#else /* CONFIG_PPC64 */ |
|---|
| 116 | 56 | static inline u64 get_tb(void) |
|---|
| 117 | 57 | { |
|---|
| 118 | 58 | unsigned int tbhi, tblo, tbhi2; |
|---|
| 119 | 59 | |
|---|
| 60 | + if (IS_ENABLED(CONFIG_PPC64)) |
|---|
| 61 | + return mftb(); |
|---|
| 62 | + |
|---|
| 120 | 63 | do { |
|---|
| 121 | | - tbhi = get_tbu(); |
|---|
| 122 | | - tblo = get_tbl(); |
|---|
| 123 | | - tbhi2 = get_tbu(); |
|---|
| 64 | + tbhi = mftbu(); |
|---|
| 65 | + tblo = mftb(); |
|---|
| 66 | + tbhi2 = mftbu(); |
|---|
| 124 | 67 | } while (tbhi != tbhi2); |
|---|
| 125 | 68 | |
|---|
| 126 | 69 | return ((u64)tbhi << 32) | tblo; |
|---|
| 127 | | -} |
|---|
| 128 | | -#endif /* !CONFIG_PPC64 */ |
|---|
| 129 | | - |
|---|
| 130 | | -static inline u64 get_tb_or_rtc(void) |
|---|
| 131 | | -{ |
|---|
| 132 | | - return __USE_RTC() ? get_rtc() : get_tb(); |
|---|
| 133 | 70 | } |
|---|
| 134 | 71 | |
|---|
| 135 | 72 | static inline void set_tb(unsigned int upper, unsigned int lower) |
|---|
| .. | .. |
|---|
| 147 | 84 | */ |
|---|
| 148 | 85 | static inline u64 get_dec(void) |
|---|
| 149 | 86 | { |
|---|
| 150 | | -#if defined(CONFIG_40x) |
|---|
| 151 | | - return (mfspr(SPRN_PIT)); |
|---|
| 152 | | -#else |
|---|
| 153 | | - return (mfspr(SPRN_DEC)); |
|---|
| 154 | | -#endif |
|---|
| 87 | + if (IS_ENABLED(CONFIG_40x)) |
|---|
| 88 | + return mfspr(SPRN_PIT); |
|---|
| 89 | + |
|---|
| 90 | + return mfspr(SPRN_DEC); |
|---|
| 155 | 91 | } |
|---|
| 156 | 92 | |
|---|
| 157 | 93 | /* |
|---|
| .. | .. |
|---|
| 161 | 97 | */ |
|---|
| 162 | 98 | static inline void set_dec(u64 val) |
|---|
| 163 | 99 | { |
|---|
| 164 | | -#if defined(CONFIG_40x) |
|---|
| 165 | | - mtspr(SPRN_PIT, (u32) val); |
|---|
| 166 | | -#else |
|---|
| 167 | | -#ifndef CONFIG_BOOKE |
|---|
| 168 | | - --val; |
|---|
| 169 | | -#endif |
|---|
| 170 | | - mtspr(SPRN_DEC, val); |
|---|
| 171 | | -#endif /* not 40x */ |
|---|
| 100 | + if (IS_ENABLED(CONFIG_40x)) |
|---|
| 101 | + mtspr(SPRN_PIT, (u32)val); |
|---|
| 102 | + else if (IS_ENABLED(CONFIG_BOOKE)) |
|---|
| 103 | + mtspr(SPRN_DEC, val); |
|---|
| 104 | + else |
|---|
| 105 | + mtspr(SPRN_DEC, val - 1); |
|---|
| 172 | 106 | } |
|---|
| 173 | 107 | |
|---|
| 174 | 108 | static inline unsigned long tb_ticks_since(unsigned long tstamp) |
|---|
| 175 | 109 | { |
|---|
| 176 | | - if (__USE_RTC()) { |
|---|
| 177 | | - int delta = get_rtcl() - (unsigned int) tstamp; |
|---|
| 178 | | - return delta < 0 ? delta + 1000000000 : delta; |
|---|
| 179 | | - } |
|---|
| 180 | | - return get_tbl() - tstamp; |
|---|
| 110 | + return mftb() - tstamp; |
|---|
| 181 | 111 | } |
|---|
| 182 | 112 | |
|---|
| 183 | 113 | #define mulhwu(x,y) \ |
|---|
| .. | .. |
|---|
| 201 | 131 | /* Convert timebase ticks to nanoseconds */ |
|---|
| 202 | 132 | unsigned long long tb_to_ns(unsigned long long tb_ticks); |
|---|
| 203 | 133 | |
|---|
| 134 | +/* SPLPAR */ |
|---|
| 135 | +void accumulate_stolen_time(void); |
|---|
| 136 | + |
|---|
| 204 | 137 | #endif /* __KERNEL__ */ |
|---|
| 205 | 138 | #endif /* __POWERPC_TIME_H */ |
|---|