// File: /workspace/github_cpp_makefile_star2_O1/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 0x8844
movl $0xcf8, %edi            # imm = 0xCF8
movl $0x4, %esi
movl $0x1, %edx
callq 0x44b0
testl %eax, %eax
jne 0x88a3
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 0x8837
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 0x8795
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 0x8839
cmpl $0x0, 0x7bb4(%rip)      # 0x10350
jne 0x87ab
cmpl $0x0, 0x7baf(%rip)      # 0x10354
jle 0x8837
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
testq %rax, %rax
je 0x87d8
movq %rax, %r14
movq %rax, %rdi
callq 0x4130
movq 0x7815(%rip), %rdi      # 0xffe0
movq %r14, %rsi
movq %rax, %rdx
callq 0x4310
jmp 0x87f6
movq 0x7801(%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 0x77e3(%rip), %r14      # 0xffe0
leaq 0x3325(%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 0x32c1(%rip), %rsi      # 0xbb22
leaq 0x32c0(%rip), %rdx      # 0xbb28
leaq 0x8(%rsp), %rdi
callq 0x5e88
callq 0x4030
movl (%rax), %edx
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x5be8
xorl %ebp, %ebp
leaq 0x6e5e(%rip), %rsi      # 0xf6f0
movq 0x7707(%rip), %rdx      # 0xffa0
movq %rbx, %rdi
callq 0x4520
jmp 0x8900
movl $0x10, %edi
callq 0x4140
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x3262(%rip), %rsi      # 0xbb22
leaq 0x3261(%rip), %rdx      # 0xbb28
leaq 0x8(%rsp), %rdi
callq 0x5e88
callq 0x4030
movl (%rax), %edx
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x5be8
xorl %ebp, %ebp
leaq 0x6dff(%rip), %rsi      # 0xf6f0
movq 0x76a8(%rip), %rdx      # 0xffa0
movq %rbx, %rdi
callq 0x4520
jmp 0x8904
jmp 0x8920
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x8926
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42c0
jmp 0x8926
movq %rax, %r14
movb $0x1, %bpl
testb %bpl, %bpl
je 0x8933
movq %rbx, %rdi
callq 0x41e0
movq %r14, %rdi
callq 0x4550
nop