Andrew Scull | fbc938a | 2018-08-20 14:09:28 +0100 | [diff] [blame] | 1 | #pragma once |
Wedson Almeida Filho | fed6902 | 2018-07-11 15:39:12 +0100 | [diff] [blame] | 2 | |
| 3 | #include <stdbool.h> |
Wedson Almeida Filho | 84a30a0 | 2018-07-23 20:05:05 +0100 | [diff] [blame] | 4 | #include <stdint.h> |
Wedson Almeida Filho | fed6902 | 2018-07-11 15:39:12 +0100 | [diff] [blame] | 5 | |
Andrew Scull | 18c78fc | 2018-08-20 12:57:41 +0100 | [diff] [blame] | 6 | #include "hf/arch/mm.h" |
| 7 | |
| 8 | #include "hf/addr.h" |
Wedson Almeida Filho | fed6902 | 2018-07-11 15:39:12 +0100 | [diff] [blame] | 9 | |
| 10 | struct mm_ptable { |
Andrew Scull | 265ada9 | 2018-07-30 15:19:01 +0100 | [diff] [blame] | 11 | paddr_t table; |
Wedson Almeida Filho | fed6902 | 2018-07-11 15:39:12 +0100 | [diff] [blame] | 12 | }; |
| 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 Filho | 84a30a0 | 2018-07-23 20:05:05 +0100 | [diff] [blame] | 36 | /* |
| 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 | |
Andrew Scull | 8c3a63a | 2018-09-20 13:38:34 +0100 | [diff] [blame^] | 42 | bool mm_ptable_init(struct mm_ptable *t, int mode); |
Wedson Almeida Filho | 84a30a0 | 2018-07-23 20:05:05 +0100 | [diff] [blame] | 43 | void mm_ptable_dump(struct mm_ptable *t, int mode); |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 44 | void mm_ptable_defrag(struct mm_ptable *t, int mode); |
Wedson Almeida Filho | 84a30a0 | 2018-07-23 20:05:05 +0100 | [diff] [blame] | 45 | bool mm_ptable_unmap_hypervisor(struct mm_ptable *t, int mode); |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 46 | |
Andrew Scull | 8087132 | 2018-08-06 12:04:09 +0100 | [diff] [blame] | 47 | bool mm_vm_identity_map(struct mm_ptable *t, paddr_t begin, paddr_t end, |
| 48 | int mode, ipaddr_t *ipa); |
| 49 | bool mm_vm_identity_map_page(struct mm_ptable *t, paddr_t begin, int mode, |
| 50 | ipaddr_t *ipa); |
| 51 | bool mm_vm_unmap(struct mm_ptable *t, paddr_t begin, paddr_t end, int mode); |
| 52 | bool mm_vm_is_mapped(struct mm_ptable *t, ipaddr_t ipa, int mode); |
| 53 | bool mm_vm_translate(struct mm_ptable *t, ipaddr_t ipa, paddr_t *pa); |
| 54 | |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 55 | bool mm_init(void); |
Wedson Almeida Filho | 03e767a | 2018-07-30 15:32:03 +0100 | [diff] [blame] | 56 | bool mm_cpu_init(void); |
Andrew Scull | 8087132 | 2018-08-06 12:04:09 +0100 | [diff] [blame] | 57 | void *mm_identity_map(paddr_t begin, paddr_t end, int mode); |
| 58 | bool mm_unmap(paddr_t begin, paddr_t end, int mode); |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 59 | void mm_defrag(void); |