/*-1* Copyright (c) 2014 Andrew Turner2* Copyright (c) 2015-2018 Ruslan Bukin <[email protected]>3* All rights reserved.4*5* Portions of this software were developed by SRI International and the6* University of Cambridge Computer Laboratory under DARPA/AFRL contract7* FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme.8*9* Portions of this software were developed by the University of Cambridge10* Computer Laboratory as part of the CTSRD Project, with support from the11* UK Higher Education Innovation Fund (HEIF).12*13* Redistribution and use in source and binary forms, with or without14* modification, are permitted provided that the following conditions15* are met:16* 1. Redistributions of source code must retain the above copyright17* notice, this list of conditions and the following disclaimer.18* 2. Redistributions in binary form must reproduce the above copyright19* notice, this list of conditions and the following disclaimer in the20* documentation and/or other materials provided with the distribution.21*22* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND23* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE24* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE25* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE26* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL27* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS28* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)29* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT30* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY31* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF32* SUCH DAMAGE.33*/3435#ifndef _MACHINE_PTE_H_36#define _MACHINE_PTE_H_3738#ifndef LOCORE39typedef uint64_t pd_entry_t; /* page directory entry */40typedef uint64_t pt_entry_t; /* page table entry */41typedef uint64_t pn_t; /* page number */42#endif4344/* Level 0 table, 512GiB per entry, SV48 only */45#define L0_SHIFT 3946#define L0_SIZE (1UL << L0_SHIFT)47#define L0_OFFSET (L0_SIZE - 1)4849/* Level 1 table, 1GiB per entry */50#define L1_SHIFT 3051#define L1_SIZE (1UL << L1_SHIFT)52#define L1_OFFSET (L1_SIZE - 1)5354/* Level 2 table, 2MiB per entry */55#define L2_SHIFT 2156#define L2_SIZE (1UL << L2_SHIFT)57#define L2_OFFSET (L2_SIZE - 1)5859/* Level 3 table, 4KiB per entry */60#define L3_SHIFT 1261#define L3_SIZE (1UL << L3_SHIFT)62#define L3_OFFSET (L3_SIZE - 1)6364#define Ln_ENTRIES_SHIFT 965#define Ln_ENTRIES (1 << Ln_ENTRIES_SHIFT)66#define Ln_ADDR_MASK (Ln_ENTRIES - 1)6768/* Bits 9:8 are reserved for software */69#define PTE_SW_MANAGED (1 << 9)70#define PTE_SW_WIRED (1 << 8)71#define PTE_D (1 << 7) /* Dirty */72#define PTE_A (1 << 6) /* Accessed */73#define PTE_G (1 << 5) /* Global */74#define PTE_U (1 << 4) /* User */75#define PTE_X (1 << 3) /* Execute */76#define PTE_W (1 << 2) /* Write */77#define PTE_R (1 << 1) /* Read */78#define PTE_V (1 << 0) /* Valid */79#define PTE_RWX (PTE_R | PTE_W | PTE_X)80#define PTE_RX (PTE_R | PTE_X)81#define PTE_KERN (PTE_V | PTE_R | PTE_W | PTE_A | PTE_D)82#define PTE_PROMOTE (PTE_V | PTE_RWX | PTE_D | PTE_G | PTE_U | \83PTE_SW_MANAGED | PTE_SW_WIRED)8485/*86* Svpbmt Memory Attribute (MA) bits [62:61].87*88* +------+-------+------------------------------------------------------------+89* | Mode | Value | Requested Memory Attributes |90* +------+-------+------------------------------------------------------------+91* | PMA | 00 | None, inherited from Physical Memory Attributes (firmware) |92* | NC | 01 | Non-cacheable, idempotent, weakly-ordered (RVWMO), |93* | | | main memory |94* | IO | 10 | Non-cacheable, non-idempotent, strongly-ordered, I/O |95* | -- | 11 | Reserved |96* +------+-------+------------------------------------------------------------+97*/98#define PTE_MA_SHIFT 6199#define PTE_MA_MASK (0x3ul << PTE_MA_SHIFT)100#define PTE_MA_NONE (0ul)101#define PTE_MA_NC (1ul << PTE_MA_SHIFT)102#define PTE_MA_IO (2ul << PTE_MA_SHIFT)103104/*105* T-HEAD Custom Memory Attribute (MA) bits [63:59].106*107* bit 59: Trustable (relating to TEE)108* bit 60: Shareable (among CPUs, not configurable)109* bit 61: Bufferable (writes to device memory)110* bit 62: Cacheable111* bit 63: Memory Ordering (1 = strongly ordered (device), 0 = default)112*113* +------+-------+------------------------------------------------------------+114* | Mode | Value | Requested Memory Attributes |115* +------+-------+------------------------------------------------------------+116* | NC | 00110 | Weakly-ordered, non-cacheable, bufferable, shareable, |117* | | | non-trustable |118* | PMA | 01110 | Weakly-ordered, cacheable, bufferable, shareable, |119* | | | non-trustable |120* | IO | 10010 | Strongly-ordered, non-cacheable, non-bufferable, |121* | | | shareable, non-trustable |122* +------+-------+------------------------------------------------------------+123*/124#define PTE_THEAD_MA_SHIFT 59125#define PTE_THEAD_MA_MASK (0x1ful << PTE_THEAD_MA_SHIFT)126#define PTE_THEAD_MA_NC (0x6ul << PTE_THEAD_MA_SHIFT)127#define PTE_THEAD_MA_NONE (0xeul << PTE_THEAD_MA_SHIFT)128#define PTE_THEAD_MA_IO (0x12ul << PTE_THEAD_MA_SHIFT)129130/* Bits 63 - 54 are reserved for future use. */131#define PTE_HI_MASK 0xFFC0000000000000ULL132133#define PTE_PPN0_S 10134#define PTE_PPN1_S 19135#define PTE_PPN2_S 28136#define PTE_PPN3_S 37137#define PTE_SIZE 8138139#endif /* !_MACHINE_PTE_H_ */140141142