xlat_helpers.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * Redistributions of source code must retain the above copyright notice, this
  8. * list of conditions and the following disclaimer.
  9. *
  10. * Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. *
  14. * Neither the name of ARM nor the names of its contributors may be used
  15. * to endorse or promote products derived from this software without specific
  16. * prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  22. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  23. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  24. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  25. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  26. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #include <string.h>
  31. #include <assert.h>
  32. #include <arch.h>
  33. /*******************************************************************************
  34. * Helper to create a level 1/2 table descriptor which points to a level 2/3
  35. * table.
  36. ******************************************************************************/
  37. unsigned long create_table_desc(unsigned long *next_table_ptr)
  38. {
  39. unsigned long desc = (unsigned long) next_table_ptr;
  40. /* Clear the last 12 bits */
  41. desc >>= FOUR_KB_SHIFT;
  42. desc <<= FOUR_KB_SHIFT;
  43. desc |= TABLE_DESC;
  44. return desc;
  45. }
  46. /*******************************************************************************
  47. * Helper to create a level 1/2/3 block descriptor which maps the va to addr
  48. ******************************************************************************/
  49. unsigned long create_block_desc(unsigned long desc,
  50. unsigned long addr,
  51. unsigned int level)
  52. {
  53. switch (level) {
  54. case LEVEL1:
  55. desc |= (addr << FIRST_LEVEL_DESC_N) | BLOCK_DESC;
  56. break;
  57. case LEVEL2:
  58. desc |= (addr << SECOND_LEVEL_DESC_N) | BLOCK_DESC;
  59. break;
  60. case LEVEL3:
  61. desc |= (addr << THIRD_LEVEL_DESC_N) | TABLE_DESC;
  62. break;
  63. default:
  64. assert(0);
  65. }
  66. return desc;
  67. }
  68. /*******************************************************************************
  69. * Helper to create a level 1/2/3 block descriptor which maps the va to output_
  70. * addr with Device nGnRE attributes.
  71. ******************************************************************************/
  72. unsigned long create_device_block(unsigned long output_addr,
  73. unsigned int level,
  74. unsigned int ns)
  75. {
  76. unsigned long upper_attrs, lower_attrs, desc;
  77. lower_attrs = LOWER_ATTRS(ACCESS_FLAG | OSH | AP_RW);
  78. lower_attrs |= LOWER_ATTRS(ns | ATTR_DEVICE_INDEX);
  79. upper_attrs = UPPER_ATTRS(XN);
  80. desc = upper_attrs | lower_attrs;
  81. return create_block_desc(desc, output_addr, level);
  82. }
  83. /*******************************************************************************
  84. * Helper to create a level 1/2/3 block descriptor which maps the va to output_
  85. * addr with inner-shareable normal wbwa read-only memory attributes.
  86. ******************************************************************************/
  87. unsigned long create_romem_block(unsigned long output_addr,
  88. unsigned int level,
  89. unsigned int ns)
  90. {
  91. unsigned long upper_attrs, lower_attrs, desc;
  92. lower_attrs = LOWER_ATTRS(ACCESS_FLAG | ISH | AP_RO);
  93. lower_attrs |= LOWER_ATTRS(ns | ATTR_IWBWA_OWBWA_NTR_INDEX);
  94. upper_attrs = UPPER_ATTRS(0ull);
  95. desc = upper_attrs | lower_attrs;
  96. return create_block_desc(desc, output_addr, level);
  97. }
  98. /*******************************************************************************
  99. * Helper to create a level 1/2/3 block descriptor which maps the va to output_
  100. * addr with inner-shareable normal wbwa read-write memory attributes.
  101. ******************************************************************************/
  102. unsigned long create_rwmem_block(unsigned long output_addr,
  103. unsigned int level,
  104. unsigned int ns)
  105. {
  106. unsigned long upper_attrs, lower_attrs, desc;
  107. lower_attrs = LOWER_ATTRS(ACCESS_FLAG | ISH | AP_RW);
  108. lower_attrs |= LOWER_ATTRS(ns | ATTR_IWBWA_OWBWA_NTR_INDEX);
  109. upper_attrs = UPPER_ATTRS(XN);
  110. desc = upper_attrs | lower_attrs;
  111. return create_block_desc(desc, output_addr, level);
  112. }