dscr.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * POWER Data Stream Control Register (DSCR)
  4. *
  5. * This header file contains helper functions and macros
  6. * required for all the DSCR related test cases.
  7. *
  8. * Copyright 2012, Anton Blanchard, IBM Corporation.
  9. * Copyright 2015, Anshuman Khandual, IBM Corporation.
  10. */
  11. #ifndef _SELFTESTS_POWERPC_DSCR_DSCR_H
  12. #define _SELFTESTS_POWERPC_DSCR_DSCR_H
  13. #include <unistd.h>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <fcntl.h>
  18. #include <dirent.h>
  19. #include <pthread.h>
  20. #include <sched.h>
  21. #include <sys/types.h>
  22. #include <sys/stat.h>
  23. #include <sys/wait.h>
  24. #include "reg.h"
  25. #include "utils.h"
  26. #define THREADS 100 /* Max threads */
  27. #define COUNT 100 /* Max iterations */
  28. #define DSCR_MAX 16 /* Max DSCR value */
  29. #define LEN_MAX 100 /* Max name length */
  30. #define DSCR_DEFAULT "/sys/devices/system/cpu/dscr_default"
  31. #define CPU_PATH "/sys/devices/system/cpu/"
  32. #define rmb() asm volatile("lwsync":::"memory")
  33. #define wmb() asm volatile("lwsync":::"memory")
  34. #define READ_ONCE(x) (*(volatile typeof(x) *)&(x))
  35. /* Prilvilege state DSCR access */
  36. inline unsigned long get_dscr(void)
  37. {
  38. return mfspr(SPRN_DSCR_PRIV);
  39. }
  40. inline void set_dscr(unsigned long val)
  41. {
  42. mtspr(SPRN_DSCR_PRIV, val);
  43. }
  44. /* Problem state DSCR access */
  45. inline unsigned long get_dscr_usr(void)
  46. {
  47. return mfspr(SPRN_DSCR);
  48. }
  49. inline void set_dscr_usr(unsigned long val)
  50. {
  51. mtspr(SPRN_DSCR, val);
  52. }
  53. /* Default DSCR access */
  54. unsigned long get_default_dscr(void)
  55. {
  56. int err;
  57. unsigned long val;
  58. err = read_ulong(DSCR_DEFAULT, &val, 16);
  59. if (err) {
  60. perror("read() failed");
  61. exit(1);
  62. }
  63. return val;
  64. }
  65. void set_default_dscr(unsigned long val)
  66. {
  67. int err;
  68. err = write_ulong(DSCR_DEFAULT, val, 16);
  69. if (err) {
  70. perror("write() failed");
  71. exit(1);
  72. }
  73. }
  74. #endif /* _SELFTESTS_POWERPC_DSCR_DSCR_H */