summaryrefslogtreecommitdiff
path: root/hifi/xaf/hifi-dpf/include/sys/xt-shmem/xf-hal.h
blob: 82cf3c11f4072ddbf700ed9b6adb7a1294409d2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*******************************************************************************
* Copyright (C) 2018 Cadence Design Systems, Inc.
* 
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to use this Software with Cadence processor cores only and 
* not with any other processors and platforms, subject to
* the following conditions:
* 
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

******************************************************************************/

/*******************************************************************************
 * xf-hal.h
 *
 * Platform-specific HAL definitions
 *
 *******************************************************************************/

#ifndef __XF_H
#error "xf-hal.h mustn't be included directly"
#endif

/*******************************************************************************
 * Includes
 ******************************************************************************/

/* ...primitive types */
#include "xf-types.h"

/* ...XTOS runtime */
#include <xtensa/xtruntime.h>

/*******************************************************************************
 * Auxilliary macros definitions
 ******************************************************************************/

/* ...use system-specific cache-line size */
#define XF_PROXY_ALIGNMENT              XCHAL_DCACHE_LINESIZE

/* ...properly aligned shared memory structure */
#define __xf_shmem__        __attribute__((__aligned__(XF_PROXY_ALIGNMENT)))

/*******************************************************************************
 * Interrupt control
 ******************************************************************************/

/* ...disable interrupts on given core */
static inline u32 xf_isr_disable(u32 core)
{
    /* ...no actual dependency on the core identifier */
    return XTOS_SET_INTLEVEL(XCHAL_EXCM_LEVEL);
}

/* ...enable interrupts on given core */
static inline void xf_isr_restore(u32 core, u32 status)
{
    /* ...no actual dependency on the core identifier */
    XTOS_RESTORE_INTLEVEL(status);
}

/*******************************************************************************
 * Auxiliary system-specific functions
 ******************************************************************************/

#if XF_CFG_CORES_NUM > 1
/* ...current core identifier (from HW) */
static inline u32 xf_core_id(void)
{
    /* ...retrieve core identifier from HAL */
    return (u32) xthal_get_prid();
}
#else
#define xf_core_id()        0
#endif

/*******************************************************************************
 * Atomic operations (atomicity is assured on local core only)
 ******************************************************************************/

static inline int xf_atomic_test_and_set(volatile u32 *bitmap, u32 mask)
{
    u32     status;
    u32     v;

    /* ...atomicity is assured by interrupts masking */
    status = XTOS_DISABLE_ALL_INTERRUPTS;
    v = *bitmap, *bitmap = v | mask;
    XTOS_RESTORE_INTLEVEL(status);
    
    return !(v & mask);
}

static inline int xf_atomic_test_and_clear(volatile u32 *bitmap, u32 mask)
{
    u32     status;
    u32     v;

    /* ...atomicity is assured by interrupts masking */
    status = XTOS_DISABLE_ALL_INTERRUPTS;
    v = *bitmap, *bitmap = v & ~mask;
    XTOS_RESTORE_INTLEVEL(status);
    
    return (v & mask);
}

static inline u32 xf_atomic_set(volatile u32 *bitmap, u32 mask)
{
    u32     status;
    u32     v;

    /* ...atomicity is assured by interrupts masking */
    status = XTOS_DISABLE_ALL_INTERRUPTS;
    v = *bitmap, *bitmap = (v |= mask);
    XTOS_RESTORE_INTLEVEL(status);

    return v;
}

static inline u32 xf_atomic_clear(volatile u32 *bitmap, u32 mask)
{
    u32     status;
    u32     v;
    
    /* ...atomicity is assured by interrupts masking */
    status = XTOS_DISABLE_ALL_INTERRUPTS;
    v = *bitmap, *bitmap = (v &= ~mask);
    XTOS_RESTORE_INTLEVEL(status);

    return v;
}

/*******************************************************************************
 * Abortion macro (debugger should be configured)
 ******************************************************************************/

/* ...breakpoint function */
extern void breakpoint(void);

/* ...abort execution (enter into debugger) */
#define __xf_abort()            breakpoint()