www.pudn.com > PlxSdk.rar > PciSupport.c
/*******************************************************************************
* Copyright (c) 2007 PLX Technology, Inc.
*
* PLX Technology Inc. licenses this software under specific terms and
* conditions. Use of any of the software or derviatives thereof in any
* product without a PLX Technology chip is strictly prohibited.
*
* PLX Technology, Inc. provides this software AS IS, WITHOUT ANY WARRANTY,
* EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. PLX makes no guarantee
* or representations regarding the use of, or the results of the use of,
* the software and documentation in terms of correctness, accuracy,
* reliability, currentness, or otherwise; and you rely on the software,
* documentation and results solely at your own risk.
*
* IN NO EVENT SHALL PLX BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS,
* LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES
* OF ANY KIND. IN NO EVENT SHALL PLX'S TOTAL LIABILITY EXCEED THE SUM
* PAID TO PLX FOR THE PRODUCT LICENSED HEREUNDER.
*
******************************************************************************/
/******************************************************************************
*
* File Name:
*
* PciSupport.c
*
* Description:
*
* This file contains the PCI support functions
*
* Revision History:
*
* 02-01-07 : PLX SDK v5.00
*
******************************************************************************/
#include "PciSupport.h"
/******************************************************************************
*
* Function : PlxPciRegisterRead
*
* Description: Reads a PCI register at the specified offset
*
******************************************************************************/
RETURN_CODE
PlxPciRegisterRead(
U8 bus,
U8 slot,
U8 function,
U16 offset,
U32 *pValue
)
{
int rc;
U32 RegValue;
struct pci_dev *pPciDevice;
// Offset must on a 4-byte boundary
if (offset & 0x3)
{
*pValue = (U32)-1;
return ApiInvalidOffset;
}
// Locate PCI device
pPciDevice =
pci_find_slot(
bus,
PCI_DEVFN(slot, function)
);
if (pPciDevice == NULL)
{
DebugPrintf((
"ERROR - Device at bus %02d, slot %02d does not exist\n",
bus, slot
));
*pValue = (U32)-1;
return ApiInvalidDeviceInfo;
}
rc =
pci_read_config_dword(
pPciDevice,
offset,
&RegValue
);
if (rc != 0)
{
DebugPrintf((
"ERROR - Unable to read PCI register 0x%02x\n",
offset
));
*pValue = (U32)-1;
return ApiConfigAccessFailed;
}
*pValue = RegValue;
return ApiSuccess;
}
/******************************************************************************
*
* Function : PlxPciRegisterWrite
*
* Description: Writes a value to a PCI register at the specified offset
*
******************************************************************************/
RETURN_CODE
PlxPciRegisterWrite(
U8 bus,
U8 slot,
U8 function,
U16 offset,
U32 value
)
{
int rc;
struct pci_dev *pPciDevice;
// Offset must on a 4-byte boundary
if (offset & 0x3)
{
return ApiInvalidOffset;
}
// Locate PCI device
pPciDevice =
pci_find_slot(
bus,
PCI_DEVFN(slot, function)
);
if (pPciDevice == NULL)
{
DebugPrintf((
"ERROR - Device at bus %02d, slot %02d does not exist\n",
bus, slot
));
return ApiInvalidDeviceInfo;
}
rc =
pci_write_config_dword(
pPciDevice,
offset,
value
);
if (rc != 0)
{
DebugPrintf((
"ERROR - Unable to write to PCI register 0x%02x\n",
offset
));
return ApiConfigAccessFailed;
}
return ApiSuccess;
}