Changeset 3a5909f in mainline for uspace/srv/drivers/pciintel/pci.h


Ignore:
Timestamp:
2010-04-09T11:46:56Z (14 years ago)
Author:
Lenka Trochtova <trochtova.lenka@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3843ecb
Parents:
d1fc8f0
Message:

pci bus enumeration - bars and ints

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/drivers/pciintel/pci.h

    rd1fc8f0 r3a5909f  
    4141#include <malloc.h>
    4242
     43#include "pci_regs.h"
     44
     45#define PCI_MAX_HW_RES 8
     46
    4347typedef struct pci_dev_data {
    4448        int bus;
     
    4953        hw_resource_list_t hw_resources;
    5054} pci_dev_data_t;
     55
     56void create_pci_match_ids(device_t *dev);
     57
     58uint8_t pci_conf_read_8(device_t *dev, int reg);
     59uint16_t pci_conf_read_16(device_t *dev, int reg);
     60uint32_t pci_conf_read_32(device_t *dev, int reg);
     61void pci_conf_write_8(device_t *dev, int reg, uint8_t val);
     62void pci_conf_write_16(device_t *dev, int reg, uint16_t val);
     63void pci_conf_write_32(device_t *dev, int reg, uint32_t val);
     64
     65void pci_add_range(device_t *dev, uint64_t range_addr, size_t range_size, bool io);
     66int pci_read_bar(device_t *dev, int addr);
     67void pci_read_interrupt(device_t *dev);
     68void pci_add_interrupt(device_t *dev, int irq);
     69
     70void pci_bus_scan(device_t *parent, int bus_num);
     71
    5172
    5273static inline pci_dev_data_t *create_pci_dev_data()
     
    82103}
    83104
    84 void create_pci_match_ids(device_t *dev);
     105static inline bool pci_alloc_resource_list(device_t *dev)
     106{
     107        pci_dev_data_t *dev_data = (pci_dev_data_t *)dev->driver_data;
     108        dev_data->hw_resources.resources = (hw_resource_t *)malloc(PCI_MAX_HW_RES * sizeof(hw_resource_t));
     109        return dev_data->hw_resources.resources != NULL;       
     110}
    85111
    86 uint8_t pci_conf_read_8(device_t *dev, int reg);
    87 uint16_t pci_conf_read_16(device_t *dev, int reg);
    88 uint32_t pci_conf_read_32(device_t *dev, int reg);
    89 void pci_conf_write_8(device_t *dev, int reg, uint8_t val);
    90 void pci_conf_write_16(device_t *dev, int reg, uint16_t val);
    91 void pci_conf_write_32(device_t *dev, int reg, uint32_t val);
     112static inline bool pci_clean_resource_list(device_t *dev)
     113{
     114        pci_dev_data_t *dev_data = (pci_dev_data_t *)dev->driver_data;
     115        if (NULL != dev_data->hw_resources.resources) {
     116                free(dev_data->hw_resources.resources);
     117                dev_data->hw_resources.resources = NULL;
     118        }
     119}
    92120
    93 void pci_bus_scan(device_t *parent, int bus_num);
     121/** Read the base address registers (BARs) of the device
     122 *  and adds the addresses to its hw resource list.
     123 *
     124 * @param dev the pci device.
     125 */
     126static inline  void pci_read_bars(device_t *dev)
     127{
     128        // position of the BAR in the PCI configuration address space of the device
     129        int addr = PCI_BASE_ADDR_0;
     130       
     131        while (addr <= PCI_BASE_ADDR_5) {
     132                addr = pci_read_bar(dev, addr);
     133        }       
     134}
     135
     136static inline size_t pci_bar_mask_to_size(uint32_t mask)
     137{
     138        return ((mask & 0xfffffff0) ^ 0xffffffff) + 1;
     139}
     140
    94141
    95142#endif
Note: See TracChangeset for help on using the changeset viewer.