[Libsysio-commit] gmdev: libsysio/dev/gmdev gmdev.c gmdev.h module.mk
Brought to you by:
lward
From: Ruth K. <rk...@us...> - 2004-03-04 18:29:29
|
Update of /cvsroot/libsysio/libsysio/dev/gmdev In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3889/dev/gmdev Added Files: Tag: gmdev gmdev.c gmdev.h module.mk Log Message: The gmdev branch records what is currently sitting in the Cplant repository. Changes to fs_yod.c also make it compatible with the strided-io mods. --- NEW FILE --- /* * This Cplant(TM) source code is the property of Sandia National * Laboratories. * * This Cplant(TM) source code is copyrighted by Sandia National * Laboratories. * * The redistribution of this Cplant(TM) source code is subject to the * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * * Cplant(TM) Copyright 1998-2003 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States * Government. */ /* * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Questions or comments about this library should be sent to: * * Lee Ward * Sandia National Laboratories, New Mexico * P.O. Box 5800 * Albuquerque, NM 87185-1110 * * le...@sa... */ #ifdef __linux__ #define _BSD_SOURCE #endif #include <errno.h> #include <stdlib.h> #include <sys/syscall.h> #include <unistd.h> #include <sys/uio.h> #include <sys/types.h> #include <sys/queue.h> #include "sysio.h" #include "inode.h" #include "dev.h" #include "gmdev.h" /* * Myricom GM device driver support */ struct gmdev_private{ int g_fd; dev_t g_dev; }; #define I2GP(ino) ((struct gmdev_private *)((ino)->i_private)) static int gmdev_open(struct pnode *pno, int flags, mode_t mode); static int gmdev_close(struct inode *ino); static int gmdev_read(struct inode *ino, struct ioctx *ioctx); static int gmdev_write(struct inode *ino, struct ioctx *ioctx); static int gmdev_iodone(struct ioctx *ioctx); static int gmdev_datasync(struct inode *ino); static int gmdev_ioctl(struct inode *ino, unsigned long int request, va_list ap); static void *gmdev_mmap(struct inode *ino, void *start, size_t length, int prot, int flags, _SYSIO_OFF_T offset); int _sysio_gmdev_init() { int err = 0; struct inode_ops gmdev_operations; gmdev_operations = _sysio_nodev_ops; gmdev_operations.inop_open = gmdev_open; gmdev_operations.inop_close = gmdev_close; gmdev_operations.inop_read = gmdev_read; gmdev_operations.inop_write = gmdev_write; gmdev_operations.inop_iodone = gmdev_iodone; gmdev_operations.inop_datasync = gmdev_datasync; gmdev_operations.inop_ioctl = gmdev_ioctl; gmdev_operations.inop_mmap = gmdev_mmap; err = _sysio_char_dev_register(SYSIO_GM_DEV_MAJOR, "gmdev", &gmdev_operations); if (err < 0) return err; err = _sysio_char_dev_register(SYSIO_CTASK_MAJOR, "cTask", &gmdev_operations); if (err < 0) return err; err = _sysio_char_dev_register(SYSIO_ptRXTX_MAJOR, "ptRXTX", &gmdev_operations); return err; } static int gmdev_open(struct pnode *pno, int flags, mode_t mode) { int fd, err = 0; char *path; dev_t gdev; struct inode *ino; struct gmdev_private *gpriv; gpriv = malloc(sizeof(struct gmdev_private)); if (gpriv == NULL) { err = -ENOMEM; goto out; } path = _sysio_pb_path(pno->p_base, '/'); if (path == NULL) { err = -ENOMEM; goto out; } if ((ino = pno->p_base->pb_ino) == NULL) { err = -ENOENT; goto out; } gdev = SYSIO_MAJOR_DEV(ino->i_rdev); if (gdev == I2GP(ino)->g_dev) { /* * Disallow multiple opens */ err = -EBUSY; goto out; } fd = syscall(SYS_open, path, flags, mode); if (fd < 0) { err = -errno; goto out; } gpriv->g_fd = fd; gpriv->g_dev = ino->i_rdev; ino->i_private = gpriv; out: if (err < 0) free(gpriv); return err; } static int gmdev_close(struct inode *ino) { syscall(SYS_close, I2GP(ino)->g_fd); return 0; } static int doio(ssize_t (*f)(void *, size_t, _SYSIO_OFF_T, struct inode *), struct inode *ino, struct ioctx *ioctx) { if (ioctx->ioctx_xtvlen != 1) { /* * No scatter/gather to "file" address space (we're not * seekable) and "nowhere" makes no sense. */ return -EINVAL; } ioctx->ioctx_cc = _sysio_doio(ioctx->ioctx_xtv, ioctx->ioctx_xtvlen, ioctx->ioctx_iov, ioctx->ioctx_iovlen, (ssize_t (*)(void *, size_t, _SYSIO_OFF_T, void *))f, ino); if (ioctx->ioctx_cc < 0) { ioctx->ioctx_errno = -ioctx->ioctx_cc; ioctx->ioctx_cc = -1; } return 0; } static ssize_t gmdev_read_simple(void *buf, size_t nbytes, _SYSIO_OFF_T off __IS_UNUSED, struct inode *ino) { return syscall(SYS_read, I2GP(ino)->g_fd, buf, nbytes); } static ssize_t gmdev_write_simple(const void *buf, size_t nbytes, _SYSIO_OFF_T off __IS_UNUSED, struct inode *ino) { return syscall(SYS_write, I2GP(ino)->g_fd, buf, nbytes); } static int gmdev_read(struct inode *ino, struct ioctx *ioctx) { return doio(gmdev_read_simple, ino, ioctx); } static int gmdev_write(struct inode *ino, struct ioctx *ioctx) { return doio((ssize_t (*)(void *, size_t, _SYSIO_OFF_T, struct inode *))gmdev_write_simple, ino, ioctx); } static int gmdev_iodone(struct ioctx *iocp __IS_UNUSED) { /* * It's always done in this driver. It completed when posted. */ return 1; } static int gmdev_datasync(struct inode *ino __IS_UNUSED) { /* * We don't buffer, so nothing to do. */ return 0; } static int gmdev_ioctl(struct inode *ino, unsigned long int request, va_list ap) { int err = 0; unsigned long arg; arg = va_arg(ap, unsigned long); err = syscall(SYS_ioctl, I2GP(ino)->g_fd, request, arg); if (err < 0) err = -errno; return err; } extern void * __mmap64(void *, size_t, int, int, int, off64_t); static void * gmdev_mmap(struct inode *ino, void *start, size_t length, int prot, int flags, _SYSIO_OFF_T offset) { void *p; int fd; #if 0 long _sc_ret, _sc_err; #endif fd = I2GP(ino)->g_fd; #if 0 /* * GLIBC 2.2.4 in RH7.2 exports a syscall interface enabled for * only 5 args, see sysdeps/unix/sysv/linux/alpha/syscall.S * return is always EINVAL here. */ p = syscall(SYS_mmap, start, length, prot, flags, fd, offset); #elif 0 /* * This is the way GLIBC 2.2.4 in RH7.2 implements its own * internal 6 arg syscall (definition in gmdev.h), and it works fine, * see sysdeps/unix/alpha/sysdep.h */ inline_syscall6(mmap, start, length, prot, flags, fd, offset); if (_sc_err != 0) return (void *)_sc_err; return (void *)_sc_ret; #else p = __mmap64(start, length, prot, flags, fd, offset); #endif return p; } --- NEW FILE --- /* * This Cplant(TM) source code is the property of Sandia National * Laboratories. * * This Cplant(TM) source code is copyrighted by Sandia National * Laboratories. * * The redistribution of this Cplant(TM) source code is subject to the * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * * Cplant(TM) Copyright 1998-2003 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States * Government. */ /* * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Questions or comments about this library should be sent to: * * Lee Ward * Sandia National Laboratories, New Mexico * P.O. Box 5800 * Albuquerque, NM 87185-1110 * * le...@sa... */ /* * Myricom GM device driver support */ #define SYSIO_GM_DEV_MAJOR 0x29 #define SYSIO_CTASK_MAJOR 0x3f #define SYSIO_ptRXTX_MAJOR 0x41 extern int _sysio_gm_init(void); struct native_inode_identifier { dev_t dev; /* device number */ ino_t ino; /* i-number */ #ifdef HAVE_GENERATION unsigned int gen; /* generation number */ #endif }; struct native_inode { unsigned ni_seekok : 1; /* can seek? */ struct native_inode_identifier ni_ident; /* unique identifier */ struct file_identifier ni_fileid; /* ditto */ int ni_fd; /* host fildes */ int ni_oflags; /* flags, from open */ unsigned ni_nopens; /* soft ref count */ _SYSIO_OFF_T ni_fpos; /* current pos */ }; #define I2NI(ino) ((struct native_inode *)((ino)->i_private)) #if 0 /* * This is the way GLIBC 2.2.4 in RH7.2 implements its own * internal 6 arg syscall * see sysdeps/unix/alpha/sysdep.h */ #define inline_syscall_clobbers \ "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", \ "$22", "$23", "$24", "$25", "$27", "$28", "memory" #define inline_syscall6(name,arg1,arg2,arg3,arg4,arg5,arg6) \ { \ register long _sc_0 __asm__("$0"); \ register long _sc_16 __asm__("$16"); \ register long _sc_17 __asm__("$17"); \ register long _sc_18 __asm__("$18"); \ register long _sc_19 __asm__("$19"); \ register long _sc_20 __asm__("$20"); \ register long _sc_21 __asm__("$21"); \ \ _sc_0 = __NR_##name; \ _sc_16 = (long) (arg1); \ _sc_17 = (long) (arg2); \ _sc_18 = (long) (arg3); \ _sc_19 = (long) (arg4); \ _sc_20 = (long) (arg5); \ _sc_21 = (long) (arg6); \ __asm__("callsys # %0 %1 <= %2 %3 %4 %5 %6 %7 %8" \ : "=r"(_sc_0), "=r"(_sc_19) \ : "0"(_sc_0), "r"(_sc_16), "r"(_sc_17), \ "r"(_sc_18), "1"(_sc_19), "r"(_sc_20), \ "r"(_sc_21) \ : inline_syscall_clobbers); \ _sc_ret = _sc_0, _sc_err = _sc_19; \ } #endif --- NEW FILE --- GMDEV_SRCS = dev/gmdev/gmdev.c GMDEV_EXTRA = dev/gmdev/gmdev.h dev/gmdev/module.mk |