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