Changeset ab92305 in mainline for uspace/lib/c/generic/device/hw_res.c


Ignore:
Timestamp:
2013-08-19T17:23:31Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4da8fdb
Parents:
2921602 (diff), 4a9728ec (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 audio support.

Includes audio server and sb16 driver.

Tested on ia32 and amd64 (qemu).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/device/hw_res.c

    r2921602 rab92305  
    4242{
    4343        sysarg_t count = 0;
    44        
     44
    4545        async_exch_t *exch = async_exchange_begin(sess);
     46        if (exch == NULL)
     47                return ENOMEM;
    4648        int rc = async_req_1_1(exch, DEV_IFACE_ID(HW_RES_DEV_IFACE),
    4749            HW_RES_GET_RESOURCE_LIST, &count);
    48        
     50
    4951        if (rc != EOK) {
    5052                async_exchange_end(exch);
    5153                return rc;
    5254        }
    53        
     55
    5456        size_t size = count * sizeof(hw_resource_t);
    5557        hw_resource_t *resources = (hw_resource_t *) malloc(size);
     
    5961                return ENOMEM;
    6062        }
    61        
     63
    6264        rc = async_data_read_start(exch, resources, size);
    6365        async_exchange_end(exch);
    64        
     66
    6567        if (rc != EOK) {
    6668                free(resources);
    6769                return rc;
    6870        }
    69        
     71
    7072        hw_resources->resources = resources;
    7173        hw_resources->count = count;
    72        
     74
    7375        return EOK;
    7476}
     
    7779{
    7880        async_exch_t *exch = async_exchange_begin(sess);
     81        if (exch == NULL)
     82                return false;
    7983        int rc = async_req_1_0(exch, DEV_IFACE_ID(HW_RES_DEV_IFACE),
    8084            HW_RES_ENABLE_INTERRUPT);
    8185        async_exchange_end(exch);
    82        
     86
    8387        return (rc == EOK);
     88}
     89
     90/**
     91 * Setup DMA channel to specified place and mode.
     92 * @param channel DMA Channel 1,2,3 for 8 bit transfers, 5,6,7 for 16 bit.
     93 * @param pa Physical address of the buffer. Must be < 16MB for 16 bit and < 1MB
     94 *           for 8 bit transfers.
     95 * @param size DMA buffer size, limited to 64K.
     96 * @param mode Mode of the DMA channel:
     97 *              - Read or Write
     98 *              - Allow automatic reset
     99 *              - Use address decrement instead of increment
     100 *              - Use SINGLE/BLOCK/ON DEMAND transfer mode
     101 * @return Error code.
     102 */
     103int hw_res_dma_channel_setup(async_sess_t *sess,
     104    unsigned channel, uint32_t pa, uint32_t size, uint8_t mode)
     105{
     106        async_exch_t *exch = async_exchange_begin(sess);
     107        if (exch == NULL)
     108                return ENOMEM;
     109        const uint32_t packed = (channel & 0xffff) | (mode << 16);
     110        const int ret = async_req_4_0(exch, DEV_IFACE_ID(HW_RES_DEV_IFACE),
     111            HW_RES_DMA_CHANNEL_SETUP, packed, pa, size);
     112        async_exchange_end(exch);
     113
     114        return ret;
     115}
     116
     117/**
     118 * Query remaining bytes in the buffer.
     119 * @param channel DMA Channel 1,2,3 for 8 bit transfers, 5,6,7 for 16 bit.
     120 * @return Number of bytes remaining in the buffer(>=0) or error code(<0).
     121 */
     122int hw_res_dma_channel_remain(async_sess_t *sess, unsigned channel)
     123{
     124        async_exch_t *exch = async_exchange_begin(sess);
     125        if (exch == NULL)
     126                return ENOMEM;
     127        sysarg_t remain;
     128        const int ret = async_req_2_1(exch, DEV_IFACE_ID(HW_RES_DEV_IFACE),
     129            HW_RES_DMA_CHANNEL_REMAIN, channel, &remain);
     130        async_exchange_end(exch);
     131        if (ret == EOK)
     132                return remain;
     133        return ret;
    84134}
    85135
Note: See TracChangeset for help on using the changeset viewer.