]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/ia32/ipi-ia32.cpp
update
[l4.git] / kernel / fiasco / src / kern / ia32 / ipi-ia32.cpp
1 INTERFACE [mp]:
2
3 #include "per_cpu_data.h"
4
5 EXTENSION class Ipi
6 {
7 private:
8   Unsigned32 _apic_id;
9   unsigned _count;
10
11 public:
12   enum Message
13   {
14     Request        = APIC_IRQ_BASE - 1,
15     Global_request = APIC_IRQ_BASE + 2,
16     Debug          = APIC_IRQ_BASE - 2
17   };
18 };
19
20
21 //---------------------------------------------------------------------------
22 IMPLEMENTATION[mp]:
23
24 #include <cstdio>
25 #include "apic.h"
26 #include "kmem.h"
27
28 PUBLIC inline
29 Ipi::Ipi() : _apic_id(~0)
30 {}
31
32
33 /**
34  * \param cpu the logical CPU number of the current CPU.
35  * \pre cpu == current CPU.
36  */
37 IMPLEMENT static inline NEEDS["apic.h"]
38 void
39 Ipi::init(unsigned cpu)
40 {
41   _ipi.cpu(cpu)._apic_id = Apic::get_id();
42 }
43
44
45 PUBLIC static inline
46 void
47 Ipi::ipi_call_debug_arch()
48 {
49   //ipi_call_spin(); // debug
50 }
51
52 PUBLIC static inline NEEDS["apic.h"]
53 void
54 Ipi::eoi(Message, unsigned cpu)
55 {
56   Apic::mp_ipi_ack();
57   stat_received(cpu);
58 }
59
60 PUBLIC static inline NEEDS["apic.h"]
61 void
62 Ipi::send(Message m, unsigned from_cpu, unsigned to_cpu)
63 {
64   Apic::mp_send_ipi(_ipi.cpu(to_cpu)._apic_id, (Unsigned8)m);
65   stat_sent(from_cpu);
66 }
67
68 PUBLIC static inline NEEDS["apic.h"]
69 void
70 Ipi::bcast(Message m, unsigned from_cpu)
71 {
72   (void)from_cpu;
73   Apic::mp_send_ipi(Apic::APIC_IPI_OTHERS, (Unsigned8)m);
74 }
75
76 #if defined(CONFIG_IRQ_SPINNER)
77
78 // debug
79 PRIVATE static
80 void Ipi::ipi_call_spin()
81 {
82   unsigned cpu;
83   Ipi *ipi = 0;
84   for (cpu = 0; cpu < Config::Max_num_cpus; ++cpu)
85     {
86       if (!Per_cpu_data::valid(cpu))
87         continue;
88
89       if (_ipi.cpu(cpu)._apic_id == Apic::get_id())
90         {
91           ipi = &_ipi.cpu(cpu);
92           break;
93         }
94     }
95
96   if (!ipi)
97     return;
98
99   *(unsigned char*)(Mem_layout::Adap_vram_cga_beg + 22*160 + cpu*+2)
100     = '0' + (ipi->_count++ % 10);
101 }
102 #endif
103