2 * Copyright (C) 2010-2015 ARM Limited. All rights reserved.
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.
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.
12 * @file mali_osk_low_level_mem.c
13 * Implementation of the OS abstraction layer for the kernel device driver
17 #include <linux/ioport.h>
18 #include <linux/slab.h>
20 #include "mali_kernel_common.h"
24 void _mali_osk_mem_barrier(void)
29 void _mali_osk_write_mem_barrier(void)
34 mali_io_address _mali_osk_mem_mapioregion(uintptr_t phys, u32 size, const char *description)
36 return (mali_io_address)ioremap_nocache(phys, size);
39 void _mali_osk_mem_unmapioregion(uintptr_t phys, u32 size, mali_io_address virt)
41 iounmap((void *)virt);
44 _mali_osk_errcode_t inline _mali_osk_mem_reqregion(uintptr_t phys, u32 size, const char *description)
46 #if MALI_LICENSE_IS_GPL
47 return _MALI_OSK_ERR_OK; /* GPL driver gets the mem region for the resources registered automatically */
49 return ((NULL == request_mem_region(phys, size, description)) ? _MALI_OSK_ERR_NOMEM : _MALI_OSK_ERR_OK);
53 void inline _mali_osk_mem_unreqregion(uintptr_t phys, u32 size)
55 #if !MALI_LICENSE_IS_GPL
56 release_mem_region(phys, size);
60 void inline _mali_osk_mem_iowrite32_relaxed(volatile mali_io_address addr, u32 offset, u32 val)
62 __raw_writel(cpu_to_le32(val), ((u8 *)addr) + offset);
65 u32 inline _mali_osk_mem_ioread32(volatile mali_io_address addr, u32 offset)
67 return ioread32(((u8 *)addr) + offset);
70 void inline _mali_osk_mem_iowrite32(volatile mali_io_address addr, u32 offset, u32 val)
72 iowrite32(val, ((u8 *)addr) + offset);
75 void _mali_osk_cache_flushall(void)
77 /** @note Cached memory is not currently supported in this implementation */
80 void _mali_osk_cache_ensure_uncached_range_flushed(void *uncached_mapping, u32 offset, u32 size)
82 _mali_osk_write_mem_barrier();
85 u32 _mali_osk_mem_write_safe(void __user *dest, const void __user *src, u32 size)
87 #define MALI_MEM_SAFE_COPY_BLOCK_SIZE 4096
91 temp_buf = kmalloc(MALI_MEM_SAFE_COPY_BLOCK_SIZE, GFP_KERNEL);
92 if (NULL != temp_buf) {
93 u32 bytes_left_to_copy = size;
95 for (i = 0; i < size; i += MALI_MEM_SAFE_COPY_BLOCK_SIZE) {
100 if (bytes_left_to_copy > MALI_MEM_SAFE_COPY_BLOCK_SIZE) {
101 size_to_copy = MALI_MEM_SAFE_COPY_BLOCK_SIZE;
103 size_to_copy = bytes_left_to_copy;
106 bytes_left = copy_from_user(temp_buf, ((char *)src) + i, size_to_copy);
107 size_copied = size_to_copy - bytes_left;
109 bytes_left = copy_to_user(((char *)dest) + i, temp_buf, size_copied);
110 size_copied -= bytes_left;
112 bytes_left_to_copy -= size_copied;
113 retval += size_copied;
115 if (size_copied != size_to_copy) {
116 break; /* Early out, we was not able to copy this entire block */
126 _mali_osk_errcode_t _mali_ukk_mem_write_safe(_mali_uk_mem_write_safe_s *args)
130 struct mali_session_data *session;
132 MALI_DEBUG_ASSERT_POINTER(args);
134 session = (struct mali_session_data *)(uintptr_t)args->ctx;
136 if (NULL == session) {
137 return _MALI_OSK_ERR_INVALID_ARGS;
140 src = (void __user *)(uintptr_t)args->src;
141 dst = (void __user *)(uintptr_t)args->dest;
143 /* Return number of bytes actually copied */
144 args->size = _mali_osk_mem_write_safe(dst, src, args->size);
145 return _MALI_OSK_ERR_OK;