1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
/***************************************************************************
*
* devinfo_acpi : acpi devices
*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Licensed under the Academic Free License version 2.1
*
**************************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <string.h>
#include <sys/utsname.h>
#include <libdevinfo.h>
#include <sys/mkdev.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/sysevent/dev.h>
#include <sys/sysevent/pwrctl.h>
#include "../osspec.h"
#include "../logger.h"
#include "../hald.h"
#include "../hald_dbus.h"
#include "../device_info.h"
#include "../util.h"
#include "../hald_runner.h"
#include "devinfo_acpi.h"
#define DEVINFO_PROBE_ACPI_TIMEOUT 30000
static HalDevice *devinfo_acpi_add(HalDevice *, di_node_t, char *, char *);
static HalDevice *devinfo_power_button_add(HalDevice *parent, di_node_t node,
char *devfs_path, char *device_type);
static void devinfo_battery_rescan_probing_done(HalDevice *d, guint32 exit_type,
gint return_code, char **error, gpointer userdata1, gpointer userdata2);
DevinfoDevHandler devinfo_acpi_handler = {
devinfo_acpi_add,
NULL,
NULL,
NULL,
NULL,
devinfo_acpi_get_prober
};
DevinfoDevHandler devinfo_power_button_handler = {
devinfo_power_button_add,
NULL,
NULL,
NULL,
NULL,
NULL
};
static HalDevice *
devinfo_acpi_add(HalDevice *parent, di_node_t node, char *devfs_path,
char *device_type)
{
HalDevice *d, *computer;
char *driver_name;
di_devlink_handle_t devlink_hdl;
int major;
di_minor_t minor;
dev_t dev;
char *minor_path = NULL;
char *devpath;
driver_name = di_driver_name(node);
if ((driver_name == NULL) || (strcmp(driver_name, "acpi_drv") != 0)) {
return (NULL);
}
d = hal_device_new();
if ((computer = hal_device_store_find(hald_get_gdl(),
"/org/freedesktop/Hal/devices/computer")) ||
(computer = hal_device_store_find(hald_get_tdl(),
"/org/freedesktop/Hal/devices/computer"))) {
hal_device_property_set_string(computer,
"system.formfactor", "laptop");
hal_device_property_set_string(computer,
"power_management.type", "acpi");
}
devinfo_set_default_properties(d, parent, node, devfs_path);
devinfo_add_enqueue(d, devfs_path, &devinfo_acpi_handler);
major = di_driver_major(node);
if ((devlink_hdl = di_devlink_init(NULL, 0)) == NULL) {
return (d);
}
minor = DI_MINOR_NIL;
while ((minor = di_minor_next(node, minor)) != DI_MINOR_NIL) {
dev = di_minor_devt(minor);
if ((major != major(dev)) ||
(di_minor_type(minor) != DDM_MINOR) ||
(di_minor_spectype(minor) != S_IFCHR) ||
((minor_path = di_devfs_minor_path(minor)) == NULL)) {
continue;
}
if (hal_device_store_match_key_value_string(hald_get_gdl(),
"solaris.devfs_path", minor_path) == NULL) {
devinfo_acpi_add_minor(d, node, minor_path, dev);
}
di_devfs_path_free(minor_path);
}
di_devlink_fini(&devlink_hdl);
return (d);
}
void
devinfo_acpi_add_minor(HalDevice *parent, di_node_t node, char *minor_path,
dev_t dev)
{
HalDevice *d;
d = hal_device_new();
devinfo_set_default_properties(d, parent, node, minor_path);
devinfo_add_enqueue(d, minor_path, &devinfo_acpi_handler);
}
static HalDevice *
devinfo_power_button_add(HalDevice *parent, di_node_t node, char *devfs_path,
char *device_type)
{
HalDevice *d;
char *driver_name;
driver_name = di_driver_name(node);
if ((driver_name == NULL) || (strcmp(driver_name, "power") != 0)) {
return (NULL);
}
d = hal_device_new();
devinfo_set_default_properties(d, parent, node, devfs_path);
hal_device_add_capability(d, "button");
hal_device_property_set_bool(d, "button.has_state", FALSE);
hal_device_property_set_string(d, "info.category", "input");
hal_device_property_set_string(d, "button.type", "power");
hal_device_property_set_string(d, "info.product", "Power Button");
devinfo_add_enqueue(d, devfs_path, &devinfo_power_button_handler);
return (d);
}
void
devinfo_power_button_event(void)
{
HalDevice *d = NULL;
HalDeviceStore *store = hald_get_gdl();
d = hal_device_store_match_key_value_string (store, "button.type",
"power");
if (d != NULL) {
device_send_signal_condition(d, "ButtonPressed", "power");
}
}
void
devinfo_brightness_hotkeys_event(char *subclass)
{
HalDevice *d = NULL;
if ((d = hal_device_store_find(hald_get_gdl(),
"/org/freedesktop/Hal/devices/computer")) ||
(d = hal_device_store_find(hald_get_tdl(),
"/org/freedesktop/Hal/devices/computer"))) {
if (strcmp(subclass, ESC_PWRCTL_BRIGHTNESS_UP) == 0) {
device_send_signal_condition(d, "ButtonPressed",
"brightness-up");
} else {
device_send_signal_condition(d, "ButtonPressed",
"brightness-down");
}
}
}
void
devinfo_battery_rescan(char *parent_devfs_path, gchar *udi)
{
HalDevice *d = NULL;
d = hal_device_store_find(hald_get_gdl(), udi);
if (d == NULL) {
HAL_INFO(("device not found %s", udi));
return;
}
hald_runner_run(d, "hald-probe-acpi", NULL,
DEVINFO_PROBE_ACPI_TIMEOUT, devinfo_battery_rescan_probing_done,
NULL, NULL);
}
void
devinfo_lid_event(char *subclass, gchar *udi)
{
HalDevice *d = NULL;
d = hal_device_store_find(hald_get_gdl(), udi);
if (d == NULL) {
HAL_INFO(("device not found %s", udi));
return;
}
hal_device_property_set_bool(d, "button.state.value",
(strcmp(subclass, ESC_PWRCTL_REMOVE) == 0));
device_send_signal_condition(d, "ButtonPressed", "lid");
}
gboolean
devinfo_lid_rescan(HalDevice *d)
{
if (hal_device_property_get_bool(d, "button.workaround")) {
/* Set lid state to open for workaround */
hal_device_property_set_bool(d, "button.state.value", FALSE);
} else {
hald_runner_run(d, "hald-probe-acpi", NULL,
DEVINFO_PROBE_ACPI_TIMEOUT,
devinfo_battery_rescan_probing_done, NULL, NULL);
}
return (TRUE);
}
static void
devinfo_battery_rescan_probing_done(HalDevice *d, guint32 exit_type,
gint return_code, char **error, gpointer userdata1, gpointer userdata2)
{
/* hald_runner_run() requires this function since cannot pass NULL */
}
const gchar *
devinfo_acpi_get_prober(HalDevice *d, int *timeout)
{
*timeout = DEVINFO_PROBE_ACPI_TIMEOUT; /* 30 second timeout */
return ("hald-probe-acpi");
}
|