Changeset 60898b6 in mainline for uspace/drv/pciintel/pci.c


Ignore:
Timestamp:
2010-11-05T16:17:48Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
08042bd
Parents:
a63ff7d (diff), a66e2993 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

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

    ra63ff7d r60898b6  
    6565        pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
    6666       
    67         if (NULL == dev_data)
     67        if (dev_data == NULL)
    6868                return NULL;
    6969        return &dev_data->hw_resources;
     
    109109       
    110110        bus_data = (pci_bus_data_t *) malloc(sizeof(pci_bus_data_t));
    111         if (NULL != bus_data) {
     111        if (bus_data != NULL) {
    112112                memset(bus_data, 0, sizeof(pci_bus_data_t));
    113113                fibril_mutex_initialize(&bus_data->conf_mutex);
    114114        }
     115
    115116        return bus_data;
    116117}
     
    123124static void pci_conf_read(device_t *dev, int reg, uint8_t *buf, size_t len)
    124125{
    125         assert(NULL != dev->parent);
     126        assert(dev->parent != NULL);
    126127       
    127128        pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
     
    153154static void pci_conf_write(device_t *dev, int reg, uint8_t *buf, size_t len)
    154155{
    155         assert(NULL != dev->parent);
     156        assert(dev->parent != NULL);
    156157       
    157158        pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
     
    224225       
    225226        match_id = create_match_id();
    226         if (NULL != match_id) {
     227        if (match_id != NULL) {
    227228                asprintf(&match_id_str, "pci/ven=%04x&dev=%04x",
    228229                    dev_data->vendor_id, dev_data->device_id);
     
    230231                match_id->score = 90;
    231232                add_match_id(&dev->match_ids, match_id);
    232         }       
     233        }
     234
    233235        /* TODO add more ids (with subsys ids, using class id etc.) */
    234236}
     
    242244        size_t count = hw_res_list->count;
    243245       
    244         assert(NULL != hw_resources);
     246        assert(hw_resources != NULL);
    245247        assert(count < PCI_MAX_HW_RES);
    246248       
     
    275277        bool io;
    276278        /* 64-bit wide address */
    277         bool w64;
     279        bool addrw64;
    278280       
    279281        /* Size of the io or memory range specified by the BAR */
     
    287289        io = (bool) (val & 1);
    288290        if (io) {
    289                 w64 = false;
     291                addrw64 = false;
    290292        } else {
    291293                switch ((val >> 1) & 3) {
    292294                case 0:
    293                         w64 = false;
     295                        addrw64 = false;
    294296                        break;
    295297                case 2:
    296                         w64 = true;
     298                        addrw64 = true;
    297299                        break;
    298300                default:
     
    312314        range_size = pci_bar_mask_to_size(mask);
    313315       
    314         if (w64) {
     316        if (addrw64) {
    315317                range_addr = ((uint64_t)pci_conf_read_32(dev, addr + 4) << 32) |
    316318                    (val & 0xfffffff0);
     
    319321        }
    320322       
    321         if (0 != range_addr) {
     323        if (range_addr != 0) {
    322324                printf(NAME ": device %s : ", dev->name);
    323325                printf("address = %x", range_addr);
     
    327329        pci_add_range(dev, range_addr, range_size, io);
    328330       
    329         if (w64)
     331        if (addrw64)
    330332                return addr + 8;
    331333       
     
    354356{
    355357        uint8_t irq = pci_conf_read_8(dev, PCI_BRIDGE_INT_LINE);
    356         if (0xff != irq)
     358        if (irq != 0xff)
    357359                pci_add_interrupt(dev, irq);
    358360}
     
    415417                        create_pci_match_ids(dev);
    416418                       
    417                         if (EOK != child_device_register(dev, parent)) {
     419                        if (child_device_register(dev, parent) != EOK) {
    418420                                pci_clean_resource_list(dev);
    419421                                clean_match_ids(&dev->match_ids);
     
    424426                       
    425427                        if (header_type == PCI_HEADER_TYPE_BRIDGE ||
    426                             header_type == PCI_HEADER_TYPE_CARDBUS ) {
     428                            header_type == PCI_HEADER_TYPE_CARDBUS) {
    427429                                child_bus = pci_conf_read_8(dev,
    428430                                    PCI_BRIDGE_SEC_BUS_NUM);
    429431                                printf(NAME ": device is pci-to-pci bridge, "
    430432                                    "secondary bus number = %d.\n", bus_num);
    431                                 if(child_bus > bus_num)
     433                                if (child_bus > bus_num)
    432434                                        pci_bus_scan(parent, child_bus);
    433435                        }
     
    453455       
    454456        pci_bus_data_t *bus_data = create_pci_bus_data();
    455         if (NULL == bus_data) {
     457        if (bus_data == NULL) {
    456458                printf(NAME ": pci_add_device allocation failed.\n");
    457459                return ENOMEM;
     
    513515}
    514516
     517pci_dev_data_t *create_pci_dev_data(void)
     518{
     519        pci_dev_data_t *res = (pci_dev_data_t *) malloc(sizeof(pci_dev_data_t));
     520       
     521        if (res != NULL)
     522                memset(res, 0, sizeof(pci_dev_data_t));
     523        return res;
     524}
     525
     526void init_pci_dev_data(pci_dev_data_t *dev_data, int bus, int dev, int fn)
     527{
     528        dev_data->bus = bus;
     529        dev_data->dev = dev;
     530        dev_data->fn = fn;
     531}
     532
     533void delete_pci_dev_data(pci_dev_data_t *dev_data)
     534{
     535        if (dev_data != NULL) {
     536                clean_hw_resource_list(&dev_data->hw_resources);
     537                free(dev_data);
     538        }
     539}
     540
     541void create_pci_dev_name(device_t *dev)
     542{
     543        pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
     544        char *name = NULL;
     545       
     546        asprintf(&name, "%02x:%02x.%01x", dev_data->bus, dev_data->dev,
     547            dev_data->fn);
     548        dev->name = name;
     549}
     550
     551bool pci_alloc_resource_list(device_t *dev)
     552{
     553        pci_dev_data_t *dev_data = (pci_dev_data_t *)dev->driver_data;
     554       
     555        dev_data->hw_resources.resources =
     556            (hw_resource_t *) malloc(PCI_MAX_HW_RES * sizeof(hw_resource_t));
     557        return dev_data->hw_resources.resources != NULL;
     558}
     559
     560void pci_clean_resource_list(device_t *dev)
     561{
     562        pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
     563       
     564        if (dev_data->hw_resources.resources != NULL) {
     565                free(dev_data->hw_resources.resources);
     566                dev_data->hw_resources.resources = NULL;
     567        }
     568}
     569
     570/** Read the base address registers (BARs) of the device and adds the addresses
     571 * to its hw resource list.
     572 *
     573 * @param dev the pci device.
     574 */
     575void pci_read_bars(device_t *dev)
     576{
     577        /*
     578         * Position of the BAR in the PCI configuration address space of the
     579         * device.
     580         */
     581        int addr = PCI_BASE_ADDR_0;
     582       
     583        while (addr <= PCI_BASE_ADDR_5)
     584                addr = pci_read_bar(dev, addr);
     585}
     586
     587size_t pci_bar_mask_to_size(uint32_t mask)
     588{
     589        return ((mask & 0xfffffff0) ^ 0xffffffff) + 1;
     590}
     591
    515592int main(int argc, char *argv[])
    516593{
Note: See TracChangeset for help on using the changeset viewer.