~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/Documentation/arch/powerpc/cpu_features.rst

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 ============
  2 CPU Features
  3 ============
  4 
  5 Hollis Blanchard <hollis@austin.ibm.com>
  6 5 Jun 2002
  7 
  8 This document describes the system (including self-modifying code) used in the
  9 PPC Linux kernel to support a variety of PowerPC CPUs without requiring
 10 compile-time selection.
 11 
 12 Early in the boot process the ppc32 kernel detects the current CPU type and
 13 chooses a set of features accordingly. Some examples include Altivec support,
 14 split instruction and data caches, and if the CPU supports the DOZE and NAP
 15 sleep modes.
 16 
 17 Detection of the feature set is simple. A list of processors can be found in
 18 arch/powerpc/kernel/cputable.c. The PVR register is masked and compared with
 19 each value in the list. If a match is found, the cpu_features of cur_cpu_spec
 20 is assigned to the feature bitmask for this processor and a __setup_cpu
 21 function is called.
 22 
 23 C code may test 'cur_cpu_spec[smp_processor_id()]->cpu_features' for a
 24 particular feature bit. This is done in quite a few places, for example
 25 in ppc_setup_l2cr().
 26 
 27 Implementing cpufeatures in assembly is a little more involved. There are
 28 several paths that are performance-critical and would suffer if an array
 29 index, structure dereference, and conditional branch were added. To avoid the
 30 performance penalty but still allow for runtime (rather than compile-time) CPU
 31 selection, unused code is replaced by 'nop' instructions. This nop'ing is
 32 based on CPU 0's capabilities, so a multi-processor system with non-identical
 33 processors will not work (but such a system would likely have other problems
 34 anyways).
 35 
 36 After detecting the processor type, the kernel patches out sections of code
 37 that shouldn't be used by writing nop's over it. Using cpufeatures requires
 38 just 2 macros (found in arch/powerpc/include/asm/cputable.h), as seen in head.S
 39 transfer_to_handler::
 40 
 41         #ifdef CONFIG_ALTIVEC
 42         BEGIN_FTR_SECTION
 43                 mfspr   r22,SPRN_VRSAVE         /* if G4, save vrsave register value */
 44                 stw     r22,THREAD_VRSAVE(r23)
 45         END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
 46         #endif /* CONFIG_ALTIVEC */
 47 
 48 If CPU 0 supports Altivec, the code is left untouched. If it doesn't, both
 49 instructions are replaced with nop's.
 50 
 51 The END_FTR_SECTION macro has two simpler variations: END_FTR_SECTION_IFSET
 52 and END_FTR_SECTION_IFCLR. These simply test if a flag is set (in
 53 cur_cpu_spec[0]->cpu_features) or is cleared, respectively. These two macros
 54 should be used in the majority of cases.
 55 
 56 The END_FTR_SECTION macros are implemented by storing information about this
 57 code in the '__ftr_fixup' ELF section. When do_cpu_ftr_fixups
 58 (arch/powerpc/kernel/misc.S) is invoked, it will iterate over the records in
 59 __ftr_fixup, and if the required feature is not present it will loop writing
 60 nop's from each BEGIN_FTR_SECTION to END_FTR_SECTION.

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php