From 4f7550dcaf9375046514cdd97cea0f667e955e9f Mon Sep 17 00:00:00 2001
From: Andrew Deason <adeason@sinenomine.net>
Date: Sat, 7 Mar 2015 17:27:47 -0600
Subject: [PATCH] Add support for arm64_linux26

Add support for the arm64/aarch64 architecture on Linux 2.6+. The
param header file is mostly combined from arm and amd64.

Note that the code for syscall interception has not been updated for
arm64, so this will not build on arm64 without support for kernel
keyrings. This also does not define any AFS syscall number, since no
number in the Linux arm64 syscall table is "free" for us to use, as
far as I am aware.

Adapted from initial patches from Micheal Waltz <mwaltz@qualcomm.com>.

Change-Id: I1ee239ded17d8fea3b91b70405215aa1b3f7a6e9
Reviewed-on: https://gerrit.openafs.org/11940
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
---
 INSTALL                          |  2 +-
 src/afs/afs_syscall.c            |  4 ++++
 src/afs/sysincludes.h            |  1 +
 src/cf/osconf.m4                 |  2 +-
 src/cf/sysname.m4                |  3 +++
 src/config/afs_sysnames.h        |  2 ++
 src/config/param.arm64_linux26.h | 38 ++++++++++++++++++++++++++++++++++++++
 7 files changed, 50 insertions(+), 2 deletions(-)
 create mode 100644 src/config/param.arm64_linux26.h

diff --git a/INSTALL b/INSTALL
index 3d802a72d3..920e23e615 100644
--- a/INSTALL
+++ b/INSTALL
@@ -38,7 +38,7 @@ A  Configuring
          amd64_fbsd_93, amd64_fbsd_100, amd64_fbsd_101
       amd64_linux26
       amd64_nbsd20, amd64_nbsd30, amd64_nbsd40
-      arm_linux26
+      arm_linux26, arm64_linux26
       hp_ux11i, hp_ux110, hp_ux1123 (See notes below for information on
          getting missing header)
       hp_ux102 (Client port possible, but db servers and utilities work)
diff --git a/src/afs/afs_syscall.c b/src/afs/afs_syscall.c
index b2b644ae13..ce6afdf9a8 100644
--- a/src/afs/afs_syscall.c
+++ b/src/afs/afs_syscall.c
@@ -141,6 +141,8 @@ copyin_afs_ioctl(caddr_t cmarg, struct afs_ioctl *dst)
     if (test_thread_flag(TIF_31BIT))
 #elif defined(AFS_S390X_LINUX20_ENV)
     if (current->thread.flags & S390_FLAG_31BIT)
+#elif defined(AFS_ARM64_LINUX26_ENV)
+    if (is_compat_task())
 
 #else
 #error pioctl32 not done for this linux
@@ -416,6 +418,8 @@ copyin_iparam(caddr_t cmarg, struct iparam *dst)
     if (test_thread_flag(TIF_31BIT))
 #elif defined(AFS_S390X_LINUX20_ENV)
     if (current->thread.flags & S390_FLAG_31BIT)
+#elif defined(AFS_ARM64_LINUX26_ENV)
+    if (is_compat_task())
 
 #else
 #error iparam32 not done for this linux platform
diff --git a/src/afs/sysincludes.h b/src/afs/sysincludes.h
index 0e09271cdb..603773cfdd 100644
--- a/src/afs/sysincludes.h
+++ b/src/afs/sysincludes.h
@@ -122,6 +122,7 @@
 # include <linux/kdev_t.h>
 # include <linux/ioctl.h>
 # if defined(AFS_LINUX26_ENV)
+#  include <linux/compat.h>
 #  include <linux/backing-dev.h>
 #  include <linux/pagemap.h>
 #  include <linux/namei.h>
diff --git a/src/cf/osconf.m4 b/src/cf/osconf.m4
index 214dc49b8c..469b92feb6 100644
--- a/src/cf/osconf.m4
+++ b/src/cf/osconf.m4
@@ -69,7 +69,7 @@ case $AFS_SYSNAME in
 		SHLIB_LINKER="${CC} -shared"
 		;;
 
-	arm_linux_24 | arm_linux26)
+	arm_linux_24 | arm_linux26 | arm64_linux26)
 		CCOBJ="\$(CC) -fPIC"
 		MT_CFLAGS='-pthread -D_REENTRANT'
 		PAM_OPTMZ=-O2
diff --git a/src/cf/sysname.m4 b/src/cf/sysname.m4
index c4895a92a1..ff15902dc4 100644
--- a/src/cf/sysname.m4
+++ b/src/cf/sysname.m4
@@ -241,6 +241,9 @@ else
                 arm*-linux*)
                         AFS_SYSNAME="arm_linuxXX"
                         ;;
+                aarch64*-linux*)
+                        AFS_SYSNAME="arm64_linuxXX"
+                        ;;
                 parisc-*-linux-gnu|hppa-*-linux-gnu)
                         AFS_SYSNAME="parisc_linuxXX"
                         enable_pam="no"
diff --git a/src/config/afs_sysnames.h b/src/config/afs_sysnames.h
index be27ae651e..dc9e74aab1 100644
--- a/src/config/afs_sysnames.h
+++ b/src/config/afs_sysnames.h
@@ -385,6 +385,8 @@
 #define SYS_NAME_ID_amd64_obsd53        4022
 #define SYS_NAME_ID_amd64_obsd54        4023
 
+#define SYS_NAME_ID_arm64_linux2	4100
+#define SYS_NAME_ID_arm64_linux26	4103
 
 #define	AFS_REALM_SZ	64
 
diff --git a/src/config/param.arm64_linux26.h b/src/config/param.arm64_linux26.h
new file mode 100644
index 0000000000..02e867a338
--- /dev/null
+++ b/src/config/param.arm64_linux26.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2000, International Business Machines Corporation and others.
+ * All Rights Reserved.
+ *
+ * This software has been released under the terms of the IBM Public
+ * License. For details, see the LICENSE file in the top-level source
+ * directory or online at http://www.openafs.org/dl/license10.html
+ */
+
+#ifndef AFS_PARAM_H
+#define AFS_PARAM_H
+
+#ifndef UKERNEL
+
+/* This section for kernel libafs compiles only */
+#define AFS_ARM64_LINUX26_ENV	1
+#define AFS_LINUX_64BIT_KERNEL	1
+#define AFS_64BITPOINTER_ENV	1	/* pointers are 64 bits */
+#define AFS_64BITUSERPOINTER_ENV	1
+#define AFS_MAXVCOUNT_ENV       1
+
+#else /* !defined(UKERNEL) */
+
+/* This section for user space compiles only */
+#define UKERNEL			1	/* user space kernel */
+
+#endif /* !defined(UKERNEL) */
+
+#ifndef USE_UCONTEXT
+#define USE_UCONTEXT
+#endif
+
+/* Machine / Operating system information */
+#define SYS_NAME		"arm64_linux26"
+#define SYS_NAME_ID		SYS_NAME_ID_arm64_linux26
+#define AFSLITTLE_ENDIAN	1
+
+#endif /* AFS_PARAM_H */
