18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  Machine specific NMI handling for generic.
48c2ecf20Sopenharmony_ci *  Split out from traps.c by Osamu Tomita <tomita@cinet.co.jp>
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci#ifndef _ASM_X86_MACH_DEFAULT_MACH_TRAPS_H
78c2ecf20Sopenharmony_ci#define _ASM_X86_MACH_DEFAULT_MACH_TRAPS_H
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <asm/mc146818rtc.h>
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#define NMI_REASON_PORT		0x61
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#define NMI_REASON_SERR		0x80
148c2ecf20Sopenharmony_ci#define NMI_REASON_IOCHK	0x40
158c2ecf20Sopenharmony_ci#define NMI_REASON_MASK		(NMI_REASON_SERR | NMI_REASON_IOCHK)
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#define NMI_REASON_CLEAR_SERR	0x04
188c2ecf20Sopenharmony_ci#define NMI_REASON_CLEAR_IOCHK	0x08
198c2ecf20Sopenharmony_ci#define NMI_REASON_CLEAR_MASK	0x0f
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cistatic inline unsigned char default_get_nmi_reason(void)
228c2ecf20Sopenharmony_ci{
238c2ecf20Sopenharmony_ci	return inb(NMI_REASON_PORT);
248c2ecf20Sopenharmony_ci}
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_cistatic inline void reassert_nmi(void)
278c2ecf20Sopenharmony_ci{
288c2ecf20Sopenharmony_ci	int old_reg = -1;
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci	if (do_i_have_lock_cmos())
318c2ecf20Sopenharmony_ci		old_reg = current_lock_cmos_reg();
328c2ecf20Sopenharmony_ci	else
338c2ecf20Sopenharmony_ci		lock_cmos(0); /* register doesn't matter here */
348c2ecf20Sopenharmony_ci	outb(0x8f, 0x70);
358c2ecf20Sopenharmony_ci	inb(0x71);		/* dummy */
368c2ecf20Sopenharmony_ci	outb(0x0f, 0x70);
378c2ecf20Sopenharmony_ci	inb(0x71);		/* dummy */
388c2ecf20Sopenharmony_ci	if (old_reg >= 0)
398c2ecf20Sopenharmony_ci		outb(old_reg, 0x70);
408c2ecf20Sopenharmony_ci	else
418c2ecf20Sopenharmony_ci		unlock_cmos();
428c2ecf20Sopenharmony_ci}
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#endif /* _ASM_X86_MACH_DEFAULT_MACH_TRAPS_H */
45