1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (C) 2019 Intel Corporation. 3 * All rights reserved. 4 */ 5 6 #ifndef SPDK_MEMORY_H 7 #define SPDK_MEMORY_H 8 9 #include "spdk/stdinc.h" 10 11 #ifndef __linux__ 12 #define VFIO_ENABLED 0 13 #else 14 #include <linux/version.h> 15 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0) 16 #define VFIO_ENABLED 1 17 #else 18 #define VFIO_ENABLED 0 19 #endif 20 #endif 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 #define SHIFT_2MB 21 /* (1 << 21) == 2MB */ 27 #define VALUE_2MB (1ULL << SHIFT_2MB) 28 #define MASK_2MB (VALUE_2MB - 1) 29 30 #define SHIFT_4KB 12 /* (1 << 12) == 4KB */ 31 #define VALUE_4KB (1ULL << SHIFT_4KB) 32 #define MASK_4KB (VALUE_4KB - 1) 33 34 #define _2MB_OFFSET(ptr) (((uintptr_t)(ptr)) & MASK_2MB) 35 #define _2MB_PAGE(ptr) FLOOR_2MB((uintptr_t)(ptr)) 36 #define FLOOR_2MB(x) (((uintptr_t)(x)) & ~MASK_2MB) 37 #define CEIL_2MB(x) FLOOR_2MB(((uintptr_t)(x)) + VALUE_2MB - 1) 38 39 #ifdef __cplusplus 40 } 41 #endif 42 43 #endif /* SPDK_MEMORY_H */ 44