Blame IbAccess/Common/Public/ipci.c

Packit Service 3470d1
/* BEGIN_ICS_COPYRIGHT6 ****************************************
Packit Service 3470d1
Packit Service 3470d1
Copyright (c) 2015, Intel Corporation
Packit Service 3470d1
Packit Service 3470d1
Redistribution and use in source and binary forms, with or without
Packit Service 3470d1
modification, are permitted provided that the following conditions are met:
Packit Service 3470d1
Packit Service 3470d1
    * Redistributions of source code must retain the above copyright notice,
Packit Service 3470d1
      this list of conditions and the following disclaimer.
Packit Service 3470d1
    * Redistributions in binary form must reproduce the above copyright
Packit Service 3470d1
      notice, this list of conditions and the following disclaimer in the
Packit Service 3470d1
     documentation and/or other materials provided with the distribution.
Packit Service 3470d1
    * Neither the name of Intel Corporation nor the names of its contributors
Packit Service 3470d1
      may be used to endorse or promote products derived from this software
Packit Service 3470d1
      without specific prior written permission.
Packit Service 3470d1
Packit Service 3470d1
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Packit Service 3470d1
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit Service 3470d1
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Packit Service 3470d1
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
Packit Service 3470d1
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit Service 3470d1
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Packit Service 3470d1
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Packit Service 3470d1
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Packit Service 3470d1
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit Service 3470d1
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit Service 3470d1
Packit Service 3470d1
** END_ICS_COPYRIGHT6   ****************************************/
Packit Service 3470d1
Packit Service 3470d1
#include "ipci.h"
Packit Service 3470d1
Packit Service 3470d1
uint64 PciGetMemoryPciPhysAddr(IN PCI_DEVICE *pDev, IN uint8 barNumber)
Packit Service 3470d1
{
Packit Service 3470d1
	uint32 addr_l;
Packit Service 3470d1
	uint32 addr_h = 0;
Packit Service 3470d1
Packit Service 3470d1
	if (! PciReadConfig(pDev, 
Packit Service 3470d1
			offsetof(IBA_PCI_COMMON_CONFIG,u.type0.BaseAddresses[barNumber]),
Packit Service 3470d1
			4, &addr_l))
Packit Service 3470d1
	{
Packit Service 3470d1
		return 0;
Packit Service 3470d1
	}
Packit Service 3470d1
	if ((addr_l & IBA_PCI_BAR_CNTL_TYPE_MASK) == IBA_PCI_BAR_CNTL_TYPE_64BIT)
Packit Service 3470d1
	{
Packit Service 3470d1
		// 64 bit BAR, get high bits
Packit Service 3470d1
		if (! PciReadConfig(pDev, 
Packit Service 3470d1
				offsetof(IBA_PCI_COMMON_CONFIG,u.type0.BaseAddresses[barNumber+1]),
Packit Service 3470d1
				4, &addr_h))
Packit Service 3470d1
		{
Packit Service 3470d1
			return 0;
Packit Service 3470d1
		}
Packit Service 3470d1
	}
Packit Service 3470d1
	return (addr_l & ~IBA_PCI_BAR_CNTL_MASK) | ((uint64)addr_h << 32);
Packit Service 3470d1
}