// File: /workspace/github_cpp_makefile_star2_O3/merelin[P]mediasmartserverd/src/led_control_sch5127_base.h
// Function: LedControlSCH5127Base::initPciLpc_()
bool initPciLpc_( ) {
		// The LPC bridge function of the ICH9 resides in PCI Device 31:Function 0
		enum {
			CONF_VENDOR_ID	= 0x8000F800,   ///< Vendor Identification (enable, bus 0, device 31, function 0, register 0x00)
			CONF_GPIOBASE	= 0x8000F848,   ///< GPIO Base address     (enable, bus 0, device 31, function 0, register 0x48)
		};
		
		// PCI configuration space
		const unsigned int PCI_CONFIG_ADDRESS	= 0x0CF8;
		const unsigned int PCI_CONFIG_DATA		= 0x0CFC;
		
		//
		if ( ioperm(PCI_CONFIG_DATA,    4, 1) ) throw ErrnoException("ioperm");
		if ( ioperm(PCI_CONFIG_ADDRESS, 4, 1) ) throw ErrnoException("ioperm");
		
		// retrieve vendor and device identification
		outl( CONF_VENDOR_ID, PCI_CONFIG_ADDRESS );
		const unsigned int did_vid = inl( PCI_CONFIG_DATA );
		if ( !chkPciDeviceVendorId_(did_vid) ) return false;
		
		// retrieve GPIO Base Address
		outl( CONF_GPIOBASE, PCI_CONFIG_ADDRESS );
		io_lpc_gpiobase_ = inl( PCI_CONFIG_DATA );
		
		// sanity check the address
		// (only bits 15:6 provide an address while the rest are reserved as always being zero)
		if ( 0x1 != (io_lpc_gpiobase_ & 0xFFFF007F) ) {
			if ( debug || verbose > 0 ) std::cerr << Desc() << ": Expected 0x1 but got " << (io_lpc_gpiobase_ & 0xFFFF007F) << '\n';
			return false;
		}
		io_lpc_gpiobase_ &= ~0x1; // remove hardwired 1 which indicates I/O space
		
		// finished with these ports
		ioperm( PCI_CONFIG_DATA,    4, 0 );
		ioperm( PCI_CONFIG_ADDRESS, 4, 0 );
		
		return true;
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movl $0xcfc, %edi            # imm = 0xCFC
movl $0x4, %esi
movl $0x1, %edx
callq 0x44b0
testl %eax, %eax
jne 0x881e
movl $0xcf8, %edi            # imm = 0xCF8
movl $0x4, %esi
movl $0x1, %edx
callq 0x44b0
testl %eax, %eax
jne 0x887d
movl $0x8000f800, %eax       # imm = 0x8000F800
movw $0xcf8, %dx             # imm = 0xCF8
outl %eax, %dx
movw $0xcfc, %dx             # imm = 0xCFC
inl %dx, %eax
movq (%rbx), %rcx
movq %rbx, %rdi
movl %eax, %esi
callq *0x48(%rcx)
testb %al, %al
je 0x8811
movl $0x8000f848, %eax       # imm = 0x8000F848
movw $0xcf8, %dx             # imm = 0xCF8
outl %eax, %dx
movw $0xcfc, %dx             # imm = 0xCFC
inl %dx, %eax
movl %eax, 0x8(%rbx)
movl %eax, %ecx
andl $0xffff007f, %ecx       # imm = 0xFFFF007F
cmpl $0x1, %ecx
jne 0x876f
andl $0xff80, %eax           # imm = 0xFF80
movl %eax, 0x8(%rbx)
movl $0xcfc, %edi            # imm = 0xCFC
movl $0x4, %esi
xorl %edx, %edx
callq 0x44b0
movl $0xcf8, %edi            # imm = 0xCF8
movl $0x4, %esi
xorl %edx, %edx
callq 0x44b0
movb $0x1, %al
jmp 0x8813
cmpl $0x0, 0x7bda(%rip)      # 0x10350
jne 0x8785
cmpl $0x0, 0x7bd5(%rip)      # 0x10354
jle 0x8811
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
testq %rax, %rax
je 0x87b2
movq %rax, %r14
movq %rax, %rdi
callq 0x4130
movq 0x783b(%rip), %rdi      # 0xffe0
movq %r14, %rsi
movq %rax, %rdx
callq 0x4310
jmp 0x87d0
movq 0x7827(%rip), %rax      # 0xffe0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
leaq (%rax,%rcx), %rdi
movl 0x20(%rax,%rcx), %esi
orl $0x1, %esi
callq 0x4510
movq 0x7809(%rip), %r14      # 0xffe0
leaq 0x334b(%rip), %rsi      # 0xbb29
movl $0x17, %edx
movq %r14, %rdi
callq 0x4310
movl 0x8(%rbx), %esi
andl $0xffff007f, %esi       # imm = 0xFFFF007F
movq %r14, %rdi
callq 0x41a0
leaq 0x8(%rsp), %rsi
movb $0xa, (%rsi)
movl $0x1, %edx
movq %rax, %rdi
callq 0x4310
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x4140
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x32e7(%rip), %rsi      # 0xbb22
leaq 0x32e6(%rip), %rdx      # 0xbb28
leaq 0x8(%rsp), %rdi
callq 0x5e90
callq 0x4030
movl (%rax), %edx
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x5be6
xorl %ebp, %ebp
leaq 0x6f14(%rip), %rsi      # 0xf780
movq 0x772d(%rip), %rdx      # 0xffa0
movq %rbx, %rdi
callq 0x4520
jmp 0x88da
movl $0x10, %edi
callq 0x4140
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x3288(%rip), %rsi      # 0xbb22
leaq 0x3287(%rip), %rdx      # 0xbb28
leaq 0x8(%rsp), %rdi
callq 0x5e90
callq 0x4030
movl (%rax), %edx
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x5be6
xorl %ebp, %ebp
leaq 0x6eb5(%rip), %rsi      # 0xf780
movq 0x76ce(%rip), %rdx      # 0xffa0
movq %rbx, %rdi
callq 0x4520
jmp 0x88de
jmp 0x88ff
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x88f8
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42c0
testb %bpl, %bpl
jne 0x8902
jmp 0x890a
movq %rax, %r14
movq %rbx, %rdi
callq 0x41e0
movq %r14, %rdi
callq 0x4550