Module: xenomai-forge
Branch: master
Commit: 345bd643e49430acbd2c45058490f51df4689c03
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=345bd643e49430acbd2c45058490f51df4689c03

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Sun Apr  1 20:20:11 2012 +0200

x86: adapt to refactored timers

---

 include/asm-x86/bits/timer.h |    5 ++
 include/asm-x86/hal_32.h     |   14 ++++
 include/asm-x86/hal_64.h     |   14 ++++
 kernel/cobalt/arch/x86/hal.c |  135 ++++++++++++++++++++++++++++++++++++++++++
 scripts/Kconfig.frag         |    7 +--
 5 files changed, 169 insertions(+), 6 deletions(-)

diff --git a/include/asm-x86/bits/timer.h b/include/asm-x86/bits/timer.h
index 428c069..ec32d65 100644
--- a/include/asm-x86/bits/timer.h
+++ b/include/asm-x86/bits/timer.h
@@ -39,8 +39,13 @@ static inline void xnarch_program_timer_shot(unsigned long 
delay)
 static inline void xnarch_send_timer_ipi(xnarch_cpumask_t mask)
 {
 #ifdef CONFIG_SMP
+#ifndef CONFIG_IPIPE_CORE
        ipipe_send_ipi(RTHAL_APIC_TIMER_IPI, mask);
+#else /* CONFIG_IPIPE_CORE */
+       ipipe_send_ipi(RTHAL_TIMER_IPI, mask);
+#endif /* CONFIG_IPIPE_CORE */
 #endif /* CONFIG_SMP */
+
 }
 
 #endif /* !_XENO_ASM_X86_BITS_TIMER_H */
diff --git a/include/asm-x86/hal_32.h b/include/asm-x86/hal_32.h
index ee9a31d..1b00fcd 100644
--- a/include/asm-x86/hal_32.h
+++ b/include/asm-x86/hal_32.h
@@ -38,11 +38,15 @@
 #define _XENO_ASM_X86_HAL_32_H
 
 #define RTHAL_ARCH_NAME                        "i386"
+#ifndef CONFIG_IPIPE_CORE
 #ifdef CONFIG_X86_LOCAL_APIC
 # define RTHAL_TIMER_DEVICE            "lapic"
 #else
 # define RTHAL_TIMER_DEVICE            "pit"
 #endif
+#else
+# define RTHAL_TIMER_DEVICE            (ipipe_timer_name())
+#endif
 # define RTHAL_CLOCK_DEVICE            "tsc"
 
 #include <asm/xenomai/wrappers.h>
@@ -88,6 +92,7 @@ static inline __attribute_const__ unsigned long ffnz(unsigned 
long ul)
 #include <asm/xenomai/atomic.h>
 #include <asm/xenomai/smi.h>
 
+#ifndef CONFIG_IPIPE_CORE
 #ifdef CONFIG_X86_LOCAL_APIC
 #define RTHAL_APIC_TIMER_VECTOR        IPIPE_HRTIMER_VECTOR
 #define RTHAL_APIC_TIMER_IPI   IPIPE_HRTIMER_IPI
@@ -99,6 +104,11 @@ static inline __attribute_const__ unsigned long 
ffnz(unsigned long ul)
 #define RTHAL_TIMER_IRQ                0       /* i8253 PIT interrupt. */
 #define RTHAL_HOST_TICK_IRQ    0       /* Host tick is emulated by Xenomai. */
 #endif /* CONFIG_X86_LOCAL_APIC */
+#else /* CONFIG_IPIPE_CORE */
+#define RTHAL_TIMER_IRQ                __ipipe_hrtimer_irq
+#define RTHAL_TIMER_IPI                IPIPE_HRTIMER_IPI
+#define RTHAL_HOST_TICK_IRQ    RTHAL_TIMER_IRQ
+#endif /* CONFIG_IPIPE_CORE */
 
 static inline void rthal_grab_control(void)
 {
@@ -120,6 +130,7 @@ static inline unsigned long long rthal_rdtsc(void)
 
 static inline void rthal_timer_program_shot(unsigned long delay)
 {
+#ifndef CONFIG_IPIPE_CORE
 #ifdef CONFIG_X86_LOCAL_APIC
        if (likely(delay))
                apic_write(APIC_TMICT, delay);
@@ -132,6 +143,9 @@ static inline void rthal_timer_program_shot(unsigned long 
delay)
        } else
                ipipe_post_irq_head(RTHAL_TIMER_IRQ);
 #endif /* CONFIG_X86_LOCAL_APIC */
+#else /* I-pipe core */
+       ipipe_timer_set(delay);
+#endif /* I-pipe core */
 }
 
 static const char *const rthal_fault_labels[] = {
diff --git a/include/asm-x86/hal_64.h b/include/asm-x86/hal_64.h
index 1d19840..ad42c12 100644
--- a/include/asm-x86/hal_64.h
+++ b/include/asm-x86/hal_64.h
@@ -24,7 +24,11 @@
 #define _XENO_ASM_X86_HAL_64_H
 
 #define RTHAL_ARCH_NAME                        "x86_64"
+#ifndef CONFIG_IPIPE_CORE
 #define RTHAL_TIMER_DEVICE             "lapic"
+#else /* I-pipe core */
+#define RTHAL_TIMER_DEVICE             (ipipe_timer_name())
+#endif /* I-pipe core */
 #define RTHAL_CLOCK_DEVICE             "tsc"
 
 #include <asm/xenomai/wrappers.h>
@@ -49,12 +53,18 @@ static inline __attribute_const__ unsigned long 
ffnz(unsigned long ul)
 #include <asm/xenomai/atomic.h>
 #include <asm/xenomai/smi.h>
 
+#ifndef CONFIG_IPIPE_CORE
 #define RTHAL_APIC_TIMER_VECTOR                IPIPE_HRTIMER_VECTOR
 #define RTHAL_APIC_TIMER_IPI           IPIPE_HRTIMER_IPI
 #define RTHAL_APIC_ICOUNT              ((RTHAL_TIMER_FREQ + HZ/2)/HZ)
 #define RTHAL_TIMER_IRQ                        RTHAL_APIC_TIMER_IPI
 #define RTHAL_HOST_TICK_IRQ            
ipipe_apic_vector_irq(LOCAL_TIMER_VECTOR)
 #define RTHAL_BCAST_TICK_IRQ           0
+#else /* CONFIG_IPIPE_CORE */
+#define RTHAL_TIMER_IRQ                        __ipipe_hrtimer_irq
+#define RTHAL_TIMER_IPI                        IPIPE_HRTIMER_IPI
+#define RTHAL_HOST_TICK_IRQ            RTHAL_TIMER_IRQ
+#endif /* CONFIG_IPIPE_CORE */
 
 static inline void rthal_grab_control(void)
 {
@@ -76,11 +86,15 @@ static inline unsigned long long rthal_rdtsc(void)
 
 static inline void rthal_timer_program_shot(unsigned long delay)
 {
+#ifndef CONFIG_IPIPE_CORE
        if (likely(delay))
                apic_write(APIC_TMICT, delay);
        else
                /* Pend the timer interrupt. */
                ipipe_post_irq_head(RTHAL_APIC_TIMER_IPI);
+#else
+       ipipe_timer_set(delay);
+#endif
 }
 
 static const char *const rthal_fault_labels[] = {
diff --git a/kernel/cobalt/arch/x86/hal.c b/kernel/cobalt/arch/x86/hal.c
index 2bfa139..5d9d228 100644
--- a/kernel/cobalt/arch/x86/hal.c
+++ b/kernel/cobalt/arch/x86/hal.c
@@ -35,6 +35,8 @@
 
 enum rthal_ktimer_mode rthal_ktimer_saved_mode;
 
+#ifndef CONFIG_IPIPE_CORE
+
 #ifdef CONFIG_X86_LOCAL_APIC
 
 static volatile int sync_op;
@@ -425,4 +427,137 @@ void rthal_arch_cleanup(void)
 {
 }
 
+#else /* I-pipe core */
+
+unsigned long rthal_timer_calibrate(void)
+{
+       unsigned long delay = (RTHAL_TIMER_FREQ + HZ / 2) / HZ;
+       unsigned long flags;
+       rthal_time_t t, dt;
+       int i;
+
+       flags = ipipe_critical_enter(NULL);
+
+       ipipe_timer_set(delay);
+
+       t = rthal_rdtsc();
+
+       for (i = 0; i < 100; i++)
+               ipipe_timer_set(delay);
+
+       dt = rthal_rdtsc() - t;
+
+       ipipe_critical_exit(flags);
+
+       /*
+        * Reset the max trace, since it contains the calibration time
+        * now.
+        */
+       ipipe_trace_max_reset();
+
+       /*
+        * Compute average with a 5% margin to avoid negative
+        * latencies with PIT.
+        */
+       return rthal_ulldiv(dt, i + 5, NULL);
+}
+
+int rthal_timer_request(
+       void (*tick_handler)(void),
+       void (*mode_emul)(enum clock_event_mode mode,
+                         struct clock_event_device *cdev),
+       int (*tick_emul)(unsigned long delay,
+                        struct clock_event_device *cdev),
+       int cpu)
+{
+       int tickval, ret;
+
+       ret = ipipe_timer_start(tick_handler, mode_emul, tick_emul, cpu);
+       switch (ret) {
+       case CLOCK_EVT_MODE_PERIODIC:
+               /* oneshot tick emulation callback won't be used, ask
+                * the caller to start an internal timer for emulating
+                * a periodic tick. */
+               tickval = 1000000000UL / HZ;
+               break;
+
+       case CLOCK_EVT_MODE_ONESHOT:
+               /* oneshot tick emulation */
+               tickval = 1;
+               break;
+
+       case CLOCK_EVT_MODE_UNUSED:
+               /* we don't need to emulate the tick at all. */
+               tickval = 0;
+               break;
+
+       case CLOCK_EVT_MODE_SHUTDOWN:
+               return -ENODEV;
+
+       default:
+               return ret;
+       }
+
+#ifdef CONFIG_SMP
+       if (cpu == 0) {
+               ret = ipipe_request_irq(&rthal_archdata.domain,
+                                       RTHAL_TIMER_IPI,
+                                       (ipipe_irq_handler_t)tick_handler,
+                                       NULL, NULL);
+               if (ret) {
+                       ipipe_timer_stop(cpu);
+                       return ret;
+               }
+       }
+#endif
+
+       rthal_ktimer_saved_mode = ret;
+
+       return tickval;
+}
+
+void rthal_timer_release(int cpu)
+{
+       ipipe_timer_stop(cpu);
+#ifdef CONFIG_SMP
+       if (cpu == 0)
+               ipipe_free_irq(&rthal_archdata.domain, RTHAL_TIMER_IPI);
+#endif /* CONFIG_SMP */
+}
+
+void rthal_timer_notify_switch(enum clock_event_mode mode,
+                              struct clock_event_device *cdev)
+{
+       if (ipipe_processor_id() > 0)
+               /*
+                * We assume all CPUs switch the same way, so we only
+                * track mode switches from the boot CPU.
+                */
+               return;
+
+       rthal_ktimer_saved_mode = mode;
+}
+
+int rthal_arch_init(void)
+{
+       int rc = ipipe_timers_request();
+       if (rc < 0)
+               return rc;
+
+       if (rthal_clockfreq_arg == 0)
+               rthal_clockfreq_arg = rthal_get_clockfreq();
+
+       if (rthal_timerfreq_arg == 0)
+               rthal_timerfreq_arg = rthal_get_timerfreq();
+
+       return 0;
+}
+
+void rthal_arch_cleanup(void)
+{
+       ipipe_timers_release();
+       printk(KERN_INFO "Xenomai: hal/x86 stopped.\n");
+}
+#endif /* I-pipe core */
+
 /*@}*/
diff --git a/scripts/Kconfig.frag b/scripts/Kconfig.frag
index 0841598..b7c425c 100644
--- a/scripts/Kconfig.frag
+++ b/scripts/Kconfig.frag
@@ -1,6 +1,6 @@
 config XENOMAI
        depends on GENERIC_CLOCKEVENTS
-       depends on (X86_TSC || !X86) && (!HPET_TIMER || !X86 || X86_LOCAL_APIC)
+       depends on X86_TSC || !X86
        bool "Xenomai"
        select IPIPE
        default y
@@ -23,8 +23,3 @@ endif
 if !GENERIC_CLOCKEVENTS
 comment "NOTE: Xenomai needs CONFIG_GENERIC_CLOCKEVENTS"
 endif
-
-comment "NOTE: Xenomai needs either X86_LOCAL_APIC enabled or HPET_TIMER 
disabled."
-       depends on !X86_LOCAL_APIC && X86 && HPET_TIMER
-comment "(menu Processor type and features)"
-       depends on !X86_LOCAL_APIC && X86 && HPET_TIMER


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to