[228b135] | 1 | /*
|
---|
[ff3a34b] | 2 | * Copyright (c) 2007 Michal Konopa
|
---|
| 3 | * Copyright (c) 2007 Martin Jelen
|
---|
| 4 | * Copyright (c) 2007 Peter Majer
|
---|
[228b135] | 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>
|
---|
[7c34822e] | 43 | #include <sysinfo.h>
|
---|
| 44 | #include <as.h>
|
---|
| 45 | #include <ddi.h>
|
---|
| 46 | #include <align.h>
|
---|
| 47 | #include <bool.h>
|
---|
[228b135] | 48 | #include <errno.h>
|
---|
| 49 | #include <async.h>
|
---|
[ff3a34b] | 50 | #include <align.h>
|
---|
| 51 | #include <async.h>
|
---|
| 52 | #include "rd.h"
|
---|
[228b135] | 53 |
|
---|
[ff3a34b] | 54 | static void *rd_addr;
|
---|
| 55 | static void *fs_addr;
|
---|
[228b135] | 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);
|
---|
[ff3a34b] | 64 | ipcarg_t offset;
|
---|
[228b135] | 65 |
|
---|
| 66 | while (1) {
|
---|
| 67 | callid = async_get_call(&call);
|
---|
| 68 | switch (IPC_GET_METHOD(call)) {
|
---|
[8b243f2] | 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;
|
---|
[228b135] | 82 | }
|
---|
| 83 | ipc_answer_fast(callid, retval, 0, 0);
|
---|
[8b243f2] | 84 | }
|
---|
[228b135] | 85 | }
|
---|
| 86 |
|
---|
| 87 |
|
---|
[7c34822e] | 88 | static bool rd_init(void)
|
---|
[228b135] | 89 | {
|
---|
[ff3a34b] | 90 | int retval, flags;
|
---|
| 91 |
|
---|
[7c34822e] | 92 | size_t rd_size = sysinfo_value("rd.size");
|
---|
[8b243f2] | 93 | void *rd_ph_addr = (void *) sysinfo_value("rd.address.physical");
|
---|
[7c34822e] | 94 |
|
---|
| 95 | if (rd_size == 0)
|
---|
| 96 | return false;
|
---|
[228b135] | 97 |
|
---|
[ff3a34b] | 98 | rd_addr = as_get_mappable_page(rd_size);
|
---|
[228b135] | 99 |
|
---|
[ff3a34b] | 100 | flags = AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE;
|
---|
[8b243f2] | 101 | retval = physmem_map(rd_ph_addr, rd_addr,
|
---|
| 102 | ALIGN_UP(rd_size, PAGE_SIZE) >> PAGE_WIDTH, flags);
|
---|
[ff3a34b] | 103 |
|
---|
| 104 | if (retval < 0)
|
---|
| 105 | return false;
|
---|
[7c34822e] | 106 |
|
---|
[ff3a34b] | 107 | size_t fs_size = ALIGN_UP(BLOCK_SIZE * sizeof(char), PAGE_SIZE);
|
---|
| 108 | fs_addr = as_get_mappable_page(fs_size);
|
---|
| 109 |
|
---|
[7c34822e] | 110 | return true;
|
---|
| 111 | }
|
---|
[228b135] | 112 |
|
---|
[7c34822e] | 113 | int main(int argc, char **argv)
|
---|
| 114 | {
|
---|
| 115 | if (rd_init()) {
|
---|
| 116 | ipcarg_t phonead;
|
---|
| 117 |
|
---|
| 118 | async_set_client_connection(rd_connection);
|
---|
| 119 |
|
---|
| 120 | /* Register service at nameserver */
|
---|
| 121 | if (ipc_connect_to_me(PHONE_NS, SERVICE_RD, 0, &phonead) != 0)
|
---|
| 122 | return -1;
|
---|
| 123 |
|
---|
| 124 | async_manager();
|
---|
| 125 |
|
---|
| 126 | /* Never reached */
|
---|
| 127 | return 0;
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | return -1;
|
---|
[228b135] | 131 | }
|
---|
| 132 |
|
---|
| 133 | /**
|
---|
| 134 | * @}
|
---|
| 135 | */
|
---|