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

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

Move kobject's ops out of kobject

Kobject ops is a property of the kobject type rather than the individual
kernel objects. There is no need to remember the ops in every single
instance.

  • Property mode set to 100644
File size: 5.4 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 kernel_generic_ipc
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;
49struct call;
50
51typedef enum {
52 /** Phone is free and can be allocated */
53 IPC_PHONE_FREE = 0,
54 /** Phone is connecting somewhere */
55 IPC_PHONE_CONNECTING,
56 /** Phone is connected */
57 IPC_PHONE_CONNECTED,
58 /** Phone is hung up, waiting for answers to come */
59 IPC_PHONE_HUNGUP,
60 /** Phone was hungup from server */
61 IPC_PHONE_SLAMMED
62} ipc_phone_state_t;
63
64/** Structure identifying phone (in TASK structure) */
65typedef struct phone {
66 mutex_t lock;
67 link_t link;
68 struct task *caller;
69 struct answerbox *callee;
70 /* A call prepared for hangup ahead of time, so that it cannot fail. */
71 struct call *hangup_call;
72 ipc_phone_state_t state;
73 atomic_t active_calls;
74 /** User-defined label */
75 sysarg_t label;
76 kobject_t *kobject;
77} phone_t;
78
79typedef struct answerbox {
80 IRQ_SPINLOCK_DECLARE(lock);
81
82 /** Answerbox is active until it enters cleanup. */
83 bool active;
84
85 struct task *task;
86
87 waitq_t wq;
88
89 /**
90 * Number of answers the answerbox is expecting to eventually arrive.
91 */
92 atomic_t active_calls;
93
94 /** Phones connected to this answerbox. */
95 list_t connected_phones;
96 /** Received calls. */
97 list_t calls;
98 list_t dispatched_calls; /* Should be hash table in the future */
99
100 /** Answered calls. */
101 list_t answers;
102
103 IRQ_SPINLOCK_DECLARE(irq_lock);
104
105 /** Notifications from IRQ handlers. */
106 list_t irq_notifs;
107} answerbox_t;
108
109typedef struct call {
110 kobject_t *kobject;
111
112 /**
113 * Task link.
114 * Valid only when the call is not forgotten.
115 * Protected by the task's active_calls_lock.
116 */
117 link_t ta_link;
118
119 /** Answerbox link. */
120 link_t ab_link;
121
122 unsigned int flags;
123
124 /** Protects the forget member. */
125 SPINLOCK_DECLARE(forget_lock);
126
127 /**
128 * True if the caller 'forgot' this call and donated it to the callee.
129 * Forgotten calls are discarded upon answering (the answer is not
130 * delivered) and answered calls cannot be forgotten. Forgotten calls
131 * also do not figure on the task's active call list.
132 *
133 * We keep this separate from the flags so that it is not necessary
134 * to take a lock when accessing them.
135 */
136 bool forget;
137
138 /** True if the call is in the active list. */
139 bool active;
140
141 /**
142 * Identification of the caller.
143 * Valid only when the call is not forgotten.
144 */
145 struct task *sender;
146
147 /*
148 * Answerbox that will receive the answer.
149 * This will most of the times be the sender's answerbox,
150 * but we allow for useful exceptions.
151 */
152 answerbox_t *callerbox;
153
154 /** Phone which was used to send the call. */
155 phone_t *caller_phone;
156
157 /** Private data to internal IPC. */
158 sysarg_t priv;
159
160 /** Data passed from/to userspace. */
161 ipc_data_t data;
162
163 /** Method as it was sent in the request. */
164 sysarg_t request_method;
165
166 /** Buffer for IPC_M_DATA_WRITE and IPC_M_DATA_READ. */
167 uint8_t *buffer;
168} call_t;
169
170extern slab_cache_t *phone_cache;
171
172extern answerbox_t *ipc_box_0;
173
174extern kobject_ops_t call_kobject_ops;
175
176extern void ipc_init(void);
177
178extern call_t *ipc_call_alloc(void);
179
180extern errno_t ipc_call_sync(phone_t *, call_t *);
181extern errno_t ipc_call(phone_t *, call_t *);
182extern errno_t ipc_wait_for_call(answerbox_t *, uint32_t, unsigned int, call_t **);
183extern errno_t 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 errno_t 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 *, errno_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.