source: mainline/kernel/generic/include/ipc/ipc.h@ e5f5ce0

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

Create a slab cache for allocating phone_t structures

  • Property mode set to 100644
File size: 5.5 KB
Line 
1/*
2 * Copyright (c) 2006 Ondrej Palkovsky
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
29/** @addtogroup genericipc
30 * @{
31 */
32/** @file
33 */
34
35#ifndef KERN_IPC_H_
36#define KERN_IPC_H_
37
38#include <synch/spinlock.h>
39#include <synch/mutex.h>
40#include <synch/waitq.h>
41#include <abi/ipc/ipc.h>
42#include <abi/proc/task.h>
43#include <typedefs.h>
44#include <mm/slab.h>
45
46struct answerbox;
47struct task;
48
49typedef enum {
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
60} ipc_phone_state_t;
61
62/** Structure identifying phone (in TASK structure) */
63typedef struct {
64 mutex_t lock;
65 link_t link;
66 struct task *caller;
67 struct answerbox *callee;
68 ipc_phone_state_t state;
69 atomic_t active_calls;
70} phone_t;
71
72typedef struct answerbox {
73 IRQ_SPINLOCK_DECLARE(lock);
74
75 /** Answerbox is active until it enters cleanup. */
76 bool active;
77
78 struct task *task;
79
80 waitq_t wq;
81
82 /** Phones connected to this answerbox. */
83 list_t connected_phones;
84 /** Received calls. */
85 list_t calls;
86 list_t dispatched_calls; /* Should be hash table in the future */
87
88 /** Answered calls. */
89 list_t answers;
90
91 IRQ_SPINLOCK_DECLARE(irq_lock);
92
93 /** Notifications from IRQ handlers. */
94 list_t irq_notifs;
95} answerbox_t;
96
97typedef struct {
98 sysarg_t args[IPC_CALL_LEN];
99 /**
100 * Task which made or forwarded the call with IPC_FF_ROUTE_FROM_ME,
101 * or the task which answered the call.
102 */
103 task_id_t task_id;
104 /** Phone which made or last masqueraded this call. */
105 phone_t *phone;
106} ipc_data_t;
107
108typedef struct {
109 /**
110 * Task link.
111 * Valid only when the call is not forgotten.
112 * Protected by the task's active_calls_lock.
113 */
114 link_t ta_link;
115
116 atomic_t refcnt;
117
118 /** Answerbox link. */
119 link_t ab_link;
120
121 unsigned int flags;
122
123 /** Protects the forget member. */
124 SPINLOCK_DECLARE(forget_lock);
125
126 /**
127 * True if the caller 'forgot' this call and donated it to the callee.
128 * Forgotten calls are discarded upon answering (the answer is not
129 * delivered) and answered calls cannot be forgotten. Forgotten calls
130 * also do not figure on the task's active call list.
131 *
132 * We keep this separate from the flags so that it is not necessary
133 * to take a lock when accessing them.
134 */
135 bool forget;
136
137 /** True if the call is in the active list. */
138 bool active;
139
140 /**
141 * Identification of the caller.
142 * Valid only when the call is not forgotten.
143 */
144 struct task *sender;
145
146 /*
147 * Answerbox that will receive the answer.
148 * This will most of the times be the sender's answerbox,
149 * but we allow for useful exceptions.
150 */
151 answerbox_t *callerbox;
152
153 /** Phone which was used to send the call. */
154 phone_t *caller_phone;
155
156 /** Private data to internal IPC. */
157 sysarg_t priv;
158
159 /** Data passed from/to userspace. */
160 ipc_data_t data;
161
162 /** Method as it was sent in the request. */
163 sysarg_t request_method;
164
165 /** Buffer for IPC_M_DATA_WRITE and IPC_M_DATA_READ. */
166 uint8_t *buffer;
167} call_t;
168
169extern slab_cache_t *phone_slab;
170
171extern answerbox_t *ipc_phone_0;
172
173extern void ipc_init(void);
174
175extern call_t *ipc_call_alloc(unsigned int);
176extern void ipc_call_free(call_t *);
177extern void ipc_call_hold(call_t *);
178extern void ipc_call_release(call_t *);
179
180extern int ipc_call_sync(phone_t *, call_t *);
181extern int ipc_call(phone_t *, call_t *);
182extern call_t *ipc_wait_for_call(answerbox_t *, uint32_t, unsigned int);
183extern int ipc_forward(call_t *, phone_t *, answerbox_t *, unsigned int);
184extern void ipc_answer(answerbox_t *, call_t *);
185extern void _ipc_answer_free_call(call_t *, bool);
186
187extern void ipc_phone_init(phone_t *, struct task *);
188extern bool ipc_phone_connect(phone_t *, answerbox_t *);
189extern int ipc_phone_hangup(phone_t *);
190
191extern void ipc_answerbox_init(answerbox_t *, struct task *);
192
193extern void ipc_cleanup(void);
194extern void ipc_backsend_err(phone_t *, call_t *, sysarg_t);
195extern void ipc_answerbox_slam_phones(answerbox_t *, bool);
196extern void ipc_cleanup_call_list(answerbox_t *, list_t *);
197
198extern void ipc_print_task(task_id_t);
199
200#endif
201
202/** @}
203 */
Note: See TracBrowser for help on using the repository browser.