]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/io/server/src/vpci_root_bridge.cc
update
[l4.git] / l4 / pkg / io / server / src / vpci_root_bridge.cc
1 /*
2  * (c) 2010 Alexander Warg <warg@os.inf.tu-dresden.de>
3  *     economic rights: Technische Universität Dresden (Germany)
4  *
5  * This file is part of TUD:OS and distributed under the terms of the
6  * GNU General Public License 2.
7  * Please see the COPYING-GPL-2 file for details.
8  */
9
10 #include "vdevice.h"
11 #include "vpci.h"
12
13 // ------------------------------------------------------------------------
14 // Proxy for a real PCI root bridge
15 // ------------------------------------------------------------------------
16
17 class VPci_root : public VDevice
18 {
19 public:
20
21   int vbus_dispatch(l4_umword_t, l4_uint32_t func, L4::Ipc::Iostream &ios);
22
23   explicit VPci_root() : VDevice() {}
24
25   ~VPci_root() {}
26
27   char const *hid() const
28   {
29     return "PNP0A03";
30   }
31
32 public:
33   int cfg_read(L4::Ipc::Iostream &ios);
34   int cfg_write(L4::Ipc::Iostream &ios);
35   int irq_enable(L4::Ipc::Iostream &ios);
36 };
37
38
39 // IMPLEMENTATION --------------------------------------------------------
40
41 int
42 VPci_root::cfg_read(L4::Ipc::Iostream &ios)
43 {
44   l4_uint32_t bus;
45   l4_uint32_t devfn;
46   l4_uint32_t reg;
47   l4_uint32_t value;
48   l4_uint32_t width;
49
50   ios >> bus >> devfn >> reg >> width;
51
52   int res = pci_root_bridge(0)->cfg_read(bus, devfn, reg, &value, Pci::cfg_w_to_o(width));
53   if (res < 0)
54     return res;
55
56   ios << value;
57   return L4_EOK;
58 }
59
60 int
61 VPci_root::irq_enable(L4::Ipc::Iostream &ios)
62 {
63 #if 0
64   l4_uint32_t bus;
65   l4_uint32_t devfn;
66   int pin;
67
68   ios >> bus >> devfn >> pin;
69   // printf("get IRQ for %02x:%02x.%x: pin INT%c\n", bus, devfn >> 16, devfn & 0xffff, pin + 'A');
70   struct acpica_pci_irq *irq = 0;
71   int res = acpica_pci_irq_find(0, bus, devfn >> 16, pin, &irq);
72   if (res < 0)
73     {
74       ios << (int)-1;
75       return res;
76     }
77
78   if (!irq)
79     {
80       ios << (int)-1;
81       return -L4_EINVAL;
82     }
83
84   ios << irq->irq << irq->trigger << irq->polarity;
85 #endif
86   return L4_EOK;
87 }
88
89 int
90 VPci_root::cfg_write(L4::Ipc::Iostream &ios)
91 {
92   l4_uint32_t bus;
93   l4_uint32_t devfn;
94   l4_uint32_t reg;
95   l4_uint32_t value;
96   l4_uint32_t width;
97
98   ios >> bus >> devfn >> reg >> value >> width;
99
100   int res = pci_root_bridge(0)->cfg_write(bus, devfn, reg, value, Pci::cfg_w_to_o(width));
101   if (res < 0)
102     return res;
103
104   return L4_EOK;
105 }
106
107 int
108 VPci_root::vbus_dispatch(l4_umword_t, l4_uint32_t func, L4::Ipc::Iostream &ios)
109 {
110   switch (func)
111     {
112     case 0: return cfg_read(ios);
113     case 1: return cfg_write(ios);
114     case 2: return irq_enable(ios);
115     default: return -L4_ENOSYS;
116     }
117 }
118