]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/io/io/server/src/io_acpi.h
Update
[l4.git] / l4 / pkg / io / io / server / src / io_acpi.h
1 /*
2  * (c) 2013 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 #pragma once
10
11 #include "hw_device.h"
12 #include "irqs.h"
13 #include "pci.h"
14
15 extern "C" {
16 #include "acpi.h"
17 #include "accommon.h"
18 }
19
20 template<typename T>
21 class Acpi_ptr
22 {
23 public:
24   Acpi_ptr(Acpi_ptr const &) = delete;
25   Acpi_ptr &operator = (Acpi_ptr const &) = delete;
26
27   explicit Acpi_ptr(T *p = 0) : _p(p) {}
28   ~Acpi_ptr()
29   {
30     if (!_p)
31       return;
32
33     ACPI_FREE(_p);
34   }
35
36   T &operator * () const { return *_p; }
37   T *operator -> () const { return _p; }
38
39   T **ref() { return &_p; }
40   T *get() const { return _p; }
41 private:
42   T *_p;
43 };
44
45 struct Acpi_auto_buffer : ACPI_BUFFER
46 {
47   Acpi_auto_buffer() { Pointer = 0; Length = 0; }
48   ~Acpi_auto_buffer()
49   {
50     if (Pointer)
51       ACPI_FREE(Pointer);
52   }
53
54   void *release() { void *r = Pointer; Pointer = 0; return r; }
55 };
56
57 template<typename T>
58 struct Acpi_buffer : ACPI_BUFFER
59 {
60   T value;
61   Acpi_buffer()
62   {
63     Pointer = &value;
64     Length  = sizeof(value);
65   }
66 };
67
68 struct Acpi_walk
69 {
70   ACPI_WALK_CALLBACK cb;
71   void *ctxt;
72
73   template<typename Functor>
74   Acpi_walk(Functor f)
75   : cb(invoke<Functor>), ctxt(reinterpret_cast<void*>(&f))
76   {}
77
78   ACPI_STATUS walk(ACPI_OBJECT_TYPE type, ACPI_HANDLE root, unsigned max_depth)
79   {
80     return AcpiWalkNamespace(type, root, max_depth, cb, 0, ctxt, 0);
81   }
82
83 private:
84
85   template< typename Functor >
86   static ACPI_STATUS invoke(ACPI_HANDLE obj, l4_uint32_t level, void *ctxt, void **)
87   {
88     return (*reinterpret_cast<typename cxx::remove_reference<Functor>::type *>(ctxt))(obj, level);
89   }
90 };
91
92
93 namespace Hw {
94
95 class Acpi_dev :
96   public Hw::Dev_feature
97 {
98 public:
99   enum { Acpi_event = 0x8 };
100
101   Acpi_dev(ACPI_HANDLE obj)
102   : _obj(obj), _have_notification_handler(false) {}
103
104   ACPI_HANDLE handle() const { return _obj; }
105
106   void discover_crs(Hw::Device *host);
107   void enable_notifications(Hw::Device *host);
108   void disable_notifications(Hw::Device *host);
109
110 protected:
111   ACPI_HANDLE _obj;
112   bool _have_notification_handler;
113 };
114
115 struct Acpi_device_driver
116 {
117   virtual Acpi_dev *probe(Hw::Device *device, ACPI_HANDLE acpi_hdl,
118                           ACPI_DEVICE_INFO const *info);
119   virtual ~Acpi_device_driver() = 0;
120
121   static bool register_driver(char const *hid, Acpi_device_driver *driver);
122   static bool register_driver(unsigned short type, Acpi_device_driver *driver);
123   static Acpi_device_driver* find(char const *hid);
124   static Acpi_device_driver* find(unsigned short type);
125 };
126
127 inline Acpi_device_driver::~Acpi_device_driver() {}
128
129 namespace Acpi {
130
131 void register_sci(Io_irq_pin *sci);
132
133 }
134 }
135
136 unsigned acpi_get_debug_level();
137
138 extern Hw::Pci::Root_bridge *
139   (*acpi_create_pci_root_bridge)(int, int busnum, Hw::Device *device);