Modules/UDI - Cleaned up source layout, implemented PCI IRQs
[tpg/acess2.git] / KernelLand / Modules / Interfaces / UDI / udi_lib / physio.c
1 /**
2  * \file physio.c
3  * \author John Hodge (thePowersGang)
4  */
5 #include <acess.h>
6 #include <udi.h>
7 #include <udi_physio.h>
8 #include <udi_internal.h>
9 //#include <udi_internal_physio.h>
10
11 struct udi_dma_constraints_s
12 {
13         udi_ubit16_t    size;
14         udi_ubit16_t    n_attrs;
15         udi_dma_constraints_attr_spec_t attrs[];
16 };
17
18 // === EXPORTS ===
19 EXPORT(udi_dma_constraints_attr_set);
20 EXPORT(udi_dma_constraints_attr_reset);
21 EXPORT(udi_dma_constraints_free);
22
23 // === CODE ===
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,
27         udi_ubit8_t flags)
28 {
29         udi_dma_constraints_t   ret;
30         if( !src_constraints )
31         {
32                 // Allocate new
33                 ret = NEW_wA(struct udi_dma_constraints_s, attrs, list_length);
34                 if(!ret)        goto alloc_error;
35                 ret->size = list_length;
36                 ret->n_attrs = 0;
37         }
38         else
39         {
40                 udi_ubit8_t     bm[256/8] = {0};
41                 // Calculate new size
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);
45                 }
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))
50                                 ;
51                         else {
52                                 count ++;
53                                 bm[idx/8] |= 1 << (idx%8);
54                         }
55                 }
56                 
57                 if( flags & UDI_DMA_CONSTRAINTS_COPY )
58                 {
59                         // Duplicate
60                         ret = NEW_wA(struct udi_dma_constraints_s, attrs, count);
61                         if(!ret)        goto alloc_error;
62                         ret->size = count;
63                         ret->n_attrs = src_constraints->n_attrs;
64                         memcpy(ret->attrs, src_constraints->attrs,
65                                 src_constraints->n_attrs*sizeof(ret->attrs[0]));
66                 }
67                 else
68                 {
69                         // Expand
70                         ret = realloc(src_constraints, sizeof(*ret)
71                                 + count*sizeof(ret->attrs[0]));
72                         if(!ret)        goto alloc_error;
73                         ret->size = count;
74                 }
75         }
76         
77         // Begin populating
78         for( int i = 0; i < list_length; i ++ )
79         {
80                  int    j;
81                 for( j = 0; j < ret->n_attrs; j ++ )
82                 {
83                         if( ret->attrs[j].attr_type == attr_list[i].attr_type ) {
84                                 ret->attrs[j].attr_value = attr_list[i].attr_value;
85                                 break;
86                         }
87                 }
88                 if( j == ret->n_attrs )
89                 {
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;
93                         ret->n_attrs ++;
94                 }
95                 
96         }
97         
98         callback(gcb, ret, UDI_OK);
99         return ;
100 alloc_error:
101         callback(gcb, NULL, UDI_STAT_RESOURCE_UNAVAIL);
102 }
103
104 void udi_dma_constraints_attr_reset(
105         udi_dma_constraints_t   constraints,
106         udi_dma_constraints_attr_t      attr_type
107         )
108 {
109         UNIMPLEMENTED();
110 }
111
112 void udi_dma_constraints_free(udi_dma_constraints_t constraints)
113 {
114         free(constraints);
115 }

UCC git Repository :: git.ucc.asn.au