2 * This confidential and proprietary software may be used only as
3 * authorised by a licensing agreement from ARM Limited
4 * (C) COPYRIGHT 2008-2013 ARM Limited
6 * The entire notice above must be reproduced on all authorised
7 * copies and copies may only be made to the extent permitted
8 * by a licensing agreement from ARM Limited.
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( u32 phys
, u32 size
, const char *description
)
36 return (mali_io_address
)ioremap_nocache(phys
, size
);
39 void _mali_osk_mem_unmapioregion( u32 phys
, u32 size
, mali_io_address virt
)
44 _mali_osk_errcode_t
inline _mali_osk_mem_reqregion( u32 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( u32 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 *dest
, const void *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
)
128 MALI_DEBUG_ASSERT_POINTER(args
);
130 if (NULL
== args
->ctx
) {
131 return _MALI_OSK_ERR_INVALID_ARGS
;
134 /* Return number of bytes actually copied */
135 args
->size
= _mali_osk_mem_write_safe(args
->dest
, args
->src
, args
->size
);
136 return _MALI_OSK_ERR_OK
;