12912Sartem /*************************************************************************** 22912Sartem * 32912Sartem * devinfo_misc : misc devices 42912Sartem * 52912Sartem * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 62912Sartem * Use is subject to license terms. 72912Sartem * 82912Sartem * Licensed under the Academic Free License version 2.1 92912Sartem * 102912Sartem **************************************************************************/ 112912Sartem 122916Sartem #pragma ident "%Z%%M% %I% %E% SMI" 132912Sartem 14*3121Sartem #ifdef HAVE_CONFIG_H 15*3121Sartem # include <config.h> 16*3121Sartem #endif 17*3121Sartem 182912Sartem #include <stdio.h> 192912Sartem #include <string.h> 202912Sartem #include <sys/utsname.h> 212912Sartem #include <libdevinfo.h> 222912Sartem 232912Sartem #include "../osspec.h" 242912Sartem #include "../logger.h" 252912Sartem #include "../hald.h" 262912Sartem #include "../hald_dbus.h" 272912Sartem #include "../device_info.h" 282912Sartem #include "../util.h" 292912Sartem #include "devinfo_misc.h" 302912Sartem 312912Sartem static HalDevice *devinfo_computer_add(HalDevice *, di_node_t, char *, char *); 322912Sartem static HalDevice *devinfo_cpu_add(HalDevice *, di_node_t, char *,char *); 332912Sartem static HalDevice *devinfo_default_add(HalDevice *, di_node_t, char *, char *); 342912Sartem 352912Sartem DevinfoDevHandler devinfo_computer_handler = { 362912Sartem devinfo_computer_add, 372912Sartem NULL, 382912Sartem NULL, 392912Sartem NULL, 402912Sartem NULL, 412912Sartem NULL 422912Sartem }; 432912Sartem DevinfoDevHandler devinfo_cpu_handler = { 442912Sartem devinfo_cpu_add, 452912Sartem NULL, 462912Sartem NULL, 472912Sartem NULL, 482912Sartem NULL, 492912Sartem NULL 502912Sartem }; 512912Sartem DevinfoDevHandler devinfo_default_handler = { 522912Sartem devinfo_default_add, 532912Sartem NULL, 542912Sartem NULL, 552912Sartem NULL, 562912Sartem NULL, 572912Sartem NULL 582912Sartem }; 592912Sartem 602912Sartem static HalDevice * 612912Sartem devinfo_computer_add(HalDevice *parent, di_node_t node, char *devfs_path, char *device_type) 622912Sartem { 632912Sartem HalDevice *d, *local_d; 642912Sartem struct utsname un; 652912Sartem 662912Sartem if (strcmp (devfs_path, "/") != 0) { 672912Sartem return (NULL); 682912Sartem } 692912Sartem 702912Sartem d = hal_device_new (); 712912Sartem 722912Sartem hal_device_property_set_string (d, "info.bus", "unknown"); 732912Sartem hal_device_property_set_string (d, "info.product", "Computer"); 742912Sartem hal_device_property_set_string (d, "info.udi", "/org/freedesktop/Hal/devices/computer"); 752912Sartem hal_device_set_udi (d, "/org/freedesktop/Hal/devices/computer"); 762912Sartem hal_device_property_set_string (d, "solaris.devfs_path", devfs_path); 772912Sartem 782912Sartem if (uname (&un) >= 0) { 792912Sartem hal_device_property_set_string (d, "system.kernel.name", un.sysname); 802912Sartem hal_device_property_set_string (d, "system.kernel.version", un.release); 812912Sartem hal_device_property_set_string (d, "system.kernel.machine", un.machine); 822912Sartem } 832912Sartem 842912Sartem devinfo_add_enqueue (d, devfs_path, &devinfo_computer_handler); 852912Sartem 862912Sartem /* all devinfo devices belong to the 'local' branch */ 872912Sartem local_d = hal_device_new (); 882912Sartem 89*3121Sartem hal_device_property_set_string (local_d, "info.parent", hal_device_get_udi (d)); 902912Sartem hal_device_property_set_string (local_d, "info.bus", "unknown"); 912912Sartem hal_device_property_set_string (local_d, "info.product", "Local devices"); 922912Sartem hal_device_property_set_string (local_d, "info.udi", "/org/freedesktop/Hal/devices/local"); 932912Sartem hal_device_set_udi (local_d, "/org/freedesktop/Hal/devices/local"); 942912Sartem hal_device_property_set_string (local_d, "solaris.devfs_path", "/local"); 952912Sartem 962912Sartem devinfo_add_enqueue (local_d, "/local", &devinfo_default_handler); 972912Sartem 982912Sartem return (local_d); 992912Sartem } 1002912Sartem 1012912Sartem static HalDevice * 1022912Sartem devinfo_cpu_add(HalDevice *parent, di_node_t node, char *devfs_path, char *device_type) 1032912Sartem { 1042912Sartem HalDevice *d; 1052912Sartem 1062912Sartem if ((device_type == NULL) || (strcmp(device_type, "cpu") != 0)) { 1072912Sartem return (NULL); 1082912Sartem } 1092912Sartem 1102912Sartem d = hal_device_new (); 1112912Sartem 1122912Sartem devinfo_set_default_properties (d, parent, node, devfs_path); 1132912Sartem hal_device_add_capability (d, "processor"); 1142912Sartem 1152912Sartem devinfo_add_enqueue (d, devfs_path, &devinfo_cpu_handler); 1162912Sartem 1172912Sartem return (d); 1182912Sartem } 1192912Sartem 1202912Sartem static HalDevice * 1212912Sartem devinfo_default_add(HalDevice *parent, di_node_t node, char *devfs_path, char *device_type) 1222912Sartem { 1232912Sartem char *driver_name; 1242912Sartem const char *parent_path; 1252912Sartem HalDevice *d; 1262912Sartem 1272912Sartem /* ignore all children of the 'pseudo' node except lofi */ 1282912Sartem if (parent != NULL) { 1292912Sartem parent_path = hal_device_property_get_string(parent, "solaris.devfs_path"); 1302912Sartem if ((parent_path != NULL) && 1312912Sartem (strcmp (parent_path, "/pseudo") == 0)) { 1322912Sartem driver_name = di_driver_name (node); 1332912Sartem if ((driver_name != NULL) && 1342912Sartem (strcmp (driver_name, "lofi") != 0)) { 1352912Sartem return (NULL); 1362912Sartem } 1372912Sartem } 1382912Sartem } 1392912Sartem 1402912Sartem d = hal_device_new (); 1412912Sartem 1422912Sartem devinfo_set_default_properties (d, parent, node, devfs_path); 1432912Sartem 1442912Sartem devinfo_add_enqueue (d, devfs_path, &devinfo_default_handler); 1452912Sartem 1462912Sartem return (d); 1472912Sartem } 148