2 * Copyright (C) 2011-2012 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
50 MALI_MMU_FLAGS_PRESENT = 0x01,
51 MALI_MMU_FLAGS_READ_PERMISSION = 0x02,
52 MALI_MMU_FLAGS_WRITE_PERMISSION = 0x04,
53 MALI_MMU_FLAGS_OVERRIDE_CACHE = 0x8,
54 MALI_MMU_FLAGS_WRITE_CACHEABLE = 0x10,
55 MALI_MMU_FLAGS_WRITE_ALLOCATE = 0x20,
56 MALI_MMU_FLAGS_WRITE_BUFFERABLE = 0x40,
57 MALI_MMU_FLAGS_READ_CACHEABLE = 0x80,
58 MALI_MMU_FLAGS_READ_ALLOCATE = 0x100,
59 MALI_MMU_FLAGS_MASK = 0x1FF,
60 } mali_mmu_entry_flags;
63 #define MALI_MMU_FLAGS_FORCE_GP_READ_ALLOCATE ( \
64 MALI_MMU_FLAGS_PRESENT | \
65 MALI_MMU_FLAGS_READ_PERMISSION | \
66 MALI_MMU_FLAGS_WRITE_PERMISSION | \
67 MALI_MMU_FLAGS_OVERRIDE_CACHE | \
68 MALI_MMU_FLAGS_WRITE_CACHEABLE | \
69 MALI_MMU_FLAGS_WRITE_BUFFERABLE | \
70 MALI_MMU_FLAGS_READ_CACHEABLE | \
71 MALI_MMU_FLAGS_READ_ALLOCATE )
74 struct mali_page_directory
76 u32 page_directory; /**< Physical address of the memory session's page directory */
77 mali_io_address page_directory_mapped; /**< Pointer to the mapped version of the page directory into the kernel's address space */
79 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 */
80 u32 page_entries_usage_count[1024]; /**< Tracks usage count of the page table pages, so they can be releases on the last reference */
83 /* Map Mali virtual address space (i.e. ensure page tables exist for the virtual range) */
84 _mali_osk_errcode_t mali_mmu_pagedir_map(struct mali_page_directory *pagedir, u32 mali_address, u32 size);
85 _mali_osk_errcode_t mali_mmu_pagedir_unmap(struct mali_page_directory *pagedir, u32 mali_address, u32 size);
87 /* Back virtual address space with actual pages. Assumes input is contiguous and 4k aligned. */
88 void mali_mmu_pagedir_update(struct mali_page_directory *pagedir, u32 mali_address, u32 phys_address, u32 size, u32 cache_settings);
90 u32 mali_page_directory_get_phys_address(struct mali_page_directory *pagedir, u32 index);
92 u32 mali_allocate_empty_page(void);
93 void mali_free_empty_page(u32 address);
94 _mali_osk_errcode_t mali_create_fault_flush_pages(u32 *page_directory, u32 *page_table, u32 *data_page);
95 void mali_destroy_fault_flush_pages(u32 *page_directory, u32 *page_table, u32 *data_page);
97 struct mali_page_directory *mali_mmu_pagedir_alloc(void);
98 void mali_mmu_pagedir_free(struct mali_page_directory *pagedir);
100 #endif /* __MALI_MMU_PAGE_DIRECTORY_H__ */