NMI(9) | Kernel Developer's Manual (x86) | NMI(9)

# NAME

`nmi`, `nmi_establish`, `nmi_disestablish`, —
NMI

# SYNOPSIS

`#include <x86/nmi.h>`

nmi_handler_t *
`nmi_establish`(int (*func)(const struct trapframe *, void *), void *arg);

void
`nmi_disestablish`(nmi_handler_t *handle);

# DESCRIPTION

The `nmi` interface lets the kernel establish handlers for x86 Non-Maskable Interrupts (NMIs). An NMI signals to the processor an exception on a processor, memory controller, or I/O bus that is irrecoverable or else needs attention at a high priority. A “debug switch” or a performance/watchdog timer may also trigger an NMI.

An NMI handler will run to completion on the same processor where it began without being preempted by any thread or interrupt except for another NMI. An NMI handler must prepare for re-entry. An NMI handler may run simultaneously on more than one CPU.

Synchronizing access to a shared data structure from an NMI handler is a different challenge than synchronizing access from hardware/software interrupt routines or from kernel threads. An NMI handler may not perform any operation that may sleep, acquire a mutex, or schedule a software interrupt. An NMI handler may use atomic_ops(3). An NMI handler may reference per-CPU storage (percpu(9)).

An NMI handler may not write to the kernel message buffer.

# FUNCTIONS

`nmi_establish`(func, arg)
  Call this in thread context to establish a handler for non-maskable interrupts. Establish func as one of the handler functions to call when an NMI occurs. Where tf is a struct trapframe representation of the processor context where the NMI was received, and arg is the argument to `nmi_establish`(), the kernel will call `(*func)`(tf, arg); every time an NMI occurs until the handler is removed with `nmi_disestablish`(). func should return non-zero if it handled a condition that causes NMI, or zero if it did not. If, for a given NMI, all handlers return zero, the system will panic or enter the kernel debugger, ddb(4). `nmi_establish`() returns `NULL` on failure, and a handle for the NMI handler on success.
`nmi_disestablish`(handle)
  Call this in thread context to stop the kernel from calling an NMI handler. Indicate the handler to disestablish with the handle returned by `nmi_establish`().

# CODE REFERENCES

The `nmi` interface is implemented within the file sys/arch/x86/x86/nmi.c.

# SEE ALSO

atomic_ops(3), ddb(4)

# HISTORY

The `nmi` interface first appeared in NetBSD 6.0.

# AUTHORS

YAMAMOTO Takashi <yamt@NetBSD.org>

March 17, 2011 | NetBSD 9.4