Subversion Repositories HelenOS

Rev

Rev 2445 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (c) 2007 Michal Konopa
  3.  * Copyright (c) 2007 Martin Jelen
  4.  * Copyright (c) 2007 Peter Majer
  5.  * All rights reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * - Redistributions of source code must retain the above copyright
  12.  *   notice, this list of conditions and the following disclaimer.
  13.  * - Redistributions in binary form must reproduce the above copyright
  14.  *   notice, this list of conditions and the following disclaimer in the
  15.  *   documentation and/or other materials provided with the distribution.
  16.  * - The name of the author may not be used to endorse or promote products
  17.  *   derived from this software without specific prior written permission.
  18.  *
  19.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  20.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  21.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  22.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  23.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  24.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  28.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29.  */
  30.  
  31. /** @addtogroup rd
  32.  * @{
  33.  */
  34.  
  35. /**
  36.  * @file    rd.c
  37.  * @brief   Initial RAM disk for HelenOS.
  38.  */
  39.  
  40. #include <ipc/ipc.h>
  41. #include <ipc/services.h>
  42. #include <ipc/ns.h>
  43. #include <sysinfo.h>
  44. #include <as.h>
  45. #include <ddi.h>
  46. #include <align.h>
  47. #include <bool.h>
  48. #include <errno.h>
  49. #include <async.h>
  50. #include <align.h>
  51. #include <async.h>
  52. #include "rd.h"
  53.  
  54. static void *rd_addr;
  55. static void *fs_addr;
  56.  
  57. static void rd_connection(ipc_callid_t iid, ipc_call_t *icall)
  58. {
  59.     ipc_callid_t callid;
  60.     ipc_call_t call;
  61.     int retval;
  62.  
  63.     ipc_answer_fast(iid, 0, 0, 0);
  64.     ipcarg_t offset;
  65.  
  66.     while (1) {
  67.         callid = async_get_call(&call);
  68.         switch (IPC_GET_METHOD(call)) {
  69.             case IPC_M_PHONE_HUNGUP:
  70.                 ipc_answer_fast(callid, 0,0,0);
  71.                 return;
  72.             case IPC_M_AS_AREA_SEND:
  73.                 ipc_answer_fast(callid, 0, (uintptr_t)fs_addr, 0);
  74.                 continue;
  75.             case RD_READ_BLOCK:        
  76.                 offset = IPC_GET_ARG1(call);
  77.                 memcpy((void *)fs_addr, rd_addr+offset, BLOCK_SIZE);
  78.                 retval = EOK;
  79.                 break;
  80.             default:
  81.                 retval = EINVAL;
  82.         }
  83.         ipc_answer_fast(callid, retval, 0, 0);
  84.     }  
  85. }
  86.  
  87.  
  88. static bool rd_init(void)
  89. {
  90.     int retval, flags;
  91.  
  92.     size_t rd_size = sysinfo_value("rd.size");
  93.     void * rd_ph_addr = (void *) sysinfo_value("rd.address.physical");
  94.    
  95.     if (rd_size == 0)
  96.         return false;
  97.    
  98.     rd_addr = as_get_mappable_page(rd_size);
  99.    
  100.     flags = AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE;
  101.     retval = physmem_map(rd_ph_addr, rd_addr, ALIGN_UP(rd_size, PAGE_SIZE) >> PAGE_WIDTH, flags);
  102.  
  103.     if (retval < 0)
  104.         return false;
  105.    
  106.     size_t fs_size = ALIGN_UP(BLOCK_SIZE * sizeof(char), PAGE_SIZE);
  107.     fs_addr = as_get_mappable_page(fs_size);
  108.  
  109.     return true;
  110. }
  111.  
  112. int main(int argc, char **argv)
  113. {
  114.     if (rd_init()) {
  115.         ipcarg_t phonead;
  116.        
  117.         async_set_client_connection(rd_connection);
  118.        
  119.         /* Register service at nameserver */
  120.         if (ipc_connect_to_me(PHONE_NS, SERVICE_RD, 0, &phonead) != 0)
  121.             return -1;
  122.        
  123.         async_manager();
  124.        
  125.         /* Never reached */
  126.         return 0;
  127.     }
  128.    
  129.     return -1;
  130. }
  131.  
  132. /**
  133.  * @}
  134.  */
  135.