cpu_features.txt 2.6 KB

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