xref: /openbmc/linux/Documentation/powerpc/dscr.rst (revision 4d2e26a38fbcde2ba14882cbdb845caa1c17e19b)
1*4d2e26a3SMauro Carvalho Chehab===================================
2*4d2e26a3SMauro Carvalho ChehabDSCR (Data Stream Control Register)
3*4d2e26a3SMauro Carvalho Chehab===================================
4*4d2e26a3SMauro Carvalho Chehab
5*4d2e26a3SMauro Carvalho ChehabDSCR register in powerpc allows user to have some control of prefetch of data
6*4d2e26a3SMauro Carvalho Chehabstream in the processor. Please refer to the ISA documents or related manual
7*4d2e26a3SMauro Carvalho Chehabfor more detailed information regarding how to use this DSCR to attain this
8*4d2e26a3SMauro Carvalho Chehabcontrol of the prefetches . This document here provides an overview of kernel
9*4d2e26a3SMauro Carvalho Chehabsupport for DSCR, related kernel objects, it's functionalities and exported
10*4d2e26a3SMauro Carvalho Chehabuser interface.
11*4d2e26a3SMauro Carvalho Chehab
12*4d2e26a3SMauro Carvalho Chehab(A) Data Structures:
13*4d2e26a3SMauro Carvalho Chehab
14*4d2e26a3SMauro Carvalho Chehab	(1) thread_struct::
15*4d2e26a3SMauro Carvalho Chehab
16*4d2e26a3SMauro Carvalho Chehab		dscr		/* Thread DSCR value */
17*4d2e26a3SMauro Carvalho Chehab		dscr_inherit	/* Thread has changed default DSCR */
18*4d2e26a3SMauro Carvalho Chehab
19*4d2e26a3SMauro Carvalho Chehab	(2) PACA::
20*4d2e26a3SMauro Carvalho Chehab
21*4d2e26a3SMauro Carvalho Chehab		dscr_default	/* per-CPU DSCR default value */
22*4d2e26a3SMauro Carvalho Chehab
23*4d2e26a3SMauro Carvalho Chehab	(3) sysfs.c::
24*4d2e26a3SMauro Carvalho Chehab
25*4d2e26a3SMauro Carvalho Chehab		dscr_default	/* System DSCR default value */
26*4d2e26a3SMauro Carvalho Chehab
27*4d2e26a3SMauro Carvalho Chehab(B) Scheduler Changes:
28*4d2e26a3SMauro Carvalho Chehab
29*4d2e26a3SMauro Carvalho Chehab	Scheduler will write the per-CPU DSCR default which is stored in the
30*4d2e26a3SMauro Carvalho Chehab	CPU's PACA value into the register if the thread has dscr_inherit value
31*4d2e26a3SMauro Carvalho Chehab	cleared which means that it has not changed the default DSCR till now.
32*4d2e26a3SMauro Carvalho Chehab	If the dscr_inherit value is set which means that it has changed the
33*4d2e26a3SMauro Carvalho Chehab	default DSCR value, scheduler will write the changed value which will
34*4d2e26a3SMauro Carvalho Chehab	now be contained in thread struct's dscr into the register instead of
35*4d2e26a3SMauro Carvalho Chehab	the per-CPU default PACA based DSCR value.
36*4d2e26a3SMauro Carvalho Chehab
37*4d2e26a3SMauro Carvalho Chehab	NOTE: Please note here that the system wide global DSCR value never
38*4d2e26a3SMauro Carvalho Chehab	gets used directly in the scheduler process context switch at all.
39*4d2e26a3SMauro Carvalho Chehab
40*4d2e26a3SMauro Carvalho Chehab(C) SYSFS Interface:
41*4d2e26a3SMauro Carvalho Chehab
42*4d2e26a3SMauro Carvalho Chehab	- Global DSCR default:		/sys/devices/system/cpu/dscr_default
43*4d2e26a3SMauro Carvalho Chehab	- CPU specific DSCR default:	/sys/devices/system/cpu/cpuN/dscr
44*4d2e26a3SMauro Carvalho Chehab
45*4d2e26a3SMauro Carvalho Chehab	Changing the global DSCR default in the sysfs will change all the CPU
46*4d2e26a3SMauro Carvalho Chehab	specific DSCR defaults immediately in their PACA structures. Again if
47*4d2e26a3SMauro Carvalho Chehab	the current process has the dscr_inherit clear, it also writes the new
48*4d2e26a3SMauro Carvalho Chehab	value into every CPU's DSCR register right away and updates the current
49*4d2e26a3SMauro Carvalho Chehab	thread's DSCR value as well.
50*4d2e26a3SMauro Carvalho Chehab
51*4d2e26a3SMauro Carvalho Chehab	Changing the CPU specific DSCR default value in the sysfs does exactly
52*4d2e26a3SMauro Carvalho Chehab	the same thing as above but unlike the global one above, it just changes
53*4d2e26a3SMauro Carvalho Chehab	stuff for that particular CPU instead for all the CPUs on the system.
54*4d2e26a3SMauro Carvalho Chehab
55*4d2e26a3SMauro Carvalho Chehab(D) User Space Instructions:
56*4d2e26a3SMauro Carvalho Chehab
57*4d2e26a3SMauro Carvalho Chehab	The DSCR register can be accessed in the user space using any of these
58*4d2e26a3SMauro Carvalho Chehab	two SPR numbers available for that purpose.
59*4d2e26a3SMauro Carvalho Chehab
60*4d2e26a3SMauro Carvalho Chehab	(1) Problem state SPR:		0x03	(Un-privileged, POWER8 only)
61*4d2e26a3SMauro Carvalho Chehab	(2) Privileged state SPR:	0x11	(Privileged)
62*4d2e26a3SMauro Carvalho Chehab
63*4d2e26a3SMauro Carvalho Chehab	Accessing DSCR through privileged SPR number (0x11) from user space
64*4d2e26a3SMauro Carvalho Chehab	works, as it is emulated following an illegal instruction exception
65*4d2e26a3SMauro Carvalho Chehab	inside the kernel. Both mfspr and mtspr instructions are emulated.
66*4d2e26a3SMauro Carvalho Chehab
67*4d2e26a3SMauro Carvalho Chehab	Accessing DSCR through user level SPR (0x03) from user space will first
68*4d2e26a3SMauro Carvalho Chehab	create a facility unavailable exception. Inside this exception handler
69*4d2e26a3SMauro Carvalho Chehab	all mfspr instruction based read attempts will get emulated and returned
70*4d2e26a3SMauro Carvalho Chehab	where as the first mtspr instruction based write attempts will enable
71*4d2e26a3SMauro Carvalho Chehab	the DSCR facility for the next time around (both for read and write) by
72*4d2e26a3SMauro Carvalho Chehab	setting DSCR facility in the FSCR register.
73*4d2e26a3SMauro Carvalho Chehab
74*4d2e26a3SMauro Carvalho Chehab(E) Specifics about 'dscr_inherit':
75*4d2e26a3SMauro Carvalho Chehab
76*4d2e26a3SMauro Carvalho Chehab	The thread struct element 'dscr_inherit' represents whether the thread
77*4d2e26a3SMauro Carvalho Chehab	in question has attempted and changed the DSCR itself using any of the
78*4d2e26a3SMauro Carvalho Chehab	following methods. This element signifies whether the thread wants to
79*4d2e26a3SMauro Carvalho Chehab	use the CPU default DSCR value or its own changed DSCR value in the
80*4d2e26a3SMauro Carvalho Chehab	kernel.
81*4d2e26a3SMauro Carvalho Chehab
82*4d2e26a3SMauro Carvalho Chehab		(1) mtspr instruction	(SPR number 0x03)
83*4d2e26a3SMauro Carvalho Chehab		(2) mtspr instruction	(SPR number 0x11)
84*4d2e26a3SMauro Carvalho Chehab		(3) ptrace interface	(Explicitly set user DSCR value)
85*4d2e26a3SMauro Carvalho Chehab
86*4d2e26a3SMauro Carvalho Chehab	Any child of the process created after this event in the process inherits
87*4d2e26a3SMauro Carvalho Chehab	this same behaviour as well.
88