mtrr.h 3.2 KB

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