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