[1] | 1 | /* |
---|
| 2 | * hal_types.h - common kernel types for MIPS 32 bits |
---|
| 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 | |
---|
[16] | 27 | #include <kernel_config.h> |
---|
[1] | 28 | |
---|
[226] | 29 | #define HAL_32BIT |
---|
| 30 | |
---|
[1] | 31 | #ifndef NULL |
---|
| 32 | #define NULL (void*) 0 |
---|
| 33 | #endif |
---|
| 34 | |
---|
| 35 | /************************************************************************** |
---|
| 36 | * Exact-width integer types. |
---|
| 37 | **************************************************************************/ |
---|
| 38 | |
---|
| 39 | typedef signed char int8_t; |
---|
| 40 | typedef unsigned char uint8_t; |
---|
| 41 | |
---|
[8] | 42 | typedef signed short int16_t; |
---|
| 43 | typedef unsigned short uint16_t; |
---|
[1] | 44 | |
---|
| 45 | typedef signed long int int32_t; |
---|
| 46 | typedef unsigned long int uint32_t; |
---|
| 47 | |
---|
| 48 | typedef signed long long int int64_t; |
---|
| 49 | typedef unsigned long long int uint64_t; |
---|
| 50 | |
---|
| 51 | /*************************************************************************** |
---|
| 52 | * Boolean type and macros |
---|
| 53 | **************************************************************************/ |
---|
| 54 | |
---|
| 55 | typedef uint32_t bool_t; |
---|
| 56 | |
---|
| 57 | #define false 0 |
---|
| 58 | #define true 1 |
---|
| 59 | |
---|
| 60 | /*************************************************************************** |
---|
| 61 | * Kernel error type : signed |
---|
| 62 | **************************************************************************/ |
---|
| 63 | |
---|
| 64 | typedef int32_t error_t; |
---|
| 65 | |
---|
| 66 | /*************************************************************************** |
---|
| 67 | * Time related type |
---|
| 68 | **************************************************************************/ |
---|
| 69 | |
---|
[16] | 70 | typedef uint64_t cycle_t; // for cycle counters |
---|
[1] | 71 | |
---|
| 72 | /*************************************************************************** |
---|
| 73 | * Global Process identifier type / fixed format |
---|
| 74 | * 16 MSB = cluster XY identifier |
---|
| 75 | * 16 LSB = local process index |
---|
| 76 | **************************************************************************/ |
---|
| 77 | |
---|
| 78 | typedef uint32_t pid_t; |
---|
| 79 | |
---|
| 80 | /*************************************************************************** |
---|
| 81 | * Local Process index |
---|
| 82 | **************************************************************************/ |
---|
| 83 | |
---|
| 84 | typedef uint16_t lpid_t; |
---|
| 85 | |
---|
| 86 | /*************************************************************************** |
---|
| 87 | * Thread identifier type / fixed format |
---|
| 88 | * 16 MSB = cluster XY identifier |
---|
| 89 | * 16 LSB = local thread index |
---|
| 90 | **************************************************************************/ |
---|
| 91 | |
---|
| 92 | typedef uint32_t trdid_t; |
---|
| 93 | |
---|
| 94 | /*************************************************************************** |
---|
| 95 | * Local Thread index |
---|
| 96 | **************************************************************************/ |
---|
| 97 | |
---|
| 98 | typedef uint16_t ltid_t; |
---|
| 99 | |
---|
| 100 | /*************************************************************************** |
---|
| 101 | * User identifier type |
---|
| 102 | **************************************************************************/ |
---|
| 103 | |
---|
| 104 | typedef uint32_t uid_t; |
---|
| 105 | |
---|
| 106 | /*************************************************************************** |
---|
| 107 | * CPU identifier types |
---|
| 108 | **************************************************************************/ |
---|
| 109 | |
---|
[8] | 110 | typedef uint16_t lid_t; // local index in cluster |
---|
| 111 | typedef uint32_t gid_t; // global (hardware) identifier |
---|
[1] | 112 | |
---|
| 113 | /*************************************************************************** |
---|
| 114 | * File Descriptor Index in File Descriptor Array |
---|
| 115 | **************************************************************************/ |
---|
| 116 | |
---|
| 117 | typedef uint32_t fdid_t; |
---|
| 118 | |
---|
| 119 | /*************************************************************************** |
---|
| 120 | * This structure defines a single 32 bits integer alone in a cache line. |
---|
| 121 | **************************************************************************/ |
---|
| 122 | |
---|
| 123 | typedef struct cache_line_s |
---|
| 124 | { |
---|
| 125 | union |
---|
| 126 | { |
---|
| 127 | uint32_t values[CONFIG_CACHE_LINE_SIZE>>2]; |
---|
| 128 | uint32_t value; |
---|
| 129 | }; |
---|
| 130 | } |
---|
| 131 | __attribute__((packed)) cacheline_t; |
---|
| 132 | |
---|
| 133 | /*************************************************************************** |
---|
| 134 | * Address types and macros !!! hardware dependant !!! |
---|
| 135 | *************************************************************************** |
---|
[408] | 136 | * An extended pointer is a 64 bits integer, structured in two fields : |
---|
[1] | 137 | * - cxy : cluster identifier. |
---|
| 138 | * - ptr : pointer in the virtual space of a single cluster. |
---|
| 139 | * |
---|
| 140 | * In TSAR (MIPS32), the kernel virtual space has 4 Gbytes per cluster |
---|
| 141 | * - the cxy field occupies bits[47:32] |
---|
| 142 | * - the ptr field occupies bits[31:0] |
---|
| 143 | *************************************************************************** |
---|
| 144 | * A physical address is a 64 bits integer, structured in two fields : |
---|
| 145 | * - cxy : cluster identifier. |
---|
| 146 | * - lpa : local physical address inside cluster. |
---|
| 147 | * |
---|
| 148 | * In TSAR (MIPS32), the physical space has 4Gbytes per cluster. |
---|
| 149 | * - the cxy field occupies bits[39:32] |
---|
| 150 | * - the lpa field occupies bits[31:0] |
---|
| 151 | **************************************************************************/ |
---|
| 152 | |
---|
| 153 | typedef uint32_t reg_t; // core register |
---|
| 154 | |
---|
| 155 | typedef uint64_t xptr_t; // extended pointer |
---|
| 156 | |
---|
| 157 | typedef uint16_t cxy_t; // cluster identifier |
---|
| 158 | |
---|
| 159 | typedef uint64_t paddr_t; // global physical address |
---|
| 160 | |
---|
| 161 | typedef uint32_t lpa_t; // local physical address |
---|
| 162 | |
---|
| 163 | typedef uint32_t intptr_t; // local pointer stored as integer |
---|
| 164 | |
---|
| 165 | typedef uint32_t ppn_t; // Physical Page Number |
---|
| 166 | |
---|
| 167 | typedef uint32_t vpn_t; // Virtual Page number |
---|
| 168 | |
---|
[50] | 169 | |
---|
[1] | 170 | #define XPTR_NULL 0 |
---|
| 171 | |
---|
[8] | 172 | #define PTR_MASK 0x00000000FFFFFFFFULL |
---|
[1] | 173 | |
---|
[50] | 174 | #define PTR_SHIFT 32 |
---|
[1] | 175 | |
---|
[50] | 176 | #define GET_CXY(xp) ((cxy_t)((xp) >> PTR_SHIFT)) |
---|
| 177 | |
---|
[1] | 178 | #define GET_PTR(xp) ((void*)(uint32_t)((xp) & PTR_MASK)) |
---|
| 179 | |
---|
[50] | 180 | #define XPTR(cxy,ptr) (((uint64_t)(cxy) << PTR_SHIFT) | (((uint32_t)(ptr)) & PTR_MASK)) |
---|
[1] | 181 | |
---|
[50] | 182 | |
---|
[8] | 183 | #define LPA_MASK 0x00000000FFFFFFFFULL |
---|
[1] | 184 | |
---|
[50] | 185 | #define LPA_SHIFT 32 |
---|
[1] | 186 | |
---|
[50] | 187 | #define CXY_FROM_PADDR(paddr) ((cxy_t)((paddr) >> LPA_SHIFT)) |
---|
| 188 | |
---|
[315] | 189 | #define LPA_FROM_PADDR(paddr) (lpa_t)(paddr & LPA_MASK) |
---|
[1] | 190 | |
---|
[50] | 191 | #define PADDR(cxy,lpa) (((uint64_t)(cxy) << LPA_SHIFT) | (((uint64_t)(lpa)) & LPA_MASK)) |
---|
[1] | 192 | |
---|
| 193 | |
---|
| 194 | |
---|
| 195 | #endif /* HAL_TYPES_H_ */ |
---|