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