Skip to content

Commit 5a0fba3

Browse files
maass-hamburgcfriedt
authored andcommitted
soc: litex: support little CSR ordering
litex supports little CSR ordering, also support it in zephyr. historical the default is big ordering. Signed-off-by: Fin Maaß <[email protected]>
1 parent 0a21405 commit 5a0fba3

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

soc/litex/litex_vexriscv/Kconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,19 @@ config LITEX_CSR_DATA_WIDTH
1616
int "Select Control/Status register width"
1717
default 32
1818

19+
choice LITEX_CSR_ORDERING
20+
prompt "Select Control/Status register ordering"
21+
default LITEX_CSR_ORDERING_BIG
22+
23+
config LITEX_CSR_ORDERING_BIG
24+
bool "Big-endian ordering"
25+
help
26+
Use big-endian ordering for CSR accesses
27+
28+
config LITEX_CSR_ORDERING_LITTLE
29+
bool "Little-endian ordering"
30+
help
31+
Use little-endian ordering for CSR accesses
32+
endchoice
33+
1934
endif # SOC_LITEX_VEXRISCV

soc/litex/litex_vexriscv/soc.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@ static inline uint8_t litex_read8(mem_addr_t addr)
2424
static inline uint16_t litex_read16(mem_addr_t addr)
2525
{
2626
#if CONFIG_LITEX_CSR_DATA_WIDTH == 8
27+
#ifdef CONFIG_LITEX_CSR_ORDERING_BIG
2728
return (sys_read8(addr) << 8)
2829
| sys_read8(addr + 0x4);
30+
#else
31+
return sys_read8(addr)
32+
| (sys_read8(addr + 0x4) << 8);
33+
#endif
2934
#else /* CONFIG_LITEX_CSR_DATA_WIDTH == 8 */
3035
return sys_read16(addr);
3136
#endif
@@ -34,10 +39,17 @@ static inline uint16_t litex_read16(mem_addr_t addr)
3439
static inline uint32_t litex_read32(mem_addr_t addr)
3540
{
3641
#if CONFIG_LITEX_CSR_DATA_WIDTH == 8
42+
#ifdef CONFIG_LITEX_CSR_ORDERING_BIG
3743
return (sys_read8(addr) << 24)
3844
| (sys_read8(addr + 0x4) << 16)
3945
| (sys_read8(addr + 0x8) << 8)
4046
| sys_read8(addr + 0xc);
47+
#else
48+
return sys_read8(addr)
49+
| (sys_read8(addr + 0x4) << 8)
50+
| (sys_read8(addr + 0x8) << 16)
51+
| (sys_read8(addr + 0xc) << 24);
52+
#endif
4153
#else /* CONFIG_LITEX_CSR_DATA_WIDTH == 8 */
4254
return sys_read32(addr);
4355
#endif
@@ -46,6 +58,7 @@ static inline uint32_t litex_read32(mem_addr_t addr)
4658
static inline uint64_t litex_read64(mem_addr_t addr)
4759
{
4860
#if CONFIG_LITEX_CSR_DATA_WIDTH == 8
61+
#ifdef CONFIG_LITEX_CSR_ORDERING_BIG
4962
return (((uint64_t)sys_read8(addr)) << 56)
5063
| ((uint64_t)sys_read8(addr + 0x4) << 48)
5164
| ((uint64_t)sys_read8(addr + 0x8) << 40)
@@ -54,8 +67,22 @@ static inline uint64_t litex_read64(mem_addr_t addr)
5467
| ((uint64_t)sys_read8(addr + 0x14) << 16)
5568
| ((uint64_t)sys_read8(addr + 0x18) << 8)
5669
| (uint64_t)sys_read8(addr + 0x1c);
70+
#else
71+
return (uint64_t)sys_read8(addr)
72+
| ((uint64_t)sys_read8(addr + 0x4) << 8)
73+
| ((uint64_t)sys_read8(addr + 0x8) << 16)
74+
| ((uint64_t)sys_read8(addr + 0xc) << 24)
75+
| ((uint64_t)sys_read8(addr + 0x10) << 32)
76+
| ((uint64_t)sys_read8(addr + 0x14) << 40)
77+
| ((uint64_t)sys_read8(addr + 0x18) << 48)
78+
| ((uint64_t)sys_read8(addr + 0x1c) << 56);
79+
#endif
5780
#else /* CONFIG_LITEX_CSR_DATA_WIDTH == 8 */
81+
#ifdef CONFIG_LITEX_CSR_ORDERING_BIG
5882
return ((uint64_t)sys_read32(addr) << 32) | (uint64_t)sys_read32(addr + 0x4);
83+
#else
84+
return sys_read64(addr);
85+
#endif
5986
#endif
6087
}
6188

@@ -67,8 +94,13 @@ static inline void litex_write8(uint8_t value, mem_addr_t addr)
6794
static inline void litex_write16(uint16_t value, mem_addr_t addr)
6895
{
6996
#if CONFIG_LITEX_CSR_DATA_WIDTH == 8
97+
#ifdef CONFIG_LITEX_CSR_ORDERING_BIG
7098
sys_write8(value >> 8, addr);
7199
sys_write8(value, addr + 0x4);
100+
#else
101+
sys_write8(value, addr);
102+
sys_write8(value >> 8, addr + 0x4);
103+
#endif
72104
#else /* CONFIG_LITEX_CSR_DATA_WIDTH == 8 */
73105
sys_write16(value, addr);
74106
#endif
@@ -77,10 +109,17 @@ static inline void litex_write16(uint16_t value, mem_addr_t addr)
77109
static inline void litex_write32(uint32_t value, mem_addr_t addr)
78110
{
79111
#if CONFIG_LITEX_CSR_DATA_WIDTH == 8
112+
#ifdef CONFIG_LITEX_CSR_ORDERING_BIG
80113
sys_write8(value >> 24, addr);
81114
sys_write8(value >> 16, addr + 0x4);
82115
sys_write8(value >> 8, addr + 0x8);
83116
sys_write8(value, addr + 0xC);
117+
#else
118+
sys_write8(value, addr);
119+
sys_write8(value >> 8, addr + 0x4);
120+
sys_write8(value >> 16, addr + 0x8);
121+
sys_write8(value >> 24, addr + 0xC);
122+
#endif
84123
#else /* CONFIG_LITEX_CSR_DATA_WIDTH == 8 */
85124
sys_write32(value, addr);
86125
#endif
@@ -89,6 +128,7 @@ static inline void litex_write32(uint32_t value, mem_addr_t addr)
89128
static inline void litex_write64(uint64_t value, mem_addr_t addr)
90129
{
91130
#if CONFIG_LITEX_CSR_DATA_WIDTH == 8
131+
#ifdef CONFIG_LITEX_CSR_ORDERING_BIG
92132
sys_write8(value >> 56, addr);
93133
sys_write8(value >> 48, addr + 0x4);
94134
sys_write8(value >> 40, addr + 0x8);
@@ -97,9 +137,23 @@ static inline void litex_write64(uint64_t value, mem_addr_t addr)
97137
sys_write8(value >> 16, addr + 0x14);
98138
sys_write8(value >> 8, addr + 0x18);
99139
sys_write8(value, addr + 0x1C);
140+
#else
141+
sys_write8(value, addr);
142+
sys_write8(value >> 8, addr + 0x4);
143+
sys_write8(value >> 16, addr + 0x8);
144+
sys_write8(value >> 24, addr + 0xC);
145+
sys_write8(value >> 32, addr + 0x10);
146+
sys_write8(value >> 40, addr + 0x14);
147+
sys_write8(value >> 48, addr + 0x18);
148+
sys_write8(value >> 56, addr + 0x1C);
149+
#endif
100150
#else /* CONFIG_LITEX_CSR_DATA_WIDTH == 8 */
151+
#ifdef CONFIG_LITEX_CSR_ORDERING_BIG
101152
sys_write32(value >> 32, addr);
102153
sys_write32(value, addr + 0x4);
154+
#else
155+
sys_write64(value, addr);
156+
#endif
103157
#endif /* CONFIG_LITEX_CSR_DATA_WIDTH == 8 */
104158
}
105159

0 commit comments

Comments
 (0)