Changes in uspace/srv/bd/rd/rd.c [08232ee:d9fae235] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/bd/rd/rd.c
r08232ee rd9fae235 32 32 /** @addtogroup rd 33 33 * @{ 34 */ 34 */ 35 35 36 36 /** 37 * @file 38 * @brief 37 * @file rd.c 38 * @brief Initial RAM disk for HelenOS. 39 39 */ 40 40 … … 61 61 /** Pointer to the ramdisk's image */ 62 62 static void *rd_addr; 63 63 64 /** Size of the ramdisk */ 64 65 static size_t rd_size; … … 70 71 static int rd_write_blocks(uint64_t ba, size_t cnt, const void *buf); 71 72 72 /** 73 * This rwlock protects the ramdisk's data.73 /** This rwlock protects the ramdisk's data. 74 * 74 75 * If we were to serve multiple requests (read + write or several writes) 75 * concurrently (i.e. from two or more threads), each read and write needs to be 76 * protected by this rwlock. 77 */ 76 * concurrently (i.e. from two or more threads), each read and write needs to 77 * be protected by this rwlock. 78 * 79 */ 78 80 fibril_rwlock_t rd_lock; 79 81 80 82 /** Handle one connection to ramdisk. 81 83 * 82 * @param iid 83 * @param icall 84 * @param iid Hash of the request that opened the connection. 85 * @param icall Call data of the request that opened the connection. 84 86 */ 85 87 static void rd_connection(ipc_callid_t iid, ipc_call_t *icall) … … 92 94 size_t cnt; 93 95 size_t comm_size; 94 96 95 97 /* 96 98 * Answer the first IPC_M_CONNECT_ME_TO call. 97 99 */ 98 100 ipc_answer_0(iid, EOK); 99 101 100 102 /* 101 103 * Now we wait for the client to send us its communication as_area. … … 108 110 } else { 109 111 ipc_answer_0(callid, EHANGUP); 110 return; 112 return; 111 113 } 112 114 } else { … … 178 180 return ELIMIT; 179 181 } 180 182 181 183 fibril_rwlock_read_lock(&rd_lock); 182 184 memcpy(buf, rd_addr + ba * block_size, block_size * cnt); 183 185 fibril_rwlock_read_unlock(&rd_lock); 184 186 185 187 return EOK; 186 188 } … … 193 195 return ELIMIT; 194 196 } 195 197 196 198 fibril_rwlock_write_lock(&rd_lock); 197 199 memcpy(rd_addr + ba * block_size, buf, block_size * cnt); 198 200 fibril_rwlock_write_unlock(&rd_lock); 199 201 200 202 return EOK; 201 203 } … … 204 206 static bool rd_init(void) 205 207 { 206 rd_size = sysinfo_value("rd.size"); 207 void *rd_ph_addr = (void *) sysinfo_value("rd.address.physical"); 208 209 if (rd_size == 0) { 210 printf(NAME ": No RAM disk found\n"); 208 int ret = sysinfo_get_value("rd.size", &rd_size); 209 if ((ret != EOK) || (rd_size == 0)) { 210 printf("%s: No RAM disk found\n", NAME); 211 return false; 212 } 213 214 sysarg_t rd_ph_addr; 215 ret = sysinfo_get_value("rd.address.physical", &rd_ph_addr); 216 if ((ret != EOK) || (rd_ph_addr == 0)) { 217 printf("%s: Invalid RAM disk physical address\n", NAME); 211 218 return false; 212 219 } … … 215 222 216 223 int flags = AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE; 217 int retval = physmem_map( rd_ph_addr, rd_addr,224 int retval = physmem_map((void *) rd_ph_addr, rd_addr, 218 225 ALIGN_UP(rd_size, PAGE_SIZE) >> PAGE_WIDTH, flags); 219 226 220 227 if (retval < 0) { 221 printf( NAME ": Error mapping RAM disk\n");222 return false; 223 } 224 225 printf( NAME ": Found RAM disk at %p, %d bytes\n", rd_ph_addr, rd_size);228 printf("%s: Error mapping RAM disk\n", NAME); 229 return false; 230 } 231 232 printf("%s: Found RAM disk at %p, %d bytes\n", NAME, rd_ph_addr, rd_size); 226 233 227 234 int rc = devmap_driver_register(NAME, rd_connection); 228 235 if (rc < 0) { 229 printf( NAME ": Unable to register driver (%d)\n", rc);236 printf("%s: Unable to register driver (%d)\n", NAME, rc); 230 237 return false; 231 238 } … … 234 241 if (devmap_device_register("bd/initrd", &dev_handle) != EOK) { 235 242 devmap_hangup_phone(DEVMAP_DRIVER); 236 printf( NAME ": Unable to register device\n");243 printf("%s: Unable to register device\n", NAME); 237 244 return false; 238 245 } … … 245 252 int main(int argc, char **argv) 246 253 { 247 printf( NAME ": HelenOS RAM disk server\n");254 printf("%s: HelenOS RAM disk server\n", NAME); 248 255 249 256 if (!rd_init()) 250 257 return -1; 251 258 252 printf( NAME ": Accepting connections\n");259 printf("%s: Accepting connections\n", NAME); 253 260 async_manager(); 254 261
Note:
See TracChangeset
for help on using the changeset viewer.