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)
15 unsigned long cpu_dscr;
18 err = read_ulong(file, &cpu_dscr, 16);
22 if (cpu_dscr != val) {
23 printf("DSCR match failed: %ld (system) %ld (cpu)\n",
30 static int check_all_cpu_dscr_defaults(unsigned long val)
36 sysfs = opendir(CPU_PATH);
38 perror("opendir() failed");
42 while ((dp = readdir(sysfs))) {
45 if (!(dp->d_type & DT_DIR))
47 if (!strcmp(dp->d_name, "cpuidle"))
49 if (!strstr(dp->d_name, "cpu"))
52 len = snprintf(file, LEN_MAX, "%s%s/dscr", CPU_PATH, dp->d_name);
55 if (access(file, F_OK))
58 if (check_cpu_dscr_default(file, val)) {
69 unsigned long orig_dscr_default;
71 SKIP_IF(!have_hwcap2(PPC_FEATURE2_DSCR));
73 orig_dscr_default = get_default_dscr();
74 for (int i = 0; i < DSCR_MAX; i++) {
76 if (check_all_cpu_dscr_defaults(i))
79 set_default_dscr(orig_dscr_default);
82 set_default_dscr(orig_dscr_default);
86 int main(int argc, char *argv[])
88 return test_harness(dscr_sysfs, "dscr_sysfs_test");