Skip to content

Commit 9e36fa4

Browse files
xen0nchenhuacai
authored andcommitted
LoongArch: Clean up the architectural interrupt definitions
While interrupts are assigned ECodes `64 + interrupt number`, all existing use sites of interrupt numbers want the 64 subtracted. Re-arrange the definitions so that the actual interrupt number is used everywhere, and make EXCCODE_INT_END inclusive as it is more intuitive that way. While at it, according to the asm/loongarch.h definitions, the total number of architectural interrupts should be 14, but various other places indicate otherwise (13 or 15). Those places have been adjusted to 14 as well for consistency. Signed-off-by: WANG Xuerui <git@xen0n.name> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent 3b5a567 commit 9e36fa4

5 files changed

Lines changed: 29 additions & 26 deletions

File tree

arch/loongarch/include/asm/loongarch.h

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ static __always_inline void iocsr_write64(u64 val, u32 reg)
311311
#define CSR_ECFG_VS_WIDTH 3
312312
#define CSR_ECFG_VS (_ULCAST_(0x7) << CSR_ECFG_VS_SHIFT)
313313
#define CSR_ECFG_IM_SHIFT 0
314-
#define CSR_ECFG_IM_WIDTH 13
315-
#define CSR_ECFG_IM (_ULCAST_(0x1fff) << CSR_ECFG_IM_SHIFT)
314+
#define CSR_ECFG_IM_WIDTH 14
315+
#define CSR_ECFG_IM (_ULCAST_(0x3fff) << CSR_ECFG_IM_SHIFT)
316316

317317
#define LOONGARCH_CSR_ESTAT 0x5 /* Exception status */
318318
#define CSR_ESTAT_ESUBCODE_SHIFT 22
@@ -322,8 +322,8 @@ static __always_inline void iocsr_write64(u64 val, u32 reg)
322322
#define CSR_ESTAT_EXC_WIDTH 6
323323
#define CSR_ESTAT_EXC (_ULCAST_(0x3f) << CSR_ESTAT_EXC_SHIFT)
324324
#define CSR_ESTAT_IS_SHIFT 0
325-
#define CSR_ESTAT_IS_WIDTH 15
326-
#define CSR_ESTAT_IS (_ULCAST_(0x7fff) << CSR_ESTAT_IS_SHIFT)
325+
#define CSR_ESTAT_IS_WIDTH 14
326+
#define CSR_ESTAT_IS (_ULCAST_(0x3fff) << CSR_ESTAT_IS_SHIFT)
327327

328328
#define LOONGARCH_CSR_ERA 0x6 /* ERA */
329329

@@ -1090,7 +1090,7 @@ static __always_inline void iocsr_write64(u64 val, u32 reg)
10901090
#define ECFGF_IPI (_ULCAST_(1) << ECFGB_IPI)
10911091
#define ECFGF(hwirq) (_ULCAST_(1) << hwirq)
10921092

1093-
#define ESTATF_IP 0x00001fff
1093+
#define ESTATF_IP 0x00003fff
10941094

10951095
#define LOONGARCH_IOCSR_FEATURES 0x8
10961096
#define IOCSRF_TEMP BIT_ULL(0)
@@ -1418,23 +1418,26 @@ __BUILD_CSR_OP(tlbidx)
14181418
#define EXCSUBCODE_GCHC 1 /* Hardware caused */
14191419
#define EXCCODE_SE 25 /* Security */
14201420

1421-
#define EXCCODE_INT_START 64
1422-
#define EXCCODE_SIP0 64
1423-
#define EXCCODE_SIP1 65
1424-
#define EXCCODE_IP0 66
1425-
#define EXCCODE_IP1 67
1426-
#define EXCCODE_IP2 68
1427-
#define EXCCODE_IP3 69
1428-
#define EXCCODE_IP4 70
1429-
#define EXCCODE_IP5 71
1430-
#define EXCCODE_IP6 72
1431-
#define EXCCODE_IP7 73
1432-
#define EXCCODE_PMC 74 /* Performance Counter */
1433-
#define EXCCODE_TIMER 75
1434-
#define EXCCODE_IPI 76
1435-
#define EXCCODE_NMI 77
1436-
#define EXCCODE_INT_END 78
1437-
#define EXCCODE_INT_NUM (EXCCODE_INT_END - EXCCODE_INT_START)
1421+
/* Interrupt numbers */
1422+
#define INT_SWI0 0 /* Software Interrupts */
1423+
#define INT_SWI1 1
1424+
#define INT_HWI0 2 /* Hardware Interrupts */
1425+
#define INT_HWI1 3
1426+
#define INT_HWI2 4
1427+
#define INT_HWI3 5
1428+
#define INT_HWI4 6
1429+
#define INT_HWI5 7
1430+
#define INT_HWI6 8
1431+
#define INT_HWI7 9
1432+
#define INT_PCOV 10 /* Performance Counter Overflow */
1433+
#define INT_TI 11 /* Timer */
1434+
#define INT_IPI 12
1435+
#define INT_NMI 13
1436+
1437+
/* ExcCodes corresponding to interrupts */
1438+
#define EXCCODE_INT_NUM (INT_NMI + 1)
1439+
#define EXCCODE_INT_START 64
1440+
#define EXCCODE_INT_END (EXCCODE_INT_START + EXCCODE_INT_NUM - 1)
14381441

14391442
/* FPU register names */
14401443
#define LOONGARCH_FCSR0 $r0

arch/loongarch/kernel/irq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static int __init get_ipi_irq(void)
9292
struct irq_domain *d = irq_find_matching_fwnode(cpuintc_handle, DOMAIN_BUS_ANY);
9393

9494
if (d)
95-
return irq_create_mapping(d, EXCCODE_IPI - EXCCODE_INT_START);
95+
return irq_create_mapping(d, INT_IPI);
9696

9797
return -EINVAL;
9898
}

arch/loongarch/kernel/perf_event.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ static int get_pmc_irq(void)
461461
struct irq_domain *d = irq_find_matching_fwnode(cpuintc_handle, DOMAIN_BUS_ANY);
462462

463463
if (d)
464-
return irq_create_mapping(d, EXCCODE_PMC - EXCCODE_INT_START);
464+
return irq_create_mapping(d, INT_PCOV);
465465

466466
return -EINVAL;
467467
}

arch/loongarch/kernel/time.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static int get_timer_irq(void)
133133
struct irq_domain *d = irq_find_matching_fwnode(cpuintc_handle, DOMAIN_BUS_ANY);
134134

135135
if (d)
136-
return irq_create_mapping(d, EXCCODE_TIMER - EXCCODE_INT_START);
136+
return irq_create_mapping(d, INT_TI);
137137

138138
return -EINVAL;
139139
}

arch/loongarch/kernel/traps.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ void __init trap_init(void)
792792
long i;
793793

794794
/* Set interrupt vector handler */
795-
for (i = EXCCODE_INT_START; i < EXCCODE_INT_END; i++)
795+
for (i = EXCCODE_INT_START; i <= EXCCODE_INT_END; i++)
796796
set_handler(i * VECSIZE, handle_vint, VECSIZE);
797797

798798
set_handler(EXCCODE_ADE * VECSIZE, handle_ade, VECSIZE);

0 commit comments

Comments
 (0)