Changes in uspace/srv/bd/rd/rd.c [08232ee:d9fae235] in mainline


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/bd/rd/rd.c

    r08232ee rd9fae235  
    3232/** @addtogroup rd
    3333 * @{
    34  */ 
     34 */
    3535
    3636/**
    37  * @file        rd.c
    38  * @brief       Initial RAM disk for HelenOS.
     37 * @file rd.c
     38 * @brief Initial RAM disk for HelenOS.
    3939 */
    4040
     
    6161/** Pointer to the ramdisk's image */
    6262static void *rd_addr;
     63
    6364/** Size of the ramdisk */
    6465static size_t rd_size;
     
    7071static int rd_write_blocks(uint64_t ba, size_t cnt, const void *buf);
    7172
    72 /**
    73  * This rwlock protects the ramdisk's data.
     73/** This rwlock protects the ramdisk's data.
     74 *
    7475 * 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 */
    7880fibril_rwlock_t rd_lock;
    7981
    8082/** Handle one connection to ramdisk.
    8183 *
    82  * @param iid           Hash of the request that opened the connection.
    83  * @param icall         Call data of the request that opened the connection.
     84 * @param iid   Hash of the request that opened the connection.
     85 * @param icall Call data of the request that opened the connection.
    8486 */
    8587static void rd_connection(ipc_callid_t iid, ipc_call_t *icall)
     
    9294        size_t cnt;
    9395        size_t comm_size;
    94 
     96       
    9597        /*
    9698         * Answer the first IPC_M_CONNECT_ME_TO call.
    9799         */
    98100        ipc_answer_0(iid, EOK);
    99 
     101       
    100102        /*
    101103         * Now we wait for the client to send us its communication as_area.
     
    108110                } else {
    109111                        ipc_answer_0(callid, EHANGUP);
    110                         return;         
     112                        return;
    111113                }
    112114        } else {
     
    178180                return ELIMIT;
    179181        }
    180 
     182       
    181183        fibril_rwlock_read_lock(&rd_lock);
    182184        memcpy(buf, rd_addr + ba * block_size, block_size * cnt);
    183185        fibril_rwlock_read_unlock(&rd_lock);
    184 
     186       
    185187        return EOK;
    186188}
     
    193195                return ELIMIT;
    194196        }
    195 
     197       
    196198        fibril_rwlock_write_lock(&rd_lock);
    197199        memcpy(rd_addr + ba * block_size, buf, block_size * cnt);
    198200        fibril_rwlock_write_unlock(&rd_lock);
    199 
     201       
    200202        return EOK;
    201203}
     
    204206static bool rd_init(void)
    205207{
    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);
    211218                return false;
    212219        }
     
    215222       
    216223        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,
    218225            ALIGN_UP(rd_size, PAGE_SIZE) >> PAGE_WIDTH, flags);
    219226       
    220227        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);
    226233       
    227234        int rc = devmap_driver_register(NAME, rd_connection);
    228235        if (rc < 0) {
    229                 printf(NAME ": Unable to register driver (%d)\n", rc);
     236                printf("%s: Unable to register driver (%d)\n", NAME, rc);
    230237                return false;
    231238        }
     
    234241        if (devmap_device_register("bd/initrd", &dev_handle) != EOK) {
    235242                devmap_hangup_phone(DEVMAP_DRIVER);
    236                 printf(NAME ": Unable to register device\n");
     243                printf("%s: Unable to register device\n", NAME);
    237244                return false;
    238245        }
     
    245252int main(int argc, char **argv)
    246253{
    247         printf(NAME ": HelenOS RAM disk server\n");
     254        printf("%s: HelenOS RAM disk server\n", NAME);
    248255       
    249256        if (!rd_init())
    250257                return -1;
    251258       
    252         printf(NAME ": Accepting connections\n");
     259        printf("%s: Accepting connections\n", NAME);
    253260        async_manager();
    254261
Note: See TracChangeset for help on using the changeset viewer.