Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/alpha Reduce code duplication when setting up the i...
details: https://anonhg.NetBSD.org/src/rev/dd0af7953818
branches: trunk
changeset: 984362:dd0af7953818
user: thorpej <thorpej%NetBSD.org@localhost>
date: Sun Jul 04 22:36:43 2021 +0000
description:
Reduce code duplication when setting up the interrupt handler data
structures:
- alpha_shared_intr_alloc() no longer takes a "string length" argument,
and just uses kmem_asprintf() to create an "irq %u" string by default.
This is suitable for nearly every caller.
- Add a alpha_shared_intr_set_string() that allows callers to override
the default IRQ description string.
- Related: make alpha_shared_intr_string() return a const char *, since
no callers should need to modify the string directly now.
- Re-factor PCI shared interrupt structure allocation / initialization
into a new alpha_pci_intr_alloc(), which is suitable for nearly every
Alpha PCI platform. Callers are expected to first have initialized
the interrupt hardware to the quiescent state.
Adjust various call sites of above functions to account for changes,
even if they are not able to use the newly re-factored code.
diffstat:
sys/arch/alpha/common/shared_intr.c | 27 +++++++++++++--------
sys/arch/alpha/include/intr.h | 8 ++++--
sys/arch/alpha/include/pci_machdep.h | 3 +-
sys/arch/alpha/jensenio/jensenio_intr.c | 21 ++++++----------
sys/arch/alpha/pci/pci_1000.c | 23 ++++--------------
sys/arch/alpha/pci/pci_1000a.c | 21 +++-------------
sys/arch/alpha/pci/pci_2100_a500.c | 41 +++++++++++++++++---------------
sys/arch/alpha/pci/pci_550.c | 28 ++++------------------
sys/arch/alpha/pci/pci_6600.c | 25 +++++--------------
sys/arch/alpha/pci/pci_eb164.c | 31 ++++++++----------------
sys/arch/alpha/pci/pci_eb64plus.c | 21 ++++------------
sys/arch/alpha/pci/pci_eb66.c | 21 ++++------------
sys/arch/alpha/pci/pci_kn20aa.c | 19 ++++-----------
sys/arch/alpha/pci/pci_kn300.c | 23 ++++++++++--------
sys/arch/alpha/pci/pci_machdep.c | 27 ++++++++++++++++++++-
sys/arch/alpha/pci/sio_pic.c | 16 ++++++------
16 files changed, 146 insertions(+), 209 deletions(-)
diffs (truncated from 896 to 300 lines):
diff -r 456c55da6397 -r dd0af7953818 sys/arch/alpha/common/shared_intr.c
--- a/sys/arch/alpha/common/shared_intr.c Sun Jul 04 20:22:31 2021 +0000
+++ b/sys/arch/alpha/common/shared_intr.c Sun Jul 04 22:36:43 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: shared_intr.c,v 1.28 2021/06/25 18:08:34 thorpej Exp $ */
+/* $NetBSD: shared_intr.c,v 1.29 2021/07/04 22:36:43 thorpej Exp $ */
/*
* Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
-__KERNEL_RCSID(0, "$NetBSD: shared_intr.c,v 1.28 2021/06/25 18:08:34 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: shared_intr.c,v 1.29 2021/07/04 22:36:43 thorpej Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@@ -96,25 +96,23 @@
}
struct alpha_shared_intr *
-alpha_shared_intr_alloc(unsigned int n, unsigned int namesize)
+alpha_shared_intr_alloc(unsigned int n)
{
struct alpha_shared_intr *intr;
unsigned int i;
+ KASSERT(n != 0);
+
intr = kmem_alloc(n * sizeof(*intr), KM_SLEEP);
for (i = 0; i < n; i++) {
TAILQ_INIT(&intr[i].intr_q);
intr[i].intr_sharetype = IST_NONE;
intr[i].intr_dfltsharetype = IST_NONE;
intr[i].intr_nstrays = 0;
- intr[i].intr_maxstrays = 5;
+ intr[i].intr_maxstrays = 0;
intr[i].intr_private = NULL;
intr[i].intr_cpu = NULL;
- if (namesize != 0) {
- intr[i].intr_string = kmem_zalloc(namesize, KM_SLEEP);
- } else {
- intr[i].intr_string = NULL;
- }
+ intr[i].intr_string = kmem_asprintf("irq %u", i);
}
return (intr);
@@ -492,7 +490,16 @@
return (&intr[num].intr_evcnt);
}
-char *
+void
+alpha_shared_intr_set_string(struct alpha_shared_intr *intr,
+ unsigned int num, char *str)
+{
+ char *ostr = intr[num].intr_string;
+ intr[num].intr_string = str;
+ kmem_strfree(ostr);
+}
+
+const char *
alpha_shared_intr_string(struct alpha_shared_intr *intr,
unsigned int num)
{
diff -r 456c55da6397 -r dd0af7953818 sys/arch/alpha/include/intr.h
--- a/sys/arch/alpha/include/intr.h Sun Jul 04 20:22:31 2021 +0000
+++ b/sys/arch/alpha/include/intr.h Sun Jul 04 22:36:43 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: intr.h,v 1.83 2020/10/10 03:05:04 thorpej Exp $ */
+/* $NetBSD: intr.h,v 1.84 2021/07/04 22:36:43 thorpej Exp $ */
/*-
* Copyright (c) 2000, 2001, 2002 The NetBSD Foundation, Inc.
@@ -227,7 +227,7 @@
((asi)[num].intr_maxstrays != 0 && \
(asi)[num].intr_nstrays == (asi)[num].intr_maxstrays)
-struct alpha_shared_intr *alpha_shared_intr_alloc(unsigned int, unsigned int);
+struct alpha_shared_intr *alpha_shared_intr_alloc(unsigned int);
int alpha_shared_intr_dispatch(struct alpha_shared_intr *,
unsigned int);
struct alpha_shared_intrhand *
@@ -262,7 +262,9 @@
struct cpu_info *
alpha_shared_intr_get_cpu(struct alpha_shared_intr *,
unsigned int);
-char *alpha_shared_intr_string(struct alpha_shared_intr *,
+void alpha_shared_intr_set_string(struct alpha_shared_intr *,
+ unsigned int, char *);
+const char *alpha_shared_intr_string(struct alpha_shared_intr *,
unsigned int);
struct evcnt *alpha_shared_intr_evcnt(struct alpha_shared_intr *,
unsigned int);
diff -r 456c55da6397 -r dd0af7953818 sys/arch/alpha/include/pci_machdep.h
--- a/sys/arch/alpha/include/pci_machdep.h Sun Jul 04 20:22:31 2021 +0000
+++ b/sys/arch/alpha/include/pci_machdep.h Sun Jul 04 22:36:43 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_machdep.h,v 1.23 2021/06/19 16:59:07 thorpej Exp $ */
+/* $NetBSD: pci_machdep.h,v 1.24 2021/07/04 22:36:43 thorpej Exp $ */
/*
* Copyright (c) 1996 Carnegie-Mellon University.
@@ -136,6 +136,7 @@
void alpha_pci_intr_init(void *, bus_space_tag_t, bus_space_tag_t,
pci_chipset_tag_t);
+void alpha_pci_intr_alloc(pci_chipset_tag_t, unsigned int);
int alpha_pci_generic_intr_map(const struct pci_attach_args *,
pci_intr_handle_t *);
diff -r 456c55da6397 -r dd0af7953818 sys/arch/alpha/jensenio/jensenio_intr.c
--- a/sys/arch/alpha/jensenio/jensenio_intr.c Sun Jul 04 20:22:31 2021 +0000
+++ b/sys/arch/alpha/jensenio/jensenio_intr.c Sun Jul 04 22:36:43 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: jensenio_intr.c,v 1.15 2021/06/25 18:08:34 thorpej Exp $ */
+/* $NetBSD: jensenio_intr.c,v 1.16 2021/07/04 22:36:43 thorpej Exp $ */
/*-
* Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
-__KERNEL_RCSID(0, "$NetBSD: jensenio_intr.c,v 1.15 2021/06/25 18:08:34 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: jensenio_intr.c,v 1.16 2021/07/04 22:36:43 thorpej Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -66,7 +66,6 @@
static int jensenio_eisa_intr_alloc(void *, int, int, int *);
#define JENSEN_MAX_IRQ 16
-#define JENSEN_MAX_IRQ_STR 16
static struct alpha_shared_intr *jensenio_eisa_intr;
@@ -111,27 +110,23 @@
{
eisa_chipset_tag_t ec = &jcp->jc_ec;
isa_chipset_tag_t ic = &jcp->jc_ic;
- char *cp;
+ struct evcnt *ev;
+ const char *cp;
int i;
pic_iot = &jcp->jc_eisa_iot;
jensenio_pic_init();
- jensenio_eisa_intr = alpha_shared_intr_alloc(JENSEN_MAX_IRQ,
- JENSEN_MAX_IRQ_STR);
+ jensenio_eisa_intr = alpha_shared_intr_alloc(JENSEN_MAX_IRQ);
for (i = 0; i < JENSEN_MAX_IRQ; i++) {
alpha_shared_intr_set_dfltsharetype(jensenio_eisa_intr,
i, jensenio_intr_deftype[i]);
- /* Don't bother with stray interrupts. */
- alpha_shared_intr_set_maxstrays(jensenio_eisa_intr,
- i, 0);
+ ev = alpha_shared_intr_evcnt(jensenio_eisa_intr, i);
cp = alpha_shared_intr_string(jensenio_eisa_intr, i);
- snprintf(cp, JENSEN_MAX_IRQ_STR, "irq %d", i);
- evcnt_attach_dynamic(alpha_shared_intr_evcnt(
- jensenio_eisa_intr, i), EVCNT_TYPE_INTR,
- NULL, "eisa", cp);
+
+ evcnt_attach_dynamic(ev, EVCNT_TYPE_INTR, NULL, "eisa", cp);
}
/*
diff -r 456c55da6397 -r dd0af7953818 sys/arch/alpha/pci/pci_1000.c
--- a/sys/arch/alpha/pci/pci_1000.c Sun Jul 04 20:22:31 2021 +0000
+++ b/sys/arch/alpha/pci/pci_1000.c Sun Jul 04 22:36:43 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_1000.c,v 1.29 2021/06/25 18:08:34 thorpej Exp $ */
+/* $NetBSD: pci_1000.c,v 1.30 2021/07/04 22:36:43 thorpej Exp $ */
/*
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
-__KERNEL_RCSID(0, "$NetBSD: pci_1000.c,v 1.29 2021/06/25 18:08:34 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_1000.c,v 1.30 2021/07/04 22:36:43 thorpej Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -99,8 +99,6 @@
pci_1000_pickintr(void *core, bus_space_tag_t iot, bus_space_tag_t memt,
pci_chipset_tag_t pc)
{
- char *cp;
- int i;
another_mystery_icu_iot = iot;
@@ -116,9 +114,6 @@
pc->pc_pciide_compat_intr_establish = NULL;
-#define PCI_1000_IRQ_STR 8
- pc->pc_shared_intrs =
- alpha_shared_intr_alloc(PCI_NIRQ, PCI_1000_IRQ_STR);
pc->pc_intr_desc = "dec 1000";
pc->pc_vecbase = 0x900;
pc->pc_nirq = PCI_NIRQ;
@@ -126,18 +121,10 @@
pc->pc_intr_enable = dec_1000_enable_intr;
pc->pc_intr_disable = dec_1000_disable_intr;
- for (i = 0; i < PCI_NIRQ; i++) {
- alpha_shared_intr_set_maxstrays(pc->pc_shared_intrs, i,
- PCI_STRAY_MAX);
-
- cp = alpha_shared_intr_string(pc->pc_shared_intrs, i);
- snprintf(cp, PCI_1000_IRQ_STR, "irq %d", i);
- evcnt_attach_dynamic(alpha_shared_intr_evcnt(
- pc->pc_shared_intrs, i), EVCNT_TYPE_INTR, NULL,
- pc->pc_intr_desc, cp);
- }
+ pci_1000_imi();
- pci_1000_imi();
+ alpha_pci_intr_alloc(pc, PCI_STRAY_MAX);
+
#if NSIO > 0 || NPCEB > 0
sio_intr_setup(pc, iot);
#endif
diff -r 456c55da6397 -r dd0af7953818 sys/arch/alpha/pci/pci_1000a.c
--- a/sys/arch/alpha/pci/pci_1000a.c Sun Jul 04 20:22:31 2021 +0000
+++ b/sys/arch/alpha/pci/pci_1000a.c Sun Jul 04 22:36:43 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_1000a.c,v 1.31 2021/06/25 18:08:34 thorpej Exp $ */
+/* $NetBSD: pci_1000a.c,v 1.32 2021/07/04 22:36:43 thorpej Exp $ */
/*
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
-__KERNEL_RCSID(0, "$NetBSD: pci_1000a.c,v 1.31 2021/06/25 18:08:34 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_1000a.c,v 1.32 2021/07/04 22:36:43 thorpej Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -102,8 +102,6 @@
pci_1000a_pickintr(void *core, bus_space_tag_t iot, bus_space_tag_t memt,
pci_chipset_tag_t pc)
{
- char *cp;
- int i;
mystery_icu_iot = iot;
@@ -120,9 +118,6 @@
pc->pc_pciide_compat_intr_establish = NULL;
-#define PCI_1000A_IRQ_STR 8
- pc->pc_shared_intrs = alpha_shared_intr_alloc(PCI_NIRQ,
- PCI_1000A_IRQ_STR);
pc->pc_intr_desc = "dec 1000a";
pc->pc_vecbase = 0x900;
pc->pc_nirq = PCI_NIRQ;
@@ -130,18 +125,10 @@
pc->pc_intr_enable = dec_1000a_enable_intr;
pc->pc_intr_disable = dec_1000a_disable_intr;
- for (i = 0; i < PCI_NIRQ; i++) {
- alpha_shared_intr_set_maxstrays(pc->pc_shared_intrs, i,
- PCI_STRAY_MAX);
+ pci_1000a_imi();
- cp = alpha_shared_intr_string(pc->pc_shared_intrs, i);
- snprintf(cp, PCI_1000A_IRQ_STR, "irq %d", i);
- evcnt_attach_dynamic(alpha_shared_intr_evcnt(
- pc->pc_shared_intrs, i), EVCNT_TYPE_INTR, NULL,
- pc->pc_intr_desc, cp);
- }
+ alpha_pci_intr_alloc(pc, PCI_STRAY_MAX);
- pci_1000a_imi();
#if NSIO > 0 || NPCEB > 0
sio_intr_setup(pc, iot);
#endif
diff -r 456c55da6397 -r dd0af7953818 sys/arch/alpha/pci/pci_2100_a500.c
--- a/sys/arch/alpha/pci/pci_2100_a500.c Sun Jul 04 20:22:31 2021 +0000
+++ b/sys/arch/alpha/pci/pci_2100_a500.c Sun Jul 04 22:36:43 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_2100_a500.c,v 1.16 2021/06/25 18:08:34 thorpej Exp $ */
+/* $NetBSD: pci_2100_a500.c,v 1.17 2021/07/04 22:36:43 thorpej Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -31,13 +31,14 @@
Home |
Main Index |
Thread Index |
Old Index