1 // SPDX-License-Identifier: GPL-2.0-only
3 * POWER Data Stream Control Register (DSCR) sysfs interface test
5 * This test updates to system wide DSCR default through the sysfs interface
6 * and then verifies that all the CPU specific DSCR defaults are updated as
7 * well verified from their sysfs interfaces.
9 * Copyright 2015, Anshuman Khandual, IBM Corporation.
13 static int check_cpu_dscr_default(char *file, unsigned long val)
18 fd = open(file, O_RDWR);
20 perror("open() failed");
24 rc = read(fd, buf, sizeof(buf));
26 perror("read() failed");
32 if (strtol(buf, NULL, 16) != val) {
33 printf("DSCR match failed: %ld (system) %ld (cpu)\n",
34 val, strtol(buf, NULL, 16));
40 static int check_all_cpu_dscr_defaults(unsigned long val)
46 sysfs = opendir(CPU_PATH);
48 perror("opendir() failed");
52 while ((dp = readdir(sysfs))) {
55 if (!(dp->d_type & DT_DIR))
57 if (!strcmp(dp->d_name, "cpuidle"))
59 if (!strstr(dp->d_name, "cpu"))
62 len = snprintf(file, LEN_MAX, "%s%s/dscr", CPU_PATH, dp->d_name);
65 if (access(file, F_OK))
68 if (check_cpu_dscr_default(file, val))
77 unsigned long orig_dscr_default;
80 orig_dscr_default = get_default_dscr();
81 for (i = 0; i < COUNT; i++) {
82 for (j = 0; j < DSCR_MAX; j++) {
84 if (check_all_cpu_dscr_defaults(j))
88 set_default_dscr(orig_dscr_default);
91 set_default_dscr(orig_dscr_default);
95 int main(int argc, char *argv[])
97 return test_harness(dscr_sysfs, "dscr_sysfs_test");