]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/kernel_uart-libuart.cpp
update
[l4.git] / kernel / fiasco / src / kern / kernel_uart-libuart.cpp
1 IMPLEMENTATION [libuart]:
2
3 #include "kmem.h"
4 #include "io_regblock.h"
5
6 //------------------------------------------------------------------------
7 IMPLEMENTATION [libuart && serial && io]:
8
9 #include "io_regblock_port.h"
10
11 namespace {
12
13 union Regs
14 {
15   Static_object<L4::Io_register_block_port> io;
16   Static_object<L4::Io_register_block_mmio> mem;
17 };
18
19 static bool
20 setup_uart_io_port(Regs *regs, Address base, int irq)
21 {
22   regs->io.construct(base);
23   return Kernel_uart::uart()->startup(regs->io.get(), irq,
24                                       Koptions::o()->uart.base_baud);
25 }
26
27 }
28
29 //------------------------------------------------------------------------
30 IMPLEMENTATION [libuart && serial && !io]:
31
32 namespace {
33
34 struct Regs
35 {
36   Static_object<L4::Io_register_block_mmio> mem;
37 };
38
39 static bool
40 setup_uart_io_port(Regs *, Address, int)
41 {
42   panic ("cannot use IO-Port based uart\n");
43 }
44
45 }
46
47 //------------------------------------------------------------------------
48 IMPLEMENTATION [libuart && serial]:
49
50 IMPLEMENT
51 bool
52 Kernel_uart::init_for_mode(Init_mode init_mode)
53 {
54   if (Koptions::o()->uart.access_type == Koptions::Uart_type_ioport)
55     return init_mode == Init_before_mmu;
56   else
57     return init_mode == Init_after_mmu;
58 }
59
60 IMPLEMENT
61 bool Kernel_uart::startup(unsigned, int irq)
62 {
63   static Regs regs;
64
65   if (Koptions::o()->opt(Koptions::F_uart_base))
66     {
67       Address base = Koptions::o()->uart.base_address;
68       switch (Koptions::o()->uart.access_type)
69         {
70         case Koptions::Uart_type_ioport:
71           return setup_uart_io_port(&regs, base, irq);
72
73         case Koptions::Uart_type_mmio:
74           regs.mem.construct(Kmem::mmio_remap(base),
75                              Koptions::o()->uart.reg_shift);
76           return uart()->startup(regs.mem.get(), irq,
77                                  Koptions::o()->uart.base_baud);
78         default:
79           return false;
80         }
81     }
82
83   return false;
84 }