Rev 2449 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2449 | Rev 2471 | ||
---|---|---|---|
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 <align.h> |
50 | #include <align.h> |
51 | #include <async.h> |
51 | #include <async.h> |
52 | #include "rd.h" |
52 | #include "rd.h" |
53 | 53 | ||
54 | static void *rd_addr; |
54 | static void *rd_addr; |
55 | static void *fs_addr; |
55 | static void *fs_addr; |
56 | 56 | ||
57 | 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) |
58 | { |
58 | { |
59 | ipc_callid_t callid; |
59 | ipc_callid_t callid; |
60 | ipc_call_t call; |
60 | ipc_call_t call; |
61 | int retval; |
61 | int retval; |
62 | 62 | ||
63 | ipc_answer_fast(iid, 0, 0, 0); |
63 | ipc_answer_fast(iid, 0, 0, 0); |
64 | ipcarg_t offset; |
64 | ipcarg_t offset; |
65 | 65 | ||
66 | while (1) { |
66 | while (1) { |
67 | callid = async_get_call(&call); |
67 | callid = async_get_call(&call); |
68 | switch (IPC_GET_METHOD(call)) { |
68 | switch (IPC_GET_METHOD(call)) { |
69 | case IPC_M_PHONE_HUNGUP: |
69 | case IPC_M_PHONE_HUNGUP: |
70 | ipc_answer_fast(callid, 0,0,0); |
70 | ipc_answer_fast(callid, 0, 0, 0); |
71 | return; |
71 | return; |
72 | case IPC_M_AS_AREA_SEND: |
72 | case IPC_M_AS_AREA_SEND: |
73 | ipc_answer_fast(callid, 0, (uintptr_t)fs_addr, 0); |
73 | ipc_answer_fast(callid, 0, (uintptr_t) fs_addr, 0); |
74 | continue; |
74 | continue; |
75 | case RD_READ_BLOCK: |
75 | case RD_READ_BLOCK: |
76 | offset = IPC_GET_ARG1(call); |
76 | offset = IPC_GET_ARG1(call); |
77 | memcpy((void *)fs_addr, rd_addr+offset, BLOCK_SIZE); |
77 | memcpy((void *) fs_addr, rd_addr + offset, BLOCK_SIZE); |
78 | retval = EOK; |
78 | retval = EOK; |
79 | break; |
79 | break; |
80 | default: |
80 | default: |
81 | retval = EINVAL; |
81 | retval = EINVAL; |
82 | } |
82 | } |
83 | ipc_answer_fast(callid, retval, 0, 0); |
83 | ipc_answer_fast(callid, retval, 0, 0); |
84 | } |
84 | } |
85 | } |
85 | } |
86 | 86 | ||
87 | 87 | ||
88 | static bool rd_init(void) |
88 | static bool rd_init(void) |
89 | { |
89 | { |
90 | int retval, flags; |
90 | int retval, flags; |
91 | 91 | ||
92 | size_t rd_size = sysinfo_value("rd.size"); |
92 | size_t rd_size = sysinfo_value("rd.size"); |
93 | void * rd_ph_addr = (void *) sysinfo_value("rd.address.physical"); |
93 | void *rd_ph_addr = (void *) sysinfo_value("rd.address.physical"); |
94 | 94 | ||
95 | if (rd_size == 0) |
95 | if (rd_size == 0) |
96 | return false; |
96 | return false; |
97 | 97 | ||
98 | rd_addr = as_get_mappable_page(rd_size); |
98 | rd_addr = as_get_mappable_page(rd_size); |
99 | 99 | ||
100 | flags = AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE; |
100 | flags = AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE; |
- | 101 | retval = physmem_map(rd_ph_addr, rd_addr, |
|
101 | retval = physmem_map(rd_ph_addr, rd_addr, ALIGN_UP(rd_size, PAGE_SIZE) >> PAGE_WIDTH, flags); |
102 | ALIGN_UP(rd_size, PAGE_SIZE) >> PAGE_WIDTH, flags); |
102 | 103 | ||
103 | if (retval < 0) |
104 | if (retval < 0) |
104 | return false; |
105 | return false; |
105 | 106 | ||
106 | size_t fs_size = ALIGN_UP(BLOCK_SIZE * sizeof(char), PAGE_SIZE); |
107 | size_t fs_size = ALIGN_UP(BLOCK_SIZE * sizeof(char), PAGE_SIZE); |
107 | fs_addr = as_get_mappable_page(fs_size); |
108 | fs_addr = as_get_mappable_page(fs_size); |
108 | 109 | ||
109 | return true; |
110 | return true; |
110 | } |
111 | } |
111 | 112 | ||
112 | int main(int argc, char **argv) |
113 | int main(int argc, char **argv) |
113 | { |
114 | { |
114 | if (rd_init()) { |
115 | if (rd_init()) { |
115 | ipcarg_t phonead; |
116 | ipcarg_t phonead; |
116 | 117 | ||
117 | async_set_client_connection(rd_connection); |
118 | async_set_client_connection(rd_connection); |
118 | 119 | ||
119 | /* Register service at nameserver */ |
120 | /* Register service at nameserver */ |
120 | if (ipc_connect_to_me(PHONE_NS, SERVICE_RD, 0, &phonead) != 0) |
121 | if (ipc_connect_to_me(PHONE_NS, SERVICE_RD, 0, &phonead) != 0) |
121 | return -1; |
122 | return -1; |
122 | 123 | ||
123 | async_manager(); |
124 | async_manager(); |
124 | 125 | ||
125 | /* Never reached */ |
126 | /* Never reached */ |
126 | return 0; |
127 | return 0; |
127 | } |
128 | } |
128 | 129 | ||
129 | return -1; |
130 | return -1; |
130 | } |
131 | } |
131 | 132 | ||
132 | /** |
133 | /** |
133 | * @} |
134 | * @} |
134 | */ |
135 | */ |
135 | 136 |