0ab35094004b3c4fc90aec2945c431d87f2fa1d3
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / mali400 / mali / common / mali_mem_validation.c
1 /*
2  * Copyright (C) 2011-2015 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 #include "mali_mem_validation.h"
12 #include "mali_osk.h"
13 #include "mali_kernel_common.h"
14
15 #define MALI_INVALID_MEM_ADDR 0xFFFFFFFF
16
17 typedef struct {
18         u32 phys_base;        /**< Mali physical base of the memory, page aligned */
19         u32 size;             /**< size in bytes of the memory, multiple of page size */
20 } _mali_mem_validation_t;
21
22 static _mali_mem_validation_t mali_mem_validator = { MALI_INVALID_MEM_ADDR, MALI_INVALID_MEM_ADDR };
23
24 _mali_osk_errcode_t mali_mem_validation_add_range(u32 start, u32 size)
25 {
26         /* Check that no other MEM_VALIDATION resources exist */
27         if (MALI_INVALID_MEM_ADDR != mali_mem_validator.phys_base) {
28                 MALI_PRINT_ERROR(("Failed to add frame buffer memory; another range is already specified\n"));
29                 return _MALI_OSK_ERR_FAULT;
30         }
31
32         /* Check restrictions on page alignment */
33         if ((0 != (start & (~_MALI_OSK_CPU_PAGE_MASK))) ||
34             (0 != (size & (~_MALI_OSK_CPU_PAGE_MASK)))) {
35                 MALI_PRINT_ERROR(("Failed to add frame buffer memory; incorrect alignment\n"));
36                 return _MALI_OSK_ERR_FAULT;
37         }
38
39         mali_mem_validator.phys_base = start;
40         mali_mem_validator.size = size;
41         MALI_DEBUG_PRINT(2, ("Memory Validator installed for Mali physical address base=0x%08X, size=0x%08X\n",
42                              mali_mem_validator.phys_base, mali_mem_validator.size));
43
44         return _MALI_OSK_ERR_OK;
45 }
46
47 _mali_osk_errcode_t mali_mem_validation_check(u32 phys_addr, u32 size)
48 {
49 #if 0
50         if (phys_addr < (phys_addr + size)) { /* Don't allow overflow (or zero size) */
51                 if ((0 == (phys_addr & (~_MALI_OSK_CPU_PAGE_MASK))) &&
52                     (0 == (size & (~_MALI_OSK_CPU_PAGE_MASK)))) {
53                         if ((phys_addr          >= mali_mem_validator.phys_base) &&
54                             ((phys_addr + (size - 1)) >= mali_mem_validator.phys_base) &&
55                             (phys_addr          <= (mali_mem_validator.phys_base + (mali_mem_validator.size - 1))) &&
56                             ((phys_addr + (size - 1)) <= (mali_mem_validator.phys_base + (mali_mem_validator.size - 1)))) {
57                                 MALI_DEBUG_PRINT(3, ("Accepted range 0x%08X + size 0x%08X (= 0x%08X)\n", phys_addr, size, (phys_addr + size - 1)));
58                                 return _MALI_OSK_ERR_OK;
59                         }
60                 }
61         }
62
63         MALI_PRINT_ERROR(("MALI PHYSICAL RANGE VALIDATION ERROR: The range supplied was: phys_base=0x%08X, size=0x%08X\n", phys_addr, size));
64
65         return _MALI_OSK_ERR_FAULT;
66 #endif
67         return _MALI_OSK_ERR_OK;
68 }