1 /*
2 *
3 * SPDX-License-Identifier: GPL-2.0
4 *
5 * Copyright (C) 2011-2018 ARM or its affiliates
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 *
18 */
19
20 #include "acamera_logger.h"
21 #include <linux/gfp.h>
22 #include <linux/slab.h>
23
init_sw_io(void)24 int32_t init_sw_io( void )
25 {
26 int32_t result = 0;
27 //
28 return result;
29 }
30
close_sw_io(void)31 int32_t close_sw_io( void )
32 {
33 int32_t result = 0;
34 return result;
35 }
36
system_sw_alloc(uint32_t size)37 void *system_sw_alloc( uint32_t size )
38 {
39 return kzalloc( size, GFP_KERNEL | GFP_DMA | GFP_ATOMIC );
40 }
41
system_sw_free(void * ptr)42 void system_sw_free( void *ptr )
43 {
44 kfree( ptr );
45 }
46
system_sw_read_32(uintptr_t addr)47 uint32_t system_sw_read_32( uintptr_t addr )
48 {
49 uint32_t result = 0;
50 if ( (void *)addr != NULL ) {
51 volatile uint32_t *p_addr = (volatile uint32_t *)( addr );
52 result = *p_addr;
53 } else {
54 LOG( LOG_ERR, "Failed to read memory from address 0x%x. Base pointer is null ", addr );
55 }
56 return result;
57 }
58
system_sw_read_16(uintptr_t addr)59 uint16_t system_sw_read_16( uintptr_t addr )
60 {
61 uint16_t result = 0;
62 if ( (void *)addr != NULL ) {
63 volatile uint16_t *p_addr = (volatile uint16_t *)( addr );
64 result = *p_addr;
65 } else {
66 LOG( LOG_ERR, "Failed to read memory from address 0x%x. Base pointer is null ", addr );
67 }
68 return result;
69 }
70
system_sw_read_8(uintptr_t addr)71 uint8_t system_sw_read_8( uintptr_t addr )
72 {
73 uint8_t result = 0;
74 if ( (void *)addr != NULL ) {
75 volatile uint8_t *p_addr = (volatile uint8_t *)( addr );
76 result = *p_addr;
77 } else {
78 LOG( LOG_ERR, "Failed to read memory from address 0x%x. Base pointer is null ", addr );
79 }
80 return result;
81 }
82
83
system_sw_write_32(uintptr_t addr,uint32_t data)84 void system_sw_write_32( uintptr_t addr, uint32_t data )
85 {
86 if ( (void *)addr != NULL ) {
87 volatile uint32_t *p_addr = (volatile uint32_t *)( addr );
88 //LOG(LOG_CRIT, "SW WRITE full addr 0x%p addr %d, data %d", p_addr, addr, data );
89 *p_addr = data;
90 } else {
91 LOG( LOG_ERR, "Failed to write %d to memory 0x%x. Base pointer is null ", data, addr );
92 }
93 }
94
system_sw_write_16(uintptr_t addr,uint16_t data)95 void system_sw_write_16( uintptr_t addr, uint16_t data )
96 {
97 if ( (void *)addr != NULL ) {
98 volatile uint16_t *p_addr = (volatile uint16_t *)( addr );
99 *p_addr = data;
100 } else {
101 LOG( LOG_ERR, "Failed to write %d to memory 0x%x. Base pointer is null ", data, addr );
102 }
103 }
104
system_sw_write_8(uintptr_t addr,uint8_t data)105 void system_sw_write_8( uintptr_t addr, uint8_t data )
106 {
107 if ( (void *)addr != NULL ) {
108 volatile uint8_t *p_addr = (volatile uint8_t *)( addr );
109 *p_addr = data;
110 } else {
111 LOG( LOG_ERR, "Failed to write %d to memory 0x%x. Base pointer is null ", data, addr );
112 }
113 }
114