⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ecos-pci-library.html

📁 ecos 文档
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!-- 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
>The eCos PCI Library</TITLE
><meta name="MSSmartTagsPreventParsing" content="TRUE">
<META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
"><LINK
REL="HOME"
TITLE="eCos Reference Manual"
HREF="ecos-ref.html"><LINK
REL="UP"
TITLE="PCI Library"
HREF="io-pci.html"><LINK
REL="PREVIOUS"
TITLE="PCI Library"
HREF="io-pci.html"><LINK
REL="NEXT"
TITLE="PCI Library reference"
HREF="pci-library-reference.html"></HEAD
><BODY
CLASS="CHAPTER"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>eCos Reference Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="io-pci.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="pci-library-reference.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="CHAPTER"
><H1
><A
NAME="ECOS-PCI-LIBRARY">Chapter 30. The eCos PCI Library</H1
><DIV
CLASS="TOC"
><DL
><DT
><B
>Table of Contents</B
></DT
><DT
><A
HREF="ecos-pci-library.html#PCI-LIBRARY"
>PCI Library</A
></DT
><DT
><A
HREF="pci-library-reference.html"
>PCI Library reference</A
></DT
></DL
></DIV
><P
>The PCI library is an optional part of eCos, and is only
	applicable to some platforms.</P
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="PCI-LIBRARY">PCI Library</H1
><P
>The eCos PCI library provides the following functionality:</P
><P
></P
><OL
TYPE="1"
><LI
><P
>Scan the PCI bus for specific devices or devices of a certain
class.</P
></LI
><LI
><P
>Read and change generic PCI information.</P
></LI
><LI
><P
>Read and change device-specific PCI information.</P
></LI
><LI
><P
>Allocate PCI memory and IO space to devices.</P
></LI
><LI
><P
>Translate a device's PCI interrupts to equivalent HAL
vectors.</P
></LI
></OL
><P
>Example code fragments are from the pci1 test (see <TT
CLASS="FILENAME"
>io/pci/&lt;release&gt;/tests/pci1.c</TT
>).</P
><P
>All of the functions described below are declared in the header
file <TT
CLASS="FILENAME"
>&lt;cyg/io/pci.h&gt;</TT
> which all
clients of the PCI library should include.</P
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN12690">PCI Overview</H2
><P
>The PCI bus supports several address spaces: memory, IO, and configuration. All PCI
devices must support mandatory configuration space registers. Some devices may also present
IO mapped and/or memory mapped resources. Before devices on the bus can be used, they must
be configured. Basically, configuration will assign PCI IO and/or memory address ranges to
each device and then enable that device. All PCI devices have a unique address in
configuration space. This address is comprised of a bus number, a device number, and a
function number. Special devices called bridges are used to connect two PCI busses together.
The PCI standard supports up to 255 busses with each bus having up to 32 devices and each
device having up to 8 functions.</P
><P
>The environment in which a platform operates will dictate if and how eCos should
configure devices on the PCI bus. If the platform acts as a host on a single PCI bus,
then devices may be configured individually from the relevant device driver. If the
platform is not the primary host, such as a PCI card plugged into a PC, configuration
of PCI devices may be left to the PC BIOS. If PCI-PCI bridges are involved, configuration
of all devices is best done all at once early in the boot process. This is because all
devices on the secondary side of a bridge must be evaluated for their IO and memory space
requirements before the bridge can be configured.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN12694">Initializing the bus</H2
><P
>The PCI bus needs to be initialized before it can be used.
This only needs to be done once - some HALs may do it as part of
the platform initialization procedure, other HALs may leave it to
the application or device drivers to do it. The following function
will do the initialization only once, so it's safe to call from
multiple drivers:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>void cyg_pci_init( void );</PRE
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN12698">Scanning for devices</H2
><P
>After the bus has been initialized, it is possible to scan
it for devices. This is done using the function:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>cyg_bool cyg_pci_find_next(  cyg_pci_device_id cur_devid, 
	                     cyg_pci_device_id *next_devid );</PRE
></TD
></TR
></TABLE
><P
>It will scan the bus for devices starting at <TT
CLASS="PARAMETER"
><I
>cur_devid</I
></TT
>. If a device is found, its devid is stored in <TT
CLASS="PARAMETER"
><I
>next_devid</I
></TT
> and the function returns <TT
CLASS="CONSTANT"
>true</TT
>.</P
><P
>The <TT
CLASS="FILENAME"
>pci1</TT
> test's outer loop looks like:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>    cyg_pci_init();
    if (cyg_pci_find_next(CYG_PCI_NULL_DEVID, &amp;devid)) {
        do {
             &lt;use devid&gt;
        } while (cyg_pci_find_next(devid, &amp;devid));
    }</PRE
></TD
></TR
></TABLE
><P
>What happens is that the bus gets initialized and a scan is
started. <TT
CLASS="LITERAL"
>CYG_PCI_NULL_DEVID</TT
> causes <TT
CLASS="FUNCTION"
>cyg_pci_find_next()</TT
> to restart its scan. If the bus does not
contain any devices, the first call to <TT
CLASS="FUNCTION"
>cyg_pci_find_next()</TT
>
will return <TT
CLASS="CONSTANT"
>false</TT
>.</P
><P
>If the call returns <TT
CLASS="CONSTANT"
>true</TT
>, a loop is entered where
the found devid is used. After devid processing has completed, the next device
on the bus is searched for; <TT
CLASS="FUNCTION"
>cyg_pci_find_next()</TT
>
continues its scan from the current devid. The loop terminates when
no more devices are found on the bus.</P
><P
>This is the generic way of scanning the bus, enumerating all
the devices on the bus. But if the application is looking for a
device of a given device class (e.g., a SCSI controller), or a specific
vendor device, these functions simplify the task a bit:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>cyg_bool cyg_pci_find_class(  cyg_uint32 dev_class,
                              cyg_pci_device_id *devid );
cyg_bool cyg_pci_find_device(  cyg_uint16 vendor, cyg_uint16 device,
                               cyg_pci_device_id *devid );</PRE
></TD
></TR
></TABLE
><P
>They work just like <TT
CLASS="FUNCTION"
>cyg_pci_find_next()</TT
>,
but only return true when the dev_class or vendor/device
qualifiers match those of a device on the bus. The devid serves
as both an input and an output operand: the scan starts at the given
device, and if a device is found devid is updated with the value
for the found device.</P
><P
>The <TT
CLASS="FILENAME"
>&lt;cyg/io/pci_cfg.h&gt;</TT
> header
file (included by <TT
CLASS="FILENAME"
>pci.h</TT
>) contains definitions for PCI 
class, vendor and device codes which can be used as arguments to the find
functions.
The list of vendor and device codes is not complete: add new codes
as necessary. If possible also register the codes at the PCI Code
List (<A
HREF="http://www.yourvote.com/pci"
TARGET="_top"
>http://www.yourvote.com/pci)</A
> which is where the eCos definitions are generated from.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN12725">Generic config information</H2
><P
>When a valid device ID (devid) is found using one of the above
functions, the associated device can be queried and controlled using
the functions:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>void cyg_pci_get_device_info (  cyg_pci_device_id devid, 
                                cyg_pci_device *dev_info );
void cyg_pci_set_device_info (  cyg_pci_device_id devid, 
                                cyg_pci_device *dev_info );</PRE
></TD
></TR
></TABLE
><P
>The <SPAN
CLASS="STRUCTNAME"
>cyg_pci_device structure</SPAN
> (defined in
<TT
CLASS="FILENAME"
>pci.h</TT
>) primarily holds information as described by the PCI
 specification <A
HREF="ecos-pci-library.html#PCI-SPEC"
>[1]</A
>.
The <TT
CLASS="FILENAME"
>pci1</TT
> test prints out some of this information:</P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>            // Get device info
            cyg_pci_get_device_info(devid, &amp;dev_info);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -