Beispiel #1
0
ViStatus _VI_FUNC viOpen          (ViSession sesn, ViRsrc name, ViAccessMode mode,
                                    ViUInt32 timeout, ViPSession vi)
{
    PLX_DEVICE_KEY DevKey;
	PLX_DEVICE_OBJECT *Device=malloc(sizeof(PLX_DEVICE_OBJECT));
	BOOLEAN IsInitOk;
	PLX_STATUS rc;

    IsInitOk = DeviceInit(&DevKey);
	if(IsInitOk)
	{
		rc = PlxPci_DeviceOpen(&DevKey, Device);
		if(rc != ApiSuccess)
			return VI_ERROR_ALLOC;
		else
        {
            *vi = (ViSession)Device;
            return VI_SUCCESS;
        }
	}
	else
	{
		return VI_ERROR_ALLOC;
	}
}
Beispiel #2
0
/*
 * Opens the PCI device located using the specified parameters
 *
 * As the specification for the DEVICE_LOCATION struct states, id, bus and
 * slot may be set to -1 to indicate that the value should not be used in the
 * search.
 */
XIA_EXPORT int XIA_API plx_open_slot(unsigned short id, byte_t bus, byte_t slot,
                                     HANDLE *h)
{
    PLX_STATUS status;

    PLX_DEVICE_KEY dev;
    PLX_DEVICE_OBJECT device_object;

    DWORD err;

    memset(&dev, PCI_FIELD_IGNORE, sizeof(PLX_DEVICE_KEY));

    dev.bus       = bus;
    dev.slot      = slot;

    /* Per the PLX SDK docs, we are not supposed to futz with the
     * members of the PLX_DEVICE_OBJECT structure, which makes sense
     * except for the assumptions they made about new instances of
     * PLX_DEVICE_OBJECT on the stack. In some build configurations, the
     * memory will be reused between subsequent calls as-is, leading to
     * the IsValidTag value being incorrectly set to "valid". We need to
     * override that here since we are promising to pass in
     * uninitialized device objects.
     */
    device_object.IsValidTag = 0;

    status = PlxPci_DeviceOpen(&dev, &device_object);

    if (status != ApiSuccess) {
        err = GetLastError();
        _plx_log_DEBUG("Error opening device (id = %hu, bus = %hu): status = %d\n"
                       "Last windows API error = %#lx\n",
                       id, (unsigned short)bus, status, err);

        _plx_print_more(status);
        return status;
    }

    status = _plx_add_slot_to_map(&device_object);

    if (status != PLX_SUCCESS) {
        _plx_log_DEBUG("Error adding device %hu/%hu/%hu to virtual map\n",
                       (unsigned short)dev.bus, (unsigned short)dev.slot,
                       dev.DeviceId);
        return status;
    }
        
    *h = (HANDLE) device_object.hDevice;

    return PLX_SUCCESS;
}
Beispiel #3
0
/******************************************************************************
 *
 * Function   :  main
 *
 * Description:  The main entry point
 *
 *****************************************************************************/
int
main(
    void
    )
{
    S16               DeviceSelected;
    PLX_STATUS        rc;
    PLX_DEVICE_KEY    DeviceKey;
    PLX_DEVICE_OBJECT Device;


    ConsoleInitialize();

    Cons_clear();

    Cons_printf(
        "\n\n"
        "\t\t    PLX Local->PCI Interrupt Sample Application\n"
        "\t\t                 January 2008\n\n"
        );


    /************************************
    *         Select Device
    ************************************/
    DeviceSelected =
        SelectDevice(
            &DeviceKey
            );

    if (DeviceSelected == -1)
    {
        ConsoleEnd();
        exit(0);
    }

    rc =
        PlxPci_DeviceOpen(
            &DeviceKey,
            &Device
            );

    if (rc != ApiSuccess)
    {
        Cons_printf("\n   ERROR: Unable to find or select a PLX device\n");
        PlxSdkErrorDisplay(rc);
        _Pause;
        ConsoleEnd();
        exit(-1);
    }

    Cons_clear();

    Cons_printf(
        "\nSelected: %04x %04x [b:%02x  s:%02x  f:%x]\n\n",
        DeviceKey.DeviceId, DeviceKey.VendorId,
        DeviceKey.bus, DeviceKey.slot, DeviceKey.function
        );

    // Verify chip is supported
    switch (DeviceKey.PlxChip)
    {
        case 0x9050:
        case 0x9030:
        case 0x9080:
        case 0x9054:
        case 0x9056:
        case 0x9656:
        case 0x8311:
            break;

        default:
            Cons_printf(
                "ERROR: Device (%04X) does not support generic Local-to-PCI interrupt\n",
                DeviceKey.PlxChip
                );
            goto _Exit_App;
    }


    /************************************
     *        Perform the DMA
     ************************************/
    InterruptTest(
        &Device
        );


    /************************************
     *        Close the Device
     ***********************************/
_Exit_App:
    PlxPci_DeviceClose(
        &Device
        );

    _Pause;

    Cons_printf("\n\n");

    ConsoleEnd();

    exit(0);
}
Beispiel #4
0
/******************************************************************************
 *
 * Function   :  main
 *
 * Description:  The main entry point
 *
 *****************************************************************************/
int
main(
    void
    )
{
    S16               DeviceSelected;
    PLX_STATUS        rc;
    PLX_DEVICE_KEY    DeviceKey;
    PLX_DEVICE_OBJECT Device;


    ConsoleInitialize();

    Cons_clear();

    Cons_printf(
        "\n\n"
        "\t\t         PLX DMA Sample Application\n\n"
        );


    /************************************
    *         Select Device
    ************************************/
    DeviceSelected =
        SelectDevice_DMA(
            &DeviceKey
            );

    if (DeviceSelected == -1)
    {
        ConsoleEnd();
        exit(0);
    }

    rc =
        PlxPci_DeviceOpen(
            &DeviceKey,
            &Device
            );

    if (rc != ApiSuccess)
    {
        Cons_printf("\n   ERROR: Unable to find or select a PLX device\n");
        PlxSdkErrorDisplay(rc);
        _Pause;
        ConsoleEnd();
        exit(-1);
    }

    Cons_clear();

    Cons_printf(
        "\nSelected: %04x %04x [b:%02x  s:%02x  f:%x]\n\n",
        DeviceKey.DeviceId, DeviceKey.VendorId,
        DeviceKey.bus, DeviceKey.slot, DeviceKey.function
        );


    /************************************
     *        Perform the DMA
     ************************************/
    if (((DeviceKey.PlxChip & 0xF000) == 0x8000) &&
         (DeviceKey.PlxChip != 0x8311))
    {
        PerformDma_8000( &Device );
    }
    else
    {
        Cons_printf(
            "ERROR: DMA not supported by the selected device (%04X)\n",
            DeviceKey.PlxChip
            );
        goto _Exit_App;
    }


    /************************************
     *        Close the Device
     ***********************************/
_Exit_App:
    PlxPci_DeviceClose(
        &Device
        );

    _Pause;

    Cons_printf("\n\n");

    ConsoleEnd();

    exit(0);
}
Beispiel #5
0
/*********************************************************************
 *
 * Function   : SelectDevice_DMA
 *
 * Description: Asks the user which PLX DMA device to select
 *
 * Returns    : Total devices found
 *              -1,  if user cancelled the selection
 *
 ********************************************************************/
S16
SelectDevice_DMA(
    PLX_DEVICE_KEY *pKey
    )
{
    S32               i;
    S32               NumDevices;
    BOOLEAN           bAddDevice;
    PLX_STATUS        status;
    PLX_DEVICE_KEY    DevKey;
    PLX_DEVICE_KEY    DevKey_DMA[MAX_DEVICES_TO_LIST];
    PLX_DRIVER_PROP   DriverProp;
    PLX_DEVICE_OBJECT Device;


    Cons_printf("\n");

    i          = 0;
    NumDevices = 0;

    do
    {
        // Setup for next device
        memset(&DevKey, PCI_FIELD_IGNORE, sizeof(PLX_DEVICE_KEY));

        // Check if device exists
        status =
            PlxPci_DeviceFind(
                &DevKey,
                (U16)i
                );

        if (status == ApiSuccess)
        {
            // Default to add device
            bAddDevice = TRUE;

            if (bAddDevice)
            {
                // Verify supported chip type
                switch (DevKey.PlxChip)
                {
                    default:
                        if ((DevKey.PlxChip & 0xF000) == 0x8000)
                        {
                            // DMA is always function 1 or higher
                            if (DevKey.function == 0)
                                bAddDevice = FALSE;
                        }
                        else
                        {
                            bAddDevice = FALSE;
                        }
                        break;
                }
            }

            if (bAddDevice)
            {
                // Open device to get its properties
                PlxPci_DeviceOpen(
                    &DevKey,
                    &Device
                    );
            }

            // Verify driver used is PnP and not Service driver
            if (bAddDevice)
            {
                PlxPci_DriverProperties(
                    &Device,
                    &DriverProp
                    );

                if (DriverProp.bIsServiceDriver)
                {
                    bAddDevice = FALSE;
                }
            }

            // Close device
            PlxPci_DeviceClose(
                &Device
                );

            if (bAddDevice)
            {
                // Copy device key info
                DevKey_DMA[NumDevices] = DevKey;

                Cons_printf(
                    "\t\t  %2d. %04x [b:%02x s:%02x f:%x]\n",
                    (NumDevices + 1), DevKey.PlxChip,
                    DevKey.bus, DevKey.slot, DevKey.function
                    );

                // Increment device count
                NumDevices++;
            }
        }

        // Go to next devices
        i++;
    }
    while ((status == ApiSuccess) && (NumDevices < MAX_DEVICES_TO_LIST));

    if (NumDevices == 0)
        return 0;

    Cons_printf(
        "\t\t   0. Cancel\n\n"
        );

    do
    {
        Cons_printf("\t  Device Selection --> ");
        Cons_scanf("%d", &i);
    }
    while (i > NumDevices);

    if (i == 0)
        return -1;

    // Return selected device information
    *pKey = DevKey_DMA[i - 1];

    return (S16)NumDevices;
}
Beispiel #6
0
/******************************************************************************
 *
 * Function   :  Do_DMA_Test
 *
 * Description:  The main entry point
 *
 *****************************************************************************/
int
Do_DMA_Test(
    U32                NTSrcAddr,
    U32                NTDestAddr,
    U32                NTSize,
    PLX_DEVICE_OBJECT *pNTDevice
    )
{
    S8                DeviceSelected;
    PLX_STATUS        rc;
    PLX_DEVICE_KEY    DeviceKey;
    PLX_DEVICE_OBJECT Device;
    U16               LutIndex = 0xffff;
    U16               ReqId;
    U32               flags = 0;



    /************************************
     *         Select Device
     ***********************************/
    DeviceSelected =
        SelectDevice_DMA(
            &DeviceKey
            );

    if (DeviceSelected == -1)
    {
        ConsoleEnd();
        exit(0);
    }

    rc =
        PlxPci_DeviceOpen(
            &DeviceKey,
            &Device
            );

    if (rc != ApiSuccess)
    {
        Cons_printf("\n   ERROR: Unable to find or select a PLX device\n");
        PlxSdkErrorDisplay(rc);
        _Pause;
        ConsoleEnd();
        exit(-1);
    }

    Cons_printf(
        "\nSelected: %04x %04x [b:%02x  s:%02x  f:%x]\n\n",
        DeviceKey.DeviceId, DeviceKey.VendorId,
        DeviceKey.bus, DeviceKey.slot, DeviceKey.function
        );

    // Must add the DMA device ReqID to the NT LUT
    ReqId = ((U16)DeviceKey.bus << 8) | (DeviceKey.slot << 3) | (DeviceKey.function & 0x03);

    PlxPci_Nt_LutAdd(
        pNTDevice,
        &LutIndex,
        ReqId,
        flags
        );

    /************************************
     *        Perform the DMA
     ************************************/
    if (((DeviceKey.PlxChip & 0xF000) == 0x8000) &&
         (DeviceKey.PlxChip != 0x8311))
    {
        PerformDma_8000( &Device, NTSrcAddr, NTDestAddr, NTSize );
    }
    else
    {
        Cons_printf(
            "ERROR: DMA not supported by the selected device (%04X)\n",
            DeviceKey.PlxChip
            );
        goto _Exit_App;
    }


    /************************************
     *        Close the Device
     ***********************************/
_Exit_App:
    PlxPci_DeviceClose(
        &Device
        );

    _Pause;

    Cons_printf("\n\n");

    return 0;
}