|
| 1 | +/* |
| 2 | + * Copyright (c) 2022 Amazon.com, Inc. or its affiliates. |
| 3 | + * All Rights Reserved. |
| 4 | + * |
| 5 | + * Redistribution and use in source and binary forms, with or without |
| 6 | + * modification, are permitted provided that the following conditions are met: |
| 7 | + * |
| 8 | + * 1. Redistributions of source code must retain the above copyright notice, this |
| 9 | + * list of conditions and the following disclaimer. |
| 10 | + * 2. 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 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 15 | + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 16 | + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 17 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
| 18 | + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 19 | + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 20 | + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 21 | + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 23 | + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | + */ |
| 25 | +#ifndef KTF_MTRR_H |
| 26 | +#define KTF_MTRR_H |
| 27 | + |
| 28 | +#include <ktf.h> |
| 29 | + |
| 30 | +enum mtrr_memory_type { |
| 31 | + MTRR_UC = 0, /* Uncacheable */ |
| 32 | + MTRR_WC = 1, /* Write Combining */ |
| 33 | + MTRR_WT = 4, /* Write Through */ |
| 34 | + MTRR_WP, /* Write Protected */ |
| 35 | + MTRR_WB, /* Write Back */ |
| 36 | +}; |
| 37 | +typedef enum mtrr_memory_type mtrr_memory_type_t; |
| 38 | + |
| 39 | +union mtrr_cap { |
| 40 | + struct { |
| 41 | + /* clang-format off */ |
| 42 | + uint64_t vcnt : 8, |
| 43 | + fix : 1, |
| 44 | + _rsvd : 1, |
| 45 | + wc : 1, |
| 46 | + _rsvd2 : 53; |
| 47 | + /* clang-format on */ |
| 48 | + } __packed; |
| 49 | + uint64_t reg; |
| 50 | +}; |
| 51 | +typedef union mtrr_cap mtrr_cap_t; |
| 52 | + |
| 53 | +union mtrr_def_type { |
| 54 | + struct { |
| 55 | + /* clang-format off */ |
| 56 | + uint64_t type : 8, |
| 57 | + _rsvd : 2, |
| 58 | + fe : 1, |
| 59 | + e : 1, |
| 60 | + _rsvd2 : 52; |
| 61 | + /* clang-format on */ |
| 62 | + } __packed; |
| 63 | + uint64_t reg; |
| 64 | +}; |
| 65 | +typedef union mtrr_def_type mtrr_def_type_t; |
| 66 | + |
| 67 | +union mtrr_base { |
| 68 | + struct { |
| 69 | + /* clang-format off */ |
| 70 | + uint64_t type : 8, |
| 71 | + _rsvd : 4, |
| 72 | + phys_base : 40, |
| 73 | + _rsvd2 : 12; |
| 74 | + /* clang-format on */ |
| 75 | + } __packed; |
| 76 | + uint64_t reg; |
| 77 | +}; |
| 78 | +typedef union mtrr_base mtrr_base_t; |
| 79 | + |
| 80 | +union mtrr_mask { |
| 81 | + struct { |
| 82 | + /* clang-format off */ |
| 83 | + uint64_t _rsvd : 10, |
| 84 | + valid : 1, |
| 85 | + phys_base : 40, |
| 86 | + _rsvd2 : 13; |
| 87 | + /* clang-format on */ |
| 88 | + } __packed; |
| 89 | + uint64_t reg; |
| 90 | +}; |
| 91 | +typedef union mtrr_mask mtrr_mask_t; |
| 92 | + |
| 93 | +extern mtrr_cap_t mtrr_read_cap(void); |
| 94 | +extern mtrr_def_type_t mtrr_read_def_type(void); |
| 95 | +extern bool mtrr_set_phys_base(mtrr_base_t base, uint8_t reg); |
| 96 | +extern bool mtrr_set_phys_mask(mtrr_mask_t mask, uint8_t reg); |
| 97 | + |
| 98 | +#endif /* KTF_MTRR_H */ |
0 commit comments