Main Page | Modules | Class List | File List | Class Members | File Members | Related Pages

PCI Bus/Device Support
[Linux DDE Common]

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

Functions for Linux backward compatibility

This is from drivers/pci/compat.c

#define PCI_OP(rw, size, type)
 Configuration space access function creation (old interface).

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


Exploration of bus/attached devices and drivers

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.

pci_dev * pci_find_device (unsigned int vendor, unsigned int device, const struct pci_dev *from)
 Find PCI Device on vendor and device IDs.

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.

pci_dev * pci_find_slot (unsigned int bus, unsigned int devfn)
 Find PCI Device on Slot.

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.


Power Management related functions

int pci_set_power_state (struct pci_dev *dev, int state)
 Set PM State for PCI Device.


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.

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

int l4dde_pci_init ()
 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 1260 of file pci.c.


Function Documentation

int l4dde_pci_init  ) 
 

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 1286 of file pci.c.

References __pci_get_handle(), __pci_io_to_linux(), _initialized, PCI_DEVICES, and pcibus.

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 974 of file pci.c.

References DEBUG_PALLOC.

struct pci_driver* pci_dev_driver const struct pci_dev *  dev  ) 
 

Get PCI driver of given device.

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

Definition at line 209 of file pci.c.

Referenced by pci_register_driver().

void pci_disable_device struct pci_dev *  dev  ) 
 

Disable PCI Device.

Parameters:
dev target PCI device

Definition at line 410 of file pci.c.

References __pci_get_handle(), and DEBUG_ERRORS.

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 382 of file pci.c.

References __pci_get_handle(), and DEBUG_ERRORS.

struct pci_dev* pci_find_class unsigned int  class,
const struct pci_dev *  from
 

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 350 of file pci.c.

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.

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 273 of file pci.c.

Referenced by pcibios_find_device().

struct pci_dev* pci_find_slot unsigned int  bus,
unsigned int  devfn
 

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 329 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
 

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 301 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 1000 of file pci.c.

References DEBUG_PALLOC.

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 823 of file pci.c.

References pci_pool::blocks_per_page, pci_pool::lock, pci_pool::page_list, pci_pool::size, and pci_pool::waitq.

struct pci_pool* pci_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.

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 660 of file pci.c.

References kmalloc().

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 780 of file pci.c.

References pci_pool::blocks_per_page, pci_pool::dev, kfree(), pci_pool::lock, pci_pool::name, and pci_pool::page_list.

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 1029 of file pci.c.

References __pci_get_handle().

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 1093 of file pci.c.

References __pci_get_handle().

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 1061 of file pci.c.

References __pci_get_handle().

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 229 of file pci.c.

References pci_announce_device(), and pci_dev_driver().

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 438 of file pci.c.

References __pci_get_handle().

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 465 of file pci.c.

References __pci_get_handle(), and DEBUG_ERRORS.

void pci_unregister_driver struct pci_driver *  drv  ) 
 

Unregister PCI driver.

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

Definition at line 249 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 1125 of file pci.c.

References __pci_get_handle().

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 1189 of file pci.c.

References __pci_get_handle().

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 1157 of file pci.c.

References __pci_get_handle().

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 1240 of file pci.c.

References pci_find_device().


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