// File: /workspace/github_c_makefile_star2_O1/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 0x18f62
leaq 0x1bff0(%rip), %r12     # 0x33ed0
movq 0x18(%r12), %r8
leaq 0x5b82(%rip), %rdx      # 0x1da6e
leaq 0x5b9f(%rip), %r9       # 0x1da92
xorl %ebp, %ebp
movl $0x3, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x19ca8
cmpl $0x0, 0xbc(%rbx)
je 0x17fa5
cmpl $0x1, 0xc8(%rbx)
jne 0x17f51
movq %rbx, %rdi
callq 0x18168
testl %eax, %eax
je 0x17fb4
callq 0x18f62
movq (%r12), %r8
leaq 0x5b67(%rip), %rdx      # 0x1daa3
xorl %edi, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x19ca8
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x17fa5
callq 0x18f62
movq 0x10(%r12), %r8
movl 0xc8(%rbx), %r9d
leaq 0x5bab(%rip), %rdx      # 0x1db14
movl $0x2, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x19ca8
callq 0x18f62
movq 0x18(%r12), %r8
leaq 0x3599(%rip), %rdx      # 0x1b524
leaq 0x5b00(%rip), %r9       # 0x1da92
xorl %ebp, %ebp
movl $0x3, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x19ca8
movl %ebp, %eax
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
callq 0x18f62
movq 0x18(%r12), %r8
leaq 0x6018(%rip), %rdx      # 0x1dfdd
leaq 0x6039(%rip), %r9       # 0x1e005
movl $0x3, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x19ca8
cmpl $0x0, 0xc4(%rbx)
jle 0x18038
movq 0x50(%rbx), %rax
testq %rax, %rax
je 0x1801e
movq %rbx, %rdi
callq *%rax
testl %eax, %eax
je 0x1801e
callq 0x18f62
movq (%r12), %r8
movq (%rbx), %r9
leaq 0x5ae0(%rip), %rdx      # 0x1daeb
xorl %edi, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x19ca8
jmp 0x17f4a
movl 0xc4(%rbx), %edi
leaq 0x2e7(%rip), %rsi       # 0x18312
movq %rbx, %rdx
callq 0x19516
jmp 0x17f7a
xorl %edi, %edi
movl $0x80000, %esi          # imm = 0x80000
callq 0xd400
movl %eax, %ebp
movl %eax, 0xc4(%rbx)
callq 0x18f62
testl %ebp, %ebp
js 0x18111
movq 0x18(%r12), %r8
movl 0xc4(%rbx), %ecx
movl %ecx, (%rsp)
leaq 0x5fd7(%rip), %rdx      # 0x1e045
leaq 0x5f90(%rip), %r9       # 0x1e005
movl $0x3, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x19ca8
movabsq $0x2400000018, %rax     # imm = 0x2400000018
leaq 0x10(%rsp), %rdx
movq %rax, (%rdx)
movl $0x1, 0x8(%rdx)
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0xc(%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 0x18f62
movq %rax, %r14
testl %ebp, %ebp
je 0x1813f
movq (%r12), %r15
callq 0xd070
movl (%rax), %r9d
leaq 0x5f7a(%rip), %rdx      # 0x1e063
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0x19ca8
movl 0xc4(%rbx), %edi
callq 0xd1a0
movl $0x0, 0xc4(%rbx)
jmp 0x1812a
movq (%r12), %r8
leaq 0x5ef9(%rip), %rdx      # 0x1e015
xorl %edi, %edi
xorl %esi, %esi
movq %rax, %rcx
xorl %eax, %eax
callq 0x19ca8
callq 0x18f62
movq (%r12), %r8
leaq 0x598e(%rip), %rdx      # 0x1dac8
jmp 0x17f3c
movq 0x18(%r12), %r8
leaq 0x5f43(%rip), %rdx      # 0x1e08e
leaq 0x5eb3(%rip), %r9       # 0x1e005
movl $0x3, %edi
xorl %esi, %esi
movq %r14, %rcx
xorl %eax, %eax
callq 0x19ca8
jmp 0x17fe6