CVS commit: src/sys/arch/riscv/dev
Module Name:src Committed By: skrll Date: Sun Mar 24 08:34:20 UTC 2024 Modified Files: src/sys/arch/riscv/dev: plic.c plic_fdt.c Log Message: Pretty print plic attachment To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/arch/riscv/dev/plic.c cvs rdiff -u -r1.5 -r1.6 src/sys/arch/riscv/dev/plic_fdt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/arch/riscv/dev
Module Name:src Committed By: skrll Date: Sun Mar 24 08:34:20 UTC 2024 Modified Files: src/sys/arch/riscv/dev: plic.c plic_fdt.c Log Message: Pretty print plic attachment To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/arch/riscv/dev/plic.c cvs rdiff -u -r1.5 -r1.6 src/sys/arch/riscv/dev/plic_fdt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/riscv/dev/plic.c diff -u src/sys/arch/riscv/dev/plic.c:1.4 src/sys/arch/riscv/dev/plic.c:1.5 --- src/sys/arch/riscv/dev/plic.c:1.4 Mon Dec 25 13:01:59 2023 +++ src/sys/arch/riscv/dev/plic.c Sun Mar 24 08:34:20 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: plic.c,v 1.4 2023/12/25 13:01:59 skrll Exp $ */ +/* $NetBSD: plic.c,v 1.5 2024/03/24 08:34:20 skrll Exp $ */ /*- * Copyright (c) 2022 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include "opt_multiprocessor.h" #include -__KERNEL_RCSID(0, "$NetBSD: plic.c,v 1.4 2023/12/25 13:01:59 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: plic.c,v 1.5 2024/03/24 08:34:20 skrll Exp $"); #include @@ -204,7 +204,7 @@ plic_attach_common(struct plic_softc *sc } aprint_naive("\n"); - aprint_normal("RISC-V PLIC (%u IRQs)\n", sc->sc_ndev); + aprint_normal(": RISC-V PLIC (%u IRQs)\n", sc->sc_ndev); plic_sc = sc; Index: src/sys/arch/riscv/dev/plic_fdt.c diff -u src/sys/arch/riscv/dev/plic_fdt.c:1.5 src/sys/arch/riscv/dev/plic_fdt.c:1.6 --- src/sys/arch/riscv/dev/plic_fdt.c:1.5 Fri Feb 9 18:39:53 2024 +++ src/sys/arch/riscv/dev/plic_fdt.c Sun Mar 24 08:34:20 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: plic_fdt.c,v 1.5 2024/02/09 18:39:53 andvar Exp $ */ +/* $NetBSD: plic_fdt.c,v 1.6 2024/03/24 08:34:20 skrll Exp $ */ /*- * Copyright (c) 2022 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: plic_fdt.c,v 1.5 2024/02/09 18:39:53 andvar Exp $"); +__KERNEL_RCSID(0, "$NetBSD: plic_fdt.c,v 1.6 2024/03/24 08:34:20 skrll Exp $"); #include @@ -240,7 +240,7 @@ plic_fdt_attach(device_t parent, device_ context++; } - aprint_verbose_dev(self, ""); + aprint_verbose_dev(self, "attaching"); error = plic_attach_common(sc, addr, size); if (error != 0) { return;
CVS commit: src/sys/arch/riscv/dev
Module Name:src Committed By: skrll Date: Mon Dec 25 13:01:59 UTC 2023 Modified Files: src/sys/arch/riscv/dev: plic.c Log Message: Deliver plic interrupts to the cpu^Whart establishing the interrupt handler. At least this is known to be a valid hart, but it might share some interrupts around too. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/sys/arch/riscv/dev/plic.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/riscv/dev/plic.c diff -u src/sys/arch/riscv/dev/plic.c:1.3 src/sys/arch/riscv/dev/plic.c:1.4 --- src/sys/arch/riscv/dev/plic.c:1.3 Sat Dec 16 18:02:02 2023 +++ src/sys/arch/riscv/dev/plic.c Mon Dec 25 13:01:59 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: plic.c,v 1.3 2023/12/16 18:02:02 skrll Exp $ */ +/* $NetBSD: plic.c,v 1.4 2023/12/25 13:01:59 skrll Exp $ */ /*- * Copyright (c) 2022 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include "opt_multiprocessor.h" #include -__KERNEL_RCSID(0, "$NetBSD: plic.c,v 1.3 2023/12/16 18:02:02 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: plic.c,v 1.4 2023/12/25 13:01:59 skrll Exp $"); #include @@ -73,10 +73,10 @@ plic_intr_establish_xname(u_int irq, int struct plic_intrhand *ih; /* - * Choose hart 0. + * Choose calling hart. * XXX need a better hart selection method */ - u_int hartid = 0; + u_int hartid = curcpu()->ci_cpuid; evcnt_attach_dynamic(>sc_intrevs[irq], EVCNT_TYPE_INTR, NULL, "plic", xname);
CVS commit: src/sys/arch/riscv/dev
Module Name:src Committed By: skrll Date: Mon Dec 25 13:01:59 UTC 2023 Modified Files: src/sys/arch/riscv/dev: plic.c Log Message: Deliver plic interrupts to the cpu^Whart establishing the interrupt handler. At least this is known to be a valid hart, but it might share some interrupts around too. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/sys/arch/riscv/dev/plic.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/arch/riscv/dev
Module Name:src Committed By: skrll Date: Sat Dec 16 18:02:02 UTC 2023 Modified Files: src/sys/arch/riscv/dev: plic.c Log Message: Free memory on failure To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sys/arch/riscv/dev/plic.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/riscv/dev/plic.c diff -u src/sys/arch/riscv/dev/plic.c:1.2 src/sys/arch/riscv/dev/plic.c:1.3 --- src/sys/arch/riscv/dev/plic.c:1.2 Sat Sep 2 09:58:15 2023 +++ src/sys/arch/riscv/dev/plic.c Sat Dec 16 18:02:02 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: plic.c,v 1.2 2023/09/02 09:58:15 skrll Exp $ */ +/* $NetBSD: plic.c,v 1.3 2023/12/16 18:02:02 skrll Exp $ */ /*- * Copyright (c) 2022 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include "opt_multiprocessor.h" #include -__KERNEL_RCSID(0, "$NetBSD: plic.c,v 1.2 2023/09/02 09:58:15 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: plic.c,v 1.3 2023/12/16 18:02:02 skrll Exp $"); #include @@ -190,17 +190,16 @@ plic_set_threshold(struct plic_softc *sc int plic_attach_common(struct plic_softc *sc, bus_addr_t addr, bus_size_t size) { - struct cpu_info *ci; - CPU_INFO_ITERATOR cii; - u_int irq; + const size_t szintrs = sizeof(*sc->sc_intr) * sc->sc_ndev; + const size_t szintrevs = sizeof(*sc->sc_intrevs) * sc->sc_ndev; - sc->sc_intr = kmem_zalloc(sizeof(*sc->sc_intr) * sc->sc_ndev, - KM_SLEEP); - sc->sc_intrevs = kmem_zalloc(sizeof(*sc->sc_intrevs) * sc->sc_ndev, - KM_SLEEP); + sc->sc_intr = kmem_zalloc(szintrs, KM_SLEEP); + sc->sc_intrevs = kmem_zalloc(szintrevs, KM_SLEEP); if (bus_space_map(sc->sc_bst, addr, size, 0, >sc_bsh) != 0) { - aprint_error("couldn't map registers\n"); + aprint_error_dev(sc->sc_dev, "couldn't map registers\n"); + kmem_free(sc->sc_intr, szintrs); + kmem_free(sc->sc_intrevs, szintrevs); return -1; } @@ -210,10 +209,13 @@ plic_attach_common(struct plic_softc *sc plic_sc = sc; /* Start with all interrupts disabled. */ + u_int irq; for (irq = PLIC_FIRST_IRQ; irq < sc->sc_ndev; irq++) { plic_set_priority(sc, irq, 0); } + struct cpu_info *ci; + CPU_INFO_ITERATOR cii; /* Set priority thresholds for all interrupts to 0 (not masked). */ for (CPU_INFO_FOREACH(cii, ci)) { plic_set_threshold(sc, ci->ci_cpuid, 0);
CVS commit: src/sys/arch/riscv/dev
Module Name:src Committed By: skrll Date: Sat Dec 16 18:02:02 UTC 2023 Modified Files: src/sys/arch/riscv/dev: plic.c Log Message: Free memory on failure To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sys/arch/riscv/dev/plic.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/arch/riscv/dev
Module Name:src Committed By: skrll Date: Sat Sep 2 09:58:15 UTC 2023 Modified Files: src/sys/arch/riscv/dev: plic.c plic_fdt.c plicvar.h Log Message: Be clear about hart vs cpu. NFCI. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/arch/riscv/dev/plic.c \ src/sys/arch/riscv/dev/plicvar.h cvs rdiff -u -r1.2 -r1.3 src/sys/arch/riscv/dev/plic_fdt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/riscv/dev/plic.c diff -u src/sys/arch/riscv/dev/plic.c:1.1 src/sys/arch/riscv/dev/plic.c:1.2 --- src/sys/arch/riscv/dev/plic.c:1.1 Sun May 7 12:41:48 2023 +++ src/sys/arch/riscv/dev/plic.c Sat Sep 2 09:58:15 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: plic.c,v 1.1 2023/05/07 12:41:48 skrll Exp $ */ +/* $NetBSD: plic.c,v 1.2 2023/09/02 09:58:15 skrll Exp $ */ /*- * Copyright (c) 2022 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include "opt_multiprocessor.h" #include -__KERNEL_RCSID(0, "$NetBSD: plic.c,v 1.1 2023/05/07 12:41:48 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: plic.c,v 1.2 2023/09/02 09:58:15 skrll Exp $"); #include @@ -46,15 +46,15 @@ __KERNEL_RCSID(0, "$NetBSD: plic.c,v 1.1 #define PLIC_PRIORITY(irq) (PLIC_PRIORITY_BASE + (irq) * 4) -#define PLIC_ENABLE(sc, c, irq) (PLIC_ENABLE_BASE + \ - sc->sc_context[(c)] * PLIC_ENABLE_SIZE + \ +#define PLIC_ENABLE(sc, h, irq) (PLIC_ENABLE_BASE + \ + sc->sc_context[(h)] * PLIC_ENABLE_SIZE + \ ((irq / 32) * sizeof(uint32_t))) -#define PLIC_CONTEXT(sc, c) (PLIC_CONTEXT_BASE + \ - sc->sc_context[(c)] * PLIC_CONTEXT_SIZE) -#define PLIC_CLAIM(sc, c) (PLIC_CONTEXT(sc, c) + PLIC_CLAIM_COMPLETE_OFFS) -#define PLIC_COMPLETE(sc, c) PLIC_CLAIM(sc, c) /* same address */ -#define PLIC_THRESHOLD(sc, c) (PLIC_CONTEXT(sc, c) + PLIC_THRESHOLD_OFFS) +#define PLIC_CONTEXT(sc, h) (PLIC_CONTEXT_BASE + \ + sc->sc_context[(h)] * PLIC_CONTEXT_SIZE) +#define PLIC_CLAIM(sc, h) (PLIC_CONTEXT(sc, h) + PLIC_CLAIM_COMPLETE_OFFS) +#define PLIC_COMPLETE(sc, h) PLIC_CLAIM(sc, h) /* same address */ +#define PLIC_THRESHOLD(sc, h) (PLIC_CONTEXT(sc, h) + PLIC_THRESHOLD_OFFS) #define PLIC_READ(sc, reg) \ bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, (reg)) @@ -72,9 +72,11 @@ plic_intr_establish_xname(u_int irq, int struct plic_softc * const sc = plic_sc; struct plic_intrhand *ih; - /* XXX need a better CPU selection method */ -// u_int cidx = cpu_index(curcpu()); - u_int cidx = 0; + /* + * Choose hart 0. + * XXX need a better hart selection method + */ + u_int hartid = 0; evcnt_attach_dynamic(>sc_intrevs[irq], EVCNT_TYPE_INTR, NULL, "plic", xname); @@ -90,10 +92,10 @@ plic_intr_establish_xname(u_int irq, int ih->ih_func = func; ih->ih_arg = arg; ih->ih_irq = irq; - ih->ih_cidx = cidx; + ih->ih_hartid = hartid; plic_set_priority(sc, irq, 1); - plic_enable(sc, cidx, irq); + plic_enable(sc, hartid, irq); return ih; } @@ -103,10 +105,10 @@ plic_intr_disestablish(void *cookie) { struct plic_softc * const sc = plic_sc; struct plic_intrhand * const ih = cookie; - const u_int cidx = ih->ih_cidx; + const u_int hartid = ih->ih_hartid; const u_int irq = ih->ih_irq; - plic_disable(sc, cidx, irq); + plic_disable(sc, hartid, irq); plic_set_priority(sc, irq, 0); memset(>sc_intr[irq], 0, sizeof(*sc->sc_intr)); @@ -116,9 +118,9 @@ int plic_intr(void *arg) { struct plic_softc * const sc = arg; - const cpuid_t cpuid = cpu_number(); - const bus_addr_t claim_addr = PLIC_CLAIM(sc, cpuid); - const bus_addr_t complete_addr = PLIC_COMPLETE(sc, cpuid); + const cpuid_t hartid = cpu_number(); + const bus_addr_t claim_addr = PLIC_CLAIM(sc, hartid); + const bus_addr_t complete_addr = PLIC_COMPLETE(sc, hartid); uint32_t pending; int rv = 0; @@ -144,22 +146,23 @@ plic_intr(void *arg) } void -plic_enable(struct plic_softc *sc, u_int cpu, u_int irq) +plic_enable(struct plic_softc *sc, u_int hartid, u_int irq) { KASSERT(irq < PLIC_NIRQ); - const bus_addr_t addr = PLIC_ENABLE(sc, cpu, irq); + const bus_addr_t addr = PLIC_ENABLE(sc, hartid, irq); const uint32_t mask = __BIT(irq % 32); uint32_t reg = PLIC_READ(sc, addr); reg |= mask; + PLIC_WRITE(sc, addr, reg); } void -plic_disable(struct plic_softc *sc, u_int cpu, u_int irq) +plic_disable(struct plic_softc *sc, u_int hartid, u_int irq) { KASSERT(irq < PLIC_NIRQ); - const bus_addr_t addr = PLIC_ENABLE(sc, cpu, irq); + const bus_addr_t addr = PLIC_ENABLE(sc, hartid, irq); const uint32_t mask = __BIT(irq % 32); uint32_t reg = PLIC_READ(sc, addr); @@ -177,9 +180,9 @@ plic_set_priority(struct plic_softc *sc, } void -plic_set_threshold(struct plic_softc *sc, cpuid_t cpu, uint32_t threshold) +plic_set_threshold(struct plic_softc *sc, cpuid_t hartid, uint32_t threshold) { - const bus_addr_t addr = PLIC_THRESHOLD(sc, cpu); + const bus_addr_t addr = PLIC_THRESHOLD(sc,
CVS commit: src/sys/arch/riscv/dev
Module Name:src Committed By: skrll Date: Sat Sep 2 09:58:15 UTC 2023 Modified Files: src/sys/arch/riscv/dev: plic.c plic_fdt.c plicvar.h Log Message: Be clear about hart vs cpu. NFCI. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/arch/riscv/dev/plic.c \ src/sys/arch/riscv/dev/plicvar.h cvs rdiff -u -r1.2 -r1.3 src/sys/arch/riscv/dev/plic_fdt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/arch/riscv/dev
Module Name:src Committed By: skrll Date: Sat Sep 2 09:29:59 UTC 2023 Modified Files: src/sys/arch/riscv/dev: plic_fdt.c Log Message: Simplify plic_fdt_intr_disestablish by calling plic_intr_disestablish To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/arch/riscv/dev/plic_fdt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/arch/riscv/dev
Module Name:src Committed By: skrll Date: Sat Sep 2 09:29:59 UTC 2023 Modified Files: src/sys/arch/riscv/dev: plic_fdt.c Log Message: Simplify plic_fdt_intr_disestablish by calling plic_intr_disestablish To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/arch/riscv/dev/plic_fdt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/riscv/dev/plic_fdt.c diff -u src/sys/arch/riscv/dev/plic_fdt.c:1.1 src/sys/arch/riscv/dev/plic_fdt.c:1.2 --- src/sys/arch/riscv/dev/plic_fdt.c:1.1 Sun May 7 12:41:48 2023 +++ src/sys/arch/riscv/dev/plic_fdt.c Sat Sep 2 09:29:59 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: plic_fdt.c,v 1.1 2023/05/07 12:41:48 skrll Exp $ */ +/* $NetBSD: plic_fdt.c,v 1.2 2023/09/02 09:29:59 skrll Exp $ */ /*- * Copyright (c) 2022 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: plic_fdt.c,v 1.1 2023/05/07 12:41:48 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: plic_fdt.c,v 1.2 2023/09/02 09:29:59 skrll Exp $"); #include @@ -70,18 +70,12 @@ plic_fdt_intr_establish(device_t dev, u_ return ih; } + static void plic_fdt_intr_disestablish(device_t dev, void *cookie) { - struct plic_softc * const sc = device_private(dev); - struct plic_intrhand * const ih = cookie; - const u_int cidx = ih->ih_cidx; - const u_int irq = ih->ih_irq; - - plic_disable(sc, cidx, irq); - plic_set_priority(sc, irq, 0); - memset(>sc_intr[irq], 0, sizeof(*sc->sc_intr)); + plic_intr_disestablish(cookie); }