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
|
/***************************************************************************
*
* devinfo_misc : misc devices
*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Licensed under the Academic Free License version 2.1
*
**************************************************************************/
#include <sys/types.h>
#include <sys/sysctl.h>
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <sys/utsname.h>
#include <stdio.h>
#include <string.h>
#include "../osspec.h"
#include "../logger.h"
#include "../hald.h"
#include "../hald_dbus.h"
#include "../device_info.h"
#include "../util.h"
#include "devinfo_misc.h"
#include "drvctl.h"
static HalDevice *devinfo_computer_add(HalDevice *, const char *, char *, char *);
static HalDevice *devinfo_cpu_add(HalDevice *, const char *, char *,char *);
static HalDevice *devinfo_default_add(HalDevice *, const char *, char *, char *);
DevinfoDevHandler devinfo_computer_handler = {
devinfo_computer_add,
NULL,
NULL,
NULL,
NULL,
NULL
};
DevinfoDevHandler devinfo_cpu_handler = {
devinfo_cpu_add,
NULL,
NULL,
NULL,
NULL,
NULL
};
DevinfoDevHandler devinfo_default_handler = {
devinfo_default_add,
NULL,
NULL,
NULL,
NULL,
NULL
};
static HalDevice *
devinfo_computer_add(HalDevice *parent, const char *devnode, char *devfs_path, char *device_type)
{
HalDevice *d;
struct utsname un;
char acpi_supported_states[20];
size_t len = sizeof(acpi_supported_states);
if (strcmp (devnode, "mainbus0") != 0 && strcmp (devnode, "armfdt0") != 0) {
return (NULL);
}
HAL_INFO (("devinfo_computer_add parent=%p devnode=%s devfs_path=%s device_type=%s",
parent, devnode, devfs_path, device_type));
d = hal_device_new ();
hal_device_property_set_string (d, "info.subsystem", "unknown");
hal_device_property_set_string (d, "info.product", "Computer");
hal_device_set_udi (d, "/org/freedesktop/Hal/devices/computer");
hal_device_property_set_string (d, "netbsd.device", devnode);
if (uname (&un) >= 0) {
hal_device_property_set_string (d, "system.kernel.name", un.sysname);
hal_device_property_set_string (d, "system.kernel.version", un.release);
hal_device_property_set_string (d, "system.kernel.machine", un.machine);
}
devinfo_add_enqueue (d, devfs_path, &devinfo_computer_handler);
if (sysctlbyname ("hw.acpi.supported_states", acpi_supported_states, &len, NULL, 0) == 0 ||
sysctlbyname ("hw.acpi.sleep.states", acpi_supported_states, &len, NULL, 0) == 0) {
hal_device_property_set_string (d, "power_management.type", "acpi");
if (strstr (acpi_supported_states, "S3") != NULL)
hal_device_property_set_bool (d, "power_management.can_suspend", TRUE);
else
hal_device_property_set_bool (d, "power_management.can_suspend", FALSE);
hal_device_property_set_bool (d, "power_management.can_hibernate", FALSE);
}
if (drvctl_find_device ("acpibat0", NULL) == TRUE)
hal_device_property_set_string (d, "system.formfactor", "laptop");
else
hal_device_property_set_string (d, "system.formfactor", "desktop"); /* XXX */
devinfo_add_enqueue (d, devnode, &devinfo_default_handler);
return d;
}
static HalDevice *
devinfo_cpu_add(HalDevice *parent, const char *devnode, char *devfs_path, char *device_type)
{
HalDevice *d;
if (strncmp(devnode, "cpu", 3) != 0) {
return (NULL);
}
if (devnode[3] < '0' || devnode[3] > '9') {
return (NULL);
}
HAL_INFO (("devinfo_cpu_add: parent=%p devnode=%s devfs_path=%s device_type=%s",
parent, devnode, devfs_path, device_type));
d = hal_device_new ();
devinfo_set_default_properties (d, parent, devnode, devnode);
hal_device_add_capability (d, "processor");
devinfo_add_enqueue (d, devnode, &devinfo_cpu_handler);
return (d);
}
static void
devinfo_default_apply_quirks(HalDevice *d, const char *devnode)
{
/* acpiacad(4) */
if (strncmp (devnode, "acpiacad", 8) == 0) {
HAL_INFO (("%s: applying acpiacad quirks",devnode));
hal_device_add_capability (d, "ac_adapter");
/* acpibat(4) */
} else if (strncmp (devnode, "acpibat", 7) == 0) {
HAL_INFO (("%s: applying acpibat quirks",devnode));
hal_device_add_capability (d, "battery");
hal_device_property_set_string (d, "battery.type", "primary");
}
}
static HalDevice *
devinfo_default_add(HalDevice *parent, const char *devnode, char *devfs_path, char *device_type)
{
char *driver_name;
const char *parent_path;
HalDevice *d;
d = hal_device_new ();
devinfo_set_default_properties (d, parent, devnode, devnode);
devinfo_default_apply_quirks (d, devnode);
devinfo_add_enqueue (d, devnode, &devinfo_default_handler);
return (d);
}
|