summaryrefslogtreecommitdiff
path: root/sys/arch/amd64/include/i82093reg.h
blob: 0411fe47e695f81bf2440bd8553924ca46860b1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*	 $NetBSD: i82093reg.h,v 1.10 2021/04/17 20:12:55 rillig 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)

#define x2apic_asm_ack(num) \
	movl	$(MSR_X2APIC_BASE + MSR_X2APIC_EOI),%ecx ; \
	xorl	%eax,%eax			; \
	xorl	%edx,%edx			; \
	wrmsr

#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				;\
	andl	$~IOAPIC_REDLO_RIRR,%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|IOAPIC_REDLO_RIRR),%r12d	;\
	movl	%esi,(%r15)					;\
	movl	%r12d,(%r13)					;\
	movq	IS_PIC(%r14),%rdi				;\
	ioapic_asm_unlock(num)					;\
79:

#endif