1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Clock utilities for s390 4 * 5 * Authors: 6 * Thomas Huth <thuth@redhat.com> 7 * 8 * Copied from the s390/intercept test by: 9 * Pierre Morel <pmorel@linux.ibm.com> 10 */ 11 #ifndef _ASMS390X_TIME_H_ 12 #define _ASMS390X_TIME_H_ 13 14 #define STCK_SHIFT_US (63 - 51) 15 #define STCK_MAX ((1UL << 52) - 1) 16 17 static inline uint64_t get_clock_us(void) 18 { 19 uint64_t clk; 20 21 asm volatile(" stck %0 " : : "Q"(clk) : "memory"); 22 23 return clk >> STCK_SHIFT_US; 24 } 25 26 static inline uint64_t get_clock_ms(void) 27 { 28 return get_clock_us() / 1000; 29 } 30 31 static inline void udelay(unsigned long us) 32 { 33 unsigned long startclk = get_clock_us(); 34 unsigned long c; 35 36 do { 37 c = get_clock_us(); 38 if (c < startclk) 39 c += STCK_MAX; 40 } while (c < startclk + us); 41 } 42 43 static inline void mdelay(unsigned long ms) 44 { 45 udelay(ms * 1000); 46 } 47 48 #endif 49