Changeset 3a0a4d8 in mainline for uspace/lib/c/generic/device
- Timestamp:
- 2013-09-12T07:54:05Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/fix-logger-deadlock, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 95027b5
- Parents:
- 47f5a77 (diff), 64f3d3b (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. - Location:
- uspace/lib/c/generic/device
- Files:
-
- 1 added
- 2 edited
-
hw_res.c (modified) (3 diffs)
-
hw_res_parsed.c (modified) (6 diffs)
-
pio_window.c (added)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/device/hw_res.c
r47f5a77 r3a0a4d8 44 44 45 45 async_exch_t *exch = async_exchange_begin(sess); 46 46 47 int rc = async_req_1_1(exch, DEV_IFACE_ID(HW_RES_DEV_IFACE), 47 48 HW_RES_GET_RESOURCE_LIST, &count); … … 77 78 { 78 79 async_exch_t *exch = async_exchange_begin(sess); 80 79 81 int rc = async_req_1_0(exch, DEV_IFACE_ID(HW_RES_DEV_IFACE), 80 82 HW_RES_ENABLE_INTERRUPT); … … 84 86 } 85 87 88 /** Setup DMA channel to specified place and mode. 89 * 90 * @param channel DMA channel. 91 * @param pa Physical address of the buffer. 92 * @param size DMA buffer size. 93 * @param mode Mode of the DMA channel: 94 * - Read or Write 95 * - Allow automatic reset 96 * - Use address decrement instead of increment 97 * - Use SINGLE/BLOCK/ON DEMAND transfer mode 98 * 99 * @return Error code. 100 * 101 */ 102 int hw_res_dma_channel_setup(async_sess_t *sess, 103 unsigned channel, uint32_t pa, uint32_t size, uint8_t mode) 104 { 105 async_exch_t *exch = async_exchange_begin(sess); 106 107 const uint32_t packed = (channel & 0xffff) | (mode << 16); 108 const int ret = async_req_4_0(exch, DEV_IFACE_ID(HW_RES_DEV_IFACE), 109 HW_RES_DMA_CHANNEL_SETUP, packed, pa, size); 110 111 async_exchange_end(exch); 112 113 return ret; 114 } 115 116 /** Query remaining bytes in the buffer. 117 * 118 * @param channel DMA channel. 119 * 120 * @return Number of bytes remaining in the buffer if positive. 121 * @return Error code if negative. 122 * 123 */ 124 int hw_res_dma_channel_remain(async_sess_t *sess, unsigned channel) 125 { 126 async_exch_t *exch = async_exchange_begin(sess); 127 128 sysarg_t remain; 129 const int ret = async_req_2_1(exch, DEV_IFACE_ID(HW_RES_DEV_IFACE), 130 HW_RES_DMA_CHANNEL_REMAIN, channel, &remain); 131 132 async_exchange_end(exch); 133 134 if (ret == EOK) 135 return remain; 136 137 return ret; 138 } 139 86 140 /** @} 87 141 */ -
uspace/lib/c/generic/device/hw_res_parsed.c
r47f5a77 r3a0a4d8 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]);176 const hw_resource_t *resource = &(hw_resources->resources[i]); 149 177 150 178 switch (resource->type) { … … 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 }
Note:
See TracChangeset
for help on using the changeset viewer.
