Commit 9ad24050 authored by Charlie Jacobsen's avatar Charlie Jacobsen
Browse files

Add thc_ipc_call, and change where msg type and id are stored.

parent d64a5f3f
......@@ -22,19 +22,19 @@ static int thc_recv_predicate(struct fipc_message* msg, void* data)
{
struct predicate_payload* payload_ptr = (struct predicate_payload*)data;
if( THC_MSG_TYPE(msg) == (uint32_t)msg_type_request )
if( thc_get_msg_type(msg) == (uint32_t)msg_type_request )
{
payload_ptr->msg_type = msg_type_request;
return 1;
}
else if( THC_MSG_ID(msg) == payload_ptr->expected_msg_id )
else if( thc_get_msg_id(msg) == payload_ptr->expected_msg_id )
{
payload_ptr->msg_type = msg_type_response;
return 1; //message for this awe
}
else
{
payload_ptr->actual_msg_id = THC_MSG_ID(msg);
payload_ptr->actual_msg_id = thc_get_msg_id(msg);
return 0; //message not for this awe
}
}
......@@ -44,14 +44,14 @@ static int poll_recv_predicate(struct fipc_message* msg, void* data)
{
struct predicate_payload* payload_ptr = (struct predicate_payload*)data;
if( THC_MSG_TYPE(msg) == (uint32_t)msg_type_request )
if( thc_get_msg_type(msg) == (uint32_t)msg_type_request )
{
payload_ptr->msg_type = msg_type_request;
return 1;
}
else
{
payload_ptr->actual_msg_id = THC_MSG_ID(msg);
payload_ptr->actual_msg_id = thc_get_msg_id(msg);
return 0; //message not for this awe
}
}
......@@ -153,6 +153,44 @@ thc_poll_recv(struct thc_channel_group_item* item,
}
EXPORT_SYMBOL(thc_poll_recv);
int
LIBASYNC_FUNC_ATTR
thc_ipc_call(struct fipc_ring_channel *chnl,
struct fipc_message *request,
struct fipc_message **response)
{
uint32_t msg_id;
int ret;
/*
* Get an id for our current awe, and store in request.
*/
msg_id = awe_mapper_create_id();
thc_set_msg_id(request, msg_id);
/*
* Send request
*/
ret = fipc_send_msg_end(chnl, request);
if (ret) {
printk(KERN_ERR "thc: error sending request");
goto fail1;
}
/*
* Receive response
*/
ret = thc_ipc_recv(chnl, msg_id, response);
if (ret) {
printk(KERN_ERR "thc: error receiving response");
goto fail2;
}
return 0;
fail2:
awe_mapper_remove_id(msg_id);
fail1:
return ret;
}
int
LIBASYNC_FUNC_ATTR
thc_channel_group_init(struct thc_channel_group* channel_group)
......
......@@ -16,7 +16,8 @@
#ifdef LINUX_KERNEL
#define AWE_TABLE_COUNT 1024
#define AWE_TABLE_ORDER 10
#define AWE_TABLE_COUNT (1 << AWE_TABLE_ORDER)
struct awe_table
{
......
......@@ -3,9 +3,41 @@
#include <libfipc.h>
#include <thc_ipc_types.h>
#include <awe_mapper.h>
#define THC_MSG_TYPE(msg) ((msg)->regs[(FIPC_NR_REGS) - 2])
#define THC_MSG_ID(msg) ((msg)->regs[(FIPC_NR_REGS) - 1])
#define THC_RESERVED_MSG_FLAG_BITS (2 + AWE_TABLE_ORDER)
/* Message type is in low 2 bits of flags */
static inline uint32_t thc_get_msg_type(struct fipc_message *msg)
{
/* Caught at compile time */
BUILD_BUG_ON(THC_RESERVED_MSG_FLAG_BITS > 32)
return fipc_get_flags(msg) & 0x3;
}
static inline void thc_set_msg_type(struct fipc_message *msg, uint32_t type)
{
fipc_set_flags(msg,
/* erase old type, and mask off low 2 bits of type */
(fipc_get_flags(msg) & ~0x3) | (type & 0x3));
}
/* Message id is in bits 2..(2 + AWE_TABLE_ORDER) bits */
static inline uint32_t thc_get_msg_id(struct fipc_message *msg)
{
/* shift off type bits, and mask off msg id */
return (fipc_get_flags(msg) >> 2) & ((1 << AWE_TABLE_ORDER) - 1);
}
static inline uint32_t thc_set_msg_id(struct fipc_message *msg,
uint32_t msg_id)
{
uint32_t flags = fipc_get_flags(msg);
/* erase old msg id, if any */
flags &= ~(((1 << AWE_TABLE_ORDER) - 1) << 2);
/* mask off relevant bits of msg id (to ensure it is in range),
* and install in flags. */
flags |= (msg_id & ((1 << AWE_TABLE_ORDER) - 1)) << 2;
fipc_set_flags(msg, flags);
}
int thc_ipc_recv(struct fipc_ring_channel *chnl,
unsigned long msg_id,
......
......@@ -85,9 +85,9 @@ static inline int send_response(struct fipc_ring_channel *chnl,
pr_err("Error getting send slot");
return ret;
}
THC_MSG_TYPE(response) = msg_type_response;
THC_MSG_ID(response) = THC_MSG_ID(recvd_msg);
thc_set_msg_type(response, msg_type_response);
thc_set_msg_id(response, thc_get_msg_id(recvd_msg));
set_fn_type(response, type);
response->regs[0] = val;
......
......@@ -14,41 +14,6 @@
#include <awe_mapper.h>
#include "../test_helpers.h"
static inline int send_and_get_response(
struct fipc_ring_channel *chan,
struct fipc_message *request,
struct fipc_message **response,
uint32_t msg_id)
{
int ret;
struct fipc_message *resp;
/*
* Mark the request as sent
*/
ret = fipc_send_msg_end(chan, request);
if (ret) {
pr_err("failed to mark request as sent, ret = %d\n", ret);
goto fail1;
}
/*
* Try to get the response
*/
ret = thc_ipc_recv(chan, msg_id, &resp);
if (ret) {
pr_err("failed to get a response, ret = %d\n", ret);
goto fail2;
}
*response = resp;
printk(KERN_ERR "got result\n");
return 0;
fail2:
fail1:
return ret;
}
static inline int finish_response_check_fn_type(struct fipc_ring_channel *chnl,
struct fipc_message *response,
enum fn_type expected_type)
......@@ -112,17 +77,15 @@ async_add_nums(struct fipc_ring_channel *chan, unsigned long trans,
pr_err("Error getting send message, ret = %d\n", ret);
goto fail;
}
msg_id = awe_mapper_create_id();
THC_MSG_TYPE(request) = msg_type_request;
THC_MSG_ID(request) = msg_id;
thc_set_msg_type(request, msg_type_request);
set_fn_type(request, ADD_NUMS);
fipc_set_reg0(request, trans);
fipc_set_reg1(request, res1);
/*
* Send request, and get response
*/
ret = send_and_get_response(chan, request, &response, msg_id);
ret = thc_ipc_call(chan, request, &response);
if (ret) {
pr_err("Error getting response, ret = %d\n", ret);
goto fail;
......
......@@ -31,14 +31,21 @@ static inline
int
get_fn_type(struct fipc_message *msg)
{
return fipc_get_flags(msg);
return fipc_get_flags(msg) >> THC_RESERVED_MSG_FLAG_BITS;
}
static inline
void
set_fn_type(struct fipc_message *msg, enum fn_type type)
{
fipc_set_flags(msg, type);
uint32_t flags = fipc_get_flags(msg);
/* ensure type is in range */
type &= (1 << (32 - THC_RESERVED_MSG_FLAG_BITS)) - 1;
/* erase old type */
flags &= ((1 << THC_RESERVED_MSG_FLAG_BITS) - 1);
/* install new type */
flags |= (type << THC_RESERVED_MSG_FLAG_BITS)
fipc_set_flags(msg, flags);
}
#endif /* LIBFIPC_RPC_TEST_H */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment