maar.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright (C) 2014 Imagination Technologies
  3. * Author: Paul Burton <paul.burton@mips.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. */
  10. #ifndef __MIPS_ASM_MIPS_MAAR_H__
  11. #define __MIPS_ASM_MIPS_MAAR_H__
  12. #include <asm/hazards.h>
  13. #include <asm/mipsregs.h>
  14. /**
  15. * platform_maar_init() - perform platform-level MAAR configuration
  16. * @num_pairs: The number of MAAR pairs present in the system.
  17. *
  18. * Platforms should implement this function such that it configures as many
  19. * MAAR pairs as required, from 0 up to the maximum of num_pairs-1, and returns
  20. * the number that were used. Any further MAARs will be configured to be
  21. * invalid. The default implementation of this function will simply indicate
  22. * that it has configured 0 MAAR pairs.
  23. *
  24. * Return: The number of MAAR pairs configured.
  25. */
  26. unsigned platform_maar_init(unsigned num_pairs);
  27. /**
  28. * write_maar_pair() - write to a pair of MAARs
  29. * @idx: The index of the pair (ie. use MAARs idx*2 & (idx*2)+1).
  30. * @lower: The lowest address that the MAAR pair will affect. Must be
  31. * aligned to a 2^16 byte boundary.
  32. * @upper: The highest address that the MAAR pair will affect. Must be
  33. * aligned to one byte before a 2^16 byte boundary.
  34. * @attrs: The accessibility attributes to program, eg. MIPS_MAAR_S. The
  35. * MIPS_MAAR_VL attribute will automatically be set.
  36. *
  37. * Program the pair of MAAR registers specified by idx to apply the attributes
  38. * specified by attrs to the range of addresses from lower to higher.
  39. */
  40. static inline void write_maar_pair(unsigned idx, phys_addr_t lower,
  41. phys_addr_t upper, unsigned attrs)
  42. {
  43. /* Addresses begin at bit 16, but are shifted right 4 bits */
  44. BUG_ON(lower & (0xffff | ~(MIPS_MAAR_ADDR << 4)));
  45. BUG_ON(((upper & 0xffff) != 0xffff)
  46. || ((upper & ~0xffffull) & ~(MIPS_MAAR_ADDR << 4)));
  47. /* Automatically set MIPS_MAAR_VL */
  48. attrs |= MIPS_MAAR_VL;
  49. /* Write the upper address & attributes (only MIPS_MAAR_VL matters) */
  50. write_c0_maari(idx << 1);
  51. back_to_back_c0_hazard();
  52. write_c0_maar(((upper >> 4) & MIPS_MAAR_ADDR) | attrs);
  53. back_to_back_c0_hazard();
  54. /* Write the lower address & attributes */
  55. write_c0_maari((idx << 1) | 0x1);
  56. back_to_back_c0_hazard();
  57. write_c0_maar((lower >> 4) | attrs);
  58. back_to_back_c0_hazard();
  59. }
  60. /**
  61. * maar_init() - initialise MAARs
  62. *
  63. * Performs initialisation of MAARs for the current CPU, making use of the
  64. * platforms implementation of platform_maar_init where necessary and
  65. * duplicating the setup it provides on secondary CPUs.
  66. */
  67. extern void maar_init(void);
  68. /**
  69. * struct maar_config - MAAR configuration data
  70. * @lower: The lowest address that the MAAR pair will affect. Must be
  71. * aligned to a 2^16 byte boundary.
  72. * @upper: The highest address that the MAAR pair will affect. Must be
  73. * aligned to one byte before a 2^16 byte boundary.
  74. * @attrs: The accessibility attributes to program, eg. MIPS_MAAR_S. The
  75. * MIPS_MAAR_VL attribute will automatically be set.
  76. *
  77. * Describes the configuration of a pair of Memory Accessibility Attribute
  78. * Registers - applying attributes from attrs to the range of physical
  79. * addresses from lower to upper inclusive.
  80. */
  81. struct maar_config {
  82. phys_addr_t lower;
  83. phys_addr_t upper;
  84. unsigned attrs;
  85. };
  86. /**
  87. * maar_config() - configure MAARs according to provided data
  88. * @cfg: Pointer to an array of struct maar_config.
  89. * @num_cfg: The number of structs in the cfg array.
  90. * @num_pairs: The number of MAAR pairs present in the system.
  91. *
  92. * Configures as many MAARs as are present and specified in the cfg
  93. * array with the values taken from the cfg array.
  94. *
  95. * Return: The number of MAAR pairs configured.
  96. */
  97. static inline unsigned maar_config(const struct maar_config *cfg,
  98. unsigned num_cfg, unsigned num_pairs)
  99. {
  100. unsigned i;
  101. for (i = 0; i < min(num_cfg, num_pairs); i++)
  102. write_maar_pair(i, cfg[i].lower, cfg[i].upper, cfg[i].attrs);
  103. return i;
  104. }
  105. #endif /* __MIPS_ASM_MIPS_MAAR_H__ */