xref: /titanic_52/usr/src/cmd/hal/hald/solaris/devinfo_misc.c (revision eb0cc229f19c437a6b538d3ac0d0443268290b7e)
1 /***************************************************************************
2  *
3  * devinfo_misc : misc devices
4  *
5  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
6  * Use is subject to license terms.
7  *
8  * Licensed under the Academic Free License version 2.1
9  *
10  **************************************************************************/
11 
12 #pragma ident	"%Z%%M%	%I%	%E% SMI"
13 
14 #ifdef HAVE_CONFIG_H
15 #  include <config.h>
16 #endif
17 
18 #include <stdio.h>
19 #include <string.h>
20 #include <sys/utsname.h>
21 #include <libdevinfo.h>
22 
23 #include "../osspec.h"
24 #include "../logger.h"
25 #include "../hald.h"
26 #include "../hald_dbus.h"
27 #include "../device_info.h"
28 #include "../util.h"
29 #include "devinfo_misc.h"
30 
31 static HalDevice *devinfo_computer_add(HalDevice *, di_node_t, char *, char *);
32 static HalDevice *devinfo_cpu_add(HalDevice *, di_node_t, char *,char *);
33 static HalDevice *devinfo_default_add(HalDevice *, di_node_t, char *, char *);
34 
35 DevinfoDevHandler devinfo_computer_handler = {
36         devinfo_computer_add,
37 	NULL,
38 	NULL,
39 	NULL,
40 	NULL,
41         NULL
42 };
43 DevinfoDevHandler devinfo_cpu_handler = {
44         devinfo_cpu_add,
45 	NULL,
46 	NULL,
47 	NULL,
48 	NULL,
49         NULL
50 };
51 DevinfoDevHandler devinfo_default_handler = {
52         devinfo_default_add,
53 	NULL,
54 	NULL,
55 	NULL,
56 	NULL,
57         NULL
58 };
59 
60 static HalDevice *
61 devinfo_computer_add(HalDevice *parent, di_node_t node, char *devfs_path, char *device_type)
62 {
63 	HalDevice *d, *local_d;
64 	struct utsname un;
65 
66 	if (strcmp (devfs_path, "/") != 0) {
67 		return (NULL);
68 	}
69 
70 	d = hal_device_new ();
71 
72         hal_device_property_set_string (d, "info.subsystem", "unknown");
73         hal_device_property_set_string (d, "info.product", "Computer");
74         hal_device_property_set_string (d, "info.udi", "/org/freedesktop/Hal/devices/computer");
75         hal_device_set_udi (d, "/org/freedesktop/Hal/devices/computer");
76 	hal_device_property_set_string (d, "solaris.devfs_path", devfs_path);
77 
78 	if (uname (&un) >= 0) {
79 		hal_device_property_set_string (d, "system.kernel.name", un.sysname);
80 		hal_device_property_set_string (d, "system.kernel.version", un.release);
81 		hal_device_property_set_string (d, "system.kernel.machine", un.machine);
82 	}
83 
84 	/*
85 	 * Let computer be in TDL while synthesizing all other events
86 	 * because some may write to the object
87 	 */
88         hal_device_store_add (hald_get_tdl (), d);
89 
90 	devinfo_add_enqueue (d, devfs_path, &devinfo_computer_handler);
91 
92 	/* all devinfo devices belong to the 'local' branch */
93 	local_d = hal_device_new ();
94 
95 	hal_device_property_set_string (local_d, "info.parent", hal_device_get_udi (d));
96         hal_device_property_set_string (local_d, "info.subsystem", "unknown");
97         hal_device_property_set_string (local_d, "info.product", "Local devices");
98         hal_device_property_set_string (local_d, "info.udi", "/org/freedesktop/Hal/devices/local");
99         hal_device_set_udi (local_d, "/org/freedesktop/Hal/devices/local");
100 	hal_device_property_set_string (local_d, "solaris.devfs_path", "/local");
101 
102 	devinfo_add_enqueue (local_d, "/local", &devinfo_default_handler);
103 
104 	return (local_d);
105 }
106 
107 static HalDevice *
108 devinfo_cpu_add(HalDevice *parent, di_node_t node, char *devfs_path, char *device_type)
109 {
110 	HalDevice *d;
111 
112 	if ((device_type == NULL) || (strcmp(device_type, "cpu") != 0)) {
113 		return (NULL);
114 	}
115 
116 	d = hal_device_new ();
117 
118 	devinfo_set_default_properties (d, parent, node, devfs_path);
119 	hal_device_add_capability (d, "processor");
120 
121 	devinfo_add_enqueue (d, devfs_path, &devinfo_cpu_handler);
122 
123 	return (d);
124 }
125 
126 static HalDevice *
127 devinfo_default_add(HalDevice *parent, di_node_t node, char *devfs_path, char *device_type)
128 {
129 	char *driver_name;
130 	const char *parent_path;
131 	HalDevice *d;
132 
133 	/* ignore all children of the 'pseudo' node except lofi */
134 	if (parent != NULL) {
135 		parent_path = hal_device_property_get_string(parent, "solaris.devfs_path");
136 		if ((parent_path != NULL) &&
137 		    (strcmp (parent_path, "/pseudo") == 0)) {
138 			driver_name = di_driver_name (node);
139 			if ((driver_name != NULL) &&
140 			    (strcmp (driver_name, "lofi") != 0)) {
141 				return (NULL);
142 			}
143 		}
144 	}
145 
146 	d = hal_device_new ();
147 
148 	devinfo_set_default_properties (d, parent, node, devfs_path);
149 
150 	devinfo_add_enqueue (d, devfs_path, &devinfo_default_handler);
151 
152 	return (d);
153 }
154