summaryrefslogtreecommitdiffstats
path: root/src/include/kernel/blockmsghdlr.H
blob: 1f1ad6968301f49ea42a6ee6e2a6bee5a08c2f84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/include/kernel/blockmsghdlr.H $                           */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2011,2014              */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
/** @file blockmsghdlr.H
 *  @brief Defines the implementation for a block's handling of messages.
 */
#ifndef __KERNEL_BLOCKMSGHDLR_H
#define __KERNEL_BLOCKMSGHDLR_H

#include <stdint.h>
#include <kernel/types.h>
#include <kernel/msghandler.H>
#include <util/locked/list.H>

//Forward declaration.
class Spinlock;
class MessageQueue;
class Block;

struct TaskMsgNode
{
    //Next pointer for list.
    TaskMsgNode* next;
    //Previous pointer for list.
    TaskMsgNode* prev;

    task_t* key;
    uint64_t msgCount;
};

struct PageAddrNode
{
    //Next pointer for list.
    PageAddrNode* next;
    //Previous pointer for list.
    PageAddrNode* prev;

    void* key;
    uint64_t pageAddr;
};

/**
 * @class BlockReadMsgHdlr
 * @brief Class to handle read messages for blocks
 *
 * This class extends from the base MessageHandler so the base send/receive
 * message functions can be utilized. It overrides how to handle the message
 * responses for blocks within the base virtual memory segment.
 */
class BlockReadMsgHdlr : public MessageHandler
{
    public:

        /**
         * @brief Constructor
         *
         * @param[in] i_lock - Subsystem lock for this message handler, passed
         *                     directly onto the MessageHandler
         * @param[in] i_msgq - Queue used to send messages into userspace,
         *                     passed directly onto the MessageHandler
         * @param[in] i_block - Block to associate this message handler to
         */
        BlockReadMsgHdlr(Spinlock* i_lock,MessageQueue* i_msgq,
                         Block* i_block) :
                         MessageHandler(i_lock,i_msgq), iv_block(i_block) {};

        /**
         * @brief Destructor
         */
        ~BlockReadMsgHdlr() {};

        /**
         * @brief Handle response to 'send message' associated with this block
         *
         *  @param[in] i_type - The message type previously sent.
         *  @param[in] i_key - The key value for the received message.
         *  @param[in] i_task - The deferred task.
         *  @param[in] i_rc - The response rc from userspace.
         *
         *  @return HandleResult - The desired behavior on the 'recv message'
         *                         interface for this <key, task> pair.
         */
        virtual HandleResult handleResponse(msg_sys_types_t i_type,void* i_key,
                                            task_t* i_task,int i_rc);

    private:

        /* Associated block for this message handler */
        Block* const iv_block;
};

/**
 * @class BlockWriteMsgHdlr
 * @brief Class to handle write messages for blocks
 *
 * This class extends from the base MessageHandler so the base send/receive
 * message functions can be utilized. It overrides how to handle the message
 * responses for blocks within the base virtual memory segment.
 */
class BlockWriteMsgHdlr : public MessageHandler
{
    public:

        /**
         * @brief Constructor
         *
         * @param[in] i_lock - Subsystem lock for this message handler, passed
         *                     directly onto the MessageHandler
         * @param[in] i_msgq - Queue used to send messages into userspace,
         *                     passed directly onto the MessageHandler
         * @param[in] i_block - Block to associate this message handler to
         */
        BlockWriteMsgHdlr(Spinlock* i_lock,MessageQueue* i_msgq,
                          Block* i_block) :
                          MessageHandler(i_lock,i_msgq), iv_block(i_block) {};

        /**
         * @brief Destructor
         */
        ~BlockWriteMsgHdlr() {};

        /**
         * @brief Handle response to 'send message' associated with this block
         *
         *  @param[in] i_type - The message type previously sent.
         *  @param[in] i_key - The key value for the received message.
         *  @param[in] i_task - The deferred task.
         *  @param[in] i_rc - The response rc from userspace.
         *
         *  @return HandleResult - The desired behavior on the 'recv message'
         *                         interface for this <key, task> pair.
         */
        virtual HandleResult handleResponse(msg_sys_types_t i_type,void* i_key,
                                            task_t* i_task,int i_rc);

        /**
         * @brief Increments the number of messages sent from the given task
         * @param[in] i_task - Associated task to message sent
         */
        void incMsgCount(task_t* i_task);

        /**
         * @brief Adds the virtual address to page address association for
         * page removal upon response
         * @param[in] i_vaddr - Virtual address sent on message
         * @param[in] i_pgAddr - Page address to be removed
         */
        void addVirtAddr(void* i_vaddr,uint64_t i_pgAddr);

    private:

        /* Associated block for this message handler */
        Block* const iv_block;
        /* List of associated tasks to number of messages */
        Util::Locked::List<TaskMsgNode, task_t*> iv_msgGrpList;
        /* List of associated virtual address to page address */
        Util::Locked::List<PageAddrNode, void*> iv_va2paList;
};

#endif
OpenPOWER on IntegriCloud