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

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

Allocate call for ipc_phone_hangup() ahead of time

  • Property mode set to 100644
File size: 5.4 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
[174156fd]29/** @addtogroup kernel_generic_ipc
[b45c443]30 * @{
31 */
32/** @file
33 */
34
[27ab6a7]35#ifndef KERN_IPC_H_
36#define KERN_IPC_H_
[6d9c49a]37
[ff48a15]38#include <synch/spinlock.h>
39#include <synch/mutex.h>
[fa8e7d2]40#include <synch/waitq.h>
[9a426d1f]41#include <abi/ipc/ipc.h>
42#include <abi/proc/task.h>
[e2ab36f1]43#include <typedefs.h>
[e5f5ce0]44#include <mm/slab.h>
[48bcf49]45#include <cap/cap.h>
[fa8e7d2]46
47struct answerbox;
48struct task;
[b9a2725]49struct call;
[fa8e7d2]50
51typedef enum {
[80bcaed]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
[fa8e7d2]62} ipc_phone_state_t;
63
64/** Structure identifying phone (in TASK structure) */
[48bcf49]65typedef struct phone {
[ff48a15]66 mutex_t lock;
[fa8e7d2]67 link_t link;
[03a8a8e]68 struct task *caller;
[fa8e7d2]69 struct answerbox *callee;
[b9a2725]70 /* A call prepared for hangup ahead of time, so that it cannot fail. */
71 struct call *hangup_call;
[fa8e7d2]72 ipc_phone_state_t state;
73 atomic_t active_calls;
[6769005]74 /** User-defined label */
75 sysarg_t label;
[48bcf49]76 kobject_t *kobject;
[fa8e7d2]77} phone_t;
78
79typedef struct answerbox {
[da1bafb]80 IRQ_SPINLOCK_DECLARE(lock);
[c33f39f]81
82 /** Answerbox is active until it enters cleanup. */
83 bool active;
[a35b458]84
[fa8e7d2]85 struct task *task;
[a35b458]86
[fa8e7d2]87 waitq_t wq;
[a35b458]88
[70327bb]89 /**
90 * Number of answers the answerbox is expecting to eventually arrive.
91 */
92 atomic_t active_calls;
93
[8b243f2]94 /** Phones connected to this answerbox. */
[55b77d9]95 list_t connected_phones;
[8b243f2]96 /** Received calls. */
[55b77d9]97 list_t calls;
98 list_t dispatched_calls; /* Should be hash table in the future */
[a35b458]99
[8b243f2]100 /** Answered calls. */
[55b77d9]101 list_t answers;
[a35b458]102
[da1bafb]103 IRQ_SPINLOCK_DECLARE(irq_lock);
[a35b458]104
[8b243f2]105 /** Notifications from IRQ handlers. */
[55b77d9]106 list_t irq_notifs;
[fa8e7d2]107} answerbox_t;
[6d9c49a]108
[01c3bb4]109typedef struct call {
[d51a0d6]110 kobject_t *kobject;
111
[2405bb5]112 /**
113 * Task link.
114 * Valid only when the call is not forgotten.
115 * Protected by the task's active_calls_lock.
116 */
[86939b1]117 link_t ta_link;
118
[cfaa35a]119 /** Answerbox link. */
120 link_t ab_link;
[a35b458]121
[da1bafb]122 unsigned int flags;
[2405bb5]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;
[20282ef3]137
138 /** True if the call is in the active list. */
139 bool active;
[a35b458]140
[2405bb5]141 /**
142 * Identification of the caller.
143 * Valid only when the call is not forgotten.
144 */
[fa8e7d2]145 struct task *sender;
[a35b458]146
[6d351e6]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
[5a77550]154 /** Phone which was used to send the call. */
155 phone_t *caller_phone;
[a35b458]156
[8b243f2]157 /** Private data to internal IPC. */
[96b02eb9]158 sysarg_t priv;
[a35b458]159
[8b243f2]160 /** Data passed from/to userspace. */
[80bcaed]161 ipc_data_t data;
[32e4643]162
163 /** Method as it was sent in the request. */
164 sysarg_t request_method;
165
[a55d5f9f]166 /** Buffer for IPC_M_DATA_WRITE and IPC_M_DATA_READ. */
[7918fce]167 uint8_t *buffer;
[06e1e95]168} call_t;
[6d9c49a]169
[82d515e9]170extern slab_cache_t *phone_cache;
[e5f5ce0]171
[cdc4334]172extern answerbox_t *ipc_box_0;
[fd1210a]173
[6d9c49a]174extern void ipc_init(void);
[fd1210a]175
[da1bafb]176extern call_t *ipc_call_alloc(unsigned int);
[fd1210a]177
[b7fd2a0]178extern errno_t ipc_call_sync(phone_t *, call_t *);
179extern errno_t ipc_call(phone_t *, call_t *);
[acf6b55]180extern errno_t ipc_wait_for_call(answerbox_t *, uint32_t, unsigned int, call_t **);
[b7fd2a0]181extern errno_t ipc_forward(call_t *, phone_t *, answerbox_t *, unsigned int);
[fd1210a]182extern void ipc_answer(answerbox_t *, call_t *);
[f9841e69]183extern void _ipc_answer_free_call(call_t *, bool);
[fd1210a]184
[03a8a8e]185extern void ipc_phone_init(phone_t *, struct task *);
[c33f39f]186extern bool ipc_phone_connect(phone_t *, answerbox_t *);
[b7fd2a0]187extern errno_t ipc_phone_hangup(phone_t *);
[fd1210a]188
[12ab886]189extern void ipc_answerbox_init(answerbox_t *, struct task *);
[fd1210a]190
[d79dcdb]191extern void ipc_cleanup(void);
[b7fd2a0]192extern void ipc_backsend_err(phone_t *, call_t *, errno_t);
[9a1b20c]193extern void ipc_answerbox_slam_phones(answerbox_t *, bool);
[5d3ed34]194extern void ipc_cleanup_call_list(answerbox_t *, list_t *);
[7c7aae16]195
[fd1210a]196extern void ipc_print_task(task_id_t);
[6d9c49a]197
198#endif
[b45c443]199
[27ab6a7]200/** @}
[b45c443]201 */
Note: See TracBrowser for help on using the repository browser.