1 /* SPDX-License-Identifier: BSD-3-Clause
2 *
3 * Copyright(c) 2020 Intel Corporation. All rights reserved.
4 *
5 * Author: Tomasz Lauda <tomasz.lauda@linux.intel.com>
6 */
7
8 #ifdef __PLATFORM_LIB_SHIM_H__
9
10 #ifndef __CAVS_LIB_SHIM_H__
11 #define __CAVS_LIB_SHIM_H__
12
13 #ifndef ASSEMBLY
14
15 #include <sof/lib/memory.h>
16 #include <stdint.h>
17
shim_read16(uint32_t reg)18 static inline uint16_t shim_read16(uint32_t reg)
19 {
20 return *((volatile uint16_t*)(SHIM_BASE + reg));
21 }
22
shim_write16(uint32_t reg,uint16_t val)23 static inline void shim_write16(uint32_t reg, uint16_t val)
24 {
25 *((volatile uint16_t*)(SHIM_BASE + reg)) = val;
26 }
27
shim_read(uint32_t reg)28 static inline uint32_t shim_read(uint32_t reg)
29 {
30 return *((volatile uint32_t*)(SHIM_BASE + reg));
31 }
32
shim_write(uint32_t reg,uint32_t val)33 static inline void shim_write(uint32_t reg, uint32_t val)
34 {
35 *((volatile uint32_t*)(SHIM_BASE + reg)) = val;
36 }
37
shim_read64(uint32_t reg)38 static inline uint64_t shim_read64(uint32_t reg)
39 {
40 return *((volatile uint64_t*)(SHIM_BASE + reg));
41 }
42
shim_write64(uint32_t reg,uint64_t val)43 static inline void shim_write64(uint32_t reg, uint64_t val)
44 {
45 *((volatile uint64_t*)(SHIM_BASE + reg)) = val;
46 }
47
sw_reg_read(uint32_t reg)48 static inline uint32_t sw_reg_read(uint32_t reg)
49 {
50 return *((volatile uint32_t*)((SRAM_SW_REG_BASE -
51 SRAM_ALIAS_OFFSET) + reg));
52 }
53
sw_reg_write(uint32_t reg,uint32_t val)54 static inline void sw_reg_write(uint32_t reg, uint32_t val)
55 {
56 *((volatile uint32_t*)((SRAM_SW_REG_BASE -
57 SRAM_ALIAS_OFFSET) + reg)) = val;
58 }
59
mn_reg_read(uint32_t reg,uint32_t id)60 static inline uint32_t mn_reg_read(uint32_t reg, uint32_t id)
61 {
62 return *((volatile uint32_t*)(MN_BASE + reg));
63 }
64
mn_reg_write(uint32_t reg,uint32_t id,uint32_t val)65 static inline void mn_reg_write(uint32_t reg, uint32_t id, uint32_t val)
66 {
67 *((volatile uint32_t*)(MN_BASE + reg)) = val;
68 }
69
irq_read(uint32_t reg)70 static inline uint32_t irq_read(uint32_t reg)
71 {
72 return *((volatile uint32_t*)(IRQ_BASE + reg));
73 }
74
irq_write(uint32_t reg,uint32_t val)75 static inline void irq_write(uint32_t reg, uint32_t val)
76 {
77 *((volatile uint32_t*)(IRQ_BASE + reg)) = val;
78 }
79
ipc_read(uint32_t reg)80 static inline uint32_t ipc_read(uint32_t reg)
81 {
82 return *((volatile uint32_t*)(IPC_HOST_BASE + reg));
83 }
84
ipc_write(uint32_t reg,uint32_t val)85 static inline void ipc_write(uint32_t reg, uint32_t val)
86 {
87 *((volatile uint32_t*)(IPC_HOST_BASE + reg)) = val;
88 }
89
idc_read(uint32_t reg,uint32_t core_id)90 static inline uint32_t idc_read(uint32_t reg, uint32_t core_id)
91 {
92 return *((volatile uint32_t*)(IPC_DSP_BASE(core_id) + reg));
93 }
94
idc_write(uint32_t reg,uint32_t core_id,uint32_t val)95 static inline void idc_write(uint32_t reg, uint32_t core_id, uint32_t val)
96 {
97 *((volatile uint32_t*)(IPC_DSP_BASE(core_id) + reg)) = val;
98 }
99
100 #endif /* !ASSEMBLY */
101
102 #endif /* __CAVS_LIB_SHIM_H__ */
103
104 #else
105
106 #error "This file shouldn't be included from outside of platform/lib/shim.h"
107
108 #endif /* __PLATFORM_LIB_SHIM_H__ */
109