mtrr.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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_DEF_TYPE_EN (1 << 11)
  20. #define MTRR_DEF_TYPE_FIX_EN (1 << 10)
  21. #define MTRR_PHYS_BASE_MSR(reg) (0x200 + 2 * (reg))
  22. #define MTRR_PHYS_MASK_MSR(reg) (0x200 + 2 * (reg) + 1)
  23. #define MTRR_PHYS_MASK_VALID (1 << 11)
  24. #define MTRR_BASE_TYPE_MASK 0x7
  25. /* Number of MTRRs supported */
  26. #define MTRR_COUNT 8
  27. #if !defined(__ASSEMBLER__)
  28. /**
  29. * Information about the previous MTRR state, set up by mtrr_open()
  30. *
  31. * @deftype: Previous value of MTRR_DEF_TYPE_MSR
  32. * @enable_cache: true if cache was enabled
  33. */
  34. struct mtrr_state {
  35. uint64_t deftype;
  36. bool enable_cache;
  37. };
  38. /**
  39. * mtrr_open() - Prepare to adjust MTRRs
  40. *
  41. * Use mtrr_open() passing in a structure - this function will init it. Then
  42. * when done, pass the same structure to mtrr_close() to re-enable MTRRs and
  43. * possibly the cache.
  44. *
  45. * @state: Empty structure to pass in to hold settings
  46. */
  47. void mtrr_open(struct mtrr_state *state);
  48. /**
  49. * mtrr_open() - Clean up after adjusting MTRRs, and enable them
  50. *
  51. * This uses the structure containing information returned from mtrr_open().
  52. *
  53. * @state: Structure from mtrr_open()
  54. */
  55. /* */
  56. void mtrr_close(struct mtrr_state *state);
  57. /**
  58. * mtrr_add_request() - Add a new MTRR request
  59. *
  60. * This adds a request for a memory region to be set up in a particular way.
  61. *
  62. * @type: Requested type (MTRR_TYPE_)
  63. * @start: Start address
  64. * @size: Size
  65. */
  66. int mtrr_add_request(int type, uint64_t start, uint64_t size);
  67. /**
  68. * mtrr_commit() - set up the MTRR registers based on current requests
  69. *
  70. * This sets up MTRRs for the available DRAM and the requests received so far.
  71. * It must be called with caches disabled.
  72. *
  73. * @do_caches: true if caches are currently on
  74. */
  75. int mtrr_commit(bool do_caches);
  76. #endif
  77. #if ((CONFIG_XIP_ROM_SIZE & (CONFIG_XIP_ROM_SIZE - 1)) != 0)
  78. # error "CONFIG_XIP_ROM_SIZE is not a power of 2"
  79. #endif
  80. #if ((CONFIG_CACHE_ROM_SIZE & (CONFIG_CACHE_ROM_SIZE - 1)) != 0)
  81. # error "CONFIG_CACHE_ROM_SIZE is not a power of 2"
  82. #endif
  83. #define CACHE_ROM_BASE (((1 << 20) - (CONFIG_CACHE_ROM_SIZE >> 12)) << 12)
  84. #endif