summaryrefslogtreecommitdiffstats
path: root/src/lib/syscall_msg.C
blob: 9004461c4e20fe9cbe541e3ab931786e0ff8d32a (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/lib/syscall_msg.C $                                       */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2010,2018                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* 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                                                     */
#include <sys/msg.h>
#include <sys/syscall.h>
#include <sys/vfs.h>
#include <errno.h>

#include <string.h>

using namespace Systemcalls;

msg_q_t msg_q_create()
{
    return (msg_q_t) _syscall0(MSGQ_CREATE);
}

void msg_q_destroy(msg_q_t q)
{
    _syscall1(MSGQ_DESTROY, q);
}

int msg_q_register(msg_q_t q, const char* name)
{
    if (0 == strcmp(VFS_ROOT, name))
    {
        return (int64_t)_syscall2(MSGQ_REGISTER_ROOT,
                                  reinterpret_cast<void*>(MSGQ_ROOT_VFS),
                                  q);
    }
    else
    {
        msg_q_t vfsQ = (msg_q_t)_syscall1(MSGQ_RESOLVE_ROOT,
                                          reinterpret_cast<void*>(MSGQ_ROOT_VFS));
        msg_t* msg = msg_allocate();
        msg->type = VFS_MSG_REGISTER_MSGQ;
        msg->data[0] = (uint64_t) q;
        msg->extra_data = (void*) name;
        int rc = msg_sendrecv(vfsQ, msg);
        msg_free(msg);
        return rc;
    }
}

int msg_intr_q_register(msg_q_t q, uint64_t i_ipc_base_addr)
{
    int rc = (int64_t)_syscall3(MSGQ_REGISTER_ROOT,
                                reinterpret_cast<void*>(MSGQ_ROOT_INTR),
                                q,
                                reinterpret_cast<void*>(i_ipc_base_addr));

    return rc;
}

int msg_q_remove(const char * name)
{
    msg_q_t vfsQ = (msg_q_t)_syscall1(MSGQ_RESOLVE_ROOT,
                                      reinterpret_cast<void*>(MSGQ_ROOT_VFS));
    msg_t * msg = msg_allocate();
    msg->type = VFS_MSG_REMOVE_MSGQ;
    msg->extra_data = (void *)name;
    msg_sendrecv(vfsQ, msg);
    int rc = static_cast<int>(msg->data[0]);
    msg_free(msg);
    return rc;
}

msg_q_t msg_q_resolve(const char* name)
{
    if (0 == strcmp(VFS_ROOT, name))
    {
        return (msg_q_t)_syscall1(MSGQ_RESOLVE_ROOT,
                                  reinterpret_cast<void*>(MSGQ_ROOT_VFS));
    }
    else if (0 == strcmp(VFS_ROOT_MSG_INTR, name))
    {
        return (msg_q_t)_syscall1(MSGQ_RESOLVE_ROOT,
                                  reinterpret_cast<void*>(MSGQ_ROOT_INTR));
    }
    else
    {
        msg_q_t vfsQ = (msg_q_t)_syscall1(MSGQ_RESOLVE_ROOT,
                                          reinterpret_cast<void*>(MSGQ_ROOT_VFS));
        msg_t* msg = msg_allocate();
        msg->type = VFS_MSG_RESOLVE_MSGQ;
        msg->extra_data = (void*) name;
        msg_sendrecv(vfsQ, msg);
        msg_q_t rc = (msg_q_t) msg->data[0];
        msg_free(msg);
        return rc;
    }
}

msg_t* msg_allocate()
{
    msg_t* msg = reinterpret_cast<msg_t*>(malloc(sizeof(msg_t)));

    memset(msg, 0, sizeof(msg_t));

    return msg;
}

int msg_send(msg_q_t q, msg_t* msg)
{
    int64_t rc = 0;
    do
    {
        rc = (int64_t)_syscall2(MSG_SEND, q, msg);
    } while( rc == -EAGAIN );
    return rc;
}

int msg_sendrecv(msg_q_t q, msg_t* msg)
{
    return (int64_t)_syscall3(MSG_SENDRECV, q, msg, NULL);
}

int msg_sendrecv_noblk(msg_q_t q, msg_t* msg, msg_q_t q2)
{
    return (int64_t)_syscall3(MSG_SENDRECV, q, msg, q2);
}

int msg_respond(msg_q_t q, msg_t* msg)
{
    return (int64_t)_syscall2(MSG_RESPOND, q, msg);
}

msg_t* msg_wait(msg_q_t q)
{
    return (msg_t*)_syscall1(MSG_WAIT, q);
}

int updateRemoteIpcAddr(uint64_t i_Node, uint64_t i_RemoteAddr)
{
    return (int64_t)_syscall2(UPDATE_REMOTE_IPC_ADDR,
                              (void *)i_Node,
                              (void *)i_RemoteAddr);
}

int qryLocalIpcInfo(uint64_t & o_Node, uint64_t & o_Addr)
{
    // need to allocate a buffer on the heap as Kernel cannot
    //  store back to user stack buffer
    uint64_t * l_pTmpBfr = new uint64_t[2];
    l_pTmpBfr[0] = o_Node;    // seed tmp bfr with contents of out bfr
    l_pTmpBfr[1] = o_Addr;    //  to hide the existence of the
                              //  intermediate tmp bfr
    void * l_pNode = reinterpret_cast<void *>(&l_pTmpBfr[0]);
    void * l_pAddr = reinterpret_cast<void *>(&l_pTmpBfr[1]);

    void * l_retVal = _syscall2( QRY_LOCAL_IPC_INFO,
                                 l_pNode,
                                 l_pAddr );

    o_Node = l_pTmpBfr[0];
    o_Addr = l_pTmpBfr[1];
    delete [] l_pTmpBfr;

    return( reinterpret_cast<int64_t>(l_retVal) );
}
OpenPOWER on IntegriCloud