--- /dev/null
+/*
+ * UDI Ne2000 NIC Driver
+ * By John Hodge (thePowersGang)
+ *
+ * uart16c550.c
+ * - UDI initialisation
+ */
+#include <udi.h>
+#include <udi_physio.h>
+#include "uart16c550_common.h"
+
+
+#include "uart16c550_pio.h"
+
+#define __EXPJOIN(a,b) a##b
+#define _EXPJOIN(a,b) __EXPJOIN(a,b)
+#define CONTIN(suffix, call, params, args...) extern void _EXPJOIN(suffix##__,__LINE__) params;\
+ call(_EXPJOIN(suffix##__,__LINE__), gcb,## args); } \
+ void _EXPJOIN(suffix##__,__LINE__) params { \
+ rdata_t *rdata = gcb->context;
+
+// --- Management Metalang
+void uart_usage_ind(udi_usage_cb_t *cb, udi_ubit8_t resource_level)
+{
+ rdata_t *rdata = UDI_GCB(cb)->context;
+
+ // TODO: Set up region data
+
+ udi_usage_res(cb);
+}
+
+void uart_enumerate_req(udi_enumerate_cb_t *cb, udi_ubit8_t enumeration_level)
+{
+ rdata_t *rdata = UDI_GCB(cb)->context;
+ udi_instance_attr_list_t *attr_list = cb->attr_list;
+
+ switch(enumeration_level)
+ {
+ case UDI_ENUMERATE_START:
+ case UDI_ENUMERATE_START_RESCAN:
+ DPT_SET_ATTR_STRING(attr_list, "if_num", "uart", 4);
+ attr_list ++;
+ cb->attr_valid_length = attr_list - cb->attr_list;
+ udi_enumerate_ack(cb, UDI_ENUMERATE_OK, UART_OPS_GIO);
+ break;
+ case UDI_ENUMERATE_NEXT:
+ udi_enumerate_ack(cb, UDI_ENUMERATE_DONE, 0);
+ break;
+ }
+}
+void uart_devmgmt_req(udi_mgmt_cb_t *cb, udi_ubit8_t mgmt_op, udi_ubit8_t parent_ID)
+{
+}
+void uart_final_cleanup_req(udi_mgmt_cb_t *cb)
+{
+}
+// ---
+void uart_bus_dev_channel_event_ind(udi_channel_event_cb_t *cb);
+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);
+void uart_bus_dev_bind__pio_map(udi_cb_t *cb, udi_pio_handle_t new_pio_handle);
+void uart_bus_dev_bind__intr_chanel(udi_cb_t *gcb, udi_channel_t new_channel);
+void uart_bus_dev_bus_unbind_ack(udi_bus_bind_cb_t *cb);
+
+void uart_bus_dev_channel_event_ind(udi_channel_event_cb_t *cb)
+{
+ udi_cb_t *gcb = UDI_GCB(cb);
+ rdata_t *rdata = gcb->context;
+
+ switch(cb->event)
+ {
+ case UDI_CHANNEL_CLOSED:
+ break;
+ case UDI_CHANNEL_BOUND: {
+ rdata->active_cb = gcb;
+ udi_bus_bind_cb_t *bus_bind_cb = UDI_MCB(cb->params.parent_bound.bind_cb, udi_bus_bind_cb_t);
+ udi_bus_bind_req( bus_bind_cb );
+ // continue at uart_bus_dev_bus_bind_ack
+ return; }
+ }
+}
+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)
+{
+ udi_cb_t *gcb = UDI_GCB(cb);
+ rdata_t *rdata = gcb->context;
+
+ // Set up PIO handles
+ rdata->init.pio_index = -1;
+ uart_bus_dev_bind__pio_map(gcb, UDI_NULL_PIO_HANDLE);
+ // V V V V
+}
+void uart_bus_dev_bind__pio_map(udi_cb_t *gcb, udi_pio_handle_t new_pio_handle)
+{
+ rdata_t *rdata = gcb->context;
+ if( rdata->init.pio_index != -1 )
+ {
+ rdata->pio_handles[rdata->init.pio_index] = new_pio_handle;
+ }
+
+ rdata->init.pio_index ++;
+ if( rdata->init.pio_index < N_PIO )
+ {
+ udi_pio_map(uart_bus_dev_bind__pio_map, gcb,
+ UDI_PCI_BAR_0, 0, 0x8, // TODO: Use system bus index and offset
+ uart_pio_ops[rdata->init.pio_index].trans_list,
+ uart_pio_ops[rdata->init.pio_index].list_length,
+ UDI_PIO_LITTLE_ENDIAN, 0, 0
+ );
+ return ;
+ }
+
+ CONTIN( uart_bus_dev_bind, udi_channel_spawn, (udi_cb_t *gcb, udi_channel_t new_channel), gcb->channel, 0, UART_OPS_IRQ, rdata)
+// udi_channel_spawn(uart_bus_dev_bind__intr_chanel, gcb, gcb->channel, 0, UART_OPS_IRQ, rdata);
+//}
+//void uart_bus_dev_bind__intr_chanel(udi_cb_t *gcb, udi_channel_t new_channel)
+//{
+// rdata_t *rdata = gcb->context;
+
+ rdata->interrupt_channel = new_channel;
+
+ CONTIN( uart_bus_dev_bind, udi_cb_alloc, (udi_cb_t *gcb, udi_cb_t *new_cb), UART_CB_INTR, gcb->channel)
+// udi_cb_alloc(uart_bus_dev_bind__intr_attach, gcb, NE2K_CB_INTR, gcb->channel);
+// // V V V V
+//}
+//void uart_bus_dev_bind__intr_attach(udi_cb_t *gcb, udi_cb_t *new_cb)
+//{
+// rdata_t *rdata = gcb->context;
+ if( !new_cb )
+ {
+ // Oh...
+ udi_channel_event_complete( UDI_MCB(rdata->active_cb, udi_channel_event_cb_t),
+ UDI_STAT_RESOURCE_UNAVAIL );
+ return ;
+ }
+ udi_intr_attach_cb_t *intr_cb = UDI_MCB(new_cb, udi_intr_attach_cb_t);
+ intr_cb->interrupt_idx = 0;
+ intr_cb->min_event_pend = 2;
+ intr_cb->preprocessing_handle = rdata->pio_handles[PIO_RX];
+ udi_intr_attach_req(intr_cb);
+ // continued in uart_bus_dev_intr_attach_ack
+}
+void uart_bus_dev_bus_unbind_ack(udi_bus_bind_cb_t *cb)
+{
+}
+void uart_bus_dev_intr_attach_ack(udi_intr_attach_cb_t *intr_attach_cb, udi_status_t status)
+{
+}
+void uart_bus_dev_intr_detach_ack(udi_intr_detach_cb_t *intr_detach_cb)
+{
+}
+// ---
+void uart_bus_irq_channel_event_ind(udi_channel_event_cb_t *cb)
+{
+}
+void uart_bus_irq_intr_event_ind(udi_intr_event_cb_t *cb, udi_ubit8_t flags)
+{
+ udi_debug_printf("%s: flags=%x, intr_result=%x\n", __func__, flags, cb->intr_result);
+ if( cb->intr_result & 0x01 )
+ {
+ //ne2k_intr__rx_ok( UDI_GCB(cb) );
+ }
+ // TODO: TX IRQs
+ udi_intr_event_rdy(cb);
+}
+// ---
+void uart_gio_prov_channel_event_ind(udi_channel_event_cb_t *cb)
+{
+}
+void uart_gio_prov_bind_req(udi_gio_bind_cb_t *cb)
+{
+}
+void uart_gio_prov_unbind_req(udi_gio_bind_cb_t *cb)
+{
+}
+void uart_gio_prov_xfer_req(udi_gio_xfer_cb_t *cb)
+{
+}
+void uart_gio_prov_event_res(udi_gio_event_cb_t *cb)
+{
+}
+
+// ====================================================================
+// - Management ops
+udi_mgmt_ops_t uart_mgmt_ops = {
+ uart_usage_ind,
+ uart_enumerate_req,
+ uart_devmgmt_req,
+ uart_final_cleanup_req
+};
+udi_ubit8_t uart_mgmt_op_flags[4] = {0,0,0,0};
+// - Bus Ops
+udi_bus_device_ops_t uart_bus_dev_ops = {
+ uart_bus_dev_channel_event_ind,
+ uart_bus_dev_bus_bind_ack,
+ uart_bus_dev_bus_unbind_ack,
+ uart_bus_dev_intr_attach_ack,
+ uart_bus_dev_intr_detach_ack
+};
+udi_ubit8_t uart_bus_dev_ops_flags[5] = {0};
+// - IRQ Ops
+udi_intr_handler_ops_t uart_bus_irq_ops = {
+ uart_bus_irq_channel_event_ind,
+ uart_bus_irq_intr_event_ind
+};
+udi_ubit8_t uart_bus_irq_ops_flags[2] = {0};
+// - GIO provider ops
+udi_gio_provider_ops_t uart_gio_prov_ops = {
+ uart_gio_prov_channel_event_ind,
+ uart_gio_prov_bind_req,
+ uart_gio_prov_unbind_req,
+ uart_gio_prov_xfer_req,
+ uart_gio_prov_event_res
+};
+udi_ubit8_t uart_gio_prov_ops_flags[5] = {0};
+// --
+udi_primary_init_t uart_pri_init = {
+ .mgmt_ops = &uart_mgmt_ops,
+ .mgmt_op_flags = uart_mgmt_op_flags,
+ .mgmt_scratch_requirement = 0,
+ .enumeration_attr_list_length = 4,
+ .rdata_size = sizeof(rdata_t),
+ .child_data_size = 0,
+ .per_parent_paths = 0
+};
+udi_ops_init_t uart_ops_list[] = {
+ {
+ UART_OPS_DEV, UART_META_BUS, UDI_BUS_DEVICE_OPS_NUM,
+ 0,
+ (udi_ops_vector_t*)&uart_bus_dev_ops,
+ uart_bus_dev_ops_flags
+ },
+ {
+ UART_OPS_IRQ, UART_META_BUS, UDI_BUS_INTR_HANDLER_OPS_NUM,
+ 0,
+ (udi_ops_vector_t*)&uart_bus_irq_ops,
+ uart_bus_irq_ops_flags
+ },
+ {
+ UART_OPS_GIO, UART_META_GIO, UDI_GIO_PROVIDER_OPS_NUM,
+ 0,
+ (udi_ops_vector_t*)&uart_gio_prov_ops,
+ uart_gio_prov_ops_flags
+ },
+ {0}
+};
+udi_cb_init_t uart_cb_init_list[] = {
+ {UART_CB_BUS_BIND, UART_META_BUS, UDI_BUS_BIND_CB_NUM, 0, 0,NULL},
+ {UART_CB_INTR, UART_META_BUS, UDI_BUS_INTR_ATTACH_CB_NUM, 0, 0,NULL},
+ {UART_CB_INTR_EVENT, UART_META_BUS, UDI_BUS_INTR_EVENT_CB_NUM, 0, 0,NULL},
+ {0}
+};
+const udi_init_t udi_init_info = {
+ .primary_init_info = &uart_pri_init,
+ .ops_init_list = uart_ops_list,
+ .cb_init_list = uart_cb_init_list,
+};
--- /dev/null
+#ifndef _UART16C550_COMMON_H_
+#define _UART16C550_COMMON_H_
+
+enum {
+ UART_OPS_DEV = 1,
+ UART_OPS_IRQ,
+ UART_OPS_GIO,
+};
+
+enum {
+ UART_CB_BUS_BIND = 1,
+ UART_CB_INTR,
+ UART_CB_INTR_EVENT,
+};
+
+enum {
+ PIO_RESET,
+ PIO_TX,
+ PIO_RX,
+ N_PIO
+};
+
+typedef struct {
+ udi_cb_t *active_cb;
+ struct {
+ udi_index_t pio_index;
+ } init;
+
+ udi_pio_handle_t pio_handles[N_PIO];
+ udi_channel_t interrupt_channel;
+} rdata_t;
+
+// === MACROS ===
+/* Copied from http://projectudi.cvs.sourceforge.net/viewvc/projectudi/udiref/driver/udi_dpt/udi_dpt.h */
+#define DPT_SET_ATTR_BOOLEAN(attr, name, val) \
+ udi_strcpy((attr)->attr_name, (name)); \
+ (attr)->attr_type = UDI_ATTR_BOOLEAN; \
+ (attr)->attr_length = sizeof(udi_boolean_t); \
+ UDI_ATTR32_SET((attr)->attr_value, (val))
+
+#define DPT_SET_ATTR32(attr, name, val) \
+ udi_strcpy((attr)->attr_name, (name)); \
+ (attr)->attr_type = UDI_ATTR_UBIT32; \
+ (attr)->attr_length = sizeof(udi_ubit32_t); \
+ UDI_ATTR32_SET((attr)->attr_value, (val))
+
+#define DPT_SET_ATTR_ARRAY8(attr, name, val, len) \
+ udi_strcpy((attr)->attr_name, (name)); \
+ (attr)->attr_type = UDI_ATTR_ARRAY8; \
+ (attr)->attr_length = (len); \
+ udi_memcpy((attr)->attr_value, (val), (len))
+
+#define DPT_SET_ATTR_STRING(attr, name, val, len) \
+ udi_strcpy((attr)->attr_name, (name)); \
+ (attr)->attr_type = UDI_ATTR_STRING; \
+ (attr)->attr_length = (len); \
+ udi_strncpy_rtrim((char *)(attr)->attr_value, (val), (len))
+#define NE2K_SET_ATTR_STRFMT(attr, name, maxlen, fmt, v...) \
+ udi_strcpy((attr)->attr_name, (name)); \
+ (attr)->attr_type = UDI_ATTR_STRING; \
+ (attr)->attr_length = udi_snprintf((char *)(attr)->attr_value, (maxlen), (fmt) ,## v )
+
+
+#endif