Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * POWER Data Stream Control Register (DSCR) SPR test
0004  *
0005  * This test modifies the DSCR value through both the SPR number
0006  * based mtspr instruction and then makes sure that the same is
0007  * reflected through mfspr instruction using either of the SPR
0008  * numbers.
0009  *
0010  * When using the privilege state SPR, the instructions such as
0011  * mfspr or mtspr are priviledged and the kernel emulates them
0012  * for us. Instructions using problem state SPR can be exuecuted
0013  * directly without any emulation if the HW supports them. Else
0014  * they also get emulated by the kernel.
0015  *
0016  * Copyright 2013, Anton Blanchard, IBM Corporation.
0017  * Copyright 2015, Anshuman Khandual, IBM Corporation.
0018  */
0019 #include "dscr.h"
0020 
0021 static int check_dscr(char *str)
0022 {
0023     unsigned long cur_dscr, cur_dscr_usr;
0024 
0025     cur_dscr = get_dscr();
0026     cur_dscr_usr = get_dscr_usr();
0027     if (cur_dscr != cur_dscr_usr) {
0028         printf("%s set, kernel get %lx != user get %lx\n",
0029                     str, cur_dscr, cur_dscr_usr);
0030         return 1;
0031     }
0032     return 0;
0033 }
0034 
0035 int dscr_user(void)
0036 {
0037     int i;
0038 
0039     SKIP_IF(!have_hwcap2(PPC_FEATURE2_DSCR));
0040 
0041     check_dscr("");
0042 
0043     for (i = 0; i < COUNT; i++) {
0044         set_dscr(i);
0045         if (check_dscr("kernel"))
0046             return 1;
0047     }
0048 
0049     for (i = 0; i < COUNT; i++) {
0050         set_dscr_usr(i);
0051         if (check_dscr("user"))
0052             return 1;
0053     }
0054     return 0;
0055 }
0056 
0057 int main(int argc, char *argv[])
0058 {
0059     return test_harness(dscr_user, "dscr_user_test");
0060 }