blob: b62133c2abb63451a99a0a64b6d4be47dc5ca22c [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
Andrew Scull18c78fc2018-08-20 12:57:41 +01007#include "hf/arch/mm.h"
8
9#include "hf/addr.h"
Wedson Almeida Filhofed69022018-07-11 15:39:12 +010010
11struct mm_ptable {
Andrew Scull265ada92018-07-30 15:19:01 +010012 paddr_t table;
Wedson Almeida Filho84a30a02018-07-23 20:05:05 +010013 uint32_t id;
Wedson Almeida Filhofed69022018-07-11 15:39:12 +010014};
15
16#define PAGE_SIZE (1 << PAGE_BITS)
17
18/* The following are arch-independent page mapping modes. */
19#define MM_MODE_R 0x01 /* read */
20#define MM_MODE_W 0x02 /* write */
21#define MM_MODE_X 0x04 /* execute */
22#define MM_MODE_D 0x08 /* device */
23
24/*
25 * This flag indicates that memory allocation must not use locks. This is
26 * relevant in systems where interlocked operations are only available after
27 * virtual memory is enabled.
28 */
29#define MM_MODE_NOSYNC 0x10
30
31/*
32 * This flag indicates that the mapping is intended to be used in a first
33 * stage translation table, which might have different encodings for the
34 * attribute bits than the second stage table.
35 */
36#define MM_MODE_STAGE1 0x20
37
Wedson Almeida Filho84a30a02018-07-23 20:05:05 +010038/*
39 * This flag indicates that no TLB invalidations should be issued for the
40 * changes in the page table.
41 */
42#define MM_MODE_NOINVALIDATE 0x40
43
44bool mm_ptable_init(struct mm_ptable *t, uint32_t id, int mode);
45void mm_ptable_dump(struct mm_ptable *t, int mode);
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +010046void mm_ptable_defrag(struct mm_ptable *t, int mode);
Wedson Almeida Filho84a30a02018-07-23 20:05:05 +010047bool mm_ptable_unmap_hypervisor(struct mm_ptable *t, int mode);
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +010048
Andrew Scull80871322018-08-06 12:04:09 +010049bool mm_vm_identity_map(struct mm_ptable *t, paddr_t begin, paddr_t end,
50 int mode, ipaddr_t *ipa);
51bool mm_vm_identity_map_page(struct mm_ptable *t, paddr_t begin, int mode,
52 ipaddr_t *ipa);
53bool mm_vm_unmap(struct mm_ptable *t, paddr_t begin, paddr_t end, int mode);
54bool mm_vm_is_mapped(struct mm_ptable *t, ipaddr_t ipa, int mode);
55bool mm_vm_translate(struct mm_ptable *t, ipaddr_t ipa, paddr_t *pa);
56
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +010057bool mm_init(void);
Wedson Almeida Filho03e767a2018-07-30 15:32:03 +010058bool mm_cpu_init(void);
Andrew Scull80871322018-08-06 12:04:09 +010059void *mm_identity_map(paddr_t begin, paddr_t end, int mode);
60bool mm_unmap(paddr_t begin, paddr_t end, int mode);
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +010061void mm_defrag(void);
Wedson Almeida Filhofed69022018-07-11 15:39:12 +010062
Andrew Scull4f170f52018-07-19 12:58:20 +010063#endif /* _MM_H */