Rev 4400 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4400 | Rev 4401 | ||
---|---|---|---|
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 <ipc/bd.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. */ |
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 driver_phone = devmap_driver_register(NAME, rd_connection); |
268 | if (driver_phone < 0) { |
208 | if (driver_phone < 0) { |
269 | printf(NAME ": Unable to register driver\n"); |
209 | printf(NAME ": Unable to register driver\n"); |
270 | return false; |
210 | return false; |
271 | } |
211 | } |
272 | 212 | ||
273 | int dev_handle; |
213 | int dev_handle; |
274 | if (EOK != device_register(driver_phone, "initrd", &dev_handle)) { |
214 | if (devmap_device_register(driver_phone, "initrd", &dev_handle) != EOK) { |
275 | ipc_hangup(driver_phone); |
215 | ipc_hangup(driver_phone); |
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 | ||
Line 281... | Line 221... | ||
281 | * Create the second device. |
221 | * Create the second device. |
282 | * We need at least two devices for the sake of testing of non-root |
222 | * We need at least two devices for the sake of testing of non-root |
283 | * mounts. Of course it would be better to allow the second device |
223 | * mounts. Of course it would be better to allow the second device |
284 | * be created dynamically... |
224 | * be created dynamically... |
285 | */ |
225 | */ |
286 | if (EOK != device_register(driver_phone, "spared", &dev_handle)) { |
226 | if (devmap_device_register(driver_phone, "spared", &dev_handle) != EOK) { |
287 | ipc_hangup(driver_phone); |
227 | ipc_hangup(driver_phone); |
288 | printf(NAME ": Unable to register device\n"); |
228 | printf(NAME ": Unable to register device\n"); |
289 | return false; |
229 | return false; |
290 | } |
230 | } |
291 | 231 |