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