Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/pciintel/pci.h

    r713a4b9 r663f41c4  
    6969extern void pci_bus_scan(device_t *, int);
    7070
    71 extern pci_dev_data_t *create_pci_dev_data(void);
    72 extern void init_pci_dev_data(pci_dev_data_t *, int, int, int);
    73 extern void delete_pci_dev_data(pci_dev_data_t *);
    74 extern void create_pci_dev_name(device_t *);
     71static inline pci_dev_data_t *create_pci_dev_data(void)
     72{
     73        pci_dev_data_t *res = (pci_dev_data_t *) malloc(sizeof(pci_dev_data_t));
     74       
     75        if (NULL != res)
     76                memset(res, 0, sizeof(pci_dev_data_t));
     77        return res;
     78}
    7579
    76 extern bool pci_alloc_resource_list(device_t *);
    77 extern void pci_clean_resource_list(device_t *);
     80static inline void
     81init_pci_dev_data(pci_dev_data_t *d, int bus, int dev, int fn)
     82{
     83        d->bus = bus;
     84        d->dev = dev;
     85        d->fn = fn;
     86}
    7887
    79 extern void pci_read_bars(device_t *);
    80 extern size_t pci_bar_mask_to_size(uint32_t);
     88static inline void delete_pci_dev_data(pci_dev_data_t *d)
     89{
     90        if (NULL != d) {
     91                clean_hw_resource_list(&d->hw_resources);
     92                free(d);
     93        }
     94}
     95
     96static inline void create_pci_dev_name(device_t *dev)
     97{
     98        pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
     99        char *name = NULL;
     100       
     101        asprintf(&name, "%02x:%02x.%01x", dev_data->bus, dev_data->dev,
     102            dev_data->fn);
     103        dev->name = name;
     104}
     105
     106static inline bool pci_alloc_resource_list(device_t *dev)
     107{
     108        pci_dev_data_t *dev_data = (pci_dev_data_t *)dev->driver_data;
     109       
     110        dev_data->hw_resources.resources =
     111            (hw_resource_t *) malloc(PCI_MAX_HW_RES * sizeof(hw_resource_t));
     112        return dev_data->hw_resources.resources != NULL;
     113}
     114
     115static inline void pci_clean_resource_list(device_t *dev)
     116{
     117        pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
     118       
     119        if (NULL != dev_data->hw_resources.resources) {
     120                free(dev_data->hw_resources.resources);
     121                dev_data->hw_resources.resources = NULL;
     122        }
     123}
     124
     125/** Read the base address registers (BARs) of the device and adds the addresses
     126 * to its hw resource list.
     127 *
     128 * @param dev the pci device.
     129 */
     130static inline  void pci_read_bars(device_t *dev)
     131{
     132        /*
     133         * Position of the BAR in the PCI configuration address space of the
     134         * device.
     135         */
     136        int addr = PCI_BASE_ADDR_0;
     137       
     138        while (addr <= PCI_BASE_ADDR_5)
     139                addr = pci_read_bar(dev, addr);
     140}
     141
     142static inline size_t pci_bar_mask_to_size(uint32_t mask)
     143{
     144        return ((mask & 0xfffffff0) ^ 0xffffffff) + 1;
     145}
    81146
    82147#endif
Note: See TracChangeset for help on using the changeset viewer.