Changeset 79ae36dd in mainline for uspace/drv/ehci_hcd/pci.c


Ignore:
Timestamp:
2011-06-08T19:01:55Z (13 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0eff68e
Parents:
764d71e
Message:

new async framework with integrated exchange tracking

  • strict isolation between low-level IPC and high-level async framework with integrated exchange tracking
    • each IPC connection is represented by an async_sess_t structure
    • each IPC exchange is represented by an async_exch_t structure
    • exchange management is either based on atomic messages (EXCHANGE_ATOMIC), locking (EXCHANGE_SERIALIZE) or connection cloning (EXCHANGE_CLONE)
  • async_obsolete: temporary compatibility layer to keep old async clients working (several pieces of code are currently broken, but only non-essential functionality)
  • IPC_M_PHONE_HANGUP is now method no. 0 (for elegant boolean evaluation)
  • IPC_M_DEBUG_ALL has been renamed to IPC_M_DEBUG
  • IPC_M_PING has been removed (VFS protocol now has VFS_IN_PING)
  • console routines in libc have been rewritten for better abstraction
  • additional use for libc-private header files (FILE structure opaque to the client)
  • various cstyle changes (typos, indentation, missing externs in header files, improved comments, etc.)
File:
1 edited

Legend:

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

    r764d71e r79ae36dd  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
     28
    2829/**
    2930 * @addtogroup drvusbehci
     
    3435 * PCI related functions needed by the EHCI driver.
    3536 */
     37
    3638#include <errno.h>
    3739#include <str_error.h>
     
    7274#define PCI_READ(size) \
    7375do { \
    74         const int parent_phone = \
    75             devman_parent_device_connect(dev->handle, IPC_FLAG_BLOCKING);\
    76         if (parent_phone < 0) {\
    77                 return parent_phone; \
    78         } \
    79         sysarg_t add = (sysarg_t)address; \
     76        async_sess_t *parent_sess = \
     77            devman_parent_device_connect(EXCHANGE_SERIALIZE, dev->handle, \
     78            IPC_FLAG_BLOCKING); \
     79        if (!parent_sess) \
     80                return ENOMEM; \
     81        \
     82        sysarg_t add = (sysarg_t) address; \
    8083        sysarg_t val; \
     84        \
     85        async_exch_t *exch = async_exchange_begin(parent_sess); \
     86        \
    8187        const int ret = \
    82             async_req_2_1(parent_phone, DEV_IFACE_ID(PCI_DEV_IFACE), \
     88            async_req_2_1(exch, DEV_IFACE_ID(PCI_DEV_IFACE), \
    8389                IPC_M_CONFIG_SPACE_READ_##size, add, &val); \
     90        \
     91        async_exchange_end(exch); \
     92        async_hangup(parent_sess); \
     93        \
    8494        assert(value); \
     95        \
    8596        *value = val; \
    86         async_hangup(parent_phone); \
     97        return ret; \
     98} while (0)
     99
     100static int pci_read32(const ddf_dev_t *dev, int address, uint32_t *value)
     101{
     102        PCI_READ(32);
     103}
     104
     105static int pci_read16(const ddf_dev_t *dev, int address, uint16_t *value)
     106{
     107        PCI_READ(16);
     108}
     109
     110static int pci_read8(const ddf_dev_t *dev, int address, uint8_t *value)
     111{
     112        PCI_READ(8);
     113}
     114
     115#define PCI_WRITE(size) \
     116do { \
     117        async_sess_t *parent_sess = \
     118            devman_parent_device_connect(EXCHANGE_SERIALIZE, dev->handle, \
     119            IPC_FLAG_BLOCKING); \
     120        if (!parent_sess) \
     121                return ENOMEM; \
     122        \
     123        sysarg_t add = (sysarg_t) address; \
     124        sysarg_t val = value; \
     125        \
     126        async_exch_t *exch = async_exchange_begin(parent_sess); \
     127        \
     128        const int ret = \
     129            async_req_3_0(exch, DEV_IFACE_ID(PCI_DEV_IFACE), \
     130                IPC_M_CONFIG_SPACE_WRITE_##size, add, val); \
     131        \
     132        async_exchange_end(exch); \
     133        async_hangup(parent_sess); \
     134        \
    87135        return ret; \
    88136} while(0)
    89137
    90 static int pci_read32(const ddf_dev_t *dev, int address, uint32_t *value)
    91 {
    92         PCI_READ(32);
    93 }
    94 static int pci_read16(const ddf_dev_t *dev, int address, uint16_t *value)
    95 {
    96         PCI_READ(16);
    97 }
    98 static int pci_read8(const ddf_dev_t *dev, int address, uint8_t *value)
    99 {
    100         PCI_READ(8);
    101 }
    102 #define PCI_WRITE(size) \
    103 do { \
    104         const int parent_phone = \
    105             devman_parent_device_connect(dev->handle, IPC_FLAG_BLOCKING);\
    106         if (parent_phone < 0) {\
    107                 return parent_phone; \
    108         } \
    109         sysarg_t add = (sysarg_t)address; \
    110         sysarg_t val = value; \
    111         const int ret = \
    112             async_req_3_0(parent_phone, DEV_IFACE_ID(PCI_DEV_IFACE), \
    113                 IPC_M_CONFIG_SPACE_WRITE_##size, add, val); \
    114         async_hangup(parent_phone); \
    115         return ret; \
    116 } while(0)
    117 
    118138static int pci_write32(const ddf_dev_t *dev, int address, uint32_t value)
    119139{
    120140        PCI_WRITE(32);
    121141}
     142
    122143static int pci_write16(const ddf_dev_t *dev, int address, uint16_t value)
    123144{
    124145        PCI_WRITE(16);
    125146}
     147
    126148static int pci_write8(const ddf_dev_t *dev, int address, uint8_t value)
    127149{
     
    141163{
    142164        assert(dev != NULL);
    143 
    144         const int parent_phone =
    145             devman_parent_device_connect(dev->handle, IPC_FLAG_BLOCKING);
    146         if (parent_phone < 0) {
    147                 return parent_phone;
    148         }
    149 
    150         int rc;
    151 
     165       
     166        async_sess_t *parent_sess =
     167            devman_parent_device_connect(EXCHANGE_SERIALIZE, dev->handle,
     168            IPC_FLAG_BLOCKING);
     169        if (!parent_sess)
     170                return ENOMEM;
     171       
    152172        hw_resource_list_t hw_resources;
    153         rc = hw_res_get_resource_list(parent_phone, &hw_resources);
     173        int rc = hw_res_get_resource_list(parent_sess, &hw_resources);
    154174        if (rc != EOK) {
    155                 async_hangup(parent_phone);
     175                async_hangup(parent_sess);
    156176                return rc;
    157177        }
    158 
     178       
    159179        uintptr_t mem_address = 0;
    160180        size_t mem_size = 0;
    161181        bool mem_found = false;
    162 
     182       
    163183        int irq = 0;
    164184        bool irq_found = false;
    165 
     185       
    166186        size_t i;
    167187        for (i = 0; i < hw_resources.count; i++) {
    168188                hw_resource_t *res = &hw_resources.resources[i];
    169                 switch (res->type)
    170                 {
     189                switch (res->type) {
    171190                case INTERRUPT:
    172191                        irq = res->res.interrupt.irq;
     
    174193                        usb_log_debug2("Found interrupt: %d.\n", irq);
    175194                        break;
    176 
    177195                case MEM_RANGE:
    178196                        if (res->res.mem_range.address != 0
     
    183201                                    mem_address, mem_size);
    184202                                mem_found = true;
    185                                 }
     203                        }
    186204                default:
    187205                        break;
    188206                }
    189207        }
    190 
     208       
    191209        if (mem_found && irq_found) {
    192210                *mem_reg_address = mem_address;
     
    197215                rc = ENOENT;
    198216        }
    199 
    200         async_hangup(parent_phone);
     217       
     218        async_hangup(parent_sess);
    201219        return rc;
    202220}
     
    209227int pci_enable_interrupts(const ddf_dev_t *device)
    210228{
    211         const int parent_phone =
    212             devman_parent_device_connect(device->handle, IPC_FLAG_BLOCKING);
    213         if (parent_phone < 0) {
    214                 return parent_phone;
    215         }
    216         const bool enabled = hw_res_enable_interrupt(parent_phone);
    217         async_hangup(parent_phone);
     229        async_sess_t *parent_sess =
     230            devman_parent_device_connect(EXCHANGE_SERIALIZE, device->handle,
     231            IPC_FLAG_BLOCKING);
     232        if (!parent_sess)
     233                return ENOMEM;
     234       
     235        const bool enabled = hw_res_enable_interrupt(parent_sess);
     236        async_hangup(parent_sess);
     237       
    218238        return enabled ? EOK : EIO;
    219239}
     
    366386#undef CHECK_RET_RETURN
    367387}
    368 /*----------------------------------------------------------------------------*/
     388
    369389/**
    370390 * @}
    371391 */
    372 
    373 /**
    374  * @}
    375  */
Note: See TracChangeset for help on using the changeset viewer.