summaryrefslogtreecommitdiffstats
path: root/src/include/sys/msg.h
blob: 215da312e6aef8671f9bbfa76fd55506cc889ddc (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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
//  IBM_PROLOG_BEGIN_TAG
//  This is an automatically generated prolog.
//
//  $Source: src/include/sys/msg.h $
//
//  IBM CONFIDENTIAL
//
//  COPYRIGHT International Business Machines Corp. 2010 - 2011
//
//  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
#ifndef __SYS_MSG_H
#define __SYS_MSG_H

#include <stdint.h>
#include <stdlib.h>
#include <builtins.h>

#ifdef __cplusplus
extern "C"
{
#endif

typedef void* msg_q_t;

struct msg_t
{
    uint32_t type;
    struct
    {
        uint32_t __reserved__async:1;
        uint32_t __reserved__unused:31;
    };
    uint64_t data[2];
    void* extra_data;
};

// System-defined message types.
/** @enum msg_sys_types_t
 *  @brief Message types potentially sent from the kernel itself.
 */
enum msg_sys_types_t
{
    MSG_FIRST_SYS_TYPE = 0x80000000,

    MSG_MM_RP_READ,
    MSG_MM_RP_WRITE,
    MSG_MM_RP_PERM,
};

/** @var msg_sys_types_t::MSG_MM_RP_READ
 *  @brief Memory Management - Resource Provider Read
 *
 *  Sent from the kernel to a msg_q_t registered with mm_block_create when
 *  a page is requested to be read in from a resource.
 *
 *  <pre>
 *  Format:
 *      type = MSG_MM_RP_READ
 *      data[0] = virtual address requested
 *      data[1] = address to place contents
 *
 *  Expected Response:
 *      type = MSG_MM_RP_READ
 *      data[0] = virtual address requested
 *      data[1] = rc (0 or negative errno value)
 *  </pre>
 */
/** @var msg_sys_types_t::MSG_MM_RP_WRITE
 *  @brief Memory Management - Resource Provider Write
 *
 *  Sent from the kernel to a msg_q_t registered with mm_block_create when
 *  a page is requested to be written back to a resource.
 *
 *  <pre>
 *  Format:
 *      type = MSG_MM_RP_WRITE
 *      data[0] = virtual address requested
 *      data[1] = address to read contents from
 *
 *  Expected Response:
 *      type = MSG_MM_RP_WRITE
 *      data[0] = virtual address requested
 *      data[1] = rc (0 or negative errno value)
 *  </pre>
 */
/** @var msg_sys_types_t::MSG_MM_RP_PERM
 *  @brief Memory Management - Resource Provider Permission Fault
 *
 *  TODO.
 */


// Message queue interfaces.

/** @fn msg_q_create
  * @brief Create a new message queue.
  *
  * @return msg_q_t handle
  */
msg_q_t msg_q_create();


/** @fn msg_q_destroy
  * @brief Deallocate a message queue previously allocated with msg_q_create()
  *
  * @param[in] q - handle to message queue to destroy
  */
void msg_q_destroy( msg_q_t q );


/** @fn msg_q_register
  * @brief Assign a name to a message queue.
  *
  * @param[in] q - handle of message queue to name
  * @param[in] name - name
  *
  * @return  Result of msg_sendrecv where zero indicates success
  */
int msg_q_register(msg_q_t q, const char* name);


/** @fn msg_q_resolve
  * @brief Given the name of a message queue, return the handle to it.
  *
  * @param[in] name - name of message queue
  *
  * @return message queue handle or null if name not found.
  */
msg_q_t msg_q_resolve(const char* name);





// Message interfaces.
/** @fn msg_allocate
  * @brief Allocate space for message
  * @return Pointer to message
  */
ALWAYS_INLINE
    inline msg_t* msg_allocate() { return (msg_t*)malloc(sizeof(msg_t)); }


/** @fn msg_free
  * @brief Free a msg_t
  * @param[in] msg - message to free
  */

ALWAYS_INLINE
    inline void msg_free(msg_t* m) { free(m); }


/** @fn msg_send
  * @brief Send a message asynchronously.
  *
  * This call adds the message queue then returns
  * to the caller. Any process waiting for a message
  * in the queue will awake with this message.
  *
  * @param[in] q - message queue
  * @param[in] msg - message
  * @return    Always returns zero.
  */
int msg_send(msg_q_t q, msg_t* msg);


/** @fn msg_sendrecv
  * @brief Send a message to a server and get a response synchronously.
  *
  * The calling [client] thread blocks until the recipient [server] receives
  * and replies to the message.
  *
  * @param[in] q - message queue
  * @param[in,out] msg - message
  * @return Zero on success, else negative.
  */
int msg_sendrecv(msg_q_t q, msg_t* msg);


/** @fn msg_respond
  * @brief Respond to a synchronous message.
  *
  * This is how server-side code responds to synchronous
  * messaging when clients call msg_sendrecv().
  *
  * @param[in] q - message queue
  * @param[in] msg - response message
  * @return Zero on success, else negative.
  */
int msg_respond(msg_q_t q, msg_t* msg);


/** @fn msg_wait
  * @brief  Read a message from the message queue.
  *
  * If a message is already on the queue, this call will return immediately
  * with the message. Otherwise the calling thread will block and wait for
  * a message.
  *
  * @param[in] q - message queue to read
  * @return the message posted to the queue
  */
msg_t* msg_wait(msg_q_t q);


/** @fn msg_is_async
  * @brief  Indicates if message is asynchronous.
  *
  * Tests the message field "__reserved__async" which appears to be set to 0 to indicate asynchronous, and 1 to indicate synchronous message.
  *
  * @return true if asynchronous message
  */
ALWAYS_INLINE
    inline uint32_t msg_is_async(msg_t* msg)
	{ return 0 == msg->__reserved__async; }

#ifdef __cplusplus
}
#endif

#endif
OpenPOWER on IntegriCloud