]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/ux/irq_chip_ux.cpp
Update
[l4.git] / kernel / fiasco / src / kern / ux / irq_chip_ux.cpp
1 INTERFACE:
2
3 #include "config.h"
4 #include <sys/poll.h>
5
6 #include "irq_chip_ux_base.h"
7 #include "irq_chip.h"
8 #include "irq_chip_ia32.h"
9 #include "irq_mgr.h"
10
11 class Irq_chip_ux :
12   public Irq_chip_ux_base,
13   public Irq_chip_icu,
14   private Irq_chip_ia32,
15   private Irq_mgr
16 {
17   friend class Irq_chip_ia32;
18 public:
19   bool reserve(Mword pin) override { return Irq_chip_ia32::reserve(pin); }
20   Irq_base *irq(Mword pin) const override { return Irq_chip_ia32::irq(pin); }
21   unsigned nr_irqs() const override { return Num_irqs; }
22   unsigned nr_msis() const override { return 0; }
23
24   void mask(Mword) override {}
25   void ack(Mword) override {}
26   void mask_and_ack(Mword) override {}
27   int set_mode(Mword, Mode) override { return 0; }
28   bool is_edge_triggered(Mword) const override { return false; }
29   void set_cpu(Mword, Cpu_number) override {}
30
31   Irq_mgr::Irq chip(Mword pin) const override
32   {
33     if (pin < Num_irqs)
34       return Irq(const_cast<Irq_chip_ux*>(this), pin);
35
36     return Irq();
37   }
38 };
39
40
41 IMPLEMENTATION:
42
43 #include <cassert>
44 #include <cstdlib>
45 #include <csignal>
46 #include <fcntl.h>
47
48 #include "boot_info.h"
49
50 PUBLIC
51 bool
52 Irq_chip_ux::alloc(Irq_base *irq, Mword irqn)
53 {
54   if (irqn >= Num_irqs)
55     return false;
56
57   // PIC uses 16 vectors from Base_vector statically
58   unsigned vector = _base_vect + irqn;
59   return valloc<Irq_chip_ux>(irq, irqn, vector);
60 }
61
62
63 PUBLIC
64 void
65 Irq_chip_ux::unmask(Mword pin)
66 {
67   assert (pin < Num_irqs);
68   auto &p = pfd[pin];
69   // If fd is zero, someone tried to activate an IRQ without provider
70   assert (p.fd);
71
72   int flags = fcntl(p.fd, F_GETFL);
73   if (   flags < 0
74       || fcntl(p.fd, F_SETFL, flags | O_NONBLOCK | O_ASYNC) < 0
75       || fcntl(p.fd, F_SETSIG, SIGIO) < 0
76       || fcntl(p.fd, F_SETOWN, Boot_info::pid()) < 0)
77     return;
78
79   p.events = POLLIN;
80   if (pin >= highest_irq)
81     highest_irq = pin + 1;
82 }
83 static void irq_prov_shutdown()
84 {
85   if (Irq_chip_ux::main)
86     Irq_chip_ux::main->shutdown();
87 }
88
89 PUBLIC
90 Irq_chip_ux::Irq_chip_ux(bool is_main) : Irq_chip_ia32(Num_irqs)
91 {
92   if (is_main)
93     {
94       main = this;
95       Irq_mgr::mgr = this;
96       atexit(irq_prov_shutdown);
97     }
98 }
99
100 // -----------------------------------------------------------------
101 IMPLEMENTATION [ux && debug]:
102
103 PUBLIC
104 char const *
105 Irq_chip_ux::chip_type() const
106 { return "UX"; }
107