2 * This confidential and proprietary software may be used only as
3 * authorised by a licensing agreement from ARM Limited
4 * (C) COPYRIGHT 2011-2013 ARM Limited
6 * The entire notice above must be reproduced on all authorised
7 * copies and copies may only be made to the extent permitted
8 * by a licensing agreement from ARM Limited.
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
, u32 phys_address
, u32 size
, u32 cache_settings
);
93 u32
mali_page_directory_get_phys_address(struct mali_page_directory
*pagedir
, u32 index
);
95 u32
mali_allocate_empty_page(mali_io_address
*virtual);
96 void mali_free_empty_page(u32 address
, mali_io_address
virtual);
97 _mali_osk_errcode_t
mali_create_fault_flush_pages(u32
*page_directory
, mali_io_address
*page_directory_mapping
,
98 u32
*page_table
, mali_io_address
*page_table_mapping
,
99 u32
*data_page
, mali_io_address
*data_page_mapping
);
100 void mali_destroy_fault_flush_pages(u32
*page_directory
, mali_io_address
*page_directory_mapping
,
101 u32
*page_table
, mali_io_address
*page_table_mapping
,
102 u32
*data_page
, mali_io_address
*data_page_mapping
);
104 struct mali_page_directory
*mali_mmu_pagedir_alloc(void);
105 void mali_mmu_pagedir_free(struct mali_page_directory
*pagedir
);
107 #endif /* __MALI_MMU_PAGE_DIRECTORY_H__ */