1/* 2 * Copyright 2016, 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(D61_BSD) 11 */ 12 13#ifndef _REFOS_H_ 14#define _REFOS_H_ 15 16#include <stdint.h> 17 18#include <sel4/sel4.h> 19#include <refos/error.h> 20#include <stdint.h> 21#include <stddef.h> 22 23/* Include Kconfig variables. */ 24#include <autoconf.h> 25 26/*! @file 27 @brief Common definitions, macros and inline functions used by RefOS userland library. 28 29 Common definitions, macros and inline functions used by RefOS userland library. Contains 30 constant definitions (such as page size), helper functions, helper macros...etc. 31*/ 32 33/* ----------------------------------- CSpace defines ------------------------------------------- */ 34 35#define REFOS_CSPACE_RADIX 16 36#define REFOS_CSPACE_GUARD (32 - REFOS_CSPACE_RADIX) 37#define REFOS_CSPACE_DEPTH 32 38#define REFOS_CDEPTH REFOS_CSPACE_DEPTH 39 40/* ------------------------------ Reserved CSpace caps ------------------------------------------ */ 41 42#define REFOS_CSPACE 0x2 43#define REFOS_PROCSERV_EP 0x3 44#define REFOS_LIVENESS 0x4 45#define REFOS_CSPACE_RECV_TEMPSWAP 0x5 46#define REFOS_THREAD_CAP_RECV 0x6 47#define REFOS_THREAD_TCB 0x8 48#define REFOS_DEVICE_IO_PORTS 0x9 49 50/* Process server acts as the root nameserver. */ 51#define REFOS_NAMESERV_EP REFOS_PROCSERV_EP 52 53/* --------------------------------- RPC Method bases ------------------------------------------- */ 54 55#define PROCSERV_METHODS_BASE 0x1000 56#define DATASERV_METHODS_BASE 0x1100 57#define NAMESERV_METHODS_BASE 0x1200 58#define MEMSERV_METHODS_BASE 0x1300 59#define SERV_METHODS_BASE 0x1400 60#define DEVICE_METHODS_BASE 0x1500 61 62#define PROCSERV_NOTIFY_TAG 0xA82D2 63#define PROCSERV_MAX_PROCESSES 2048 64 65/* ----------------------------------- Helper functions ----------------------------------------- */ 66 67/*! @brief The RefOS system small-page size. Should be 4k on most platforms. */ 68#define REFOS_PAGE_SIZE (1 << seL4_PageBits) 69 70/*! @brief Align the given virtual address to the page size, rounding down. */ 71#define REFOS_PAGE_ALIGN(x) ((x) & ~(REFOS_PAGE_SIZE - 1)) 72 73/*! @brief Helper function to calculate number of pages that a given size in bytes covers, rounding 74 up to the next page. 75 @param size The size of region in bytes. 76 @return The number of pages needed to cover the given size. 77*/ 78static inline uint32_t 79refos_round_up_npages(uint32_t size) 80{ 81 return (size / REFOS_PAGE_SIZE) + ((size % REFOS_PAGE_SIZE) ? 1 : 0); 82} 83 84#endif /* _REFOS_H_ */ 85