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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a35b458 was a35b458, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

  • Property mode set to 100644
File size: 5.6 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#include <cap/cap.h>
46
47struct answerbox;
48struct task;
49
50typedef enum {
51 /** Phone is free and can be allocated */
52 IPC_PHONE_FREE = 0,
53 /** Phone is connecting somewhere */
54 IPC_PHONE_CONNECTING,
55 /** Phone is connected */
56 IPC_PHONE_CONNECTED,
57 /** Phone is hung up, waiting for answers to come */
58 IPC_PHONE_HUNGUP,
59 /** Phone was hungup from server */
60 IPC_PHONE_SLAMMED
61} ipc_phone_state_t;
62
63/** Structure identifying phone (in TASK structure) */
64typedef struct phone {
65 mutex_t lock;
66 link_t link;
67 struct task *caller;
68 struct answerbox *callee;
69 ipc_phone_state_t state;
70 atomic_t active_calls;
71 kobject_t *kobject;
72} phone_t;
73
74typedef struct answerbox {
75 IRQ_SPINLOCK_DECLARE(lock);
76
77 /** Answerbox is active until it enters cleanup. */
78 bool active;
79
80 struct task *task;
81
82 waitq_t wq;
83
84 /** Phones connected to this answerbox. */
85 list_t connected_phones;
86 /** Received calls. */
87 list_t calls;
88 list_t dispatched_calls; /* Should be hash table in the future */
89
90 /** Answered calls. */
91 list_t answers;
92
93 IRQ_SPINLOCK_DECLARE(irq_lock);
94
95 /** Notifications from IRQ handlers. */
96 list_t irq_notifs;
97} answerbox_t;
98
99typedef struct {
100 sysarg_t args[IPC_CALL_LEN];
101 /**
102 * Task which made or forwarded the call with IPC_FF_ROUTE_FROM_ME,
103 * or the task which answered the call.
104 */
105 task_id_t task_id;
106 /** Phone which made or last masqueraded this call. */
107 phone_t *phone;
108 /** Flags */
109 unsigned flags;
110 /** User-defined label */
111 sysarg_t label;
112 /** Capability handle */
113 cap_handle_t cap_handle;
114} ipc_data_t;
115
116typedef struct call {
117 kobject_t *kobject;
118
119 /**
120 * Task link.
121 * Valid only when the call is not forgotten.
122 * Protected by the task's active_calls_lock.
123 */
124 link_t ta_link;
125
126 /** Answerbox link. */
127 link_t ab_link;
128
129 unsigned int flags;
130
131 /** Protects the forget member. */
132 SPINLOCK_DECLARE(forget_lock);
133
134 /**
135 * True if the caller 'forgot' this call and donated it to the callee.
136 * Forgotten calls are discarded upon answering (the answer is not
137 * delivered) and answered calls cannot be forgotten. Forgotten calls
138 * also do not figure on the task's active call list.
139 *
140 * We keep this separate from the flags so that it is not necessary
141 * to take a lock when accessing them.
142 */
143 bool forget;
144
145 /** True if the call is in the active list. */
146 bool active;
147
148 /**
149 * Identification of the caller.
150 * Valid only when the call is not forgotten.
151 */
152 struct task *sender;
153
154 /*
155 * Answerbox that will receive the answer.
156 * This will most of the times be the sender's answerbox,
157 * but we allow for useful exceptions.
158 */
159 answerbox_t *callerbox;
160
161 /** Phone which was used to send the call. */
162 phone_t *caller_phone;
163
164 /** Private data to internal IPC. */
165 sysarg_t priv;
166
167 /** Data passed from/to userspace. */
168 ipc_data_t data;
169
170 /** Method as it was sent in the request. */
171 sysarg_t request_method;
172
173 /** Buffer for IPC_M_DATA_WRITE and IPC_M_DATA_READ. */
174 uint8_t *buffer;
175} call_t;
176
177extern slab_cache_t *phone_cache;
178
179extern answerbox_t *ipc_phone_0;
180
181extern void ipc_init(void);
182
183extern call_t *ipc_call_alloc(unsigned int);
184extern void ipc_call_free(call_t *);
185extern void ipc_call_hold(call_t *);
186extern void ipc_call_release(call_t *);
187
188extern errno_t ipc_call_sync(phone_t *, call_t *);
189extern errno_t ipc_call(phone_t *, call_t *);
190extern call_t *ipc_wait_for_call(answerbox_t *, uint32_t, unsigned int);
191extern errno_t ipc_forward(call_t *, phone_t *, answerbox_t *, unsigned int);
192extern void ipc_answer(answerbox_t *, call_t *);
193extern void _ipc_answer_free_call(call_t *, bool);
194
195extern void ipc_phone_init(phone_t *, struct task *);
196extern bool ipc_phone_connect(phone_t *, answerbox_t *);
197extern errno_t ipc_phone_hangup(phone_t *);
198
199extern void ipc_answerbox_init(answerbox_t *, struct task *);
200
201extern void ipc_cleanup(void);
202extern void ipc_backsend_err(phone_t *, call_t *, errno_t);
203extern void ipc_answerbox_slam_phones(answerbox_t *, bool);
204extern void ipc_cleanup_call_list(answerbox_t *, list_t *);
205
206extern void ipc_print_task(task_id_t);
207
208#endif
209
210/** @}
211 */
Note: See TracBrowser for help on using the repository browser.