TT Zephyr Platforms 18.11.99
Tenstorrent Firmware
Loading...
Searching...
No Matches
arc.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Tenstorrent AI ULC
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6#ifndef ARC_H
7#define ARC_H
8
9#include "reg.h"
10#include "status_reg.h"
11
12#include <stdint.h>
13
15
16#define ARC_AUX_TIMER_0_COUNT (0x21)
17#define ARC_AUX_TIMER_0_CONTROL (0x22)
18#define ARC_AUX_TIMER_0_LIMIT (0x23)
19
20#define ARC_CSM_START_ADDR (0x10000000)
21#define ARC_ICCM_START_ADDR (0x00000000)
22
23#define ARC_AUX_INT_VECTOR_BASE (0x25)
24
25#define ARC_ICAUSE (0x40a)
26#define ARC_IRQ_SELECT (0x40b)
27#define ARC_IRQ_ENABLE (0x40c)
28#define ARC_IRQ_TRIGGER (0x40d)
29#define ARC_IRQ_PULSE_CANCEL (0x415)
30#define ARC_IRQ_PRIORITY (0x206)
31
32static inline unsigned int ArcGetTimer0(void)
33{
34 unsigned volatile int count;
35
36 if (!IS_ENABLED(CONFIG_ARC)) {
37 return 0;
38 }
39
40 /*LR r1,[r2] ; Load contents of Aux. register ;pointed ; to by r2 into r1 */
41 __asm__ __volatile__("mov r1, %[addr]\n"
42 "lr %[reg], [r1]\n"
43 : [reg] "=r"(count)
44 : [addr] "I"(ARC_AUX_TIMER_0_COUNT)
45 : "r1");
46 return count;
47}
48
49static inline void ArcWriteAux(unsigned int addr, unsigned int value)
50{
51 if (!IS_ENABLED(CONFIG_ARC)) {
52 return;
53 }
54
55 /*SR r1,[r2] ; Store contents of r1 into Aux. register pointed to by r2 */
56 __asm__ __volatile__("mov r1, %[addr]\n"
57 "sr %[reg], [r1]\n"
58 :
59 : [reg] "r"(value), [addr] "r"(addr)
60 : "r1");
61}
62
63static inline unsigned int ArcReadAux(unsigned int addr)
64{
65 unsigned volatile int value;
66
67 if (!IS_ENABLED(CONFIG_ARC)) {
68 return 0;
69 }
70
71 /*LR r1,[r2] ; Load contents of Aux. register ;pointed ; to by r2 into r1 */
72 __asm__ __volatile__("mov r1, %[addr]\n"
73 "lr %[reg], [r1]\n"
74 : [reg] "=r"(value)
75 : [addr] "r"(addr)
76 : "r1");
77 return value;
78}
79
80static inline void _clri(void)
81{
82 if (!IS_ENABLED(CONFIG_ARC)) {
83 return;
84 }
85
86 /*clri; disables the interrupts clears any pending. */
87 __asm__ __volatile__("clri\n"
88 : /*no output */
89 : /*no input */
90 : "cc" /*no regs other than status32. */
91 );
92}
93
94static inline void _rtie(void)
95{
96 if (!IS_ENABLED(CONFIG_ARC)) {
97 return;
98 }
99
100 __asm__ __volatile__("rtie\n"
101 : /*no output */
102 : /*no input */
103 : "cc" /* status32 clobbered. */
104 );
105}
106
107static inline void _seti(unsigned int flags)
108{
109 if (!IS_ENABLED(CONFIG_ARC)) {
110 return;
111 }
112
113 /*seti r1; Sets the status register interrupt enable and level. */
114 __asm__ __volatile__("mov r1, %[reg]\n"
115 "seti r1\n"
116 : /*no output */
117 : [reg] "r"(flags)
118 : "r1", "cc" /*clobbered */
119 );
120}
121
122static inline void ArcDumpIsrVects(void)
123{
124 uint32_t volatile *p_base_isr_vect;
125
126 p_base_isr_vect = (uint32_t *)(ArcReadAux(ARC_AUX_INT_VECTOR_BASE));
127
128 for (uint32_t i = 0; i < 256; i++) {
130 WriteReg(RESET_UNIT_SCRATCH_REG_ADDR(7), p_base_isr_vect[i]);
131 }
132}
133
134static inline void ArcSetIsrVect(uint32_t volatile intvec, volatile uint32_t intvec_num)
135{
136 /*# intvbase_preset --- This sets the upper 22 bits of the interrupt vector base
137 * configuration
138 */
139 /* register, VECBASE_AC_BUILD. On reset, that register is loaded into the interrupt vector
140 * base
141 */
142 /* address register, INT_VECTOR_BASE. Because this value is the upper 22 bits, */
143 /* the vector base is aligned to a 1K-byte boundary. */
144 /* -intvbase_preset 0x20_0000 */
145 uint32_t volatile *p_reg;
146
147 p_reg = (uint32_t volatile *)(ArcReadAux(ARC_AUX_INT_VECTOR_BASE));
148
149 uint32_t volatile temp = intvec_num;
150
151 p_reg[temp] = intvec;
152 /* Reference only.
153 * __asm__ __volatile__ (
154 * "mov r1 %[intv]\n" // get the vec pointer in r1
155 * "mov r2,[r1]\n" // mov the pointer content into r2
156 *
157 * "mov r1,%[addr]\n" // mov INT_VECTOR_BASE addr into r1
158 * "lr r3,[r1]\n" // load from aux INT_VECTOR_BASE addr into r1
159 *
160 * "st r2,[r3,%[offset]]\n" // store the new value into the vector location.
161 * : // no output
162 * : [intv] "r" (intvec),
163 * [offset] "r" (intvec_num),
164 * [addr] "I" (ARC_AUX_INT_VECTOR_BASE)
165 * : "r1", "r2", "r3", "cc"
166 * );
167 */
168}
169
170static inline void ArcSleep(void)
171{
172 if (!IS_ENABLED(CONFIG_ARC)) {
173 return;
174 }
175
176 __asm__ __volatile__("sleep");
177}
178#endif
#define ARC_AUX_TIMER_0_COUNT
Definition arc.h:16
static void _seti(unsigned int flags)
Definition arc.h:107
static void _clri(void)
Definition arc.h:80
static void ArcSleep(void)
Definition arc.h:170
static unsigned int ArcGetTimer0(void)
Definition arc.h:32
static void ArcSetIsrVect(uint32_t volatile intvec, volatile uint32_t intvec_num)
Definition arc.h:134
#define ARC_AUX_INT_VECTOR_BASE
Definition arc.h:23
static void ArcWriteAux(unsigned int addr, unsigned int value)
Definition arc.h:49
static void _rtie(void)
Definition arc.h:94
static void ArcDumpIsrVects(void)
Definition arc.h:122
static unsigned int ArcReadAux(unsigned int addr)
Definition arc.h:63
#define IS_ENABLED(config_macro)
flags
static void WriteReg(uint32_t addr, uint32_t val)
Definition reg.h:19
#define RESET_UNIT_SCRATCH_REG_ADDR(n)
Definition status_reg.h:17
__UINT32_TYPE__ uint32_t