[25] | 1 | /* |
---|
[35] | 2 | * hal_types.h - common kernel types for x86_64 |
---|
[25] | 3 | * |
---|
| 4 | * Author Alain Greiner (2016) |
---|
| 5 | * |
---|
| 6 | * Copyright (c) UPMC Sorbonne Universites |
---|
| 7 | * |
---|
| 8 | * This file is part of ALMOS-MKH. |
---|
| 9 | * |
---|
| 10 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
| 11 | * under the terms of the GNU General Public License as published by |
---|
| 12 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 13 | * |
---|
| 14 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 17 | * General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
| 21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | #ifndef HAL_TYPES_H_ |
---|
| 25 | #define HAL_TYPES_H_ |
---|
| 26 | |
---|
| 27 | #include <kernel_config.h> |
---|
| 28 | |
---|
| 29 | #ifndef NULL |
---|
| 30 | #define NULL (void*) 0 |
---|
| 31 | #endif |
---|
| 32 | |
---|
[29] | 33 | #define __packed __attribute__((__packed__)) |
---|
| 34 | #define __arraycount(a) (sizeof(a) / sizeof(*(a))) |
---|
| 35 | #define __in_kdata __attribute__((section(".kdata"))) |
---|
| 36 | |
---|
[25] | 37 | /************************************************************************** |
---|
| 38 | * Exact-width integer types. |
---|
| 39 | **************************************************************************/ |
---|
| 40 | |
---|
[32] | 41 | typedef signed char int8_t; |
---|
| 42 | typedef unsigned char uint8_t; |
---|
[25] | 43 | |
---|
| 44 | typedef signed short int16_t; |
---|
| 45 | typedef unsigned short uint16_t; |
---|
| 46 | |
---|
[32] | 47 | typedef int int32_t; |
---|
| 48 | typedef unsigned int uint32_t; |
---|
[25] | 49 | |
---|
| 50 | typedef signed long long int int64_t; |
---|
| 51 | typedef unsigned long long int uint64_t; |
---|
| 52 | |
---|
[29] | 53 | typedef uint64_t size_t; |
---|
| 54 | |
---|
[32] | 55 | typedef uint64_t vaddr_t; // XXX |
---|
[34] | 56 | typedef uint64_t pt_entry_t; // XXX |
---|
[32] | 57 | |
---|
[25] | 58 | /*************************************************************************** |
---|
| 59 | * Pthread related types |
---|
| 60 | **************************************************************************/ |
---|
| 61 | |
---|
| 62 | typedef uint32_t pthread_t; |
---|
| 63 | typedef uint32_t pthread_mutexattr_t; |
---|
| 64 | typedef uint32_t pthread_barrier_t; |
---|
| 65 | typedef uint32_t pthread_barrierattr_t; |
---|
| 66 | typedef uint32_t sem_t; |
---|
| 67 | typedef uint32_t pthread_cond_t; |
---|
| 68 | typedef uint32_t pthread_condattr_t; |
---|
| 69 | typedef uint32_t pthread_rwlock_t; |
---|
| 70 | typedef uint32_t pthread_rwlockattr_t; |
---|
| 71 | typedef uint32_t pthread_key_t; |
---|
| 72 | |
---|
| 73 | /*************************************************************************** |
---|
| 74 | * Boolean type and macros |
---|
| 75 | **************************************************************************/ |
---|
| 76 | |
---|
| 77 | typedef uint32_t bool_t; |
---|
| 78 | |
---|
| 79 | #define false 0 |
---|
| 80 | #define true 1 |
---|
| 81 | |
---|
| 82 | /*************************************************************************** |
---|
| 83 | * Kernel error type : signed |
---|
| 84 | **************************************************************************/ |
---|
| 85 | |
---|
| 86 | typedef int32_t error_t; |
---|
| 87 | |
---|
| 88 | /*************************************************************************** |
---|
| 89 | * Time related type |
---|
| 90 | **************************************************************************/ |
---|
| 91 | |
---|
| 92 | typedef uint64_t cycle_t; // for cycle counters |
---|
| 93 | |
---|
| 94 | /*************************************************************************** |
---|
| 95 | * Global Process identifier type / fixed format |
---|
| 96 | * 16 MSB = cluster XY identifier |
---|
| 97 | * 16 LSB = local process index |
---|
| 98 | **************************************************************************/ |
---|
| 99 | |
---|
| 100 | typedef uint32_t pid_t; |
---|
| 101 | |
---|
| 102 | /*************************************************************************** |
---|
| 103 | * Local Process index |
---|
| 104 | **************************************************************************/ |
---|
| 105 | |
---|
| 106 | typedef uint16_t lpid_t; |
---|
| 107 | |
---|
| 108 | /*************************************************************************** |
---|
| 109 | * Thread identifier type / fixed format |
---|
| 110 | * 16 MSB = cluster XY identifier |
---|
| 111 | * 16 LSB = local thread index |
---|
| 112 | **************************************************************************/ |
---|
| 113 | |
---|
| 114 | typedef uint32_t trdid_t; |
---|
| 115 | |
---|
| 116 | /*************************************************************************** |
---|
| 117 | * Local Thread index |
---|
| 118 | **************************************************************************/ |
---|
| 119 | |
---|
| 120 | typedef uint16_t ltid_t; |
---|
| 121 | |
---|
| 122 | /*************************************************************************** |
---|
| 123 | * User identifier type |
---|
| 124 | **************************************************************************/ |
---|
| 125 | |
---|
| 126 | typedef uint32_t uid_t; |
---|
| 127 | |
---|
| 128 | /*************************************************************************** |
---|
| 129 | * CPU identifier types |
---|
| 130 | **************************************************************************/ |
---|
| 131 | |
---|
| 132 | typedef uint16_t lid_t; // local index in cluster |
---|
| 133 | typedef uint32_t gid_t; // global (hardware) identifier |
---|
| 134 | |
---|
| 135 | /*************************************************************************** |
---|
| 136 | * File Descriptor Index in File Descriptor Array |
---|
| 137 | **************************************************************************/ |
---|
| 138 | |
---|
| 139 | typedef uint32_t fdid_t; |
---|
| 140 | |
---|
| 141 | /*************************************************************************** |
---|
| 142 | * This structure defines a single 32 bits integer alone in a cache line. |
---|
| 143 | **************************************************************************/ |
---|
| 144 | |
---|
| 145 | typedef struct cache_line_s |
---|
| 146 | { |
---|
[34] | 147 | union |
---|
| 148 | { |
---|
| 149 | uint32_t values[CONFIG_CACHE_LINE_SIZE>>2]; |
---|
| 150 | uint32_t value; |
---|
| 151 | }; |
---|
[25] | 152 | } |
---|
| 153 | __attribute__((packed)) cacheline_t; |
---|
| 154 | |
---|
[34] | 155 | #define CACHELINE_ALIGNED __attribute__((aligned(CONFIG_CACHE_LINE_SIZE))) |
---|
| 156 | |
---|
[25] | 157 | /*************************************************************************** |
---|
[34] | 158 | * Address types and macros !!! hardware dependent !!! |
---|
[25] | 159 | *************************************************************************** |
---|
[34] | 160 | * An extended pointer is a 64 bits integer, structured in two fields : |
---|
[25] | 161 | * - cxy : cluster identifier. |
---|
| 162 | * - ptr : pointer in the virtual space of a single cluster. |
---|
| 163 | * |
---|
[38] | 164 | * In Intel 64 bits, the kernel virtual space has 4 Gbytes per cluster |
---|
[44] | 165 | * - the cxy field occupies bits[34:32] |
---|
[38] | 166 | * - the ptr field occupies bits[31:0] |
---|
[25] | 167 | *************************************************************************** |
---|
| 168 | * A physical address is a 64 bits integer, structured in two fields : |
---|
| 169 | * - cxy : cluster identifier. |
---|
| 170 | * - lpa : local physical address inside cluster. |
---|
| 171 | * |
---|
[38] | 172 | * In Intel 64 bits, the physical space has 8 Gbytes per cluster. |
---|
| 173 | * - the cxy field occupies bits[35:33] |
---|
| 174 | * - the lpa field occupies bits[32:0] |
---|
[25] | 175 | **************************************************************************/ |
---|
| 176 | |
---|
[38] | 177 | typedef uint64_t reg_t; // core register |
---|
[25] | 178 | |
---|
[34] | 179 | typedef uint64_t xptr_t; // extended pointer |
---|
[25] | 180 | |
---|
[34] | 181 | typedef uint16_t cxy_t; // cluster identifier |
---|
[25] | 182 | |
---|
[34] | 183 | typedef uint64_t paddr_t; // global physical address (64 bits) |
---|
[25] | 184 | |
---|
[34] | 185 | typedef uint64_t lpa_t; // local physical address |
---|
[25] | 186 | |
---|
[34] | 187 | typedef uint64_t intptr_t; // local pointer stored as integer |
---|
[25] | 188 | |
---|
[34] | 189 | typedef uint64_t ppn_t; // Physical Page Number |
---|
[25] | 190 | |
---|
[34] | 191 | typedef uint64_t vpn_t; // Virtual Page number |
---|
[25] | 192 | |
---|
| 193 | #define XPTR_NULL 0 |
---|
| 194 | |
---|
[44] | 195 | /* virtual (heap) */ |
---|
[38] | 196 | #define PTR_MASK 0x00000000FFFFFFFFULL |
---|
[44] | 197 | #define CXY_MASK 0x0000000700000000ULL |
---|
[38] | 198 | #define PTR_SHIFT 32 |
---|
[44] | 199 | #define GET_CXY(xp) ((cxy_t)(((xp) & CXY_MASK) >> PTR_SHIFT)) |
---|
[34] | 200 | #define GET_PTR(xp) ((void*)((xp) & PTR_MASK)) |
---|
[38] | 201 | #define XPTR(cxy,ptr) (((uint64_t)(cxy) << PTR_SHIFT) | (((uint64_t)(ptr)) & PTR_MASK)) |
---|
[25] | 202 | |
---|
[44] | 203 | /* virtual (kimg). A KIMG entry has 2GB of VA. */ |
---|
| 204 | #define PTR_KIMG_MASK 0x000000007FFFFFFFULL |
---|
| 205 | #define CXY_KIMG_MASK 0x0000000380000000ULL |
---|
| 206 | #define PTR_KIMG_SHIFT 31 |
---|
| 207 | #define GET_KIMG_CXY(xp) ((cxy_t)(((xp) & CXY_KIMG_MASK) >> PTR_KIMG_SHIFT)) |
---|
| 208 | #define GET_KIMG_PTR(xp) ((void*)((xp) & PTR_KIMG_MASK)) |
---|
| 209 | #define XPTR_KIMG(cxy,ptr) (((uint64_t)(cxy) << PTR_KIMG_SHIFT) | (((uint64_t)(ptr)) & PTR_KIMG_MASK)) |
---|
[25] | 210 | |
---|
[44] | 211 | /* physical */ |
---|
[38] | 212 | #define LPA_MASK 0x00000001FFFFFFFFULL |
---|
| 213 | #define LPA_SHIFT 33 |
---|
| 214 | #define CXY_FROM_PADDR(paddr) ((cxy_t)((paddr) >> LPA_SHIFT)) |
---|
[25] | 215 | #define LPA_FROM_PADDR(paddr) (lpa_t)((paddr & LPA_MASK) |
---|
[38] | 216 | #define PADDR(cxy,lad) (((uint64_t)(cxy) << LPA_SHIFT) | (((uint64_t)(ptr)) & LPA_MASK)) |
---|
[25] | 217 | |
---|
| 218 | #endif /* HAL_TYPES_H_ */ |
---|