📄 pci-library-reference.html
字号:
<!-- Copyright (C) 2003 Red Hat, Inc. --><!-- This material may be distributed only subject to the terms --><!-- and conditions set forth in the Open Publication License, v1.0 --><!-- or later (the latest version is presently available at --><!-- http://www.opencontent.org/openpub/). --><!-- Distribution of the work or derivative of the work in any --><!-- standard (paper) book form is prohibited unless prior --><!-- permission is obtained from the copyright holder. --><HTML><HEAD><TITLE>PCI Library reference</TITLE><meta name="MSSmartTagsPreventParsing" content="TRUE"><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+"><LINKREL="HOME"TITLE="eCos Reference Manual"HREF="ecos-ref.html"><LINKREL="UP"TITLE="The eCos PCI Library"HREF="ecos-pci-library.html"><LINKREL="PREVIOUS"TITLE="The eCos PCI Library"HREF="ecos-pci-library.html"><LINKREL="NEXT"TITLE="eCos POSIX compatibility layer"HREF="posix-compatibility.html"></HEAD><BODYCLASS="SECT1"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">eCos Reference Manual</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="ecos-pci-library.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 30. The eCos PCI Library</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="posix-compatibility.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="PCI-LIBRARY-REFERENCE">PCI Library reference</H1><P>This document defines the PCI Support Library for eCos.</P><P>The PCI support library provides a set of routines for accessingthe PCI bus configuration space in a portable manner. This is providedby two APIs. The high level API is used by device drivers, or othercode, to access the PCI configuration space portably. The low levelAPI is used by the PCI library itself to access the hardware ina platform-specific manner, and may also be used by device driversto access the PCI configuration space directly.</P><P>Underlying the low-level API is HAL support for the basicconfiguration space operations. These should not generally be usedby any code other than the PCI library, and are present in the HALto allow low level initialization of the PCI bus and devices totake place if necessary.</P><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="AEN12801">PCI Library API</H2><P>The PCI library provides the following routines and typesfor accessing the PCI configuration space.</P><P>The API for the PCI library is found in the header file<TTCLASS="FILENAME"><cyg/io/pci.h></TT>.</P></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="AEN12806">Definitions</H2><P>The header file contains definitions for the common configurationstructure offsets and specimen values for device, vendor and classcode.</P></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="AEN12809">Types and data structures</H2><P>The following types are defined:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">typedef CYG_WORD32 cyg_pci_device_id;</PRE></TD></TR></TABLE><P>This is comprised of the bus number, device number and functionalunit numbers packed into a single word. The macro <TTCLASS="FUNCTION">CYG_PCI_DEV_MAKE_ID()</TT>, in conjunction with the <TTCLASS="FUNCTION">CYG_PCI_DEV_MAKE_DEVFN()</TT>macro, may be used to construct a device id from the bus, device and functionalunit numbers. Similarly the macros <TTCLASS="FUNCTION">CYG_PCI_DEV_GET_BUS()</TT>,<TTCLASS="FUNCTION">CYG_PCI_DEV_GET_DEVFN()</TT>,<TTCLASS="FUNCTION">CYG_PCI_DEV_GET_DEV()</TT>, and<TTCLASS="FUNCTION">CYG_PCI_DEV_GET_FN()</TT> may be used to extract theconstituent parts of a device id. It should not be necessary to use thesemacros under normal circumstances. The following code fragment demonstrateshow these macros may be used:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING"> // Create a packed representation of device 1, function 0 cyg_uint8 devfn = CYG_PCI_DEV_MAKE_DEVFN(1,0); // Create a packed devid for that device on bus 2 cyg_pci_device_id devid = CYG_PCI_DEV_MAKE_ID(2, devfn); diag_printf("bus %d, dev %d, func %d\n", CYG_PCI_DEV_GET_BUS(devid), CYG_PCI_DEV_GET_DEV(CYG_PCI_DEV_GET_DEVFN(devid)), CYG_PCI_DEV_GET_FN(CYG_PCI_DEV_GET_DEVFN(devid));</PRE></TD></TR></TABLE><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">typedef struct cyg_pci_device;</PRE></TD></TR></TABLE><P>This structure is used to contain data read from a PCI device'sconfiguration header by <TTCLASS="FUNCTION">cyg_pci_get_device_info()</TT>.It is also used to record the resource allocations made to the device.</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">typedef CYG_WORD64 CYG_PCI_ADDRESS64;typedef CYG_WORD32 CYG_PCI_ADDRESS32;</PRE></TD></TR></TABLE><P>Pointers in the PCI address space are 32 bit (IO space) or32/64 bit (memory space). In most platform and device configurationsall of PCI memory will be linearly addressable using only 32 bitpointers as read from <TTCLASS="VARNAME">base_map[]</TT>.</P><P>The 64 bit type is used to allow handling 64 bit devices inthe future, should it be necessary, without changing the library'sAPI.</P></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="AEN12828">Functions</H2><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">void cyg_pci_init(void);</PRE></TD></TR></TABLE><P>Initialize the PCI library and establish contact with thehardware. This function is idempotent and can be called either byall drivers in the system, or just from an application initializationfunction.</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">cyg_bool cyg_pci_find_device( cyg_uint16 vendor, cyg_uint16 device, cyg_pci_device_id *devid );</PRE></TD></TR></TABLE><P>Searches the PCI bus configuration space for a device withthe given <TTCLASS="PARAMETER"><I>vendor</I></TT> and <TTCLASS="PARAMETER"><I>device</I></TT>ids. The search starts at the device pointed to by <TTCLASS="PARAMETER"><I>devid</I></TT>,or at the first slot if it contains <TTCLASS="LITERAL">CYG_PCI_NULL_DEVID</TT>.<TTCLASS="PARAMETER"><I>*devid</I></TT> will be updated with the ID of the next devicefound. Returns <TTCLASS="CONSTANT">true</TT> if one is found and <TTCLASS="CONSTANT">false</TT> if not.</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">cyg_bool cyg_pci_find_class( cyg_uint32 dev_class, cyg_pci_device_id *devid );</PRE></TD></TR></TABLE><P>Searches the PCI bus configuration space for a device withthe given <TTCLASS="PARAMETER"><I>dev_class</I></TT> class code. The search starts at thedevice pointed to by <TTCLASS="PARAMETER"><I>devid</I></TT>, or at the first slot if itcontains <TTCLASS="LITERAL">CYG_PCI_NULL_DEVID</TT>.</P><P><TTCLASS="PARAMETER"><I>*devid</I></TT> will be updated with the ID of the nextdevice found. Returns <TTCLASS="CONSTANT">true</TT> if one is found and<TTCLASS="CONSTANT">false</TT> if not.</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">cyg_bool cyg_pci_find_next( cyg_pci_device_id cur_devid, cyg_pci_device_id *next_devid );</PRE></TD></TR></TABLE><P>Searches the PCI configuration space for the next valid deviceafter <TTCLASS="PARAMETER"><I>cur_devid</I></TT>. If <TTCLASS="PARAMETER"><I>cur_devid</I></TT>is given the value <TTCLASS="LITERAL">CYG_PCI_NULL_DEVID</TT>, then the search startsat the first slot. It is permitted for <TTCLASS="PARAMETER"><I>next_devid</I></TT> topoint to <TTCLASS="PARAMETER"><I>cur_devid</I></TT>. Returns <TTCLASS="CONSTANT">true</TT>if another device is found and <TTCLASS="CONSTANT">false</TT> if not.</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">cyg_bool cyg_pci_find_matching( cyg_pci_match_func *matchp, void * match_callback_data, cyg_pci_device_id *devid );</PRE></TD></TR></TABLE><P>Searches the PCI bus configuration space for a device whose propertiesmatch those required by the caller supplied <TTCLASS="PARAMETER"><I>cyg_pci_match_func</I></TT>.The search starts at the device pointed to by <TTCLASS="PARAMETER"><I>devid</I></TT>, orat the first slot if it contains <TTCLASS="CONSTANT">CYG_PCI_NULL_DEVID</TT>. The<TTCLASS="PARAMETER"><I>devid</I></TT> will be updated with the ID of the next device found.This function returns <TTCLASS="CONSTANT">true</TT> if a matching device is foundand <TTCLASS="CONSTANT">false</TT> if not.</P><P>The match_func has a type declared as:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">typedef cyg_bool (cyg_pci_match_func)( cyg_uint16 vendor, cyg_uint16 device, cyg_uint32 class, void * user_data);</PRE></TD></TR></TABLE><P>The <TTCLASS="PARAMETER"><I>vendor</I></TT>, <TTCLASS="PARAMETER"><I>device</I></TT>, and<TTCLASS="PARAMETER"><I>class</I></TT> are from the device configuration space. The<TTCLASS="PARAMETER"><I>user_data</I></TT> is the callback data passed to <TTCLASS="FUNCTION">cyg_pci_find_matching</TT>.</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">void cyg_pci_get_device_info ( cyg_pci_device_id devid, cyg_pci_device *dev_info );</PRE></TD></TR></TABLE><P>This function gets the PCI configuration information for thedevice indicated in <TTCLASS="PARAMETER"><I>devid</I></TT>. The common fields of the<SPANCLASS="STRUCTNAME">cyg_pci_device</SPAN> structure, and the appropriate fieldsof the relevant header union member are filled in from the device'sconfiguration space.If the device has not been enabled, then this function will also fetchthe size and type information from the base address registers andplace it in the <TTCLASS="VARNAME">base_size[]</TT> array.</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">void cyg_pci_set_device_info ( cyg_pci_device_id devid, cyg_pci_device *dev_info );</PRE></TD></TR></TABLE><P>This function sets the PCI configuration information for thedevice indicated in <TTCLASS="PARAMETER"><I>devid</I></TT>. Only the configuration spaceregisters that are writable are actually written. Once all the fields havebeen written, the device info will be read back into <TTCLASS="PARAMETER"><I>*dev_info</I></TT>, so that it reflects the true state of the hardware.</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">void cyg_pci_read_config_uint8( cyg_pci_device_id devid, cyg_uint8 offset, cyg_uint8 *val );void cyg_pci_read_config_uint16( cyg_pci_device_id devid, cyg_uint8 offset, cyg_uint16 *val );void cyg_pci_read_config_uint32( cyg_pci_device_id devid, cyg_uint8 offset, cyg_uint32 *val );</PRE></TD></TR></TABLE><P>These functions read registers of the appropriate size fromthe configuration space of the given device. They should mainly
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -