|
| 1 | +/* |
| 2 | + * Copyright (c) 2006-2026, RT-Thread Development Team |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + * |
| 6 | + * Must match avaota-f2-e907/board/amp_mbox.h slot layout. |
| 7 | + * |
| 8 | + * C907 stores were invisible to E907 when only DE-off / call-all was used. |
| 9 | + * Clean the line by VA (c906+c908 encodings) after each store; invalidate |
| 10 | + * before each load. Avoid l2cache.iall (hangs). |
| 11 | + */ |
| 12 | + |
| 13 | +#ifndef AMP_MBOX_H__ |
| 14 | +#define AMP_MBOX_H__ |
| 15 | + |
| 16 | +#include <stdint.h> |
| 17 | + |
| 18 | +#define AMP_SLOT_BASE 0x41000000U |
| 19 | +#define AMP_SLOT_C907 (AMP_SLOT_BASE + 0x00U) |
| 20 | +#define AMP_SLOT_C907_REPLY (AMP_SLOT_BASE + 0x04U) |
| 21 | +#define AMP_SLOT_E907 (AMP_SLOT_BASE + 0x20U) |
| 22 | +#define AMP_SLOT_E907_STEP (AMP_SLOT_BASE + 0x24U) |
| 23 | +#define AMP_SLOT_PING_REQ (AMP_SLOT_BASE + 0x40U) |
| 24 | + |
| 25 | +#define AMP_E2C_SEQ (AMP_SLOT_BASE + 0x80U) |
| 26 | +#define AMP_E2C_DATA (AMP_SLOT_BASE + 0x84U) |
| 27 | +#define AMP_E2C_ACK (AMP_SLOT_BASE + 0x88U) |
| 28 | +#define AMP_C2E_SEQ (AMP_SLOT_BASE + 0x90U) |
| 29 | +#define AMP_C2E_DATA (AMP_SLOT_BASE + 0x94U) |
| 30 | +#define AMP_C2E_ACK (AMP_SLOT_BASE + 0x98U) |
| 31 | +#define AMP_MSGBOX_PROBE (AMP_SLOT_BASE + 0xA0U) |
| 32 | + |
| 33 | +#define AMP_MAGIC_C907 0xC907A11CU |
| 34 | +#define AMP_MAGIC_E907 0xE907A11CU |
| 35 | +#define AMP_PING_REQ 0xA11C0001U |
| 36 | + |
| 37 | +#define AMP_MXSTATUS 0x7c0U |
| 38 | +#define AMP_MXSTATUS_THEADISAEE (1UL << 22) |
| 39 | + |
| 40 | +#define AMP_MSGBOX_BASE 0x03003000U |
| 41 | +#define AMP_MSGBOX_VER (AMP_MSGBOX_BASE + 0x10U) |
| 42 | + |
| 43 | +static inline void amp_fence(void) |
| 44 | +{ |
| 45 | + __asm__ volatile("fence ow, ow" ::: "memory"); |
| 46 | +} |
| 47 | + |
| 48 | +static inline void amp_enable_thead_isa(void) |
| 49 | +{ |
| 50 | + unsigned long v; |
| 51 | + __asm__ volatile("csrr %0, %1" : "=r"(v) : "i"(AMP_MXSTATUS)); |
| 52 | + v |= AMP_MXSTATUS_THEADISAEE; |
| 53 | + __asm__ volatile("csrw %0, %1" ::"i"(AMP_MXSTATUS), "r"(v) : "memory"); |
| 54 | +} |
| 55 | + |
| 56 | +static inline void amp_sync(void) |
| 57 | +{ |
| 58 | + __asm__ volatile(".long 0x0180000b" ::: "memory"); /* sync */ |
| 59 | +} |
| 60 | + |
| 61 | +/* Clean D-cache line by VA: try c906 (rs2=x4) and c908 (rs2=x5) encodings. */ |
| 62 | +static inline void amp_dcache_clean_va(uint32_t addr) |
| 63 | +{ |
| 64 | + amp_enable_thead_isa(); |
| 65 | + __asm__ volatile(".insn r 0x0b, 0, 1, x0, %0, x4" ::"r"(addr) : "memory"); |
| 66 | + __asm__ volatile(".insn r 0x0b, 0, 1, x0, %0, x5" ::"r"(addr) : "memory"); |
| 67 | + amp_sync(); |
| 68 | + amp_fence(); |
| 69 | +} |
| 70 | + |
| 71 | +static inline void amp_dcache_inv_va(uint32_t addr) |
| 72 | +{ |
| 73 | + amp_enable_thead_isa(); |
| 74 | + __asm__ volatile(".insn r 0x0b, 0, 1, x0, %0, x6" ::"r"(addr) : "memory"); /* iva */ |
| 75 | + __asm__ volatile(".insn r 0x0b, 0, 1, x0, %0, x5" ::"r"(addr) : "memory"); /* c906 may map differently */ |
| 76 | + amp_sync(); |
| 77 | + amp_fence(); |
| 78 | +} |
| 79 | + |
| 80 | +static inline void amp_coherent_begin(void) |
| 81 | +{ |
| 82 | + amp_enable_thead_isa(); |
| 83 | + __asm__ volatile(".long 0x0010000b" ::: "memory"); /* dcache.call */ |
| 84 | + amp_sync(); |
| 85 | + amp_fence(); |
| 86 | +} |
| 87 | + |
| 88 | +static inline uint32_t amp_read(uint32_t addr) |
| 89 | +{ |
| 90 | + amp_dcache_inv_va(addr); |
| 91 | + return *(volatile uint32_t *)addr; |
| 92 | +} |
| 93 | + |
| 94 | +static inline void amp_write(uint32_t addr, uint32_t value) |
| 95 | +{ |
| 96 | + *(volatile uint32_t *)addr = value; |
| 97 | + amp_fence(); |
| 98 | + amp_dcache_clean_va(addr); |
| 99 | + __asm__ volatile(".long 0x0010000b" ::: "memory"); /* dcache.call */ |
| 100 | + amp_sync(); |
| 101 | + amp_fence(); |
| 102 | +} |
| 103 | + |
| 104 | +#endif |
0 commit comments