Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 1350 → Rev 1351

/uspace/trunk/libipc/include/ipc.h
File deleted
/uspace/trunk/libipc/include/ns.h
File deleted
/uspace/trunk/libipc/include/services.h
File deleted
/uspace/trunk/libipc/generic/ipc.c
File deleted
/uspace/trunk/libipc/Makefile
File deleted
/uspace/trunk/ns/Makefile
31,14 → 31,11
 
LIBC_PREFIX = ../libc
LIBADT_PREFIX = ../libadt
LIBIPC_PREFIX = ../libipc
SOFTINT_PREFIX = ../softint
include $(LIBC_PREFIX)/Makefile.toolchain
 
CFLAGS += -I../libipc/include
LIBS = $(LIBADT_PREFIX)/libadt.a $(LIBC_PREFIX)/libc.a
 
LIBS = $(LIBADT_PREFIX)/libadt.a $(LIBIPC_PREFIX)/libipc.a $(LIBC_PREFIX)/libc.a
 
## Sources
#
 
/uspace/trunk/init/Makefile
30,13 → 30,12
#
 
LIBC_PREFIX = ../libc
LIBIPC_PREFIX = ../libipc
SOFTINT_PREFIX = ../softint
include $(LIBC_PREFIX)/Makefile.toolchain
 
CFLAGS += -I../libipc/include -I../kbd/include
CFLAGS += -I../kbd/include
 
LIBS = $(LIBIPC_PREFIX)/libipc.a $(LIBC_PREFIX)/libc.a
LIBS = $(LIBC_PREFIX)/libc.a
 
## Sources
#
/uspace/trunk/libc/include/libipc/ipc.h
0,0 → 1,73
/*
* Copyright (C) 2006 Ondrej Palkovsky
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __LIBIPC_IPC_H__
#define __LIBIPC_IPC_H__
 
#include <kernel/ipc/ipc.h>
#include <kernel/ipc/irq.h>
#include <libc.h>
#include <types.h>
 
typedef sysarg_t ipcarg_t;
typedef struct {
ipcarg_t args[IPC_CALL_LEN];
ipcarg_t in_phone_hash;
} ipc_call_t ;
typedef sysarg_t ipc_callid_t;
 
typedef void (* ipc_async_callback_t)(void *private, int retval,
ipc_call_t *data);
 
#define ipc_call_sync_2(phoneid, method, arg1, arg2, res1, res2) ipc_call_sync_3((phoneid), (method), (arg1), (arg2), 0, (res1), (res2), 0)
extern int ipc_call_sync_3(int phoneid, ipcarg_t method, ipcarg_t arg1,
ipcarg_t arg2, ipcarg_t arg3,
ipcarg_t *result1, ipcarg_t *result2,
ipcarg_t *result3);
 
 
extern int ipc_call_sync(int phoneid, ipcarg_t method, ipcarg_t arg1,
ipcarg_t *result);
extern ipc_callid_t ipc_wait_for_call(ipc_call_t *data, int flags);
extern ipcarg_t ipc_answer_fast(ipc_callid_t callid, ipcarg_t retval, ipcarg_t arg1,
ipcarg_t arg2);
extern ipcarg_t ipc_answer(ipc_callid_t callid, ipc_call_t *call);
 
#define ipc_call_async(phoneid,method,arg1,private, callback) (ipc_call_async_2(phoneid, method, arg1, 0, private, callback))
extern void ipc_call_async_2(int phoneid, ipcarg_t method, ipcarg_t arg1,
ipcarg_t arg2, void *private,
ipc_async_callback_t callback);
extern int ipc_connect_to_me(int phoneid, int arg1, int arg2, ipcarg_t *phone);
extern int ipc_connect_me_to(int phoneid, int arg1, int arg2);
extern int ipc_hangup(int phoneid);
extern int ipc_register_irq(int irq, irq_code_t *code);
extern int ipc_unregister_irq(int irq);
extern int ipc_forward_fast(ipc_callid_t callid, int phoneid, int method, ipcarg_t arg1);
extern void _ipc_init(void);
 
#endif
/uspace/trunk/libc/include/libipc/ns.h
0,0 → 1,36
/*
* Copyright (C) 2006 Ondrej Palkovsky
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __LIBIPC__NS_H__
#define __LIBIPC__NS_H__
 
#define NS_PING 1024
#define NS_PING_SVC 1025
#define NS_HANGUP 1026
 
#endif
/uspace/trunk/libc/include/libipc/services.h
0,0 → 1,41
/*
* Copyright (C) 2006 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/**
* @file services.h
* @brief List of all known services and their codes.
*/
 
#ifndef __LIBIPC__SERVICES_H__
#define __LIBIPC__SERVICES_H__
 
#define SERVICE_PCI 1
#define SERVICE_FRAME_BUFFER 2
#define SERVICE_KEYBOARD 3
 
#endif
/uspace/trunk/libc/generic/ipc.c
0,0 → 1,363
/*
* Copyright (C) 2006 Ondrej Palkovsky
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#include <ipc.h>
#include <libc.h>
#include <malloc.h>
#include <errno.h>
#include <list.h>
#include <stdio.h>
#include <unistd.h>
#include <futex.h>
 
/** Structure used for keeping track of sent async msgs
* and queing unsent msgs
*
*/
typedef struct {
link_t list;
 
ipc_async_callback_t callback;
void *private;
union {
ipc_callid_t callid;
struct {
ipc_call_t data;
int phoneid;
} msg;
}u;
} async_call_t;
 
LIST_INITIALIZE(dispatched_calls);
LIST_INITIALIZE(queued_calls);
 
static atomic_t ipc_futex;
 
void _ipc_init(void)
{
futex_initialize(&ipc_futex, 1);
}
 
int ipc_call_sync(int phoneid, ipcarg_t method, ipcarg_t arg1,
ipcarg_t *result)
{
ipc_call_t resdata;
int callres;
callres = __SYSCALL4(SYS_IPC_CALL_SYNC_FAST, phoneid, method, arg1,
(sysarg_t)&resdata);
if (callres)
return callres;
if (result)
*result = IPC_GET_ARG1(resdata);
return IPC_GET_RETVAL(resdata);
}
 
int ipc_call_sync_3(int phoneid, ipcarg_t method, ipcarg_t arg1,
ipcarg_t arg2, ipcarg_t arg3,
ipcarg_t *result1, ipcarg_t *result2, ipcarg_t *result3)
{
ipc_call_t data;
int callres;
 
IPC_SET_METHOD(data, method);
IPC_SET_ARG1(data, arg1);
IPC_SET_ARG2(data, arg2);
IPC_SET_ARG3(data, arg3);
 
callres = __SYSCALL3(SYS_IPC_CALL_SYNC, phoneid, (sysarg_t)&data,
(sysarg_t)&data);
if (callres)
return callres;
 
if (result1)
*result1 = IPC_GET_ARG1(data);
if (result2)
*result2 = IPC_GET_ARG2(data);
if (result3)
*result3 = IPC_GET_ARG3(data);
return IPC_GET_RETVAL(data);
}
 
/** Syscall to send asynchronous message */
static ipc_callid_t _ipc_call_async(int phoneid, ipc_call_t *data)
{
return __SYSCALL2(SYS_IPC_CALL_ASYNC, phoneid, (sysarg_t)data);
}
 
/** Send asynchronous message
*
* - if fatal error, call callback handler with proper error code
* - if message cannot be temporarily sent, add to queue
*/
void ipc_call_async_2(int phoneid, ipcarg_t method, ipcarg_t arg1,
ipcarg_t arg2, void *private,
ipc_async_callback_t callback)
{
async_call_t *call;
ipc_callid_t callid;
 
call = malloc(sizeof(*call));
if (!call) {
callback(private, ENOMEM, NULL);
return;
}
callid = __SYSCALL4(SYS_IPC_CALL_ASYNC_FAST, phoneid, method, arg1, arg2);
if (callid == IPC_CALLRET_FATAL) {
/* Call asynchronous handler with error code */
callback(private, ENOENT, NULL);
free(call);
return;
}
 
call->callback = callback;
call->private = private;
 
if (callid == IPC_CALLRET_TEMPORARY) {
/* Add asynchronous call to queue of non-dispatched async calls */
call->u.msg.phoneid = phoneid;
IPC_SET_METHOD(call->u.msg.data, method);
IPC_SET_ARG1(call->u.msg.data, arg1);
IPC_SET_ARG2(call->u.msg.data, arg2);
futex_down(&ipc_futex);
list_append(&call->list, &queued_calls);
futex_up(&ipc_futex);
return;
}
call->u.callid = callid;
/* Add call to list of dispatched calls */
futex_down(&ipc_futex);
list_append(&call->list, &dispatched_calls);
futex_up(&ipc_futex);
}
 
 
/** Send a fast answer to a received call.
*
* The fast answer makes use of passing retval and first two arguments in registers.
* If you need to return more, use the ipc_answer() instead.
*
* @param callid ID of the call being answered.
* @param retval Return value.
* @param arg1 First return argument.
* @param arg2 Second return argument.
*
* @return Zero on success or a value from @ref errno.h on failure.
*/
ipcarg_t ipc_answer_fast(ipc_callid_t callid, ipcarg_t retval, ipcarg_t arg1,
ipcarg_t arg2)
{
return __SYSCALL4(SYS_IPC_ANSWER_FAST, callid, retval, arg1, arg2);
}
 
/** Send a full answer to a received call.
*
* @param callid ID of the call being answered.
* @param call Call data. Must be already initialized by the responder.
*
* @return Zero on success or a value from @ref errno.h on failure.
*/
ipcarg_t ipc_answer(ipc_callid_t callid, ipc_call_t *call)
{
return __SYSCALL2(SYS_IPC_ANSWER, callid, (sysarg_t) call);
}
 
 
/** Try to dispatch queed calls from async queue */
static void try_dispatch_queued_calls(void)
{
async_call_t *call;
ipc_callid_t callid;
 
futex_down(&ipc_futex);
while (!list_empty(&queued_calls)) {
call = list_get_instance(queued_calls.next, async_call_t,
list);
 
callid = _ipc_call_async(call->u.msg.phoneid,
&call->u.msg.data);
if (callid == IPC_CALLRET_TEMPORARY)
break;
list_remove(&call->list);
 
if (callid == IPC_CALLRET_FATAL) {
futex_up(&ipc_futex);
call->callback(call->private, ENOENT, NULL);
free(call);
futex_down(&ipc_futex);
} else {
call->u.callid = callid;
list_append(&call->list, &dispatched_calls);
}
}
futex_up(&ipc_futex);
}
 
/** Handle received answer
*
* TODO: Make it use hash table
*
* @param callid Callid (with first bit set) of the answered call
*/
static void handle_answer(ipc_callid_t callid, ipc_call_t *data)
{
link_t *item;
async_call_t *call;
 
callid &= ~IPC_CALLID_ANSWERED;
futex_down(&ipc_futex);
for (item = dispatched_calls.next; item != &dispatched_calls;
item = item->next) {
call = list_get_instance(item, async_call_t, list);
if (call->u.callid == callid) {
list_remove(&call->list);
futex_up(&ipc_futex);
call->callback(call->private,
IPC_GET_RETVAL(*data),
data);
return;
}
}
futex_up(&ipc_futex);
printf("Received unidentified answer: %P!!!\n", callid);
}
 
 
/** Wait for IPC call and return
*
* - dispatch ASYNC reoutines in the background
* @param data Space where the message is stored
* @return Callid or 0 if nothing available and started with
* IPC_WAIT_NONBLOCKING
*/
ipc_callid_t ipc_wait_for_call(ipc_call_t *call, int flags)
{
ipc_callid_t callid;
 
do {
try_dispatch_queued_calls();
 
callid = __SYSCALL2(SYS_IPC_WAIT, (sysarg_t)call, flags);
/* Handle received answers */
if (callid & IPC_CALLID_ANSWERED)
handle_answer(callid, call);
} while (callid & IPC_CALLID_ANSWERED);
 
return callid;
}
 
/** Ask destination to do a callback connection
*
* @return 0 - OK, error code
*/
int ipc_connect_to_me(int phoneid, int arg1, int arg2, ipcarg_t *phone)
{
return ipc_call_sync_3(phoneid, IPC_M_CONNECT_TO_ME, arg1,
arg2, 0, 0, 0, phone);
}
 
/** Ask through phone for a new connection to some service
*
* @return new phoneid - OK, error code
*/
int ipc_connect_me_to(int phoneid, int arg1, int arg2)
{
ipcarg_t newphid;
int res;
 
res = ipc_call_sync_3(phoneid, IPC_M_CONNECT_ME_TO, arg1,
arg2, 0, 0, 0, &newphid);
if (res)
return res;
return newphid;
}
 
/* Hang up specified phone */
int ipc_hangup(int phoneid)
{
return __SYSCALL1(SYS_IPC_HANGUP, phoneid);
}
 
int ipc_register_irq(int irq, irq_code_t *ucode)
{
return __SYSCALL2(SYS_IPC_REGISTER_IRQ, irq, (sysarg_t) ucode);
}
 
int ipc_unregister_irq(int irq)
{
return __SYSCALL1(SYS_IPC_UNREGISTER_IRQ, irq);
}
 
int ipc_forward_fast(ipc_callid_t callid, int phoneid, int method, ipcarg_t arg1)
{
return __SYSCALL4(SYS_IPC_FORWARD_FAST, callid, phoneid, method, arg1);
}
 
 
/** Open shared memory connection over specified phoneid
*
*
* Allocates AS_area, notify the other side about our intention
* to open the connection
*
* @return Connection id identifying this connection
*/
//int ipc_dgr_open(int pohoneid, size_t bufsize)
//{
/* Find new file descriptor in local descriptor table */
/* Create AS_area, initialize structures */
/* Send AS to other side, handle error states */
 
//}
/*
void ipc_dgr_close(int cid)
{
}
 
void * ipc_dgr_alloc(int cid, size_t size)
{
}
 
void ipc_dgr_free(int cid, void *area)
{
 
}
 
int ipc_dgr_send(int cid, void *area)
{
}
 
 
int ipc_dgr_send_data(int cid, void *data, size_t size)
{
}
 
*/
/uspace/trunk/libc/generic/async.c
0,0 → 1,77
/*
* Copyright (C) 2006 Ondrej Palkovsky
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
ipc_wait_t call_func(args)
{
}
 
ipc_wait_t fire_function(args)
{
stack = malloc(stacksize);
setup(stack);
add_to_list_of_ready_funcs(stack);
if (threads_waiting_for_message)
send_message_to_self_to_one_up();
}
 
void discard_result(ipc_wait_t funcid)
{
}
 
int wait_result(ipc_wait_t funcid);
{
save_context(self);
restart:
if result_available() {
if in_list_of_ready(self):
tear_off_list(self);
return retval;
}
add_to_waitlist_of(funcid);
 
take_something_from_list_of_ready();
if something {
restore_context(something);
} else { /* nothing */
wait_for_call();
if (answer) {
mark_result_ready();
put_waiting_thread_to_waitlist();
 
goto restart;
}
}
}
 
 
int ipc_call_sync(args)
{
return ipc_wait(call_func(args));
}
/uspace/trunk/libc/Makefile
60,7 → 60,8
generic/io/printf_core.c \
malloc/malloc.c \
generic/psthread.c \
generic/sysinfo.c
generic/sysinfo.c \
generic/ipc.c
 
ARCH_SOURCES += \
arch/$(ARCH)/src/entry.s \
/uspace/trunk/Makefile
35,7 → 35,6
libc \
softint \
softfloat \
libipc \
libadt \
init \
ns