Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arch: k210: Applied changes doned for fe310 recently. #65

Merged
merged 1 commit into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion arch/risc-v/include/k210/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@

/* Machine Interrupt Enable bit in mstatus register */

#define MSTATUS_MIE (0x1 << 3)
#define MSTATUS_MIE (0x1 << 3) /* Machine Interrupt Enable */
#define MSTATUS_MPIE (0x1 << 7) /* Machine Previous Interrupt Enable */
#define MSTATUS_MPPM (0x3 << 11) /* Machine Previous Privilege (m-mode) */

/* In mie (machine interrupt enable) register */

Expand Down
2 changes: 1 addition & 1 deletion arch/risc-v/src/k210/k210_clockconfig.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
* arch/arm/src/k210/k210_clockconfig.c
* arch/risc-v/src/k210/k210_clockconfig.c
*
* Copyright (C) 2019 Masayuki Ishikawa. All rights reserved.
* Author: Masayuki Ishikawa <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion arch/risc-v/src/k210/k210_clockconfig.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
* arch/arm/src/k210/k210_clockconfig.h
* arch/risc-v/src/k210/k210_clockconfig.h
*
* Copyright (C) 2019 Masayuki Ishikawa. All rights reserved.
* Author: Masayuki Ishikawa <[email protected]>
Expand Down
11 changes: 7 additions & 4 deletions arch/risc-v/src/k210/k210_irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ void up_irqinitialize(void)
/* Attach the ecall interrupt handler */

irq_attach(K210_IRQ_ECALLM, up_swint, NULL);
up_enable_irq(K210_IRQ_ECALLM);

#ifndef CONFIG_SUPPRESS_INTERRUPTS

Expand Down Expand Up @@ -191,13 +190,17 @@ void up_enable_irq(int irq)
* Name: up_get_newintctx
*
* Description:
* Return a value for EPIC. But K210 doesn't use EPIC for event control.
* Return initial mstatus when a task is created.
*
****************************************************************************/

uint32_t up_get_newintctx(void)
{
return 0;
/* Set machine previous privilege mode to machine mode.
* Also set machine previous interrupt enable
*/

return (MSTATUS_MPPM | MSTATUS_MPIE);
}

/****************************************************************************
Expand Down Expand Up @@ -240,7 +243,7 @@ irqstate_t up_irq_save(void)

void up_irq_restore(irqstate_t flags)
{
/* Machine mode - mstatus */
/* Write flags to mstatus */

asm volatile("csrw mstatus, %0" : /* no output */ : "r" (flags));
}
Expand Down
31 changes: 19 additions & 12 deletions arch/risc-v/src/k210/k210_irq_dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ void *k210_dispatch_irq(uint64_t vector, uint64_t *regs)
uint32_t irq = (vector >> (27 + 32)) | (vector & 0xf);
uint64_t *mepc = regs;

/* Firstly, check if the irq is machine external interrupt */

if (K210_IRQ_MEXT == irq)
{
/* Read & write K210_PLIC_CLAIM to clear pending */

uint32_t val = getreg32(K210_PLIC_CLAIM);
putreg32(val, K210_PLIC_CLAIM);

/* Add the value to nuttx irq which is offset to the mext */

irq += val;
}
Expand All @@ -85,22 +86,32 @@ void *k210_dispatch_irq(uint64_t vector, uint64_t *regs)
*mepc += 4;
}

/* Acknowledge the interrupt */

up_ack_irq(irq);

#ifdef CONFIG_SUPPRESS_INTERRUPTS
PANIC();
#else
/* Nested interrupts are not supported */

DEBUGASSERT(g_current_regs == NULL);

/* Current regs non-zero indicates that we are processing an interrupt;
* CURRENT_REGS is also used to manage interrupt level context switches.
* g_current_regs is also used to manage interrupt level context switches.
*
* Nested interrupts are not supported
*/

DEBUGASSERT(g_current_regs == NULL);
g_current_regs = regs;

/* Deliver the IRQ */

irq_dispatch(irq, regs);

if (K210_IRQ_MEXT <= irq)
{
/* Then write PLIC_CLAIM to clear pending in PLIC */

putreg32(irq - K210_IRQ_MEXT, K210_PLIC_CLAIM);
}
#endif

/* If a context switch occurred while processing the interrupt then
Expand All @@ -112,10 +123,6 @@ void *k210_dispatch_irq(uint64_t vector, uint64_t *regs)
regs = (uint64_t *)g_current_regs;
g_current_regs = NULL;

/* Set machine previous privilege mode to machine mode */

*(regs + REG_INT_CTX_NDX) |= 0x3 << 11;

return regs;
}

2 changes: 1 addition & 1 deletion arch/risc-v/src/k210/k210_start.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
* arch/risc-v/src/k210/k210_init.c
* arch/risc-v/src/k210/k210_start.c
*
* Copyright (C) 2019 Masayuki Ishikawa. All rights reserved.
* Author: Masayuki Ishikawa <[email protected]>
Expand Down