blob: dd9c82958e882ea4d04263446756e02c78ed7493 [file] [log] [blame]
Andrew Scull18834872018-10-12 11:48:09 +01001/*
2 * Copyright 2018 Google LLC
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Andrew Scullfbc938a2018-08-20 14:09:28 +010017#pragma once
Wedson Almeida Filhofed69022018-07-11 15:39:12 +010018
19#include <stdbool.h>
20#include <stddef.h>
Wedson Almeida Filhofed69022018-07-11 15:39:12 +010021
Andrew Scull18c78fc2018-08-20 12:57:41 +010022#include "hf/addr.h"
Wedson Almeida Filhofed69022018-07-11 15:39:12 +010023
Andrew Walbranc3910f72018-11-27 14:24:36 +000024/** A page table entry. */
Andrew Scull80871322018-08-06 12:04:09 +010025typedef uint64_t pte_t;
26
27#define PAGE_LEVEL_BITS 9
28
Andrew Walbran25133742018-09-28 16:28:02 +010029/*
Andrew Scull459d3b52018-12-07 16:37:12 +000030 * TODO: move the arch_mm_* declarations to a shared header. That header can
31 * also check that the specific implementation defines everything it needs to
32 * too.
Andrew Walbran25133742018-09-28 16:28:02 +010033 */
Andrew Scull459d3b52018-12-07 16:37:12 +000034pte_t arch_mm_absent_pte(int level);
35pte_t arch_mm_table_pte(int level, paddr_t pa);
36pte_t arch_mm_block_pte(int level, paddr_t pa, uint64_t attrs);
37bool arch_mm_is_block_allowed(int level);
38bool arch_mm_pte_is_present(pte_t pte, int level);
39bool arch_mm_pte_is_table(pte_t pte, int level);
40bool arch_mm_pte_is_block(pte_t pte, int level);
41paddr_t arch_mm_clear_pa(paddr_t pa);
42paddr_t arch_mm_block_from_pte(pte_t pte);
43paddr_t arch_mm_table_from_pte(pte_t pte);
44uint64_t arch_mm_pte_attrs(pte_t pte);
Andrew Walbran2400ed22018-09-27 14:45:58 +010045uint64_t arch_mm_combine_table_entry_attrs(uint64_t table_attrs,
46 uint64_t block_attrs);
Andrew Scull459d3b52018-12-07 16:37:12 +000047void arch_mm_invalidate_stage1_range(vaddr_t va_begin, vaddr_t va_end);
48void arch_mm_invalidate_stage2_range(ipaddr_t va_begin, ipaddr_t va_end);
49void arch_mm_write_back_dcache(void *base, size_t size);
50uint8_t arch_mm_max_level(int mode);
51uint8_t arch_mm_root_table_count(int mode);
52uint64_t arch_mm_mode_to_attrs(int mode);
53bool arch_mm_init(paddr_t table, bool first);