Changeset 5856b627 in mainline for uspace/lib/c/generic/device/hw_res_parsed.c
- Timestamp:
- 2013-08-20T12:36:48Z (12 years ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/device/hw_res_parsed.c
r0ee999d r5856b627 38 38 #include <errno.h> 39 39 40 static void hw_res_parse_add_irq(hw_res_list_parsed_t *out, hw_resource_t *res, 41 int flags) 40 static 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 62 static void hw_res_parse_add_irq(hw_res_list_parsed_t *out, 63 const hw_resource_t *res, int flags) 42 64 { 43 65 assert(res && (res->type == INTERRUPT)); … … 59 81 60 82 static 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) 62 84 { 63 85 assert(res && (res->type == IO_RANGE)); … … 90 112 91 113 static 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) 93 115 { 94 116 assert(res && (res->type == MEM_RANGE)); … … 132 154 * 133 155 */ 134 int hw_res_list_parse( hw_resource_list_t *hw_resources,156 int hw_res_list_parse(const hw_resource_list_t *hw_resources, 135 157 hw_res_list_parsed_t *out, int flags) 136 158 { … … 141 163 hw_res_list_parsed_clean(out); 142 164 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 } 146 174 147 175 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 150 178 switch (resource->type) { 151 179 case INTERRUPT: … … 158 186 hw_res_parse_add_mem_range(out, resource, flags); 159 187 break; 188 case DMA_CHANNEL_8: 189 case DMA_CHANNEL_16: 190 hw_res_parse_add_dma_channel(out, resource, flags); 191 break; 160 192 default: 193 hw_res_list_parsed_clean(out); 161 194 return EINVAL; 162 195 } 163 196 } 164 197 165 198 return EOK; 166 199 };
Note:
See TracChangeset
for help on using the changeset viewer.