blob: 7eb3169720bd013e8efb167bba400790ab847cfa [file] [log] [blame]
Wedson Almeida Filhofed69022018-07-11 15:39:12 +01001#ifndef _MM_H
2#define _MM_H
3
4#include <stdbool.h>
Wedson Almeida Filho84a30a02018-07-23 20:05:05 +01005#include <stdint.h>
Wedson Almeida Filhofed69022018-07-11 15:39:12 +01006
7#include "arch_mm.h"
8
9struct mm_ptable {
Wedson Almeida Filhofed69022018-07-11 15:39:12 +010010 pte_t *table;
Wedson Almeida Filho84a30a02018-07-23 20:05:05 +010011 uint32_t id;
Wedson Almeida Filhofed69022018-07-11 15:39:12 +010012};
13
14#define PAGE_SIZE (1 << PAGE_BITS)
15
16/* The following are arch-independent page mapping modes. */
17#define MM_MODE_R 0x01 /* read */
18#define MM_MODE_W 0x02 /* write */
19#define MM_MODE_X 0x04 /* execute */
20#define MM_MODE_D 0x08 /* device */
21
22/*
23 * This flag indicates that memory allocation must not use locks. This is
24 * relevant in systems where interlocked operations are only available after
25 * virtual memory is enabled.
26 */
27#define MM_MODE_NOSYNC 0x10
28
29/*
30 * This flag indicates that the mapping is intended to be used in a first
31 * stage translation table, which might have different encodings for the
32 * attribute bits than the second stage table.
33 */
34#define MM_MODE_STAGE1 0x20
35
Wedson Almeida Filho84a30a02018-07-23 20:05:05 +010036/*
37 * This flag indicates that no TLB invalidations should be issued for the
38 * changes in the page table.
39 */
40#define MM_MODE_NOINVALIDATE 0x40
41
42bool mm_ptable_init(struct mm_ptable *t, uint32_t id, int mode);
43void mm_ptable_dump(struct mm_ptable *t, int mode);
Andrew Scull020ae692018-07-19 16:20:14 +010044bool mm_ptable_map(struct mm_ptable *t, vaddr_t begin, vaddr_t end,
Wedson Almeida Filhofed69022018-07-11 15:39:12 +010045 paddr_t paddr, int mode);
46bool mm_ptable_map_page(struct mm_ptable *t, vaddr_t va, paddr_t pa, int mode);
47bool mm_ptable_unmap(struct mm_ptable *t, vaddr_t begin, vaddr_t end, int mode);
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +010048void mm_ptable_defrag(struct mm_ptable *t, int mode);
Wedson Almeida Filho84a30a02018-07-23 20:05:05 +010049bool mm_ptable_unmap_hypervisor(struct mm_ptable *t, int mode);
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +010050
51bool mm_init(void);
52bool mm_map(vaddr_t begin, vaddr_t end, paddr_t paddr, int mode);
53bool mm_unmap(vaddr_t begin, vaddr_t end, int mode);
54void mm_defrag(void);
Wedson Almeida Filhofed69022018-07-11 15:39:12 +010055
Andrew Scull4f170f52018-07-19 12:58:20 +010056#endif /* _MM_H */