Changeset 663f41c4 in mainline for uspace/drv/pciintel/pci.h
- Timestamp:
- 2010-10-23T10:56:44Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5291411
- Parents:
- 49698fa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/pciintel/pci.h
r49698fa r663f41c4 1 1 /* 2 * Copyright (c) 2010 Lenka Trochtova 2 * Copyright (c) 2010 Lenka Trochtova 3 3 * All rights reserved. 4 4 * … … 32 32 /** @file 33 33 */ 34 35 #ifndef PCI_H36 #define PCI_H37 34 35 #ifndef PCI_H_ 36 #define PCI_H_ 38 37 39 38 #include <stdlib.h> … … 54 53 } pci_dev_data_t; 55 54 56 void create_pci_match_ids(device_t *dev);55 extern void create_pci_match_ids(device_t *); 57 56 58 uint8_t pci_conf_read_8(device_t *dev, int reg);59 uint16_t pci_conf_read_16(device_t *dev, int reg);60 uint32_t pci_conf_read_32(device_t *dev, int reg);61 void pci_conf_write_8(device_t *dev, int reg, uint8_t val);62 void pci_conf_write_16(device_t *dev, int reg, uint16_t val);63 void pci_conf_write_32(device_t *dev, int reg, uint32_t val);57 extern uint8_t pci_conf_read_8(device_t *, int); 58 extern uint16_t pci_conf_read_16(device_t *, int); 59 extern uint32_t pci_conf_read_32(device_t *, int); 60 extern void pci_conf_write_8(device_t *, int, uint8_t); 61 extern void pci_conf_write_16(device_t *, int, uint16_t); 62 extern void pci_conf_write_32(device_t *, int, uint32_t); 64 63 65 void pci_add_range(device_t *dev, uint64_t range_addr, size_t range_size, bool io);66 int pci_read_bar(device_t *dev, int addr);67 void pci_read_interrupt(device_t *dev);68 void pci_add_interrupt(device_t *dev, int irq);64 extern void pci_add_range(device_t *, uint64_t, size_t, bool); 65 extern int pci_read_bar(device_t *, int); 66 extern void pci_read_interrupt(device_t *); 67 extern void pci_add_interrupt(device_t *, int); 69 68 70 void pci_bus_scan(device_t *parent, int bus_num);69 extern void pci_bus_scan(device_t *, int); 71 70 72 73 static inline pci_dev_data_t *create_pci_dev_data() 71 static inline pci_dev_data_t *create_pci_dev_data(void) 74 72 { 75 pci_dev_data_t *res = (pci_dev_data_t *)malloc(sizeof(pci_dev_data_t)); 76 if (NULL != res) { 73 pci_dev_data_t *res = (pci_dev_data_t *) malloc(sizeof(pci_dev_data_t)); 74 75 if (NULL != res) 77 76 memset(res, 0, sizeof(pci_dev_data_t)); 78 } 79 return res; 77 return res; 80 78 } 81 79 82 static inline void init_pci_dev_data(pci_dev_data_t *d, int bus, int dev, int fn) 80 static inline void 81 init_pci_dev_data(pci_dev_data_t *d, int bus, int dev, int fn) 83 82 { 84 83 d->bus = bus; 85 84 d->dev = dev; 86 d->fn = fn; 85 d->fn = fn; 87 86 } 88 87 89 static inline void delete_pci_dev_data(pci_dev_data_t *d) 88 static inline void delete_pci_dev_data(pci_dev_data_t *d) 90 89 { 91 90 if (NULL != d) { 92 91 clean_hw_resource_list(&d->hw_resources); 93 free(d); 92 free(d); 94 93 } 95 94 } … … 97 96 static inline void create_pci_dev_name(device_t *dev) 98 97 { 99 pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;98 pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data; 100 99 char *name = NULL; 101 asprintf(&name, "%02x:%02x.%01x", dev_data->bus, dev_data->dev, dev_data->fn); 100 101 asprintf(&name, "%02x:%02x.%01x", dev_data->bus, dev_data->dev, 102 dev_data->fn); 102 103 dev->name = name; 103 104 } … … 106 107 { 107 108 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; 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; 110 113 } 111 114 112 115 static inline void pci_clean_resource_list(device_t *dev) 113 116 { 114 pci_dev_data_t *dev_data = (pci_dev_data_t *)dev->driver_data; 117 pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data; 118 115 119 if (NULL != dev_data->hw_resources.resources) { 116 120 free(dev_data->hw_resources.resources); … … 119 123 } 120 124 121 /** Read the base address registers (BARs) of the device 122 * and adds the addressesto its hw resource list.123 * 125 /** Read the base address registers (BARs) of the device and adds the addresses 126 * to its hw resource list. 127 * 124 128 * @param dev the pci device. 125 129 */ 126 130 static inline void pci_read_bars(device_t *dev) 127 131 { 128 // position of the BAR in the PCI configuration address space of the device 132 /* 133 * Position of the BAR in the PCI configuration address space of the 134 * device. 135 */ 129 136 int addr = PCI_BASE_ADDR_0; 130 137 131 while (addr <= PCI_BASE_ADDR_5) { 132 addr = pci_read_bar(dev, addr); 133 } 138 while (addr <= PCI_BASE_ADDR_5) 139 addr = pci_read_bar(dev, addr); 134 140 } 135 141 … … 139 145 } 140 146 141 142 147 #endif 143 144 148 145 149 /**
Note:
See TracChangeset
for help on using the changeset viewer.