Linux 4.19.133
[linux/fpc-iii.git] / tools / testing / selftests / powerpc / dscr / dscr_user_test.c
blob77d16b5e7dca2d419ad28b1c0d97a7b72a8f2e2e
1 /*
2 * POWER Data Stream Control Register (DSCR) SPR test
4 * This test modifies the DSCR value through both the SPR number
5 * based mtspr instruction and then makes sure that the same is
6 * reflected through mfspr instruction using either of the SPR
7 * numbers.
9 * When using the privilege state SPR, the instructions such as
10 * mfspr or mtspr are priviledged and the kernel emulates them
11 * for us. Instructions using problem state SPR can be exuecuted
12 * directly without any emulation if the HW supports them. Else
13 * they also get emulated by the kernel.
15 * Copyright 2013, Anton Blanchard, IBM Corporation.
16 * Copyright 2015, Anshuman Khandual, IBM Corporation.
18 * This program is free software; you can redistribute it and/or modify it
19 * under the terms of the GNU General Public License version 2 as published
20 * by the Free Software Foundation.
22 #include "dscr.h"
24 static int check_dscr(char *str)
26 unsigned long cur_dscr, cur_dscr_usr;
28 cur_dscr = get_dscr();
29 cur_dscr_usr = get_dscr_usr();
30 if (cur_dscr != cur_dscr_usr) {
31 printf("%s set, kernel get %lx != user get %lx\n",
32 str, cur_dscr, cur_dscr_usr);
33 return 1;
35 return 0;
38 int dscr_user(void)
40 int i;
42 check_dscr("");
44 for (i = 0; i < COUNT; i++) {
45 set_dscr(i);
46 if (check_dscr("kernel"))
47 return 1;
50 for (i = 0; i < COUNT; i++) {
51 set_dscr_usr(i);
52 if (check_dscr("user"))
53 return 1;
55 return 0;
58 int main(int argc, char *argv[])
60 return test_harness(dscr_user, "dscr_user_test");