1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2cc6a93f1SAnshuman Khandual /*
3cc6a93f1SAnshuman Khandual * POWER Data Stream Control Register (DSCR) SPR test
4cc6a93f1SAnshuman Khandual *
5cc6a93f1SAnshuman Khandual * This test modifies the DSCR value through both the SPR number
6cc6a93f1SAnshuman Khandual * based mtspr instruction and then makes sure that the same is
7cc6a93f1SAnshuman Khandual * reflected through mfspr instruction using either of the SPR
8cc6a93f1SAnshuman Khandual * numbers.
9cc6a93f1SAnshuman Khandual *
10cc6a93f1SAnshuman Khandual * When using the privilege state SPR, the instructions such as
11*15f0c260SBenjamin Gray * mfspr or mtspr are privileged and the kernel emulates them
12*15f0c260SBenjamin Gray * for us. Instructions using problem state SPR can be executed
13cc6a93f1SAnshuman Khandual * directly without any emulation if the HW supports them. Else
14cc6a93f1SAnshuman Khandual * they also get emulated by the kernel.
15cc6a93f1SAnshuman Khandual *
16cc6a93f1SAnshuman Khandual * Copyright 2013, Anton Blanchard, IBM Corporation.
17cc6a93f1SAnshuman Khandual * Copyright 2015, Anshuman Khandual, IBM Corporation.
18cc6a93f1SAnshuman Khandual */
19cc6a93f1SAnshuman Khandual #include "dscr.h"
20cc6a93f1SAnshuman Khandual
check_dscr(char * str)21cc6a93f1SAnshuman Khandual static int check_dscr(char *str)
22cc6a93f1SAnshuman Khandual {
23cc6a93f1SAnshuman Khandual unsigned long cur_dscr, cur_dscr_usr;
24cc6a93f1SAnshuman Khandual
25cc6a93f1SAnshuman Khandual cur_dscr = get_dscr();
26cc6a93f1SAnshuman Khandual cur_dscr_usr = get_dscr_usr();
27cc6a93f1SAnshuman Khandual if (cur_dscr != cur_dscr_usr) {
28cc6a93f1SAnshuman Khandual printf("%s set, kernel get %lx != user get %lx\n",
29cc6a93f1SAnshuman Khandual str, cur_dscr, cur_dscr_usr);
30cc6a93f1SAnshuman Khandual return 1;
31cc6a93f1SAnshuman Khandual }
32cc6a93f1SAnshuman Khandual return 0;
33cc6a93f1SAnshuman Khandual }
34cc6a93f1SAnshuman Khandual
dscr_user(void)35cc6a93f1SAnshuman Khandual int dscr_user(void)
36cc6a93f1SAnshuman Khandual {
37cc6a93f1SAnshuman Khandual int i;
38cc6a93f1SAnshuman Khandual
394c3c3c50SMichael Ellerman SKIP_IF(!have_hwcap2(PPC_FEATURE2_DSCR));
404c3c3c50SMichael Ellerman
41cc6a93f1SAnshuman Khandual check_dscr("");
42cc6a93f1SAnshuman Khandual
43cc6a93f1SAnshuman Khandual for (i = 0; i < COUNT; i++) {
44cc6a93f1SAnshuman Khandual set_dscr(i);
45cc6a93f1SAnshuman Khandual if (check_dscr("kernel"))
46cc6a93f1SAnshuman Khandual return 1;
47cc6a93f1SAnshuman Khandual }
48cc6a93f1SAnshuman Khandual
49cc6a93f1SAnshuman Khandual for (i = 0; i < COUNT; i++) {
50cc6a93f1SAnshuman Khandual set_dscr_usr(i);
51cc6a93f1SAnshuman Khandual if (check_dscr("user"))
52cc6a93f1SAnshuman Khandual return 1;
53cc6a93f1SAnshuman Khandual }
54cc6a93f1SAnshuman Khandual return 0;
55cc6a93f1SAnshuman Khandual }
56cc6a93f1SAnshuman Khandual
main(int argc,char * argv[])57cc6a93f1SAnshuman Khandual int main(int argc, char *argv[])
58cc6a93f1SAnshuman Khandual {
59cc6a93f1SAnshuman Khandual return test_harness(dscr_user, "dscr_user_test");
60cc6a93f1SAnshuman Khandual }
61