writev and some fixes
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
BUILD_TARGET = mee knf
|
||||
#BUILD_TARGET = mee knf
|
||||
BUILD_TARGET = knf
|
||||
SRC = $(CURDIR)
|
||||
|
||||
AALBASE ?= $(SRC)/../../aal/manycore
|
||||
|
||||
27
kernel/include/uio.h
Normal file
27
kernel/include/uio.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef __UIO_H
|
||||
#define __UIO_H
|
||||
|
||||
struct iovec
|
||||
{
|
||||
void *iov_base; /* BSD uses caddr_t (1003.1g requires void *) */
|
||||
size_t iov_len; /* Must be size_t (1003.1g) */
|
||||
};
|
||||
|
||||
/*
|
||||
* Total number of bytes covered by an iovec.
|
||||
*
|
||||
* NOTE that it is not safe to use this function until all the iovec's
|
||||
* segment lengths have been validated. Because the individual lengths can
|
||||
* overflow a size_t when added together.
|
||||
*/
|
||||
static inline size_t iov_length(const struct iovec *iov, unsigned long nr_segs)
|
||||
{
|
||||
unsigned long seg;
|
||||
size_t ret = 0;
|
||||
|
||||
for (seg = 0; seg < nr_segs; seg++)
|
||||
ret += iov[seg].iov_len;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -9,6 +9,17 @@
|
||||
#include <syscall.h>
|
||||
#include <page.h>
|
||||
#include <amemcpy.h>
|
||||
#include <uio.h>
|
||||
|
||||
#define SYSCALL_BY_IKC
|
||||
|
||||
#define DEBUG_PRINT_SC
|
||||
|
||||
#ifdef DEBUG_PRINT_SC
|
||||
#define dkprintf kprintf
|
||||
#else
|
||||
#define dkprintf(...)
|
||||
#endif
|
||||
|
||||
int memcpy_async(unsigned long dest, unsigned long src,
|
||||
unsigned long len, int wait, unsigned long *notify);
|
||||
@ -45,15 +56,23 @@ static void send_syscall(struct syscall_request *req)
|
||||
#endif
|
||||
}
|
||||
|
||||
static int do_syscall(struct syscall_request *req)
|
||||
static int do_syscall(struct syscall_request *req, aal_mc_user_context_t *ctx)
|
||||
{
|
||||
struct syscall_response *res = cpu_local_var(scp).response_va;
|
||||
|
||||
send_syscall(req);
|
||||
|
||||
dkprintf("SC(%d)[%3d] waiting for host.. \n",
|
||||
aal_mc_get_processor_id(),
|
||||
req->number);
|
||||
|
||||
while (!res->status) {
|
||||
cpu_pause();
|
||||
}
|
||||
|
||||
dkprintf("SC(%d)[%3d] got host reply: %d \n",
|
||||
aal_mc_get_processor_id(),
|
||||
req->number, res->ret);
|
||||
|
||||
return res->ret;
|
||||
}
|
||||
@ -105,7 +124,7 @@ long sys_brk(int n, aal_mc_user_context_t *ctx)
|
||||
SYSCALL_ARG_##a0(0); SYSCALL_ARG_##a1(1); \
|
||||
SYSCALL_ARG_##a2(2); SYSCALL_ARG_##a3(3)
|
||||
|
||||
#define SYSCALL_FOOTER return do_syscall(&request)
|
||||
#define SYSCALL_FOOTER return do_syscall(&request, ctx)
|
||||
|
||||
SYSCALL_DECLARE(fstat)
|
||||
{
|
||||
@ -187,7 +206,7 @@ SYSCALL_DECLARE(lseek)
|
||||
SYSCALL_DECLARE(exit_group)
|
||||
{
|
||||
SYSCALL_HEADER;
|
||||
do_syscall(&request);
|
||||
do_syscall(&request, ctx);
|
||||
|
||||
free_process_memory(cpu_local_var(current));
|
||||
cpu_local_var(next) = &cpu_local_var(idle);
|
||||
@ -218,7 +237,7 @@ SYSCALL_DECLARE(mmap)
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
kprintf("Non-anonymous mmap: fd = %lx, %lx\n",
|
||||
dkprintf("Non-anonymous mmap: fd = %lx, %lx\n",
|
||||
aal_mc_syscall_arg4(ctx), aal_mc_syscall_arg5(ctx));
|
||||
while(1);
|
||||
}
|
||||
@ -243,6 +262,7 @@ SYSCALL_DECLARE(uname)
|
||||
{
|
||||
SYSCALL_HEADER;
|
||||
unsigned long phys;
|
||||
int ret;
|
||||
|
||||
if (aal_mc_pt_virt_to_phys(cpu_local_var(current)->vm->page_table,
|
||||
(void *)aal_mc_syscall_arg0(ctx), &phys)) {
|
||||
@ -252,7 +272,9 @@ SYSCALL_DECLARE(uname)
|
||||
request.number = n;
|
||||
request.args[0] = phys;
|
||||
|
||||
return do_syscall(&request);
|
||||
ret = do_syscall(&request, ctx);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
long sys_getxid(int n, aal_mc_user_context_t *ctx)
|
||||
@ -261,7 +283,7 @@ long sys_getxid(int n, aal_mc_user_context_t *ctx)
|
||||
|
||||
request.number = n;
|
||||
|
||||
return do_syscall(&request);
|
||||
return do_syscall(&request, ctx);
|
||||
}
|
||||
|
||||
long sys_arch_prctl(int n, aal_mc_user_context_t *ctx)
|
||||
@ -293,7 +315,7 @@ SYSCALL_DECLARE(clone)
|
||||
aal_mc_syscall_arg1(ctx));
|
||||
/* XXX Assign new pid! */
|
||||
new->pid = cpu_local_var(current)->pid;
|
||||
kprintf("Cloned: %p \n", new);
|
||||
dkprintf("Cloned: %p \n", new);
|
||||
|
||||
aal_mc_syscall_ret(new->uctx) = 0;
|
||||
|
||||
@ -301,11 +323,50 @@ SYSCALL_DECLARE(clone)
|
||||
request.number = n;
|
||||
request.args[0] = (unsigned long)new;
|
||||
/* Sync */
|
||||
do_syscall(&request);
|
||||
kprintf("Clone ret.\n");
|
||||
do_syscall(&request, ctx);
|
||||
dkprintf("Clone ret.\n");
|
||||
return new->pid;
|
||||
}
|
||||
|
||||
|
||||
SYSCALL_DECLARE(writev)
|
||||
{
|
||||
/* Adhoc implementation of writev calling write sequentially */
|
||||
struct syscall_request request AAL_DMA_ALIGN;
|
||||
unsigned long seg;
|
||||
size_t seg_ret, ret = 0;
|
||||
|
||||
int fd = aal_mc_syscall_arg0(ctx);
|
||||
struct iovec *iov = (struct iovec*)aal_mc_syscall_arg1(ctx);
|
||||
unsigned long nr_segs = aal_mc_syscall_arg2(ctx);
|
||||
|
||||
for (seg = 0; seg < nr_segs; ++seg) {
|
||||
unsigned long __phys;
|
||||
|
||||
if (aal_mc_pt_virt_to_phys(cpu_local_var(current)->vm->page_table,
|
||||
(void *)iov[seg].iov_base, &__phys)) {
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
request.number = 1; /* write */
|
||||
request.args[0] = fd;
|
||||
request.args[1] = __phys;
|
||||
request.args[2] = iov[seg].iov_len;
|
||||
|
||||
seg_ret = do_syscall(&request, ctx);
|
||||
|
||||
if (seg_ret < 0) {
|
||||
ret = -EFAULT;
|
||||
break;
|
||||
}
|
||||
|
||||
ret += seg_ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static long (*syscall_table[])(int, aal_mc_user_context_t *) = {
|
||||
[0] = sys_read,
|
||||
[1] = sys_write,
|
||||
@ -319,6 +380,7 @@ static long (*syscall_table[])(int, aal_mc_user_context_t *) = {
|
||||
[16] = sys_ioctl,
|
||||
[17] = sys_pread,
|
||||
[18] = sys_pwrite,
|
||||
[20] = sys_writev,
|
||||
[39] = sys_getpid,
|
||||
[56] = sys_clone,
|
||||
[63] = sys_uname,
|
||||
@ -338,27 +400,23 @@ long syscall(int num, aal_mc_user_context_t *ctx)
|
||||
|
||||
cpu_enable_interrupt();
|
||||
|
||||
#ifdef DEBUG_PRINT_SC
|
||||
kprintf("SC(%d)[%3d](%lx, %lx) @ %lx | %lx = ",
|
||||
dkprintf("SC(%d)[%3d](%lx, %lx) @ %lx | %lx = ",
|
||||
aal_mc_get_processor_id(),
|
||||
num,
|
||||
aal_mc_syscall_arg0(ctx), aal_mc_syscall_arg1(ctx),
|
||||
aal_mc_syscall_pc(ctx), aal_mc_syscall_sp(ctx));
|
||||
#endif
|
||||
|
||||
if (syscall_table[num]) {
|
||||
l = syscall_table[num](num, ctx);
|
||||
#ifdef DEBUG_PRINT_SC
|
||||
kprintf(" %lx\n", l);
|
||||
#endif
|
||||
dkprintf(" %lx\n", l);
|
||||
return l;
|
||||
} else {
|
||||
kprintf("USC[%3d](%lx, %lx, %lx, %lx, %lx) @ %lx | %lx\n", num,
|
||||
dkprintf("USC[%3d](%lx, %lx, %lx, %lx, %lx) @ %lx | %lx\n", num,
|
||||
aal_mc_syscall_arg0(ctx), aal_mc_syscall_arg1(ctx),
|
||||
aal_mc_syscall_arg2(ctx), aal_mc_syscall_arg3(ctx),
|
||||
aal_mc_syscall_arg4(ctx), aal_mc_syscall_pc(ctx),
|
||||
aal_mc_syscall_sp(ctx));
|
||||
while(1);
|
||||
//while(1);
|
||||
return -ENOSYS;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
CFLAGS = -O3
|
||||
CFLAGS = -O3 -Wall -g
|
||||
|
||||
all: mcexec
|
||||
|
||||
|
||||
@ -17,6 +17,8 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#define DEBUG
|
||||
|
||||
#ifndef DEBUG
|
||||
#define __dprint(msg, ...)
|
||||
#define __dprintf(arg, ...)
|
||||
@ -220,9 +222,9 @@ int main(int argc, char **argv)
|
||||
fprintf(stderr, "Error: Failed to open /dev/mcctrl.\n");
|
||||
return 1;
|
||||
}
|
||||
fdm = open("/dev/mem", O_RDWR);
|
||||
fdm = open("/dev/fmem", O_RDWR);
|
||||
if (fdm < 0) {
|
||||
fprintf(stderr, "Error: Failed to open /dev/mem.\n");
|
||||
fprintf(stderr, "Error: Failed to open /dev/fmem.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -299,14 +301,20 @@ int main_loop(int fd, int cpu)
|
||||
w.cpu = cpu;
|
||||
|
||||
while (ioctl(fd, MCEXEC_UP_WAIT_SYSCALL, (unsigned long)&w) == 0) {
|
||||
|
||||
__dprintf("got syscall: %d\n", w.sr.number);
|
||||
|
||||
switch (w.sr.number) {
|
||||
case __NR_open:
|
||||
dma_buf[256] = 0;
|
||||
do_syscall_load(fd, cpu, dma_buf_pa, w.sr.args[0], 256);
|
||||
|
||||
|
||||
do_syscall_load(fd, cpu, dma_buf, w.sr.args[0], 256);
|
||||
/*
|
||||
while (!dma_buf[256]) {
|
||||
asm volatile ("" : : : "memory");
|
||||
}
|
||||
*/
|
||||
|
||||
ret = open(dma_buf, w.sr.args[1], w.sr.args[2]);
|
||||
SET_ERR(ret);
|
||||
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
|
||||
@ -321,19 +329,21 @@ int main_loop(int fd, int cpu)
|
||||
case __NR_read:
|
||||
ret = read(w.sr.args[0], dma_buf, w.sr.args[2]);
|
||||
SET_ERR(ret);
|
||||
do_syscall_return(fd, cpu, ret, 1, dma_buf_pa,
|
||||
do_syscall_return(fd, cpu, ret, 1, dma_buf,
|
||||
w.sr.args[1], w.sr.args[2]);
|
||||
break;
|
||||
|
||||
case __NR_write:
|
||||
dma_buf[w.sr.args[2]] = 0;
|
||||
SET_ERR(ret);
|
||||
do_syscall_load(fd, cpu, dma_buf_pa,
|
||||
do_syscall_load(fd, cpu, dma_buf,
|
||||
w.sr.args[1], w.sr.args[2]);
|
||||
|
||||
/*
|
||||
while (!dma_buf[w.sr.args[2]]) {
|
||||
asm volatile ("" : : : "memory");
|
||||
}
|
||||
*/
|
||||
|
||||
ret = write(w.sr.args[0], dma_buf, w.sr.args[2]);
|
||||
do_syscall_return(fd, cpu, ret, 0, 0, 0, 0);
|
||||
@ -347,18 +357,20 @@ int main_loop(int fd, int cpu)
|
||||
case __NR_pread64:
|
||||
ret = pread(w.sr.args[0], dma_buf, w.sr.args[2],
|
||||
w.sr.args[3]);
|
||||
do_syscall_return(fd, cpu, ret, 1, dma_buf_pa,
|
||||
do_syscall_return(fd, cpu, ret, 1, dma_buf,
|
||||
w.sr.args[1], w.sr.args[2]);
|
||||
break;
|
||||
|
||||
case __NR_pwrite64:
|
||||
dma_buf[w.sr.args[2]] = 0;
|
||||
do_syscall_load(fd, cpu, dma_buf_pa,
|
||||
do_syscall_load(fd, cpu, dma_buf,
|
||||
w.sr.args[1], w.sr.args[2]);
|
||||
|
||||
/*
|
||||
while (!dma_buf[w.sr.args[2]]) {
|
||||
asm volatile ("" : : : "memory");
|
||||
}
|
||||
*/
|
||||
|
||||
ret = pwrite(w.sr.args[0], dma_buf, w.sr.args[2],
|
||||
w.sr.args[3]);
|
||||
@ -371,7 +383,7 @@ int main_loop(int fd, int cpu)
|
||||
if (ret == -1) {
|
||||
ret = -errno;
|
||||
}
|
||||
do_syscall_return(fd, cpu, ret, 1, dma_buf_pa,
|
||||
do_syscall_return(fd, cpu, ret, 1, dma_buf,
|
||||
w.sr.args[1], sizeof(struct stat));
|
||||
break;
|
||||
|
||||
@ -382,7 +394,7 @@ int main_loop(int fd, int cpu)
|
||||
if (ret == -1) {
|
||||
ret = -errno;
|
||||
}
|
||||
do_syscall_return(fd, cpu, ret, 1, dma_buf_pa,
|
||||
do_syscall_return(fd, cpu, ret, 1, dma_buf,
|
||||
w.sr.args[2],
|
||||
sizeof(struct kernel_termios)
|
||||
);
|
||||
@ -413,7 +425,7 @@ int main_loop(int fd, int cpu)
|
||||
ret = -errno;
|
||||
}
|
||||
do_syscall_return(fd,
|
||||
cpu, ret, 1, dma_buf_pa, w.sr.args[0],
|
||||
cpu, ret, 1, dma_buf, w.sr.args[0],
|
||||
sizeof(struct utsname));
|
||||
break;
|
||||
default:
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
ifeq ($(K),"current")
|
||||
|
||||
#ifeq ($(K),"current")
|
||||
KDIR=/lib/modules/`uname -r `/build
|
||||
else
|
||||
KDIR=../target
|
||||
endif
|
||||
#else
|
||||
#KDIR=../target
|
||||
#endif
|
||||
|
||||
|
||||
obj-m += mcctrl.o
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#include <asm/uaccess.h>
|
||||
#include <asm/delay.h>
|
||||
#include <asm/msr.h>
|
||||
#include <asm/io.h>
|
||||
#include "mcctrl.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
@ -145,9 +146,10 @@ int mcexec_syscall(struct mcctrl_channel *c, unsigned long arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#ifndef DO_USER_MODE
|
||||
int __do_in_kernel_syscall(aal_os_t os, struct mcctrl_channel *c,
|
||||
struct syscall_request *sc);
|
||||
#endif
|
||||
|
||||
static int remaining_job, base_cpu, job_pos;
|
||||
extern int num_channels;
|
||||
@ -251,29 +253,52 @@ long mcexec_pin_region(aal_os_t os, unsigned long *__user uaddress)
|
||||
long mcexec_load_syscall(aal_os_t os, struct syscall_load_desc *__user arg)
|
||||
{
|
||||
struct syscall_load_desc desc;
|
||||
unsigned long phys;
|
||||
void *rpm;
|
||||
|
||||
if (copy_from_user(&desc, arg, sizeof(struct syscall_load_desc))) {
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
phys = aal_device_map_memory(aal_os_to_dev(os), desc.src, desc.size);
|
||||
rpm = ioremap_wc(phys, desc.size);
|
||||
|
||||
printk("mcexec_load_syscall: %s (desc.size: %d)\n", rpm, desc.size);
|
||||
|
||||
if (copy_to_user((void *__user)desc.dest, rpm, desc.size)) {
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
iounmap(rpm);
|
||||
aal_device_unmap_memory(aal_os_to_dev(os), phys, desc.size);
|
||||
|
||||
/*
|
||||
aal_dma_channel_t channel;
|
||||
struct aal_dma_request request;
|
||||
unsigned long dma_status = 0;
|
||||
|
||||
channel = aal_device_get_dma_channel(aal_os_to_dev(os), 0);
|
||||
if (!channel) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (copy_from_user(&desc, arg, sizeof(struct syscall_load_desc))) {
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
memset(&request, 0, sizeof(request));
|
||||
request.src_os = os;
|
||||
request.src_phys = desc.src;
|
||||
request.dest_os = NULL;
|
||||
request.dest_phys = desc.dest;
|
||||
request.size = desc.size;
|
||||
request.notify = (void *)(desc.dest + desc.size);
|
||||
request.notify = (void *)virt_to_phys(&dma_status);
|
||||
request.priv = (void *)1;
|
||||
|
||||
aal_dma_request(channel, &request);
|
||||
|
||||
while (!dma_status) {
|
||||
mb();
|
||||
udelay(1);
|
||||
}
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -308,7 +333,10 @@ long mcexec_ret_syscall(aal_os_t os, struct syscall_ret_desc *__user arg)
|
||||
ret.size);
|
||||
rpm = ioremap_wc(phys, ret.size);
|
||||
|
||||
memcpy(rpm, phys_to_virt(ret.src), ret.size);
|
||||
if (copy_from_user(rpm, (void *__user)ret.src, ret.size)) {
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
mc->param.response_va->status = 1;
|
||||
|
||||
iounmap(rpm);
|
||||
|
||||
@ -16,6 +16,8 @@
|
||||
|
||||
#define DMA_PIN_SHIFT 21
|
||||
|
||||
#define DO_USER_MODE
|
||||
|
||||
struct ikc_scd_packet {
|
||||
int msg;
|
||||
int ref;
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#include <linux/syscalls.h>
|
||||
#include <asm/uaccess.h>
|
||||
#include <asm/delay.h>
|
||||
#include <asm/io.h>
|
||||
#include "mcctrl.h"
|
||||
|
||||
#define ALIGN_WAIT_BUF(z) (((z + 63) >> 6) << 6)
|
||||
@ -112,10 +113,14 @@ static unsigned long translate_remote_va(struct mcctrl_channel *c,
|
||||
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
unsigned long last_thread_exec = 0;
|
||||
|
||||
extern struct mcctrl_channel *channels;
|
||||
|
||||
#ifndef DO_USER_MODE
|
||||
|
||||
|
||||
int __do_in_kernel_syscall(aal_os_t os, struct mcctrl_channel *c,
|
||||
struct syscall_request *sc)
|
||||
{
|
||||
@ -230,3 +235,4 @@ int __do_in_kernel_syscall(aal_os_t os, struct mcctrl_channel *c,
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* DO_USER_MODE */
|
||||
|
||||
Reference in New Issue
Block a user