blob: 17d9daa8c6dc7ecf3dde0811d88c54e0ac414398 [file] [log] [blame]
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +01001/*
2 * Copyright (c) 2016, Intel Corporation
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the Intel Corporation nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Pan Xiuli530ef2a2018-05-04 15:41:48 +080029 * Xiuli Pan <xiuli.pan@linux.intel.com>
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010030 */
31
32#ifndef __INCLUDE_MAILBOX__
33#define __INCLUDE_MAILBOX__
34
35#include <platform/mailbox.h>
Liam Girdwood3c5d9a32017-06-07 10:13:57 +010036#include <arch/cache.h>
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010037#include <stdint.h>
Pierre-Louis Bossart81708a52018-04-04 18:46:50 -050038#include <sof/string.h>
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010039
Pan Xiuli530ef2a2018-05-04 15:41:48 +080040/* For those platform did not have SW_REG window, use DEBUG at now */
41#ifndef MAILBOX_SW_REG_BASE
42#define MAILBOX_SW_REG_BASE MAILBOX_DEBUG_BASE
43#endif /* MAILBOX_SW_REG_BASE */
44
Liam Girdwood2d5f55c2017-08-22 22:24:17 +010045/* 4k should be enough for everyone ..... */
46#define IPC_MAX_MAILBOX_BYTES 0x1000
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010047
48#define mailbox_get_exception_base() \
49 MAILBOX_EXCEPTION_BASE
50
51#define mailbox_get_exception_size() \
52 MAILBOX_EXCEPTION_SIZE
53
Liam Girdwood46be4c52017-09-05 23:49:38 +010054#define mailbox_get_dspbox_base() \
55 MAILBOX_DSPBOX_BASE
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010056
Liam Girdwood46be4c52017-09-05 23:49:38 +010057#define mailbox_get_dspbox_size() \
58 MAILBOX_DSPBOX_SIZE
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010059
Liam Girdwood46be4c52017-09-05 23:49:38 +010060#define mailbox_get_hostbox_base() \
61 MAILBOX_HOSTBOX_BASE
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010062
Liam Girdwood46be4c52017-09-05 23:49:38 +010063#define mailbox_get_hostbox_size() \
64 MAILBOX_HOSTBOX_SIZE
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010065
66#define mailbox_get_debug_base() \
67 MAILBOX_DEBUG_BASE
68
69#define mailbox_get_debug_size() \
70 MAILBOX_DEBUG_SIZE
71
Pierre-Louis Bossart082c86f2018-04-03 08:57:18 -050072static inline
73void mailbox_dspbox_write(size_t offset, const void *src, size_t bytes)
74{
75 rmemcpy((void *)(MAILBOX_DSPBOX_BASE + offset), src, bytes);
76 dcache_writeback_region((void *)(MAILBOX_DSPBOX_BASE + offset), bytes);
77}
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010078
Pierre-Louis Bossart082c86f2018-04-03 08:57:18 -050079static inline
80void mailbox_dspbox_read(void *dest, size_t offset, size_t bytes)
81{
82 dcache_invalidate_region((void *)(MAILBOX_DSPBOX_BASE + offset), bytes);
83 rmemcpy(dest, (void *)(MAILBOX_DSPBOX_BASE + offset), bytes);
84}
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010085
Pierre-Louis Bossart082c86f2018-04-03 08:57:18 -050086static inline
87void mailbox_hostbox_write(size_t offset, const void *src, size_t bytes)
88{
89 rmemcpy((void *)(MAILBOX_HOSTBOX_BASE + offset), src, bytes);
90 dcache_writeback_region((void *)(MAILBOX_HOSTBOX_BASE + offset), bytes);
91}
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010092
Pierre-Louis Bossart082c86f2018-04-03 08:57:18 -050093static inline
94void mailbox_hostbox_read(void *dest, size_t offset, size_t bytes)
95{
96 dcache_invalidate_region((void *)(MAILBOX_HOSTBOX_BASE + offset),
97 bytes);
98 rmemcpy(dest, (void *)(MAILBOX_HOSTBOX_BASE + offset), bytes);
99}
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +0100100
Pierre-Louis Bossart082c86f2018-04-03 08:57:18 -0500101static inline
102void mailbox_stream_write(size_t offset, const void *src, size_t bytes)
103{
104 rmemcpy((void *)(MAILBOX_STREAM_BASE + offset), src, bytes);
105 dcache_writeback_region((void *)(MAILBOX_STREAM_BASE + offset),
106 bytes);
107}
Pan Xiulie92ef972018-03-02 17:20:27 +0800108
Pan Xiuli530ef2a2018-05-04 15:41:48 +0800109static inline
110void mailbox_sw_reg_write(size_t offset, uint32_t src)
111{
112 *((volatile uint32_t*)(MAILBOX_SW_REG_BASE + offset)) = src;
113 dcache_writeback_region((void *)(MAILBOX_SW_REG_BASE + offset),
114 sizeof(src));
115}
116
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +0100117#endif