Skip to contentSkip to conversation

refactor x86/hal_*.c

RFC PATCH New Jan Kiszka 1 participant 1 message Nov 1, 2007

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

RFC PATCH 1/1 refactor x86/hal_*.c

This is the kind of patch I've warned about regarding this late -rc state... :->

It refactores most code from arch/x86/hal_*.c into hal-shared.c, overall killing more than 200 lines of code. It's compile- and run-tested on both i386 and x86_64 from 2.6.20 up to 2.6.24-rc1 (x86_64 only on 2.6.23 and 2.6.24). Still, the patch may contain copy&paste regressions or some remaining ugliness, so it is RFC and not a must for the release.

Jan

---
 include/asm-x86/hal.h         |   14 +
 include/asm-x86/hal_32.h      |   39 ++++
 include/asm-x86/hal_64.h      |   20 ++
 include/asm-x86/wrappers_64.h |    3 
 ksrc/arch/x86/Makefile        |    4 
 ksrc/arch/x86/hal-shared.c    |  371 +++++++++++++++++++++++++++++++++++++++++
 ksrc/arch/x86/hal_32.c        |  375 ------------------------------------------
 ksrc/arch/x86/hal_64.c        |  313 -----------------------------------
 8 files changed, 450 insertions(+), 689 deletions(-)
include/asm-x86/hal.h +14 -0
Index: xenomai/include/asm-x86/hal.h
===================================================================
@@ -1,5 +1,19 @@
+#ifndef _XENO_ASM_X86_HAL_H
+#define _XENO_ASM_X86_HAL_H
+
+enum rthal_ktimer_mode { /* <!> Must follow enum clock_event_mode */
+	KTIMER_MODE_UNUSED = 0,
+	KTIMER_MODE_SHUTDOWN,
+	KTIMER_MODE_PERIODIC,
+	KTIMER_MODE_ONESHOT,
+};
+
+extern enum rthal_ktimer_mode rthal_ktimer_saved_mode;
+
 #ifdef __i386__
 #include "hal_32.h"
 #else
 #include "hal_64.h"
 #endif
+
+#endif /* !_XENO_ASM_X86_HAL_H */
include/asm-x86/hal_32.h +37 -2
Index: xenomai/include/asm-x86/hal_32.h
===================================================================
@@ -36,7 +36,8 @@
 
 #ifndef _XENO_ASM_X86_HAL_32_H
 #define _XENO_ASM_X86_HAL_32_H
-#define _XENO_ASM_X86_HAL_H
+
+#define RTHAL_ARCH_NAME			"i386"
 
 #include <asm/xenomai/wrappers.h>
 
@@ -175,8 +176,42 @@ static const char *const rthal_fault_lab
 	[20] = NULL,
 };
 
-long rthal_strncpy_from_user(char *dst, const char __user * src, long count);
+#ifdef CONFIG_X86_LOCAL_APIC
+
+#include <asm/fixmap.h>
+#include <asm/mpspec.h>
+#ifdef CONFIG_X86_IO_APIC
+#include <asm/io_apic.h>
+#endif /* CONFIG_X86_IO_APIC */
+#include <asm/apic.h>
+
+static inline int rthal_set_apic_base(int lvtt_value)
+{
+	if (APIC_INTEGRATED(GET_APIC_VERSION(apic_read(APIC_LVR))))
+		lvtt_value |= SET_APIC_TIMER_BASE(APIC_TIMER_BASE_DIV);
+
+	return lvtt_value;
+}
+
+static inline void rthal_setup_periodic_apic(int count, int vector)
+{
+	apic_read_around(APIC_LVTT);
+	apic_write_around(APIC_LVTT, rthal_set_apic_base(APIC_LVT_TIMER_PERIODIC | vector));
+	apic_read_around(APIC_TMICT);
+	apic_write_around(APIC_TMICT, count);
+}
+
+static inline void rthal_setup_oneshot_apic(int vector)
+{
+	apic_read_around(APIC_LVTT);
+	apic_write_around(APIC_LVTT, rthal_set_apic_base(vector));
+}
+#endif /* !CONFIG_X86_LOCAL_APIC */
 
 #endif /* !__cplusplus */
 
+long rthal_strncpy_from_user(char *dst, const char __user * src, long count);
+
+void rthal_latency_above_max(struct pt_regs *regs);
+
 #endif /* !_XENO_ASM_X86_HAL_32_H */
include/asm-x86/hal_64.h +19 -1
Index: xenomai/include/asm-x86/hal_64.h
===================================================================
@@ -22,7 +22,8 @@
 
 #ifndef _XENO_ASM_X86_HAL_64_H
 #define _XENO_ASM_X86_HAL_64_H
-#define _XENO_ASM_X86_HAL_H
+
+#define RTHAL_ARCH_NAME			"x86_64"
 
 #include <asm/xenomai/wrappers.h>
 #include <asm-generic/xenomai/hal.h>    /* Read the generic bits. */
@@ -116,6 +117,23 @@ static const char *const rthal_fault_lab
     [20] = NULL,
 };
 
+#ifdef CONFIG_X86_LOCAL_APIC
+
+#include <asm/mach_apic.h>
+
+static inline void rthal_setup_periodic_apic(int count, int vector)
+{
+	apic_write(APIC_LVTT, APIC_LVT_TIMER_PERIODIC | vector);
+	apic_write(APIC_TMICT, count);
+}
+
+static inline void rthal_setup_oneshot_apic(int vector)
+{
+	apic_write(APIC_LVTT, vector);
+}
+
+#endif /* !CONFIG_X86_LOCAL_APIC */
+
 #endif /* !__cplusplus */
 
 long rthal_strncpy_from_user(char *dst,
ksrc/arch/x86/Makefile +2 -2
Index: xenomai/ksrc/arch/x86/Makefile
===================================================================
@@ -10,7 +10,7 @@ endif
 
 obj-$(CONFIG_XENOMAI) += xeno_hal.o
 
-xeno_hal-y := hal_$(X86_MODE).o usercopy_$(X86_MODE).o
+xeno_hal-y := hal_$(X86_MODE).o hal-shared.o usercopy_$(X86_MODE).o
 
 xeno_hal-$(CONFIG_XENO_HW_NMI_DEBUG_LATENCY) += nmi_$(X86_MODE).o
 
@@ -26,7 +26,7 @@ USE_STANDARD_AS_RULE := true
 
 O_TARGET := built-in.o
 
-obj-y := hal_32.o
+obj-y := hal_32.o hal-shared.o
 
 obj-$(CONFIG_XENO_HW_NMI_DEBUG_LATENCY) += nmi_32.o
 
ksrc/arch/x86/hal-shared.c new file +371 -0

371 lines not on this page · raw message

ksrc/arch/x86/hal_32.c +4 -371

425 lines not on this page · raw message

ksrc/arch/x86/hal_64.c +0 -313

328 lines not on this page · raw message

include/asm-x86/wrappers_64.h +3 -0
Index: xenomai/include/asm-x86/wrappers_64.h
===================================================================
@@ -37,4 +37,7 @@
 
 typedef irq_handler_t rthal_irq_host_handler_t;
 
+#define DECLARE_LINUX_IRQ_HANDLER(fn, irq, dev_id)	\
+	irqreturn_t fn(int irq, void *dev_id)
+
 #endif /* _XENO_ASM_X86_WRAPPERS_64_H */