18c2ecf20Sopenharmony_ci===================================
28c2ecf20Sopenharmony_ciDSCR (Data Stream Control Register)
38c2ecf20Sopenharmony_ci===================================
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ciDSCR register in powerpc allows user to have some control of prefetch of data
68c2ecf20Sopenharmony_cistream in the processor. Please refer to the ISA documents or related manual
78c2ecf20Sopenharmony_cifor more detailed information regarding how to use this DSCR to attain this
88c2ecf20Sopenharmony_cicontrol of the prefetches . This document here provides an overview of kernel
98c2ecf20Sopenharmony_cisupport for DSCR, related kernel objects, it's functionalities and exported
108c2ecf20Sopenharmony_ciuser interface.
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci(A) Data Structures:
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci	(1) thread_struct::
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci		dscr		/* Thread DSCR value */
178c2ecf20Sopenharmony_ci		dscr_inherit	/* Thread has changed default DSCR */
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci	(2) PACA::
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci		dscr_default	/* per-CPU DSCR default value */
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci	(3) sysfs.c::
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci		dscr_default	/* System DSCR default value */
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci(B) Scheduler Changes:
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci	Scheduler will write the per-CPU DSCR default which is stored in the
308c2ecf20Sopenharmony_ci	CPU's PACA value into the register if the thread has dscr_inherit value
318c2ecf20Sopenharmony_ci	cleared which means that it has not changed the default DSCR till now.
328c2ecf20Sopenharmony_ci	If the dscr_inherit value is set which means that it has changed the
338c2ecf20Sopenharmony_ci	default DSCR value, scheduler will write the changed value which will
348c2ecf20Sopenharmony_ci	now be contained in thread struct's dscr into the register instead of
358c2ecf20Sopenharmony_ci	the per-CPU default PACA based DSCR value.
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci	NOTE: Please note here that the system wide global DSCR value never
388c2ecf20Sopenharmony_ci	gets used directly in the scheduler process context switch at all.
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci(C) SYSFS Interface:
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci	- Global DSCR default:		/sys/devices/system/cpu/dscr_default
438c2ecf20Sopenharmony_ci	- CPU specific DSCR default:	/sys/devices/system/cpu/cpuN/dscr
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci	Changing the global DSCR default in the sysfs will change all the CPU
468c2ecf20Sopenharmony_ci	specific DSCR defaults immediately in their PACA structures. Again if
478c2ecf20Sopenharmony_ci	the current process has the dscr_inherit clear, it also writes the new
488c2ecf20Sopenharmony_ci	value into every CPU's DSCR register right away and updates the current
498c2ecf20Sopenharmony_ci	thread's DSCR value as well.
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci	Changing the CPU specific DSCR default value in the sysfs does exactly
528c2ecf20Sopenharmony_ci	the same thing as above but unlike the global one above, it just changes
538c2ecf20Sopenharmony_ci	stuff for that particular CPU instead for all the CPUs on the system.
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci(D) User Space Instructions:
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci	The DSCR register can be accessed in the user space using any of these
588c2ecf20Sopenharmony_ci	two SPR numbers available for that purpose.
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci	(1) Problem state SPR:		0x03	(Un-privileged, POWER8 only)
618c2ecf20Sopenharmony_ci	(2) Privileged state SPR:	0x11	(Privileged)
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci	Accessing DSCR through privileged SPR number (0x11) from user space
648c2ecf20Sopenharmony_ci	works, as it is emulated following an illegal instruction exception
658c2ecf20Sopenharmony_ci	inside the kernel. Both mfspr and mtspr instructions are emulated.
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci	Accessing DSCR through user level SPR (0x03) from user space will first
688c2ecf20Sopenharmony_ci	create a facility unavailable exception. Inside this exception handler
698c2ecf20Sopenharmony_ci	all mfspr instruction based read attempts will get emulated and returned
708c2ecf20Sopenharmony_ci	where as the first mtspr instruction based write attempts will enable
718c2ecf20Sopenharmony_ci	the DSCR facility for the next time around (both for read and write) by
728c2ecf20Sopenharmony_ci	setting DSCR facility in the FSCR register.
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci(E) Specifics about 'dscr_inherit':
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci	The thread struct element 'dscr_inherit' represents whether the thread
778c2ecf20Sopenharmony_ci	in question has attempted and changed the DSCR itself using any of the
788c2ecf20Sopenharmony_ci	following methods. This element signifies whether the thread wants to
798c2ecf20Sopenharmony_ci	use the CPU default DSCR value or its own changed DSCR value in the
808c2ecf20Sopenharmony_ci	kernel.
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci		(1) mtspr instruction	(SPR number 0x03)
838c2ecf20Sopenharmony_ci		(2) mtspr instruction	(SPR number 0x11)
848c2ecf20Sopenharmony_ci		(3) ptrace interface	(Explicitly set user DSCR value)
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	Any child of the process created after this event in the process inherits
878c2ecf20Sopenharmony_ci	this same behaviour as well.
88