]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libvbus/lib/src/vbus_pci.cc
update
[l4.git] / l4 / pkg / libvbus / lib / src / vbus_pci.cc
1 /*
2  * (c) 2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3  *          Alexander Warg <warg@os.inf.tu-dresden.de>
4  *     economic rights: Technische Universität Dresden (Germany)
5  *
6  * This file is part of TUD:OS and distributed under the terms of the
7  * GNU General Public License 2.
8  * Please see the COPYING-GPL-2 file for details.
9  */
10 #include <l4/vbus/vbus_pci.h>
11 #include <l4/vbus/vbus_generic>
12 #include <l4/cxx/ipc_stream>
13
14 int L4_CV
15 l4vbus_pci_cfg_read(l4_cap_idx_t vbus, l4vbus_device_handle_t handle,
16                     l4_uint32_t bus, l4_uint32_t devfn,
17                     l4_uint32_t reg, l4_uint32_t *value, l4_uint32_t width)
18 {
19   L4::Ipc_iostream s(l4_utcb());
20   l4vbus_device_msg(handle, 0, s);
21   s << bus << devfn << reg << width;
22   int err = l4_error(s.call(vbus));
23   if (err < 0)
24     return err;
25   s >> *value;
26   return 0;
27 }
28
29 int L4_CV
30 l4vbus_pci_cfg_write(l4_cap_idx_t vbus, l4vbus_device_handle_t handle,
31                      l4_uint32_t bus, l4_uint32_t devfn,
32                      l4_uint32_t reg, l4_uint32_t value, l4_uint32_t width)
33 {
34   L4::Ipc_iostream s(l4_utcb());
35   l4vbus_device_msg(handle, 1, s);
36   s << bus << devfn << reg << value << width;
37   return l4_error(s.call(vbus));
38 }
39
40 int L4_CV
41 l4vbus_pci_irq_enable(l4_cap_idx_t vbus, l4vbus_device_handle_t handle,
42                       l4_uint32_t bus, l4_uint32_t devfn,
43                       int pin, unsigned char *trigger, unsigned char *polarity)
44 {
45   int irq;
46   L4::Ipc_iostream s(l4_utcb());
47   l4vbus_device_msg(handle, 2, s);
48   s << bus << devfn << pin;
49   int err = l4_error(s.call(vbus));
50   if (err < 0)
51     return err;
52
53   s >> irq >> *trigger >> *polarity;
54   return irq;
55 }
56
57