PCI Bus/Device Support
[Linux DDE Common]

This module emulates the PCI subsystem inside the Linux kernel. More...

Exploration of bus/attached devices and drivers

struct pci_driver * pci_dev_driver (const struct pci_dev *dev)
 Get PCI driver of given device.
int pci_register_driver (struct pci_driver *drv)
 Register PCI driver.
void pci_unregister_driver (struct pci_driver *drv)
 Unregister PCI driver.
struct pci_dev * pci_find_device (unsigned int vendor, unsigned int device, const struct pci_dev *from)
 Find PCI Device on vendor and device IDs.
struct pci_dev * pci_find_subsys (unsigned int vendor, unsigned int device, unsigned int ss_vendor, unsigned int ss_device, const struct pci_dev *from)
 Find PCI Device on vendor, subvendor, device and subdevice IDs.
struct pci_dev * pci_find_slot (unsigned int bus, unsigned int devfn)
 Find PCI Device on Slot.
struct pci_dev * pci_find_class (unsigned int class, const struct pci_dev *from)
 Find PCI Device on Class.

Device setup (bus mastering, enable/disable)

int pci_enable_device (struct pci_dev *dev)
 Enable PCI Device.
void pci_disable_device (struct pci_dev *dev)
 Disable PCI Device.
void pci_set_master (struct pci_dev *dev)
 Set Busmastering for PCI Device.
int pci_set_mwi (struct pci_dev *dev)
 FIXME Dummy (could also go into L4IO.
void pci_clear_mwi (struct pci_dev *dev)
 FIXME Dummy (should also go into L4IO.

Power Management related functions

int pci_set_power_state (struct pci_dev *dev, int state)
 Set PM State for PCI Device.
int pci_enable_wake (struct pci_dev *dev, u32 state, int enable)
 FIXME Dummy (could also go into L4IO.
int pci_save_state (struct pci_dev *dev, u32 *buffer)
 FIXME Dummy (could also go into L4IO.
int pci_restore_state (struct pci_dev *dev, u32 *buffer)
 FIXME Dummy (could also go into L4IO.

PCI memory pools (consistent DMA mappings...)

Pool allocator .

.. wraps the pci_alloc_consistent page allocator, so small blocks are easily used by drivers for bus mastering controllers. This should probably be sharing the guts of the slab allocator.

struct pci_poolpci_pool_create (const char *name, struct pci_dev *pdev, size_t size, size_t align, size_t allocation, int flags)
 Create a pool of pci consistent memory blocks, for dma.
void pci_pool_destroy (struct pci_pool *pool)
 Destroy a pool of pci memory blocks.
void * pci_pool_alloc (struct pci_pool *pool, int mem_flags, dma_addr_t *handle)
 Get a block of consistent memory.
void * pci_alloc_consistent (struct pci_dev *hwdev, size_t size, dma_addr_t *dma_handle)
 Allocation of PCI consistent DMA Memory.
void pci_free_consistent (struct pci_dev *hwdev, size_t size, void *vaddr, dma_addr_t dma_handle)
 Deallocation of PCI consistent DMA Memory.

Configuration space access

int pci_read_config_byte (struct pci_dev *dev, int pos, l4_uint8_t *val)
 PCI Configuration Space access - read byte.
int pci_read_config_word (struct pci_dev *dev, int pos, l4_uint16_t *val)
 PCI Configuration Space access - read word.
int pci_read_config_dword (struct pci_dev *dev, int pos, l4_uint32_t *val)
 PCI Configuration Space access - read double word.
int pci_write_config_byte (struct pci_dev *dev, int pos, l4_uint8_t val)
 PCI Configuration Space access - write byte.
int pci_write_config_word (struct pci_dev *dev, int pos, l4_uint16_t val)
 PCI Configuration Space access - write word.
int pci_write_config_dword (struct pci_dev *dev, int pos, l4_uint32_t val)
 PCI Configuration Space access - write double word.

Functions for Linux backward compatibility

This is from drivers/pci/compat.c

int pcibios_find_device (unsigned short vendor, unsigned short device, unsigned short index, unsigned char *bus, unsigned char *devfn)
 Find .
#define PCI_OP(rw, size, type)
 Configuration space access function creation (old interface).

Functions

int l4dde_pci_init (void)
 Initalize PCI module.

Detailed Description

This module emulates the PCI subsystem inside the Linux kernel.

Most of the services of this module are wrappers to libio functions. The remainder is simple glue code. The PCI module supports up to PCI_DEVICES devices at one virtual PCI bus.

Services are:

  1. exploration of bus/attached devices (find)
  2. device setup (bus mastering, enable/disable)
  3. Power Management related functions
  4. PCI device related resources
  5. Hotplugging (not supported yet)
  6. PCI memory pools (consistent DMA mappings...)
  7. configuration space access
  8. functions for Linux backward compatibility

Requirements: (additionally to Global Requirements)

Configuration:


Define Documentation

#define PCI_OP ( rw,
size,
type   ) 

Value:

int pcibios_##rw##_config_##size (unsigned char bus, unsigned char dev_fn,  \
                                  unsigned char where, unsigned type val)   \
{                                                                           \
  struct pci_dev *dev = pci_find_slot(bus, dev_fn);                         \
  if (!dev) return PCIBIOS_DEVICE_NOT_FOUND;                                \
  return pci_##rw##_config_##size(dev, where, val);                         \
}
Configuration space access function creation (old interface).

Definition at line 1304 of file pci.c.


Function Documentation

int l4dde_pci_init ( void   ) 

Initalize PCI module.

Returns:
0 on success; negative error code otherwise
Scan all PCI devices and establish virtual PCI bus.

Todo:
consider pcibus no as parameter

Definition at line 1330 of file pci.c.

void* pci_alloc_consistent ( struct pci_dev *  hwdev,
size_t  size,
dma_addr_t *  dma_handle 
)

Allocation of PCI consistent DMA Memory.

Todo:
Is this really a PCI issue?!

Definition at line 1018 of file pci.c.

struct pci_driver* pci_dev_driver ( const struct pci_dev *  dev  )  [read]

Get PCI driver of given device.

Parameters:
dev device to query
Returns:
appropriate pci_driver structure or NULL

Definition at line 210 of file pci.c.

void pci_disable_device ( struct pci_dev *  dev  ) 

Disable PCI Device.

Parameters:
dev target PCI device

Definition at line 411 of file pci.c.

int pci_enable_device ( struct pci_dev *  dev  ) 

Enable PCI Device.

Parameters:
dev target PCI device
Returns:
0 on success; error code otherwise

Definition at line 383 of file pci.c.

struct pci_dev* pci_find_class ( unsigned int  class,
const struct pci_dev *  from 
) [read]

Find PCI Device on Class.

Parameters:
class class id of desired device
from PCI device in list to start at (incremental calls)
Returns:
PCI device found or NULL on error

Definition at line 351 of file pci.c.

struct pci_dev* pci_find_device ( unsigned int  vendor,
unsigned int  device,
const struct pci_dev *  from 
) [read]

Find PCI Device on vendor and device IDs.

Parameters:
vendor vendor id of desired device
device device id of desired device
from PCI device in list to start at (incremental calls)
Returns:
PCI device found or NULL on error

Definition at line 274 of file pci.c.

struct pci_dev* pci_find_slot ( unsigned int  bus,
unsigned int  devfn 
) [read]

Find PCI Device on Slot.

Parameters:
bus target PCI bus
devfn device and function number
Returns:
PCI device found or NULL on error

Definition at line 330 of file pci.c.

struct pci_dev* pci_find_subsys ( unsigned int  vendor,
unsigned int  device,
unsigned int  ss_vendor,
unsigned int  ss_device,
const struct pci_dev *  from 
) [read]

Find PCI Device on vendor, subvendor, device and subdevice IDs.

Parameters:
vendor vendor id of desired device
device device id of desired device
ss_vendor subsystem vendor id of desired device
ss_device subsystem device id of desired device
from PCI device in list to start at (incremental calls)
Returns:
PCI device found or NULL on error

Definition at line 302 of file pci.c.

void pci_free_consistent ( struct pci_dev *  hwdev,
size_t  size,
void *  vaddr,
dma_addr_t  dma_handle 
)

Deallocation of PCI consistent DMA Memory.

Todo:
Is this really a PCI issue?!

Definition at line 1044 of file pci.c.

void* pci_pool_alloc ( struct pci_pool pool,
int  mem_flags,
dma_addr_t *  handle 
)

Get a block of consistent memory.

Parameters:
pool pci pool that will produce the block
mem_flags SLAB_KERNEL or SLAB_ATOMIC
handle pointer to dma address of block
This returns the kernel virtual address of a currently unused block, and reports its dma address through the handle. If such a memory block can't be allocated, null is returned.

Definition at line 867 of file pci.c.

struct pci_pool* pci_pool_create ( const char *  name,
struct pci_dev *  pdev,
size_t  size,
size_t  align,
size_t  allocation,
int  flags 
) [read]

Create a pool of pci consistent memory blocks, for dma.

Parameters:
name name of pool, for diagnostics
pdev pci device that will be doing the DMA
size size of the blocks in this pool.
align alignment requirement for blocks; must be a power of two
allocation returned blocks won't cross this boundary (or zero)
flags SLAB_* flags (not all are supported).
Returns a pci allocation pool with the requested characteristics, or null if one can't be created. Given one of these pools, pci_pool_alloc() may be used to allocate memory. Such memory will all have "consistent" DMA mappings, accessible by the device and its driver without using cache flushing primitives. The actual size of blocks allocated may be larger than requested because of alignment.

If allocation is nonzero, objects returned from pci_pool_alloc() won't cross that size boundary. This is useful for devices which have addressing restrictions on individual DMA transfers, such as not crossing boundaries of 4KBytes.

Definition at line 704 of file pci.c.

void pci_pool_destroy ( struct pci_pool pool  ) 

Destroy a pool of pci memory blocks.

Parameters:
pool pci pool that will be destroyed
Caller guarantees that no more memory from the pool is in use, and that nothing will try to use the pool after this call.

Definition at line 824 of file pci.c.

int pci_read_config_byte ( struct pci_dev *  dev,
int  pos,
l4_uint8_t *  val 
)

PCI Configuration Space access - read byte.

Parameters:
dev PCI device
pos configuration register
Return values:
val register contents
Returns:
0 on success; negative error code otherwise

Definition at line 1073 of file pci.c.

int pci_read_config_dword ( struct pci_dev *  dev,
int  pos,
l4_uint32_t *  val 
)

PCI Configuration Space access - read double word.

Parameters:
dev PCI device
pos configuration register
Return values:
val register contents
Returns:
0 on success; negative error code otherwise

Definition at line 1137 of file pci.c.

int pci_read_config_word ( struct pci_dev *  dev,
int  pos,
l4_uint16_t *  val 
)

PCI Configuration Space access - read word.

Parameters:
dev PCI device
pos configuration register
Return values:
val register contents
Returns:
0 on success; negative error code otherwise

Definition at line 1105 of file pci.c.

int pci_register_driver ( struct pci_driver *  drv  ) 

Register PCI driver.

Parameters:
drv device driver structure
Returns:
number of pci devices which were claimed by the driver
pci_module_init(struct pci_driver *drv) is used to initalize drivers. Doing it this way keeps the drivers away from for_each_dev() or pci_find_device().

pci_register/unregister_driver() are helpers for these and have to be implemented.

Definition at line 230 of file pci.c.

void pci_set_master ( struct pci_dev *  dev  ) 

Set Busmastering for PCI Device.

Parameters:
dev target PCI device
Todo:
Who panics if it fails?

Definition at line 439 of file pci.c.

int pci_set_power_state ( struct pci_dev *  dev,
int  state 
)

Set PM State for PCI Device.

Parameters:
dev target PCI device
state PM state
Returns:
old PM state

Definition at line 482 of file pci.c.

void pci_unregister_driver ( struct pci_driver *  drv  ) 

Unregister PCI driver.

Parameters:
drv device driver structure
See also:
pci_register_driver()

Definition at line 250 of file pci.c.

int pci_write_config_byte ( struct pci_dev *  dev,
int  pos,
l4_uint8_t  val 
)

PCI Configuration Space access - write byte.

Parameters:
dev PCI device
pos configuration register
val new value
Returns:
0 on success; negative error code otherwise

Definition at line 1169 of file pci.c.

int pci_write_config_dword ( struct pci_dev *  dev,
int  pos,
l4_uint32_t  val 
)

PCI Configuration Space access - write double word.

Parameters:
dev PCI device
pos configuration register
val new value
Returns:
0 on success; negative error code otherwise

Definition at line 1233 of file pci.c.

int pci_write_config_word ( struct pci_dev *  dev,
int  pos,
l4_uint16_t  val 
)

PCI Configuration Space access - write word.

Parameters:
dev PCI device
pos configuration register
val new value
Returns:
0 on success; negative error code otherwise

Definition at line 1201 of file pci.c.

int pcibios_find_device ( unsigned short  vendor,
unsigned short  device,
unsigned short  index,
unsigned char *  bus,
unsigned char *  devfn 
)

Find .

.. (old interface)

Definition at line 1284 of file pci.c.


Linux DDE, written by Christian Helmuth  © 2003 Technische Universitaet Dresden