1  /*
   2   * \brief  PCI bus access
   3   * \author Christian Helmuth
   4   * \date   2008-10-01
   5   *
   6   * The DDE Kit provides virtual PCI bus hierarchy, which may be a subset of
   7   * the PCI bus with the same bus-device-function IDs.
   8   */

   9  
  10  /*
  11   * Copyright (C) 2008-2012 Genode Labs GmbH
  12   *
  13   * This file is part of the Genode OS framework, which is distributed
  14   * under the terms of the GNU General Public License version 2.
  15   */

  16  
  17  #ifndef _INCLUDE__DDE_KIT__PCI_H_
  18  #define _INCLUDE__DDE_KIT__PCI_H_
  19  
  20  #include <dde_kit/types.h>
  21  
  22  /********************************
  23   ** Configuration space access **
  24   ********************************/

  25  
  26  /**
  27   * Read byte from PCI config space
  28   *
  29   * \param bus   bus number
  30   * \param dev   device number
  31   * \param fun   function number
  32   * \param pos   offset in config space
  33   *
  34   * \retval val  read value
  35   *
  36   * \return 0 on success, -1 otherwise
  37   */

  38  void dde_kit_pci_readb(int bus, int dev, int fun, int pos, dde_kit_uint8_t  *val);

  39  
  40  /**
  41   * Read word from PCI config space
  42   *
  43   * \param bus   bus number
  44   * \param dev   device number
  45   * \param fun   function number
  46   * \param pos   offset in config space
  47   *
  48   * \retval val  read value
  49   *
  50   * \return 0 on success, -1 otherwise
  51   */

  52  void dde_kit_pci_readw(int bus, int dev, int fun, int pos, dde_kit_uint16_t *val);

  53  
  54  /**
  55   * Read dword from PCI config space
  56   *
  57   * \param bus   bus number
  58   * \param dev   device number
  59   * \param fun   function number
  60   * \param pos   offset in config space
  61   *
  62   * \retval val  read value
  63   *
  64   * \return 0 on success, -1 otherwise
  65   */

  66  void dde_kit_pci_readl(int bus, int dev, int fun, int pos, dde_kit_uint32_t *val);

  67  
  68  /**
  69   * Write byte to PCI config space
  70   *
  71   * \param bus   bus number
  72   * \param dev  device number
  73   * \param fun  function  number
  74   * \param pos  offset in config space
  75   * \param val  value to write
  76   *
  77   * \return 0 on success, -1 otherwise
  78   */

  79  void dde_kit_pci_writeb(int bus, int dev, int fun, int pos, dde_kit_uint8_t val);

  80  
  81  /**
  82   * Write word to PCI config space
  83   *
  84   * \param bus   bus number
  85   * \param dev  device number
  86   * \param fun  function  number
  87   * \param pos  offset in config space
  88   * \param val  value to write
  89   *
  90   * \return 0 on success, -1 otherwise
  91   */

  92  void dde_kit_pci_writew(int bus, int dev, int fun, int pos, dde_kit_uint16_t  val);

  93  
  94  /**
  95   * Write dword to PCI config space.
  96   *
  97   * \param bus   bus number
  98   * \param dev  device number
  99   * \param fun  function  number
 100   * \param pos  offset in config space
 101   * \param val  value to write
 102   *
 103   * \return 0 on success, -1 otherwise
 104   */

 105  void dde_kit_pci_writel(int bus, int dev, int fun, int pos, dde_kit_uint32_t  val);

 106  
 107  
 108  /***************************
 109   ** Convenience functions **
 110   ***************************/

 111  
 112  /**
 113   * Find first PCI device on virtual bus tree
 114   *
 115   * \retval bus  bus number
 116   * \retval dev  device number
 117   * \retval fun  function number
 118   *
 119   * \return 0 on success, -1 otherwise
 120   */

 121  int dde_kit_pci_first_device(int *bus, int *dev, int *fun);

 122  
 123  /**
 124   * Find next PCI device
 125   *
 126   * \param bus   bus number to start at
 127   * \param dev   device number to start at
 128   * \param fun   function number to start at
 129   *
 130   * \retval bus  bus number
 131   * \retval dev  device number
 132   * \retval fun  function number
 133   *
 134   * \return 0 on success, -1 otherwise
 135   */

 136  int dde_kit_pci_next_device(int *bus, int *dev, int *fun);

 137  
 138  /**
 139   * Initialize PCI subsystem
 140   */

 141  void dde_kit_pci_init(void);

 142  
 143  
 144  #endif /* _INCLUDE__DDE_KIT__PCI_H_ */