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/*! @file
14    @brief CPIO Fileserver pager RAM frame block module. */
15
16#ifndef _FILE_SERVER_FRAME_PAGER_H_
17#define _FILE_SERVER_FRAME_PAGER_H_
18
19#include <refos/refos.h>
20#include <sel4/types.h>
21#include <sel4/sel4.h>
22#include <data_struct/cpool.h>
23
24typedef seL4_Word vaddr_t;
25
26/*! @brief CPIO File server RAM frame block
27
28    CPIO Fileserver frame block structure, stores book-keeping data for allocation of frames used
29    for paging clients.
30 */
31struct fs_frame_block {
32    bool initialised;
33    cpool_t framePool;
34    seL4_CPtr dataspace;
35    seL4_CPtr window;
36    vaddr_t frameBlockVAddr;
37    uint32_t frameBlockNumPages;
38};
39
40/*! @brief Initialises pager frame block table.
41    @param fb The frame block to initialise.
42    @param framesSize The size of the pager frame block in bytes. This number must be a multiple
43                      of PAGE_SIZE (4k).
44    @return A pager frame block if success, NULL otherwise.
45 */
46void pager_init(struct fs_frame_block* fb, uint32_t framesSize);
47
48/*! @brief Tear downs a pager frame block table and releases all associated memory.
49    @param fb The frame block to de-initialise.
50*/
51void pager_release(struct fs_frame_block* fb);
52
53/*! @brief Allocates a frame from the pager frame block.
54    @param fb Pager frame block table to allocate from.
55    @return Virtual addr of a pager frame if success, NULL otherwise.
56 */
57vaddr_t pager_alloc_frame(struct fs_frame_block *fb);
58
59/*! @brief Frees a frame.
60    @param fb Pager frame block table to return the frame to.
61    @param frame VAddr to the frame to be freed.
62 */
63void pager_free_frame(struct fs_frame_block *fb, vaddr_t frame);
64
65#endif /* _FILE_SERVER_FRAME_PAGER_H_ */
66