Rev 4419 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4419 | Rev 4420 | ||
---|---|---|---|
Line 50... | Line 50... | ||
50 | #include <async.h> |
50 | #include <async.h> |
51 | #include <align.h> |
51 | #include <align.h> |
52 | #include <async.h> |
52 | #include <async.h> |
53 | #include <futex.h> |
53 | #include <futex.h> |
54 | #include <stdio.h> |
54 | #include <stdio.h> |
55 | #include <ipc/devmap.h> |
55 | #include <devmap.h> |
56 | #include "rd.h" |
56 | #include <ipc/bd.h> |
57 | 57 | ||
58 | #define NAME "rd" |
58 | #define NAME "rd" |
59 | 59 | ||
60 | /** Pointer to the ramdisk's image. */ |
60 | /** Pointer to the ramdisk's image. */ |
61 | static void *rd_addr; |
61 | static void *rd_addr; |
Line 110... | Line 110... | ||
110 | */ |
110 | */ |
111 | ipc_answer_0(callid, EHANGUP); |
111 | ipc_answer_0(callid, EHANGUP); |
112 | return; |
112 | return; |
113 | } |
113 | } |
114 | 114 | ||
115 | while (1) { |
115 | while (true) { |
116 | callid = async_get_call(&call); |
116 | callid = async_get_call(&call); |
117 | switch (IPC_GET_METHOD(call)) { |
117 | switch (IPC_GET_METHOD(call)) { |
118 | case IPC_M_PHONE_HUNGUP: |
118 | case IPC_M_PHONE_HUNGUP: |
119 | /* |
119 | /* |
120 | * The other side has hung up. |
120 | * The other side has hung up. |
121 | * Answer the message and exit the fibril. |
121 | * Answer the message and exit the fibril. |
122 | */ |
122 | */ |
123 | ipc_answer_0(callid, EOK); |
123 | ipc_answer_0(callid, EOK); |
124 | return; |
124 | return; |
125 | case RD_READ_BLOCK: |
125 | case BD_READ_BLOCK: |
126 | offset = IPC_GET_ARG1(call); |
126 | offset = IPC_GET_ARG1(call); |
127 | block_size = IPC_GET_ARG2(call); |
127 | block_size = IPC_GET_ARG2(call); |
128 | if (block_size > maxblock_size) { |
128 | if (block_size > maxblock_size) { |
129 | /* |
129 | /* |
130 | * Maximum block size exceeded. |
130 | * Maximum block size exceeded. |
Line 142... | Line 142... | ||
142 | futex_down(&rd_futex); |
142 | futex_down(&rd_futex); |
143 | memcpy(fs_va, rd_addr + offset * block_size, block_size); |
143 | memcpy(fs_va, rd_addr + offset * block_size, block_size); |
144 | futex_up(&rd_futex); |
144 | futex_up(&rd_futex); |
145 | retval = EOK; |
145 | retval = EOK; |
146 | break; |
146 | break; |
147 | case RD_WRITE_BLOCK: |
147 | case BD_WRITE_BLOCK: |
148 | offset = IPC_GET_ARG1(call); |
148 | offset = IPC_GET_ARG1(call); |
149 | block_size = IPC_GET_ARG2(call); |
149 | block_size = IPC_GET_ARG2(call); |
150 | if (block_size > maxblock_size) { |
150 | if (block_size > maxblock_size) { |
151 | /* |
151 | /* |
152 | * Maximum block size exceeded. |
152 | * Maximum block size exceeded. |
Line 178... | Line 178... | ||
178 | } |
178 | } |
179 | ipc_answer_0(callid, retval); |
179 | ipc_answer_0(callid, retval); |
180 | } |
180 | } |
181 | } |
181 | } |
182 | 182 | ||
183 | static int driver_register(char *name) |
- | |
184 | { |
- | |
185 | ipcarg_t retval; |
- | |
186 | aid_t req; |
- | |
187 | ipc_call_t answer; |
- | |
188 | int phone; |
- | |
189 | ipcarg_t callback_phonehash; |
- | |
190 | - | ||
191 | phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAP, DEVMAP_DRIVER, 0); |
- | |
192 | if (phone < 0) { |
- | |
193 | printf(NAME ": Failed to connect to device mapper\n"); |
- | |
194 | return -1; |
- | |
195 | } |
- | |
196 | - | ||
197 | req = async_send_2(phone, DEVMAP_DRIVER_REGISTER, 0, 0, &answer); |
- | |
198 | - | ||
199 | retval = ipc_data_write_start(phone, (char *) name, str_size(name) + 1); |
- | |
200 | - | ||
201 | if (retval != EOK) { |
- | |
202 | async_wait_for(req, NULL); |
- | |
203 | return -1; |
- | |
204 | } |
- | |
205 | - | ||
206 | async_set_client_connection(rd_connection); |
- | |
207 | - | ||
208 | ipc_connect_to_me(phone, 0, 0, 0, &callback_phonehash); |
- | |
209 | async_wait_for(req, &retval); |
- | |
210 | - | ||
211 | return phone; |
- | |
212 | } |
- | |
213 | - | ||
214 | static int device_register(int driver_phone, char *name, int *handle) |
- | |
215 | { |
- | |
216 | ipcarg_t retval; |
- | |
217 | aid_t req; |
- | |
218 | ipc_call_t answer; |
- | |
219 | - | ||
220 | req = async_send_2(driver_phone, DEVMAP_DEVICE_REGISTER, 0, 0, &answer); |
- | |
221 | - | ||
222 | retval = ipc_data_write_start(driver_phone, (char *) name, |
- | |
223 | str_size(name) + 1); |
- | |
224 | - | ||
225 | if (retval != EOK) { |
- | |
226 | async_wait_for(req, NULL); |
- | |
227 | return retval; |
- | |
228 | } |
- | |
229 | - | ||
230 | async_wait_for(req, &retval); |
- | |
231 | - | ||
232 | if (handle != NULL) |
- | |
233 | *handle = -1; |
- | |
234 | - | ||
235 | if (EOK == retval) { |
- | |
236 | if (NULL != handle) |
- | |
237 | *handle = (int) IPC_GET_ARG1(answer); |
- | |
238 | } |
- | |
239 | - | ||
240 | return retval; |
- | |
241 | } |
- | |
242 | - | ||
243 | /** Prepare the ramdisk image for operation. */ |
183 | /** Prepare the ramdisk image for operation. */ |
244 | static bool rd_init(void) |
184 | static bool rd_init(void) |
245 | { |
185 | { |
246 | rd_size = sysinfo_value("rd.size"); |
186 | rd_size = sysinfo_value("rd.size"); |
247 | void *rd_ph_addr = (void *) sysinfo_value("rd.address.physical"); |
187 | void *rd_ph_addr = (void *) sysinfo_value("rd.address.physical"); |
Line 262... | Line 202... | ||
262 | return false; |
202 | return false; |
263 | } |
203 | } |
264 | 204 | ||
265 | printf(NAME ": Found RAM disk at %p, %d bytes\n", rd_ph_addr, rd_size); |
205 | printf(NAME ": Found RAM disk at %p, %d bytes\n", rd_ph_addr, rd_size); |
266 | 206 | ||
267 | int driver_phone = driver_register(NAME); |
207 | int rc = devmap_driver_register(NAME, rd_connection); |
268 | if (driver_phone < 0) { |
208 | if (rc < 0) { |
269 | printf(NAME ": Unable to register driver\n"); |
209 | printf(NAME ": Unable to register driver (%d)\n", rc); |
270 | return false; |
210 | return false; |
271 | } |
211 | } |
272 | 212 | ||
273 | int dev_handle; |
213 | dev_handle_t dev_handle; |
274 | if (EOK != device_register(driver_phone, "initrd", &dev_handle)) { |
214 | if (devmap_device_register("initrd", &dev_handle) != EOK) { |
275 | ipc_hangup(driver_phone); |
215 | devmap_hangup_phone(DEVMAP_DRIVER); |
276 | printf(NAME ": Unable to register device\n"); |
216 | printf(NAME ": Unable to register device\n"); |
277 | return false; |
217 | return false; |
278 | } |
218 | } |
279 | 219 | ||
280 | return true; |
220 | return true; |
Line 294... | Line 234... | ||
294 | return 0; |
234 | return 0; |
295 | } |
235 | } |
296 | 236 | ||
297 | /** |
237 | /** |
298 | * @} |
238 | * @} |
299 | */ |
239 | */ |