OpenSDE Packages Database (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

982 lines
29 KiB

  1. diff -Naur linux-2.4.20/Documentation/Configure.help linux-2.4.20-rtai/Documentation/Configure.help
  2. --- linux-2.4.20/Documentation/Configure.help Fri Nov 29 19:01:31 2002
  3. +++ linux-2.4.20-rtai/Documentation/Configure.help Mon Dec 2 16:11:55 2002
  4. @@ -254,6 +254,13 @@
  5. You will need a new lynxer.elf file to flash your firmware with - send
  6. email to Martin.Bligh@us.ibm.com
  7. +Real-Time Harware Abstraction
  8. +CONFIG_RTHAL
  9. + The Real-Time Hardware Abstraction Layer (RTHAL) is used by
  10. + the Real-Time Application Interface (RTAI) to provide a
  11. + hard real-time environment as part of Linux. This feature
  12. + cannot be turned off, so say Y.
  13. +
  14. Support for IBM Summit (EXA) systems
  15. CONFIG_X86_SUMMIT
  16. This option is needed for IBM systems that use the Summit/EXA chipset.
  17. diff -Naur linux-2.4.20/arch/i386/config.in linux-2.4.20-rtai/arch/i386/config.in
  18. --- linux-2.4.20/arch/i386/config.in Fri Nov 29 19:01:34 2002
  19. +++ linux-2.4.20-rtai/arch/i386/config.in Mon Dec 2 16:11:55 2002
  20. @@ -256,6 +256,8 @@
  21. if [ "$CONFIG_SMP" = "y" -a "$CONFIG_X86_CMPXCHG" = "y" ]; then
  22. define_bool CONFIG_HAVE_DEC_LOCK y
  23. fi
  24. +comment 'CONFIG_RTHAL must be yes'
  25. +bool 'Real-Time Hardware Abstraction Layer' CONFIG_RTHAL
  26. endmenu
  27. mainmenu_option next_comment
  28. diff -Naur linux-2.4.20/arch/i386/defconfig linux-2.4.20-rtai/arch/i386/defconfig
  29. --- linux-2.4.20/arch/i386/defconfig Fri Nov 29 19:01:34 2002
  30. +++ linux-2.4.20-rtai/arch/i386/defconfig Mon Dec 2 16:11:55 2002
  31. @@ -66,6 +66,7 @@
  32. # CONFIG_MULTIQUAD is not set
  33. CONFIG_HAVE_DEC_LOCK=y
  34. CONFIG_NR_CPUS=32
  35. +CONFIG_RTHAL=y
  36. #
  37. # General setup
  38. diff -Naur linux-2.4.20/arch/i386/kernel/entry.S linux-2.4.20-rtai/arch/i386/kernel/entry.S
  39. --- linux-2.4.20/arch/i386/kernel/entry.S Fri Nov 29 19:01:34 2002
  40. +++ linux-2.4.20-rtai/arch/i386/kernel/entry.S Mon Dec 2 16:11:55 2002
  41. @@ -184,6 +184,7 @@
  42. ENTRY(ret_from_fork)
  43. + sti
  44. pushl %ebx
  45. call SYMBOL_NAME(schedule_tail)
  46. addl $4, %esp
  47. @@ -210,17 +211,20 @@
  48. call *SYMBOL_NAME(sys_call_table)(,%eax,4)
  49. movl %eax,EAX(%esp) # save the return value
  50. ENTRY(ret_from_sys_call)
  51. - cli # need_resched and signals atomic test
  52. + call *(SYMBOL_NAME(rthal) + 12) # cli
  53. cmpl $0,need_resched(%ebx)
  54. jne reschedule
  55. cmpl $0,sigpending(%ebx)
  56. jne signal_return
  57. + sti
  58. + call *(SYMBOL_NAME(rthal) + 16) # sti
  59. restore_all:
  60. RESTORE_ALL
  61. ALIGN
  62. signal_return:
  63. - sti # we can get here from an interrupt handler
  64. + sti # we can get here from an interrupt handler
  65. + call *(SYMBOL_NAME(rthal) + 16) # sti
  66. testl $(VM_MASK),EFLAGS(%esp)
  67. movl %esp,%eax
  68. jne v86_signal_return
  69. diff -Naur linux-2.4.20/arch/i386/kernel/i386_ksyms.c linux-2.4.20-rtai/arch/i386/kernel/i386_ksyms.c
  70. --- linux-2.4.20/arch/i386/kernel/i386_ksyms.c Sat Aug 3 02:39:42 2002
  71. +++ linux-2.4.20-rtai/arch/i386/kernel/i386_ksyms.c Mon Dec 2 16:11:55 2002
  72. @@ -32,6 +32,18 @@
  73. extern void dump_thread(struct pt_regs *, struct user *);
  74. extern spinlock_t rtc_lock;
  75. +EXPORT_SYMBOL_NOVERS(rthal);
  76. +
  77. +#ifdef CONFIG_VT
  78. + #include <linux/vt_kern.h>
  79. + EXPORT_SYMBOL(kd_mksound);
  80. +#endif
  81. +
  82. +#include <linux/console.h>
  83. +EXPORT_SYMBOL(console_drivers);
  84. +extern unsigned long cpu_khz;
  85. +EXPORT_SYMBOL(cpu_khz);
  86. +
  87. #if defined(CONFIG_APM) || defined(CONFIG_APM_MODULE)
  88. extern void machine_real_restart(unsigned char *, int);
  89. EXPORT_SYMBOL(machine_real_restart);
  90. @@ -172,6 +184,13 @@
  91. #ifdef CONFIG_HAVE_DEC_LOCK
  92. EXPORT_SYMBOL(atomic_dec_and_lock);
  93. +#endif
  94. +
  95. +#ifdef CONFIG_X86_REMOTE_DEBUG
  96. +#include <linux/gdb.h>
  97. +EXPORT_SYMBOL(linux_debug_hook);
  98. +EXPORT_SYMBOL(gdb_irq);
  99. +EXPORT_SYMBOL(gdb_interrupt);
  100. #endif
  101. extern int is_sony_vaio_laptop;
  102. diff -Naur linux-2.4.20/arch/i386/kernel/i8259.c linux-2.4.20-rtai/arch/i386/kernel/i8259.c
  103. --- linux-2.4.20/arch/i386/kernel/i8259.c Tue Sep 18 08:03:09 2001
  104. +++ linux-2.4.20-rtai/arch/i386/kernel/i8259.c Mon Dec 2 16:11:55 2002
  105. @@ -290,12 +290,12 @@
  106. handle_real_irq:
  107. if (irq & 8) {
  108. - inb(0xA1); /* DUMMY - (do we need this?) */
  109. +// inb(0xA1); /* DUMMY - (do we need this?) */
  110. outb(cached_A1,0xA1);
  111. outb(0x60+(irq&7),0xA0);/* 'Specific EOI' to slave */
  112. outb(0x62,0x20); /* 'Specific EOI' to master-IRQ2 */
  113. } else {
  114. - inb(0x21); /* DUMMY - (do we need this?) */
  115. +// inb(0x21); /* DUMMY - (do we need this?) */
  116. outb(cached_21,0x21);
  117. outb(0x60+irq,0x20); /* 'Specific EOI' to master */
  118. }
  119. @@ -508,3 +508,17 @@
  120. if (boot_cpu_data.hard_math && !cpu_has_fpu)
  121. setup_irq(13, &irq13);
  122. }
  123. +
  124. +void ack_8259_irq(unsigned int irq)
  125. +{
  126. + spin_lock(&i8259A_lock);
  127. + if (irq & 8) {
  128. + outb(0x62,0x20);
  129. + outb(0x20,0xA0);
  130. + } else {
  131. + outb(0x20,0x20);
  132. + }
  133. + spin_unlock(&i8259A_lock);
  134. + return;
  135. +}
  136. +
  137. diff -Naur linux-2.4.20/arch/i386/kernel/io_apic.c linux-2.4.20-rtai/arch/i386/kernel/io_apic.c
  138. --- linux-2.4.20/arch/i386/kernel/io_apic.c Fri Nov 29 19:01:34 2002
  139. +++ linux-2.4.20-rtai/arch/i386/kernel/io_apic.c Mon Dec 2 16:11:55 2002
  140. @@ -38,7 +38,7 @@
  141. #undef APIC_LOCKUP_DEBUG
  142. -#define APIC_LOCKUP_DEBUG
  143. +//#define APIC_LOCKUP_DEBUG
  144. static spinlock_t ioapic_lock = SPIN_LOCK_UNLOCKED;
  145. @@ -1282,11 +1282,10 @@
  146. #define enable_level_ioapic_irq unmask_IO_APIC_irq
  147. #define disable_level_ioapic_irq mask_IO_APIC_irq
  148. +static unsigned long strange_level;
  149. +
  150. static void end_level_ioapic_irq (unsigned int irq)
  151. {
  152. - unsigned long v;
  153. - int i;
  154. -
  155. /*
  156. * It appears there is an erratum which affects at least version 0x11
  157. * of I/O APIC (that's the 82093AA and cores integrated into various
  158. @@ -1306,12 +1305,8 @@
  159. * operation to prevent an edge-triggered interrupt escaping meanwhile.
  160. * The idea is from Manfred Spraul. --macro
  161. */
  162. - i = IO_APIC_VECTOR(irq);
  163. - v = apic_read(APIC_TMR + ((i & ~0x1f) >> 1));
  164. -
  165. - ack_APIC_irq();
  166. - if (!(v & (1 << (i & 0x1f)))) {
  167. + if (test_and_clear_bit(irq, &strange_level)) {
  168. #ifdef APIC_LOCKUP_DEBUG
  169. struct irq_pin_list *entry;
  170. #endif
  171. @@ -1320,7 +1315,6 @@
  172. atomic_inc(&irq_mis_count);
  173. #endif
  174. spin_lock(&ioapic_lock);
  175. - __mask_and_edge_IO_APIC_irq(irq);
  176. #ifdef APIC_LOCKUP_DEBUG
  177. for (entry = irq_2_pin + irq;;) {
  178. unsigned int reg;
  179. @@ -1338,10 +1332,30 @@
  180. #endif
  181. __unmask_and_level_IO_APIC_irq(irq);
  182. spin_unlock(&ioapic_lock);
  183. + } else {
  184. + spin_lock(&ioapic_lock);
  185. + __unmask_IO_APIC_irq(irq);
  186. + spin_unlock(&ioapic_lock);
  187. }
  188. }
  189. -static void mask_and_ack_level_ioapic_irq (unsigned int irq) { /* nothing */ }
  190. +static void mask_and_ack_level_ioapic_irq (unsigned int irq)
  191. +{
  192. + unsigned long i;
  193. +
  194. + i = IO_APIC_VECTOR(irq);
  195. + if (!(apic_read(APIC_TMR + ((i & ~0x1f) >> 1)) & (1 << (i & 0x1f)))) {
  196. + test_and_set_bit(irq, &strange_level);
  197. + spin_lock(&ioapic_lock);
  198. + __mask_and_edge_IO_APIC_irq(irq);
  199. + spin_unlock(&ioapic_lock);
  200. + } else {
  201. + spin_lock(&ioapic_lock);
  202. + __mask_IO_APIC_irq(irq);
  203. + spin_unlock(&ioapic_lock);
  204. + }
  205. + ack_APIC_irq();
  206. +}
  207. #ifndef CONFIG_SMP
  208. diff -Naur linux-2.4.20/arch/i386/kernel/irq.c linux-2.4.20-rtai/arch/i386/kernel/irq.c
  209. --- linux-2.4.20/arch/i386/kernel/irq.c Fri Nov 29 19:01:34 2002
  210. +++ linux-2.4.20-rtai/arch/i386/kernel/irq.c Mon Dec 2 16:11:55 2002
  211. @@ -1212,3 +1212,71 @@
  212. register_irq_proc(i);
  213. }
  214. +static void linux_cli(void)
  215. +{
  216. + hard_cli();
  217. +}
  218. +
  219. +static void linux_sti(void)
  220. +{
  221. + hard_sti();
  222. +}
  223. +
  224. +static unsigned int linux_save_flags(void)
  225. +{
  226. + int flags;
  227. + hard_save_flags(flags);
  228. + return flags;
  229. +}
  230. +
  231. +static void linux_restore_flags(unsigned int flags)
  232. +{
  233. + hard_restore_flags(flags);
  234. +}
  235. +
  236. +static unsigned int linux_save_flags_and_cli(void)
  237. +{
  238. + int flags;
  239. + hard_save_flags_and_cli(flags);
  240. + return flags;
  241. +}
  242. +
  243. +#include <asm/mmu_context.h>
  244. +
  245. +#ifndef CONFIG_X86_IO_APIC
  246. +int irq_vector[];
  247. +#endif
  248. +#ifndef CONFIG_SMP
  249. +void smp_invalidate_interrupt(void) { }
  250. +static unsigned long irq_affinity [NR_IRQS] = { [0 ... NR_IRQS-1] = ~0UL };
  251. +static volatile int physical_apicid_2_cpu[1];
  252. +#endif
  253. +
  254. +extern void *ret_from_intr;
  255. +extern struct desc_struct idt_table[];
  256. +extern void ack_8259_irq(unsigned int);
  257. +extern int idle_weight;
  258. +extern void smp_invalidate_interrupt(void);
  259. +extern void switch_mem(struct task_struct *, struct task_struct *, int);
  260. +extern volatile int physical_apicid_2_cpu[];
  261. +
  262. +struct rt_hal rthal = {
  263. + ret_from_intr: &ret_from_intr,
  264. + __switch_to: __switch_to,
  265. + idt_table: idt_table,
  266. + disint: linux_cli,
  267. + enint: linux_sti,
  268. + getflags: linux_save_flags,
  269. + setflags: linux_restore_flags,
  270. + getflags_and_cli: linux_save_flags_and_cli,
  271. + irq_desc: irq_desc,
  272. + irq_vector: irq_vector,
  273. + irq_affinity: irq_affinity,
  274. + smp_invalidate_interrupt: smp_invalidate_interrupt,
  275. + ack_8259_irq: ack_8259_irq,
  276. + idle_weight: &idle_weight,
  277. + lxrt_global_cli: NULL,
  278. + switch_mem: switch_mem,
  279. + init_tasks: init_tasks,
  280. + apicmap: physical_apicid_2_cpu,
  281. +};
  282. diff -Naur linux-2.4.20/arch/i386/kernel/smp.c linux-2.4.20-rtai/arch/i386/kernel/smp.c
  283. --- linux-2.4.20/arch/i386/kernel/smp.c Fri Nov 29 19:01:34 2002
  284. +++ linux-2.4.20-rtai/arch/i386/kernel/smp.c Mon Dec 2 16:11:55 2002
  285. @@ -160,8 +160,7 @@
  286. unsigned long cfg;
  287. unsigned long flags;
  288. - __save_flags(flags);
  289. - __cli();
  290. + hard_save_flags_and_cli(flags);
  291. /*
  292. @@ -185,7 +184,7 @@
  293. */
  294. apic_write_around(APIC_ICR, cfg);
  295. - __restore_flags(flags);
  296. + hard_restore_flags(flags);
  297. }
  298. static inline void send_IPI_mask_sequence(int mask, int vector)
  299. diff -Naur linux-2.4.20/arch/i386/kernel/time.c linux-2.4.20-rtai/arch/i386/kernel/time.c
  300. --- linux-2.4.20/arch/i386/kernel/time.c Fri Nov 29 19:01:34 2002
  301. +++ linux-2.4.20-rtai/arch/i386/kernel/time.c Mon Dec 2 16:11:55 2002
  302. @@ -673,6 +673,7 @@
  303. rdtscl(last_tsc_low);
  304. +#if 0
  305. spin_lock(&i8253_lock);
  306. outb_p(0x00, 0x43); /* latch the count ASAP */
  307. @@ -704,6 +705,7 @@
  308. count = ((LATCH-1) - count) * TICK_SIZE;
  309. delay_at_last_interrupt = (count + LATCH/2) / LATCH;
  310. +#endif
  311. }
  312. do_timer_interrupt(irq, NULL, regs);
  313. diff -Naur linux-2.4.20/arch/i386/mm/fault.c linux-2.4.20-rtai/arch/i386/mm/fault.c
  314. --- linux-2.4.20/arch/i386/mm/fault.c Fri Nov 29 19:01:34 2002
  315. +++ linux-2.4.20-rtai/arch/i386/mm/fault.c Mon Dec 2 16:11:55 2002
  316. @@ -153,7 +153,7 @@
  317. /* It's safe to allow irq's after cr2 has been saved */
  318. if (regs->eflags & X86_EFLAGS_IF)
  319. - local_irq_enable();
  320. + hard_sti();
  321. tsk = current;
  322. diff -Naur linux-2.4.20/arch/i386/mm/ioremap.c linux-2.4.20-rtai/arch/i386/mm/ioremap.c
  323. --- linux-2.4.20/arch/i386/mm/ioremap.c Sat Aug 3 02:39:42 2002
  324. +++ linux-2.4.20-rtai/arch/i386/mm/ioremap.c Mon Dec 2 16:11:55 2002
  325. @@ -81,6 +81,7 @@
  326. if (remap_area_pmd(pmd, address, end - address,
  327. phys_addr + address, flags))
  328. break;
  329. + set_pgdir(address, *dir);
  330. error = 0;
  331. address = (address + PGDIR_SIZE) & PGDIR_MASK;
  332. dir++;
  333. diff -Naur linux-2.4.20/arch/ppc/config.in linux-2.4.20-rtai/arch/ppc/config.in
  334. --- linux-2.4.20/arch/ppc/config.in Fri Nov 29 19:01:45 2002
  335. +++ linux-2.4.20-rtai/arch/ppc/config.in Mon Dec 2 16:11:55 2002
  336. @@ -125,6 +125,9 @@
  337. bool ' Distribute interrupts on all CPUs by default' CONFIG_IRQ_ALL_CPUS
  338. fi
  339. +#bool 'Real-Time Hardware Abstraction Layer' CONFIG_RTHAL
  340. +define_bool CONFIG_RTHAL y
  341. +
  342. if [ "$CONFIG_6xx" = "y" -a "$CONFIG_8260" = "n" ];then
  343. bool 'AltiVec Support' CONFIG_ALTIVEC
  344. bool 'Thermal Management Support' CONFIG_TAU
  345. diff -Naur linux-2.4.20/arch/ppc/kernel/entry.S linux-2.4.20-rtai/arch/ppc/kernel/entry.S
  346. --- linux-2.4.20/arch/ppc/kernel/entry.S Fri Nov 29 19:01:45 2002
  347. +++ linux-2.4.20-rtai/arch/ppc/kernel/entry.S Mon Dec 2 16:11:55 2002
  348. @@ -291,6 +291,7 @@
  349. bl do_signal
  350. .globl do_signal_ret
  351. do_signal_ret:
  352. + bl do_soft_sti
  353. .globl ret_to_user_hook
  354. ret_to_user_hook:
  355. nop
  356. diff -Naur linux-2.4.20/arch/ppc/kernel/irq.c linux-2.4.20-rtai/arch/ppc/kernel/irq.c
  357. --- linux-2.4.20/arch/ppc/kernel/irq.c Fri Nov 29 19:01:45 2002
  358. +++ linux-2.4.20-rtai/arch/ppc/kernel/irq.c Mon Dec 2 16:11:55 2002
  359. @@ -510,6 +510,17 @@
  360. spin_unlock(&desc->lock);
  361. }
  362. +void do_soft_cli(void)
  363. +{
  364. +}
  365. +
  366. +void (*rtai_soft_sti)(void);
  367. +
  368. +void do_soft_sti(void)
  369. +{
  370. + if(rtai_soft_sti)rtai_soft_sti();
  371. +}
  372. +
  373. int do_IRQ(struct pt_regs *regs)
  374. {
  375. int cpu = smp_processor_id();
  376. diff -Naur linux-2.4.20/arch/ppc/kernel/traps.c linux-2.4.20-rtai/arch/ppc/kernel/traps.c
  377. --- linux-2.4.20/arch/ppc/kernel/traps.c Sat Nov 3 02:43:54 2001
  378. +++ linux-2.4.20-rtai/arch/ppc/kernel/traps.c Mon Dec 2 16:11:55 2002
  379. @@ -320,9 +320,15 @@
  380. return retval;
  381. }
  382. +int (*rtai_srq_bckdr)(struct pt_regs *regs) = NULL;
  383. +
  384. void
  385. ProgramCheckException(struct pt_regs *regs)
  386. {
  387. + if (rtai_srq_bckdr && !rtai_srq_bckdr(regs)) {
  388. + return;
  389. + }
  390. +{
  391. unsigned int reason = get_reason(regs);
  392. extern int do_mathemu(struct pt_regs *regs);
  393. @@ -378,6 +384,7 @@
  394. }
  395. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  396. +}
  397. }
  398. void
  399. diff -Naur linux-2.4.20/arch/ppc/kernel/ppc_ksyms.c linux-2.4.20-rtai/arch/ppc/kernel/ppc_ksyms.c
  400. --- linux-2.4.20/arch/ppc/kernel/ppc_ksyms.c Fri Nov 29 19:01:46 2002
  401. +++ linux-2.4.20-rtai/arch/ppc/kernel/ppc_ksyms.c Mon Dec 2 16:11:55 2002
  402. @@ -220,6 +220,12 @@
  403. EXPORT_SYMBOL(synchronize_irq);
  404. #endif
  405. +extern int (*rtai_srq_bckdr)(struct pt_regs *);
  406. +EXPORT_SYMBOL(rtai_srq_bckdr);
  407. +
  408. +extern void (*rtai_soft_sti)(void);
  409. +EXPORT_SYMBOL(rtai_soft_sti);
  410. +
  411. EXPORT_SYMBOL(ppc_md);
  412. #ifdef CONFIG_ADB
  413. diff -Naur linux-2.4.20/include/asm-i386/hw_irq.h linux-2.4.20-rtai/include/asm-i386/hw_irq.h
  414. --- linux-2.4.20/include/asm-i386/hw_irq.h Thu Nov 22 20:46:18 2001
  415. +++ linux-2.4.20-rtai/include/asm-i386/hw_irq.h Mon Dec 2 16:16:00 2002
  416. @@ -37,18 +37,31 @@
  417. *
  418. * Vectors 0xf0-0xfa are free (reserved for future Linux use).
  419. */
  420. +#ifdef CONFIG_RTHAL
  421. +/* the standard definitions conflict with LXRT */
  422. +#define SPURIOUS_APIC_VECTOR 0xdf
  423. +#define ERROR_APIC_VECTOR 0xde
  424. +#define INVALIDATE_TLB_VECTOR 0xdd
  425. +#define RESCHEDULE_VECTOR 0xdc
  426. +#define CALL_FUNCTION_VECTOR 0xdb
  427. +#else
  428. #define SPURIOUS_APIC_VECTOR 0xff
  429. #define ERROR_APIC_VECTOR 0xfe
  430. #define INVALIDATE_TLB_VECTOR 0xfd
  431. #define RESCHEDULE_VECTOR 0xfc
  432. #define CALL_FUNCTION_VECTOR 0xfb
  433. +#endif
  434. /*
  435. * Local APIC timer IRQ vector is on a different priority level,
  436. * to work around the 'lost local interrupt if more than 2 IRQ
  437. * sources per level' errata.
  438. */
  439. +#ifdef CONFIG_RTHAL
  440. +#define LOCAL_TIMER_VECTOR 0xcf
  441. +#else
  442. #define LOCAL_TIMER_VECTOR 0xef
  443. +#endif
  444. /*
  445. * First APIC vector available to drivers: (vectors 0x30-0xee)
  446. @@ -56,7 +69,11 @@
  447. * levels. (0x80 is the syscall vector)
  448. */
  449. #define FIRST_DEVICE_VECTOR 0x31
  450. +#ifdef CONFIG_RTHAL
  451. +#define FIRST_SYSTEM_VECTOR 0xcf
  452. +#else
  453. #define FIRST_SYSTEM_VECTOR 0xef
  454. +#endif
  455. extern int irq_vector[NR_IRQS];
  456. #define IO_APIC_VECTOR(irq) irq_vector[irq]
  457. diff -Naur linux-2.4.20/include/asm-i386/irq.h linux-2.4.20-rtai/include/asm-i386/irq.h
  458. --- linux-2.4.20/include/asm-i386/irq.h Sat Aug 3 02:39:45 2002
  459. +++ linux-2.4.20-rtai/include/asm-i386/irq.h Mon Dec 2 16:11:55 2002
  460. @@ -26,7 +26,7 @@
  461. #ifdef CONFIG_X86_IO_APIC
  462. #define NR_IRQS 224
  463. #else
  464. -#define NR_IRQS 16
  465. +#define NR_IRQS 32 /* 2.4.19 vanilla has 16, this is rtai back compatibility */
  466. #endif
  467. static __inline__ int irq_cannonicalize(int irq)
  468. diff -Naur linux-2.4.20/include/asm-i386/pgalloc.h linux-2.4.20-rtai/include/asm-i386/pgalloc.h
  469. --- linux-2.4.20/include/asm-i386/pgalloc.h Sat Aug 3 02:39:45 2002
  470. +++ linux-2.4.20-rtai/include/asm-i386/pgalloc.h Mon Dec 2 16:16:00 2002
  471. @@ -158,6 +158,33 @@
  472. extern int do_check_pgt_cache(int, int);
  473. +extern inline void set_pgdir(unsigned long address, pgd_t entry)
  474. +{
  475. + struct task_struct * p;
  476. + pgd_t *pgd;
  477. +#ifdef CONFIG_SMP
  478. + int i;
  479. +#endif
  480. +
  481. + read_lock(&tasklist_lock);
  482. + for_each_task(p) {
  483. + if (!p->mm)
  484. + continue;
  485. + *pgd_offset(p->mm,address) = entry;
  486. + }
  487. + read_unlock(&tasklist_lock);
  488. +#ifndef CONFIG_SMP
  489. + for (pgd = (pgd_t *)pgd_quicklist; pgd; pgd = (pgd_t *)*(unsigned long *)pgd)
  490. + pgd[address >> PGDIR_SHIFT] = entry;
  491. +#else
  492. + /* To pgd_alloc/pgd_free, one holds master kernel lock and so does our callee, so we can
  493. + modify pgd caches of other CPUs as well. -jj */
  494. + for (i = 0; i < NR_CPUS; i++)
  495. + for (pgd = (pgd_t *)cpu_data[i].pgd_quick; pgd; pgd = (pgd_t *)*(unsigned long *)pgd)
  496. + pgd[address >> PGDIR_SHIFT] = entry;
  497. +#endif
  498. +}
  499. +
  500. /*
  501. * TLB flushing:
  502. *
  503. diff -Naur linux-2.4.20/include/asm-i386/system.h linux-2.4.20-rtai/include/asm-i386/system.h
  504. --- linux-2.4.20/include/asm-i386/system.h Fri Nov 29 19:02:50 2002
  505. +++ linux-2.4.20-rtai/include/asm-i386/system.h Mon Dec 2 16:16:00 2002
  506. @@ -12,7 +12,12 @@
  507. struct task_struct; /* one of the stranger aspects of C forward declarations.. */
  508. extern void FASTCALL(__switch_to(struct task_struct *prev, struct task_struct *next));
  509. -#define prepare_to_switch() do { } while(0)
  510. +#define prepare_to_switch() do { \
  511. + if (rthal.lxrt_global_cli) { \
  512. + rthal.lxrt_global_cli(); \
  513. + } \
  514. +} while(0)
  515. +
  516. #define switch_to(prev,next,last) do { \
  517. asm volatile("pushl %%esi\n\t" \
  518. "pushl %%edi\n\t" \
  519. @@ -23,6 +28,7 @@
  520. "pushl %4\n\t" /* restore EIP */ \
  521. "jmp __switch_to\n" \
  522. "1:\t" \
  523. + "sti\n\t" \
  524. "popl %%ebp\n\t" \
  525. "popl %%edi\n\t" \
  526. "popl %%esi\n\t" \
  527. @@ -315,29 +321,59 @@
  528. #define set_wmb(var, value) do { var = value; wmb(); } while (0)
  529. +struct rt_hal {
  530. + void *ret_from_intr;
  531. + void *__switch_to;
  532. + struct desc_struct *idt_table;
  533. + void (*disint)(void);
  534. + void (*enint)(void);
  535. + unsigned int (*getflags)(void);
  536. + void (*setflags)(unsigned int flags);
  537. + unsigned int (*getflags_and_cli)(void);
  538. + void *irq_desc;
  539. + int *irq_vector;
  540. + unsigned long *irq_affinity;
  541. + void (*smp_invalidate_interrupt)(void);
  542. + void (*ack_8259_irq)(unsigned int);
  543. + int *idle_weight;
  544. + void (*lxrt_global_cli)(void);
  545. + void (*switch_mem)(struct task_struct *, struct task_struct *, int);
  546. + struct task_struct **init_tasks;
  547. + unsigned int *apicmap;
  548. +};
  549. +
  550. +extern struct rt_hal rthal;
  551. +
  552. /* interrupt control.. */
  553. -#define __save_flags(x) __asm__ __volatile__("pushfl ; popl %0":"=g" (x): /* no input */)
  554. -#define __restore_flags(x) __asm__ __volatile__("pushl %0 ; popfl": /* no output */ :"g" (x):"memory", "cc")
  555. -#define __cli() __asm__ __volatile__("cli": : :"memory")
  556. -#define __sti() __asm__ __volatile__("sti": : :"memory")
  557. -/* used in the idle loop; sti takes one instruction cycle to complete */
  558. -#define safe_halt() __asm__ __volatile__("sti; hlt": : :"memory")
  559. +#define hard_save_flags(x) __asm__ __volatile__("pushfl ; popl %0":"=g" (x): /* no input */)
  560. +#define hard_restore_flags(x) __asm__ __volatile__("pushl %0 ; popfl": /* no output */ :"g" (x):"memory", "cc")
  561. +#define hard_cli() __asm__ __volatile__("cli": : :"memory")
  562. +#define hard_sti() __asm__ __volatile__("sti": : :"memory")
  563. +#define hard_save_flags_and_cli(x) __asm__ __volatile__("pushfl; popl %0; cli":"=g" (x): /* no input */)
  564. +
  565. +#define __cli() do { rthal.disint(); } while (0)
  566. +#define __sti() do { rthal.enint(); } while (0)
  567. +#define __save_flags(x) do { x = rthal.getflags(); } while (0)
  568. +#define __restore_flags(x) do { rthal.setflags(x); } while (0)
  569. +
  570. +#define __save_and_cli(x) do { x = rthal.getflags_and_cli(); } while (0)
  571. +#define __save_and_sti(x) do { x = rthal.getflags(); rthal.enint(); } while (0)
  572. -#define __save_and_cli(x) do { __save_flags(x); __cli(); } while(0);
  573. -#define __save_and_sti(x) do { __save_flags(x); __sti(); } while(0);
  574. +/* used in the idle loop; sti takes one instruction cycle to complete */
  575. +#define safe_halt() __asm__ __volatile__("call *"SYMBOL_NAME_STR(rthal + 16)"; hlt": : :"memory")
  576. /* For spinlocks etc */
  577. #if 0
  578. #define local_irq_save(x) __asm__ __volatile__("pushfl ; popl %0 ; cli":"=g" (x): /* no input */ :"memory")
  579. #define local_irq_set(x) __asm__ __volatile__("pushfl ; popl %0 ; sti":"=g" (x): /* no input */ :"memory")
  580. #else
  581. -#define local_irq_save(x) __save_and_cli(x)
  582. -#define local_irq_set(x) __save_and_sti(x)
  583. +#define local_irq_save(x) do { x = rthal.getflags_and_cli(); } while (0)
  584. +#define local_irq_set(x) do { x = rthal.getflags(); rthal.enint(); } while (0)
  585. #endif
  586. -#define local_irq_restore(x) __restore_flags(x)
  587. -#define local_irq_disable() __cli()
  588. -#define local_irq_enable() __sti()
  589. +#define local_irq_restore(x) do { rthal.setflags(x); } while (0)
  590. +#define local_irq_disable() do { rthal.disint(); } while (0)
  591. +#define local_irq_enable() do { rthal.enint(); } while (0)
  592. #ifdef CONFIG_SMP
  593. diff -Naur linux-2.4.20/include/asm-ppc/system.h linux-2.4.20-rtai/include/asm-ppc/system.h
  594. --- linux-2.4.20/include/asm-ppc/system.h Sat Aug 3 02:39:45 2002
  595. +++ linux-2.4.20-rtai/include/asm-ppc/system.h Mon Dec 2 16:11:55 2002
  596. @@ -82,6 +82,7 @@
  597. struct task_struct;
  598. #define prepare_to_switch() do { } while(0)
  599. +#define end_switch() do { } while(0)
  600. #define switch_to(prev,next,last) _switch_to((prev),(next),&(last))
  601. extern void _switch_to(struct task_struct *, struct task_struct *,
  602. struct task_struct **);
  603. diff -Naur linux-2.4.20/include/linux/sched.h linux-2.4.20-rtai/include/linux/sched.h
  604. --- linux-2.4.20/include/linux/sched.h Fri Nov 29 19:03:06 2002
  605. +++ linux-2.4.20-rtai/include/linux/sched.h Mon Dec 2 16:16:00 2002
  606. @@ -415,6 +415,8 @@
  607. /* journalling filesystem info */
  608. void *journal_info;
  609. +
  610. + void *this_rt_task[2];
  611. };
  612. /*
  613. @@ -509,6 +511,7 @@
  614. blocked: {{0}}, \
  615. alloc_lock: SPIN_LOCK_UNLOCKED, \
  616. journal_info: NULL, \
  617. + this_rt_task: {0,0}, \
  618. }
  619. diff -Naur linux-2.4.20/kernel/exit.c linux-2.4.20-rtai/kernel/exit.c
  620. --- linux-2.4.20/kernel/exit.c Fri Nov 29 19:03:07 2002
  621. +++ linux-2.4.20-rtai/kernel/exit.c Mon Dec 2 16:11:55 2002
  622. @@ -422,6 +422,71 @@
  623. write_unlock_irq(&tasklist_lock);
  624. }
  625. +//
  626. +// PGGC added these lines to callback rtai when a task dies.
  627. +// A list of functions allows different rt_modules to be informed.
  628. +//
  629. +static struct t_callback {
  630. + void (*rtai_callback)(struct task_struct *tsk);
  631. + struct t_callback *next;
  632. + } *rtai_callback_list;
  633. +
  634. +extern int set_rtai_callback( void (*fun)(struct task_struct *tsk));
  635. +extern void remove_rtai_callback( void (*fun)(struct task_struct *tsk));
  636. +
  637. +void inform_rtai(void)
  638. +{
  639. + struct t_callback *pt;
  640. +
  641. + pt = rtai_callback_list;
  642. + while (pt) {
  643. + (*(pt->rtai_callback))(current);
  644. + pt = pt->next;
  645. + }
  646. +//printk( "Task pid %d going down\n", current->pid);
  647. +}
  648. +
  649. +int set_rtai_callback( void (*pt)(struct task_struct *tsk))
  650. +{
  651. + struct t_callback *ptn;
  652. +
  653. + ptn = kmalloc(sizeof(struct t_callback), GFP_KERNEL);
  654. + if (!ptn) {
  655. + return -ENOMEM;
  656. + }
  657. + ptn->rtai_callback = pt;
  658. + ptn->next = rtai_callback_list ? rtai_callback_list : 0;
  659. + rtai_callback_list = ptn;
  660. + return 0;
  661. +}
  662. +
  663. +void remove_rtai_callback(void (*pt)(struct task_struct *tsk))
  664. +{
  665. + struct t_callback *pto, *ptoo, *ptd;
  666. +
  667. + pto = rtai_callback_list;
  668. + ptoo = 0;
  669. + while (pto) {
  670. + if (pto->rtai_callback == pt) {
  671. + if (!ptoo) {
  672. + rtai_callback_list = pto->next;
  673. + } else {
  674. + ptoo->next = pto->next;
  675. + }
  676. + ptd = pto;
  677. + pto = pto->next;
  678. + kfree(ptd);
  679. + } else {
  680. + ptoo = pto;
  681. + pto = pto->next;
  682. + }
  683. + }
  684. +//printk("rtai_callback_list %X\n", rtai_callback_list);
  685. +}
  686. +//
  687. +//
  688. +//
  689. +
  690. NORET_TYPE void do_exit(long code)
  691. {
  692. struct task_struct *tsk = current;
  693. @@ -439,6 +504,18 @@
  694. #ifdef CONFIG_BSD_PROCESS_ACCT
  695. acct_process(code);
  696. #endif
  697. +
  698. +/*
  699. + * PGGC added these lines to callback rtai when a task dies.
  700. + * This assumes that a LXRT task should/will always set its
  701. + * scheduling police to SCHED_FIFO or SCHED_RR.
  702. + * We may want to enforce this in rt_task_init(...).
  703. + * (For the moment it is not so, thus let's inform LXRT anyhow (Paolo))
  704. + */
  705. + if(tsk->this_rt_task[0]) {
  706. + inform_rtai();
  707. + }
  708. +
  709. __exit_mm(tsk);
  710. lock_kernel();
  711. diff -Naur linux-2.4.20/kernel/fork.c linux-2.4.20-rtai/kernel/fork.c
  712. --- linux-2.4.20/kernel/fork.c Fri Nov 29 19:03:07 2002
  713. +++ linux-2.4.20-rtai/kernel/fork.c Mon Dec 2 16:11:55 2002
  714. @@ -233,7 +233,9 @@
  715. atomic_set(&mm->mm_count, 1);
  716. init_rwsem(&mm->mmap_sem);
  717. mm->page_table_lock = SPIN_LOCK_UNLOCKED;
  718. + lock_kernel();
  719. mm->pgd = pgd_alloc(mm);
  720. + unlock_kernel();
  721. mm->def_flags = 0;
  722. if (mm->pgd)
  723. return mm;
  724. @@ -265,7 +267,9 @@
  725. inline void __mmdrop(struct mm_struct *mm)
  726. {
  727. BUG_ON(mm == &init_mm);
  728. + lock_kernel();
  729. pgd_free(mm->pgd);
  730. + unlock_kernel();
  731. check_pgt_cache();
  732. destroy_context(mm);
  733. free_mm(mm);
  734. diff -Naur linux-2.4.20/kernel/ksyms.c linux-2.4.20-rtai/kernel/ksyms.c
  735. --- linux-2.4.20/kernel/ksyms.c Fri Nov 29 19:03:07 2002
  736. +++ linux-2.4.20-rtai/kernel/ksyms.c Mon Dec 2 16:11:55 2002
  737. @@ -600,3 +600,44 @@
  738. /* To match ksyms with System.map */
  739. extern const char _end[];
  740. EXPORT_SYMBOL(_end);
  741. +
  742. +/*
  743. + * used to inform rtai a task is about to die.
  744. + */
  745. +extern int set_rtai_callback( void (*fun)(struct task_struct *tsk));
  746. +extern void remove_rtai_callback(void (*fun)(struct task_struct *tsk));
  747. +extern NORET_TYPE void do_exit(long code);
  748. +EXPORT_SYMBOL(set_rtai_callback);
  749. +EXPORT_SYMBOL(remove_rtai_callback);
  750. +EXPORT_SYMBOL(do_exit);
  751. +
  752. +/*
  753. + * used to inform RTAI LXRT a task should deal with a Linux signal, and for rt_lxrt_fork()
  754. + */
  755. +extern int (*rtai_signal_handler)(struct task_struct *lnxt, int sig);
  756. +EXPORT_SYMBOL(rtai_signal_handler);
  757. +extern int do_fork(unsigned long clone_flags, unsigned long stack_start, struct pt_regs *regs, unsigned long stack_size);
  758. +EXPORT_SYMBOL(do_fork);
  759. +
  760. +/*
  761. + * used to provide async io support (aio) to RTAI LXRT.
  762. + */
  763. +extern ssize_t sys_read(unsigned int fd, char * buf, size_t count);
  764. +extern ssize_t sys_write(unsigned int fd, const char * buf, size_t count);
  765. +extern ssize_t sys_pread(unsigned int fd, char * buf,
  766. + size_t count, loff_t pos);
  767. +extern ssize_t sys_pwrite(unsigned int fd, const char * buf,
  768. + size_t count, loff_t pos);
  769. +extern long sys_fsync(unsigned int fd);
  770. +extern long sys_fdatasync(unsigned int fd);
  771. +extern long sys_open(const char * filename, int flags, int mode);
  772. +extern long sys_close(unsigned int fd);
  773. +
  774. +EXPORT_SYMBOL(sys_read);
  775. +EXPORT_SYMBOL(sys_write);
  776. +EXPORT_SYMBOL(sys_open);
  777. +//EXPORT_SYMBOL(sys_close);
  778. +EXPORT_SYMBOL(sys_pread);
  779. +EXPORT_SYMBOL(sys_pwrite);
  780. +EXPORT_SYMBOL(sys_fsync);
  781. +EXPORT_SYMBOL(sys_fdatasync);
  782. diff -Naur linux-2.4.20/kernel/sched.c linux-2.4.20-rtai/kernel/sched.c
  783. --- linux-2.4.20/kernel/sched.c Fri Nov 29 19:03:07 2002
  784. +++ linux-2.4.20-rtai/kernel/sched.c Mon Dec 2 16:11:55 2002
  785. @@ -544,6 +544,43 @@
  786. * tasks can run. It can not be killed, and it cannot sleep. The 'state'
  787. * information in task[0] is never used.
  788. */
  789. +
  790. +int idle_weight = -1000;
  791. +#define MAX_MM 1024 // How large should it be?
  792. +static struct smm_t { int in, out; struct mm_struct *mm[MAX_MM]; } smm[NR_CPUS];
  793. +#define incpnd(x) do { x = (x + 1) & (MAX_MM - 1); } while(0)
  794. +
  795. +static inline void pend_mm(struct mm_struct *mm, int cpu)
  796. +{
  797. + if (rthal.lxrt_global_cli) {
  798. + struct smm_t *p = smm + cpu;
  799. + p->mm[p->in] = mm;
  800. + incpnd(p->in);
  801. + } else {
  802. + mmdrop(mm);
  803. + }
  804. +}
  805. +
  806. +static inline void drop_mm(void)
  807. +{
  808. + if (rthal.lxrt_global_cli) {
  809. + struct smm_t *p = smm + smp_processor_id();
  810. + while (p->out != p->in) {
  811. + mmdrop(p->mm[p->out]);
  812. + incpnd(p->out);
  813. + }
  814. + }
  815. +}
  816. +
  817. +void switch_mem(struct task_struct *prevp, struct task_struct *nextp, int cpuid)
  818. +{
  819. + struct mm_struct *oldmm = prevp->active_mm;
  820. + switch_mm(oldmm, nextp->active_mm, nextp, cpuid & 0x0FFFFFFF);
  821. + if (!nextp->mm) {
  822. + enter_lazy_tlb(oldmm, nextp, cpuid & 0x0FFFFFFF);
  823. + }
  824. +}
  825. +
  826. asmlinkage void schedule(void)
  827. {
  828. struct schedule_data * sched_data;
  829. @@ -602,7 +639,7 @@
  830. * Default process to select..
  831. */
  832. next = idle_task(this_cpu);
  833. - c = -1000;
  834. + c = idle_weight;
  835. list_for_each(tmp, &runqueue_head) {
  836. p = list_entry(tmp, struct task_struct, run_list);
  837. if (can_schedule(p, this_cpu)) {
  838. @@ -684,7 +721,7 @@
  839. if (!prev->mm) {
  840. prev->active_mm = NULL;
  841. - mmdrop(oldmm);
  842. + pend_mm(oldmm, this_cpu);
  843. }
  844. }
  845. @@ -693,6 +730,7 @@
  846. * stack.
  847. */
  848. switch_to(prev, next, prev);
  849. + drop_mm();
  850. __schedule_tail(prev);
  851. same_process:
  852. diff -Naur linux-2.4.20/kernel/signal.c linux-2.4.20-rtai/kernel/signal.c
  853. --- linux-2.4.20/kernel/signal.c Fri Nov 29 19:03:07 2002
  854. +++ linux-2.4.20-rtai/kernel/signal.c Mon Dec 2 16:11:55 2002
  855. @@ -1010,9 +1010,30 @@
  856. return ret;
  857. }
  858. +//
  859. +// Add this pointer to the RTAI signal handler.
  860. +//
  861. +int (*rtai_signal_handler)(struct task_struct *lnxt, int sig);
  862. +
  863. asmlinkage long
  864. sys_kill(int pid, int sig)
  865. {
  866. +// Add this section to call the RTAI signal handler.
  867. +//
  868. + {
  869. + struct task_struct *p;
  870. + int ret;
  871. +
  872. + if (rtai_signal_handler) {
  873. + p = find_task_by_pid(pid);
  874. + if(p && (p->policy == SCHED_FIFO || p->policy == SCHED_RR) && p->this_rt_task[0]) {
  875. + ret = rtai_signal_handler(p, sig);
  876. + if(!ret) return 0; //let Linux deal with it.
  877. + }
  878. + }
  879. + }
  880. +
  881. + {
  882. struct siginfo info;
  883. info.si_signo = sig;
  884. @@ -1022,6 +1043,7 @@
  885. info.si_uid = current->uid;
  886. return kill_something_info(sig, &info, pid);
  887. + }
  888. }
  889. /*
  890. diff -Naur linux-2.4.20/mm/vmalloc.c linux-2.4.20-rtai/mm/vmalloc.c
  891. --- linux-2.4.20/mm/vmalloc.c Fri Nov 29 19:03:09 2002
  892. +++ linux-2.4.20-rtai/mm/vmalloc.c Mon Dec 2 16:11:55 2002
  893. @@ -166,6 +166,9 @@
  894. spin_lock(&init_mm.page_table_lock);
  895. do {
  896. pmd_t *pmd;
  897. +#ifdef CONFIG_X86
  898. + pgd_t olddir = *dir;
  899. +#endif
  900. pmd = pmd_alloc(&init_mm, dir, address);
  901. ret = -ENOMEM;
  902. @@ -175,6 +178,10 @@
  903. ret = -ENOMEM;
  904. if (alloc_area_pmd(pmd, address, end - address, gfp_mask, prot, pages))
  905. break;
  906. +#ifdef CONFIG_X86
  907. + if (pgd_val(olddir) != pgd_val(*dir))
  908. + set_pgdir(address, *dir);
  909. +#endif
  910. address = (address + PGDIR_SIZE) & PGDIR_MASK;
  911. dir++;