Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:14

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @brief PCI Library
0007  *
0008  * Defines in this file was taken from FreeBSD and auto-generated
0009  * pci_ids.h reused from RTEMS.
0010  *
0011  */
0012 
0013 /*
0014  * COPYRIGHT (c) 2009 Cobham Gaisler AB.
0015  *
0016  * Redistribution and use in source and binary forms, with or without
0017  * modification, are permitted provided that the following conditions
0018  * are met:
0019  * 1. Redistributions of source code must retain the above copyright
0020  *    notice, this list of conditions and the following disclaimer.
0021  * 2. Redistributions in binary form must reproduce the above copyright
0022  *    notice, this list of conditions and the following disclaimer in the
0023  *    documentation and/or other materials provided with the distribution.
0024  *
0025  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0026  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0027  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0028  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0029  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0030  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0031  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0032  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0033  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0034  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0035  * POSSIBILITY OF SUCH DAMAGE.
0036  */
0037 
0038 #ifndef __PCI_H__
0039 #define __PCI_H__
0040 
0041 #include <pci/pcireg.h>
0042 #include <pci/ids.h>
0043 
0044 #define PCI_INVALID_VENDORDEVICEID    0xffffffff
0045 
0046 #define PCID_CLASS(class, dev) ((class << 8) | dev)
0047 #define PCID_PCI2PCI_BRIDGE PCID_CLASS(PCIC_BRIDGE, PCIS_BRIDGE_PCI)
0048 
0049 #include <pci/access.h>
0050 
0051 #ifdef __cplusplus
0052 extern "C" {
0053 #endif
0054 
0055 /* The PCI Library have the following build time configuration options. It is
0056  * up to the BSP header file (bsp.h) to set options properly.
0057  *
0058  * BSP_PCI_BIG_ENDIAN    - Access inline routines will be for a big-endian PCI
0059  *                         bus, if not defined the routines will assume that
0060  *                         PCI is as the standard defines: little-endian.
0061  *
0062  *                         Note that drivers may be run-time configurable,
0063  *                         meaning that they may adopt to either big-endian or
0064  *                         little-endian PCI bus, the host driver or BSP may
0065  *                         detect endianness during run-time.
0066  */
0067 
0068 /* Error return values */
0069 enum {
0070     PCISTS_ERR         = -1, /* Undefined Error */
0071     PCISTS_OK          = 0,
0072     PCISTS_EINVAL      = 1, /* Bad input arguments */
0073     PCISTS_MSTABRT     = 2, /* CFG space access error (can be ignored) */
0074 };
0075 
0076 /* PCI System type can be used to determine system for drivers. Normally
0077  * the system is Host, but the peripheral configuration library also supports
0078  * being PCI peripheral not allowed to access configuration space.
0079  *
0080  * The active configuration Library set this variable.
0081  */
0082 enum pci_system_type {
0083     PCI_SYSTEM_NONE = 0,
0084     PCI_SYSTEM_HOST = 1,
0085     PCI_SYSTEM_PERIPHERAL = 2,
0086 };
0087 extern enum pci_system_type pci_system_type;
0088 
0089 /* PCI Bus Endianness. The PCI specification is little endian, however on some
0090  * embedded systems (AT697-LEON2 for example) the PCI bus is defined as big
0091  * endian (non-standard) in order to avoid byte-twisting.
0092  */
0093 enum {
0094     PCI_LITTLE_ENDIAN = 0,
0095     PCI_BIG_ENDIAN = 1,
0096 };
0097 extern int pci_endian;
0098 
0099 /* Return the number of PCI busses in the system */
0100 extern int pci_bus_count(void);
0101 
0102 /* Scan the PCI bus and print the PCI device/functions/bridges and their
0103  * current resources and size to the system console.
0104  */
0105 extern void pci_print(void);
0106 
0107 /* Print current configuration of a single PCI device by reading PCI
0108  * configuration space
0109  */
0110 extern void pci_print_dev(pci_dev_t dev);
0111 extern void pci_print_device(int bus, int slot, int function);
0112 
0113 /*** PCI Configuration Space direct access routines ***/
0114 
0115 /* Function iterates over all PCI buses/devices/functions and calls
0116  * func(PCIDEV,arg) for each present device. The iteration is stopped if
0117  * func() returns non-zero result the same result is returned. As long
0118  * as func() returns zero the function will keep on iterating, when all
0119  * devices has been processed the function return zero.
0120  *
0121  * The function iterates over all devices/functions on all buses by accessing
0122  * configuration space directly (PCI RAM data structures not used). This
0123  * function is valid to call after PCI buses have been enumrated.
0124  */
0125 extern int pci_for_each(int (*func)(pci_dev_t, void*), void *arg);
0126 
0127 /* Get PCI Configuration space BUS|SLOT|FUNC for a device matching PCI
0128  * Vendor, Device and instance number 'index'.
0129  *
0130  * Return Values
0131  * -1  pci_find_dev did not find a device matching the criterion.
0132  *  0  device was found, *pdev was updated with the device's BUS|SLOT|FUNC
0133  */
0134 extern int pci_find(uint16_t ven, uint16_t dev, int index, pci_dev_t *pdev);
0135 
0136 #ifdef __cplusplus
0137 }
0138 #endif
0139 
0140 #endif /* __PCI_H__ */