diff options
author | Brad Bishop <bradleyb@us.ibm.com> | 2012-07-10 21:25:03 -0500 |
---|---|---|
committer | A. Patrick Williams III <iawillia@us.ibm.com> | 2012-08-15 12:44:44 -0500 |
commit | 122f4ba48151f29cfb8be1d411509a219bd1df12 (patch) | |
tree | 319aac016f0f4dba5b8e9f8624aea755c16e24c6 /src | |
parent | 63227ec1b2670c6e2eec5936607e8cd5f485933d (diff) | |
download | blackbird-hostboot-122f4ba48151f29cfb8be1d411509a219bd1df12.tar.gz blackbird-hostboot-122f4ba48151f29cfb8be1d411509a219bd1df12.zip |
Attention handler fake interrupt presenter.
A fake presenter for unit testing.
RTC: 41428
Change-Id: I03f90cc00ee368fb8bde24e47da6fc4a4db130cf
Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/1355
Tested-by: Jenkins Server
Reviewed-by: A. Patrick Williams III <iawillia@us.ibm.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/usr/diag/attn/test/attnfakepresenter.C | 227 | ||||
-rw-r--r-- | src/usr/diag/attn/test/attnfakepresenter.H | 148 | ||||
-rw-r--r-- | src/usr/diag/attn/test/attntest.H | 47 | ||||
-rw-r--r-- | src/usr/diag/attn/test/makefile | 6 |
4 files changed, 403 insertions, 25 deletions
diff --git a/src/usr/diag/attn/test/attnfakepresenter.C b/src/usr/diag/attn/test/attnfakepresenter.C new file mode 100644 index 000000000..db0d84dc9 --- /dev/null +++ b/src/usr/diag/attn/test/attnfakepresenter.C @@ -0,0 +1,227 @@ +/* IBM_PROLOG_BEGIN_TAG + * This is an automatically generated prolog. + * + * $Source: src/usr/diag/attn/test/attnfakepresenter.C $ + * + * IBM CONFIDENTIAL + * + * COPYRIGHT International Business Machines Corp. 2012 + * + * p1 + * + * Object Code Only (OCO) source materials + * Licensed Internal Code Source Materials + * IBM HostBoot Licensed Internal Code + * + * The source code for this program is not published or other- + * wise divested of its trade secrets, irrespective of what has + * been deposited with the U.S. Copyright Office. + * + * Origin: 30 + * + * IBM_PROLOG_END_TAG + */ +/** + * @file attnfakepresenter.C + * + * @brief HBATTN fake interrupt presenter class method definitions. + */ + +#include "attnfakepresenter.H" +#include "../attntrace.H" + +using namespace TARGETING; +using namespace PRDF; + +namespace ATTN +{ + +struct InterruptProperties +{ + TargetHandle_t source; + MessageType type; + void * data; + void (*callback)(TargetHandle_t, MessageType, void *); +}; + +struct PresenterProperties +{ + FakePresenter * presenter; + msg_q_t msgQ; +}; + +bool FakePresenter::start(msg_q_t i_q) +{ + // start threads, create message q... + + bool success = false; + PresenterProperties * properties = NULL; + + mutex_lock(&iv_mutex); + + do { + + if(!iv_recvQ) + { + iv_recvQ = msg_q_create(); + } + + if(!iv_recvQ) + { + break; + } + + if(!iv_tid) + { + properties = new PresenterProperties; + + properties->presenter = this; + properties->msgQ = i_q; + + iv_tid = task_create(&main, properties); + } + + if(!iv_tid) + { + msg_q_destroy(iv_recvQ); + delete properties; + + break; + } + + } while(0); + + success = ((iv_tid != 0) && (iv_recvQ != 0)); + + mutex_unlock(&iv_mutex); + + return success; +} + +void FakePresenter::stop() +{ + mutex_lock(&iv_mutex); + + tid_t t = iv_tid; + iv_tid = 0; + + mutex_unlock(&iv_mutex); + + if(t) + { + msg_t * m = msg_allocate(); + m->type = SHUTDOWN; + msg_send(iv_recvQ, m); + + task_wait_tid(t, 0, 0); + } +} + +void FakePresenter::interrupt( + TargetHandle_t i_source, + MessageType i_type, + void * i_data, + void (*i_callback)(TargetHandle_t, MessageType, void *)) +{ + mutex_lock(&iv_mutex); + + if(iv_tid) + { + InterruptProperties * p = new InterruptProperties; + + p->source = i_source; + p->type = i_type; + p->data = i_data; + p->callback = i_callback; + + msg_t * m = msg_allocate(); + + m->type = i_type; + m->data[0] = reinterpret_cast<uint64_t>(p); + + ATTN_DBG("FakePresenter: interrupt request: src: %p, type: %d", + p->source, p->type); + + msg_send(iv_recvQ, m); + } + + mutex_unlock(&iv_mutex); +} + +bool FakePresenter::wait(msg_q_t i_q) +{ + bool shutdown = false; + + msg_t * recvMsg = msg_wait(iv_recvQ); + + shutdown = recvMsg->type == SHUTDOWN; + + if(shutdown) + { + msg_q_destroy(iv_recvQ); + iv_recvQ = 0; + } + + else + { + msg_t * sendMsg = msg_allocate(); + + InterruptProperties * p = reinterpret_cast<InterruptProperties *>( + recvMsg->data[0]); + + sendMsg->type = p->type; + sendMsg->data[0] = reinterpret_cast<uint64_t>(p->source); + + ATTN_DBG("FakePresenter: raising interrupt: src: %p, type: %d", + p->source, p->type); + + msg_sendrecv(i_q, sendMsg); + + msg_free(sendMsg); + + (*p->callback)(p->source, p->type, p->data); + delete p; + } + + msg_free(recvMsg); + + return shutdown; +} + +void FakePresenter::main(void * i_properties) +{ + PresenterProperties * properties + = static_cast<PresenterProperties *>(i_properties); + + while(true) + { + bool shutdown = properties->presenter->wait(properties->msgQ); + + if(shutdown) + { + break; + } + } + + delete properties; +} + +FakePresenter::FakePresenter() + : iv_tid(0), + iv_recvQ(0) +{ + mutex_init(&iv_mutex); +} + +FakePresenter::~FakePresenter() +{ + stop(); + + if(iv_recvQ) + { + msg_q_destroy(iv_recvQ); + } + + mutex_destroy(&iv_mutex); +} +} diff --git a/src/usr/diag/attn/test/attnfakepresenter.H b/src/usr/diag/attn/test/attnfakepresenter.H new file mode 100644 index 000000000..4fe250ba7 --- /dev/null +++ b/src/usr/diag/attn/test/attnfakepresenter.H @@ -0,0 +1,148 @@ +/* IBM_PROLOG_BEGIN_TAG + * This is an automatically generated prolog. + * + * $Source: src/usr/diag/attn/test/attnfakepresenter.H $ + * + * IBM CONFIDENTIAL + * + * COPYRIGHT International Business Machines Corp. 2012 + * + * p1 + * + * Object Code Only (OCO) source materials + * Licensed Internal Code Source Materials + * IBM HostBoot Licensed Internal Code + * + * The source code for this program is not published or other- + * wise divested of its trade secrets, irrespective of what has + * been deposited with the U.S. Copyright Office. + * + * Origin: 30 + * + * IBM_PROLOG_END_TAG + */ +#ifndef __TEST_ATTNFAKEPRESENTER_H +#define __TEST_ATTNFAKEPRESENTER_H + +/** + * @file attnfakepresenter.H + * + * @brief HBATTN fake interrupt presenter class definition. + */ + +#include "sys/sync.h" +#include "sys/task.h" +#include "sys/msg.h" +#include "attntest.H" + +namespace ATTN +{ + +/** + * @brief FakePresenter + * + * HBATTN fake interrupt presenter class definition. + */ +class FakePresenter +{ + public: + + /** + * @brief start + * + * Start the fake interrupt presenter. + * + * @param[in] i_q The message queue on which to place + * interrupt messages. + * + * @retval[true] Started succesfully. + * @retval[false] Did not start succesfully. + */ + bool start(msg_q_t i_q); + + /** + * @brief stop + * + * Stop the fake interrupt presenter. + * + * @post All resources reclaimed. + */ + void stop(); + + /** + * @brief interrupt + * + * Instruct the fake presenter to raise an interrupt. + * + * @param[in] i_source Interrupt source. + * @param[in] i_type Interrupt type. + * @param[in] i_data User pointer passed to callback. + * @param[in] i_callback Function to call at EOI. + */ + void interrupt( + TARGETING::TargetHandle_t i_source, + MessageType i_type, + void * i_data, + void (*i_callback)( + TARGETING::TargetHandle_t, MessageType, void *)); + + /** + * @brief ctor. + */ + FakePresenter(); + + /** + * @brief dtor. + */ + ~FakePresenter(); + + private: + + /** + * @brief wait + * + * Listen for fake interrupt requests. + * + * @param[in] i_q The message queue on which to place + * interrupt messages. + * + * @retval[true] Shutdown requested. + * @retval[false] Shutdown not requested. + */ + bool wait(msg_q_t i_q); + + /** + * @brief main static wrapper for wait. + * + * @param[in] i_properties The presenter on which to call wait. + */ + static void main(void * i_properties); + + /** + * @brief iv_mutex Shared data access serialization. + */ + mutex_t iv_mutex; + + /** + * @brief iv_tid + */ + tid_t iv_tid; + + /** + * @brief iv_recvQ The message Q on which to listen for interrupt + * requests. + */ + msg_q_t iv_recvQ; + + /** + * @brief copy disabled. + */ + FakePresenter(const FakePresenter &); + + /** + * @brief assignment disabled. + */ + FakePresenter & operator=(const FakePresenter &); +}; +} +#endif diff --git a/src/usr/diag/attn/test/attntest.H b/src/usr/diag/attn/test/attntest.H index 96b0f3749..b8d036d16 100644 --- a/src/usr/diag/attn/test/attntest.H +++ b/src/usr/diag/attn/test/attntest.H @@ -1,25 +1,26 @@ -// IBM_PROLOG_BEGIN_TAG -// This is an automatically generated prolog. -// -// $Source: src/usr/diag/attn/test/attntest.H $ -// -// IBM CONFIDENTIAL -// -// COPYRIGHT International Business Machines Corp. 2012 -// -// p1 -// -// Object Code Only (OCO) source materials -// Licensed Internal Code Source Materials -// IBM HostBoot Licensed Internal Code -// -// The source code for this program is not published or other- -// wise divested of its trade secrets, irrespective of what has -// been deposited with the U.S. Copyright Office. -// -// Origin: 30 -// -// IBM_PROLOG_END +/* IBM_PROLOG_BEGIN_TAG + * This is an automatically generated prolog. + * + * $Source: src/usr/diag/attn/test/attntest.H $ + * + * IBM CONFIDENTIAL + * + * COPYRIGHT International Business Machines Corp. 2012 + * + * p1 + * + * Object Code Only (OCO) source materials + * Licensed Internal Code Source Materials + * IBM HostBoot Licensed Internal Code + * + * The source code for this program is not published or other- + * wise divested of its trade secrets, irrespective of what has + * been deposited with the U.S. Copyright Office. + * + * Origin: 30 + * + * IBM_PROLOG_END_TAG + */ #ifndef __TEST_ATTNTEST_H #define __TEST_ATTNTEST_H @@ -34,6 +35,8 @@ namespace ATTN { +class FakePresenter; + /** * @brief randint Generate random integer between bounds. * diff --git a/src/usr/diag/attn/test/makefile b/src/usr/diag/attn/test/makefile index e3838f065..20dd9cf89 100644 --- a/src/usr/diag/attn/test/makefile +++ b/src/usr/diag/attn/test/makefile @@ -1,4 +1,4 @@ -# IBM_PROLOG_BEGIN_TAG +# IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # $Source: src/usr/diag/attn/test/makefile $ @@ -19,12 +19,12 @@ # # Origin: 30 # -# IBM_PROLOG_END +# IBM_PROLOG_END_TAG ROOTPATH = ../../../../.. EXTRAINCDIR += ${ROOTPATH}/src/include/usr/diag -OBJS = attnfakesys.o attntest.o attnrand.o +OBJS = attnfakesys.o attntest.o attnrand.o attnfakepresenter.o MODULE = testattn |