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 <abi/ipc/ipc.h>
|
---|
39 | #include <synch/spinlock.h>
|
---|
40 | #include <synch/mutex.h>
|
---|
41 | #include <synch/waitq.h>
|
---|
42 |
|
---|
43 | #define IPC_MAX_PHONES 32
|
---|
44 |
|
---|
45 | struct answerbox;
|
---|
46 | struct task;
|
---|
47 |
|
---|
48 | typedef enum {
|
---|
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
|
---|
59 | } ipc_phone_state_t;
|
---|
60 |
|
---|
61 | /** Structure identifying phone (in TASK structure) */
|
---|
62 | typedef struct {
|
---|
63 | mutex_t lock;
|
---|
64 | link_t link;
|
---|
65 | struct answerbox *callee;
|
---|
66 | ipc_phone_state_t state;
|
---|
67 | atomic_t active_calls;
|
---|
68 | } phone_t;
|
---|
69 |
|
---|
70 | typedef struct answerbox {
|
---|
71 | IRQ_SPINLOCK_DECLARE(lock);
|
---|
72 |
|
---|
73 | struct task *task;
|
---|
74 |
|
---|
75 | waitq_t wq;
|
---|
76 |
|
---|
77 | /** Linkage for the list of task's synchronous answerboxes. */
|
---|
78 | link_t sync_box_link;
|
---|
79 |
|
---|
80 | /** Phones connected to this answerbox. */
|
---|
81 | list_t connected_phones;
|
---|
82 | /** Received calls. */
|
---|
83 | list_t calls;
|
---|
84 | list_t dispatched_calls; /* Should be hash table in the future */
|
---|
85 |
|
---|
86 | /** Answered calls. */
|
---|
87 | list_t answers;
|
---|
88 |
|
---|
89 | IRQ_SPINLOCK_DECLARE(irq_lock);
|
---|
90 |
|
---|
91 | /** Notifications from IRQ handlers. */
|
---|
92 | list_t irq_notifs;
|
---|
93 | /** IRQs with notifications to this answerbox. */
|
---|
94 | list_t irq_list;
|
---|
95 | } answerbox_t;
|
---|
96 |
|
---|
97 | typedef struct {
|
---|
98 | sysarg_t args[IPC_CALL_LEN];
|
---|
99 | /** Task which made or forwarded the call with IPC_FF_ROUTE_FROM_ME. */
|
---|
100 | struct task *task;
|
---|
101 | /** Phone which made or last masqueraded this call. */
|
---|
102 | phone_t *phone;
|
---|
103 | } ipc_data_t;
|
---|
104 |
|
---|
105 | typedef struct {
|
---|
106 | link_t link;
|
---|
107 |
|
---|
108 | unsigned int flags;
|
---|
109 |
|
---|
110 | /** Identification of the caller. */
|
---|
111 | struct task *sender;
|
---|
112 |
|
---|
113 | /*
|
---|
114 | * The caller box is different from sender->answerbox
|
---|
115 | * for synchronous calls.
|
---|
116 | */
|
---|
117 | answerbox_t *callerbox;
|
---|
118 |
|
---|
119 | /** Private data to internal IPC. */
|
---|
120 | sysarg_t priv;
|
---|
121 |
|
---|
122 | /** Data passed from/to userspace. */
|
---|
123 | ipc_data_t data;
|
---|
124 |
|
---|
125 | /** Buffer for IPC_M_DATA_WRITE and IPC_M_DATA_READ. */
|
---|
126 | uint8_t *buffer;
|
---|
127 |
|
---|
128 | /*
|
---|
129 | * The forward operation can masquerade the caller phone. For those
|
---|
130 | * cases, we must keep it aside so that the answer is processed
|
---|
131 | * correctly.
|
---|
132 | */
|
---|
133 | phone_t *caller_phone;
|
---|
134 | } call_t;
|
---|
135 |
|
---|
136 | extern answerbox_t *ipc_phone_0;
|
---|
137 |
|
---|
138 | extern void ipc_init(void);
|
---|
139 |
|
---|
140 | extern call_t *ipc_call_alloc(unsigned int);
|
---|
141 | extern void ipc_call_free(call_t *);
|
---|
142 |
|
---|
143 | extern int ipc_call(phone_t *, call_t *);
|
---|
144 | extern int ipc_call_sync(phone_t *, call_t *);
|
---|
145 | extern call_t * ipc_wait_for_call(answerbox_t *, uint32_t, unsigned int);
|
---|
146 | extern int ipc_forward(call_t *, phone_t *, answerbox_t *, unsigned int);
|
---|
147 | extern void ipc_answer(answerbox_t *, call_t *);
|
---|
148 |
|
---|
149 | extern void ipc_phone_init(phone_t *);
|
---|
150 | extern void ipc_phone_connect(phone_t *, answerbox_t *);
|
---|
151 | extern int ipc_phone_hangup(phone_t *);
|
---|
152 |
|
---|
153 | extern void ipc_answerbox_init(answerbox_t *, struct task *);
|
---|
154 |
|
---|
155 | extern void ipc_cleanup(void);
|
---|
156 | extern void ipc_backsend_err(phone_t *, call_t *, sysarg_t);
|
---|
157 | extern void ipc_answerbox_slam_phones(answerbox_t *, bool);
|
---|
158 | extern void ipc_cleanup_call_list(list_t *);
|
---|
159 |
|
---|
160 | extern void ipc_print_task(task_id_t);
|
---|
161 |
|
---|
162 | #endif
|
---|
163 |
|
---|
164 | /** @}
|
---|
165 | */
|
---|