3 * \author John Hodge (thePowersGang)
7 #include <udi_physio.h>
8 #include "../udi_internal.h"
9 //#include <udi_internal/physio.h>
11 struct udi_dma_constraints_s
15 udi_dma_constraints_attr_spec_t attrs[];
19 EXPORT(udi_dma_constraints_attr_set);
20 EXPORT(udi_dma_constraints_attr_reset);
21 EXPORT(udi_dma_constraints_free);
24 void udi_dma_constraints_attr_set(udi_dma_constraints_attr_set_call_t *callback, udi_cb_t *gcb,
25 udi_dma_constraints_t src_constraints,
26 const udi_dma_constraints_attr_spec_t *attr_list, udi_ubit16_t list_length,
29 udi_dma_constraints_t ret;
30 if( !src_constraints )
33 ret = NEW_wA(struct udi_dma_constraints_s, attrs, list_length);
34 if(!ret) goto alloc_error;
35 ret->size = list_length;
40 udi_ubit8_t bm[256/8] = {0};
42 for( int i = 0; i < src_constraints->n_attrs; i ++ ) {
43 int idx = src_constraints->attrs[i].attr_type;
44 bm[idx/8] |= 1 << (idx%8);
46 udi_ubit16_t count = src_constraints->n_attrs;
47 for( int i = 0; i < list_length; i ++ ) {
48 int idx = attr_list[i].attr_type;
49 if(bm[idx/8] & 1 << (idx%8))
53 bm[idx/8] |= 1 << (idx%8);
57 if( flags & UDI_DMA_CONSTRAINTS_COPY )
60 ret = NEW_wA(struct udi_dma_constraints_s, attrs, count);
61 if(!ret) goto alloc_error;
63 ret->n_attrs = src_constraints->n_attrs;
64 memcpy(ret->attrs, src_constraints->attrs,
65 src_constraints->n_attrs*sizeof(ret->attrs[0]));
70 ret = realloc(src_constraints, sizeof(*ret)
71 + count*sizeof(ret->attrs[0]));
72 if(!ret) goto alloc_error;
78 for( int i = 0; i < list_length; i ++ )
81 for( j = 0; j < ret->n_attrs; j ++ )
83 if( ret->attrs[j].attr_type == attr_list[i].attr_type ) {
84 ret->attrs[j].attr_value = attr_list[i].attr_value;
88 if( j == ret->n_attrs )
90 ASSERTC(ret->n_attrs, !=, ret->size);
91 ret->attrs[j].attr_type = attr_list[i].attr_type;
92 ret->attrs[j].attr_value = attr_list[i].attr_value;
98 callback(gcb, ret, UDI_OK);
101 callback(gcb, NULL, UDI_STAT_RESOURCE_UNAVAIL);
104 void udi_dma_constraints_attr_reset(
105 udi_dma_constraints_t constraints,
106 udi_dma_constraints_attr_t attr_type
112 void udi_dma_constraints_free(udi_dma_constraints_t constraints)