Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/arch/x86/x86/intr.c,v rcsdiff: /ftp/cvs/cvsroot/src/sys/arch/x86/x86/intr.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.29.10.2 retrieving revision 1.29.10.3 diff -u -p -r1.29.10.2 -r1.29.10.3 --- src/sys/arch/x86/x86/intr.c 2008/01/09 01:49:55 1.29.10.2 +++ src/sys/arch/x86/x86/intr.c 2008/03/23 02:04:28 1.29.10.3 @@ -1,4 +1,4 @@ -/* $NetBSD: intr.c,v 1.29.10.2 2008/01/09 01:49:55 matt Exp $ */ +/* intr.c,v 1.29.10.2 2008/01/09 01:49:55 matt Exp */ /*- * Copyright (c) 2007 The NetBSD Foundation, Inc. @@ -140,7 +140,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.29.10.2 2008/01/09 01:49:55 matt Exp $"); +__KERNEL_RCSID(0, "intr.c,v 1.29.10.2 2008/01/09 01:49:55 matt Exp"); #include "opt_multiprocessor.h" #include "opt_acpi.h" @@ -226,6 +226,61 @@ intr_default_setup(void) i8259_default_setup(); } +struct nmi_handler { + int (*n_func)(void *); + void *n_arg; + SLIST_ENTRY(nmi_handler) n_next; +}; + +SLIST_HEAD(nmi_handler_head, nmi_handler) nmi_handlers = + SLIST_HEAD_INITIALIZER(nmi_handler_head); + +void * +nmi_establish(int (*func)(void *), void *arg) +{ + struct nmi_handler *n; + + n = malloc(sizeof(*n), M_DEVBUF, cold ? M_NOWAIT : M_WAITOK); + + if (n == NULL) + return NULL; + + n->n_func = func; + n->n_arg = arg; + SLIST_INSERT_HEAD(&nmi_handlers, n, n_next); + KASSERT(SLIST_FIRST(&nmi_handlers) == n); + return n; +} + +bool +nmi_disestablish(void *n0) +{ + struct nmi_handler *n; + + SLIST_FOREACH(n, &nmi_handlers, n_next) { + if (n == n0) + break; + } + if (n == NULL) + return false; + SLIST_REMOVE(&nmi_handlers, n, nmi_handler, n_next); + free(n, M_DEVBUF); + return true; +} + +int +nmi_dispatch(void) +{ + int handled = 0; + struct nmi_handler *n; + + SLIST_FOREACH(n, &nmi_handlers, n_next) { + if ((*n->n_func)(n->n_arg)) + handled = 1; + } + return handled; +} + /* * Handle a NMI, possibly a machine check. * return true to panic system, false to ignore.