1 /* SPDX-License-Identifier: BSD-3-Clause
2 *
3 * Copyright(c) 2016 Intel Corporation. All rights reserved.
4 *
5 * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
6 * Xiuli Pan <xiuli.pan@linux.intel.com>
7 */
8
9 #ifndef __SOF_LIB_MAILBOX_H__
10 #define __SOF_LIB_MAILBOX_H__
11
12 #include <kernel/mailbox.h>
13 #include <platform/lib/mailbox.h>
14 #include <sof/debug/panic.h>
15 #include <sof/lib/cache.h>
16 #include <sof/string.h>
17 #include <stddef.h>
18 #include <stdint.h>
19
20 #define mailbox_get_exception_base() \
21 MAILBOX_EXCEPTION_BASE
22
23 #define mailbox_get_exception_size() \
24 MAILBOX_EXCEPTION_SIZE
25
26 #define mailbox_get_dspbox_base() \
27 MAILBOX_DSPBOX_BASE
28
29 #define mailbox_get_dspbox_size() \
30 MAILBOX_DSPBOX_SIZE
31
32 #define mailbox_get_hostbox_base() \
33 MAILBOX_HOSTBOX_BASE
34
35 #define mailbox_get_hostbox_size() \
36 MAILBOX_HOSTBOX_SIZE
37
38 #define mailbox_get_debug_base() \
39 MAILBOX_DEBUG_BASE
40
41 #define mailbox_get_debug_size() \
42 MAILBOX_DEBUG_SIZE
43
44 static inline
mailbox_dspbox_write(size_t offset,const void * src,size_t bytes)45 void mailbox_dspbox_write(size_t offset, const void *src, size_t bytes)
46 {
47 int ret = memcpy_s((void *)(MAILBOX_DSPBOX_BASE + offset),
48 MAILBOX_DSPBOX_SIZE - offset, src, bytes);
49
50 assert(!ret);
51 dcache_writeback_region((void *)(MAILBOX_DSPBOX_BASE + offset), bytes);
52 }
53
54 static inline
mailbox_dspbox_read(void * dest,size_t dest_size,size_t offset,size_t bytes)55 void mailbox_dspbox_read(void *dest, size_t dest_size,
56 size_t offset, size_t bytes)
57 {
58 int ret;
59
60 dcache_invalidate_region((void *)(MAILBOX_DSPBOX_BASE + offset),
61 bytes);
62 ret = memcpy_s(dest, dest_size,
63 (void *)(MAILBOX_DSPBOX_BASE + offset), bytes);
64 assert(!ret);
65 }
66
67 #if CONFIG_LIBRARY
68
69 static inline
mailbox_hostbox_write(size_t offset,const void * src,size_t bytes)70 void mailbox_hostbox_write(size_t offset, const void *src, size_t bytes)
71 {}
72
73 #else
74
75 static inline
mailbox_hostbox_write(size_t offset,const void * src,size_t bytes)76 void mailbox_hostbox_write(size_t offset, const void *src, size_t bytes)
77 {
78 int ret = memcpy_s((void *)(MAILBOX_HOSTBOX_BASE + offset),
79 MAILBOX_HOSTBOX_SIZE - offset, src, bytes);
80
81 assert(!ret);
82 dcache_writeback_region((void *)(MAILBOX_HOSTBOX_BASE + offset), bytes);
83 }
84
85 #endif
86
87 static inline
mailbox_hostbox_read(void * dest,size_t dest_size,size_t offset,size_t bytes)88 void mailbox_hostbox_read(void *dest, size_t dest_size,
89 size_t offset, size_t bytes)
90 {
91 int ret;
92
93 dcache_invalidate_region((void *)(MAILBOX_HOSTBOX_BASE + offset),
94 bytes);
95 ret = memcpy_s(dest, dest_size,
96 (void *)(MAILBOX_HOSTBOX_BASE + offset), bytes);
97 assert(!ret);
98 }
99
100 static inline
mailbox_stream_write(size_t offset,const void * src,size_t bytes)101 void mailbox_stream_write(size_t offset, const void *src, size_t bytes)
102 {
103 int ret = memcpy_s((void *)(MAILBOX_STREAM_BASE + offset),
104 MAILBOX_STREAM_SIZE - offset, src, bytes);
105
106 assert(!ret);
107 dcache_writeback_region((void *)(MAILBOX_STREAM_BASE + offset),
108 bytes);
109 }
110
111 #endif /* __SOF_LIB_MAILBOX_H__ */
112