support McKernel's sysfs tree
This commit is contained in:
@@ -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 ****/
|
||||
Reference in New Issue
Block a user