support McKernel's sysfs tree
This commit is contained in:
@ -9,7 +9,7 @@ obj-m += mcctrl.o
|
||||
|
||||
ccflags-y := -I$(IHK_BASE)/linux/include -I$(IHK_BASE)/ikc/include -I$(IHK_BASE)/include -I$(src)/../../include -mcmodel=kernel -mno-red-zone -DMCEXEC_PATH=\"$(BINDIR)/mcexec\"
|
||||
|
||||
mcctrl-y := driver.o control.o ikc.o syscall.o procfs.o binfmt_mcexec.o
|
||||
mcctrl-y := driver.o control.o ikc.o syscall.o procfs.o binfmt_mcexec.o sysfs.o
|
||||
|
||||
KBUILD_EXTRA_SYMBOLS = @abs_builddir@/../../../../ihk/linux/core/Module.symvers
|
||||
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
#include <linux/fs.h>
|
||||
#include <linux/miscdevice.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/device.h>
|
||||
#include "mcctrl.h"
|
||||
|
||||
#define OS_MAX_MINOR 64
|
||||
@ -137,6 +138,7 @@ static void __exit mcctrl_exit(void)
|
||||
printk("mcctrl: unregistered.\n");
|
||||
for(i = 0; i < OS_MAX_MINOR; i++){
|
||||
if(os[i]){
|
||||
sysfsm_cleanup(os[i]);
|
||||
ihk_os_unregister_user_call_handlers(os[i], mcctrl_uc + i);
|
||||
destroy_ikc_channels(os[i]);
|
||||
procfs_exit(i);
|
||||
|
||||
@ -84,6 +84,26 @@ static int syscall_packet_handler(struct ihk_ikc_channel_desc *c,
|
||||
case SCD_MSG_SEND_SIGNAL:
|
||||
sig_done(pisp->arg, pisp->err);
|
||||
break;
|
||||
|
||||
case SCD_MSG_SYSFS_REQ_CREATE:
|
||||
case SCD_MSG_SYSFS_REQ_MKDIR:
|
||||
case SCD_MSG_SYSFS_REQ_SYMLINK:
|
||||
case SCD_MSG_SYSFS_REQ_LOOKUP:
|
||||
case SCD_MSG_SYSFS_REQ_UNLINK:
|
||||
case SCD_MSG_SYSFS_REQ_SETUP:
|
||||
case SCD_MSG_SYSFS_RESP_SHOW:
|
||||
case SCD_MSG_SYSFS_RESP_STORE:
|
||||
case SCD_MSG_SYSFS_RESP_RELEASE:
|
||||
sysfsm_packet_handler(__os, pisp->msg, pisp->err,
|
||||
pisp->sysfs_arg1, pisp->sysfs_arg2);
|
||||
break;
|
||||
|
||||
default:
|
||||
printk(KERN_ERR "mcctrl:syscall_packet_handler:"
|
||||
"unknown message (%d.%d.%d.%d.%d.%#lx)\n",
|
||||
pisp->msg, pisp->ref, pisp->osnum, pisp->pid,
|
||||
pisp->err, pisp->arg);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -33,10 +33,12 @@
|
||||
#define HEADER_MCCTRL_H
|
||||
|
||||
#include <ihk/ihk_host_driver.h>
|
||||
#include <linux/resource.h>
|
||||
#include <uprotocol.h>
|
||||
#include <linux/wait.h>
|
||||
#include <ihk/ikc.h>
|
||||
#include <ikc/master.h>
|
||||
#include <linux/semaphore.h>
|
||||
|
||||
#define SCD_MSG_PREPARE_PROCESS 0x1
|
||||
#define SCD_MSG_PREPARE_PROCESS_ACKED 0x2
|
||||
@ -57,6 +59,27 @@
|
||||
|
||||
#define SCD_MSG_DEBUG_LOG 0x20
|
||||
|
||||
#define SCD_MSG_SYSFS_REQ_CREATE 0x30
|
||||
/* #define SCD_MSG_SYSFS_RESP_CREATE 0x31 */
|
||||
#define SCD_MSG_SYSFS_REQ_MKDIR 0x32
|
||||
/* #define SCD_MSG_SYSFS_RESP_MKDIR 0x33 */
|
||||
#define SCD_MSG_SYSFS_REQ_SYMLINK 0x34
|
||||
/* #define SCD_MSG_SYSFS_RESP_SYMLINK 0x35 */
|
||||
#define SCD_MSG_SYSFS_REQ_LOOKUP 0x36
|
||||
/* #define SCD_MSG_SYSFS_RESP_LOOKUP 0x37 */
|
||||
#define SCD_MSG_SYSFS_REQ_UNLINK 0x38
|
||||
/* #define SCD_MSG_SYSFS_RESP_UNLINK 0x39 */
|
||||
#define SCD_MSG_SYSFS_REQ_SHOW 0x3a
|
||||
#define SCD_MSG_SYSFS_RESP_SHOW 0x3b
|
||||
#define SCD_MSG_SYSFS_REQ_STORE 0x3c
|
||||
#define SCD_MSG_SYSFS_RESP_STORE 0x3d
|
||||
#define SCD_MSG_SYSFS_REQ_RELEASE 0x3e
|
||||
#define SCD_MSG_SYSFS_RESP_RELEASE 0x3f
|
||||
#define SCD_MSG_SYSFS_REQ_SETUP 0x40
|
||||
#define SCD_MSG_SYSFS_RESP_SETUP 0x41
|
||||
/* #define SCD_MSG_SYSFS_REQ_CLEANUP 0x42 */
|
||||
/* #define SCD_MSG_SYSFS_RESP_CLEANUP 0x43 */
|
||||
|
||||
#define DMA_PIN_SHIFT 21
|
||||
|
||||
#define DO_USER_MODE
|
||||
@ -70,11 +93,24 @@ struct coretable {
|
||||
|
||||
struct ikc_scd_packet {
|
||||
int msg;
|
||||
int ref;
|
||||
int osnum;
|
||||
int pid;
|
||||
int err;
|
||||
unsigned long arg;
|
||||
union {
|
||||
/* for traditional SCD_MSG_* */
|
||||
struct {
|
||||
int ref;
|
||||
int osnum;
|
||||
int pid;
|
||||
int padding;
|
||||
unsigned long arg;
|
||||
};
|
||||
|
||||
/* for SCD_MSG_SYSFS_* */
|
||||
struct {
|
||||
long sysfs_arg1;
|
||||
long sysfs_arg2;
|
||||
long sysfs_arg3;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
struct mcctrl_priv {
|
||||
@ -128,6 +164,31 @@ struct mcctrl_per_proc_data {
|
||||
unsigned long rpgtable; /* per process, not per OS */
|
||||
};
|
||||
|
||||
struct sysfsm_req {
|
||||
int busy;
|
||||
int padding;
|
||||
long lresult;
|
||||
wait_queue_head_t wq;
|
||||
};
|
||||
|
||||
struct sysfsm_data {
|
||||
size_t sysfs_bufsize;
|
||||
void *sysfs_buf;
|
||||
long sysfs_buf_rpa;
|
||||
long sysfs_buf_pa;
|
||||
struct kobject *sysfs_kobj;
|
||||
struct sysfsm_node *sysfs_root;
|
||||
struct semaphore sysfs_tree_sem;
|
||||
struct semaphore sysfs_io_sem;
|
||||
struct sysfsm_req sysfs_req;
|
||||
ihk_os_t sysfs_os;
|
||||
};
|
||||
|
||||
static inline int sysfs_inited(struct sysfsm_data *sdp)
|
||||
{
|
||||
return !!(sdp->sysfs_buf);
|
||||
} /* sysfs_inited() */
|
||||
|
||||
struct mcctrl_usrdata {
|
||||
struct ihk_ikc_listen_param listen_param;
|
||||
struct ihk_ikc_listen_param listen_param2;
|
||||
@ -146,6 +207,7 @@ struct mcctrl_usrdata {
|
||||
struct list_head per_proc_list;
|
||||
ihk_spinlock_t per_proc_list_lock;
|
||||
void **keys;
|
||||
struct sysfsm_data sysfsm_data;
|
||||
};
|
||||
|
||||
struct mcctrl_signal {
|
||||
@ -188,4 +250,8 @@ struct procfs_file {
|
||||
char fname[PROCFS_NAME_MAX]; /* procfs filename (request) */
|
||||
};
|
||||
|
||||
/* sysfs.c */
|
||||
void sysfsm_cleanup(ihk_os_t os);
|
||||
void sysfsm_packet_handler(void *os, int msg, int err, long arg1, long arg2);
|
||||
|
||||
#endif
|
||||
|
||||
1634
executer/kernel/mcctrl/sysfs.c
Normal file
1634
executer/kernel/mcctrl/sysfs.c
Normal file
File diff suppressed because it is too large
Load Diff
76
executer/kernel/mcctrl/sysfs_msg.h
Normal file
76
executer/kernel/mcctrl/sysfs_msg.h
Normal file
@ -0,0 +1,76 @@
|
||||
/**
|
||||
* \file sysfs_msg.h
|
||||
* License details are found in the file LICENSE.
|
||||
* \brief
|
||||
* message declarations for sysfs framework
|
||||
* \author Gou Nakamura <go.nakamura.yw@hitachi-solutions.com> \par
|
||||
* Copyright (C) 2015 RIKEN AICS
|
||||
*/
|
||||
/*
|
||||
* HISTORY:
|
||||
*/
|
||||
|
||||
#ifndef MCKERNEL_SYSFS_MSG_H
|
||||
#define MCKERNEL_SYSFS_MSG_H
|
||||
|
||||
#define SYSFS_PATH_MAX 1024
|
||||
|
||||
struct sysfs_req_create_param {
|
||||
int mode;
|
||||
int error;
|
||||
long client_ops;
|
||||
long client_instance;
|
||||
char path[SYSFS_PATH_MAX];
|
||||
int padding;
|
||||
int busy;
|
||||
}; /* struct sysfs_req_create_param */
|
||||
|
||||
struct sysfs_req_mkdir_param {
|
||||
int error;
|
||||
int padding;
|
||||
long handle;
|
||||
char path[SYSFS_PATH_MAX];
|
||||
int padding2;
|
||||
int busy;
|
||||
}; /* struct sysfs_req_mkdir_param */
|
||||
|
||||
struct sysfs_req_symlink_param {
|
||||
int error;
|
||||
int padding;
|
||||
long target;
|
||||
char path[SYSFS_PATH_MAX];
|
||||
int padding2;
|
||||
int busy;
|
||||
}; /* struct sysfs_req_symlink_param */
|
||||
|
||||
struct sysfs_req_lookup_param {
|
||||
int error;
|
||||
int padding;
|
||||
long handle;
|
||||
char path[SYSFS_PATH_MAX];
|
||||
int padding2;
|
||||
int busy;
|
||||
}; /* struct sysfs_req_lookup_param */
|
||||
|
||||
/* for sysfs_req_unlink_param.flags */
|
||||
#define SYSFS_UNLINK_KEEP_ANCESTOR 0x01
|
||||
|
||||
struct sysfs_req_unlink_param {
|
||||
int flags;
|
||||
int error;
|
||||
char path[SYSFS_PATH_MAX];
|
||||
int padding;
|
||||
int busy;
|
||||
}; /* struct sysfs_req_unlink_param */
|
||||
|
||||
struct sysfs_req_setup_param {
|
||||
int error;
|
||||
int padding;
|
||||
long buf_rpa;
|
||||
long bufsize;
|
||||
char padding3[SYSFS_PATH_MAX];
|
||||
int padding2;
|
||||
int busy;
|
||||
}; /* struct sysfs_req_setup_param */
|
||||
|
||||
#endif /* MCKERNEL_SYSFS_MSG_H */
|
||||
@ -3,7 +3,7 @@ SRC=$(VPATH)
|
||||
IHKDIR=$(IHKBASE)/$(TARGETDIR)
|
||||
OBJS = init.o mem.o debug.o mikc.o listeners.o ap.o syscall.o cls.o host.o
|
||||
OBJS += process.o copy.o waitq.o futex.o timer.o plist.o fileobj.o shmobj.o
|
||||
OBJS += zeroobj.o procfs.o devobj.o
|
||||
OBJS += zeroobj.o procfs.o devobj.o sysfs.o
|
||||
DEPSRCS=$(wildcard $(SRC)/*.c)
|
||||
|
||||
CFLAGS += -I$(SRC)/include -mcmodel=kernel -D__KERNEL__ -g
|
||||
|
||||
@ -30,6 +30,7 @@
|
||||
#include <mman.h>
|
||||
#include <init.h>
|
||||
#include <kmalloc.h>
|
||||
#include <sysfs.h>
|
||||
|
||||
//#define DEBUG_PRINT_HOST
|
||||
|
||||
@ -607,6 +608,22 @@ static int syscall_packet_handler(struct ihk_ikc_channel_desc *c,
|
||||
dkprintf("SCD_MSG_DEBUG_LOG code=%lx\n", packet->arg);
|
||||
debug_log(packet->arg);
|
||||
return 0;
|
||||
|
||||
case SCD_MSG_SYSFS_REQ_SHOW:
|
||||
case SCD_MSG_SYSFS_REQ_STORE:
|
||||
case SCD_MSG_SYSFS_REQ_RELEASE:
|
||||
sysfss_packet_handler(c, packet->msg, packet->err,
|
||||
packet->sysfs_arg1, packet->sysfs_arg2,
|
||||
packet->sysfs_arg3);
|
||||
return 0;
|
||||
|
||||
default:
|
||||
kprintf("syscall_pakcet_handler:unknown message "
|
||||
"(%d.%d.%d.%d.%d.%#lx)\n",
|
||||
packet->msg, packet->ref, packet->osnum,
|
||||
packet->pid, packet->err, packet->arg);
|
||||
return 0;
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -46,6 +46,27 @@
|
||||
|
||||
#define SCD_MSG_DEBUG_LOG 0x20
|
||||
|
||||
#define SCD_MSG_SYSFS_REQ_CREATE 0x30
|
||||
/* #define SCD_MSG_SYSFS_RESP_CREATE 0x31 */
|
||||
#define SCD_MSG_SYSFS_REQ_MKDIR 0x32
|
||||
/* #define SCD_MSG_SYSFS_RESP_MKDIR 0x33 */
|
||||
#define SCD_MSG_SYSFS_REQ_SYMLINK 0x34
|
||||
/* #define SCD_MSG_SYSFS_RESP_SYMLINK 0x35 */
|
||||
#define SCD_MSG_SYSFS_REQ_LOOKUP 0x36
|
||||
/* #define SCD_MSG_SYSFS_RESP_LOOKUP 0x37 */
|
||||
#define SCD_MSG_SYSFS_REQ_UNLINK 0x38
|
||||
/* #define SCD_MSG_SYSFS_RESP_UNLINK 0x39 */
|
||||
#define SCD_MSG_SYSFS_REQ_SHOW 0x3a
|
||||
#define SCD_MSG_SYSFS_RESP_SHOW 0x3b
|
||||
#define SCD_MSG_SYSFS_REQ_STORE 0x3c
|
||||
#define SCD_MSG_SYSFS_RESP_STORE 0x3d
|
||||
#define SCD_MSG_SYSFS_REQ_RELEASE 0x3e
|
||||
#define SCD_MSG_SYSFS_RESP_RELEASE 0x3f
|
||||
#define SCD_MSG_SYSFS_REQ_SETUP 0x40
|
||||
#define SCD_MSG_SYSFS_RESP_SETUP 0x41
|
||||
/* #define SCD_MSG_SYSFS_REQ_CLEANUP 0x42 */
|
||||
/* #define SCD_MSG_SYSFS_RESP_CLEANUP 0x43 */
|
||||
|
||||
#define ARCH_SET_GS 0x1001
|
||||
#define ARCH_SET_FS 0x1002
|
||||
#define ARCH_GET_FS 0x1003
|
||||
@ -94,13 +115,27 @@ struct user_desc {
|
||||
unsigned int useable:1;
|
||||
unsigned int lm:1;
|
||||
};
|
||||
|
||||
struct ikc_scd_packet {
|
||||
int msg;
|
||||
int ref;
|
||||
int osnum;
|
||||
int pid;
|
||||
int err;
|
||||
unsigned long arg;
|
||||
union {
|
||||
/* for traditional SCD_MSG_* */
|
||||
struct {
|
||||
int ref;
|
||||
int osnum;
|
||||
int pid;
|
||||
int padding;
|
||||
unsigned long arg;
|
||||
};
|
||||
|
||||
/* for SCD_MSG_SYSFS_* */
|
||||
struct {
|
||||
long sysfs_arg1;
|
||||
long sysfs_arg2;
|
||||
long sysfs_arg3;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
struct program_image_section {
|
||||
|
||||
48
kernel/include/sysfs.h
Normal file
48
kernel/include/sysfs.h
Normal file
@ -0,0 +1,48 @@
|
||||
/**
|
||||
* \file sysfs.h
|
||||
* License details are found in the file LICENSE.
|
||||
* \brief
|
||||
* sysfs framework API definitions
|
||||
* \author Gou Nakamura <go.nakamura.yw@hitachi-solutions.com> \par
|
||||
* Copyright (C) 2015 RIKEN AICS
|
||||
*/
|
||||
/*
|
||||
* HISTORY:
|
||||
*/
|
||||
|
||||
#ifndef MCKERNEL_SYSFS_H
|
||||
#define MCKERNEL_SYSFS_H
|
||||
|
||||
#define SYSFS_PATH_MAX 1024
|
||||
|
||||
/* for sysfs_unlinkf() */
|
||||
#define SYSFS_UNLINK_KEEP_ANCESTOR 0x01
|
||||
|
||||
|
||||
struct sysfs_ops {
|
||||
ssize_t (*show)(struct sysfs_ops *ops, void *instance, void *buf,
|
||||
size_t bufsize);
|
||||
ssize_t (*store)(struct sysfs_ops *ops, void *instance, void *buf,
|
||||
size_t bufsize);
|
||||
void (*release)(struct sysfs_ops *ops, void *instance);
|
||||
};
|
||||
|
||||
struct sysfs_handle {
|
||||
long handle;
|
||||
};
|
||||
typedef struct sysfs_handle sysfs_handle_t;
|
||||
|
||||
|
||||
extern int sysfs_createf(struct sysfs_ops *ops, void *instance, int mode,
|
||||
const char *fmt, ...);
|
||||
extern int sysfs_mkdirf(sysfs_handle_t *dirhp, const char *fmt, ...);
|
||||
extern int sysfs_symlinkf(sysfs_handle_t targeth, const char *fmt, ...);
|
||||
extern int sysfs_lookupf(sysfs_handle_t *objhp, const char *fmt, ...);
|
||||
extern int sysfs_unlinkf(int flags, const char *fmt, ...);
|
||||
|
||||
extern void sysfs_init(void);
|
||||
struct ihk_ikc_channel_desc;
|
||||
extern void sysfss_packet_handler(struct ihk_ikc_channel_desc *ch, int msg,
|
||||
int error, long arg1, long arg2, long arg3);
|
||||
|
||||
#endif /* MCKERNEL_SYSFS_H */
|
||||
76
kernel/include/sysfs_msg.h
Normal file
76
kernel/include/sysfs_msg.h
Normal file
@ -0,0 +1,76 @@
|
||||
/**
|
||||
* \file sysfs_msg.h
|
||||
* License details are found in the file LICENSE.
|
||||
* \brief
|
||||
* message declarations for sysfs framework
|
||||
* \author Gou Nakamura <go.nakamura.yw@hitachi-solutions.com> \par
|
||||
* Copyright (C) 2015 RIKEN AICS
|
||||
*/
|
||||
/*
|
||||
* HISTORY:
|
||||
*/
|
||||
|
||||
#ifndef MCKERNEL_SYSFS_MSG_H
|
||||
#define MCKERNEL_SYSFS_MSG_H
|
||||
|
||||
#define SYSFS_PATH_MAX 1024
|
||||
|
||||
struct sysfs_req_create_param {
|
||||
int mode;
|
||||
int error;
|
||||
long client_ops;
|
||||
long client_instance;
|
||||
char path[SYSFS_PATH_MAX];
|
||||
int padding;
|
||||
int busy;
|
||||
}; /* struct sysfs_req_create_param */
|
||||
|
||||
struct sysfs_req_mkdir_param {
|
||||
int error;
|
||||
int padding;
|
||||
long handle;
|
||||
char path[SYSFS_PATH_MAX];
|
||||
int padding2;
|
||||
int busy;
|
||||
}; /* struct sysfs_req_mkdir_param */
|
||||
|
||||
struct sysfs_req_symlink_param {
|
||||
int error;
|
||||
int padding;
|
||||
long target;
|
||||
char path[SYSFS_PATH_MAX];
|
||||
int padding2;
|
||||
int busy;
|
||||
}; /* struct sysfs_req_symlink_param */
|
||||
|
||||
struct sysfs_req_lookup_param {
|
||||
int error;
|
||||
int padding;
|
||||
long handle;
|
||||
char path[SYSFS_PATH_MAX];
|
||||
int padding2;
|
||||
int busy;
|
||||
}; /* struct sysfs_req_lookup_param */
|
||||
|
||||
/* for sysfs_req_unlink_param.flags */
|
||||
#define SYSFS_UNLINK_KEEP_ANCESTOR 0x01
|
||||
|
||||
struct sysfs_req_unlink_param {
|
||||
int flags;
|
||||
int error;
|
||||
char path[SYSFS_PATH_MAX];
|
||||
int padding;
|
||||
int busy;
|
||||
}; /* struct sysfs_req_unlink_param */
|
||||
|
||||
struct sysfs_req_setup_param {
|
||||
int error;
|
||||
int padding;
|
||||
long buf_rpa;
|
||||
long bufsize;
|
||||
char padding3[SYSFS_PATH_MAX];
|
||||
int padding2;
|
||||
int busy;
|
||||
}; /* struct sysfs_req_setup_param */
|
||||
|
||||
#endif /* MCKERNEL_SYSFS_MSG_H */
|
||||
@ -30,6 +30,7 @@
|
||||
#include <init.h>
|
||||
#include <cls.h>
|
||||
#include <syscall.h>
|
||||
#include <sysfs.h>
|
||||
|
||||
//#define IOCTL_FUNC_EXTENSION
|
||||
#ifdef IOCTL_FUNC_EXTENSION
|
||||
@ -278,6 +279,7 @@ static void post_init(void)
|
||||
ap_start();
|
||||
|
||||
create_os_procfs_files();
|
||||
sysfs_init();
|
||||
}
|
||||
#ifdef DCFA_RUN
|
||||
extern void user_main();
|
||||
|
||||
617
kernel/sysfs.c
Normal file
617
kernel/sysfs.c
Normal file
@ -0,0 +1,617 @@
|
||||
/**
|
||||
* \file sysfs.c
|
||||
* License details are found in the file LICENSE.
|
||||
* \brief
|
||||
* sysfs framework, IHK-Slave side
|
||||
* \author Gou Nakamura <go.nakamura.yw@hitachi-solutions.com> \par
|
||||
* Copyright (C) 2015 RIKEN AICS
|
||||
*/
|
||||
/*
|
||||
* HISTORY:
|
||||
*/
|
||||
|
||||
#include <ihk/mm.h>
|
||||
#include <ihk/types.h>
|
||||
#include <ikc/queue.h>
|
||||
#include <cls.h>
|
||||
#include <kmsg.h>
|
||||
#include <kmalloc.h>
|
||||
#include <page.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <arch/cpu.h>
|
||||
#include <sysfs.h>
|
||||
#include <sysfs_msg.h>
|
||||
#include <vsprintf.h>
|
||||
|
||||
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
|
||||
#define ekprintf(...) do { if (1) kprintf(__VA_ARGS__); } while (0)
|
||||
|
||||
static size_t sysfs_data_bufsize;
|
||||
static void *sysfs_data_buf;
|
||||
|
||||
int
|
||||
sysfs_createf(struct sysfs_ops *ops, void *instance, int mode,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
int error;
|
||||
va_list ap;
|
||||
ssize_t n;
|
||||
struct sysfs_req_create_param *param = NULL;
|
||||
struct ikc_scd_packet packet;
|
||||
|
||||
dkprintf("sysfs_createf(%p,%p,%#o,%s,...)\n",
|
||||
ops, instance, mode, fmt);
|
||||
|
||||
param = allocate_pages(1, IHK_MC_AP_NOWAIT);
|
||||
if (!param) {
|
||||
error = -ENOMEM;
|
||||
ekprintf("sysfs_createf:allocate_pages failed. %d\n", error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
param->client_ops = (long)ops;
|
||||
param->client_instance = (long)instance;
|
||||
param->mode = mode;
|
||||
param->busy = 1;
|
||||
|
||||
va_start(ap, fmt);
|
||||
n = vsnprintf(param->path, sizeof(param->path), fmt, ap);
|
||||
va_end(ap);
|
||||
if (n >= sizeof(param->path)) {
|
||||
error = -ENAMETOOLONG;
|
||||
ekprintf("sysfs_createf:vsnprintf failed. %d\n", error);
|
||||
goto out;
|
||||
}
|
||||
dkprintf("sysfs_createf:path %s\n", param->path);
|
||||
if (param->path[0] != '/') {
|
||||
error = -ENOENT;
|
||||
ekprintf("sysfs_createf:not an absolute path. %d\n", error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
packet.msg = SCD_MSG_SYSFS_REQ_CREATE;
|
||||
packet.sysfs_arg1 = virt_to_phys(param);
|
||||
|
||||
error = ihk_ikc_send(cpu_local_var(syscall_channel), &packet, 0);
|
||||
if (error) {
|
||||
ekprintf("sysfs_createf:ihk_ikc_send failed. %d\n", error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
while (param->busy) {
|
||||
cpu_pause();
|
||||
}
|
||||
rmb();
|
||||
|
||||
error = param->error;
|
||||
if (error) {
|
||||
ekprintf("sysfs_createf:SCD_MSG_SYSFS_REQ_CREATE failed. %d\n",
|
||||
error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
error = 0;
|
||||
out:
|
||||
if (param) {
|
||||
free_pages(param, 1);
|
||||
}
|
||||
if (error) {
|
||||
ekprintf("sysfs_createf(%p,%p,%#o,%s,...): %d\n",
|
||||
ops, instance, mode, fmt, error);
|
||||
}
|
||||
dkprintf("sysfs_createf(%p,%p,%#o,%s,...): %d\n",
|
||||
ops, instance, mode, fmt, error);
|
||||
return error;
|
||||
} /* sysfs_createf() */
|
||||
|
||||
int
|
||||
sysfs_mkdirf(sysfs_handle_t *dirhp, const char *fmt, ...)
|
||||
{
|
||||
int error;
|
||||
struct sysfs_req_mkdir_param *param = NULL;
|
||||
struct ikc_scd_packet packet;
|
||||
va_list ap;
|
||||
int n;
|
||||
|
||||
dkprintf("sysfs_mkdirf(%p,%s,...)\n", dirhp, fmt);
|
||||
|
||||
param = allocate_pages(1, IHK_MC_AP_NOWAIT);
|
||||
if (!param) {
|
||||
error = -ENOMEM;
|
||||
ekprintf("sysfs_mkdirf:allocate_pages failed. %d\n", error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
param->busy = 1;
|
||||
|
||||
va_start(ap, fmt);
|
||||
n = vsnprintf(param->path, sizeof(param->path), fmt, ap);
|
||||
va_end(ap);
|
||||
if (n >= sizeof(param->path)) {
|
||||
error = -ENAMETOOLONG;
|
||||
ekprintf("sysfs_mkdirf:vsnprintf failed. %d\n", error);
|
||||
goto out;
|
||||
}
|
||||
dkprintf("sysfs_mkdirf:path %s\n", param->path);
|
||||
if (param->path[0] != '/') {
|
||||
error = -ENOENT;
|
||||
ekprintf("sysfs_mkdirf:not an absolute path. %d\n", error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
packet.msg = SCD_MSG_SYSFS_REQ_MKDIR;
|
||||
packet.sysfs_arg1 = virt_to_phys(param);
|
||||
|
||||
error = ihk_ikc_send(cpu_local_var(syscall_channel), &packet, 0);
|
||||
if (error) {
|
||||
ekprintf("sysfs_mkdirf:ihk_ikc_send failed. %d\n", error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
while (param->busy) {
|
||||
cpu_pause();
|
||||
}
|
||||
rmb();
|
||||
|
||||
error = param->error;
|
||||
if (error) {
|
||||
ekprintf("sysfs_mkdirf:SCD_MSG_SYSFS_REQ_MKDIR failed. %d\n",
|
||||
error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
error = 0;
|
||||
if (dirhp) {
|
||||
dirhp->handle = param->handle;
|
||||
}
|
||||
|
||||
out:
|
||||
if (param) {
|
||||
free_pages(param, 1);
|
||||
}
|
||||
if (error) {
|
||||
ekprintf("sysfs_mkdirf(%p,%s,...): %d\n", dirhp, fmt, error);
|
||||
}
|
||||
dkprintf("sysfs_mkdirf(%p,%s,...): %d %#lx\n", dirhp, fmt, error,
|
||||
(dirhp)?dirhp->handle:0);
|
||||
return error;
|
||||
} /* sysfs_mkdirf() */
|
||||
|
||||
int
|
||||
sysfs_symlinkf(sysfs_handle_t targeth, const char *fmt, ...)
|
||||
{
|
||||
int error;
|
||||
struct sysfs_req_symlink_param *param = NULL;
|
||||
struct ikc_scd_packet packet;
|
||||
va_list ap;
|
||||
int n;
|
||||
|
||||
dkprintf("sysfs_symlinkf(%#lx,%s,...)\n", targeth.handle, fmt);
|
||||
|
||||
param = allocate_pages(1, IHK_MC_AP_NOWAIT);
|
||||
if (!param) {
|
||||
error = -ENOMEM;
|
||||
ekprintf("sysfs_symlinkf:allocate_pages failed. %d\n", error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
param->target = targeth.handle;
|
||||
param->busy = 1;
|
||||
|
||||
va_start(ap, fmt);
|
||||
n = vsnprintf(param->path, sizeof(param->path), fmt, ap);
|
||||
va_end(ap);
|
||||
if (n >= sizeof(param->path)) {
|
||||
error = -ENAMETOOLONG;
|
||||
ekprintf("sysfs_symlinkf:vsnprintf failed. %d\n", error);
|
||||
goto out;
|
||||
}
|
||||
dkprintf("sysfs_symlinkf:path %s\n", param->path);
|
||||
if (param->path[0] != '/') {
|
||||
error = -ENOENT;
|
||||
ekprintf("sysfs_symlinkf:not an absolute path. %d\n", error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
packet.msg = SCD_MSG_SYSFS_REQ_SYMLINK;
|
||||
packet.sysfs_arg1 = virt_to_phys(param);
|
||||
|
||||
error = ihk_ikc_send(cpu_local_var(syscall_channel), &packet, 0);
|
||||
if (error) {
|
||||
ekprintf("sysfs_symlinkf:ihk_ikc_send failed. %d\n", error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
while (param->busy) {
|
||||
cpu_pause();
|
||||
}
|
||||
rmb();
|
||||
|
||||
error = param->error;
|
||||
if (error) {
|
||||
ekprintf("sysfs_symlinkf:"
|
||||
"SCD_MSG_SYSFS_REQ_SYMLINK failed. %d\n",
|
||||
error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
error = 0;
|
||||
out:
|
||||
if (param) {
|
||||
free_pages(param, 1);
|
||||
}
|
||||
if (error) {
|
||||
ekprintf("sysfs_symlinkf(%#lx,%s,...): %d\n",
|
||||
targeth.handle, fmt, error);
|
||||
}
|
||||
dkprintf("sysfs_symlinkf(%#lx,%s,...): %d\n",
|
||||
targeth.handle, fmt, error);
|
||||
return error;
|
||||
} /* sysfs_symlinkf() */
|
||||
|
||||
int
|
||||
sysfs_lookupf(sysfs_handle_t *objhp, const char *fmt, ...)
|
||||
{
|
||||
int error;
|
||||
struct sysfs_req_lookup_param *param = NULL;
|
||||
struct ikc_scd_packet packet;
|
||||
va_list ap;
|
||||
int n;
|
||||
|
||||
dkprintf("sysfs_lookupf(%p,%s,...)\n", objhp, fmt);
|
||||
|
||||
param = allocate_pages(1, IHK_MC_AP_NOWAIT);
|
||||
if (!param) {
|
||||
error = -ENOMEM;
|
||||
ekprintf("sysfs_lookupf:allocate_pages failed. %d\n", error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
param->busy = 1;
|
||||
|
||||
va_start(ap, fmt);
|
||||
n = vsnprintf(param->path, sizeof(param->path), fmt, ap);
|
||||
va_end(ap);
|
||||
if (n >= sizeof(param->path)) {
|
||||
error = -ENAMETOOLONG;
|
||||
ekprintf("sysfs_lookupf:vsnprintf failed. %d\n", error);
|
||||
goto out;
|
||||
}
|
||||
dkprintf("sysfs_lookupf:path %s\n", param->path);
|
||||
if (param->path[0] != '/') {
|
||||
error = -ENOENT;
|
||||
ekprintf("sysfs_lookupf:not an absolute path. %d\n", error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
packet.msg = SCD_MSG_SYSFS_REQ_LOOKUP;
|
||||
packet.sysfs_arg1 = virt_to_phys(param);
|
||||
|
||||
error = ihk_ikc_send(cpu_local_var(syscall_channel), &packet, 0);
|
||||
if (error) {
|
||||
ekprintf("sysfs_lookupf:ihk_ikc_send failed. %d\n", error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
while (param->busy) {
|
||||
cpu_pause();
|
||||
}
|
||||
rmb();
|
||||
|
||||
error = param->error;
|
||||
if (error) {
|
||||
ekprintf("sysfs_lookupf:SCD_MSG_SYSFS_REQ_LOOKUP failed. %d\n",
|
||||
error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
error = 0;
|
||||
if (objhp) {
|
||||
objhp->handle = param->handle;
|
||||
}
|
||||
|
||||
out:
|
||||
if (param) {
|
||||
free_pages(param, 1);
|
||||
}
|
||||
if (error) {
|
||||
ekprintf("sysfs_lookupf(%p,%s,...): %d\n", objhp, fmt, error);
|
||||
}
|
||||
dkprintf("sysfs_lookupf(%p,%s,...): %d %#lx\n", objhp, fmt, error,
|
||||
(objhp)?objhp->handle:0);
|
||||
return error;
|
||||
} /* sysfs_lookupf() */
|
||||
|
||||
int
|
||||
sysfs_unlinkf(int flags, const char *fmt, ...)
|
||||
{
|
||||
int error;
|
||||
struct sysfs_req_unlink_param *param = NULL;
|
||||
struct ikc_scd_packet packet;
|
||||
va_list ap;
|
||||
int n;
|
||||
|
||||
dkprintf("sysfs_unlinkf(%#x,%s,...)\n", flags, fmt);
|
||||
|
||||
param = allocate_pages(1, IHK_MC_AP_NOWAIT);
|
||||
if (!param) {
|
||||
error = -ENOMEM;
|
||||
ekprintf("sysfs_unlinkf:allocate_pages failed. %d\n", error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
param->flags = flags;
|
||||
param->busy = 1;
|
||||
|
||||
va_start(ap, fmt);
|
||||
n = vsnprintf(param->path, sizeof(param->path), fmt, ap);
|
||||
va_end(ap);
|
||||
if (n >= sizeof(param->path)) {
|
||||
error = -ENAMETOOLONG;
|
||||
ekprintf("sysfs_unlinkf:vsnprintf failed. %d\n", error);
|
||||
goto out;
|
||||
}
|
||||
dkprintf("sysfs_unlinkf:path %s\n", param->path);
|
||||
if (param->path[0] != '/') {
|
||||
error = -ENOENT;
|
||||
ekprintf("sysfs_unlinkf:not an absolute path. %d\n", error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
packet.msg = SCD_MSG_SYSFS_REQ_UNLINK;
|
||||
packet.sysfs_arg1 = virt_to_phys(param);
|
||||
|
||||
error = ihk_ikc_send(cpu_local_var(syscall_channel), &packet, 0);
|
||||
if (error) {
|
||||
ekprintf("sysfs_unlinkf:ihk_ikc_send failed. %d\n", error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
while (param->busy) {
|
||||
cpu_pause();
|
||||
}
|
||||
rmb();
|
||||
|
||||
error = param->error;
|
||||
if (error) {
|
||||
ekprintf("sysfs_unlinkf:SCD_MSG_SYSFS_REQ_UNLINK failed. %d\n",
|
||||
error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
error = 0;
|
||||
out:
|
||||
if (param) {
|
||||
free_pages(param, 1);
|
||||
}
|
||||
if (error) {
|
||||
ekprintf("sysfs_unlinkf(%#x,%s,...): %d\n", flags, fmt, error);
|
||||
}
|
||||
dkprintf("sysfs_unlinkf(%#x,%s,...): %d\n", flags, fmt, error);
|
||||
return error;
|
||||
} /* sysfs_unlinkf() */
|
||||
|
||||
static void
|
||||
sysfss_req_show(long nodeh, struct sysfs_ops *ops, void *instance)
|
||||
{
|
||||
int error;
|
||||
ssize_t ssize;
|
||||
struct ikc_scd_packet packet;
|
||||
|
||||
dkprintf("sysfss_req_show(%#lx,%p,%p)\n", nodeh, ops, instance);
|
||||
|
||||
ssize = -EIO;
|
||||
if (ops->show) {
|
||||
ssize = (*ops->show)(ops, instance, sysfs_data_buf,
|
||||
sysfs_data_bufsize);
|
||||
if (ssize < 0) {
|
||||
ekprintf("sysfss_req_show:->show failed. %ld\n",
|
||||
ssize);
|
||||
/* through */
|
||||
}
|
||||
}
|
||||
|
||||
error = 0;
|
||||
if (ssize < 0) {
|
||||
error = ssize;
|
||||
}
|
||||
|
||||
packet.msg = SCD_MSG_SYSFS_RESP_SHOW;
|
||||
packet.err = error;
|
||||
packet.sysfs_arg1 = nodeh;
|
||||
packet.sysfs_arg2 = ssize;
|
||||
|
||||
error = ihk_ikc_send(cpu_local_var(syscall_channel), &packet, 0);
|
||||
if (error) {
|
||||
ekprintf("sysfss_req_show:ihk_ikc_send failed. %d\n", error);
|
||||
/* through */
|
||||
}
|
||||
|
||||
if (error || packet.err) {
|
||||
ekprintf("sysfss_req_show(%#lx,%p,%p): %d %d\n",
|
||||
nodeh, ops, instance, error, packet.err);
|
||||
}
|
||||
dkprintf("sysfss_req_show(%#lx,%p,%p): %d %d %ld\n",
|
||||
nodeh, ops, instance, error, packet.err, ssize);
|
||||
return;
|
||||
} /* sysfss_req_show() */
|
||||
|
||||
static void
|
||||
sysfss_req_store(long nodeh, struct sysfs_ops *ops, void *instance,
|
||||
size_t size)
|
||||
{
|
||||
int error;
|
||||
ssize_t ssize;
|
||||
struct ikc_scd_packet packet;
|
||||
|
||||
dkprintf("sysfss_req_store(%#lx,%p,%p,%d)\n",
|
||||
nodeh, ops, instance, size);
|
||||
|
||||
ssize = -EIO;
|
||||
if (ops->store) {
|
||||
ssize = (*ops->store)(ops, instance, sysfs_data_buf, size);
|
||||
if (ssize < 0) {
|
||||
ekprintf("sysfss_req_store:->store failed. %ld\n",
|
||||
ssize);
|
||||
/* through */
|
||||
}
|
||||
}
|
||||
|
||||
error = 0;
|
||||
if (ssize < 0) {
|
||||
error = ssize;
|
||||
}
|
||||
|
||||
packet.msg = SCD_MSG_SYSFS_RESP_STORE;
|
||||
packet.err = error;
|
||||
packet.sysfs_arg1 = nodeh;
|
||||
packet.sysfs_arg2 = ssize;
|
||||
|
||||
error = ihk_ikc_send(cpu_local_var(syscall_channel), &packet, 0);
|
||||
if (error) {
|
||||
ekprintf("sysfss_req_store:ihk_ikc_send failed. %d\n", error);
|
||||
/* through */
|
||||
}
|
||||
|
||||
if (error || packet.err) {
|
||||
ekprintf("sysfss_req_store(%#lx,%p,%p,%d): %d %d\n",
|
||||
nodeh, ops, instance, size, error, packet.err);
|
||||
}
|
||||
dkprintf("sysfss_req_store(%#lx,%p,%p,%d): %d %d %ld\n",
|
||||
nodeh, ops, instance, size, error, packet.err, ssize);
|
||||
return;
|
||||
} /* sysfss_req_store() */
|
||||
|
||||
static void
|
||||
sysfss_req_release(long nodeh, struct sysfs_ops *ops, void *instance)
|
||||
{
|
||||
int error;
|
||||
struct ikc_scd_packet packet;
|
||||
|
||||
dkprintf("sysfss_req_release(%#lx,%p,%p)\n", nodeh, ops, instance);
|
||||
|
||||
if (ops->release) {
|
||||
(*ops->release)(ops, instance);
|
||||
}
|
||||
|
||||
packet.msg = SCD_MSG_SYSFS_RESP_RELEASE;
|
||||
packet.err = 0;
|
||||
packet.sysfs_arg1 = nodeh;
|
||||
|
||||
error = ihk_ikc_send(cpu_local_var(syscall_channel), &packet, 0);
|
||||
if (error) {
|
||||
ekprintf("sysfss_req_release:ihk_ikc_send failed. %d\n",
|
||||
error);
|
||||
/* through */
|
||||
}
|
||||
|
||||
if (error || packet.err) {
|
||||
ekprintf("sysfss_req_release(%#lx,%p,%p): %d %d\n",
|
||||
nodeh, ops, instance, error, packet.err);
|
||||
}
|
||||
dkprintf("sysfss_req_release(%#lx,%p,%p): %d %d\n",
|
||||
nodeh, ops, instance, error, packet.err);
|
||||
return;
|
||||
} /* sysfss_req_release() */
|
||||
|
||||
void
|
||||
sysfss_packet_handler(struct ihk_ikc_channel_desc *ch, int msg, int error,
|
||||
long arg1, long arg2, long arg3)
|
||||
{
|
||||
switch (msg) {
|
||||
case SCD_MSG_SYSFS_REQ_SHOW:
|
||||
sysfss_req_show(arg1, (void *)arg2, (void *)arg3);
|
||||
break;
|
||||
|
||||
case SCD_MSG_SYSFS_REQ_STORE:
|
||||
sysfss_req_store(arg1, (void *)arg2, (void *)arg3, error);
|
||||
break;
|
||||
|
||||
case SCD_MSG_SYSFS_REQ_RELEASE:
|
||||
sysfss_req_release(arg1, (void *)arg2, (void *)arg3);
|
||||
break;
|
||||
|
||||
default:
|
||||
kprintf("sysfss_packet_handler:unknown message. msg %d"
|
||||
" error %d arg1 %#lx arg2 %#lx arg3 %#lx\n",
|
||||
msg, error, arg1, arg2, arg3);
|
||||
break;
|
||||
|
||||
}
|
||||
return;
|
||||
} /* sysfss_packet_handler() */
|
||||
|
||||
void
|
||||
sysfs_init(void)
|
||||
{
|
||||
int error;
|
||||
struct sysfs_req_setup_param *param = NULL;
|
||||
struct ikc_scd_packet packet;
|
||||
|
||||
dkprintf("sysfs_init()\n");
|
||||
|
||||
if ((sizeof(struct sysfs_req_create_param) > PAGE_SIZE)
|
||||
|| (sizeof(struct sysfs_req_mkdir_param) > PAGE_SIZE)
|
||||
|| (sizeof(struct sysfs_req_symlink_param) > PAGE_SIZE)
|
||||
|| (sizeof(struct sysfs_req_lookup_param) > PAGE_SIZE)
|
||||
|| (sizeof(struct sysfs_req_unlink_param) > PAGE_SIZE)
|
||||
|| (sizeof(struct sysfs_req_setup_param) > PAGE_SIZE)) {
|
||||
panic("struct sysfs_*_req_param too large");
|
||||
}
|
||||
|
||||
sysfs_data_bufsize = PAGE_SIZE;
|
||||
sysfs_data_buf = allocate_pages(1, IHK_MC_AP_NOWAIT);
|
||||
if (!sysfs_data_buf) {
|
||||
error = -ENOMEM;
|
||||
ekprintf("sysfs_init:allocate_pages(buf) failed. %d\n", error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
param = allocate_pages(1, IHK_MC_AP_NOWAIT);
|
||||
if (!param) {
|
||||
error = -ENOMEM;
|
||||
ekprintf("sysfs_init:allocate_pages(param) failed. %d\n",
|
||||
error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
param->busy = 1;
|
||||
param->buf_rpa = virt_to_phys(sysfs_data_buf);
|
||||
param->bufsize = PAGE_SIZE;
|
||||
|
||||
packet.msg = SCD_MSG_SYSFS_REQ_SETUP;
|
||||
packet.sysfs_arg1 = virt_to_phys(param);
|
||||
|
||||
error = ihk_ikc_send(cpu_local_var(syscall_channel), &packet, 0);
|
||||
if (error) {
|
||||
ekprintf("sysfs_init:ihk_ikc_send failed. %d\n", error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
while (param->busy) {
|
||||
cpu_pause();
|
||||
}
|
||||
rmb();
|
||||
|
||||
error = param->error;
|
||||
if (error) {
|
||||
ekprintf("sysfs_init:SCD_MSG_SYSFS_REQ_SETUP failed. %d\n",
|
||||
error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
error = 0;
|
||||
out:
|
||||
if (param) {
|
||||
free_pages(param, 1);
|
||||
}
|
||||
if (error) {
|
||||
ekprintf("sysfs_init(): %d\n", error);
|
||||
panic("sysfs_init");
|
||||
}
|
||||
dkprintf("sysfs_init():\n");
|
||||
return;
|
||||
} /* sysfs_init() */
|
||||
|
||||
/**** End of File ****/
|
||||
22
lib/include/vsprintf.h
Normal file
22
lib/include/vsprintf.h
Normal file
@ -0,0 +1,22 @@
|
||||
/**
|
||||
* \file vsprintf.h
|
||||
* License details are found in the file LICENSE.
|
||||
* \brief
|
||||
* declare printf() like functions
|
||||
* \author Gou Nakamura <go.nakamura.yw@hitachi-solutions.com> \par
|
||||
* Copyright (C) 2015 RIKEN AICS
|
||||
*/
|
||||
/*
|
||||
* HISTORY
|
||||
*/
|
||||
|
||||
#ifndef VSPRINTF_H
|
||||
#define VSPRINTF_H
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <types.h>
|
||||
|
||||
extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
|
||||
extern int snprintf(char *buf, size_t size, const char *fmt, ...);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user