sys/arch/amd64/include/i82093reg.h
author skrll <skrll@NetBSD.org>
Mon, 05 Dec 2016 10:54:48 +0000
branchnick-nhusb
changeset 278624 e375aab2fc60
parent 278601 0e9a0ff85e3f
child 278713 e1ce05dcfb31
permissions -rw-r--r--
Sync with HEAD

/*	 $NetBSD: i82093reg.h,v 1.5.60.2 2016/12/05 10:54:49 skrll Exp $ */

#include <x86/i82093reg.h>

#ifdef _KERNEL

#if defined(_KERNEL_OPT)
#include "opt_multiprocessor.h"
#endif

#define ioapic_asm_ack(num) \
	movq	_C_LABEL(local_apic_va),%rax	; \
	movl	$0,LAPIC_EOI(%rax)

#ifdef MULTIPROCESSOR

#define ioapic_asm_lock(num) 			        \
	movb	$1,%bl				;	\
76:							\
        xchgb	%bl,PIC_LOCK(%rdi)		;	\
	testb	%bl,%bl				;	\
	jz	78f				;	\
77:							\
	pause					;	\
	nop					;	\
	nop					;	\
	cmpb	$0,PIC_LOCK(%rdi)		;	\
	jne	77b				;	\
	jmp	76b				;	\
78:

#define ioapic_asm_unlock(num) \
	movb	$0,PIC_LOCK(%rdi)
	
#else

#define ioapic_asm_lock(num)
#define ioapic_asm_unlock(num)

#endif	/* MULTIPROCESSOR */


#define ioapic_mask(num) \
	movq	IS_PIC(%r14),%rdi				;\
	ioapic_asm_lock(num)					;\
	movl	IS_PIN(%r14),%esi				;\
	leaq	0x10(%rsi,%rsi,1),%rsi				;\
	movq	PIC_IOAPIC(%rdi),%rdi				;\
	movq	IOAPIC_SC_REG(%rdi),%r15			;\
	movl	%esi, (%r15)					;\
	movq	IOAPIC_SC_DATA(%rdi),%r15			;\
	movl	(%r15),%esi					;\
	orl	$IOAPIC_REDLO_MASK,%esi				;\
	movl	%esi,(%r15)					;\
	movq	IS_PIC(%r14),%rdi				;\
	ioapic_asm_unlock(num)

#define ioapic_unmask(num) \
	cmpq	$IREENT_MAGIC,(TF_ERR+8)(%rsp)			;\
	jne	79f						;\
	movq	IS_PIC(%r14),%rdi				;\
	ioapic_asm_lock(num)					;\
	movl	IS_PIN(%r14),%esi				;\
	leaq	0x10(%rsi,%rsi,1),%rsi				;\
	movq	PIC_IOAPIC(%rdi),%rdi				;\
	movq	IOAPIC_SC_REG(%rdi),%r15			;\
	movq	IOAPIC_SC_DATA(%rdi),%r13			;\
	movl	%esi, (%r15)					;\
	movl	(%r13),%r12d					;\
	andl	$~IOAPIC_REDLO_MASK,%r12d			;\
	movl	%esi,(%r15)					;\
	movl	%r12d,(%r13)					;\
	movq	IS_PIC(%r14),%rdi				;\
	ioapic_asm_unlock(num)					;\
79:

#endif