[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 |
|
---|
[19fc04c] | 45 | #define IPC_MAX_PHONES 64
|
---|
[c0699467] | 46 |
|
---|
[fa8e7d2] | 47 | struct answerbox;
|
---|
| 48 | struct task;
|
---|
| 49 |
|
---|
| 50 | typedef enum {
|
---|
[80bcaed] | 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
|
---|
[fa8e7d2] | 61 | } ipc_phone_state_t;
|
---|
| 62 |
|
---|
| 63 | /** Structure identifying phone (in TASK structure) */
|
---|
| 64 | typedef struct {
|
---|
[ff48a15] | 65 | mutex_t lock;
|
---|
[fa8e7d2] | 66 | link_t link;
|
---|
| 67 | struct answerbox *callee;
|
---|
| 68 | ipc_phone_state_t state;
|
---|
| 69 | atomic_t active_calls;
|
---|
| 70 | } phone_t;
|
---|
| 71 |
|
---|
| 72 | typedef struct answerbox {
|
---|
[da1bafb] | 73 | IRQ_SPINLOCK_DECLARE(lock);
|
---|
| 74 |
|
---|
[fa8e7d2] | 75 | struct task *task;
|
---|
[da1bafb] | 76 |
|
---|
[fa8e7d2] | 77 | waitq_t wq;
|
---|
[da1bafb] | 78 |
|
---|
[8b243f2] | 79 | /** Phones connected to this answerbox. */
|
---|
[55b77d9] | 80 | list_t connected_phones;
|
---|
[8b243f2] | 81 | /** Received calls. */
|
---|
[55b77d9] | 82 | list_t calls;
|
---|
| 83 | list_t dispatched_calls; /* Should be hash table in the future */
|
---|
[da1bafb] | 84 |
|
---|
[8b243f2] | 85 | /** Answered calls. */
|
---|
[55b77d9] | 86 | list_t answers;
|
---|
[da1bafb] | 87 |
|
---|
| 88 | IRQ_SPINLOCK_DECLARE(irq_lock);
|
---|
| 89 |
|
---|
[8b243f2] | 90 | /** Notifications from IRQ handlers. */
|
---|
[55b77d9] | 91 | list_t irq_notifs;
|
---|
[80bcaed] | 92 | /** IRQs with notifications to this answerbox. */
|
---|
[55b77d9] | 93 | list_t irq_list;
|
---|
[fa8e7d2] | 94 | } answerbox_t;
|
---|
[6d9c49a] | 95 |
|
---|
| 96 | typedef struct {
|
---|
[96b02eb9] | 97 | sysarg_t args[IPC_CALL_LEN];
|
---|
[ab34cc9] | 98 | /**
|
---|
| 99 | * Task which made or forwarded the call with IPC_FF_ROUTE_FROM_ME,
|
---|
| 100 | * or the task which answered the call.
|
---|
| 101 | */
|
---|
[e2ab36f1] | 102 | task_id_t task_id;
|
---|
[fdb9982c] | 103 | /** Phone which made or last masqueraded this call. */
|
---|
[fbcfd458] | 104 | phone_t *phone;
|
---|
[06e1e95] | 105 | } ipc_data_t;
|
---|
[6d9c49a] | 106 |
|
---|
[fbcfd458] | 107 | typedef struct {
|
---|
[cfaa35a] | 108 | /** Answerbox link. */
|
---|
| 109 | link_t ab_link;
|
---|
[da1bafb] | 110 |
|
---|
| 111 | unsigned int flags;
|
---|
| 112 |
|
---|
[8b243f2] | 113 | /** Identification of the caller. */
|
---|
[fa8e7d2] | 114 | struct task *sender;
|
---|
[da1bafb] | 115 |
|
---|
[8b243f2] | 116 | /** Private data to internal IPC. */
|
---|
[96b02eb9] | 117 | sysarg_t priv;
|
---|
[da1bafb] | 118 |
|
---|
[8b243f2] | 119 | /** Data passed from/to userspace. */
|
---|
[80bcaed] | 120 | ipc_data_t data;
|
---|
[da1bafb] | 121 |
|
---|
[a55d5f9f] | 122 | /** Buffer for IPC_M_DATA_WRITE and IPC_M_DATA_READ. */
|
---|
[7918fce] | 123 | uint8_t *buffer;
|
---|
[da1bafb] | 124 |
|
---|
[27526e87] | 125 | /*
|
---|
| 126 | * The forward operation can masquerade the caller phone. For those
|
---|
| 127 | * cases, we must keep it aside so that the answer is processed
|
---|
| 128 | * correctly.
|
---|
| 129 | */
|
---|
| 130 | phone_t *caller_phone;
|
---|
[06e1e95] | 131 | } call_t;
|
---|
[6d9c49a] | 132 |
|
---|
[fd1210a] | 133 | extern answerbox_t *ipc_phone_0;
|
---|
| 134 |
|
---|
[6d9c49a] | 135 | extern void ipc_init(void);
|
---|
[fd1210a] | 136 |
|
---|
[da1bafb] | 137 | extern call_t *ipc_call_alloc(unsigned int);
|
---|
[fd1210a] | 138 | extern void ipc_call_free(call_t *);
|
---|
| 139 |
|
---|
[12ab886] | 140 | extern int ipc_call(phone_t *, call_t *);
|
---|
[4e5dabf] | 141 | extern call_t *ipc_wait_for_call(answerbox_t *, uint32_t, unsigned int);
|
---|
[da1bafb] | 142 | extern int ipc_forward(call_t *, phone_t *, answerbox_t *, unsigned int);
|
---|
[fd1210a] | 143 | extern void ipc_answer(answerbox_t *, call_t *);
|
---|
| 144 |
|
---|
[12ab886] | 145 | extern void ipc_phone_init(phone_t *);
|
---|
| 146 | extern void ipc_phone_connect(phone_t *, answerbox_t *);
|
---|
[fd1210a] | 147 | extern int ipc_phone_hangup(phone_t *);
|
---|
| 148 |
|
---|
[12ab886] | 149 | extern void ipc_answerbox_init(answerbox_t *, struct task *);
|
---|
[fd1210a] | 150 |
|
---|
[d79dcdb] | 151 | extern void ipc_cleanup(void);
|
---|
[96b02eb9] | 152 | extern void ipc_backsend_err(phone_t *, call_t *, sysarg_t);
|
---|
[9a1b20c] | 153 | extern void ipc_answerbox_slam_phones(answerbox_t *, bool);
|
---|
[55b77d9] | 154 | extern void ipc_cleanup_call_list(list_t *);
|
---|
[7c7aae16] | 155 |
|
---|
[fd1210a] | 156 | extern void ipc_print_task(task_id_t);
|
---|
[6d9c49a] | 157 |
|
---|
| 158 | #endif
|
---|
[b45c443] | 159 |
|
---|
[27ab6a7] | 160 | /** @}
|
---|
[b45c443] | 161 | */
|
---|