Specific config information, Allocating memory – Comtrol eCos User Manual

Page 443

Advertising
background image

Chapter 30. The eCos PCI Library

The cyg_pci_device structure (defined in

pci.h

) primarily holds information as described by the PCI specification

[1]

. The

pci1

test prints out some of this information:

// Get device info

cyg_pci_get_device_info(devid, &dev_info);

diag_printf("\n Command

0x%04x, Status 0x%04x\n",

dev_info.command, dev_info.status);

The command register can also be written to, controlling (among other things) whether the device responds to IO
and memory access from the bus.

Specific config information

The above functions only allow access to generic PCI config registers. A device can have extra config registers not
specified by the PCI specification. These can be accessed with these functions:

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);

void cyg_pci_write_config_uint8(

cyg_pci_device_id devid,

cyg_uint8 offset, cyg_uint8 val);

void cyg_pci_write_config_uint16(

cyg_pci_device_id devid,

cyg_uint8 offset, cyg_uint16 val);

void cyg_pci_write_config_uint32(

cyg_pci_device_id devid,

cyg_uint8 offset, cyg_uint32 val);

The write functions should only be used for device-specific config registers since using them on generic registers
may invalidate the contents of a previously fetched cyg_pci_device structure.

Allocating memory

A PCI device ignores all IO and memory access from the PCI bus until it has been activated. Activation cannot
happen until after device configuration. Configuration means telling the device where it should map its IO and
memory resources. This is done with one of the following functions::

cyg_bool cyg_pci_configure_device( cyg_pci_device *dev_info );

cyg_bool cyg_pci_configure_bus( cyg_uint8 bus, cyg_uint8 *next_bus );

The

cyg_pci_configure_device

handles all IO and memory regions that need configuration on non-bridge

devices. On platforms with multiple busses connected by bridges, the

cyg_pci_configure_bus

function

should be used. It will recursively configure all devices on the given

bus

and all subordinate busses.

cyg_pci_configure_bus

will use

cyg_pci_configure_device

to configure individual non-bridge devices.

Each region is represented in the PCI device’s config space by BARs (Base Address Registers) and is handled
individually according to type using these functions:

cyg_bool cyg_pci_allocate_memory(

cyg_pci_device *dev_info,

cyg_uint32 bar,

CYG_PCI_ADDRESS64 *base );

339

Advertising