summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorAaron Durbin <adurbin@chromium.org>2020-05-28 21:21:49 -0600
committerAaron Durbin <adurbin@chromium.org>2020-06-02 16:09:58 +0000
commitfa5eded303ac25c95ca4300ebfb4788c149bf2ab (patch)
tree2baed17b0f6e99b449c6ac93b81314cc633c4a45 /src/include
parenta21eae0441209d596fd39ad6f394136c87b9ff91 (diff)
cpu/x86/mtrr: add helper for setting multiple MTRRs
Introduce concept of var_mtrr_context object for tracking and assigning MTRR values. The algorithm is lifted from postcar_loader code, but it's generalized for different type of users: setting MSRs explicitly or deferring to a particular caller's desired actions. BUG=b:155426691,b:155322763 Change-Id: Ic03b4b617196f04071093bbba4cf28d23fa482d8 Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/41849 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Furquan Shaikh <furquan@google.com>
Diffstat (limited to 'src/include')
-rw-r--r--src/include/cpu/x86/mtrr.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/include/cpu/x86/mtrr.h b/src/include/cpu/x86/mtrr.h
index 301ea3052d..c1ee51accf 100644
--- a/src/include/cpu/x86/mtrr.h
+++ b/src/include/cpu/x86/mtrr.h
@@ -110,6 +110,37 @@ void clear_all_var_mtrr(void);
asmlinkage void display_mtrrs(void);
+/* Variable MTRR structure to help track and set MTRRs prior to ramstage. This
+ and the following APIs can be used to set up more complex MTRR solutions
+ instead of open coding get_free_var_mtrr() and set_var_mtrr() or for determining
+ a future solution, such as postcar_loader. */
+struct var_mtrr_context {
+ uint32_t upper_mask;
+ int max_var_mtrrs;
+ int used_var_mtrrs;
+ void *arg; /* optional callback parameter */
+};
+
+/* Returns 0-relative MTRR from context. Use MTRR_PHYS_BASE|MASK macros for calculating
+ MSR address value. */
+static inline int var_mtrr_context_current_mtrr(const struct var_mtrr_context *ctx)
+{
+ return ctx->used_var_mtrrs;
+}
+
+/* Initialize var_mtrr_context object. Assumes all variable MTRRs are not yet used. */
+void var_mtrr_context_init(struct var_mtrr_context *ctx, void *arg);
+/* Allocate a variable mtrr base and mask, calling the provided callback for each MTRR
+ MSR base-mask pair needed to accommodate the address and size request.
+ Returns < 0 on error and 0 on success. */
+int var_mtrr_set_with_cb(struct var_mtrr_context *ctx,
+ uintptr_t addr, size_t size, int type,
+ void (*callback)(const struct var_mtrr_context *ctx,
+ uintptr_t base_addr, size_t size,
+ msr_t base, msr_t mask));
+/* Same as var_mtrr_set_with_cb() but just write the MSRs directly. */
+int var_mtrr_set(struct var_mtrr_context *ctx, uintptr_t addr, size_t size, int type);
+
/*
* Set the MTRRs using the data on the stack from setup_stack_and_mtrrs.
* Return a new top_of_stack value which removes the setup_stack_and_mtrrs data.