base/include/asm-m68knommu/rtai_lxrt.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 1999-2003 Paolo Mantegazza <mantegazza@aero.polimi.it>
00003  * extensions for user space modules are jointly copyrighted (2000) with:
00004  *      Pierre Cloutier <pcloutier@poseidoncontrols.com>,
00005  *      Steve Papacharalambous <stevep@zentropix.com>.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
00019  */
00020 
00021 #ifndef _RTAI_ASM_M68KNOMMU_LXRT_H
00022 #define _RTAI_ASM_M68KNOMMU_LXRT_H
00023 
00024 #include <linux/version.h>
00025 
00026 #include <asm/rtai_vectors.h>
00027 
00028 #ifdef CONFIG_RTAI_LXRT_USE_LINUX_SYSCALL
00029 #define USE_LINUX_SYSCALL
00030 #else
00031 #undef USE_LINUX_SYSCALL
00032 #endif
00033 
00034 #define RTAI_SYSCALL_NR      0x70000000
00035 #define RTAI_SYSCALL_CODE    d0 //From RTAI_DO_TRAP_SYS
00036 #define RTAI_SYSCALL_ARGS    d1 //From RTAI_DO_TRAP_SYS
00037 #define RTAI_SYSCALL_RETPNT  d2
00038 
00039 #define LINUX_SYSCALL_NR      orig_d0
00040 #define LINUX_SYSCALL_REG1    d1
00041 #define LINUX_SYSCALL_REG2    d2
00042 #define LINUX_SYSCALL_REG3    d3
00043 #define LINUX_SYSCALL_REG4    d4
00044 #define LINUX_SYSCALL_REG5    d5
00045 #define LINUX_SYSCALL_REG6    a0
00046 #define LINUX_SYSCALL_RETREG  d0
00047 #define LINUX_SYSCALL_FLAGS   sr
00048 
00049 #define LXRT_DO_IMMEDIATE_LINUX_SYSCALL(regs) \
00050     do { \
00051         regs->LINUX_SYSCALL_RETREG = sys_call_table[regs->LINUX_SYSCALL_NR](*regs); \
00052     } while (0)
00053 
00054 #define SET_LXRT_RETVAL_IN_SYSCALL(regs, retval) \
00055     do { \
00056 /*                if (regs->RTAI_SYSCALL_RETPNT) { \
00057             rt_copy_to_user((void *)regs->RTAI_SYSCALL_RETPNT, &retval, sizeof(retval)); \
00058         } */\
00059     } while (0)
00060 
00061 #define LOW  0
00062 #define HIGH 1
00063 
00064 #if defined(CONFIG_RTAI_RTC_FREQ) && CONFIG_RTAI_RTC_FREQ >= 2
00065 
00066 #define TIMER_NAME        "RTC"
00067 #define TIMER_FREQ        CONFIG_RTAI_RTC_FREQ
00068 #define TIMER_LATENCY     0
00069 #define TIMER_SETUP_TIME  0
00070 #define ONESHOT_SPAN      0
00071 
00072 #else /* CONFIG_RTAI_RTC_FREQ == 0 */
00073 
00074 #define USE_LINUX_TIMER
00075 #define TIMER_NAME        "COLDFIRE TIMER"
00076 #define TIMER_TYPE  0
00077 #define HRT_LINUX_TIMER_NAME  "pit"
00078 #define TIMER_FREQ        RTAI_FREQ_8254
00079 #define TIMER_LATENCY     RTAI_LATENCY_8254
00080 #define TIMER_SETUP_TIME  RTAI_SETUP_TIME_8254
00081 #define ONESHOT_SPAN      (CPU_FREQ/(CONFIG_RTAI_CAL_FREQS_FACT + 2)) //(0x7FFFFFFFLL*(CPU_FREQ/TIMER_FREQ))
00082 #define update_linux_timer(cpuid) \
00083 do { \
00084     if (!IS_FUSION_TIMER_RUNNING()) { \
00085         hal_pend_uncond(RTAI_TIMER_LINUX_IRQ, cpuid); \
00086     } \
00087 } while (0)
00088 
00089 #endif /* CONFIG_RTAI_RTC_FREQ != 0 */
00090 
00091 union rtai_lxrt_t {
00092     RTIME rt;
00093     int i[2];
00094     void *v[2];
00095 };
00096 
00097 #ifdef __cplusplus
00098 extern "C" {
00099 #endif /* __cplusplus */
00100 
00101 #ifdef __KERNEL__
00102 
00103 #include <asm/segment.h>
00104 #include <asm/mmu_context.h>
00105 
00106 #define __LXRT_GET_DATASEG(reg) "movel $" STR(__USER_DS) ",%" #reg "\n\t"
00107 
00108 static inline void _lxrt_context_switch (struct task_struct *prev, struct task_struct *next, int cpuid)
00109 {
00110     extern void context_switch(void *, void *, void *);
00111 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,19)
00112     prev->fpu_counter = 0;
00113 #endif
00114     context_switch(0, prev, next);
00115 }
00116 
00117 #if 0
00118 #define IN_INTERCEPT_IRQ_ENABLE()   do { rtai_hw_sti(); } while (0)
00119 #define IN_INTERCEPT_IRQ_DISABLE()  do { rtai_hw_cli(); } while (0)
00120 #else
00121 #define IN_INTERCEPT_IRQ_ENABLE()   do { } while (0)
00122 #define IN_INTERCEPT_IRQ_DISABLE()  do { } while (0)
00123 #endif
00124 
00125 #include <linux/slab.h>
00126 
00127 #define REG_SP ksp
00128 #if 1 // optimised (?)
00129 static inline void kthread_fun_set_jump(struct task_struct *lnxtsk)
00130 {
00131     lnxtsk->rtai_tskext(TSKEXT2) = kmalloc(sizeof(struct thread_struct)/* + sizeof(struct thread_info)*/ + (lnxtsk->thread.REG_SP & ~(THREAD_SIZE - 1)) + THREAD_SIZE - lnxtsk->thread.REG_SP, GFP_KERNEL);
00132     *((struct thread_struct *)lnxtsk->rtai_tskext(TSKEXT2)) = lnxtsk->thread;
00133 //  memcpy(lnxtsk->rtai_tskext(TSKEXT2) + sizeof(struct thread_struct), (void *)(lnxtsk->thread.REG_SP & ~(THREAD_SIZE - 1)), sizeof(struct thread_info));
00134     memcpy(lnxtsk->rtai_tskext(TSKEXT2) + sizeof(struct thread_struct)/* + sizeof(struct thread_info)*/, (void *)(lnxtsk->thread.REG_SP), (lnxtsk->thread.REG_SP & ~(THREAD_SIZE - 1)) + THREAD_SIZE - lnxtsk->thread.REG_SP);
00135 }
00136 
00137 static inline void kthread_fun_long_jump(struct task_struct *lnxtsk)
00138 {
00139     lnxtsk->thread = *((struct thread_struct *)lnxtsk->rtai_tskext(TSKEXT2));
00140 //  memcpy((void *)(lnxtsk->thread.REG_SP & ~(THREAD_SIZE - 1)), lnxtsk->rtai_tskext(TSKEXT2) + sizeof(struct thread_struct), sizeof(struct thread_info));
00141     memcpy((void *)lnxtsk->thread.REG_SP, lnxtsk->rtai_tskext(TSKEXT2) + sizeof(struct thread_struct)/* + sizeof(struct thread_info)*/, (lnxtsk->thread.REG_SP & ~(THREAD_SIZE - 1)) + THREAD_SIZE - lnxtsk->thread.REG_SP);
00142 }
00143 #else  // brute force
00144 static inline void kthread_fun_set_jump(struct task_struct *lnxtsk)
00145 {
00146     lnxtsk->rtai_tskext(TSKEXT2) = kmalloc(sizeof(struct thread_struct) + THREAD_SIZE, GFP_KERNEL);
00147     *((struct thread_struct *)lnxtsk->rtai_tskext(TSKEXT2)) = lnxtsk->thread;
00148     memcpy(lnxtsk->rtai_tskext(TSKEXT2) + sizeof(struct thread_struct), (void *)(lnxtsk->thread.REG_SP & ~(THREAD_SIZE - 1)), THREAD_SIZE);
00149 }
00150 
00151 static inline void kthread_fun_long_jump(struct task_struct *lnxtsk)
00152 {
00153     lnxtsk->thread = *((struct thread_struct *)lnxtsk->rtai_tskext(TSKEXT2));
00154     memcpy((void *)(lnxtsk->thread.REG_SP & ~(THREAD_SIZE - 1)), lnxtsk->rtai_tskext(TSKEXT2) + sizeof(struct thread_struct), THREAD_SIZE);
00155 }
00156 #endif
00157 
00158 #define rt_copy_from_user(a, b, c)  \
00159     ( { int ret = __copy_from_user_inatomic(a, b, c); ret; } )
00160 #define rt_copy_to_user(a, b, c)  \
00161     ( { int ret = __copy_to_user_inatomic(a, b, c); ret; } )
00162 #define rt_strncpy_from_user(a, b, c)  \
00163     ( { int ret = strncpy_from_user(a, b, c); ret; } )
00164 #define rt_put_user  __put_user
00165 #define rt_get_user  __get_user
00166 
00167 //FIXME: Shit may happen here
00168 /*__attribute__((regparm(3)))*/
00169 #define do_notify_resume(regs, _unused, thread_info_flags) \
00170 { \
00171     rt_printk("RTAI-do_notify_resume: Shit!!! \n"); \
00172 }
00173 #define RT_DO_SIGNAL(regs)  do_notify_resume(regs, NULL, (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK));
00174 
00175 #else /* !__KERNEL__ */
00176 
00177 /* NOTE: Keep the following routines unfold: this is a compiler
00178    compatibility issue. */
00179 
00180 #include <sys/syscall.h>
00181 #include <unistd.h>
00182 
00183 #define CLOCK_MONOTONIC 1
00184 #define PTHREAD_STACK_MIN 16384
00185 
00186 #define mlockall(asd) do {} while (0)
00187 
00188 static union rtai_lxrt_t _rtai_lxrt(int srq, void *arg)
00189 {
00190     union rtai_lxrt_t retval;
00191 #ifdef USE_LINUX_SYSCALL
00192     syscall(RTAI_SYSCALL_NR, srq, arg, &retval);
00193 #else 
00194     RTAI_DO_TRAP_SYS(&retval.rt, srq, (unsigned long)arg);
00195 #endif
00196     return retval;
00197 }
00198 
00199 static inline union rtai_lxrt_t rtai_lxrt(short int dynx, short int lsize, int srq, void *arg)
00200 {
00201     return _rtai_lxrt(ENCODE_LXRT_REQ(dynx, srq, lsize), arg);
00202 }
00203 
00204 #define rtai_iopl()  do { extern int iopl(int);/* iopl(3); */ } while (0)
00205 
00206 #endif /* __KERNEL__ */
00207 
00208 #ifdef __cplusplus
00209 }
00210 #endif /* __cplusplus */
00211 
00212 #endif /* !_RTAI_ASM_M68KNOMMU_LXRT_H */

Generated on Tue Feb 2 17:46:04 2010 for RTAI API by  doxygen 1.4.7