50,15 → 50,21 |
#include <align.h> |
#include <async.h> |
#include <ddi.h> |
#include <sysinfo.h> |
#include <libarch/ddi.h> |
|
#include <stdio.h> |
#include "rd.h" |
#include "../console/console.h" |
#include "../share/base_const.h" |
|
#define EOK 0 |
|
static void * rd_addr; |
#define CON_CONN_ATTEMPTS 1000 |
|
static int con_phone; |
static void *rd_addr; |
static void *fs_addr; |
|
static int connect_to_con(int *phone, int attempts); |
|
static void rd_connection(ipc_callid_t iid, ipc_call_t *icall) |
{ |
ipc_callid_t callid; |
66,25 → 72,25 |
int retval; |
|
ipc_answer_fast(iid, 0, 0, 0); |
int block_size = 512; |
ipcarg_t dst, offset; |
|
while (1) { |
callid = async_get_call(&call); |
switch (IPC_GET_METHOD(call)) { |
case IPC_M_PHONE_HUNGUP: |
ipc_answer_fast(callid, 0,0,0); |
return; |
case BD_READ_BLOCK: |
//returnt the block data |
dst = IPC_GET_ARG1(call); |
offset = IPC_GET_ARG2(call); |
//copy_from_uspace(dst, rd_addr+offset,block_size); |
memcpy((void *) dst, rd_addr+offset, block_size); |
retval = EOK; |
break; |
default: |
retval = EINVAL; |
case IPC_M_PHONE_HUNGUP: |
ipc_answer_fast(callid, 0,0,0); |
return; |
case IPC_M_AS_AREA_SEND: |
//print_console("Receiving shared area from FS..."); |
ipc_answer_fast(callid, 0, (uintptr_t)fs_addr, 0); |
//print_console("OK\n"); |
continue; |
case RD_READ_BLOCK: |
offset = IPC_GET_ARG1(call); |
memcpy((void *)fs_addr, rd_addr+offset, BLOCK_SIZE); |
retval = OK; |
break; |
default: retval = EINVAL; |
} |
ipc_answer_fast(callid, retval, 0, 0); |
} |
93,6 → 99,9 |
|
static bool rd_init(void) |
{ |
|
int retval, flags; |
|
size_t rd_size = sysinfo_value("rd.size"); |
void * rd_ph_addr = (void *) sysinfo_value("rd.address.physical"); |
int rd_color = (int) sysinfo_value("rd.address.color"); |
102,14 → 111,55 |
|
rd_addr = as_get_mappable_page(rd_size, rd_color); |
|
physmem_map(rd_ph_addr, rd_addr, ALIGN_UP(rd_size, PAGE_SIZE) >> PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE); |
//print_console("Physmem mapping..."); |
flags = AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE; |
retval = physmem_map(rd_ph_addr, rd_addr, ALIGN_UP(rd_size, PAGE_SIZE) >> PAGE_WIDTH, flags); |
|
if (retval < 0) { |
//print_console_int("%d\n", retval); |
return FALSE; |
} |
//print_console("OK\n"); |
|
size_t fs_size = ALIGN_UP(BLOCK_SIZE * sizeof(char), PAGE_SIZE); |
fs_addr = as_get_mappable_page(fs_size, PAGE_COLOR((uintptr_t)fs_addr)); |
|
return TRUE; |
} |
|
int connect_to_con(int *phone, int attempts) |
{ |
|
return true; |
int i; |
|
if (attempts <= 0) |
return FALSE; |
|
for (i = 1; i <= attempts; i++) { |
*phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0); |
|
if (*phone > 0) |
return TRUE; |
|
usleep(10000); |
} |
|
if (*phone >= 0) |
return TRUE; |
|
return FALSE; |
} |
|
|
int main(int argc, char **argv) |
{ |
|
/* Connection to SERVICE_CONSOLE service. */ |
if (!connect_to_con(&con_phone, CON_CONN_ATTEMPTS)) { |
return -1; |
} |
|
//print_console("RAMDISK task\n"); |
|
if (rd_init()) { |
ipcarg_t phonead; |
|