// File: /workspace/github_c_makefile_star2_O3/intel[P]pf-bb-config/bb_acc_vfio.c
// Function: vfio_enable_intr
int vfio_enable_intr(void *dev)
{
	hw_device *hwd = (hw_device *)dev;

	LOG(DEBUG, "VFIO enable interrupts");

	if (!hwd->vfio_mode)
		return 0;

	switch (hwd->vfio_int_mode) {
	case VFIO_PCI_MSI_IRQ_INDEX:
		if (vfio_set_bus_master(hwd)) {
			LOG(ERR, "vfio enable bus master failed");
			return -1;
		}

		if (vfio_enable_msi(hwd)) {
			LOG(ERR, "vfio enable MSI intr failed");
			return -1;
		}

		if ((hwd->ops.dev_enable_intr) && (hwd->ops.dev_enable_intr(hwd))) {
			LOG(ERR, "vfio enable %s device intr failed", hwd->device_name);
			return -1;
		}

		/* register isr callback for intr event */
		event_add_fd(hwd->irq_event_fd, vfio_intr_handler, hwd);
		break;

	case VFIO_PCI_INTX_IRQ_INDEX:
	case VFIO_PCI_MSIX_IRQ_INDEX:
	case VFIO_PCI_ERR_IRQ_INDEX:
	default:
		LOG(INFO, "Not supported irq index (%d)", hwd->vfio_int_mode);
		break;
	}

	LOG(DEBUG, "Done");
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x30, %rsp
movq %rdi, %rbx
callq 0x18c40
leaq 0x1c2bc(%rip), %r12     # 0x33ed0
movq 0x18(%r12), %r8
leaq 0x5ead(%rip), %rdx      # 0x1dacd
leaq 0x5eca(%rip), %r9       # 0x1daf1
xorl %ebp, %ebp
movl $0x3, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x199b4
cmpl $0x0, 0xbc(%rbx)
je 0x17cd9
cmpl $0x1, 0xc8(%rbx)
jne 0x17c85
movq %rbx, %rdi
callq 0x17e8b
testl %eax, %eax
je 0x17ce8
callq 0x18c40
movq (%r12), %r8
leaq 0x5e92(%rip), %rdx      # 0x1db02
xorl %edi, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x199b4
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x17cd9
callq 0x18c40
movq 0x10(%r12), %r8
movl 0xc8(%rbx), %r9d
leaq 0x5ed6(%rip), %rdx      # 0x1db73
movl $0x2, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x199b4
callq 0x18c40
movq 0x18(%r12), %r8
leaq 0x3865(%rip), %rdx      # 0x1b524
leaq 0x5e2b(%rip), %r9       # 0x1daf1
xorl %ebp, %ebp
movl $0x3, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x199b4
movl %ebp, %eax
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
callq 0x18c40
movq 0x18(%r12), %r8
leaq 0x6343(%rip), %rdx      # 0x1e03c
leaq 0x6364(%rip), %r9       # 0x1e064
movl $0x3, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x199b4
cmpl $0x0, 0xc4(%rbx)
jle 0x17d6c
movq 0x50(%rbx), %rax
testq %rax, %rax
je 0x17d52
movq %rbx, %rdi
callq *%rax
testl %eax, %eax
je 0x17d52
callq 0x18c40
movq (%r12), %r8
movq (%rbx), %r9
leaq 0x5e0b(%rip), %rdx      # 0x1db4a
xorl %edi, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x199b4
jmp 0x17c7e
movl 0xc4(%rbx), %edi
leaq 0x298(%rip), %rsi       # 0x17ff7
movq %rbx, %rdx
callq 0x191f5
jmp 0x17cae
xorl %edi, %edi
movl $0x80000, %esi          # imm = 0x80000
callq 0xd3f0
movl %eax, %ebp
movl %eax, 0xc4(%rbx)
callq 0x18c40
testl %ebp, %ebp
js 0x17e34
movq 0x18(%r12), %r8
movl 0xc4(%rbx), %ecx
movl %ecx, (%rsp)
leaq 0x6302(%rip), %rdx      # 0x1e0a4
leaq 0x62bb(%rip), %r9       # 0x1e064
movl $0x3, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x199b4
movaps 0x5c4f(%rip), %xmm0     # 0x1da10
leaq 0x10(%rsp), %rdx
movaps %xmm0, (%rdx)
movl $0x1, 0x10(%rdx)
movl 0xc4(%rbx), %eax
movl %eax, 0x14(%rdx)
movl 0xc0(%rbx), %edi
movl $0x3b6e, %esi           # imm = 0x3B6E
xorl %eax, %eax
callq 0xd190
movl %eax, %ebp
callq 0x18c40
movq %rax, %r14
testl %ebp, %ebp
je 0x17e62
movq (%r12), %r15
callq 0xd070
movl (%rax), %r9d
leaq 0x62b6(%rip), %rdx      # 0x1e0c2
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0x199b4
movl 0xc4(%rbx), %edi
callq 0xd1a0
movl $0x0, 0xc4(%rbx)
jmp 0x17e4d
movq (%r12), %r8
leaq 0x6235(%rip), %rdx      # 0x1e074
xorl %edi, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x199b4
callq 0x18c40
movq (%r12), %r8
leaq 0x5cca(%rip), %rdx      # 0x1db27
jmp 0x17c70
movq 0x18(%r12), %r8
leaq 0x627f(%rip), %rdx      # 0x1e0ed
leaq 0x61ef(%rip), %r9       # 0x1e064
movl $0x3, %edi
xorl %esi, %esi
movq %r14, %rcx
xorl %eax, %eax
callq 0x199b4
jmp 0x17d1a