1 /* SPDX-License-Identifier: BSD-3-Clause
2 *
3 * Copyright(c) 2019 Intel Corporation. All rights reserved.
4 *
5 * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
6 * Keyon Jie <yang.jie@linux.intel.com>
7 */
8
9 #ifdef __PLATFORM_LIB_MAILBOX_H__
10
11 #ifndef __CAVS_LIB_MAILBOX_H__
12 #define __CAVS_LIB_MAILBOX_H__
13
14 #include <sof/debug/panic.h>
15 #include <sof/lib/memory.h>
16 #include <sof/string.h>
17 #include <stddef.h>
18 #include <stdint.h>
19
20 /*
21 * The Window Region on HPSRAM for cAVS platforms is organised like
22 * this. The actual region order is platform-specific, see memory.h
23 * files.
24 *
25 * +--------------------------------------------------------------------------+
26 * | Offset | Region | Size |
27 * +---------------------+----------------+-----------------------------------+
28 * | SRAM_TRACE_BASE | Trace Buffer W3| SRAM_TRACE_SIZE |
29 * +---------------------+----------------+-----------------------------------+
30 * | SRAM_DEBUG_BASE | Debug data W2 | SRAM_DEBUG_SIZE |
31 * +---------------------+----------------+-----------------------------------+
32 * | SRAM_INBOX_BASE | Inbox W1 | SRAM_INBOX_SIZE |
33 * +---------------------+----------------+-----------------------------------+
34 * | SRAM_OUTBOX_BASE | Outbox W0 | SRAM_MAILBOX_SIZE |
35 * +---------------------+----------------+-----------------------------------+
36 * | SRAM_SW_REG_BASE | SW Registers W0| SRAM_SW_REG_SIZE |
37 * +---------------------+----------------+-----------------------------------+
38 *
39 * Note: For suecreek SRAM_SW_REG window does not exist - MAILBOX_SW_REG_BASE
40 * and MAILBOX_SW_REG_BASE are equal to 0
41 */
42
43 /* window 3 - trace */
44 #define MAILBOX_TRACE_SIZE SRAM_TRACE_SIZE
45 #define MAILBOX_TRACE_BASE SRAM_TRACE_BASE
46
47 /* window 2 debug, exception and stream */
48 #define MAILBOX_DEBUG_SIZE SRAM_DEBUG_SIZE
49 #define MAILBOX_DEBUG_BASE SRAM_DEBUG_BASE
50
51 #define MAILBOX_EXCEPTION_SIZE SRAM_EXCEPT_SIZE
52 #define MAILBOX_EXCEPTION_BASE SRAM_EXCEPT_BASE
53 #define MAILBOX_EXCEPTION_OFFSET SRAM_DEBUG_SIZE
54
55 #define MAILBOX_STREAM_SIZE SRAM_STREAM_SIZE
56 #define MAILBOX_STREAM_BASE SRAM_STREAM_BASE
57 #define MAILBOX_STREAM_OFFSET (SRAM_DEBUG_SIZE + SRAM_EXCEPT_SIZE)
58
59 /* window 1 inbox/downlink and FW registers */
60 #define MAILBOX_HOSTBOX_SIZE SRAM_INBOX_SIZE
61 #define MAILBOX_HOSTBOX_BASE SRAM_INBOX_BASE
62
63 /* window 0 */
64 #define MAILBOX_DSPBOX_SIZE SRAM_OUTBOX_SIZE
65 #define MAILBOX_DSPBOX_BASE SRAM_OUTBOX_BASE
66
67 #define MAILBOX_SW_REG_SIZE SRAM_SW_REG_SIZE
68 #define MAILBOX_SW_REG_BASE SRAM_SW_REG_BASE
69
mailbox_sw_reg_write(size_t offset,uint32_t src)70 static inline void mailbox_sw_reg_write(size_t offset, uint32_t src)
71 {
72 volatile uint32_t *ptr;
73
74 ptr = (volatile uint32_t *)(MAILBOX_SW_REG_BASE + offset);
75 ptr = cache_to_uncache(ptr);
76 *ptr = src;
77 }
78
mailbox_sw_reg_write64(size_t offset,uint64_t src)79 static inline void mailbox_sw_reg_write64(size_t offset, uint64_t src)
80 {
81 volatile uint64_t *ptr;
82
83 ptr = (volatile uint64_t *)(MAILBOX_SW_REG_BASE + offset);
84 ptr = cache_to_uncache(ptr);
85 *ptr = src;
86 }
87
mailbox_sw_reg_read(size_t offset)88 static inline uint32_t mailbox_sw_reg_read(size_t offset)
89 {
90 volatile uint32_t *ptr;
91
92 ptr = (volatile uint32_t *)(MAILBOX_SW_REG_BASE + offset);
93 ptr = cache_to_uncache(ptr);
94
95 return *ptr;
96 }
97
mailbox_sw_reg_read64(size_t offset)98 static inline uint64_t mailbox_sw_reg_read64(size_t offset)
99 {
100 volatile uint64_t *ptr;
101
102 ptr = (volatile uint64_t *)(MAILBOX_SW_REG_BASE + offset);
103 ptr = cache_to_uncache(ptr);
104
105 return *ptr;
106 }
107
mailbox_sw_regs_write(size_t offset,const void * src,size_t bytes)108 static inline void mailbox_sw_regs_write(size_t offset, const void *src, size_t bytes)
109 {
110 int ret = memcpy_s((void *)(MAILBOX_SW_REG_BASE + offset),
111 MAILBOX_SW_REG_SIZE - offset, src, bytes);
112
113 assert(!ret);
114 dcache_writeback_region((void *)(MAILBOX_SW_REG_BASE + offset), bytes);
115 }
116
117 #endif /* __CAVS_LIB_MAILBOX_H__ */
118
119 #else
120
121 #error "This file shouldn't be included from outside of platform/lib/mailbox.h"
122
123 #endif /* __PLATFORM_LIB_MAILBOX_H__ */
124