tizen 2.4 release
[kernel/linux-3.0.git] / drivers / gpu / arm / mali400 / r4p0_rel0 / common / mali_mmu_page_directory.h
1 /*
2  * Copyright (C) 2011-2012 ARM Limited. All rights reserved.
3  * 
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.
6  * 
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.
9  */
10
11 #ifndef __MALI_MMU_PAGE_DIRECTORY_H__
12 #define __MALI_MMU_PAGE_DIRECTORY_H__
13
14 #include "mali_osk.h"
15
16 /**
17  * Size of an MMU page in bytes
18  */
19 #define MALI_MMU_PAGE_SIZE 0x1000
20
21 /*
22  * Size of the address space referenced by a page table page
23  */
24 #define MALI_MMU_VIRTUAL_PAGE_SIZE 0x400000 /* 4 MiB */
25
26 /**
27  * Page directory index from address
28  * Calculates the page directory index from the given address
29  */
30 #define MALI_MMU_PDE_ENTRY(address) (((address)>>22) & 0x03FF)
31
32 /**
33  * Page table index from address
34  * Calculates the page table index from the given address
35  */
36 #define MALI_MMU_PTE_ENTRY(address) (((address)>>12) & 0x03FF)
37
38 /**
39  * Extract the memory address from an PDE/PTE entry
40  */
41 #define MALI_MMU_ENTRY_ADDRESS(value) ((value) & 0xFFFFFC00)
42
43 #define MALI_INVALID_PAGE ((u32)(~0))
44
45 /**
46  *
47  */
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;
60
61
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 )
71
72 #define MALI_MMU_FLAGS_DEFAULT ( \
73         MALI_MMU_FLAGS_PRESENT | \
74         MALI_MMU_FLAGS_READ_PERMISSION |  \
75         MALI_MMU_FLAGS_WRITE_PERMISSION )
76
77
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 */
81
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 */
84 };
85
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);
89
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);
92
93 u32 mali_page_directory_get_phys_address(struct mali_page_directory *pagedir, u32 index);
94
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);
103
104 struct mali_page_directory *mali_mmu_pagedir_alloc(void);
105 void mali_mmu_pagedir_free(struct mali_page_directory *pagedir);
106
107 #endif /* __MALI_MMU_PAGE_DIRECTORY_H__ */