[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 |
|
---|
[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>
|
---|
[fa8e7d2] | 44 |
|
---|
| 45 | struct answerbox;
|
---|
| 46 | struct task;
|
---|
| 47 |
|
---|
| 48 | typedef enum {
|
---|
[80bcaed] | 49 | /** Phone is free and can be allocated */
|
---|
| 50 | IPC_PHONE_FREE = 0,
|
---|
| 51 | /** Phone is connecting somewhere */
|
---|
| 52 | IPC_PHONE_CONNECTING,
|
---|
| 53 | /** Phone is connected */
|
---|
| 54 | IPC_PHONE_CONNECTED,
|
---|
| 55 | /** Phone is hung up, waiting for answers to come */
|
---|
| 56 | IPC_PHONE_HUNGUP,
|
---|
| 57 | /** Phone was hungup from server */
|
---|
| 58 | IPC_PHONE_SLAMMED
|
---|
[fa8e7d2] | 59 | } ipc_phone_state_t;
|
---|
| 60 |
|
---|
| 61 | /** Structure identifying phone (in TASK structure) */
|
---|
| 62 | typedef struct {
|
---|
[ff48a15] | 63 | mutex_t lock;
|
---|
[fa8e7d2] | 64 | link_t link;
|
---|
[03a8a8e] | 65 | struct task *caller;
|
---|
[fa8e7d2] | 66 | struct answerbox *callee;
|
---|
| 67 | ipc_phone_state_t state;
|
---|
| 68 | atomic_t active_calls;
|
---|
| 69 | } phone_t;
|
---|
| 70 |
|
---|
| 71 | typedef struct answerbox {
|
---|
[da1bafb] | 72 | IRQ_SPINLOCK_DECLARE(lock);
|
---|
[c33f39f] | 73 |
|
---|
| 74 | /** Answerbox is active until it enters cleanup. */
|
---|
| 75 | bool active;
|
---|
[da1bafb] | 76 |
|
---|
[fa8e7d2] | 77 | struct task *task;
|
---|
[da1bafb] | 78 |
|
---|
[fa8e7d2] | 79 | waitq_t wq;
|
---|
[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 |
|
---|
| 98 | typedef struct {
|
---|
[96b02eb9] | 99 | sysarg_t args[IPC_CALL_LEN];
|
---|
[ab34cc9] | 100 | /**
|
---|
| 101 | * Task which made or forwarded the call with IPC_FF_ROUTE_FROM_ME,
|
---|
| 102 | * or the task which answered the call.
|
---|
| 103 | */
|
---|
[e2ab36f1] | 104 | task_id_t task_id;
|
---|
[fdb9982c] | 105 | /** Phone which made or last masqueraded this call. */
|
---|
[fbcfd458] | 106 | phone_t *phone;
|
---|
[06e1e95] | 107 | } ipc_data_t;
|
---|
[6d9c49a] | 108 |
|
---|
[fbcfd458] | 109 | typedef struct {
|
---|
[2405bb5] | 110 | /**
|
---|
| 111 | * Task link.
|
---|
| 112 | * Valid only when the call is not forgotten.
|
---|
| 113 | * Protected by the task's active_calls_lock.
|
---|
| 114 | */
|
---|
[86939b1] | 115 | link_t ta_link;
|
---|
| 116 |
|
---|
[cd671c3] | 117 | atomic_t refcnt;
|
---|
| 118 |
|
---|
[cfaa35a] | 119 | /** Answerbox link. */
|
---|
| 120 | link_t ab_link;
|
---|
[da1bafb] | 121 |
|
---|
| 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;
|
---|
[da1bafb] | 140 |
|
---|
[2405bb5] | 141 | /**
|
---|
| 142 | * Identification of the caller.
|
---|
| 143 | * Valid only when the call is not forgotten.
|
---|
| 144 | */
|
---|
[fa8e7d2] | 145 | struct task *sender;
|
---|
[da1bafb] | 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;
|
---|
| 156 |
|
---|
[8b243f2] | 157 | /** Private data to internal IPC. */
|
---|
[96b02eb9] | 158 | sysarg_t priv;
|
---|
[da1bafb] | 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 |
|
---|
[fd1210a] | 170 | extern answerbox_t *ipc_phone_0;
|
---|
| 171 |
|
---|
[6d9c49a] | 172 | extern void ipc_init(void);
|
---|
[fd1210a] | 173 |
|
---|
[da1bafb] | 174 | extern call_t *ipc_call_alloc(unsigned int);
|
---|
[fd1210a] | 175 | extern void ipc_call_free(call_t *);
|
---|
[cd671c3] | 176 | extern void ipc_call_hold(call_t *);
|
---|
| 177 | extern void ipc_call_release(call_t *);
|
---|
[fd1210a] | 178 |
|
---|
[bc117a5] | 179 | extern int ipc_call_sync(phone_t *, call_t *);
|
---|
[12ab886] | 180 | extern int ipc_call(phone_t *, call_t *);
|
---|
[4e5dabf] | 181 | extern call_t *ipc_wait_for_call(answerbox_t *, uint32_t, unsigned int);
|
---|
[da1bafb] | 182 | extern int ipc_forward(call_t *, phone_t *, answerbox_t *, unsigned int);
|
---|
[fd1210a] | 183 | extern void ipc_answer(answerbox_t *, call_t *);
|
---|
[f9841e69] | 184 | extern void _ipc_answer_free_call(call_t *, bool);
|
---|
[fd1210a] | 185 |
|
---|
[03a8a8e] | 186 | extern void ipc_phone_init(phone_t *, struct task *);
|
---|
[c33f39f] | 187 | extern bool ipc_phone_connect(phone_t *, answerbox_t *);
|
---|
[fd1210a] | 188 | extern int ipc_phone_hangup(phone_t *);
|
---|
| 189 |
|
---|
[12ab886] | 190 | extern void ipc_answerbox_init(answerbox_t *, struct task *);
|
---|
[fd1210a] | 191 |
|
---|
[d79dcdb] | 192 | extern void ipc_cleanup(void);
|
---|
[96b02eb9] | 193 | extern void ipc_backsend_err(phone_t *, call_t *, sysarg_t);
|
---|
[9a1b20c] | 194 | extern void ipc_answerbox_slam_phones(answerbox_t *, bool);
|
---|
[5d3ed34] | 195 | extern void ipc_cleanup_call_list(answerbox_t *, list_t *);
|
---|
[7c7aae16] | 196 |
|
---|
[fd1210a] | 197 | extern void ipc_print_task(task_id_t);
|
---|
[6d9c49a] | 198 |
|
---|
| 199 | #endif
|
---|
[b45c443] | 200 |
|
---|
[27ab6a7] | 201 | /** @}
|
---|
[b45c443] | 202 | */
|
---|