Modules/UDI - PIO and better instance startup
[tpg/acess2.git] / KernelLand / Modules / Interfaces / UDI / include / udi_internal.h
1 /*
2  * Acess2 UDI Layer
3  * - By John Hodge (thePowersGang)
4  *
5  * udi_internal.h
6  * - Definitions for opaque structures
7  */
8 #ifndef _UDI_INTERNAL_H_
9 #define _UDI_INTERNAL_H_
10
11 #include <stdbool.h>
12
13 #define NEW(type,extra) (type*)calloc(sizeof(type)extra,1)
14 #define NEW_wA(type,fld,cnt)    NEW(type,+(sizeof(((type*)NULL)->fld[0])*cnt))
15
16 typedef struct sUDI_PropMessage         tUDI_PropMessage;
17 typedef struct sUDI_PropRegion  tUDI_PropRegion;
18 typedef struct sUDI_PropDevSpec tUDI_PropDevSpec;
19
20 typedef const struct sUDI_MetaLang      tUDI_MetaLang;
21
22 typedef struct sUDI_MetaLangRef         tUDI_MetaLangRef;
23 typedef struct sUDI_BindOps     tUDI_BindOps;
24
25 typedef struct sUDI_DriverModule        tUDI_DriverModule;
26 typedef struct sUDI_DriverInstance      tUDI_DriverInstance;
27 typedef struct sUDI_DriverRegion        tUDI_DriverRegion;
28
29 typedef struct sUDI_ChildBinding        tUDI_ChildBinding;
30
31 struct sUDI_PropMessage
32 {
33          int    locale;
34         udi_ubit16_t    index;
35         const char      *string;
36 };
37
38 struct sUDI_PropRegion
39 {
40         udi_index_t     RegionIdx;
41         enum {
42                 UDI_REGIONTYPE_NORMAL,
43                 UDI_REGIONTYPE_FP,
44         }       Type;
45         enum {
46                 UDI_REGIONBINDING_STATIC,
47                 UDI_REGIONBINDING_DYNAMIC,
48         }       Binding;
49         enum {
50                 UDI_REGIONPRIO_MED,
51                 UDI_REGIONPRIO_LO,
52                 UDI_REGIONPRIO_HI,
53         }       Priority;
54         enum {
55                 UDI_REGIONLATENCY_NONOVERRRUNABLE,
56                 UDI_REGIONLATENCY_POWERFAIL,
57                 UDI_REGIONLATENCY_OVERRUNNABLE,
58                 UDI_REGIONLATENCY_RETRYABLE,
59                 // non_overrunable
60                 UDI_REGIONLATENCY_NONCTRITICAL,
61         }       Latency;
62         udi_ubit32_t    OverrunTime;
63
64         udi_index_t     BindMeta;
65         udi_index_t     PriBindOps;
66         udi_index_t     SecBindOps;
67         udi_index_t     BindCb;
68 };
69
70 struct sUDI_MetaLang
71 {
72         const char *Name;
73          int    nCbTypes;
74         struct {
75                 udi_size_t      Size;
76                 udi_layout_t    *Layout;
77         } CbTypes[];
78 };
79
80 struct sUDI_MetaLangRef
81 {
82         udi_ubit8_t     meta_idx;
83         const char      *interface_name;
84         tUDI_MetaLang   *metalang;
85         // TODO: pointer to metalanguage structure
86 };
87
88 struct sUDI_BindOps
89 {
90         udi_ubit8_t     meta_idx;
91         udi_ubit8_t     region_idx;
92         udi_ubit8_t     ops_idx;
93         udi_ubit8_t     bind_cb_idx;
94 };
95
96 struct sUDI_PropDevSpec
97 {
98          int    MessageNum;
99         udi_ubit8_t     MetaIdx;
100         tUDI_MetaLang   *Metalang;
101          int    nAttribs;
102         udi_instance_attr_list_t        Attribs[];
103 };
104
105 struct sUDI_DriverModule
106 {
107         tUDI_DriverModule       *Next;
108         void    *Base;
109
110         udi_init_t      *InitInfo;
111
112         // Counts of arrays in InitInfo
113          int    nCBInit;
114          int    nOpsInit;
115                 
116         const char      *ModuleName;
117          int    nMessages;
118         tUDI_PropMessage        *Messages;      // Sorted list
119         
120          int    nRegionTypes;
121         tUDI_PropRegion *RegionTypes;
122
123          int    nMetaLangs;
124         tUDI_MetaLangRef        *MetaLangs;
125
126          int    nParents;
127         tUDI_BindOps    *Parents;
128         
129          int    nChildBindOps;
130         tUDI_BindOps    *ChildBindOps;
131
132          int    nDevices;
133         tUDI_PropDevSpec        **Devices;
134
135          int    nRegions;
136 };
137
138 struct sUDI_DriverInstance
139 {
140         struct sUDI_DriverInstance      *Next;
141         tUDI_DriverModule       *Module;
142         udi_channel_t   ManagementChannel;
143         tUDI_DriverInstance     *Parent;
144         tUDI_ChildBinding       *ParentChildBinding;
145
146          int    CurState;       // Current MA state
147         
148         tUDI_ChildBinding       *FirstChild;
149         tUDI_DriverRegion       *Regions[];
150 };
151
152 struct sUDI_DriverRegion
153 {
154         udi_init_context_t      *InitContext;
155 };
156
157 struct sUDI_ChildBinding
158 {
159         tUDI_ChildBinding       *Next;
160         
161         udi_ubit32_t    ChildID;
162         tUDI_MetaLang   *Metalang;
163         tUDI_BindOps    *BindOps;
164         
165         udi_ops_init_t  *Ops;
166         tUDI_DriverInstance     *BoundInstance;
167         
168          int    nAttribs;
169         udi_instance_attr_list_t        Attribs[];
170 };
171
172 // --- Metalanguages ---
173 extern tUDI_MetaLang    cMetaLang_Management;
174
175 // --- Index to pointer translation ---
176 extern udi_ops_init_t   *UDI_int_GetOps(tUDI_DriverInstance *Inst, udi_index_t index);
177 extern tUDI_MetaLang *UDI_int_GetMetaLang(tUDI_DriverInstance *Inst, udi_index_t meta_idx);
178
179 // --- Channels ---
180 extern udi_channel_t    UDI_CreateChannel_Blank(tUDI_MetaLang *metalang);
181 extern udi_channel_t    UDI_CreateChannel_Linked(udi_channel_t orig, udi_ubit8_t spawn_idx);
182 extern int      UDI_BindChannel_Raw(udi_channel_t channel, bool other_side, tUDI_DriverInstance *inst, udi_index_t region_idx, udi_index_t meta_ops_num,  void *context, const void *ops);
183 extern int      UDI_BindChannel(udi_channel_t channel, bool other_side, tUDI_DriverInstance *inst, udi_index_t ops, udi_index_t region, void *context, bool is_child_bind, udi_ubit32_t child_ID);
184 extern tUDI_DriverInstance      *UDI_int_ChannelGetInstance(udi_cb_t *gcb, bool other_side, udi_index_t *region_idx);
185 extern void     UDI_int_ChannelSetContext(udi_channel_t channel, void *context);
186 extern const void       *UDI_int_ChannelPrepForCall(udi_cb_t *gcb, tUDI_MetaLang *metalang, udi_index_t meta_ops_num);
187 extern void     UDI_int_ChannelFlip(udi_cb_t *gcb);
188 extern void     UDI_int_ChannelReleaseFromCall(udi_cb_t *gcb);
189
190 // --- Async Calls ---
191 typedef struct sUDI_DeferredCall        tUDI_DeferredCall;
192 typedef void    tUDI_DeferredUnmarshal(tUDI_DeferredCall *Call);
193 struct sUDI_DeferredCall
194 {
195         struct sUDI_DeferredCall        *Next;
196         tUDI_DeferredUnmarshal  *Unmarshal;
197         udi_cb_t        *cb;
198         udi_op_t        *Handler;
199         // ...
200 };
201 extern void     UDI_int_DeferredThread(void *unused);   // Worker started by main.c
202 extern void     UDI_int_AddDeferred(tUDI_DeferredCall *Call);
203 extern void     UDI_int_MakeDeferredCb(udi_cb_t *cb, udi_op_t *handler);
204
205 extern void     UDI_int_MakeDeferredCbU8(udi_cb_t *cb, udi_op_t *handler, udi_ubit8_t arg1);
206 extern void     UDI_int_MakeDeferredCbS(udi_cb_t *cb, udi_op_t *handler, udi_status_t status);
207
208 // --- CBs ---
209 extern void *udi_cb_alloc_internal(tUDI_DriverInstance *Inst, udi_ubit8_t bind_cb_idx, udi_channel_t channel);
210 extern udi_cb_t *udi_cb_alloc_internal_v(tUDI_MetaLang *Meta, udi_index_t MetaCBNum, size_t inline_size, size_t scratch_size, udi_channel_t channel);
211
212 // --- Attribute Management ---
213 extern udi_instance_attr_type_t udi_instance_attr_get_internal(udi_cb_t *gcb, const char *attr_name, udi_ubit32_t child_ID, void *attr_value, udi_size_t attr_length, udi_size_t *actual_length);
214
215 #endif
216

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