source: mainline/kernel/generic/include/ipc/ipc.h@ 921b84f

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 921b84f was e2ab36f1, checked in by Jakub Jermar <jakub@…>, 14 years ago

Track client data by client task ID instead of client task hash.

  • Property mode set to 100644
File size: 4.5 KB
RevLine 
[6d9c49a]1/*
[df4ed85]2 * Copyright (c) 2006 Ondrej Palkovsky
[6d9c49a]3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
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
15 * derived from this software without specific prior written permission.
16 *
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
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
[06e1e95]29/** @addtogroup genericipc
[b45c443]30 * @{
31 */
32/** @file
33 */
34
[27ab6a7]35#ifndef KERN_IPC_H_
36#define KERN_IPC_H_
[6d9c49a]37
[c0699467]38#include <abi/ipc/ipc.h>
[ff48a15]39#include <synch/spinlock.h>
40#include <synch/mutex.h>
[fa8e7d2]41#include <synch/waitq.h>
[e2ab36f1]42#include <typedefs.h>
[fa8e7d2]43
[c0699467]44#define IPC_MAX_PHONES 32
45
[fa8e7d2]46struct answerbox;
47struct task;
48
49typedef enum {
[80bcaed]50 /** Phone is free and can be allocated */
51 IPC_PHONE_FREE = 0,
52 /** Phone is connecting somewhere */
53 IPC_PHONE_CONNECTING,
54 /** Phone is connected */
55 IPC_PHONE_CONNECTED,
56 /** Phone is hung up, waiting for answers to come */
57 IPC_PHONE_HUNGUP,
58 /** Phone was hungup from server */
59 IPC_PHONE_SLAMMED
[fa8e7d2]60} ipc_phone_state_t;
61
62/** Structure identifying phone (in TASK structure) */
63typedef struct {
[ff48a15]64 mutex_t lock;
[fa8e7d2]65 link_t link;
66 struct answerbox *callee;
67 ipc_phone_state_t state;
68 atomic_t active_calls;
69} phone_t;
70
71typedef struct answerbox {
[da1bafb]72 IRQ_SPINLOCK_DECLARE(lock);
73
[fa8e7d2]74 struct task *task;
[da1bafb]75
[fa8e7d2]76 waitq_t wq;
[da1bafb]77
[33adc6ce]78 /** Linkage for the list of task's synchronous answerboxes. */
79 link_t sync_box_link;
[da1bafb]80
[8b243f2]81 /** Phones connected to this answerbox. */
[55b77d9]82 list_t connected_phones;
[8b243f2]83 /** Received calls. */
[55b77d9]84 list_t calls;
85 list_t dispatched_calls; /* Should be hash table in the future */
[da1bafb]86
[8b243f2]87 /** Answered calls. */
[55b77d9]88 list_t answers;
[da1bafb]89
90 IRQ_SPINLOCK_DECLARE(irq_lock);
91
[8b243f2]92 /** Notifications from IRQ handlers. */
[55b77d9]93 list_t irq_notifs;
[80bcaed]94 /** IRQs with notifications to this answerbox. */
[55b77d9]95 list_t irq_list;
[fa8e7d2]96} answerbox_t;
[6d9c49a]97
98typedef struct {
[96b02eb9]99 sysarg_t args[IPC_CALL_LEN];
[f21a61e]100 /** Task which made or forwarded the call with IPC_FF_ROUTE_FROM_ME. */
[e2ab36f1]101 task_id_t task_id;
[fdb9982c]102 /** Phone which made or last masqueraded this call. */
[fbcfd458]103 phone_t *phone;
[06e1e95]104} ipc_data_t;
[6d9c49a]105
[fbcfd458]106typedef struct {
[c4e4507]107 link_t link;
[da1bafb]108
109 unsigned int flags;
110
[8b243f2]111 /** Identification of the caller. */
[fa8e7d2]112 struct task *sender;
[da1bafb]113
114 /*
115 * The caller box is different from sender->answerbox
116 * for synchronous calls.
117 */
[fbcfd458]118 answerbox_t *callerbox;
[da1bafb]119
[8b243f2]120 /** Private data to internal IPC. */
[96b02eb9]121 sysarg_t priv;
[da1bafb]122
[8b243f2]123 /** Data passed from/to userspace. */
[80bcaed]124 ipc_data_t data;
[da1bafb]125
[a55d5f9f]126 /** Buffer for IPC_M_DATA_WRITE and IPC_M_DATA_READ. */
[7918fce]127 uint8_t *buffer;
[da1bafb]128
[27526e87]129 /*
130 * The forward operation can masquerade the caller phone. For those
131 * cases, we must keep it aside so that the answer is processed
132 * correctly.
133 */
134 phone_t *caller_phone;
[06e1e95]135} call_t;
[6d9c49a]136
[fd1210a]137extern answerbox_t *ipc_phone_0;
138
[6d9c49a]139extern void ipc_init(void);
[fd1210a]140
[da1bafb]141extern call_t *ipc_call_alloc(unsigned int);
[fd1210a]142extern void ipc_call_free(call_t *);
143
[12ab886]144extern int ipc_call(phone_t *, call_t *);
[79872cd]145extern int ipc_call_sync(phone_t *, call_t *);
[da1bafb]146extern call_t * ipc_wait_for_call(answerbox_t *, uint32_t, unsigned int);
147extern int ipc_forward(call_t *, phone_t *, answerbox_t *, unsigned int);
[fd1210a]148extern void ipc_answer(answerbox_t *, call_t *);
149
[12ab886]150extern void ipc_phone_init(phone_t *);
151extern void ipc_phone_connect(phone_t *, answerbox_t *);
[fd1210a]152extern int ipc_phone_hangup(phone_t *);
153
[12ab886]154extern void ipc_answerbox_init(answerbox_t *, struct task *);
[fd1210a]155
[d79dcdb]156extern void ipc_cleanup(void);
[96b02eb9]157extern void ipc_backsend_err(phone_t *, call_t *, sysarg_t);
[9a1b20c]158extern void ipc_answerbox_slam_phones(answerbox_t *, bool);
[55b77d9]159extern void ipc_cleanup_call_list(list_t *);
[7c7aae16]160
[fd1210a]161extern void ipc_print_task(task_id_t);
[6d9c49a]162
163#endif
[b45c443]164
[27ab6a7]165/** @}
[b45c443]166 */
Note: See TracBrowser for help on using the repository browser.