1/* 2 * Copyright 2017, Data61 3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO) 4 * ABN 41 687 119 230. 5 * 6 * This software may be distributed and modified according to the terms of 7 * the BSD 2-Clause license. Note that NO WARRANTY is provided. 8 * See "LICENSE_BSD2.txt" for details. 9 * 10 * @TAG(DATA61_BSD) 11 */ 12 13#pragma once 14 15/* macros on page sizes */ 16 17#include <stdint.h> 18 19#include <utils/arith.h> 20 21#define SIZE_BITS_TO_BYTES(size_bits) (BIT(size_bits)) 22#define BYTES_TO_SIZE_BITS(bytes) (LOG_BASE_2(bytes)) 23 24#define PAGE_BITS_4M 22 25#define PAGE_BITS_4K 12 26#define PAGE_SIZE_4K (SIZE_BITS_TO_BYTES(PAGE_BITS_4K)) 27#define PAGE_MASK_4K (PAGE_SIZE_4K - 1) 28#define PAGE_ALIGN_4K(addr) ((addr) & ~PAGE_MASK_4K) 29#define IS_ALIGNED_4K(addr) IS_ALIGNED(addr, PAGE_BITS_4K) 30 31#define MiB_TO_BYTES(x) (1024 * 1024 * ((size_t)x)) 32 33/* convert b bytes to the number of pages of size size_bits required for that many bytes */ 34#define BYTES_TO_SIZE_BITS_PAGES(b, size_bits) (((b) / (BIT(size_bits))) + ((((b) % (BIT(size_bits))) > 0) ? 1 : 0)) 35#define BYTES_TO_4K_PAGES(b) BYTES_TO_SIZE_BITS_PAGES(b, PAGE_BITS_4K) 36 37#define PAGE_ALIGN(addr, size) ((addr) & ~(size-1)) 38 39#define SAME_PAGE_4K(a, b) \ 40 ((((uintptr_t)(a)) & ~PAGE_MASK_4K) == (((uintptr_t)(b)) & ~PAGE_MASK_4K)) 41