summaryrefslogtreecommitdiffstats
path: root/src/lib/syscall_msg.C
blob: 1f9478cc40ef64aedcc5392c663ccd805c492908 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/lib/syscall_msg.C $                                       */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2010,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                                                     */
#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)
{
    return (int64_t)_syscall2(MSG_SEND, q, msg);
}

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);
}

OpenPOWER on IntegriCloud