Modules/UDI - Minor tweaks
[tpg/acess2.git] / KernelLand / Modules / Interfaces / UDI / udi_lib / physio / meta_bus.c
1 /**
2  * Acess2 UDI Layer
3  * - By John Hodge (thePowersGang)
4  *
5  * udi_lib/physio/meta_bus.c
6  * - Bus Bridge Metalanguage
7  */
8 #define DEBUG   1
9 #include <acess.h>
10 #include <udi.h>
11 #include <udi_physio.h>
12 #include "../../udi_internal.h"
13
14 // === GLOBALS ==
15 udi_layout_t    cMetaLang_BusBridge_IntrAttachCbLayout[] = {
16         UDI_DL_STATUS_T,
17         UDI_DL_UBIT8_T,
18         UDI_DL_ORIGIN_T,        // TODO: handle
19         0
20 };
21 tUDI_MetaLang   cMetaLang_BusBridge = {
22         "udi_bridge",
23         // CB Types
24         5,
25         {
26                 {0},    // 0: Empty
27                 {sizeof(udi_bus_bind_cb_t), NULL},      // Defined, but is just a gcb
28                 {sizeof(udi_intr_attach_cb_t), NULL},
29                 {sizeof(udi_intr_detach_cb_t), NULL},
30                 {sizeof(udi_intr_event_cb_t), NULL}
31         }
32 };
33
34 // === EXPORTS ===
35 EXPORT(udi_bus_unbind_req);
36 EXPORT(udi_bus_unbind_ack);
37 EXPORT(udi_bus_bind_req);
38 EXPORT(udi_bus_bind_ack);
39
40 #define PREP_OPS(type,ml,num)   const type *ops = UDI_int_ChannelPrepForCall(UDI_GCB(cb), ml, num); \
41         if(!ops) { Log_Warning("UDI", "%s on wrong channel type", __func__); return ; }
42
43 #define PREP_OPS_DEVICE const udi_bus_device_ops_t *ops = UDI_int_ChannelPrepForCall( UDI_GCB(cb), &cMetaLang_BusBridge, UDI_BUS_DEVICE_OPS_NUM ); \
44         if(!ops) { Log_Warning("UDI", "%s on wrong channel type", __func__); return ; }
45
46 // === CODE ===
47 void udi_bus_unbind_req(udi_bus_bind_cb_t *cb)
48 {
49         UNIMPLEMENTED();
50 }
51 void udi_bus_unbind_ack(udi_bus_bind_cb_t *cb)
52 {
53         UNIMPLEMENTED();
54 }
55
56 void udi_bus_bind_req(udi_bus_bind_cb_t *cb)
57 {
58         LOG("cb=%p{...}", cb);
59         PREP_OPS(udi_bus_bridge_ops_t, &cMetaLang_BusBridge, UDI_BUS_BRIDGE_OPS_NUM)
60         
61         UDI_int_MakeDeferredCb( UDI_GCB(cb), (udi_op_t*)ops->bus_bind_req_op );
62 }
63
64 struct marshalled_bus_bind_ack
65 {
66         tUDI_DeferredCall       Call;
67         udi_dma_constraints_t   dma_constraints;
68         udi_ubit8_t     preferred_endianness;
69         udi_status_t    status;
70 };
71
72 static void _unmarshal_bus_bind_ack(tUDI_DeferredCall *Call)
73 {
74         struct marshalled_bus_bind_ack *info = (void*)Call;
75         ((udi_bus_bind_ack_op_t*)Call->Handler)(
76                 UDI_MCB(Call->cb, udi_bus_bind_cb_t),
77                 info->dma_constraints,
78                 info->preferred_endianness,
79                 info->status);
80         free(info);
81 }
82
83 void udi_bus_bind_ack(
84         udi_bus_bind_cb_t       *cb,
85         udi_dma_constraints_t   dma_constraints,
86         udi_ubit8_t     preferred_endianness,
87         udi_status_t    status
88         )
89 {
90         LOG("cb=%p{...}, dma_constraints=%p, preferred_endianness=%i,status=%i",
91                 cb, dma_constraints, preferred_endianness, status);
92         PREP_OPS(udi_bus_device_ops_t, &cMetaLang_BusBridge, UDI_BUS_DEVICE_OPS_NUM)
93         
94         struct marshalled_bus_bind_ack *call = NEW(struct marshalled_bus_bind_ack,);
95         call->Call.Unmarshal = _unmarshal_bus_bind_ack;
96         call->Call.cb = UDI_GCB(cb);
97         call->Call.Handler = (udi_op_t*)ops->bus_bind_ack_op;
98         call->dma_constraints = dma_constraints;
99         call->preferred_endianness = preferred_endianness;
100         call->status = status;
101         UDI_int_AddDeferred(&call->Call);
102 }

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