// File: 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
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x80(%rbp)
movl $0xcf8, -0x14(%rbp)     # imm = 0xCF8
movl $0xcfc, -0x18(%rbp)     # imm = 0xCFC
movl $0xcfc, %edi            # imm = 0xCFC
movl $0x4, %esi
movl $0x1, %edx
callq 0x5620
cmpl $0x0, %eax
je 0xc7e1
movb $0x1, -0x4d(%rbp)
movl $0x10, %edi
callq 0x51b0
movq %rax, -0x90(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x88(%rbp)
callq 0x56c0
movq -0x88(%rbp), %rdx
leaq 0x6491(%rip), %rsi      # 0x12be6
leaq -0x38(%rbp), %rdi
callq 0x7600
jmp 0xc760
callq 0x5030
movq -0x90(%rbp), %rdi
movl (%rax), %edx
leaq -0x38(%rbp), %rsi
callq 0x76b0
jmp 0xc779
movq -0x90(%rbp), %rdi
movb $0x0, -0x4d(%rbp)
leaq 0xae75(%rip), %rsi      # 0x17600
leaq -0x5012(%rip), %rdx     # 0x7780
callq 0x5680
jmp 0xc9d3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xc7bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x5230
leaq -0x39(%rbp), %rdi
callq 0x53f0
testb $0x1, -0x4d(%rbp)
jne 0xc7d0
jmp 0xc7dc
movq -0x90(%rbp), %rdi
callq 0x52a0
jmp 0xc9ca
movl $0xcf8, %edi            # imm = 0xCF8
movl $0x4, %esi
movl $0x1, %edx
callq 0x5620
cmpl $0x0, %eax
je 0xc8bd
movb $0x1, -0x72(%rbp)
movl $0x10, %edi
callq 0x51b0
movq %rax, -0xa0(%rbp)
leaq -0x71(%rbp), %rdi
movq %rdi, -0x98(%rbp)
callq 0x56c0
movq -0x98(%rbp), %rdx
leaq 0x63b5(%rip), %rsi      # 0x12be6
leaq -0x70(%rbp), %rdi
callq 0x7600
jmp 0xc83c
callq 0x5030
movq -0xa0(%rbp), %rdi
movl (%rax), %edx
leaq -0x70(%rbp), %rsi
callq 0x76b0
jmp 0xc855
movq -0xa0(%rbp), %rdi
movb $0x0, -0x72(%rbp)
leaq 0xad99(%rip), %rsi      # 0x17600
leaq -0x50ee(%rip), %rdx     # 0x7780
callq 0x5680
jmp 0xc9d3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xc89b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x5230
leaq -0x71(%rbp), %rdi
callq 0x53f0
testb $0x1, -0x72(%rbp)
jne 0xc8ac
jmp 0xc8b8
movq -0xa0(%rbp), %rdi
callq 0x52a0
jmp 0xc9ca
movl $0x8000f800, %edi       # imm = 0x8000F800
movl $0xcf8, %esi            # imm = 0xCF8
callq 0xb070
movl $0xcfc, %edi            # imm = 0xCFC
callq 0xb090
movq -0x80(%rbp), %rdi
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %esi
movq (%rdi), %rax
callq *0x48(%rax)
testb $0x1, %al
jne 0xc8f3
movb $0x0, -0x1(%rbp)
jmp 0xc9bc
movl $0x8000f848, %edi       # imm = 0x8000F848
movl $0xcf8, %esi            # imm = 0xCF8
callq 0xb070
movl $0xcfc, %edi            # imm = 0xCFC
callq 0xb090
movl %eax, %ecx
movq -0x80(%rbp), %rax
movl %ecx, 0x8(%rax)
movl 0x8(%rax), %ecx
andl $0xffff007f, %ecx       # imm = 0xFFFF007F
movl $0x1, %eax
cmpl %ecx, %eax
je 0xc989
cmpl $0x0, 0xbaea(%rip)      # 0x18418
jne 0xc939
cmpl $0x0, 0xbae5(%rip)      # 0x1841c
jle 0xc983
movq -0x80(%rbp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movq %rax, %rsi
movq 0xb693(%rip), %rdi      # 0x17fe0
callq 0x5380
movq %rax, %rdi
leaq 0x6291(%rip), %rsi      # 0x12bed
callq 0x5380
movq %rax, %rdi
movq -0x80(%rbp), %rax
movl 0x8(%rax), %esi
andl $0xffff007f, %esi       # imm = 0xFFFF007F
callq 0x5530
movq %rax, %rdi
movl $0xa, %esi
callq 0x5470
movb $0x0, -0x1(%rbp)
jmp 0xc9bc
movq -0x80(%rbp), %rax
movl 0x8(%rax), %ecx
andl $-0x2, %ecx
movl %ecx, 0x8(%rax)
movl $0xcfc, %edi            # imm = 0xCFC
movl $0x4, %esi
xorl %edx, %edx
callq 0x5620
movl $0xcf8, %edi            # imm = 0xCF8
movl $0x4, %esi
xorl %edx, %edx
callq 0x5620
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xa0, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x56b0
nopw %cs:(%rax,%rax)
nopl (%rax)