Subversion Repositories HelenOS

Rev

Rev 4581 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4581 Rev 4718
1
/*
1
/*
2
 * Copyright (c) 2006 Ondrej Palkovsky
2
 * Copyright (c) 2006 Ondrej Palkovsky
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup ns
29
/** @addtogroup ns
30
 * @{
30
 * @{
31
 */
31
 */
32
 
32
 
33
/**
33
/**
34
 * @file  ns.c
34
 * @file  ns.c
35
 * @brief Naming service for HelenOS IPC.
35
 * @brief Naming service for HelenOS IPC.
36
 */
36
 */
37
 
37
 
38
#include <ipc/ipc.h>
38
#include <ipc/ipc.h>
39
#include <ipc/services.h>
39
#include <ipc/services.h>
40
#include <ipc/ns.h>
40
#include <ipc/ns.h>
41
#include <unistd.h>
41
#include <unistd.h>
42
#include <stdio.h>
42
#include <stdio.h>
43
#include <errno.h>
43
#include <errno.h>
44
#include <as.h>
44
#include <as.h>
45
#include <ddi.h>
45
#include <ddi.h>
46
#include <event.h>
46
#include <event.h>
47
#include <macros.h>
47
#include <macros.h>
48
#include <sysinfo.h>
48
#include <sysinfo.h>
49
#include "ns.h"
49
#include "ns.h"
50
#include "service.h"
50
#include "service.h"
51
#include "clonable.h"
51
#include "clonable.h"
52
#include "task.h"
52
#include "task.h"
53
 
53
 
54
static void *clockaddr = NULL;
54
static void *clockaddr = NULL;
55
static void *klogaddr = NULL;
55
static void *klogaddr = NULL;
56
 
56
 
57
static void get_as_area(ipc_callid_t callid, ipc_call_t *call, void *ph_addr,
57
static void get_as_area(ipc_callid_t callid, ipc_call_t *call, void *ph_addr,
58
    size_t pages, void **addr)
58
    size_t pages, void **addr)
59
{
59
{
60
    if (ph_addr == NULL) {
60
    if (ph_addr == NULL) {
61
        ipc_answer_0(callid, ENOENT);
61
        ipc_answer_0(callid, ENOENT);
62
        return;
62
        return;
63
    }
63
    }
64
   
64
   
65
    if (*addr == NULL) {
65
    if (*addr == NULL) {
66
        *addr = as_get_mappable_page(pages * PAGE_SIZE);
66
        *addr = as_get_mappable_page(pages * PAGE_SIZE);
67
       
67
       
68
        if (*addr == NULL) {
68
        if (*addr == NULL) {
69
            ipc_answer_0(callid, ENOENT);
69
            ipc_answer_0(callid, ENOENT);
70
            return;
70
            return;
71
        }
71
        }
72
       
72
       
73
        if (physmem_map(ph_addr, *addr, pages,
73
        if (physmem_map(ph_addr, *addr, pages,
74
            AS_AREA_READ | AS_AREA_CACHEABLE) != 0) {
74
            AS_AREA_READ | AS_AREA_CACHEABLE) != 0) {
75
            ipc_answer_0(callid, ENOENT);
75
            ipc_answer_0(callid, ENOENT);
76
            return;
76
            return;
77
        }
77
        }
78
    }
78
    }
79
   
79
   
80
    ipc_answer_2(callid, EOK, (ipcarg_t) *addr, AS_AREA_READ);
80
    ipc_answer_2(callid, EOK, (ipcarg_t) *addr, AS_AREA_READ);
81
}
81
}
82
 
82
 
83
int main(int argc, char **argv)
83
int main(int argc, char **argv)
84
{
84
{
85
    printf(NAME ": HelenOS IPC Naming Service\n");
85
    printf(NAME ": HelenOS IPC Naming Service\n");
86
   
86
   
87
    int rc = service_init();
87
    int rc = service_init();
88
    if (rc != EOK)
88
    if (rc != EOK)
89
        return rc;
89
        return rc;
90
   
90
   
91
    rc = clonable_init();
91
    rc = clonable_init();
92
    if (rc != EOK)
92
    if (rc != EOK)
93
        return rc;
93
        return rc;
94
   
94
   
95
    rc = task_init();
95
    rc = task_init();
96
    if (rc != EOK)
96
    if (rc != EOK)
97
        return rc;
97
        return rc;
98
   
98
   
99
    printf(NAME ": Accepting connections\n");
99
    printf(NAME ": Accepting connections\n");
100
   
100
   
101
    while (true) {
101
    while (true) {
102
        process_pending_conn();
102
        process_pending_conn();
103
        process_pending_wait();
103
        process_pending_wait();
104
       
104
       
105
        ipc_call_t call;
105
        ipc_call_t call;
106
        ipc_callid_t callid = ipc_wait_for_call(&call);
106
        ipc_callid_t callid = ipc_wait_for_call(&call);
107
       
107
       
108
        task_id_t id;
108
        task_id_t id;
109
        ipcarg_t retval;
109
        ipcarg_t retval;
110
       
110
       
111
        if (callid & IPC_CALLID_NOTIFICATION) {
-
 
112
            id = (task_id_t)
-
 
113
                MERGE_LOUP32(IPC_GET_ARG2(call), IPC_GET_ARG3(call));
-
 
114
            wait_notification((wait_type_t) IPC_GET_ARG1(call), id);
-
 
115
            continue;
-
 
116
        }
-
 
117
       
-
 
118
        switch (IPC_GET_METHOD(call)) {
111
        switch (IPC_GET_METHOD(call)) {
119
        case IPC_M_SHARE_IN:
112
        case IPC_M_SHARE_IN:
120
            switch (IPC_GET_ARG3(call)) {
113
            switch (IPC_GET_ARG3(call)) {
121
            case SERVICE_MEM_REALTIME:
114
            case SERVICE_MEM_REALTIME:
122
                get_as_area(callid, &call,
115
                get_as_area(callid, &call,
123
                    (void *) sysinfo_value("clock.faddr"),
116
                    (void *) sysinfo_value("clock.faddr"),
124
                    1, &clockaddr);
117
                    1, &clockaddr);
125
                break;
118
                break;
126
            case SERVICE_MEM_KLOG:
119
            case SERVICE_MEM_KLOG:
127
                get_as_area(callid, &call,
120
                get_as_area(callid, &call,
128
                    (void *) sysinfo_value("klog.faddr"),
121
                    (void *) sysinfo_value("klog.faddr"),
129
                    sysinfo_value("klog.pages"), &klogaddr);
122
                    sysinfo_value("klog.pages"), &klogaddr);
130
                break;
123
                break;
131
            default:
124
            default:
132
                ipc_answer_0(callid, ENOENT);
125
                ipc_answer_0(callid, ENOENT);
133
            }
126
            }
134
            continue;
127
            continue;
135
        case IPC_M_PHONE_HUNGUP:
128
        case IPC_M_PHONE_HUNGUP:
136
            retval = EOK;
129
            retval = ns_task_disconnect(&call);
137
            break;
130
            break;
138
        case IPC_M_CONNECT_TO_ME:
131
        case IPC_M_CONNECT_TO_ME:
139
            /*
132
            /*
140
             * Server requests service registration.
133
             * Server requests service registration.
141
             */
134
             */
142
            if (service_clonable(IPC_GET_ARG1(call))) {
135
            if (service_clonable(IPC_GET_ARG1(call))) {
143
                register_clonable(IPC_GET_ARG1(call),
136
                register_clonable(IPC_GET_ARG1(call),
144
                    IPC_GET_ARG5(call), &call, callid);
137
                    IPC_GET_ARG5(call), &call, callid);
145
                continue;
138
                continue;
146
            } else {
139
            } else {
147
                retval = register_service(IPC_GET_ARG1(call),
140
                retval = register_service(IPC_GET_ARG1(call),
148
                    IPC_GET_ARG5(call), &call);
141
                    IPC_GET_ARG5(call), &call);
149
            }
142
            }
150
            break;
143
            break;
151
        case IPC_M_CONNECT_ME_TO:
144
        case IPC_M_CONNECT_ME_TO:
152
            /*
145
            /*
153
             * Client requests to be connected to a service.
146
             * Client requests to be connected to a service.
154
             */
147
             */
155
            if (service_clonable(IPC_GET_ARG1(call))) {
148
            if (service_clonable(IPC_GET_ARG1(call))) {
156
                connect_to_clonable(IPC_GET_ARG1(call),
149
                connect_to_clonable(IPC_GET_ARG1(call),
157
                    &call, callid);
150
                    &call, callid);
158
                continue;
151
                continue;
159
            } else {
152
            } else {
160
                connect_to_service(IPC_GET_ARG1(call), &call,
153
                connect_to_service(IPC_GET_ARG1(call), &call,
161
                    callid);
154
                    callid);
162
                continue;
155
                continue;
163
            }
156
            }
164
            break;
157
            break;
165
        case NS_PING:
158
        case NS_PING:
166
            retval = EOK;
159
            retval = EOK;
167
            break;
160
            break;
168
        case NS_TASK_WAIT:
161
        case NS_TASK_WAIT:
169
            id = (task_id_t)
162
            id = (task_id_t)
170
                MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
163
                MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
171
            wait_for_task(id, &call, callid);
164
            wait_for_task(id, &call, callid);
172
            continue;
165
            continue;
-
 
166
        case NS_ID_INTRO:
-
 
167
            retval = ns_task_id_intro(&call);
-
 
168
            break;
-
 
169
        case NS_RETVAL:
-
 
170
            retval = ns_task_retval(&call);
-
 
171
            break;
173
        default:
172
        default:
174
            retval = ENOENT;
173
            retval = ENOENT;
175
            break;
174
            break;
176
        }
175
        }
177
       
176
       
178
        if (!(callid & IPC_CALLID_NOTIFICATION))
177
        if (!(callid & IPC_CALLID_NOTIFICATION))
179
            ipc_answer_0(callid, retval);
178
            ipc_answer_0(callid, retval);
180
    }
179
    }
181
   
180
   
182
    /* Not reached */
181
    /* Not reached */
183
    return 0;
182
    return 0;
184
}
183
}
185
 
184
 
186
/**
185
/**
187
 * @}
186
 * @}
188
 */
187
 */
189
 
188