Rev 2248 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2248 | Rev 2396 | ||
---|---|---|---|
Line 48... | Line 48... | ||
48 | #include <stdlib.h> |
48 | #include <stdlib.h> |
49 | #include <unistd.h> |
49 | #include <unistd.h> |
50 | #include <align.h> |
50 | #include <align.h> |
51 | #include <async.h> |
51 | #include <async.h> |
52 | #include <ddi.h> |
52 | #include <ddi.h> |
53 | #include <sysinfo.h> |
- | |
54 | #include <libarch/ddi.h> |
53 | #include <libarch/ddi.h> |
55 | - | ||
- | 54 | #include <stdio.h> |
|
56 | #include "rd.h" |
55 | #include "rd.h" |
- | 56 | #include "../console/console.h" |
|
- | 57 | #include "../share/base_const.h" |
|
- | 58 | ||
- | 59 | ||
- | 60 | #define CON_CONN_ATTEMPTS 1000 |
|
57 | 61 | ||
58 | #define EOK 0 |
62 | static int con_phone; |
- | 63 | static void *rd_addr; |
|
- | 64 | static void *fs_addr; |
|
59 | 65 | ||
60 | static void * rd_addr; |
66 | static int connect_to_con(int *phone, int attempts); |
61 | 67 | ||
62 | static void rd_connection(ipc_callid_t iid, ipc_call_t *icall) |
68 | static void rd_connection(ipc_callid_t iid, ipc_call_t *icall) |
63 | { |
69 | { |
64 | ipc_callid_t callid; |
70 | ipc_callid_t callid; |
65 | ipc_call_t call; |
71 | ipc_call_t call; |
66 | int retval; |
72 | int retval; |
67 | 73 | ||
68 | ipc_answer_fast(iid, 0, 0, 0); |
74 | ipc_answer_fast(iid, 0, 0, 0); |
69 | int block_size = 512; |
- | |
70 | ipcarg_t dst, offset; |
75 | ipcarg_t dst, offset; |
71 | 76 | ||
72 | while (1) { |
77 | while (1) { |
73 | callid = async_get_call(&call); |
78 | callid = async_get_call(&call); |
74 | switch (IPC_GET_METHOD(call)) { |
79 | switch (IPC_GET_METHOD(call)) { |
75 | case IPC_M_PHONE_HUNGUP: |
80 | case IPC_M_PHONE_HUNGUP: |
76 | ipc_answer_fast(callid, 0,0,0); |
81 | ipc_answer_fast(callid, 0,0,0); |
77 | return; |
82 | return; |
78 | case BD_READ_BLOCK: |
83 | case IPC_M_AS_AREA_SEND: |
- | 84 | //print_console("Receiving shared area from FS..."); |
|
- | 85 | ipc_answer_fast(callid, 0, (uintptr_t)fs_addr, 0); |
|
79 | //returnt the block data |
86 | //print_console("OK\n"); |
- | 87 | continue; |
|
80 | dst = IPC_GET_ARG1(call); |
88 | case RD_READ_BLOCK: |
81 | offset = IPC_GET_ARG2(call); |
89 | offset = IPC_GET_ARG1(call); |
82 | //copy_from_uspace(dst, rd_addr+offset,block_size); |
- | |
83 | memcpy((void *) dst, rd_addr+offset, block_size); |
90 | memcpy((void *)fs_addr, rd_addr+offset, BLOCK_SIZE); |
84 | retval = EOK; |
91 | retval = OK; |
85 | break; |
92 | break; |
86 | default: |
- | |
87 | retval = EINVAL; |
93 | default: retval = EINVAL; |
88 | } |
94 | } |
89 | ipc_answer_fast(callid, retval, 0, 0); |
95 | ipc_answer_fast(callid, retval, 0, 0); |
90 | } |
96 | } |
91 | } |
97 | } |
92 | 98 | ||
93 | 99 | ||
94 | static bool rd_init(void) |
100 | static bool rd_init(void) |
95 | { |
101 | { |
- | 102 | ||
- | 103 | int retval, flags; |
|
- | 104 | ||
96 | size_t rd_size = sysinfo_value("rd.size"); |
105 | size_t rd_size = sysinfo_value("rd.size"); |
97 | void * rd_ph_addr = (void *) sysinfo_value("rd.address.physical"); |
106 | void * rd_ph_addr = (void *) sysinfo_value("rd.address.physical"); |
98 | int rd_color = (int) sysinfo_value("rd.address.color"); |
107 | int rd_color = (int) sysinfo_value("rd.address.color"); |
99 | 108 | ||
100 | if (rd_size == 0) |
109 | if (rd_size == 0) |
101 | return false; |
110 | return false; |
102 | 111 | ||
103 | rd_addr = as_get_mappable_page(rd_size, rd_color); |
112 | rd_addr = as_get_mappable_page(rd_size, rd_color); |
104 | 113 | ||
- | 114 | //print_console("Physmem mapping..."); |
|
- | 115 | flags = AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE; |
|
105 | physmem_map(rd_ph_addr, rd_addr, ALIGN_UP(rd_size, PAGE_SIZE) >> PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE); |
116 | retval = physmem_map(rd_ph_addr, rd_addr, ALIGN_UP(rd_size, PAGE_SIZE) >> PAGE_WIDTH, flags); |
- | 117 | ||
- | 118 | if (retval < 0) { |
|
- | 119 | //print_console_int("%d\n", retval); |
|
- | 120 | return FALSE; |
|
- | 121 | } |
|
- | 122 | //print_console("OK\n"); |
|
106 | 123 | ||
- | 124 | size_t fs_size = ALIGN_UP(BLOCK_SIZE * sizeof(char), PAGE_SIZE); |
|
- | 125 | fs_addr = as_get_mappable_page(fs_size, PAGE_COLOR((uintptr_t)fs_addr)); |
|
- | 126 | ||
107 | return true; |
127 | return TRUE; |
108 | } |
128 | } |
109 | 129 | ||
- | 130 | int connect_to_con(int *phone, int attempts) |
|
- | 131 | { |
|
- | 132 | ||
- | 133 | int i; |
|
- | 134 | ||
- | 135 | if (attempts <= 0) |
|
- | 136 | return FALSE; |
|
- | 137 | ||
- | 138 | for (i = 1; i <= attempts; i++) { |
|
- | 139 | *phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0); |
|
- | 140 | ||
- | 141 | if (*phone > 0) |
|
- | 142 | return TRUE; |
|
- | 143 | ||
- | 144 | usleep(10000); |
|
- | 145 | } |
|
- | 146 | ||
- | 147 | if (*phone >= 0) |
|
- | 148 | return TRUE; |
|
- | 149 | ||
- | 150 | return FALSE; |
|
- | 151 | } |
|
110 | 152 | ||
111 | int main(int argc, char **argv) |
153 | int main(int argc, char **argv) |
112 | { |
154 | { |
- | 155 | ||
- | 156 | /* Connection to SERVICE_CONSOLE service. */ |
|
- | 157 | if (!connect_to_con(&con_phone, CON_CONN_ATTEMPTS)) { |
|
- | 158 | return -1; |
|
- | 159 | } |
|
- | 160 | ||
- | 161 | //print_console("RAMDISK task\n"); |
|
- | 162 | ||
113 | if (rd_init()) { |
163 | if (rd_init()) { |
114 | ipcarg_t phonead; |
164 | ipcarg_t phonead; |
115 | 165 | ||
116 | async_set_client_connection(rd_connection); |
166 | async_set_client_connection(rd_connection); |
117 | 167 |