Rev 2396 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2396 | Rev 2435 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2006 Martin Decky |
2 | * Copyright (c) 2007 Konopa-Jelen-Majer |
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 | /** @addtogroup rd |
29 | /** @addtogroup RamDiskTask |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | 32 | ||
33 | /** |
33 | /** |
34 | * @file rd.c |
34 | * @file rd.c |
35 | * @brief Initial RAM disk for HelenOS. |
35 | * @brief Initial RAM disk for HelenOS. |
36 | */ |
36 | */ |
37 | 37 | ||
38 | #include <ipc/ipc.h> |
38 | #include <ipc/ipc.h> |
39 | #include <ipc/services.h> |
39 | #include <ipc/services.h> |
40 | #include <ipc/ns.h> |
40 | #include <ipc/ns.h> |
41 | #include <sysinfo.h> |
41 | #include <sysinfo.h> |
42 | #include <as.h> |
42 | #include <as.h> |
43 | #include <ddi.h> |
43 | #include <ddi.h> |
44 | #include <align.h> |
44 | #include <align.h> |
45 | #include <bool.h> |
45 | #include <bool.h> |
46 | #include <errno.h> |
46 | #include <errno.h> |
47 | #include <async.h> |
47 | #include <async.h> |
48 | #include <stdlib.h> |
48 | #include <stdlib.h> |
49 | #include <unistd.h> |
49 | #include <unistd.h> |
50 | #include <align.h> |
50 | #include <align.h> |
51 | #include <async.h> |
51 | #include <async.h> |
52 | #include <ddi.h> |
52 | #include <ddi.h> |
53 | #include <libarch/ddi.h> |
53 | #include <libarch/ddi.h> |
54 | #include <stdio.h> |
54 | #include <stdio.h> |
55 | #include "rd.h" |
55 | #include "rd.h" |
56 | #include "../console/console.h" |
56 | #include "../console/console.h" |
57 | #include "../share/base_const.h" |
57 | #include "../share/base_const.h" |
58 | 58 | ||
59 | 59 | ||
60 | #define CON_CONN_ATTEMPTS 1000 |
60 | #define CON_CONN_ATTEMPTS 1000 |
61 | 61 | ||
62 | static int con_phone; |
62 | static int con_phone; |
63 | static void *rd_addr; |
63 | static void *rd_addr; |
64 | static void *fs_addr; |
64 | static void *fs_addr; |
65 | 65 | ||
66 | static int connect_to_con(int *phone, int attempts); |
66 | static int connect_to_con(int *phone, int attempts); |
67 | 67 | ||
68 | static void rd_connection(ipc_callid_t iid, ipc_call_t *icall) |
68 | static void rd_connection(ipc_callid_t iid, ipc_call_t *icall) |
69 | { |
69 | { |
70 | ipc_callid_t callid; |
70 | ipc_callid_t callid; |
71 | ipc_call_t call; |
71 | ipc_call_t call; |
72 | int retval; |
72 | int retval; |
73 | 73 | ||
74 | ipc_answer_fast(iid, 0, 0, 0); |
74 | ipc_answer_fast(iid, 0, 0, 0); |
75 | ipcarg_t dst, offset; |
75 | ipcarg_t dst, offset; |
76 | 76 | ||
77 | while (1) { |
77 | while (1) { |
78 | callid = async_get_call(&call); |
78 | callid = async_get_call(&call); |
79 | switch (IPC_GET_METHOD(call)) { |
79 | switch (IPC_GET_METHOD(call)) { |
80 | case IPC_M_PHONE_HUNGUP: |
80 | case IPC_M_PHONE_HUNGUP: |
81 | ipc_answer_fast(callid, 0,0,0); |
81 | ipc_answer_fast(callid, 0,0,0); |
82 | return; |
82 | return; |
83 | case IPC_M_AS_AREA_SEND: |
83 | case IPC_M_AS_AREA_SEND: |
84 | //print_console("Receiving shared area from FS..."); |
84 | //print_console("Receiving shared area from FS..."); |
85 | ipc_answer_fast(callid, 0, (uintptr_t)fs_addr, 0); |
85 | ipc_answer_fast(callid, 0, (uintptr_t)fs_addr, 0); |
86 | //print_console("OK\n"); |
86 | //print_console("OK\n"); |
87 | continue; |
87 | continue; |
88 | case RD_READ_BLOCK: |
88 | case RD_READ_BLOCK: |
89 | offset = IPC_GET_ARG1(call); |
89 | offset = IPC_GET_ARG1(call); |
90 | memcpy((void *)fs_addr, rd_addr+offset, BLOCK_SIZE); |
90 | memcpy((void *)fs_addr, rd_addr+offset, BLOCK_SIZE); |
91 | retval = OK; |
91 | retval = OK; |
92 | break; |
92 | break; |
93 | default: retval = EINVAL; |
93 | default: retval = EINVAL; |
94 | } |
94 | } |
95 | ipc_answer_fast(callid, retval, 0, 0); |
95 | ipc_answer_fast(callid, retval, 0, 0); |
96 | } |
96 | } |
97 | } |
97 | } |
98 | 98 | ||
99 | 99 | ||
100 | static bool rd_init(void) |
100 | static bool rd_init(void) |
101 | { |
101 | { |
102 | 102 | ||
103 | int retval, flags; |
103 | int retval, flags; |
104 | 104 | ||
105 | size_t rd_size = sysinfo_value("rd.size"); |
105 | size_t rd_size = sysinfo_value("rd.size"); |
106 | void * rd_ph_addr = (void *) sysinfo_value("rd.address.physical"); |
106 | void * rd_ph_addr = (void *) sysinfo_value("rd.address.physical"); |
107 | int rd_color = (int) sysinfo_value("rd.address.color"); |
107 | int rd_color = (int) sysinfo_value("rd.address.color"); |
108 | 108 | ||
109 | if (rd_size == 0) |
109 | if (rd_size == 0) |
110 | return false; |
110 | return false; |
111 | 111 | ||
112 | rd_addr = as_get_mappable_page(rd_size, rd_color); |
112 | rd_addr = as_get_mappable_page(rd_size, rd_color); |
113 | 113 | ||
114 | //print_console("Physmem mapping..."); |
114 | //print_console("Physmem mapping..."); |
115 | flags = AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE; |
115 | flags = AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE; |
116 | retval = physmem_map(rd_ph_addr, rd_addr, ALIGN_UP(rd_size, PAGE_SIZE) >> PAGE_WIDTH, flags); |
116 | retval = physmem_map(rd_ph_addr, rd_addr, ALIGN_UP(rd_size, PAGE_SIZE) >> PAGE_WIDTH, flags); |
117 | 117 | ||
118 | if (retval < 0) { |
118 | if (retval < 0) { |
119 | //print_console_int("%d\n", retval); |
119 | //print_console_int("%d\n", retval); |
120 | return FALSE; |
120 | return FALSE; |
121 | } |
121 | } |
122 | //print_console("OK\n"); |
122 | //print_console("OK\n"); |
123 | 123 | ||
124 | size_t fs_size = ALIGN_UP(BLOCK_SIZE * sizeof(char), PAGE_SIZE); |
124 | size_t fs_size = ALIGN_UP(BLOCK_SIZE * sizeof(char), PAGE_SIZE); |
125 | fs_addr = as_get_mappable_page(fs_size, PAGE_COLOR((uintptr_t)fs_addr)); |
125 | fs_addr = as_get_mappable_page(fs_size, PAGE_COLOR((uintptr_t)fs_addr)); |
126 | 126 | ||
127 | return TRUE; |
127 | return TRUE; |
128 | } |
128 | } |
129 | 129 | ||
130 | int connect_to_con(int *phone, int attempts) |
130 | int connect_to_con(int *phone, int attempts) |
131 | { |
131 | { |
132 | 132 | ||
133 | int i; |
133 | int i; |
134 | 134 | ||
135 | if (attempts <= 0) |
135 | if (attempts <= 0) |
136 | return FALSE; |
136 | return FALSE; |
137 | 137 | ||
138 | for (i = 1; i <= attempts; i++) { |
138 | for (i = 1; i <= attempts; i++) { |
139 | *phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0); |
139 | *phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0); |
140 | 140 | ||
141 | if (*phone > 0) |
141 | if (*phone > 0) |
142 | return TRUE; |
142 | return TRUE; |
143 | 143 | ||
144 | usleep(10000); |
144 | usleep(10000); |
145 | } |
145 | } |
146 | 146 | ||
147 | if (*phone >= 0) |
147 | if (*phone >= 0) |
148 | return TRUE; |
148 | return TRUE; |
149 | 149 | ||
150 | return FALSE; |
150 | return FALSE; |
151 | } |
151 | } |
152 | 152 | ||
153 | int main(int argc, char **argv) |
153 | int main(int argc, char **argv) |
154 | { |
154 | { |
155 | 155 | ||
156 | /* Connection to SERVICE_CONSOLE service. */ |
156 | /* Connection to SERVICE_CONSOLE service. */ |
157 | if (!connect_to_con(&con_phone, CON_CONN_ATTEMPTS)) { |
157 | if (!connect_to_con(&con_phone, CON_CONN_ATTEMPTS)) { |
158 | return -1; |
158 | return -1; |
159 | } |
159 | } |
160 | 160 | ||
161 | //print_console("RAMDISK task\n"); |
161 | //print_console("RAMDISK task\n"); |
162 | 162 | ||
163 | if (rd_init()) { |
163 | if (rd_init()) { |
164 | ipcarg_t phonead; |
164 | ipcarg_t phonead; |
165 | 165 | ||
166 | async_set_client_connection(rd_connection); |
166 | async_set_client_connection(rd_connection); |
167 | 167 | ||
168 | /* Register service at nameserver */ |
168 | /* Register service at nameserver */ |
169 | if (ipc_connect_to_me(PHONE_NS, SERVICE_RD, 0, &phonead) != 0) |
169 | if (ipc_connect_to_me(PHONE_NS, SERVICE_RD, 0, &phonead) != 0) |
170 | return -1; |
170 | return -1; |
171 | 171 | ||
172 | async_manager(); |
172 | async_manager(); |
173 | 173 | ||
174 | /* Never reached */ |
174 | /* Never reached */ |
175 | return 0; |
175 | return 0; |
176 | } |
176 | } |
177 | 177 | ||
178 | return -1; |
178 | return -1; |
179 | } |
179 | } |
180 | 180 | ||
181 | /** |
181 | /** |
182 | * @} |
182 | * @} |
183 | */ |
183 | */ |
184 | 184 |