Skip to content

Commit cbedb6b

Browse files
authored
[libcpu/risc-v/c906] add ioremap && default param (RT-Thread#7345)
1 parent a09a2ea commit cbedb6b

File tree

5 files changed

+35
-14
lines changed

5 files changed

+35
-14
lines changed

libcpu/risc-v/t-head/c906/io.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ static inline uint32_t readl(const volatile void *addr)
4040
static inline void write_reg(
4141
uint32_t val, volatile void *addr, unsigned offset)
4242
{
43-
writel(val, addr + offset);
43+
writel(val, (void *)((rt_size_t)addr + offset));
4444
}
4545

4646
static inline uint32_t read_reg(
4747
const volatile void *addr, unsigned offset)
4848
{
49-
return readl(addr + offset);
49+
return readl((void *)((rt_size_t)addr + offset));
5050
}
5151

5252
#endif // ARCH_IO_H

libcpu/risc-v/t-head/c906/plic.c

+23-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/*
2-
* Copyright (c) 2006-2021, RT-Thread Development Team
2+
* Copyright (c) 2006-2023, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
66
* Change Logs:
77
* Date Author Notes
88
* 2021-10-19 JasonHu first version
99
* 2021-11-12 JasonHu fix bug that not intr on f133
10+
* 2023-04-22 flyingcys add plic register ioremap
1011
*/
1112

1213
#include <rtthread.h>
@@ -30,13 +31,23 @@ struct plic_handler
3031

3132
rt_inline void plic_toggle(struct plic_handler *handler, int hwirq, int enable);
3233
struct plic_handler c906_plic_handlers[C906_NR_CPUS];
34+
static void *c906_irq_priority[INTERRUPTS_MAX] = {RT_NULL};
3335

3436
rt_inline void plic_irq_toggle(int hwirq, int enable)
3537
{
3638
int cpu = 0;
39+
void *priority_addr;
3740

3841
/* set priority of interrupt, interrupt 0 is zero. */
39-
writel(enable, c906_plic_regs + PRIORITY_BASE + hwirq * PRIORITY_PER_ID);
42+
priority_addr = (void *)((rt_size_t)c906_plic_regs + PRIORITY_BASE + hwirq * PRIORITY_PER_ID);
43+
#ifdef RT_USING_SMART
44+
if (c906_irq_priority[hwirq] == RT_NULL)
45+
{
46+
c906_irq_priority[hwirq] = rt_ioremap(priority_addr, 0x1000);
47+
}
48+
priority_addr = c906_irq_priority[hwirq];
49+
#endif
50+
writel(enable, priority_addr);
4051
struct plic_handler *handler = &c906_plic_handlers[cpu];
4152

4253
if (handler->present)
@@ -76,7 +87,7 @@ void plic_complete(int irqno)
7687
int cpu = 0;
7788
struct plic_handler *handler = &c906_plic_handlers[cpu];
7889

79-
writel(irqno, handler->hart_base + CONTEXT_CLAIM);
90+
writel(irqno, (void *)((rt_size_t)handler->hart_base + CONTEXT_CLAIM));
8091
}
8192

8293
void plic_disable_irq(int irqno)
@@ -101,7 +112,7 @@ void plic_handle_irq(void)
101112
unsigned int irq;
102113

103114
struct plic_handler *handler = &c906_plic_handlers[cpu];
104-
void *claim = handler->hart_base + CONTEXT_CLAIM;
115+
void *claim = (void *)((rt_size_t)handler->hart_base + CONTEXT_CLAIM);
105116

106117
if (c906_plic_regs == RT_NULL || !handler->present)
107118
{
@@ -128,7 +139,7 @@ void plic_handle_irq(void)
128139

129140
rt_inline void plic_toggle(struct plic_handler *handler, int hwirq, int enable)
130141
{
131-
uint32_t *reg = handler->enable_base + (hwirq / 32) * sizeof(uint32_t);
142+
uint32_t *reg = (uint32_t *)((rt_size_t)handler->enable_base + (hwirq / 32) * sizeof(uint32_t));
132143
uint32_t hwirq_mask = 1 << (hwirq % 32);
133144

134145
if (enable)
@@ -188,11 +199,15 @@ void plic_init(void)
188199
}
189200

190201
handler->present = RT_TRUE;
191-
handler->hart_base = c906_plic_regs + CONTEXT_BASE + i * CONTEXT_PER_HART;
192-
handler->enable_base = c906_plic_regs + ENABLE_BASE + i * ENABLE_PER_HART;
202+
handler->hart_base = (void *)((rt_size_t)c906_plic_regs + CONTEXT_BASE + i * CONTEXT_PER_HART);
203+
handler->enable_base = (void *)((rt_size_t)c906_plic_regs + ENABLE_BASE + i * ENABLE_PER_HART);
204+
#ifdef RT_USING_SMART
205+
handler->hart_base = rt_ioremap(handler->hart_base, 0x1000);
206+
handler->enable_base = rt_ioremap(handler->enable_base, 0x1000);
207+
#endif
193208
done:
194209
/* priority must be > threshold to trigger an interrupt */
195-
writel(threshold, handler->hart_base + CONTEXT_THRESHOLD);
210+
writel(threshold, (void *)((rt_size_t)handler->hart_base + CONTEXT_THRESHOLD));
196211
for (hwirq = 1; hwirq <= nr_irqs; hwirq++)
197212
{
198213
plic_toggle(handler, hwirq, 0);

libcpu/risc-v/t-head/c906/plic.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
/*
2-
* Copyright (c) 2006-2021, RT-Thread Development Team
2+
* Copyright (c) 2006-2023, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
66
* Change Logs:
77
* Date Author Notes
88
* 2021-10-19 JasonHu first version
9+
* 2023-04-22 flyingcys add C906_PLIC_PHY_ADDR macro judge
910
*/
1011

1112
#ifndef __RISCV64_PLIC_H__
1213
#define __RISCV64_PLIC_H__
1314

1415
#include <rt_interrupt.h>
1516

17+
#ifndef C906_PLIC_PHY_ADDR
1618
#define C906_PLIC_PHY_ADDR (0x10000000)
19+
#endif
1720
#define C906_PLIC_NR_EXT_IRQS (IRQ_MAX_NR)
1821
#define C906_NR_CPUS (NR_CPUS)
1922

libcpu/risc-v/t-head/c906/rt_interrupt.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2021, RT-Thread Development Team
2+
* Copyright (c) 2006-2023, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -16,7 +16,9 @@
1616
#define NR_CPUS 1
1717

1818
#define IRQ_OFFSET 16
19+
#ifndef IRQ_MAX_NR
1920
#define IRQ_MAX_NR 207
21+
#endif
2022
#define INTERRUPTS_MAX (IRQ_OFFSET + IRQ_MAX_NR)
2123

2224
enum {

libcpu/risc-v/t-head/c906/tick.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2021, RT-Thread Development Team
2+
* Copyright (c) 2006-2023, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -12,8 +12,9 @@
1212
#define TICK_H__
1313

1414
/* timer clock is 24 MHZ */
15+
#ifndef TIMER_CLK_FREQ
1516
#define TIMER_CLK_FREQ (24000000)
16-
17+
#endif
1718
int tick_isr(void);
1819
int rt_hw_tick_init(void);
1920

0 commit comments

Comments
 (0)