Ignore:
File:
1 edited

Legend:

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

    r6dbc500 rc90aed4  
    5757#include <ops/hw_res.h>
    5858#include <device/hw_res.h>
    59 #include <ops/pio_window.h>
    60 #include <device/pio_window.h>
    6159#include <ddi.h>
    6260#include <pci_dev_iface.h>
     
    143141}
    144142
    145 static pio_window_t *pciintel_get_pio_window(ddf_fun_t *fnode)
    146 {
    147         pci_fun_t *fun = pci_fun(fnode);
    148        
    149         if (fun == NULL)
    150                 return NULL;
    151         return &fun->pio_window;
    152 }
    153 
    154 
    155143static int pci_config_space_write_32(ddf_fun_t *fun, uint32_t address,
    156144    uint32_t data)
     
    210198        .get_resource_list = &pciintel_get_resources,
    211199        .enable_interrupt = &pciintel_enable_interrupt,
    212 };
    213 
    214 static pio_window_ops_t pciintel_pio_window_ops = {
    215         .get_pio_window = &pciintel_get_pio_window
    216200};
    217201
     
    227211static ddf_dev_ops_t pci_fun_ops = {
    228212        .interfaces[HW_RES_DEV_IFACE] = &pciintel_hw_res_ops,
    229         .interfaces[PIO_WINDOW_DEV_IFACE] = &pciintel_pio_window_ops,
    230213        .interfaces[PCI_DEV_IFACE] = &pci_dev_ops
    231214};
     
    250233static void pci_conf_read(pci_fun_t *fun, int reg, uint8_t *buf, size_t len)
    251234{
     235        pci_bus_t *bus = pci_bus_from_fun(fun);
     236       
     237        fibril_mutex_lock(&bus->conf_mutex);
     238       
    252239        const uint32_t conf_addr = CONF_ADDR(fun->bus, fun->dev, fun->fn, reg);
    253         pci_bus_t *bus = pci_bus_from_fun(fun);
    254         uint32_t val;
    255        
    256         fibril_mutex_lock(&bus->conf_mutex);
    257 
     240        void *addr = bus->conf_data_port + (reg & 3);
     241       
    258242        pio_write_32(bus->conf_addr_port, host2uint32_t_le(conf_addr));
    259 
    260         /*
    261          * Always read full 32-bits from the PCI conf_data_port register and
    262          * get the desired portion of it afterwards. Some architectures do not
    263          * support shorter PIO reads offset from this register.
    264          */
    265         val = uint32_t_le2host(pio_read_32(bus->conf_data_port));
    266 
     243       
    267244        switch (len) {
    268245        case 1:
    269                 *buf = (uint8_t) (val >> ((reg & 3) * 8));
     246                /* No endianness change for 1 byte */
     247                buf[0] = pio_read_8(addr);
    270248                break;
    271249        case 2:
    272                 *((uint16_t *) buf) = (uint16_t) (val >> ((reg & 3)) * 8);
     250                ((uint16_t *) buf)[0] = uint16_t_le2host(pio_read_16(addr));
    273251                break;
    274252        case 4:
    275                 *((uint32_t *) buf) = (uint32_t) val;
     253                ((uint32_t *) buf)[0] = uint32_t_le2host(pio_read_32(addr));
    276254                break;
    277255        }
     
    282260static void pci_conf_write(pci_fun_t *fun, int reg, uint8_t *buf, size_t len)
    283261{
     262        pci_bus_t *bus = pci_bus_from_fun(fun);
     263       
     264        fibril_mutex_lock(&bus->conf_mutex);
     265       
    284266        const uint32_t conf_addr = CONF_ADDR(fun->bus, fun->dev, fun->fn, reg);
    285         pci_bus_t *bus = pci_bus_from_fun(fun);
    286         uint32_t val;
    287        
    288         fibril_mutex_lock(&bus->conf_mutex);
    289 
    290         /*
    291          * Prepare to write full 32-bits to the PCI conf_data_port register.
    292          * Some architectures do not support shorter PIO writes offset from this
    293          * register.
    294          */
    295 
    296         if (len < 4) {
    297                 /*
    298                  * We have fewer than full 32-bits, so we need to read the
    299                  * missing bits first.
    300                  */
    301                 pio_write_32(bus->conf_addr_port, host2uint32_t_le(conf_addr));
    302                 val = uint32_t_le2host(pio_read_32(bus->conf_data_port));
    303         }
     267        void *addr = bus->conf_data_port + (reg & 3);
     268       
     269        pio_write_32(bus->conf_addr_port, host2uint32_t_le(conf_addr));
    304270       
    305271        switch (len) {
    306272        case 1:
    307                 val &= ~(0xffU << ((reg & 3) * 8));
    308                 val |= *buf << ((reg & 3) * 8);
     273                /* No endianness change for 1 byte */
     274                pio_write_8(addr, buf[0]);
    309275                break;
    310276        case 2:
    311                 val &= ~(0xffffU << ((reg & 3) * 8));
    312                 val |= *((uint16_t *) buf) << ((reg & 3) * 8);
     277                pio_write_16(addr, host2uint16_t_le(((uint16_t *) buf)[0]));
    313278                break;
    314279        case 4:
    315                 val = *((uint32_t *) buf);
     280                pio_write_32(addr, host2uint32_t_le(((uint32_t *) buf)[0]));
    316281                break;
    317282        }
    318 
    319         pio_write_32(bus->conf_addr_port, host2uint32_t_le(conf_addr));
    320         pio_write_32(bus->conf_data_port, host2uint32_t_le(val));
    321283       
    322284        fibril_mutex_unlock(&bus->conf_mutex);
     
    471433{
    472434        /* Value of the BAR */
    473         uint32_t val;
    474         uint32_t bar;
    475         uint32_t mask;
    476 
     435        uint32_t val, mask;
    477436        /* IO space address */
    478437        bool io;
     
    512471        /* Get the address mask. */
    513472        pci_conf_write_32(fun, addr, 0xffffffff);
    514         bar = pci_conf_read_32(fun, addr);
    515 
    516         /*
    517          * Unimplemented BARs read back as all 0's.
    518          */
    519         if (!bar)
    520                 return addr + (addrw64 ? 8 : 4);
    521 
    522         mask &= bar;   
    523 
     473        mask &= pci_conf_read_32(fun, addr);
     474       
    524475        /* Restore the original value. */
    525476        pci_conf_write_32(fun, addr, val);
     
    569520{
    570521        uint8_t irq = pci_conf_read_8(fun, PCI_BRIDGE_INT_LINE);
    571         uint8_t pin = pci_conf_read_8(fun, PCI_BRIDGE_INT_PIN);
    572 
    573         if (pin != 0 && irq != 0xff)
     522        if (irq != 0xff)
    574523                pci_add_interrupt(fun, irq);
    575524}
     
    634583                        pci_read_bars(fun);
    635584                        pci_read_interrupt(fun);
    636 
    637                         /* Propagate the PIO window to the function. */
    638                         fun->pio_window = bus->pio_win;
    639585                       
    640586                        ddf_fun_set_ops(fun->fnode, &pci_fun_ops);
     
    667613static int pci_dev_add(ddf_dev_t *dnode)
    668614{
    669         hw_resource_list_t hw_resources;
    670615        pci_bus_t *bus = NULL;
    671616        ddf_fun_t *ctl = NULL;
     
    693638                goto fail;
    694639        }
    695 
    696         rc = pio_window_get(sess, &bus->pio_win);
    697         if (rc != EOK) {
    698                 ddf_msg(LVL_ERROR, "pci_dev_add failed to get PIO window "
    699                     "for the device.");
    700                 goto fail;
    701         }
     640       
     641        hw_resource_list_t hw_resources;
    702642       
    703643        rc = hw_res_get_resource_list(sess, &hw_resources);
     
    789729{
    790730        ddf_log_init(NAME);
     731        pci_fun_ops.interfaces[HW_RES_DEV_IFACE] = &pciintel_hw_res_ops;
     732        pci_fun_ops.interfaces[PCI_DEV_IFACE] = &pci_dev_ops;
    791733}
    792734
Note: See TracChangeset for help on using the changeset viewer.