Rev 1072 | Rev 1084 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1072 | Rev 1083 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2006 Ondrej Palkovsky |
2 | * Copyright (C) 2006 Ondrej Palkovsky |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
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 |
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. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
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 |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
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. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /* IPC resources management |
29 | /* IPC resources management |
30 | * |
30 | * |
31 | * The goal of this source code is to properly manage IPC resources |
31 | * The goal of this source code is to properly manage IPC resources |
32 | * and allow straight and clean clean-up procedure upon task termination. |
32 | * and allow straight and clean clean-up procedure upon task termination. |
33 | * |
33 | * |
34 | * The pattern of usage of the resources is: |
34 | * The pattern of usage of the resources is: |
35 | * - allocate empty phone slot, connect | deallocate slot |
35 | * - allocate empty phone slot, connect | deallocate slot |
36 | * - disconnect connected phone (some messages might be on the fly) |
36 | * - disconnect connected phone (some messages might be on the fly) |
37 | * - find phone in slot and send a message using phone |
37 | * - find phone in slot and send a message using phone |
38 | * - answer message to phone |
38 | * - answer message to phone |
39 | * |
39 | * |
40 | * |
40 | * |
41 | */ |
41 | */ |
42 | 42 | ||
43 | #include <synch/spinlock.h> |
43 | #include <synch/spinlock.h> |
44 | #include <ipc/ipc.h> |
44 | #include <ipc/ipc.h> |
45 | #include <arch.h> |
45 | #include <arch.h> |
46 | #include <proc/task.h> |
46 | #include <proc/task.h> |
47 | #include <ipc/ipcrsc.h> |
47 | #include <ipc/ipcrsc.h> |
48 | #include <debug.h> |
48 | #include <debug.h> |
49 | 49 | ||
50 | /** Find call_t * in call table according to callid |
50 | /** Find call_t * in call table according to callid |
51 | * |
51 | * |
52 | * @return NULL on not found, otherwise pointer to call structure |
52 | * @return NULL on not found, otherwise pointer to call structure |
53 | */ |
53 | */ |
54 | call_t * get_call(__native callid) |
54 | call_t * get_call(__native callid) |
55 | { |
55 | { |
56 | /* TODO: Traverse list of dispatched calls and find one */ |
56 | /* TODO: Traverse list of dispatched calls and find one */ |
57 | /* TODO: locking of call, ripping it from dispatched calls etc. */ |
57 | /* TODO: locking of call, ripping it from dispatched calls etc. */ |
58 | return (call_t *) callid; |
58 | return (call_t *) callid; |
59 | } |
59 | } |
60 | 60 | ||
61 | /** Return pointer to phone identified by phoneid or NULL if non-existent */ |
61 | /** Return pointer to phone identified by phoneid or NULL if non-existent */ |
62 | phone_t * get_phone_and_lock(__native phoneid) |
62 | phone_t * get_phone_and_lock(__native phoneid) |
63 | { |
63 | { |
64 | phone_t *phone; |
64 | phone_t *phone; |
65 | 65 | ||
66 | if (phoneid >= IPC_MAX_PHONES) |
66 | if (phoneid >= IPC_MAX_PHONES) |
67 | return NULL; |
67 | return NULL; |
68 | 68 | ||
69 | phone = &TASK->phones[phoneid]; |
69 | phone = &TASK->phones[phoneid]; |
70 | spinlock_lock(&phone->lock); |
70 | spinlock_lock(&phone->lock); |
71 | if (!phone->callee) { |
71 | if (!phone->callee) { |
72 | spinlock_unlock(&phone->lock); |
72 | spinlock_unlock(&phone->lock); |
73 | return NULL; |
73 | return NULL; |
74 | } |
74 | } |
- | 75 | /* TODO... */ |
|
- | 76 | spinlock_unlock(&phone->lock); |
|
75 | return phone; |
77 | return phone; |
76 | } |
78 | } |
77 | 79 | ||
78 | /** Allocate new phone slot in current TASK structure */ |
80 | /** Allocate new phone slot in current TASK structure */ |
79 | int phone_alloc(void) |
81 | int phone_alloc(void) |
80 | { |
82 | { |
81 | int i; |
83 | int i; |
82 | 84 | ||
83 | spinlock_lock(&TASK->lock); |
85 | spinlock_lock(&TASK->lock); |
84 | 86 | ||
85 | for (i=0; i < IPC_MAX_PHONES; i++) { |
87 | for (i=0; i < IPC_MAX_PHONES; i++) { |
86 | if (!TASK->phones[i].busy) { |
88 | if (!TASK->phones[i].busy) { |
87 | TASK->phones[i].busy = 1; |
89 | TASK->phones[i].busy = 1; |
88 | break; |
90 | break; |
89 | } |
91 | } |
90 | } |
92 | } |
91 | spinlock_unlock(&TASK->lock); |
93 | spinlock_unlock(&TASK->lock); |
92 | 94 | ||
93 | if (i >= IPC_MAX_PHONES) |
95 | if (i >= IPC_MAX_PHONES) |
94 | return -1; |
96 | return -1; |
95 | return i; |
97 | return i; |
96 | } |
98 | } |
97 | 99 | ||
98 | /** Disconnect phone */ |
100 | /** Disconnect phone */ |
99 | void phone_dealloc(int phoneid) |
101 | void phone_dealloc(int phoneid) |
100 | { |
102 | { |
101 | spinlock_lock(&TASK->lock); |
103 | spinlock_lock(&TASK->lock); |
102 | 104 | ||
103 | ASSERT(TASK->phones[phoneid].busy); |
105 | ASSERT(TASK->phones[phoneid].busy); |
104 | 106 | ||
105 | if (TASK->phones[phoneid].callee) |
107 | if (TASK->phones[phoneid].callee) |
106 | ipc_phone_destroy(&TASK->phones[phoneid]); |
108 | ipc_phone_destroy(&TASK->phones[phoneid]); |
107 | 109 | ||
108 | TASK->phones[phoneid].busy = 0; |
110 | TASK->phones[phoneid].busy = 0; |
109 | spinlock_unlock(&TASK->lock); |
111 | spinlock_unlock(&TASK->lock); |
110 | } |
112 | } |
111 | 113 | ||
112 | void phone_connect(int phoneid, answerbox_t *box) |
114 | void phone_connect(int phoneid, answerbox_t *box) |
113 | { |
115 | { |
114 | phone_t *phone = &TASK->phones[phoneid]; |
116 | phone_t *phone = &TASK->phones[phoneid]; |
115 | 117 | ||
116 | ipc_phone_connect(phone, box); |
118 | ipc_phone_connect(phone, box); |
117 | } |
119 | } |
118 | 120 |