/drivers/gpu/mali/mali/common/mali_mem_validation.c
C | 71 lines | 49 code | 11 blank | 11 comment | 10 complexity | a47c85f479bcd52c5d62403ce57a53d6 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
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#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 17typedef struct 18{ 19 u32 phys_base; /**< Mali physical base of the memory, page aligned */ 20 u32 size; /**< size in bytes of the memory, multiple of page size */ 21} _mali_mem_validation_t; 22 23static _mali_mem_validation_t mali_mem_validator = { MALI_INVALID_MEM_ADDR, MALI_INVALID_MEM_ADDR }; 24 25_mali_osk_errcode_t mali_mem_validation_add_range(const _mali_osk_resource_t *resource) 26{ 27 /* Check that no other MEM_VALIDATION resources exist */ 28 if (MALI_INVALID_MEM_ADDR != mali_mem_validator.phys_base) 29 { 30 MALI_PRINT_ERROR(("Failed to add MEM_VALIDATION resource %s; another range is already specified\n", resource->description)); 31 return _MALI_OSK_ERR_FAULT; 32 } 33 34 /* Check restrictions on page alignment */ 35 if ((0 != (resource->base & (~_MALI_OSK_CPU_PAGE_MASK))) || 36 (0 != (resource->size & (~_MALI_OSK_CPU_PAGE_MASK)))) 37 { 38 MALI_PRINT_ERROR(("Failed to add MEM_VALIDATION resource %s; incorrect alignment\n", resource->description)); 39 return _MALI_OSK_ERR_FAULT; 40 } 41 42 mali_mem_validator.phys_base = resource->base; 43 mali_mem_validator.size = resource->size; 44 MALI_DEBUG_PRINT(2, ("Memory Validator '%s' installed for Mali physical address base=0x%08X, size=0x%08X\n", 45 resource->description, mali_mem_validator.phys_base, mali_mem_validator.size)); 46 47 return _MALI_OSK_ERR_OK; 48} 49 50_mali_osk_errcode_t mali_mem_validation_check(u32 phys_addr, u32 size) 51{ 52 if (phys_addr < (phys_addr + size)) /* Don't allow overflow (or zero size) */ 53 { 54 if ((0 == ( phys_addr & (~_MALI_OSK_CPU_PAGE_MASK))) && 55 (0 == ( size & (~_MALI_OSK_CPU_PAGE_MASK)))) 56 { 57 if ((phys_addr >= mali_mem_validator.phys_base) && 58 ((phys_addr + (size - 1)) >= mali_mem_validator.phys_base) && 59 (phys_addr <= (mali_mem_validator.phys_base + (mali_mem_validator.size - 1))) && 60 ((phys_addr + (size - 1)) <= (mali_mem_validator.phys_base + (mali_mem_validator.size - 1))) ) 61 { 62 MALI_DEBUG_PRINT(3, ("Accepted range 0x%08X + size 0x%08X (= 0x%08X)\n", phys_addr, size, (phys_addr + size - 1))); 63 return _MALI_OSK_ERR_OK; 64 } 65 } 66 } 67 68 MALI_PRINT_ERROR(("MALI PHYSICAL RANGE VALIDATION ERROR: The range supplied was: phys_base=0x%08X, size=0x%08X\n", phys_addr, size)); 69 70 return _MALI_OSK_ERR_FAULT; 71}