xref: /titanic_41/usr/src/cmd/hal/hald/solaris/devinfo_misc.c (revision 058561cbaa119a6f2659bc27ef343e1b47266bb2)
1 /***************************************************************************
2  *
3  * devinfo_misc : misc devices
4  *
5  * Copyright 2006 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.bus", "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 	devinfo_add_enqueue (d, devfs_path, &devinfo_computer_handler);
85 
86 	/* all devinfo devices belong to the 'local' branch */
87 	local_d = hal_device_new ();
88 
89 	hal_device_property_set_string (local_d, "info.parent", hal_device_get_udi (d));
90         hal_device_property_set_string (local_d, "info.bus", "unknown");
91         hal_device_property_set_string (local_d, "info.product", "Local devices");
92         hal_device_property_set_string (local_d, "info.udi", "/org/freedesktop/Hal/devices/local");
93         hal_device_set_udi (local_d, "/org/freedesktop/Hal/devices/local");
94 	hal_device_property_set_string (local_d, "solaris.devfs_path", "/local");
95 
96 	devinfo_add_enqueue (local_d, "/local", &devinfo_default_handler);
97 
98 	return (local_d);
99 }
100 
101 static HalDevice *
102 devinfo_cpu_add(HalDevice *parent, di_node_t node, char *devfs_path, char *device_type)
103 {
104 	HalDevice *d;
105 
106 	if ((device_type == NULL) || (strcmp(device_type, "cpu") != 0)) {
107 		return (NULL);
108 	}
109 
110 	d = hal_device_new ();
111 
112 	devinfo_set_default_properties (d, parent, node, devfs_path);
113 	hal_device_add_capability (d, "processor");
114 
115 	devinfo_add_enqueue (d, devfs_path, &devinfo_cpu_handler);
116 
117 	return (d);
118 }
119 
120 static HalDevice *
121 devinfo_default_add(HalDevice *parent, di_node_t node, char *devfs_path, char *device_type)
122 {
123 	char *driver_name;
124 	const char *parent_path;
125 	HalDevice *d;
126 
127 	/* ignore all children of the 'pseudo' node except lofi */
128 	if (parent != NULL) {
129 		parent_path = hal_device_property_get_string(parent, "solaris.devfs_path");
130 		if ((parent_path != NULL) &&
131 		    (strcmp (parent_path, "/pseudo") == 0)) {
132 			driver_name = di_driver_name (node);
133 			if ((driver_name != NULL) &&
134 			    (strcmp (driver_name, "lofi") != 0)) {
135 				return (NULL);
136 			}
137 		}
138 	}
139 
140 	d = hal_device_new ();
141 
142 	devinfo_set_default_properties (d, parent, node, devfs_path);
143 
144 	devinfo_add_enqueue (d, devfs_path, &devinfo_default_handler);
145 
146 	return (d);
147 }
148