Ignore:
Timestamp:
2013-09-17T19:51:20Z (11 years ago)
Author:
Jakub Klama <jakub.klama@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6ac3d27
Parents:
3efc35a (diff), ca62f86 (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 from launchpad branch.

File:
1 edited

Legend:

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

    r3efc35a rf7bb6d1  
    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]);
     176                const hw_resource_t *resource = &(hw_resources->resources[i]);
    149177               
    150178                switch (resource->type) {
     
    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                }
Note: See TracChangeset for help on using the changeset viewer.