2 * UDI Ne2000 NIC Driver
3 * By John Hodge (thePowersGang)
9 #include <udi_physio.h>
10 #include "uart16c550_common.h"
13 #include "uart16c550_pio.h"
15 #define __EXPJOIN(a,b) a##b
16 #define _EXPJOIN(a,b) __EXPJOIN(a,b)
17 #define CONTIN(suffix, call, params, args...) extern void _EXPJOIN(suffix##__,__LINE__) params;\
18 call(_EXPJOIN(suffix##__,__LINE__), gcb,## args); } \
19 void _EXPJOIN(suffix##__,__LINE__) params { \
20 rdata_t *rdata = gcb->context;
22 // --- Management Metalang
23 void uart_usage_ind(udi_usage_cb_t *cb, udi_ubit8_t resource_level)
25 rdata_t *rdata = UDI_GCB(cb)->context;
27 // TODO: Set up region data
32 void uart_enumerate_req(udi_enumerate_cb_t *cb, udi_ubit8_t enumeration_level)
34 rdata_t *rdata = UDI_GCB(cb)->context;
35 udi_instance_attr_list_t *attr_list = cb->attr_list;
37 switch(enumeration_level)
39 case UDI_ENUMERATE_START:
40 case UDI_ENUMERATE_START_RESCAN:
41 DPT_SET_ATTR_STRING(attr_list, "if_num", "uart", 4);
43 cb->attr_valid_length = attr_list - cb->attr_list;
44 udi_enumerate_ack(cb, UDI_ENUMERATE_OK, UART_OPS_GIO);
46 case UDI_ENUMERATE_NEXT:
47 udi_enumerate_ack(cb, UDI_ENUMERATE_DONE, 0);
51 void uart_devmgmt_req(udi_mgmt_cb_t *cb, udi_ubit8_t mgmt_op, udi_ubit8_t parent_ID)
54 void uart_final_cleanup_req(udi_mgmt_cb_t *cb)
58 void uart_bus_dev_channel_event_ind(udi_channel_event_cb_t *cb);
59 void uart_bus_dev_bus_bind_ack(udi_bus_bind_cb_t *cb, udi_dma_constraints_t dma_constraints, udi_ubit8_t perferred_endianness, udi_status_t status);
60 void uart_bus_dev_bind__pio_map(udi_cb_t *cb, udi_pio_handle_t new_pio_handle);
61 void uart_bus_dev_bind__intr_chanel(udi_cb_t *gcb, udi_channel_t new_channel);
62 void uart_bus_dev_bus_unbind_ack(udi_bus_bind_cb_t *cb);
64 void uart_bus_dev_channel_event_ind(udi_channel_event_cb_t *cb)
66 udi_cb_t *gcb = UDI_GCB(cb);
67 rdata_t *rdata = gcb->context;
71 case UDI_CHANNEL_CLOSED:
73 case UDI_CHANNEL_BOUND: {
74 rdata->active_cb = gcb;
75 udi_bus_bind_cb_t *bus_bind_cb = UDI_MCB(cb->params.parent_bound.bind_cb, udi_bus_bind_cb_t);
76 udi_bus_bind_req( bus_bind_cb );
77 // continue at uart_bus_dev_bus_bind_ack
81 void uart_bus_dev_bus_bind_ack(udi_bus_bind_cb_t *cb,
82 udi_dma_constraints_t dma_constraints, udi_ubit8_t perferred_endianness, udi_status_t status)
84 udi_cb_t *gcb = UDI_GCB(cb);
85 rdata_t *rdata = gcb->context;
88 rdata->init.pio_index = -1;
89 uart_bus_dev_bind__pio_map(gcb, UDI_NULL_PIO_HANDLE);
92 void uart_bus_dev_bind__pio_map(udi_cb_t *gcb, udi_pio_handle_t new_pio_handle)
94 rdata_t *rdata = gcb->context;
95 if( rdata->init.pio_index != -1 )
97 rdata->pio_handles[rdata->init.pio_index] = new_pio_handle;
100 rdata->init.pio_index ++;
101 if( rdata->init.pio_index < N_PIO )
103 udi_pio_map(uart_bus_dev_bind__pio_map, gcb,
104 UDI_PCI_BAR_0, 0, 0x8, // TODO: Use system bus index and offset
105 uart_pio_ops[rdata->init.pio_index].trans_list,
106 uart_pio_ops[rdata->init.pio_index].list_length,
107 UDI_PIO_LITTLE_ENDIAN, 0, 0
112 CONTIN( uart_bus_dev_bind, udi_channel_spawn, (udi_cb_t *gcb, udi_channel_t new_channel), gcb->channel, 0, UART_OPS_IRQ, rdata)
113 // udi_channel_spawn(uart_bus_dev_bind__intr_chanel, gcb, gcb->channel, 0, UART_OPS_IRQ, rdata);
115 //void uart_bus_dev_bind__intr_chanel(udi_cb_t *gcb, udi_channel_t new_channel)
117 // rdata_t *rdata = gcb->context;
119 rdata->interrupt_channel = new_channel;
121 CONTIN( uart_bus_dev_bind, udi_cb_alloc, (udi_cb_t *gcb, udi_cb_t *new_cb), UART_CB_INTR, gcb->channel)
122 // udi_cb_alloc(uart_bus_dev_bind__intr_attach, gcb, NE2K_CB_INTR, gcb->channel);
125 //void uart_bus_dev_bind__intr_attach(udi_cb_t *gcb, udi_cb_t *new_cb)
127 // rdata_t *rdata = gcb->context;
131 udi_channel_event_complete( UDI_MCB(rdata->active_cb, udi_channel_event_cb_t),
132 UDI_STAT_RESOURCE_UNAVAIL );
135 udi_intr_attach_cb_t *intr_cb = UDI_MCB(new_cb, udi_intr_attach_cb_t);
136 intr_cb->interrupt_idx = 0;
137 intr_cb->min_event_pend = 2;
138 intr_cb->preprocessing_handle = rdata->pio_handles[PIO_RX];
139 udi_intr_attach_req(intr_cb);
140 // continued in uart_bus_dev_intr_attach_ack
142 void uart_bus_dev_bus_unbind_ack(udi_bus_bind_cb_t *cb)
145 void uart_bus_dev_intr_attach_ack(udi_intr_attach_cb_t *intr_attach_cb, udi_status_t status)
148 void uart_bus_dev_intr_detach_ack(udi_intr_detach_cb_t *intr_detach_cb)
152 void uart_bus_irq_channel_event_ind(udi_channel_event_cb_t *cb)
155 void uart_bus_irq_intr_event_ind(udi_intr_event_cb_t *cb, udi_ubit8_t flags)
157 udi_debug_printf("%s: flags=%x, intr_result=%x\n", __func__, flags, cb->intr_result);
158 if( cb->intr_result & 0x01 )
160 //ne2k_intr__rx_ok( UDI_GCB(cb) );
163 udi_intr_event_rdy(cb);
166 void uart_gio_prov_channel_event_ind(udi_channel_event_cb_t *cb)
169 void uart_gio_prov_bind_req(udi_gio_bind_cb_t *cb)
172 void uart_gio_prov_unbind_req(udi_gio_bind_cb_t *cb)
175 void uart_gio_prov_xfer_req(udi_gio_xfer_cb_t *cb)
178 void uart_gio_prov_event_res(udi_gio_event_cb_t *cb)
182 // ====================================================================
184 udi_mgmt_ops_t uart_mgmt_ops = {
188 uart_final_cleanup_req
190 udi_ubit8_t uart_mgmt_op_flags[4] = {0,0,0,0};
192 udi_bus_device_ops_t uart_bus_dev_ops = {
193 uart_bus_dev_channel_event_ind,
194 uart_bus_dev_bus_bind_ack,
195 uart_bus_dev_bus_unbind_ack,
196 uart_bus_dev_intr_attach_ack,
197 uart_bus_dev_intr_detach_ack
199 udi_ubit8_t uart_bus_dev_ops_flags[5] = {0};
201 udi_intr_handler_ops_t uart_bus_irq_ops = {
202 uart_bus_irq_channel_event_ind,
203 uart_bus_irq_intr_event_ind
205 udi_ubit8_t uart_bus_irq_ops_flags[2] = {0};
206 // - GIO provider ops
207 udi_gio_provider_ops_t uart_gio_prov_ops = {
208 uart_gio_prov_channel_event_ind,
209 uart_gio_prov_bind_req,
210 uart_gio_prov_unbind_req,
211 uart_gio_prov_xfer_req,
212 uart_gio_prov_event_res
214 udi_ubit8_t uart_gio_prov_ops_flags[5] = {0};
216 udi_primary_init_t uart_pri_init = {
217 .mgmt_ops = &uart_mgmt_ops,
218 .mgmt_op_flags = uart_mgmt_op_flags,
219 .mgmt_scratch_requirement = 0,
220 .enumeration_attr_list_length = 4,
221 .rdata_size = sizeof(rdata_t),
222 .child_data_size = 0,
223 .per_parent_paths = 0
225 udi_ops_init_t uart_ops_list[] = {
227 UART_OPS_DEV, UART_META_BUS, UDI_BUS_DEVICE_OPS_NUM,
229 (udi_ops_vector_t*)&uart_bus_dev_ops,
230 uart_bus_dev_ops_flags
233 UART_OPS_IRQ, UART_META_BUS, UDI_BUS_INTR_HANDLER_OPS_NUM,
235 (udi_ops_vector_t*)&uart_bus_irq_ops,
236 uart_bus_irq_ops_flags
239 UART_OPS_GIO, UART_META_GIO, UDI_GIO_PROVIDER_OPS_NUM,
241 (udi_ops_vector_t*)&uart_gio_prov_ops,
242 uart_gio_prov_ops_flags
246 udi_cb_init_t uart_cb_init_list[] = {
247 {UART_CB_BUS_BIND, UART_META_BUS, UDI_BUS_BIND_CB_NUM, 0, 0,NULL},
248 {UART_CB_INTR, UART_META_BUS, UDI_BUS_INTR_ATTACH_CB_NUM, 0, 0,NULL},
249 {UART_CB_INTR_EVENT, UART_META_BUS, UDI_BUS_INTR_EVENT_CB_NUM, 0, 0,NULL},
252 const udi_init_t udi_init_info = {
253 .primary_init_info = &uart_pri_init,
254 .ops_init_list = uart_ops_list,
255 .cb_init_list = uart_cb_init_list,