2 * Copyright (C) 2011-2014, 2016 ARM Limited. All rights reserved.
4 * This program is free software and is provided to you under the terms of the GNU General Public License version 2
5 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
7 * A copy of the licence is included with the program, and can also be obtained from Free Software
8 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
11 #ifndef __MALI_MMU_PAGE_DIRECTORY_H__
12 #define __MALI_MMU_PAGE_DIRECTORY_H__
17 * Size of an MMU page in bytes
19 #define MALI_MMU_PAGE_SIZE 0x1000
22 * Size of the address space referenced by a page table page
24 #define MALI_MMU_VIRTUAL_PAGE_SIZE 0x400000 /* 4 MiB */
27 * Page directory index from address
28 * Calculates the page directory index from the given address
30 #define MALI_MMU_PDE_ENTRY(address) (((address)>>22) & 0x03FF)
33 * Page table index from address
34 * Calculates the page table index from the given address
36 #define MALI_MMU_PTE_ENTRY(address) (((address)>>12) & 0x03FF)
39 * Extract the memory address from an PDE/PTE entry
41 #define MALI_MMU_ENTRY_ADDRESS(value) ((value) & 0xFFFFFC00)
43 #define MALI_INVALID_PAGE ((u32)(~0))
48 typedef enum mali_mmu_entry_flags {
49 MALI_MMU_FLAGS_PRESENT = 0x01,
50 MALI_MMU_FLAGS_READ_PERMISSION = 0x02,
51 MALI_MMU_FLAGS_WRITE_PERMISSION = 0x04,
52 MALI_MMU_FLAGS_OVERRIDE_CACHE = 0x8,
53 MALI_MMU_FLAGS_WRITE_CACHEABLE = 0x10,
54 MALI_MMU_FLAGS_WRITE_ALLOCATE = 0x20,
55 MALI_MMU_FLAGS_WRITE_BUFFERABLE = 0x40,
56 MALI_MMU_FLAGS_READ_CACHEABLE = 0x80,
57 MALI_MMU_FLAGS_READ_ALLOCATE = 0x100,
58 MALI_MMU_FLAGS_MASK = 0x1FF,
59 } mali_mmu_entry_flags;
62 #define MALI_MMU_FLAGS_FORCE_GP_READ_ALLOCATE ( \
63 MALI_MMU_FLAGS_PRESENT | \
64 MALI_MMU_FLAGS_READ_PERMISSION | \
65 MALI_MMU_FLAGS_WRITE_PERMISSION | \
66 MALI_MMU_FLAGS_OVERRIDE_CACHE | \
67 MALI_MMU_FLAGS_WRITE_CACHEABLE | \
68 MALI_MMU_FLAGS_WRITE_BUFFERABLE | \
69 MALI_MMU_FLAGS_READ_CACHEABLE | \
70 MALI_MMU_FLAGS_READ_ALLOCATE )
72 #define MALI_MMU_FLAGS_DEFAULT ( \
73 MALI_MMU_FLAGS_PRESENT | \
74 MALI_MMU_FLAGS_READ_PERMISSION | \
75 MALI_MMU_FLAGS_WRITE_PERMISSION )
78 struct mali_page_directory {
79 u32 page_directory; /**< Physical address of the memory session's page directory */
80 mali_io_address page_directory_mapped; /**< Pointer to the mapped version of the page directory into the kernel's address space */
82 mali_io_address page_entries_mapped[1024]; /**< Pointers to the page tables which exists in the page directory mapped into the kernel's address space */
83 u32 page_entries_usage_count[1024]; /**< Tracks usage count of the page table pages, so they can be releases on the last reference */
86 /* Map Mali virtual address space (i.e. ensure page tables exist for the virtual range) */
87 _mali_osk_errcode_t mali_mmu_pagedir_map(struct mali_page_directory *pagedir, u32 mali_address, u32 size);
88 _mali_osk_errcode_t mali_mmu_pagedir_unmap(struct mali_page_directory *pagedir, u32 mali_address, u32 size);
90 /* Back virtual address space with actual pages. Assumes input is contiguous and 4k aligned. */
91 void mali_mmu_pagedir_update(struct mali_page_directory *pagedir, u32 mali_address,
92 mali_dma_addr phys_address, u32 size, u32 permission_bits);
94 u32 mali_allocate_empty_page(mali_io_address *virtual);
95 void mali_free_empty_page(mali_dma_addr address, mali_io_address virt_addr);
96 _mali_osk_errcode_t mali_create_fault_flush_pages(mali_dma_addr *page_directory,
97 mali_io_address *page_directory_mapping,
98 mali_dma_addr *page_table, mali_io_address *page_table_mapping,
99 mali_dma_addr *data_page, mali_io_address *data_page_mapping);
100 void mali_destroy_fault_flush_pages(
101 mali_dma_addr *page_directory, mali_io_address *page_directory_mapping,
102 mali_dma_addr *page_table, mali_io_address *page_table_mapping,
103 mali_dma_addr *data_page, mali_io_address *data_page_mapping);
105 struct mali_page_directory *mali_mmu_pagedir_alloc(void);
106 void mali_mmu_pagedir_free(struct mali_page_directory *pagedir);
108 void mali_mmu_pagedir_diag(struct mali_page_directory *pagedir, u32 fault_addr);
110 #endif /* __MALI_MMU_PAGE_DIRECTORY_H__ */