From c5a0982ee5185d1384cecba05ec22892a9723f93 Mon Sep 17 00:00:00 2001 From: MelwareDE Date: Wed, 13 Apr 2011 10:39:05 +0000 Subject: [PATCH] Add support for host based protocol code --- divastreaming/chan_capi_divastreaming_utils.c | 3 ++- divastreaming/diva_segment_alloc_ifc.h | 2 +- divastreaming/diva_streaming_idi_host_ifc.h | 2 +- .../diva_streaming_idi_host_ifc_impl.c | 8 +++++--- .../diva_streaming_idi_host_rx_ifc_impl.c | 2 +- divastreaming/diva_streaming_manager.c | 19 +++++++++++++++++-- divastreaming/diva_streaming_manager.h | 3 ++- divastreaming/segment_alloc.c | 6 +++--- 8 files changed, 32 insertions(+), 13 deletions(-) diff --git a/divastreaming/chan_capi_divastreaming_utils.c b/divastreaming/chan_capi_divastreaming_utils.c index 4edb90f..e2623bf 100644 --- a/divastreaming/chan_capi_divastreaming_utils.c +++ b/divastreaming/chan_capi_divastreaming_utils.c @@ -217,7 +217,8 @@ void capi_DivaStreamingOn(struct capi_pvt *i, byte streamCommand, _cword message ret = diva_stream_create (&pE->diva_stream, NULL, 255, divaStreamingMessageRx, pE, trace_ident); if (ret == 0) { - byte* description = (byte*)pE->diva_stream->description (pE->diva_stream); + static byte addie[] = { 0x2d, 0x01, 0x00, 0x00 }; + byte* description = (byte*)pE->diva_stream->description (pE->diva_stream, addie, (byte)sizeof(addie)); MESSAGE_EXCHANGE_ERROR error; description[1] = streamCommand; diff --git a/divastreaming/diva_segment_alloc_ifc.h b/divastreaming/diva_segment_alloc_ifc.h index af8bb76..21853f5 100644 --- a/divastreaming/diva_segment_alloc_ifc.h +++ b/divastreaming/diva_segment_alloc_ifc.h @@ -33,7 +33,7 @@ typedef struct _diva_segment_alloc_access { void* (*segment_alloc)(struct _diva_segment_alloc* ifc, dword* lo, dword* hi); void (*segment_free)(struct _diva_segment_alloc* ifc, void* addr, dword lo, dword hi); dword (*get_segment_length)(struct _diva_segment_alloc* ifc); - void* (*map_address)(struct _diva_segment_alloc* ifc, dword lo, dword hi); + void* (*map_address)(struct _diva_segment_alloc* ifc, dword lo, dword hi, int map_host); void* (*umap_address)(struct _diva_segment_alloc* ifc, dword lo, dword hi, void* local); int (*write_address)(struct _diva_segment_alloc* ifc, dword lo, dword hi, dword data); void (*resource_removed)(struct _diva_segment_alloc* ifc); diff --git a/divastreaming/diva_streaming_idi_host_ifc.h b/divastreaming/diva_streaming_idi_host_ifc.h index e08443d..080f5d4 100644 --- a/divastreaming/diva_streaming_idi_host_ifc.h +++ b/divastreaming/diva_streaming_idi_host_ifc.h @@ -50,7 +50,7 @@ typedef struct _diva_streaming_idi_host_ifc_w_access { dword (*get_free)(const struct _diva_streaming_idi_host_ifc_w* ifc); dword (*get_length)(const struct _diva_streaming_idi_host_ifc_w* ifc); byte (*description)(struct _diva_streaming_idi_host_ifc_w* ifc, byte* dst, byte max_length); - int (*init)(struct _diva_streaming_idi_host_ifc_w* ifc, dword version, dword counter); + int (*init)(struct _diva_streaming_idi_host_ifc_w* ifc, dword version, dword counter, dword info); diva_streaming_idi_result_t (*sync)(struct _diva_streaming_idi_host_ifc_w* ifc, dword ident); diva_streaming_idi_result_t (*trace_ident)(struct _diva_streaming_idi_host_ifc_w* ifc); } diva_streaming_idi_host_ifc_w_access_t; diff --git a/divastreaming/diva_streaming_idi_host_ifc_impl.c b/divastreaming/diva_streaming_idi_host_ifc_impl.c index 335f7d4..6aa3539 100644 --- a/divastreaming/diva_streaming_idi_host_ifc_impl.c +++ b/divastreaming/diva_streaming_idi_host_ifc_impl.c @@ -43,7 +43,7 @@ static int write_message (struct _diva_streaming_idi_host_ifc_w* ifc, const void* data, dword data_length); static byte description (diva_streaming_idi_host_ifc_w_t* ifc, byte* dst, byte max_length); -static int init (struct _diva_streaming_idi_host_ifc_w* ifc, dword version, dword counter); +static int init (struct _diva_streaming_idi_host_ifc_w* ifc, dword version, dword counter, dword info); static diva_streaming_idi_result_t sync_req (struct _diva_streaming_idi_host_ifc_w* ifc, dword ident); static int ack_data (struct _diva_streaming_idi_host_ifc_w* ifc, dword length); static int ack_rx_data (struct _diva_streaming_idi_host_ifc_w* ifc, dword length, int flush_ack); @@ -322,13 +322,15 @@ static byte description (diva_streaming_idi_host_ifc_w_t* ifc, byte* dst, byte m return (length); } -static int init (struct _diva_streaming_idi_host_ifc_w* ifc, dword version, dword counter) { +static int init (struct _diva_streaming_idi_host_ifc_w* ifc, dword version, dword counter, dword info) { diva_segment_alloc_access_t* segment_alloc_access = diva_get_segment_alloc_ifc (ifc->segment_alloc); ifc->remote_counter_offset = counter % (4*1024); ifc->remote_counter_base = counter - ifc->remote_counter_offset; - ifc->remote_counter_mapped_base = segment_alloc_access->map_address (ifc->segment_alloc, ifc->remote_counter_base, 0); + ifc->remote_counter_mapped_base = segment_alloc_access->map_address (ifc->segment_alloc, + ifc->remote_counter_base, 0, + (info & DIVA_STREAMING_MANAGER_HOST_USER_MODE_STREAM) != 0); if (ifc->remote_counter_mapped_base != 0) { byte* p = ifc->remote_counter_mapped_base; ifc->remote_counter_mapped = (dword*)&p[ifc->remote_counter_offset]; diff --git a/divastreaming/diva_streaming_idi_host_rx_ifc_impl.c b/divastreaming/diva_streaming_idi_host_rx_ifc_impl.c index 9617c83..2b0e7e1 100644 --- a/divastreaming/diva_streaming_idi_host_rx_ifc_impl.c +++ b/divastreaming/diva_streaming_idi_host_rx_ifc_impl.c @@ -253,7 +253,7 @@ static int diva_streaming_idi_host_rx_process_message (struct _diva_streaming_id DBG_TRC(("version:%u counter:%08x info:%08x [%s]", version, counter, info, ifc->trace_ident)) - ifc->tx_ifc->init (ifc->tx, version, counter); + ifc->tx_ifc->init (ifc->tx, version, counter, info); ifc->tx_ifc->trace_ident (ifc->tx); ifc->notify_user_proc (ifc->user_context, DIVA_STREAM_MESSAGE_INIT << 8 | 0xffU, 0, 0, 0); } diff --git a/divastreaming/diva_streaming_manager.c b/divastreaming/diva_streaming_manager.c index 02a3edc..67b67a4 100644 --- a/divastreaming/diva_streaming_manager.c +++ b/divastreaming/diva_streaming_manager.c @@ -57,7 +57,7 @@ static diva_streaming_idi_result_t diva_stream_manager_release (struct _diva_str static diva_streaming_idi_result_t diva_stream_manager_release_stream (struct _diva_stream* ifc); static diva_streaming_idi_result_t diva_stream_manager_write (struct _diva_stream* ifc, dword message, const void* data, dword length); static diva_streaming_idi_result_t diva_stream_manager_wakeup (struct _diva_stream* ifc); -static const byte* diva_stream_manager_description (struct _diva_stream* ifc); +static const byte* diva_stream_manager_description (struct _diva_stream* ifc, const byte* addie, byte addielen); static diva_streaming_idi_result_t diva_stream_manager_sync_req (struct _diva_stream* ifc, dword ident); static diva_streaming_idi_result_t diva_stream_flush (struct _diva_stream* ifc); static dword diva_stream_get_tx_free (const struct _diva_stream* ifc); @@ -193,7 +193,7 @@ static diva_streaming_idi_result_t diva_stream_manager_wakeup (struct _diva_stre return (pI->rx_ifc->wakeup (pI->rx)); } -const byte* diva_stream_manager_description (struct _diva_stream* ifc) { +const byte* diva_stream_manager_description (struct _diva_stream* ifc, const byte* addie, byte addielen) { diva_stream_manager_t* pI = DIVAS_CONTAINING_RECORD(ifc, diva_stream_manager_t, ifc); byte length = 4, len_tx, len_rx; @@ -209,6 +209,21 @@ const byte* diva_stream_manager_description (struct _diva_stream* ifc) { pI->description[2] = len_rx+len_tx+1; /* Structure length */ pI->description[3] = 0; /* Version */ + if (addie != 0 && addielen != 0) { + byte* description = &pI->description[0]; + byte* start = &description[3]; + + start[0] |= 2U; + start = start + start[-1]; + memcpy (start, addie, addielen); + start += addielen; + *start++ = 0; + + description[2] += addielen+1; + description[0] += addielen+1; + length += addielen+1; + } + DBG_TRC(("description length %u [%s]", length, pI->trace_ident)) DBG_BLK(((void*)pI->description, length)) diff --git a/divastreaming/diva_streaming_manager.h b/divastreaming/diva_streaming_manager.h index baa2f99..7ce9ab5 100644 --- a/divastreaming/diva_streaming_manager.h +++ b/divastreaming/diva_streaming_manager.h @@ -33,7 +33,7 @@ typedef struct _diva_stream { diva_streaming_idi_result_t (*release_stream)(struct _diva_stream* ifc); /**< destroy stream */ diva_streaming_idi_result_t (*write)(struct _diva_stream* ifc, dword message, const void* data, dword length); /**< write data to stream */ diva_streaming_idi_result_t (*wakeup)(struct _diva_stream* ifc); - const byte* (*description)(struct _diva_stream* ifc); + const byte* (*description)(struct _diva_stream* ifc, const byte* addie, byte addielength); diva_streaming_idi_result_t (*sync)(struct _diva_stream* ifc, dword ident); diva_streaming_idi_result_t (*flush_stream)(struct _diva_stream* ifc); dword (*get_tx_free)(const struct _diva_stream* ifc); @@ -57,6 +57,7 @@ typedef struct _diva_stream { #define DIVA_STREAM_MESSAGE_INIT_ERROR 0x00000007 /** Stream init error */ #define DIVA_STREAM_MESSAGE_RELEASED 0x00000008 /** Not message, used internally */ +#define DIVA_STREAMING_MANAGER_HOST_USER_MODE_STREAM 0x40000000U diva_streaming_idi_result_t diva_stream_create_with_user_segment_alloc (struct _diva_stream** ifc, void* os_context, diff --git a/divastreaming/segment_alloc.c b/divastreaming/segment_alloc.c index f90c6f0..0f05846 100644 --- a/divastreaming/segment_alloc.c +++ b/divastreaming/segment_alloc.c @@ -80,7 +80,7 @@ static dword get_segment_length_proc(struct _diva_segment_alloc*); #if defined(DIVA_USERMODE) static int map_entry (struct _diva_segment_alloc* pI, diva_map_entry_t* pE); #endif -static void* map_address (struct _diva_segment_alloc* ifc, dword lo, dword hi); +static void* map_address (struct _diva_segment_alloc* ifc, dword lo, dword hi, int map_host); static void* umap_address (struct _diva_segment_alloc* ifc, dword lo, dword hi, void* local); static int write_address (struct _diva_segment_alloc* ifc, dword lo, dword hi, dword data); static void resource_removed (struct _diva_segment_alloc* ifc); @@ -331,14 +331,14 @@ static int map_entry (struct _diva_segment_alloc* pI, diva_map_entry_t* pE) { } #endif -static void* map_address (struct _diva_segment_alloc* pI, dword lo, dword hi) { +static void* map_address (struct _diva_segment_alloc* pI, dword lo, dword hi, int map_host) { void* ret = 0; #if defined(DIVA_USERMODE) #if defined(LINUX) qword addr = ((qword)lo) | (((qword)hi) << 32); - ret = mmap (0, 4*1024, PROT_READ|PROT_WRITE, MAP_SHARED, pI->fd_mem, addr); + ret = mmap (0, 4*1024, PROT_READ|PROT_WRITE, MAP_SHARED, (map_host == 0) ? pI->fd_mem : pI->fd, addr); if (ret == ((void*)-1)) { ret = 0; }