Changeset 5856b627 in mainline for uspace/lib/c


Ignore:
Timestamp:
2013-08-20T12:36:48Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
26e2de3
Parents:
0ee999d (diff), 4da8fdb (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:

Mainline changes.

Location:
uspace/lib/c
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/async.c

    r0ee999d r5856b627  
    22812281bool async_data_read_receive(ipc_callid_t *callid, size_t *size)
    22822282{
     2283        ipc_call_t data;
     2284        return async_data_read_receive_call(callid, &data, size);
     2285}
     2286
     2287/** Wrapper for receiving the IPC_M_DATA_READ calls using the async framework.
     2288 *
     2289 * This wrapper only makes it more comfortable to receive IPC_M_DATA_READ
     2290 * calls so that the user doesn't have to remember the meaning of each IPC
     2291 * argument.
     2292 *
     2293 * So far, this wrapper is to be used from within a connection fibril.
     2294 *
     2295 * @param callid Storage for the hash of the IPC_M_DATA_READ.
     2296 * @param size   Storage for the maximum size. Can be NULL.
     2297 *
     2298 * @return True on success, false on failure.
     2299 *
     2300 */
     2301bool async_data_read_receive_call(ipc_callid_t *callid, ipc_call_t *data,
     2302    size_t *size)
     2303{
    22832304        assert(callid);
    2284        
    2285         ipc_call_t data;
    2286         *callid = async_get_call(&data);
    2287        
    2288         if (IPC_GET_IMETHOD(data) != IPC_M_DATA_READ)
     2305        assert(data);
     2306       
     2307        *callid = async_get_call(data);
     2308       
     2309        if (IPC_GET_IMETHOD(*data) != IPC_M_DATA_READ)
    22892310                return false;
    22902311       
    22912312        if (size)
    2292                 *size = (size_t) IPC_GET_ARG2(data);
     2313                *size = (size_t) IPC_GET_ARG2(*data);
    22932314       
    22942315        return true;
     
    23852406bool async_data_write_receive(ipc_callid_t *callid, size_t *size)
    23862407{
     2408        ipc_call_t data;
     2409        return async_data_write_receive_call(callid, &data, size);
     2410}
     2411
     2412/** Wrapper for receiving the IPC_M_DATA_WRITE calls using the async framework.
     2413 *
     2414 * This wrapper only makes it more comfortable to receive IPC_M_DATA_WRITE
     2415 * calls so that the user doesn't have to remember the meaning of each IPC
     2416 * argument.
     2417 *
     2418 * So far, this wrapper is to be used from within a connection fibril.
     2419 *
     2420 * @param callid Storage for the hash of the IPC_M_DATA_WRITE.
     2421 * @param data   Storage for the ipc call data.
     2422 * @param size   Storage for the suggested size. May be NULL.
     2423 *
     2424 * @return True on success, false on failure.
     2425 *
     2426 */
     2427bool async_data_write_receive_call(ipc_callid_t *callid, ipc_call_t *data,
     2428    size_t *size)
     2429{
    23872430        assert(callid);
    2388        
    2389         ipc_call_t data;
    2390         *callid = async_get_call(&data);
    2391        
    2392         if (IPC_GET_IMETHOD(data) != IPC_M_DATA_WRITE)
     2431        assert(data);
     2432       
     2433        *callid = async_get_call(data);
     2434       
     2435        if (IPC_GET_IMETHOD(*data) != IPC_M_DATA_WRITE)
    23932436                return false;
    23942437       
    23952438        if (size)
    2396                 *size = (size_t) IPC_GET_ARG2(data);
     2439                *size = (size_t) IPC_GET_ARG2(*data);
    23972440       
    23982441        return true;
  • uspace/lib/c/generic/device/hw_res.c

    r0ee999d r5856b627  
    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
  • uspace/lib/c/generic/device/hw_res_parsed.c

    r0ee999d r5856b627  
    3838#include <errno.h>
    3939
    40 static void hw_res_parse_add_irq(hw_res_list_parsed_t *out, hw_resource_t *res,
    41     int flags)
     40static void hw_res_parse_add_dma_channel(hw_res_list_parsed_t *out,
     41    const hw_resource_t *res, int flags)
     42{
     43        assert(res);
     44        assert((res->type == DMA_CHANNEL_8) || (res->type == DMA_CHANNEL_16));
     45       
     46        const unsigned channel = (res->type == DMA_CHANNEL_8) ?
     47            res->res.dma_channel.dma8 : res->res.dma_channel.dma16;
     48        const size_t count = out->dma_channels.count;
     49        const int keep_duplicit = flags & HW_RES_KEEP_DUPLICIT;
     50       
     51        if (!keep_duplicit) {
     52                for (size_t i = 0; i < count; ++i) {
     53                        if (out->dma_channels.channels[i] == channel)
     54                                return;
     55                }
     56        }
     57       
     58        out->dma_channels.channels[count] = channel;
     59        ++out->dma_channels.count;
     60}
     61
     62static void hw_res_parse_add_irq(hw_res_list_parsed_t *out,
     63    const hw_resource_t *res, int flags)
    4264{
    4365        assert(res && (res->type == INTERRUPT));
     
    5981
    6082static void hw_res_parse_add_io_range(hw_res_list_parsed_t *out,
    61     hw_resource_t *res, int flags)
     83    const hw_resource_t *res, int flags)
    6284{
    6385        assert(res && (res->type == IO_RANGE));
     
    90112
    91113static void hw_res_parse_add_mem_range(hw_res_list_parsed_t *out,
    92     hw_resource_t *res, int flags)
     114    const hw_resource_t *res, int flags)
    93115{
    94116        assert(res && (res->type == MEM_RANGE));
     
    132154 *
    133155 */
    134 int hw_res_list_parse(hw_resource_list_t *hw_resources,
     156int hw_res_list_parse(const hw_resource_list_t *hw_resources,
    135157    hw_res_list_parsed_t *out, int flags)
    136158{
     
    141163        hw_res_list_parsed_clean(out);
    142164       
    143         out->irqs.irqs = malloc(res_count * sizeof(int));
    144         out->io_ranges.ranges = malloc(res_count * sizeof(io_range_t));
    145         out->mem_ranges.ranges = malloc(res_count * sizeof(mem_range_t));
     165        out->irqs.irqs = calloc(res_count, sizeof(int));
     166        out->dma_channels.channels = calloc(res_count, sizeof(int));
     167        out->io_ranges.ranges = calloc(res_count, sizeof(io_range_t));
     168        out->mem_ranges.ranges = calloc(res_count, sizeof(mem_range_t));
     169        if (!out->irqs.irqs || !out->dma_channels.channels ||
     170            !out->io_ranges.ranges || !out->mem_ranges.ranges) {
     171                hw_res_list_parsed_clean(out);
     172                return ENOMEM;
     173        }
    146174       
    147175        for (size_t i = 0; i < res_count; ++i) {
    148                 hw_resource_t *resource = &(hw_resources->resources[i]);
    149                
     176                const hw_resource_t *resource = &(hw_resources->resources[i]);
     177
    150178                switch (resource->type) {
    151179                case INTERRUPT:
     
    158186                        hw_res_parse_add_mem_range(out, resource, flags);
    159187                        break;
     188                case DMA_CHANNEL_8:
     189                case DMA_CHANNEL_16:
     190                        hw_res_parse_add_dma_channel(out, resource, flags);
     191                        break;
    160192                default:
     193                        hw_res_list_parsed_clean(out);
    161194                        return EINVAL;
    162195                }
    163196        }
    164        
     197
    165198        return EOK;
    166199};
  • uspace/lib/c/generic/inet/addr.c

    r0ee999d r5856b627  
    5252};
    5353
     54static const addr48_t inet_addr48_solicited_node = {
     55        0x33, 0x33, 0xff, 0, 0, 0
     56};
     57
    5458static const inet_addr_t inet_addr_any_addr = {
    5559        .family = AF_INET,
     
    7276}
    7377
     78int addr48_compare(const addr48_t a, const addr48_t b)
     79{
     80        return memcmp(a, b, 6);
     81}
     82
    7483int addr128_compare(const addr128_t a, const addr128_t b)
    7584{
    7685        return memcmp(a, b, 16);
     86}
     87
     88/** Compute solicited node MAC multicast address from target IPv6 address
     89 *
     90 * @param ip  Target IPv6 address
     91 * @param mac Solicited MAC address to be assigned
     92 *
     93 */
     94void addr48_solicited_node(const addr128_t ip, addr48_t mac)
     95{
     96        memcpy(mac, inet_addr48_solicited_node, 3);
     97        memcpy(mac + 3, ip + 13, 3);
    7798}
    7899
  • uspace/lib/c/include/async.h

    r0ee999d r5856b627  
    399399extern int async_data_read_start(async_exch_t *, void *, size_t);
    400400extern bool async_data_read_receive(ipc_callid_t *, size_t *);
     401extern bool async_data_read_receive_call(ipc_callid_t *, ipc_call_t *, size_t *);
    401402extern int async_data_read_finalize(ipc_callid_t, const void *, size_t);
    402403
     
    437438extern int async_data_write_start(async_exch_t *, const void *, size_t);
    438439extern bool async_data_write_receive(ipc_callid_t *, size_t *);
     440extern bool async_data_write_receive_call(ipc_callid_t *, ipc_call_t *, size_t *);
    439441extern int async_data_write_finalize(ipc_callid_t, void *, size_t);
    440442
  • uspace/lib/c/include/device/hw_res.h

    r0ee999d r5856b627  
    5353        HW_RES_ENABLE_INTERRUPT,
    5454        HW_RES_DMA_CHANNEL_SETUP,
     55        HW_RES_DMA_CHANNEL_REMAIN,
    5556} hw_res_method_t;
    5657
     
    115116
    116117extern int hw_res_dma_channel_setup(async_sess_t *, unsigned int, uint32_t,
    117     uint16_t, uint8_t);
     118    uint32_t, uint8_t);
     119extern int hw_res_dma_channel_remain(async_sess_t *, unsigned);
    118120
    119121#endif
  • uspace/lib/c/include/device/hw_res_parsed.h

    r0ee999d r5856b627  
    139139}
    140140
    141 extern int hw_res_list_parse(hw_resource_list_t *, hw_res_list_parsed_t *, int);
     141extern int hw_res_list_parse(
     142    const hw_resource_list_t *, hw_res_list_parsed_t *, int);
    142143extern int hw_res_get_list_parsed(async_sess_t *, hw_res_list_parsed_t *, int);
    143144
  • uspace/lib/c/include/inet/addr.h

    r0ee999d r5856b627  
    7373extern void addr128(const addr128_t, addr128_t);
    7474
     75extern int addr48_compare(const addr48_t, const addr48_t);
    7576extern int addr128_compare(const addr128_t, const addr128_t);
     77
     78extern void addr48_solicited_node(const addr128_t, addr48_t);
    7679
    7780extern void host2addr128_t_be(const addr128_t, addr128_t);
  • uspace/lib/c/include/ipc/dev_iface.h

    r0ee999d r5856b627  
    3636typedef enum {
    3737        HW_RES_DEV_IFACE = 0,
     38
     39        /** Audio device mixer interface */
     40        AUDIO_MIXER_IFACE,
     41        /** Audio device pcm buffer interface */
     42        AUDIO_PCM_BUFFER_IFACE,
     43
    3844        /** Character device interface */
    3945        CHAR_DEV_IFACE,
Note: See TracChangeset for help on using the changeset viewer.