rockchip:midgard:1,update gpu version to r4p1-00rel0 2,add input handler when runtim...
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / midgard / mali_kbase_mem.h
1 /*
2  *
3  * (C) COPYRIGHT ARM Limited. All rights reserved.
4  *
5  * This program is free software and is provided to you under the terms of the
6  * GNU General Public License version 2 as published by the Free Software
7  * Foundation, and any use by you of this program is subject to the terms
8  * of such GNU licence.
9  *
10  * A copy of the licence is included with the program, and can also be obtained
11  * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
12  * Boston, MA  02110-1301, USA.
13  *
14  */
15
16
17
18
19
20 /**
21  * @file mali_kbase_mem.h
22  * Base kernel memory APIs
23  */
24
25 #ifndef _KBASE_MEM_H_
26 #define _KBASE_MEM_H_
27
28 #ifndef _KBASE_H_
29 #error "Don't include this file directly, use mali_kbase.h instead"
30 #endif
31
32 #include <malisw/mali_malisw.h>
33 #include <linux/kref.h>
34
35 #ifdef CONFIG_UMP
36 #include <linux/ump.h>
37 #endif                          /* CONFIG_UMP */
38 #include "mali_base_kernel.h"
39 #include <mali_kbase_hw.h>
40 #include "mali_kbase_pm.h"
41 #include "mali_kbase_defs.h"
42 #ifdef CONFIG_MALI_GATOR_SUPPORT
43 #include "mali_kbase_gator.h"
44 #endif  /*CONFIG_MALI_GATOR_SUPPORT*/
45
46 /* Part of the workaround for uTLB invalid pages is to ensure we grow/shrink tmem by 4 pages at a time */
47 #define KBASEP_TMEM_GROWABLE_BLOCKSIZE_PAGES_LOG2_HW_ISSUE_8316 (2)     /* round to 4 pages */
48
49 /* Part of the workaround for PRLAM-9630 requires us to grow/shrink memory by 8 pages.
50 The MMU reads in 8 page table entries from memory at a time, if we have more than one page fault within the same 8 pages and
51 page tables are updated accordingly, the MMU does not re-read the page table entries from memory for the subsequent page table
52 updates and generates duplicate page faults as the page table information used by the MMU is not valid.   */
53 #define KBASEP_TMEM_GROWABLE_BLOCKSIZE_PAGES_LOG2_HW_ISSUE_9630 (3)     /* round to 8 pages */
54
55 #define KBASEP_TMEM_GROWABLE_BLOCKSIZE_PAGES_LOG2 (0)   /* round to 1 page */
56
57 /* This must always be a power of 2 */
58 #define KBASEP_TMEM_GROWABLE_BLOCKSIZE_PAGES (1u << KBASEP_TMEM_GROWABLE_BLOCKSIZE_PAGES_LOG2)
59 #define KBASEP_TMEM_GROWABLE_BLOCKSIZE_PAGES_HW_ISSUE_8316 (1u << KBASEP_TMEM_GROWABLE_BLOCKSIZE_PAGES_LOG2_HW_ISSUE_8316)
60 #define KBASEP_TMEM_GROWABLE_BLOCKSIZE_PAGES_HW_ISSUE_9630 (1u << KBASEP_TMEM_GROWABLE_BLOCKSIZE_PAGES_LOG2_HW_ISSUE_9630)
61 /**
62  * A CPU mapping
63  */
64 typedef struct kbase_cpu_mapping {
65         struct  list_head mappings_list;
66         struct  kbase_mem_phy_alloc *alloc;
67         struct  kbase_context *kctx;
68         struct  kbase_va_region *region;
69         pgoff_t page_off;
70         int     count;
71
72         unsigned long vm_start;
73         unsigned long vm_end;
74 } kbase_cpu_mapping;
75
76 enum kbase_memory_type {
77         KBASE_MEM_TYPE_NATIVE,
78         KBASE_MEM_TYPE_IMPORTED_UMP,
79         KBASE_MEM_TYPE_IMPORTED_UMM,
80         KBASE_MEM_TYPE_ALIAS,
81         KBASE_MEM_TYPE_TB,
82         KBASE_MEM_TYPE_RAW
83 };
84
85 /* internal structure, mirroring base_mem_aliasing_info,
86  * but with alloc instead of a gpu va (handle) */
87 struct kbase_aliased {
88         struct kbase_mem_phy_alloc *alloc; /* NULL for special, non-NULL for native */
89         u64 offset; /* in pages */
90         u64 length; /* in pages */
91 };
92
93 /* physical pages tracking object.
94  * Set up to track N pages.
95  * N not stored here, the creator holds that info.
96  * This object only tracks how many elements are actually valid (present).
97  * Changing of nents or *pages should only happen if the kbase_mem_phy_alloc is not
98  * shared with another region or client. CPU mappings are OK to exist when changing, as
99  * long as the tracked mappings objects are updated as part of the change.
100  */
101 struct kbase_mem_phy_alloc
102 {
103         struct kref           kref; /* number of users of this alloc */
104         atomic_t              gpu_mappings;
105         size_t                nents; /* 0..N */
106         phys_addr_t *         pages; /* N elements, only 0..nents are valid */
107
108         /* kbase_cpu_mappings */
109         struct list_head      mappings;
110
111         /* type of buffer */
112         enum kbase_memory_type type;
113
114         int accessed_cached;
115
116         /* member in union valid based on @a type */
117         union {
118 #ifdef CONFIG_UMP
119                 ump_dd_handle ump_handle;
120 #endif /* CONFIG_UMP */
121 #if defined(CONFIG_DMA_SHARED_BUFFER)
122                 struct {
123                         struct dma_buf *dma_buf;
124                         struct dma_buf_attachment *dma_attachment;
125                         unsigned int current_mapping_usage_count;
126                         struct sg_table *sgt;
127                 } umm;
128 #endif /* defined(CONFIG_DMA_SHARED_BUFFER) */
129                 struct {
130                         mali_size64 stride;
131                         size_t nents;
132                         struct kbase_aliased *aliased;
133                 } alias;
134                 /* Used by type = (KBASE_MEM_TYPE_NATIVE, KBASE_MEM_TYPE_TB) */
135                 struct kbase_context *kctx;
136         } imported;
137 };
138
139 static inline void kbase_mem_phy_alloc_gpu_mapped(struct kbase_mem_phy_alloc *alloc)
140 {
141         KBASE_DEBUG_ASSERT(alloc);
142         /* we only track mappings of NATIVE buffers */
143         if (alloc->type == KBASE_MEM_TYPE_NATIVE)
144                 atomic_inc(&alloc->gpu_mappings);
145 }
146
147 static inline void kbase_mem_phy_alloc_gpu_unmapped(struct kbase_mem_phy_alloc *alloc)
148 {
149         KBASE_DEBUG_ASSERT(alloc);
150         /* we only track mappings of NATIVE buffers */
151         if (alloc->type == KBASE_MEM_TYPE_NATIVE)
152                 if (0 > atomic_dec_return(&alloc->gpu_mappings)) {
153                         pr_err("Mismatched %s:\n", __func__);
154                         dump_stack();
155                 }
156 }
157
158 void kbase_mem_kref_free(struct kref * kref);
159
160 mali_error kbase_mem_init(kbase_device * kbdev);
161 void kbase_mem_halt(kbase_device * kbdev);
162 void kbase_mem_term(kbase_device * kbdev);
163
164 static inline struct kbase_mem_phy_alloc * kbase_mem_phy_alloc_get(struct kbase_mem_phy_alloc * alloc)
165 {
166         kref_get(&alloc->kref);
167         return alloc;
168 }
169
170 static inline struct kbase_mem_phy_alloc * kbase_mem_phy_alloc_put(struct kbase_mem_phy_alloc * alloc)
171 {
172         kref_put(&alloc->kref, kbase_mem_kref_free);
173         return NULL;
174 }
175
176 /**
177  * A GPU memory region, and attributes for CPU mappings.
178  */
179 typedef struct kbase_va_region {
180         struct rb_node rblink;
181         struct list_head link;
182
183         kbase_context *kctx;    /* Backlink to base context */
184
185         u64 start_pfn;          /* The PFN in GPU space */
186         size_t nr_pages;
187
188 /* Free region */
189 #define KBASE_REG_FREE              (1ul << 0)
190 /* CPU write access */
191 #define KBASE_REG_CPU_WR            (1ul << 1)
192 /* GPU write access */
193 #define KBASE_REG_GPU_WR            (1ul << 2)
194 /* No eXecute flag */
195 #define KBASE_REG_GPU_NX            (1ul << 3)
196 /* Is CPU cached? */
197 #define KBASE_REG_CPU_CACHED        (1ul << 4)
198 /* Is GPU cached? */
199 #define KBASE_REG_GPU_CACHED        (1ul << 5)
200
201 #define KBASE_REG_GROWABLE          (1ul << 6)
202 /* Can grow on pf? */
203 #define KBASE_REG_PF_GROW           (1ul << 7)
204
205 /* VA managed by us */
206 #define KBASE_REG_CUSTOM_VA         (1ul << 8)
207
208 /* inner shareable coherency */
209 #define KBASE_REG_SHARE_IN          (1ul << 9)
210 /* inner & outer shareable coherency */
211 #define KBASE_REG_SHARE_BOTH        (1ul << 10)
212
213 /* Space for 4 different zones */
214 #define KBASE_REG_ZONE_MASK         (3ul << 11)
215 #define KBASE_REG_ZONE(x)           (((x) & 3) << 11)
216
217 /* GPU read access */
218 #define KBASE_REG_GPU_RD            (1ul<<13)
219 /* CPU read access */
220 #define KBASE_REG_CPU_RD            (1ul<<14)
221
222 /* Aligned for GPU EX in SAME_VA */
223 #define KBASE_REG_ALIGNED           (1ul<<15)
224
225 /* Index of chosen MEMATTR for this region (0..7) */
226 #define KBASE_REG_MEMATTR_MASK      (7ul << 16)
227 #define KBASE_REG_MEMATTR_INDEX(x)  (((x) & 7) << 16)
228 #define KBASE_REG_MEMATTR_VALUE(x)  (((x) & KBASE_REG_MEMATTR_MASK) >> 16)
229
230 #define KBASE_REG_ZONE_SAME_VA      KBASE_REG_ZONE(0)
231
232 /* only used with 32-bit clients */
233 /*
234  * On a 32bit platform, custom VA should be wired from (4GB + shader region)
235  * to the VA limit of the GPU. Unfortunately, the Linux mmap() interface 
236  * limits us to 2^32 pages (2^44 bytes, see mmap64 man page for reference).
237  * So we put the default limit to the maximum possible on Linux and shrink
238  * it down, if required by the GPU, during initialization.
239  */
240 #define KBASE_REG_ZONE_EXEC         KBASE_REG_ZONE(1)   /* Dedicated 16MB region for shader code */
241 #define KBASE_REG_ZONE_EXEC_BASE    ((1ULL << 32) >> PAGE_SHIFT)
242 #define KBASE_REG_ZONE_EXEC_SIZE    ((16ULL * 1024 * 1024) >> PAGE_SHIFT)
243
244 #define KBASE_REG_ZONE_CUSTOM_VA         KBASE_REG_ZONE(2)
245 #define KBASE_REG_ZONE_CUSTOM_VA_BASE    (KBASE_REG_ZONE_EXEC_BASE + KBASE_REG_ZONE_EXEC_SIZE) /* Starting after KBASE_REG_ZONE_EXEC */
246 #define KBASE_REG_ZONE_CUSTOM_VA_SIZE    (((1ULL << 44) >> PAGE_SHIFT) - KBASE_REG_ZONE_CUSTOM_VA_BASE)
247 /* end 32-bit clients only */
248
249         unsigned long flags;
250
251         size_t extent; /* nr of pages alloc'd on PF */
252
253         struct kbase_mem_phy_alloc * alloc; /* the one alloc object we mmap to the GPU and CPU when mapping this region */
254
255         /* non-NULL if this memory object is a kds_resource */
256         struct kds_resource *kds_res;
257
258 } kbase_va_region;
259
260 /* Common functions */
261 static INLINE phys_addr_t *kbase_get_phy_pages(struct kbase_va_region *reg)
262 {
263         KBASE_DEBUG_ASSERT(reg);
264         KBASE_DEBUG_ASSERT(reg->alloc);
265
266         return reg->alloc->pages;
267 }
268
269 static INLINE size_t kbase_reg_current_backed_size(struct kbase_va_region * reg)
270 {
271         KBASE_DEBUG_ASSERT(reg);
272         /* if no alloc object the backed size naturally is 0 */
273         if (reg->alloc)
274                 return reg->alloc->nents;
275         else
276                 return 0;
277 }
278
279 static INLINE struct kbase_mem_phy_alloc * kbase_alloc_create(size_t nr_pages, enum kbase_memory_type type)
280 {
281         struct kbase_mem_phy_alloc *alloc;
282
283         /* Prevent nr_pages*sizeof + sizeof(*alloc) from wrapping around. */
284         if (nr_pages > ((((size_t) -1) - sizeof(*alloc)) / sizeof(*alloc->pages)))
285                 return ERR_PTR(-ENOMEM);
286
287         alloc = vzalloc(sizeof(*alloc) + sizeof(*alloc->pages) * nr_pages);
288         if (!alloc)
289                 return ERR_PTR(-ENOMEM);
290
291         kref_init(&alloc->kref);
292         atomic_set(&alloc->gpu_mappings, 0);
293         alloc->nents = 0;
294         alloc->pages = (void*)(alloc + 1);
295         INIT_LIST_HEAD(&alloc->mappings);
296         alloc->type = type;
297
298         return alloc;
299 }
300
301 static INLINE int kbase_reg_prepare_native(struct kbase_va_region * reg, struct kbase_context * kctx)
302 {
303         KBASE_DEBUG_ASSERT(reg);
304         KBASE_DEBUG_ASSERT(!reg->alloc);
305         KBASE_DEBUG_ASSERT(reg->flags & KBASE_REG_FREE);
306
307         reg->alloc = kbase_alloc_create(reg->nr_pages, KBASE_MEM_TYPE_NATIVE);
308         if (IS_ERR(reg->alloc))
309                 return PTR_ERR(reg->alloc);
310         else if (!reg->alloc)
311                 return -ENOMEM;
312         reg->alloc->imported.kctx = kctx;
313         reg->flags &= ~KBASE_REG_FREE;
314         return 0;
315 }
316
317 static inline int kbase_atomic_add_pages(int num_pages, atomic_t *used_pages)
318 {
319         int new_val = atomic_add_return(num_pages, used_pages);
320 #ifdef CONFIG_MALI_GATOR_SUPPORT
321         kbase_trace_mali_total_alloc_pages_change((long long int)new_val);
322 #endif
323         return new_val;
324 }
325
326 static inline int kbase_atomic_sub_pages(int num_pages, atomic_t *used_pages)
327 {
328         int new_val = atomic_sub_return(num_pages, used_pages);
329 #ifdef CONFIG_MALI_GATOR_SUPPORT
330         kbase_trace_mali_total_alloc_pages_change((long long int)new_val);
331 #endif
332         return new_val;
333 }
334
335 /**
336  * @brief Initialize an OS based memory allocator.
337  *
338  * Initializes a allocator.
339  * Must be called before any allocation is attempted.
340  * \a kbase_mem_allocator_alloc and \a kbase_mem_allocator_free is used
341  * to allocate and free memory.
342  * \a kbase_mem_allocator_term must be called to clean up the allocator.
343  * All memory obtained via \a kbase_mem_allocator_alloc must have been
344  * \a kbase_mem_allocator_free before \a kbase_mem_allocator_term is called.
345  *
346  * @param allocator Allocator object to initialize
347  * @param max_size Maximum number of pages to keep on the freelist.
348  * @return MALI_ERROR_NONE on success, an error code indicating what failed on error.
349  */
350 mali_error kbase_mem_allocator_init(kbase_mem_allocator * allocator, unsigned int max_size);
351
352 /**
353  * @brief Allocate memory via an OS based memory allocator.
354  *
355  * @param[in] allocator Allocator to obtain the memory from
356  * @param nr_pages Number of pages to allocate
357  * @param[out] pages Pointer to an array where the physical address of the allocated pages will be stored
358  * @return MALI_ERROR_NONE if the pages were allocated, an error code indicating what failed on error
359  */
360 mali_error kbase_mem_allocator_alloc(kbase_mem_allocator * allocator, size_t nr_pages, phys_addr_t *pages);
361
362 /**
363  * @brief Free memory obtained for an OS based memory allocator.
364  *
365  * @param[in] allocator Allocator to free the memory back to
366  * @param nr_pages Number of pages to free
367  * @param[in] pages Pointer to an array holding the physical address of the paghes to free.
368  * @param[in] sync_back MALI_TRUE case the memory should be synced back
369  */
370 void kbase_mem_allocator_free(kbase_mem_allocator * allocator, size_t nr_pages, phys_addr_t *pages, mali_bool sync_back);
371
372 /**
373  * @brief Terminate an OS based memory allocator.
374  *
375  * Frees all cached allocations and clean up internal state.
376  * All allocate pages must have been \a kbase_mem_allocator_free before
377  * this function is called.
378  *
379  * @param[in] allocator Allocator to terminate
380  */
381 void kbase_mem_allocator_term(kbase_mem_allocator * allocator);
382
383
384
385 mali_error kbase_region_tracker_init(kbase_context *kctx);
386 void kbase_region_tracker_term(kbase_context *kctx);
387
388 struct kbase_va_region *kbase_region_tracker_find_region_enclosing_range(kbase_context *kctx, u64 start_pgoff, size_t nr_pages);
389
390 struct kbase_va_region *kbase_region_tracker_find_region_enclosing_address(kbase_context *kctx, mali_addr64 gpu_addr);
391
392 /**
393  * @brief Check that a pointer is actually a valid region.
394  *
395  * Must be called with context lock held.
396  */
397 struct kbase_va_region *kbase_region_tracker_find_region_base_address(kbase_context *kctx, mali_addr64 gpu_addr);
398
399 struct kbase_va_region *kbase_alloc_free_region(kbase_context *kctx, u64 start_pfn, size_t nr_pages, int zone);
400 void kbase_free_alloced_region(struct kbase_va_region *reg);
401 mali_error kbase_add_va_region(kbase_context *kctx, struct kbase_va_region *reg, mali_addr64 addr, size_t nr_pages, size_t align);
402
403 mali_error kbase_gpu_mmap(kbase_context *kctx, struct kbase_va_region *reg, mali_addr64 addr, size_t nr_pages, size_t align);
404 mali_bool kbase_check_alloc_flags(unsigned long flags);
405 void kbase_update_region_flags(struct kbase_va_region *reg, unsigned long flags);
406
407 void kbase_gpu_vm_lock(kbase_context *kctx);
408 void kbase_gpu_vm_unlock(kbase_context *kctx);
409
410 int kbase_alloc_phy_pages(struct kbase_va_region *reg, size_t vsize, size_t size);
411
412 mali_error kbase_mmu_init(kbase_context *kctx);
413 void kbase_mmu_term(kbase_context *kctx);
414
415 phys_addr_t kbase_mmu_alloc_pgd(kbase_context *kctx);
416 void kbase_mmu_free_pgd(kbase_context *kctx);
417 mali_error kbase_mmu_insert_pages(kbase_context *kctx, u64 vpfn,
418                                   phys_addr_t *phys, size_t nr,
419                                   unsigned long flags);
420 mali_error kbase_mmu_insert_single_page(kbase_context *kctx, u64 vpfn,
421                                         phys_addr_t phys, size_t nr,
422                                         unsigned long flags);
423
424 mali_error kbase_mmu_teardown_pages(kbase_context *kctx, u64 vpfn, size_t nr);
425 mali_error kbase_mmu_update_pages(kbase_context* kctx, u64 vpfn, phys_addr_t* phys, size_t nr, unsigned long flags);
426
427 /**
428  * @brief Register region and map it on the GPU.
429  *
430  * Call kbase_add_va_region() and map the region on the GPU.
431  */
432 mali_error kbase_gpu_mmap(kbase_context *kctx, struct kbase_va_region *reg, mali_addr64 addr, size_t nr_pages, size_t align);
433
434 /**
435  * @brief Remove the region from the GPU and unregister it.
436  *
437  * Must be called with context lock held.
438  */
439 mali_error kbase_gpu_munmap(kbase_context *kctx, struct kbase_va_region *reg);
440
441 /**
442  * The caller has the following locking conditions:
443  * - It must hold kbase_as::transaction_mutex on kctx's address space
444  * - It must hold the kbasep_js_device_data::runpool_irq::lock
445  */
446 void kbase_mmu_update(kbase_context *kctx);
447
448 /**
449  * The caller has the following locking conditions:
450  * - It must hold kbase_as::transaction_mutex on kctx's address space
451  * - It must hold the kbasep_js_device_data::runpool_irq::lock
452  */
453 void kbase_mmu_disable(kbase_context *kctx);
454
455 void kbase_mmu_interrupt(kbase_device *kbdev, u32 irq_stat);
456
457 /** Dump the MMU tables to a buffer
458  *
459  * This function allocates a buffer (of @c nr_pages pages) to hold a dump of the MMU tables and fills it. If the
460  * buffer is too small then the return value will be NULL.
461  *
462  * The GPU vm lock must be held when calling this function.
463  *
464  * The buffer returned should be freed with @ref vfree when it is no longer required.
465  *
466  * @param[in]   kctx        The kbase context to dump
467  * @param[in]   nr_pages    The number of pages to allocate for the buffer.
468  *
469  * @return The address of the buffer containing the MMU dump or NULL on error (including if the @c nr_pages is too
470  * small)
471  */
472 void *kbase_mmu_dump(kbase_context *kctx, int nr_pages);
473
474 mali_error kbase_sync_now(kbase_context *kctx, base_syncset *syncset);
475 void kbase_pre_job_sync(kbase_context *kctx, base_syncset *syncsets, size_t nr);
476 void kbase_post_job_sync(kbase_context *kctx, base_syncset *syncsets, size_t nr);
477
478 /**
479  * Set attributes for imported tmem region
480  *
481  * This function sets (extends with) requested attributes for given region
482  * of imported external memory
483  *
484  * @param[in]  kctx         The kbase context which the tmem belongs to
485  * @param[in]  gpu_adr     The base address of the tmem region
486  * @param[in]  attributes   The attributes of tmem region to be set
487  *
488  * @return MALI_ERROR_NONE on success.  Any other value indicates failure.
489  */
490 mali_error kbase_tmem_set_attributes(kbase_context *kctx, mali_addr64 gpu_adr, u32  attributes );
491
492 /**
493  * Get attributes of imported tmem region
494  *
495  * This function retrieves the attributes of imported external memory
496  *
497  * @param[in]  kctx         The kbase context which the tmem belongs to
498  * @param[in]  gpu_adr     The base address of the tmem region
499  * @param[out] attributes   The actual attributes of tmem region
500  *
501  * @return MALI_ERROR_NONE on success.  Any other value indicates failure.
502  */
503 mali_error kbase_tmem_get_attributes(kbase_context *kctx, mali_addr64 gpu_adr, u32 * const attributes );
504
505 /* OS specific functions */
506 mali_error kbase_mem_free(kbase_context *kctx, mali_addr64 gpu_addr);
507 mali_error kbase_mem_free_region(kbase_context *kctx, struct kbase_va_region *reg);
508 void kbase_os_mem_map_lock(kbase_context *kctx);
509 void kbase_os_mem_map_unlock(kbase_context *kctx);
510
511 /**
512  * @brief Update the memory allocation counters for the current process
513  *
514  * OS specific call to updates the current memory allocation counters for the current process with
515  * the supplied delta.
516  *
517  * @param[in] kctx  The kbase context 
518  * @param[in] pages The desired delta to apply to the memory usage counters.
519  */
520
521 void kbasep_os_process_page_usage_update( struct kbase_context * kctx, int pages );
522
523 /**
524  * @brief Add to the memory allocation counters for the current process
525  *
526  * OS specific call to add to the current memory allocation counters for the current process by
527  * the supplied amount.
528  *
529  * @param[in] kctx  The kernel base context used for the allocation.
530  * @param[in] pages The desired delta to apply to the memory usage counters.
531  */
532
533 static INLINE void kbase_process_page_usage_inc( struct kbase_context *kctx, int pages )
534 {
535         kbasep_os_process_page_usage_update( kctx, pages );
536 }
537
538 /**
539  * @brief Subtract from the memory allocation counters for the current process
540  *
541  * OS specific call to subtract from the current memory allocation counters for the current process by
542  * the supplied amount.
543  *
544  * @param[in] kctx  The kernel base context used for the allocation.
545  * @param[in] pages The desired delta to apply to the memory usage counters.
546  */
547
548 static INLINE void kbase_process_page_usage_dec( struct kbase_context *kctx, int pages )
549 {
550         kbasep_os_process_page_usage_update( kctx, 0 - pages );
551 }
552
553 /**
554  * @brief Find the offset of the CPU mapping of a memory allocation containing
555  *        a given address range
556  *
557  * Searches for a CPU mapping of any part of the region starting at @p gpu_addr
558  * that fully encloses the CPU virtual address range specified by @p uaddr and
559  * @p size. Returns a failure indication if only part of the address range lies
560  * within a CPU mapping, or the address range lies within a CPU mapping of a
561  * different region.
562  *
563  * @param[in,out] kctx      The kernel base context used for the allocation.
564  * @param[in]     gpu_addr  GPU address of the start of the allocated region
565  *                          within which to search.
566  * @param[in]     uaddr     Start of the CPU virtual address range.
567  * @param[in]     size      Size of the CPU virtual address range (in bytes).
568  * @param[out]    offset    The offset from the start of the allocation to the
569  *                          specified CPU virtual address.
570  *
571  * @return MALI_ERROR_NONE if offset was obtained successfully. Error code
572  *         otherwise.
573  */
574 mali_error kbasep_find_enclosing_cpu_mapping_offset(kbase_context *kctx,
575                                                         mali_addr64 gpu_addr,
576                                                         unsigned long uaddr,
577                                                         size_t size,
578                                                         mali_size64 *offset);
579
580 enum hrtimer_restart kbasep_as_poke_timer_callback(struct hrtimer *timer);
581 void kbase_as_poking_timer_retain_atom(kbase_device *kbdev, kbase_context *kctx, kbase_jd_atom *katom);
582 void kbase_as_poking_timer_release_atom(kbase_device *kbdev, kbase_context *kctx, kbase_jd_atom *katom);
583
584 /**
585 * @brief Allocates physical pages.
586 *
587 * Allocates \a nr_pages_requested and updates the alloc object.
588 *
589 * @param[in] alloc allocation object to add pages to
590 * @param[in] nr_pages_requested number of physical pages to allocate
591 *
592 * @return 0 if all pages have been successfully allocated. Error code otherwise
593 */
594 int kbase_alloc_phy_pages_helper(struct kbase_mem_phy_alloc * alloc, size_t nr_pages_requested);
595
596 /**
597 * @brief Free physical pages.
598 *
599 * Frees \a nr_pages and updates the alloc object.
600 *
601 * @param[in] alloc allocation object to free pages from
602 * @param[in] nr_pages_to_free number of physical pages to free
603 */
604 int kbase_free_phy_pages_helper(struct kbase_mem_phy_alloc * alloc, size_t nr_pages_to_free);
605
606 #ifdef CONFIG_MALI_NO_MALI
607 static inline void kbase_wait_write_flush(kbase_context *kctx)
608 {
609 }
610 #else
611 void kbase_wait_write_flush(kbase_context *kctx);
612 #endif
613
614
615 #endif                          /* _KBASE_MEM_H_ */