00001
00028 #ifndef _RTAI_ASM_GENERIC_HAL_H
00029 #define _RTAI_ASM_GENERIC_HAL_H
00030
00031 #ifdef __KERNEL__
00032
00033 #include <rtai_config.h>
00034 #include <linux/kernel.h>
00035 #include <linux/sched.h>
00036 #include <linux/interrupt.h>
00037 #include <linux/kallsyms.h>
00038
00039 #define RTHAL_DOMAIN_ID 0x52544149
00040
00041 #define RTHAL_TIMER_FREQ (rthal_tunables.timer_freq)
00042 #define RTHAL_CPU_FREQ (rthal_tunables.cpu_freq)
00043 #define RTHAL_NR_APCS BITS_PER_LONG
00044
00045 #define RTHAL_EVENT_PROPAGATE 0
00046 #define RTHAL_EVENT_STOP 1
00047
00048 #ifdef CONFIG_IPIPE
00049
00050 #define RTHAL_NR_CPUS IPIPE_NR_CPUS
00051 #define RTHAL_ROOT_PRIO IPIPE_ROOT_PRIO
00052 #define RTHAL_NR_FAULTS IPIPE_NR_FAULTS
00053
00054 #define RTHAL_SERVICE_IPI0 IPIPE_SERVICE_IPI0
00055 #define RTHAL_SERVICE_VECTOR0 IPIPE_SERVICE_VECTOR0
00056 #define RTHAL_SERVICE_IPI1 IPIPE_SERVICE_IPI1
00057 #define RTHAL_SERVICE_VECTOR1 IPIPE_SERVICE_VECTOR1
00058 #define RTHAL_SERVICE_IPI2 IPIPE_SERVICE_IPI2
00059 #define RTHAL_SERVICE_VECTOR2 IPIPE_SERVICE_VECTOR2
00060 #define RTHAL_SERVICE_IPI3 IPIPE_SERVICE_IPI3
00061 #define RTHAL_SERVICE_VECTOR3 IPIPE_SERVICE_VECTOR3
00062 #define RTHAL_CRITICAL_IPI IPIPE_CRITICAL_IPI
00063
00064 typedef struct ipipe_domain rthal_pipeline_stage_t;
00065
00066 #define rthal_local_irq_disable() ipipe_stall_pipeline_from(&rthal_domain)
00067 #define rthal_local_irq_enable() ipipe_unstall_pipeline_from(&rthal_domain)
00068 #define rthal_local_irq_save(x) ((x) = !!ipipe_test_and_stall_pipeline_from(&rthal_domain))
00069 #define rthal_local_irq_restore(x) ipipe_restore_pipeline_from(&rthal_domain,(x))
00070 #define rthal_local_irq_flags(x) ((x) = !!ipipe_test_pipeline_from(&rthal_domain))
00071 #define rthal_local_irq_test() (!!ipipe_test_pipeline_from(&rthal_domain))
00072 #define rthal_local_irq_sync(x) ((x) = !!ipipe_test_and_unstall_pipeline_from(&rthal_domain))
00073 #define rthal_stage_irq_enable(dom) ipipe_unstall_pipeline_from(dom)
00074 #define rthal_local_irq_save_hw(x) local_irq_save_hw(x)
00075 #define rthal_local_irq_restore_hw(x) local_irq_restore_hw(x)
00076 #define rthal_local_irq_enable_hw() local_irq_enable_hw()
00077 #define rthal_local_irq_disable_hw() local_irq_disable_hw()
00078 #define rthal_local_irq_flags_hw(x) local_save_flags_hw(x)
00079
00080 #define rthal_write_lock(lock) write_lock_hw(lock)
00081 #define rthal_write_unlock(lock) write_unlock_hw(lock)
00082 #define rthal_read_lock(lock) read_lock_hw(lock)
00083 #define rthal_read_unlock(lock) read_unlock_hw(lock)
00084 #define rthal_spin_lock(lock) spin_lock_hw(lock)
00085 #define rthal_spin_unlock(lock) spin_unlock_hw(lock)
00086
00087 #define rthal_root_domain ipipe_root_domain
00088 #define rthal_current_domain ipipe_current_domain
00089 #define rthal_declare_cpuid ipipe_declare_cpuid
00090
00091 #define rthal_load_cpuid() ipipe_load_cpuid()
00092 #define rthal_suspend_domain() ipipe_suspend_domain()
00093 #define rthal_grab_superlock(syncfn) ipipe_critical_enter(syncfn)
00094 #define rthal_release_superlock(x) ipipe_critical_exit(x)
00095 #define rthal_propagate_irq(irq) ipipe_propagate_irq(irq)
00096 #define rthal_set_irq_affinity(irq,aff) ipipe_set_irq_affinity(irq,aff)
00097 #define rthal_schedule_irq(irq) ipipe_schedule_irq(irq)
00098 #define rthal_virtualize_irq(dom,irq,isr,ackfn,mode) ipipe_virtualize_irq(dom,irq,isr,ackfn,mode)
00099 #define rthal_alloc_virq() ipipe_alloc_virq()
00100 #define rthal_free_virq(irq) ipipe_free_virq(irq)
00101 #define rthal_trigger_irq(irq) ipipe_trigger_irq(irq)
00102 #define rthal_get_sysinfo(ibuf) ipipe_get_sysinfo(ibuf)
00103 #define rthal_alloc_ptdkey() ipipe_alloc_ptdkey()
00104 #define rthal_free_ptdkey(key) ipipe_free_ptdkey(key)
00105 #define rthal_send_ipi(irq,cpus) ipipe_send_ipi(irq,cpus)
00106 #define rthal_lock_irq(dom,cpu,irq) __ipipe_lock_irq(dom,cpu,irq)
00107 #define rthal_unlock_irq(dom,irq) __ipipe_unlock_irq(dom,irq)
00108 #ifdef IPIPE_GRAB_TIMER
00109 #define rthal_set_timer(ns) ipipe_tune_timer(ns,ns ? 0 : IPIPE_GRAB_TIMER)
00110 #else
00111 #define rthal_set_timer(ns) ipipe_tune_timer(ns,0)
00112 #endif
00113 #define rthal_reset_timer() ipipe_tune_timer(0,IPIPE_RESET_TIMER)
00114
00115 #define rthal_lock_cpu(x) ipipe_lock_cpu(x)
00116 #define rthal_unlock_cpu(x) ipipe_unlock_cpu(x)
00117 #define rthal_get_cpu(x) ipipe_get_cpu(x)
00118 #define rthal_put_cpu(x) ipipe_put_cpu(x)
00119 #define rthal_processor_id() ipipe_processor_id()
00120
00121 #define rthal_setsched_root(t,pol,prio) ipipe_setscheduler_root(t,pol,prio)
00122 #define rthal_reenter_root(t,pol,prio) ipipe_reenter_root(t,pol,prio)
00123 #define rthal_emergency_console() ipipe_set_printk_sync(ipipe_current_domain)
00124 #define rthal_read_tsc(v) ipipe_read_tsc(v)
00125
00126 static inline unsigned long rthal_get_cpufreq(void)
00127 {
00128 struct ipipe_sysinfo sysinfo;
00129 rthal_get_sysinfo(&sysinfo);
00130 return (unsigned long)sysinfo.cpufreq;
00131 }
00132
00133 #define RTHAL_DECLARE_EVENT(hdlr) \
00134 static int hdlr (unsigned event, struct ipipe_domain *ipd, void *data) \
00135 { \
00136 return do_##hdlr(event,ipd->domid,data); \
00137 }
00138
00139 #define RTHAL_DECLARE_SCHEDULE_EVENT(hdlr) \
00140 static int hdlr (unsigned event, struct ipipe_domain *ipd, void *data) \
00141 { \
00142 struct task_struct *p = (struct task_struct *)data; \
00143 do_##hdlr(p); \
00144 return RTHAL_EVENT_PROPAGATE; \
00145 }
00146
00147 #define RTHAL_DECLARE_SETSCHED_EVENT(hdlr) \
00148 static int hdlr (unsigned event, struct ipipe_domain *ipd, void *data) \
00149 { \
00150 struct task_struct *p = (struct task_struct *)data; \
00151 do_##hdlr(p,p->rt_priority); \
00152 return RTHAL_EVENT_PROPAGATE; \
00153 }
00154
00155 #define RTHAL_DECLARE_SIGWAKE_EVENT(hdlr) \
00156 static int hdlr (unsigned event, struct ipipe_domain *ipd, void *data) \
00157 { \
00158 struct task_struct *p = (struct task_struct *)data; \
00159 do_##hdlr(p); \
00160 return RTHAL_EVENT_PROPAGATE; \
00161 }
00162
00163 #define RTHAL_DECLARE_EXIT_EVENT(hdlr) \
00164 static int hdlr (unsigned event, struct ipipe_domain *ipd, void *data) \
00165 { \
00166 struct task_struct *p = (struct task_struct *)data; \
00167 do_##hdlr(p); \
00168 return RTHAL_EVENT_PROPAGATE; \
00169 }
00170
00171 #define rthal_catch_taskexit(hdlr) \
00172 ipipe_catch_event(ipipe_root_domain,IPIPE_EVENT_EXIT,hdlr)
00173 #define rthal_catch_sigwake(hdlr) \
00174 ipipe_catch_event(ipipe_root_domain,IPIPE_EVENT_SIGWAKE,hdlr)
00175 #define rthal_catch_schedule(hdlr) \
00176 ipipe_catch_event(ipipe_root_domain,IPIPE_EVENT_SCHEDULE,hdlr)
00177 #define rthal_catch_setsched(hdlr) \
00178 ipipe_catch_event(&rthal_domain,IPIPE_EVENT_SETSCHED,hdlr)
00179 #define rthal_catch_losyscall(hdlr) \
00180 ipipe_catch_event(ipipe_root_domain,IPIPE_EVENT_SYSCALL,hdlr)
00181 #define rthal_catch_hisyscall(hdlr) \
00182 ipipe_catch_event(&rthal_domain,IPIPE_EVENT_SYSCALL,hdlr)
00183 #define rthal_catch_exception(ex,hdlr) \
00184 ipipe_catch_event(&rthal_domain,ex,hdlr)
00185
00186 #define rthal_register_domain(_dom,_name,_id,_prio,_entry) \
00187 ({ \
00188 struct ipipe_domain_attr attr; \
00189 ipipe_init_attr(&attr); \
00190 attr.name = _name; \
00191 attr.entry = _entry; \
00192 attr.domid = _id; \
00193 attr.priority = _prio; \
00194 ipipe_register_domain(_dom,&attr); \
00195 })
00196
00197 #define rthal_unregister_domain(dom) ipipe_unregister_domain(dom)
00198
00199 #define RTHAL_DECLARE_DOMAIN(entry) \
00200 void entry (void) \
00201 { \
00202 do_##entry(); \
00203 }
00204
00205 extern void rthal_domain_entry(void);
00206
00207 #else
00208
00209 #define RTHAL_NR_CPUS ADEOS_NR_CPUS
00210 #define RTHAL_ROOT_PRIO ADEOS_ROOT_PRI
00211 #define RTHAL_NR_FAULTS ADEOS_NR_FAULTS
00212
00213 #define RTHAL_SERVICE_IPI0 ADEOS_SERVICE_IPI0
00214 #define RTHAL_SERVICE_VECTOR0 ADEOS_SERVICE_VECTOR0
00215 #define RTHAL_SERVICE_IPI1 ADEOS_SERVICE_IPI1
00216 #define RTHAL_SERVICE_VECTOR1 ADEOS_SERVICE_VECTOR1
00217 #define RTHAL_SERVICE_IPI2 ADEOS_SERVICE_IPI2
00218 #define RTHAL_SERVICE_VECTOR2 ADEOS_SERVICE_VECTOR2
00219 #define RTHAL_SERVICE_IPI3 ADEOS_SERVICE_IPI3
00220 #define RTHAL_SERVICE_VECTOR3 ADEOS_SERVICE_VECTOR3
00221 #define RTHAL_CRITICAL_IPI ADEOS_CRITICAL_IPI
00222
00223 typedef adomain_t rthal_pipeline_stage_t;
00224
00225 #define rthal_local_irq_disable() adeos_stall_pipeline_from(&rthal_domain)
00226 #define rthal_local_irq_enable() adeos_unstall_pipeline_from(&rthal_domain)
00227 #define rthal_local_irq_save(x) ((x) = !!adeos_test_and_stall_pipeline_from(&rthal_domain))
00228 #define rthal_local_irq_restore(x) adeos_restore_pipeline_from(&rthal_domain,(x))
00229 #define rthal_local_irq_flags(x) ((x) = !!adeos_test_pipeline_from(&rthal_domain))
00230 #define rthal_local_irq_test() (!!adeos_test_pipeline_from(&rthal_domain))
00231 #define rthal_local_irq_sync(x) ((x) = !!adeos_test_and_unstall_pipeline_from(&rthal_domain))
00232 #define rthal_stage_irq_enable(dom) adeos_unstall_pipeline_from(dom)
00233 #define rthal_local_irq_save_hw(x) adeos_hw_local_irq_save(x)
00234 #define rthal_local_irq_restore_hw(x) adeos_hw_local_irq_restore(x)
00235 #define rthal_local_irq_enable_hw() adeos_hw_sti()
00236 #define rthal_local_irq_disable_hw() adeos_hw_cli()
00237 #define rthal_local_irq_flags_hw(x) adeos_hw_local_irq_flags(x)
00238
00239 #define rthal_write_lock(lock) adeos_write_lock(lock)
00240 #define rthal_write_unlock(lock) adeos_write_unlock(lock)
00241 #define rthal_read_lock(lock) adeos_read_lock(lock)
00242 #define rthal_read_unlock(lock) adeos_read_unlock(lock)
00243 #define rthal_spin_lock(lock) adeos_spin_lock(lock)
00244 #define rthal_spin_unlock(lock) adeos_spin_unlock(lock)
00245
00246 #define rthal_root_domain adp_root
00247 #define rthal_current_domain adp_current
00248 #define rthal_declare_cpuid adeos_declare_cpuid
00249
00250 #define rthal_load_cpuid() adeos_load_cpuid()
00251 #define rthal_suspend_domain() adeos_suspend_domain()
00252 #define rthal_grab_superlock(syncfn) adeos_critical_enter(syncfn)
00253 #define rthal_release_superlock(x) adeos_critical_exit(x)
00254 #define rthal_propagate_irq(irq) adeos_propagate_irq(irq)
00255 #define rthal_set_irq_affinity(irq,aff) adeos_set_irq_affinity(irq,aff)
00256 #define rthal_schedule_irq(irq) adeos_schedule_irq(irq)
00257 #define rthal_virtualize_irq(dom,irq,isr,ackfn,mode) adeos_virtualize_irq_from(dom,irq,isr,ackfn,mode)
00258 #define rthal_alloc_virq() adeos_alloc_irq()
00259 #define rthal_free_virq(irq) adeos_free_irq(irq)
00260 #define rthal_trigger_irq(irq) adeos_trigger_irq(irq)
00261 #define rthal_get_sysinfo(ibuf) adeos_get_sysinfo(ibuf)
00262 #define rthal_alloc_ptdkey() adeos_alloc_ptdkey()
00263 #define rthal_free_ptdkey(key) adeos_free_ptdkey(key)
00264 #define rthal_send_ipi(irq,cpus) adeos_send_ipi(irq,cpus)
00265 #define rthal_lock_irq(dom,cpu,irq) __adeos_lock_irq(dom,cpu,irq)
00266 #define rthal_unlock_irq(dom,irq) __adeos_unlock_irq(dom,irq)
00267 #ifdef ADEOS_GRAB_TIMER
00268 #define rthal_set_timer(ns) adeos_tune_timer(ns,ns ? 0 : ADEOS_GRAB_TIMER)
00269 #else
00270 #define rthal_set_timer(ns) adeos_tune_timer(ns,0)
00271 #endif
00272 #define rthal_reset_timer() adeos_tune_timer(0,ADEOS_RESET_TIMER)
00273
00274 #define rthal_lock_cpu(x) adeos_lock_cpu(x)
00275 #define rthal_unlock_cpu(x) adeos_unlock_cpu(x)
00276 #define rthal_get_cpu(x) adeos_get_cpu(x)
00277 #define rthal_put_cpu(x) adeos_put_cpu(x)
00278 #define rthal_processor_id() adeos_processor_id()
00279
00280 #define rthal_setsched_root(t,pol,prio) __adeos_setscheduler_root(t,pol,prio)
00281 #define rthal_reenter_root(t,pol,prio) __adeos_reenter_root(t,pol,prio)
00282 #define rthal_emergency_console() adeos_set_printk_sync(adp_current)
00283 #define rthal_read_tsc(v) adeos_hw_tsc(v)
00284
00285 static inline unsigned long rthal_get_cpufreq(void)
00286 {
00287 adsysinfo_t sysinfo;
00288 rthal_get_sysinfo(&sysinfo);
00289 return (unsigned long)sysinfo.cpufreq;
00290 }
00291
00292 #define RTHAL_DECLARE_EVENT(hdlr) \
00293 static void hdlr (adevinfo_t *p) \
00294 { \
00295 if (do_##hdlr((p)->event,(p)->domid,(p)->evdata) == RTHAL_EVENT_PROPAGATE) \
00296 adeos_propagate_event(p); \
00297 }
00298
00299 #define RTHAL_DECLARE_SCHEDULE_EVENT(hdlr) \
00300 static void hdlr (adevinfo_t *p) \
00301 { \
00302 struct { \
00303 struct task_struct *prev; \
00304 struct task_struct *next; \
00305 } *ev = (__typeof(ev))(p)->evdata; \
00306 do_##hdlr(ev->next); \
00307 adeos_propagate_event(p); \
00308 }
00309
00310 #define RTHAL_DECLARE_SETSCHED_EVENT(hdlr) \
00311 static void hdlr (adevinfo_t *p) \
00312 { \
00313 struct { \
00314 struct task_struct *task; \
00315 int policy; \
00316 struct sched_param *param; \
00317 } *ev = (__typeof(ev))(p)->evdata; \
00318 do_##hdlr(ev->task,ev->param->sched_priority); \
00319 adeos_propagate_event(p); \
00320 }
00321
00322 #define RTHAL_DECLARE_SIGWAKE_EVENT(hdlr) \
00323 static void hdlr (adevinfo_t *p) \
00324 { \
00325 struct { \
00326 struct task_struct *task; \
00327 } *ev = (__typeof(ev))(p)->evdata; \
00328 do_##hdlr(ev->task); \
00329 adeos_propagate_event(p); \
00330 }
00331
00332 #define RTHAL_DECLARE_EXIT_EVENT(hdlr) \
00333 static void hdlr (adevinfo_t *p) \
00334 { \
00335 struct task_struct *task = (struct task_struct *)p->evdata; \
00336 do_##hdlr(task); \
00337 adeos_propagate_event(p); \
00338 }
00339
00340 #define rthal_catch_taskexit(hdlr) \
00341 adeos_catch_event_from(adp_root,ADEOS_EXIT_PROCESS,hdlr)
00342 #define rthal_catch_sigwake(hdlr) \
00343 adeos_catch_event_from(adp_root,ADEOS_KICK_PROCESS,hdlr)
00344 #define rthal_catch_schedule(hdlr) \
00345 adeos_catch_event_from(adp_root,ADEOS_SCHEDULE_HEAD,hdlr)
00346 #define rthal_catch_setsched(hdlr) \
00347 adeos_catch_event_from(&rthal_domain,ADEOS_RENICE_PROCESS,hdlr)
00348 #define rthal_catch_losyscall(hdlr) \
00349 adeos_catch_event_from(adp_root,ADEOS_SYSCALL_PROLOGUE,hdlr)
00350 #define rthal_catch_hisyscall(hdlr) \
00351 adeos_catch_event_from(&rthal_domain,ADEOS_SYSCALL_PROLOGUE,hdlr)
00352 #define rthal_catch_exception(ex,hdlr) \
00353 adeos_catch_event_from(&rthal_domain,ex,hdlr)
00354
00355 #define rthal_register_domain(_dom,_name,_id,_prio,_entry) \
00356 ({ \
00357 adattr_t attr; \
00358 adeos_init_attr(&attr); \
00359 attr.name = _name; \
00360 attr.entry = _entry; \
00361 attr.domid = _id; \
00362 attr.priority = _prio; \
00363 adeos_register_domain(_dom,&attr); \
00364 })
00365
00366 #define rthal_unregister_domain(dom) adeos_unregister_domain(dom)
00367
00368 #if !defined(CONFIG_ADEOS_NOTHREADS)
00369 #define RTHAL_DECLARE_DOMAIN(entry) \
00370 void entry (int iflag) \
00371 { \
00372 if (iflag) \
00373 do_##entry();\
00374 for (;;) \
00375 rthal_suspend_domain(); \
00376 }
00377 #else
00378 #define RTHAL_DECLARE_DOMAIN(entry) \
00379 void entry (int iflag) \
00380 { \
00381 do_##entry(); \
00382 }
00383 #endif
00384
00385 extern void rthal_domain_entry(int iflag);
00386
00387 #endif
00388
00389 #define rthal_spin_lock_irq(lock) \
00390 do { \
00391 rthal_local_irq_disable(); \
00392 rthal_spin_lock(lock); \
00393 } while(0)
00394
00395 #define rthal_spin_unlock_irq(lock) \
00396 do { \
00397 rthal_spin_unlock(lock); \
00398 rthal_local_irq_enable(); \
00399 } while(0)
00400
00401 #define rthal_spin_lock_irqsave(lock,x) \
00402 do { \
00403 rthal_local_irq_save(x); \
00404 rthal_spin_lock(lock); \
00405 } while(0)
00406
00407 #define rthal_spin_unlock_irqrestore(lock,x) \
00408 do { \
00409 rthal_spin_unlock(lock); \
00410 rthal_local_irq_restore(x); \
00411 } while(0)
00412
00413 #define rthal_printk printk
00414
00415 typedef void (*rthal_irq_handler_t)(unsigned irq,
00416 void *cookie);
00417
00418 struct rthal_calibration_data {
00419
00420 unsigned long cpu_freq;
00421 unsigned long timer_freq;
00422 };
00423
00424 typedef int (*rthal_trap_handler_t)(unsigned trapno,
00425 unsigned domid,
00426 void *data);
00427
00428 extern unsigned long rthal_cpufreq_arg;
00429
00430 extern unsigned long rthal_timerfreq_arg;
00431
00432 extern rthal_pipeline_stage_t rthal_domain;
00433
00434 extern struct rthal_calibration_data rthal_tunables;
00435
00436 extern volatile int rthal_sync_op;
00437
00438 extern volatile unsigned long rthal_cpu_realtime;
00439
00440 extern rthal_trap_handler_t rthal_trap_handler;
00441
00442 extern int rthal_realtime_faults[RTHAL_NR_CPUS][RTHAL_NR_FAULTS];
00443
00444 extern int rthal_arch_init(void);
00445
00446 extern void rthal_arch_cleanup(void);
00447
00448
00449
00450 unsigned long rthal_critical_enter(void (*synch)(void));
00451
00452 void rthal_critical_exit(unsigned long flags);
00453
00454
00455
00456 #ifdef __cplusplus
00457 extern "C" {
00458 #endif
00459
00460 int rthal_irq_request(unsigned irq,
00461 void (*handler)(unsigned irq, void *cookie),
00462 int (*ackfn)(unsigned irq),
00463 void *cookie);
00464
00465 int rthal_irq_release(unsigned irq);
00466
00467 int rthal_irq_enable(unsigned irq);
00468
00469 int rthal_irq_disable(unsigned irq);
00470
00471 int rthal_irq_host_request(unsigned irq,
00472 irqreturn_t (*handler)(int irq,
00473 void *dev_id,
00474 struct pt_regs *regs),
00475 char *name,
00476 void *dev_id);
00477
00478 int rthal_irq_host_release(unsigned irq,
00479 void *dev_id);
00480
00481 int rthal_irq_host_pend(unsigned irq);
00482
00483 int rthal_apc_alloc(const char *name,
00484 void (*handler)(void *cookie),
00485 void *cookie);
00486
00487 int rthal_apc_free(int apc);
00488
00489 int rthal_apc_schedule(int apc);
00490
00491 int rthal_irq_affinity(unsigned irq,
00492 cpumask_t cpumask,
00493 cpumask_t *oldmask);
00494
00495 int rthal_timer_request(void (*handler)(void),
00496 unsigned long nstick);
00497
00498 void rthal_timer_release(void);
00499
00500 rthal_trap_handler_t rthal_trap_catch(rthal_trap_handler_t handler);
00501
00502 unsigned long rthal_timer_calibrate(void);
00503
00504 #ifdef __cplusplus
00505 }
00506 #endif
00507
00508 #endif
00509
00512 #endif