Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 1 | /* |
| 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 Xiuli | 530ef2a | 2018-05-04 15:41:48 +0800 | [diff] [blame] | 29 | * Xiuli Pan <xiuli.pan@linux.intel.com> |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 30 | */ |
| 31 | |
| 32 | #ifndef __INCLUDE_MAILBOX__ |
| 33 | #define __INCLUDE_MAILBOX__ |
| 34 | |
| 35 | #include <platform/mailbox.h> |
Liam Girdwood | 3c5d9a3 | 2017-06-07 10:13:57 +0100 | [diff] [blame] | 36 | #include <arch/cache.h> |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 37 | #include <stdint.h> |
Pierre-Louis Bossart | 81708a5 | 2018-04-04 18:46:50 -0500 | [diff] [blame] | 38 | #include <sof/string.h> |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 39 | |
Pan Xiuli | 530ef2a | 2018-05-04 15:41:48 +0800 | [diff] [blame] | 40 | /* 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 Girdwood | 2d5f55c | 2017-08-22 22:24:17 +0100 | [diff] [blame] | 45 | /* 4k should be enough for everyone ..... */ |
| 46 | #define IPC_MAX_MAILBOX_BYTES 0x1000 |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 47 | |
| 48 | #define mailbox_get_exception_base() \ |
| 49 | MAILBOX_EXCEPTION_BASE |
| 50 | |
| 51 | #define mailbox_get_exception_size() \ |
| 52 | MAILBOX_EXCEPTION_SIZE |
| 53 | |
Liam Girdwood | 46be4c5 | 2017-09-05 23:49:38 +0100 | [diff] [blame] | 54 | #define mailbox_get_dspbox_base() \ |
| 55 | MAILBOX_DSPBOX_BASE |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 56 | |
Liam Girdwood | 46be4c5 | 2017-09-05 23:49:38 +0100 | [diff] [blame] | 57 | #define mailbox_get_dspbox_size() \ |
| 58 | MAILBOX_DSPBOX_SIZE |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 59 | |
Liam Girdwood | 46be4c5 | 2017-09-05 23:49:38 +0100 | [diff] [blame] | 60 | #define mailbox_get_hostbox_base() \ |
| 61 | MAILBOX_HOSTBOX_BASE |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 62 | |
Liam Girdwood | 46be4c5 | 2017-09-05 23:49:38 +0100 | [diff] [blame] | 63 | #define mailbox_get_hostbox_size() \ |
| 64 | MAILBOX_HOSTBOX_SIZE |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 65 | |
| 66 | #define mailbox_get_debug_base() \ |
| 67 | MAILBOX_DEBUG_BASE |
| 68 | |
| 69 | #define mailbox_get_debug_size() \ |
| 70 | MAILBOX_DEBUG_SIZE |
| 71 | |
Pierre-Louis Bossart | 082c86f | 2018-04-03 08:57:18 -0500 | [diff] [blame] | 72 | static inline |
| 73 | void 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 Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 78 | |
Pierre-Louis Bossart | 082c86f | 2018-04-03 08:57:18 -0500 | [diff] [blame] | 79 | static inline |
| 80 | void 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 Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 85 | |
Pierre-Louis Bossart | 082c86f | 2018-04-03 08:57:18 -0500 | [diff] [blame] | 86 | static inline |
| 87 | void 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 Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 92 | |
Pierre-Louis Bossart | 082c86f | 2018-04-03 08:57:18 -0500 | [diff] [blame] | 93 | static inline |
| 94 | void 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 Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 100 | |
Pierre-Louis Bossart | 082c86f | 2018-04-03 08:57:18 -0500 | [diff] [blame] | 101 | static inline |
| 102 | void 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 Xiuli | e92ef97 | 2018-03-02 17:20:27 +0800 | [diff] [blame] | 108 | |
Pan Xiuli | 530ef2a | 2018-05-04 15:41:48 +0800 | [diff] [blame] | 109 | static inline |
| 110 | void 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 Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 117 | #endif |