// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
subq $0x30, %rsp
movq %rdi, %rbx
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movl $0xcfc, %edi            # imm = 0xCFC
callq 0x44e0
testl %eax, %eax
jne 0x7b8d
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movl $0xcf8, %edi            # imm = 0xCF8
callq 0x44e0
testl %eax, %eax
jne 0x7bdf
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 0x7b82
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 0x7b2d
andl $0xff80, %eax           # imm = 0xFF80
movl %eax, 0x8(%rbx)
pushq $0x4
popq %rbx
movl $0xcfc, %edi            # imm = 0xCFC
movq %rbx, %rsi
xorl %edx, %edx
callq 0x44e0
movl $0xcf8, %edi            # imm = 0xCF8
movq %rbx, %rsi
xorl %edx, %edx
callq 0x44e0
movb $0x1, %al
jmp 0x7b84
cmpl $0x0, 0x882c(%rip)      # 0x10360
jne 0x7b3f
cmpl $0x0, 0x8827(%rip)      # 0x10364
jle 0x7b82
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq 0x8491(%rip), %rdi      # 0xffe0
movq %rax, %rsi
callq 0x42d0
leaq 0x2fb3(%rip), %rsi      # 0xab11
movq %rax, %rdi
callq 0x42d0
movl 0x8(%rbx), %esi
andl $0xffff007f, %esi       # imm = 0xFFFF007F
movq %rax, %rdi
callq 0x41e0
pushq $0xa
popq %rsi
movq %rax, %rdi
callq 0x4370
xorl %eax, %eax
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x4160
movq %rax, %rbx
leaq 0x2f6b(%rip), %rsi      # 0xab0a
leaq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x5694
callq 0x4030
movl (%rax), %edx
movb $0x1, %bpl
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x56d0
xorl %ebp, %ebp
leaq 0x7b12(%rip), %rsi      # 0xf6e0
movq 0x83cb(%rip), %rdx      # 0xffa0
movq %rbx, %rdi
callq 0x4530
jmp 0x7c2f
pushq $0x10
popq %rdi
callq 0x4160
movq %rax, %rbx
leaq 0x2f19(%rip), %rsi      # 0xab0a
leaq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x5694
callq 0x4030
movl (%rax), %edx
movb $0x1, %bpl
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x56d0
xorl %ebp, %ebp
leaq 0x7ac0(%rip), %rsi      # 0xf6e0
movq 0x8379(%rip), %rdx      # 0xffa0
movq %rbx, %rdi
callq 0x4530
jmp 0x7c33
jmp 0x7c47
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x4150
testb %bpl, %bpl
jne 0x7c4a
jmp 0x7c52
movq %rax, %r14
movq %rbx, %rdi
callq 0x4220
movq %r14, %rdi
callq 0x4550