mtrr.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (c) 2014 Google, Inc
  4. *
  5. * From Coreboot file of the same name
  6. */
  7. #ifndef _ASM_MTRR_H
  8. #define _ASM_MTRR_H
  9. /* MTRR region types */
  10. #define MTRR_TYPE_UNCACHEABLE 0
  11. #define MTRR_TYPE_WRCOMB 1
  12. #define MTRR_TYPE_WRTHROUGH 4
  13. #define MTRR_TYPE_WRPROT 5
  14. #define MTRR_TYPE_WRBACK 6
  15. #define MTRR_TYPE_COUNT 7
  16. #define MTRR_CAP_MSR 0x0fe
  17. #define MTRR_DEF_TYPE_MSR 0x2ff
  18. #define MTRR_CAP_SMRR (1 << 11)
  19. #define MTRR_CAP_WC (1 << 10)
  20. #define MTRR_CAP_FIX (1 << 8)
  21. #define MTRR_CAP_VCNT_MASK 0xff
  22. #define MTRR_DEF_TYPE_EN (1 << 11)
  23. #define MTRR_DEF_TYPE_FIX_EN (1 << 10)
  24. #define MTRR_PHYS_BASE_MSR(reg) (0x200 + 2 * (reg))
  25. #define MTRR_PHYS_MASK_MSR(reg) (0x200 + 2 * (reg) + 1)
  26. #define MTRR_PHYS_MASK_VALID (1 << 11)
  27. #define MTRR_BASE_TYPE_MASK 0x7
  28. /* Number of MTRRs supported */
  29. #define MTRR_COUNT 8
  30. #define NUM_FIXED_MTRRS 11
  31. #define RANGES_PER_FIXED_MTRR 8
  32. #define NUM_FIXED_RANGES (NUM_FIXED_MTRRS * RANGES_PER_FIXED_MTRR)
  33. #define MTRR_FIX_64K_00000_MSR 0x250
  34. #define MTRR_FIX_16K_80000_MSR 0x258
  35. #define MTRR_FIX_16K_A0000_MSR 0x259
  36. #define MTRR_FIX_4K_C0000_MSR 0x268
  37. #define MTRR_FIX_4K_C8000_MSR 0x269
  38. #define MTRR_FIX_4K_D0000_MSR 0x26a
  39. #define MTRR_FIX_4K_D8000_MSR 0x26b
  40. #define MTRR_FIX_4K_E0000_MSR 0x26c
  41. #define MTRR_FIX_4K_E8000_MSR 0x26d
  42. #define MTRR_FIX_4K_F0000_MSR 0x26e
  43. #define MTRR_FIX_4K_F8000_MSR 0x26f
  44. #define MTRR_FIX_TYPE(t) ((t << 24) | (t << 16) | (t << 8) | t)
  45. #if !defined(__ASSEMBLER__)
  46. /**
  47. * Information about the previous MTRR state, set up by mtrr_open()
  48. *
  49. * @deftype: Previous value of MTRR_DEF_TYPE_MSR
  50. * @enable_cache: true if cache was enabled
  51. */
  52. struct mtrr_state {
  53. uint64_t deftype;
  54. bool enable_cache;
  55. };
  56. /**
  57. * mtrr_open() - Prepare to adjust MTRRs
  58. *
  59. * Use mtrr_open() passing in a structure - this function will init it. Then
  60. * when done, pass the same structure to mtrr_close() to re-enable MTRRs and
  61. * possibly the cache.
  62. *
  63. * @state: Empty structure to pass in to hold settings
  64. * @do_caches: true to disable caches before opening
  65. */
  66. void mtrr_open(struct mtrr_state *state, bool do_caches);
  67. /**
  68. * mtrr_open() - Clean up after adjusting MTRRs, and enable them
  69. *
  70. * This uses the structure containing information returned from mtrr_open().
  71. *
  72. * @state: Structure from mtrr_open()
  73. * @state: true to restore cache state to that before mtrr_open()
  74. */
  75. void mtrr_close(struct mtrr_state *state, bool do_caches);
  76. /**
  77. * mtrr_add_request() - Add a new MTRR request
  78. *
  79. * This adds a request for a memory region to be set up in a particular way.
  80. *
  81. * @type: Requested type (MTRR_TYPE_)
  82. * @start: Start address
  83. * @size: Size
  84. *
  85. * @return: 0 on success, non-zero on failure
  86. */
  87. int mtrr_add_request(int type, uint64_t start, uint64_t size);
  88. /**
  89. * mtrr_commit() - set up the MTRR registers based on current requests
  90. *
  91. * This sets up MTRRs for the available DRAM and the requests received so far.
  92. * It must be called with caches disabled.
  93. *
  94. * @do_caches: true if caches are currently on
  95. *
  96. * @return: 0 on success, non-zero on failure
  97. */
  98. int mtrr_commit(bool do_caches);
  99. #endif
  100. #if ((CONFIG_XIP_ROM_SIZE & (CONFIG_XIP_ROM_SIZE - 1)) != 0)
  101. # error "CONFIG_XIP_ROM_SIZE is not a power of 2"
  102. #endif
  103. #if ((CONFIG_CACHE_ROM_SIZE & (CONFIG_CACHE_ROM_SIZE - 1)) != 0)
  104. # error "CONFIG_CACHE_ROM_SIZE is not a power of 2"
  105. #endif
  106. #define CACHE_ROM_BASE (((1 << 20) - (CONFIG_CACHE_ROM_SIZE >> 12)) << 12)
  107. #endif