// File: /workspace/github_c_makefile_star2_O0/intel[P]pf-bb-config/bb_acc_vfio.c
// Function: vfio_enable_msi
static int vfio_enable_msi(hw_device *hwd)
{
	int len;
	int32_t *pfd;
	char  set_irq_buf[VFIO_IRQ_SET_BUF_LEN];
	struct vfio_irq_set *irqs;

	LOG(DEBUG, "MSI IRQ event registration");

	/* check if already enabled then do nothing */
	if (hwd->irq_event_fd > 0)
		return 0;

	hwd->irq_event_fd = eventfd(0, EFD_CLOEXEC);
	if (hwd->irq_event_fd < 0) {
		LOG(ERR, "Failed to get eventfd for vfio interrupt");
		return -1;
	}
	LOG(DEBUG, "irq_event_fd: %d", hwd->irq_event_fd);

	len = sizeof(set_irq_buf);

	irqs = (struct vfio_irq_set *)set_irq_buf;
	irqs->argsz = len;
	irqs->index = VFIO_PCI_MSI_IRQ_INDEX;
	irqs->flags = VFIO_IRQ_SET_DATA_EVENTFD | VFIO_IRQ_SET_ACTION_TRIGGER;
	irqs->start = 0;
	irqs->count = 1;
	pfd = (int *)&irqs->data;
	*pfd = hwd->irq_event_fd;

	if (ioctl(hwd->vfio_dev_fd, VFIO_DEVICE_SET_IRQS, irqs)) {
		LOG(ERR, "ioctl VFIO_DEVICE_SET_IRQS error %d", errno);
		close(hwd->irq_event_fd);
		hwd->irq_event_fd = 0;
		return -1;
	}

	LOG(DEBUG, "irq eventfd registration success");
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
callq 0x20230
movq %rax, %rcx
leaq 0x1ca95(%rip), %rax     # 0x3b8d0
movq 0x18(%rax), %r8
movl $0x3, %edi
xorl %esi, %esi
leaq 0x7191(%rip), %rdx      # 0x25fde
leaq 0x71b2(%rip), %r9       # 0x26006
movb $0x0, %al
callq 0x216e0
movq -0x10(%rbp), %rax
cmpl $0x0, 0xc4(%rax)
jle 0x1ee74
movl $0x0, -0x4(%rbp)
jmp 0x1f019
xorl %edi, %edi
movl $0x80000, %esi          # imm = 0x80000
callq 0xd400
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc4(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0xc4(%rax)
jge 0x1eec9
callq 0x20230
movq %rax, %rcx
leaq 0x1ca28(%rip), %rax     # 0x3b8d0
movq (%rax), %r8
xorl %esi, %esi
leaq 0x7162(%rip), %rdx      # 0x26016
movl %esi, %edi
movb $0x0, %al
callq 0x216e0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1f019
callq 0x20230
movq %rax, %rcx
leaq 0x1c9f8(%rip), %rax     # 0x3b8d0
movq 0x18(%rax), %r8
movq -0x10(%rbp), %rax
movl 0xc4(%rax), %eax
movl $0x3, %edi
xorl %esi, %esi
leaq 0x7152(%rip), %rdx      # 0x26046
leaq 0x710b(%rip), %r9       # 0x26006
movl %eax, (%rsp)
movb $0x0, %al
callq 0x216e0
movl $0x18, -0x14(%rbp)
leaq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x14(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, (%rax)
movq -0x48(%rbp), %rax
movl $0x1, 0x8(%rax)
movq -0x48(%rbp), %rax
movl $0x24, 0x4(%rax)
movq -0x48(%rbp), %rax
movl $0x0, 0xc(%rax)
movq -0x48(%rbp), %rax
movl $0x1, 0x10(%rax)
movq -0x48(%rbp), %rax
addq $0x14, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl 0xc4(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movl 0xc0(%rax), %edi
movq -0x48(%rbp), %rdx
movl $0x3b6e, %esi           # imm = 0x3B6E
movb $0x0, %al
callq 0xd180
cmpl $0x0, %eax
je 0x1efe3
callq 0x20230
movq %rax, -0x58(%rbp)
leaq 0x1c93c(%rip), %rax     # 0x3b8d0
movq (%rax), %rax
movq %rax, -0x50(%rbp)
callq 0xd060
movq -0x58(%rbp), %rcx
movq -0x50(%rbp), %r8
movl (%rax), %r9d
xorl %esi, %esi
leaq 0x70b0(%rip), %rdx      # 0x26064
movl %esi, %edi
movb $0x0, %al
callq 0x216e0
movq -0x10(%rbp), %rax
movl 0xc4(%rax), %edi
callq 0xd190
movq -0x10(%rbp), %rax
movl $0x0, 0xc4(%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1f019
callq 0x20230
movq %rax, %rcx
leaq 0x1c8de(%rip), %rax     # 0x3b8d0
movq 0x18(%rax), %r8
movl $0x3, %edi
xorl %esi, %esi
leaq 0x708b(%rip), %rdx      # 0x2608f
leaq 0x6ffb(%rip), %r9       # 0x26006
movb $0x0, %al
callq 0x216e0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)