sysreg.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Macros for accessing system registers with older binutils.
  3. *
  4. * Copyright (C) 2014 ARM Ltd.
  5. * Author: Catalin Marinas <catalin.marinas@arm.com>
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef __ASM_SYSREG_H
  20. #define __ASM_SYSREG_H
  21. #include <asm/opcodes.h>
  22. #define SCTLR_EL1_CP15BEN (0x1 << 5)
  23. #define SCTLR_EL1_SED (0x1 << 8)
  24. /*
  25. * ARMv8 ARM reserves the following encoding for system registers:
  26. * (Ref: ARMv8 ARM, Section: "System instruction class encoding overview",
  27. * C5.2, version:ARM DDI 0487A.f)
  28. * [20-19] : Op0
  29. * [18-16] : Op1
  30. * [15-12] : CRn
  31. * [11-8] : CRm
  32. * [7-5] : Op2
  33. */
  34. #define sys_reg(op0, op1, crn, crm, op2) \
  35. ((((op0)&3)<<19)|((op1)<<16)|((crn)<<12)|((crm)<<8)|((op2)<<5))
  36. #define REG_PSTATE_PAN_IMM sys_reg(0, 0, 4, 0, 4)
  37. #define SCTLR_EL1_SPAN (1 << 23)
  38. #define SET_PSTATE_PAN(x) __inst_arm(0xd5000000 | REG_PSTATE_PAN_IMM |\
  39. (!!x)<<8 | 0x1f)
  40. #ifdef __ASSEMBLY__
  41. .irp num,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30
  42. .equ __reg_num_x\num, \num
  43. .endr
  44. .equ __reg_num_xzr, 31
  45. .macro mrs_s, rt, sreg
  46. .inst 0xd5200000|(\sreg)|(__reg_num_\rt)
  47. .endm
  48. .macro msr_s, sreg, rt
  49. .inst 0xd5000000|(\sreg)|(__reg_num_\rt)
  50. .endm
  51. #else
  52. asm(
  53. " .irp num,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30\n"
  54. " .equ __reg_num_x\\num, \\num\n"
  55. " .endr\n"
  56. " .equ __reg_num_xzr, 31\n"
  57. "\n"
  58. " .macro mrs_s, rt, sreg\n"
  59. " .inst 0xd5200000|(\\sreg)|(__reg_num_\\rt)\n"
  60. " .endm\n"
  61. "\n"
  62. " .macro msr_s, sreg, rt\n"
  63. " .inst 0xd5000000|(\\sreg)|(__reg_num_\\rt)\n"
  64. " .endm\n"
  65. );
  66. static inline void config_sctlr_el1(u32 clear, u32 set)
  67. {
  68. u32 val;
  69. asm volatile("mrs %0, sctlr_el1" : "=r" (val));
  70. val &= ~clear;
  71. val |= set;
  72. asm volatile("msr sctlr_el1, %0" : : "r" (val));
  73. }
  74. #endif
  75. #endif /* __ASM_SYSREG_H */