1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * POWER Data Stream Control Register (DSCR)
5 * This header file contains helper functions and macros
6 * required for all the DSCR related test cases.
8 * Copyright 2012, Anton Blanchard, IBM Corporation.
9 * Copyright 2015, Anshuman Khandual, IBM Corporation.
11 #ifndef _SELFTESTS_POWERPC_DSCR_DSCR_H
12 #define _SELFTESTS_POWERPC_DSCR_DSCR_H
22 #include <sys/types.h>
28 #define THREADS 100 /* Max threads */
29 #define COUNT 100 /* Max iterations */
30 #define DSCR_MAX 16 /* Max DSCR value */
31 #define LEN_MAX 100 /* Max name length */
33 #define DSCR_DEFAULT "/sys/devices/system/cpu/dscr_default"
34 #define CPU_PATH "/sys/devices/system/cpu/"
36 #define rmb() asm volatile("lwsync":::"memory")
37 #define wmb() asm volatile("lwsync":::"memory")
39 #define READ_ONCE(x) (*(volatile typeof(x) *)&(x))
41 /* Prilvilege state DSCR access */
42 inline unsigned long get_dscr(void)
46 asm volatile("mfspr %0,%1" : "=r" (ret
) : "i" (SPRN_DSCR_PRIV
));
51 inline void set_dscr(unsigned long val
)
53 asm volatile("mtspr %1,%0" : : "r" (val
), "i" (SPRN_DSCR_PRIV
));
56 /* Problem state DSCR access */
57 inline unsigned long get_dscr_usr(void)
61 asm volatile("mfspr %0,%1" : "=r" (ret
) : "i" (SPRN_DSCR
));
66 inline void set_dscr_usr(unsigned long val
)
68 asm volatile("mtspr %1,%0" : : "r" (val
), "i" (SPRN_DSCR
));
71 /* Default DSCR access */
72 unsigned long get_default_dscr(void)
79 fd
= open(DSCR_DEFAULT
, O_RDONLY
);
81 perror("open() failed");
85 memset(buf
, 0, sizeof(buf
));
86 lseek(fd
, 0, SEEK_SET
);
87 ret
= read(fd
, buf
, sizeof(buf
));
89 perror("read() failed");
92 sscanf(buf
, "%lx", &val
);
97 void set_default_dscr(unsigned long val
)
103 fd
= open(DSCR_DEFAULT
, O_RDWR
);
105 perror("open() failed");
109 sprintf(buf
, "%lx\n", val
);
110 ret
= write(fd
, buf
, strlen(buf
));
112 perror("write() failed");
118 double uniform_deviate(int seed
)
120 return seed
* (1.0 / (RAND_MAX
+ 1.0));
122 #endif /* _SELFTESTS_POWERPC_DSCR_DSCR_H */