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