Changeset 2f65fb0 in mainline
- Timestamp:
- 2008-06-03T15:10:17Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 536ec42
- Parents:
- 271b540
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/rd/rd.c
r271b540 r2f65fb0 52 52 #include <async.h> 53 53 #include <futex.h> 54 #include <stdio.h> 55 #include <ipc/devmap.h> 54 56 #include "rd.h" 57 58 #define NAME "rd" 55 59 56 60 /** Pointer to the ramdisk's image. */ … … 105 109 */ 106 110 size_t size; 107 if (ipc_share_out_receive(&callid, &size, NULL)) { 111 int flags; 112 if (ipc_share_out_receive(&callid, &size, &flags)) { 108 113 if (size >= BLOCK_SIZE) { 109 114 /* … … 150 155 } 151 156 futex_down(&rd_futex); 152 memcpy(fs_va, rd_addr + offset , BLOCK_SIZE);157 memcpy(fs_va, rd_addr + offset * BLOCK_SIZE, BLOCK_SIZE); 153 158 futex_up(&rd_futex); 154 159 retval = EOK; … … 164 169 } 165 170 futex_up(&rd_futex); 166 memcpy(rd_addr + offset , fs_va, BLOCK_SIZE);171 memcpy(rd_addr + offset * BLOCK_SIZE, fs_va, BLOCK_SIZE); 167 172 futex_down(&rd_futex); 168 173 retval = EOK; … … 182 187 } 183 188 189 static int driver_register(char *name) 190 { 191 ipcarg_t retval; 192 aid_t req; 193 ipc_call_t answer; 194 int phone; 195 ipcarg_t callback_phonehash; 196 197 phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, DEVMAP_DRIVER, 0); 198 199 while (phone < 0) { 200 usleep(10000); 201 phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, 202 DEVMAP_DRIVER, 0); 203 } 204 205 req = async_send_2(phone, DEVMAP_DRIVER_REGISTER, 0, 0, &answer); 206 207 retval = ipc_data_write_start(phone, (char *) name, strlen(name) + 1); 208 209 if (retval != EOK) { 210 async_wait_for(req, NULL); 211 return -1; 212 } 213 214 async_set_client_connection(rd_connection); 215 216 ipc_connect_to_me(phone, 0, 0, 0, &callback_phonehash); 217 async_wait_for(req, &retval); 218 219 return phone; 220 } 221 222 static int device_register(int driver_phone, char *name, int *handle) 223 { 224 ipcarg_t retval; 225 aid_t req; 226 ipc_call_t answer; 227 228 req = async_send_2(driver_phone, DEVMAP_DEVICE_REGISTER, 0, 0, &answer); 229 230 retval = ipc_data_write_start(driver_phone, (char *) name, strlen(name) + 1); 231 232 if (retval != EOK) { 233 async_wait_for(req, NULL); 234 return retval; 235 } 236 237 async_wait_for(req, &retval); 238 239 if (handle != NULL) 240 *handle = -1; 241 242 if (EOK == retval) { 243 if (NULL != handle) 244 *handle = (int) IPC_GET_ARG1(answer); 245 } 246 247 return retval; 248 } 249 184 250 /** Prepare the ramdisk image for operation. */ 185 251 static bool rd_init(void) 186 252 { 187 int retval, flags;188 189 253 rd_size = sysinfo_value("rd.size"); 190 254 void *rd_ph_addr = (void *) sysinfo_value("rd.address.physical"); 191 255 192 if (rd_size == 0) 256 if (rd_size == 0) { 257 printf(NAME ": No RAM disk found\n"); 193 258 return false; 259 } 194 260 195 261 rd_addr = as_get_mappable_page(rd_size); 196 262 197 flags = AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE;198 retval = physmem_map(rd_ph_addr, rd_addr,263 int flags = AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE; 264 int retval = physmem_map(rd_ph_addr, rd_addr, 199 265 ALIGN_UP(rd_size, PAGE_SIZE) >> PAGE_WIDTH, flags); 200 266 201 if (retval < 0) 267 if (retval < 0) { 268 printf(NAME ": Error mapping RAM disk\n"); 202 269 return false; 270 } 271 272 printf(NAME ": Found RAM disk at %p, %d bytes\n", rd_ph_addr, rd_size); 273 274 int driver_phone = driver_register(NAME); 275 if (driver_phone < 0) { 276 printf(NAME ": Unable to register driver\n"); 277 return false; 278 } 279 280 int dev_handle; 281 if (EOK != device_register(driver_phone, "initrd", &dev_handle)) { 282 ipc_hangup(driver_phone); 283 printf(NAME ": Unable to register device\n"); 284 return false; 285 } 286 203 287 return true; 204 288 } … … 206 290 int main(int argc, char **argv) 207 291 { 208 if (rd_init()) { 209 ipcarg_t phonead; 210 211 async_set_client_connection(rd_connection); 212 213 /* Register service at nameserver */ 214 if (ipc_connect_to_me(PHONE_NS, SERVICE_RD, 0, 0, &phonead) != 0) 215 return -1; 216 217 async_manager(); 218 219 /* Never reached */ 220 return 0; 221 } 222 223 return -1; 292 printf(NAME ": HelenOS RAM disk server\n"); 293 294 if (!rd_init()) 295 return -1; 296 297 printf(NAME ": Accepting connections\n"); 298 async_manager(); 299 300 /* Never reached */ 301 return 0; 224 302 } 225 303
Note:
See TracChangeset
for help on using the changeset viewer.