// File: /workspace/github_c_makefile_star2_O0/intel[P]pf-bb-config/vrb2/vrb2_cfg_app.c
// Function: vrb2_allocate_info_ring
static int
vrb2_allocate_info_ring(void *dev)
{
	hw_device *accel_pci_dev = (hw_device *)dev;
	void *bar0addr = accel_pci_dev->bar0Addr;
	uint32_t i, *ring_data;

	if (accel_pci_dev->info_ring)
		return 0; /* already configured */

	accel_pci_dev->info_ring = vfio_dma_alloc(dev,
			BB_ACC_INFO_RING_SIZE,
			&accel_pci_dev->info_ring_phys_addr);

	if (!accel_pci_dev->info_ring) {
		LOG(ERR, "memory allocation for info_ring failed");
		return -1;
	}

	LOG(DEBUG, "dev info ring virt:%p, phy: 0x%08lx",
			accel_pci_dev->info_ring, accel_pci_dev->info_ring_phys_addr);

	vrb2_reg_write(bar0addr, HWPfHiInfoRingBaseHiRegPf,
		(uint32_t) (accel_pci_dev->info_ring_phys_addr >> 32));
	vrb2_reg_write(bar0addr, HWPfHiInfoRingBaseLoRegPf,
		(uint32_t) (accel_pci_dev->info_ring_phys_addr));
	vrb2_reg_write(bar0addr, HWPfHiInfoRingPointerRegPf, 0xF000);

	accel_pci_dev->info_ring_head =
			(vrb2_reg_read(bar0addr, HWPfHiInfoRingPointerRegPf) & 0xFFF) /
			sizeof(uint32_t);

	/* Clear explicitly content of Info Ring */
	if (accel_pci_dev->info_ring != NULL) {
		for (i = 0; i < VRB2_INFO_RING_NUM_ENTRIES; i++) {
			ring_data = ((uint32_t *) accel_pci_dev->info_ring) + i;
			*ring_data = 0;
		}
	}

	LOG(DEBUG, "info_ring_head: %d", accel_pci_dev->info_ring_head);

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0xb0(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x90(%rax)
je 0x199ed
movl $0x0, -0x4(%rbp)
jmp 0x19ba6
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rdx
addq $0x98, %rdx
movl $0x1000, %esi           # imm = 0x1000
callq 0x201b0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x90(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x90(%rax)
jne 0x19a52
callq 0x1bd70
movq %rax, %rcx
leaq 0x21e9f(%rip), %rax     # 0x3b8d0
movq (%rax), %r8
xorl %esi, %esi
leaq 0xadac(%rip), %rdx      # 0x247e9
movl %esi, %edi
movb $0x0, %al
callq 0x216e0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x19ba6
callq 0x1bd70
movq %rax, %rcx
leaq 0x21e6f(%rip), %rax     # 0x3b8d0
movq 0x18(%rax), %r8
movq -0x18(%rbp), %rax
movq 0x90(%rax), %r10
movq -0x18(%rbp), %rax
movq 0x98(%rax), %rax
movl $0x3, %edi
xorl %esi, %esi
leaq 0xad8e(%rip), %rdx      # 0x24817
leaq 0xbcc2(%rip), %r9       # 0x25752
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x216e0
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x98(%rax), %rax
shrq $0x20, %rax
movl %eax, %edx
movl $0xc84018, %esi         # imm = 0xC84018
callq 0x197e0
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x98(%rax), %rax
movl %eax, %edx
movl $0xc84014, %esi         # imm = 0xC84014
callq 0x197e0
movq -0x20(%rbp), %rdi
movl $0xc8401c, %esi         # imm = 0xC8401C
movl $0xf000, %edx           # imm = 0xF000
callq 0x197e0
movq -0x20(%rbp), %rdi
movl $0xc8401c, %esi         # imm = 0xC8401C
callq 0x18b70
andl $0xfff, %eax            # imm = 0xFFF
movl %eax, %eax
shrq $0x2, %rax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0xa8(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x90(%rax)
je 0x19b62
movl $0x0, -0x24(%rbp)
cmpl $0x400, -0x24(%rbp)     # imm = 0x400
jae 0x19b60
movq -0x18(%rbp), %rax
movq 0x90(%rax), %rax
movl -0x24(%rbp), %ecx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movl $0x0, (%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x19b29
jmp 0x19b62
callq 0x1bd70
movq %rax, %rcx
leaq 0x21d5f(%rip), %rax     # 0x3b8d0
movq 0x18(%rax), %r8
movq -0x18(%rbp), %rax
movzwl 0xa8(%rax), %eax
movl $0x3, %edi
xorl %esi, %esi
leaq 0xacd2(%rip), %rdx      # 0x24860
leaq 0xbbbd(%rip), %r9       # 0x25752
movl %eax, (%rsp)
movb $0x0, %al
callq 0x216e0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nop