mcrmrc.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* Copyright (c) 2010, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. */
  13. /*
  14. mrcmcr.h
  15. DESCRIPTION: Convenience macros for access the cp registers in the arm.
  16. REV/DATE: Fri Mar 18 16:34:44 EST 2005
  17. */
  18. #ifndef __mrcmcr__h_
  19. #define __mrcmcr__h_
  20. /*
  21. * Define some convenience macros to acccess the cp registers from c code
  22. * Lots of macro trickery here.
  23. *
  24. * Takes the same format as the asm instructions and unfortunatly you cannot
  25. * use variables to select the crn, crn or op fields...
  26. *
  27. * For those unfamiliar with the # and string stuff.
  28. * # creates a string from the value and any two strings that are beside
  29. * are concatenated...thus these create one big asm string for the
  30. * inline asm code.
  31. *
  32. * When compiled these compile to single asm instructions (fast) but
  33. * without all the hassel of __asm__ __volatile__ (...) =r
  34. *
  35. * Format is:
  36. *
  37. * unsigned long reg; // destination variable
  38. * MRC(reg, p15, 0, c1, c0, 0 );
  39. *
  40. * MRC read control register
  41. * MCR control register write
  42. */
  43. /*
  44. * Some assembly macros so we can use the same macros as in the C version.
  45. * Turns the ASM code a little C-ish but keeps the code consistent and in
  46. * one location...
  47. */
  48. #ifdef __ASSEMBLY__
  49. #define MRC(reg, processor, op1, crn, crm, op2) \
  50. (mrc processor , op1 , reg, crn , crm , op2)
  51. #define MCR(reg, processor, op1, crn, crm, op2) \
  52. (mcr processor , op1 , reg, crn , crm , op2)
  53. /*
  54. * C version of the macros.
  55. */
  56. #else
  57. #define MRC(reg, processor, op1, crn, crm, op2) \
  58. __asm__ __volatile__ ( \
  59. " mrc " #processor "," #op1 ", %0," #crn "," #crm "," #op2 "\n" \
  60. : "=r" (reg))
  61. #define MCR(reg, processor, op1, crn, crm, op2) \
  62. __asm__ __volatile__ ( \
  63. " mcr " #processor "," #op1 ", %0," #crn "," #crm "," #op2 "\n" \
  64. : : "r" (reg))
  65. #endif
  66. /*
  67. * Easy access convenience function to read CP15 registers from c code
  68. */
  69. #define MRC15(reg, op1, crn, crm, op2) MRC(reg, p15, op1, crn, crm, op2)
  70. #define MCR15(reg, op1, crn, crm, op2) MCR(reg, p15, op1, crn, crm, op2)
  71. #endif