	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.p2align	4, 0x90                         ## -- Begin function allocate_doorbell
_allocate_doorbell:                     ## @allocate_doorbell
	.cfi_startproc
## %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register %rbp
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	pushq	%rax
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	movq	%rsi, %r12
	movq	%rdi, %r15
	movq	8(%rdi), %rax
	movq	(%rax), %r14
	movq	8(%r14), %rax
	movl	(%rax), %edi
	callq	_KFD_IS_SOC15
	testl	%eax, %eax
	je	LBB0_1
## %bb.2:
	movq	16(%r12), %rax
	movq	_KFD_QUEUE_TYPE_SDMA@GOTPCREL(%rip), %rcx
	cmpq	(%rcx), %rax
	je	LBB0_4
## %bb.3:
	movq	_KFD_QUEUE_TYPE_SDMA_XGMI@GOTPCREL(%rip), %rcx
	cmpq	(%rcx), %rax
	je	LBB0_4
## %bb.5:
	movl	(%r15), %edi
	movq	_KFD_MAX_NUM_OF_QUEUES_PER_PROCESS@GOTPCREL(%rip), %r13
	movl	(%r13), %esi
	callq	_find_first_zero_bit
	cmpl	(%r13), %eax
	jae	LBB0_9
## %bb.6:
	movl	%eax, %ebx
	movl	(%r15), %esi
	movl	%eax, %edi
	callq	_set_bit
	jmp	LBB0_7
LBB0_1:
	movl	8(%r12), %ebx
	jmp	LBB0_7
LBB0_4:
	movq	(%r14), %rax
	movq	24(%r12), %rcx
	movl	32(%r12), %ebx
	movl	%ebx, %edx
	andl	$1, %edx
	movq	_KFD_QUEUE_DOORBELL_MIRROR_OFFSET@GOTPCREL(%rip), %rsi
	imull	(%rsi), %edx
	sarl	%ebx
	addl	(%rax,%rcx,4), %ebx
	addl	%edx, %ebx
LBB0_7:
	movl	%ebx, (%r12)
	movl	4(%r12), %esi
	movq	%r14, %rdi
	movl	%ebx, %edx
	callq	_kfd_doorbell_id_to_offset
	movl	%eax, 36(%r12)
	xorl	%eax, %eax
LBB0_8:
	addq	$8, %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	retq
LBB0_9:
	leaq	L_.str(%rip), %rdi
	callq	_pr_debug
	movq	_EBUSY@GOTPCREL(%rip), %rcx
	xorl	%eax, %eax
	subl	(%rcx), %eax
	jmp	LBB0_8
	.cfi_endproc
                                        ## -- End function
	.comm	_KFD_QUEUE_TYPE_SDMA,8,3        ## @KFD_QUEUE_TYPE_SDMA
	.comm	_KFD_QUEUE_TYPE_SDMA_XGMI,8,3   ## @KFD_QUEUE_TYPE_SDMA_XGMI
	.comm	_KFD_QUEUE_DOORBELL_MIRROR_OFFSET,4,2 ## @KFD_QUEUE_DOORBELL_MIRROR_OFFSET
	.comm	_KFD_MAX_NUM_OF_QUEUES_PER_PROCESS,4,2 ## @KFD_MAX_NUM_OF_QUEUES_PER_PROCESS
	.section	__TEXT,__cstring,cstring_literals
L_.str:                                 ## @.str
	.asciz	"No doorbells available"

	.comm	_EBUSY,4,2                      ## @EBUSY
	.no_dead_strip	_allocate_doorbell
.subsections_via_symbols

	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.p2align	2                               ; -- Begin function allocate_doorbell
_allocate_doorbell:                     ; @allocate_doorbell
	.cfi_startproc
; %bb.0:
	stp	x24, x23, [sp, #-64]!           ; 16-byte Folded Spill
	.cfi_def_cfa_offset 64
	stp	x22, x21, [sp, #16]             ; 16-byte Folded Spill
	stp	x20, x19, [sp, #32]             ; 16-byte Folded Spill
	stp	x29, x30, [sp, #48]             ; 16-byte Folded Spill
	add	x29, sp, #48
	.cfi_def_cfa w29, 16
	.cfi_offset w30, -8
	.cfi_offset w29, -16
	.cfi_offset w19, -24
	.cfi_offset w20, -32
	.cfi_offset w21, -40
	.cfi_offset w22, -48
	.cfi_offset w23, -56
	.cfi_offset w24, -64
	mov	x19, x1
	mov	x21, x0
	ldr	x8, [x0, #8]
	ldr	x20, [x8]
	ldr	x8, [x20, #8]
	ldr	w0, [x8]
	bl	_KFD_IS_SOC15
	cbz	w0, LBB0_3
; %bb.1:
	ldr	x8, [x19, #16]
Lloh0:
	adrp	x9, _KFD_QUEUE_TYPE_SDMA@GOTPAGE
Lloh1:
	ldr	x9, [x9, _KFD_QUEUE_TYPE_SDMA@GOTPAGEOFF]
Lloh2:
	ldr	x9, [x9]
Lloh3:
	adrp	x10, _KFD_QUEUE_TYPE_SDMA_XGMI@GOTPAGE
Lloh4:
	ldr	x10, [x10, _KFD_QUEUE_TYPE_SDMA_XGMI@GOTPAGEOFF]
Lloh5:
	ldr	x10, [x10]
	cmp	x8, x9
	ccmp	x8, x10, #4, ne
	b.ne	LBB0_4
; %bb.2:
	ldr	x8, [x20]
	ldr	x9, [x19, #24]
	ldr	w8, [x8, x9, lsl #2]
	ldr	w9, [x19, #32]
	and	w10, w9, #0x1
Lloh6:
	adrp	x11, _KFD_QUEUE_DOORBELL_MIRROR_OFFSET@GOTPAGE
Lloh7:
	ldr	x11, [x11, _KFD_QUEUE_DOORBELL_MIRROR_OFFSET@GOTPAGEOFF]
Lloh8:
	ldr	w11, [x11]
	add	w8, w8, w9, asr #1
	madd	w22, w10, w11, w8
	b	LBB0_6
LBB0_3:
	ldr	w22, [x19, #8]
	b	LBB0_6
LBB0_4:
	ldr	w0, [x21]
Lloh9:
	adrp	x23, _KFD_MAX_NUM_OF_QUEUES_PER_PROCESS@GOTPAGE
Lloh10:
	ldr	x23, [x23, _KFD_MAX_NUM_OF_QUEUES_PER_PROCESS@GOTPAGEOFF]
	ldr	w1, [x23]
	bl	_find_first_zero_bit
	ldr	w8, [x23]
	cmp	w0, w8
	b.hs	LBB0_8
; %bb.5:
	mov	x22, x0
	ldr	w1, [x21]
	bl	_set_bit
LBB0_6:
	str	w22, [x19]
	ldr	w1, [x19, #4]
	mov	x0, x20
	mov	x2, x22
	bl	_kfd_doorbell_id_to_offset
	mov	x8, x0
	mov	w0, #0
	str	w8, [x19, #36]
LBB0_7:
	ldp	x29, x30, [sp, #48]             ; 16-byte Folded Reload
	ldp	x20, x19, [sp, #32]             ; 16-byte Folded Reload
	ldp	x22, x21, [sp, #16]             ; 16-byte Folded Reload
	ldp	x24, x23, [sp], #64             ; 16-byte Folded Reload
	ret
LBB0_8:
Lloh11:
	adrp	x0, l_.str@PAGE
Lloh12:
	add	x0, x0, l_.str@PAGEOFF
	bl	_pr_debug
Lloh13:
	adrp	x8, _EBUSY@GOTPAGE
Lloh14:
	ldr	x8, [x8, _EBUSY@GOTPAGEOFF]
Lloh15:
	ldr	w8, [x8]
	neg	w0, w8
	b	LBB0_7
	.loh AdrpLdrGotLdr	Lloh3, Lloh4, Lloh5
	.loh AdrpLdrGotLdr	Lloh0, Lloh1, Lloh2
	.loh AdrpLdrGotLdr	Lloh6, Lloh7, Lloh8
	.loh AdrpLdrGot	Lloh9, Lloh10
	.loh AdrpLdrGotLdr	Lloh13, Lloh14, Lloh15
	.loh AdrpAdd	Lloh11, Lloh12
	.cfi_endproc
                                        ; -- End function
	.comm	_KFD_QUEUE_TYPE_SDMA,8,3        ; @KFD_QUEUE_TYPE_SDMA
	.comm	_KFD_QUEUE_TYPE_SDMA_XGMI,8,3   ; @KFD_QUEUE_TYPE_SDMA_XGMI
	.comm	_KFD_QUEUE_DOORBELL_MIRROR_OFFSET,4,2 ; @KFD_QUEUE_DOORBELL_MIRROR_OFFSET
	.comm	_KFD_MAX_NUM_OF_QUEUES_PER_PROCESS,4,2 ; @KFD_MAX_NUM_OF_QUEUES_PER_PROCESS
	.section	__TEXT,__cstring,cstring_literals
l_.str:                                 ; @.str
	.asciz	"No doorbells available"

	.comm	_EBUSY,4,2                      ; @EBUSY
	.no_dead_strip	_allocate_doorbell
.subsections_via_symbols
