1*2912Sartem /*************************************************************************** 2*2912Sartem * 3*2912Sartem * devinfo_pci.c : PCI devices 4*2912Sartem * 5*2912Sartem * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 6*2912Sartem * Use is subject to license terms. 7*2912Sartem * 8*2912Sartem * Licensed under the Academic Free License version 2.1 9*2912Sartem * 10*2912Sartem **************************************************************************/ 11*2912Sartem 12*2912Sartem #pragma ident "%Z%%M% %I% %E% SMI" 13*2912Sartem 14*2912Sartem #include <stdio.h> 15*2912Sartem #include <string.h> 16*2912Sartem #include <libdevinfo.h> 17*2912Sartem 18*2912Sartem #include "../osspec.h" 19*2912Sartem #include "../logger.h" 20*2912Sartem #include "../hald.h" 21*2912Sartem #include "../hald_dbus.h" 22*2912Sartem #include "../device_info.h" 23*2912Sartem #include "../util.h" 24*2912Sartem #include "../ids.h" 25*2912Sartem #include "devinfo_pci.h" 26*2912Sartem 27*2912Sartem HalDevice *devinfo_pci_add (HalDevice *parent, di_node_t node, char *devfs_path, char *device_type); 28*2912Sartem 29*2912Sartem DevinfoDevHandler devinfo_pci_handler = { 30*2912Sartem devinfo_pci_add, 31*2912Sartem NULL, 32*2912Sartem NULL, 33*2912Sartem NULL, 34*2912Sartem NULL, 35*2912Sartem NULL 36*2912Sartem }; 37*2912Sartem 38*2912Sartem HalDevice *devinfo_pci_add (HalDevice *parent, di_node_t node, char *devfs_path, char *device_type) 39*2912Sartem { 40*2912Sartem HalDevice *d; 41*2912Sartem char *s; 42*2912Sartem int *i; 43*2912Sartem int vid, pid, svid, spid; 44*2912Sartem 45*2912Sartem if ((device_type == NULL) || 46*2912Sartem ((strcmp (device_type, "pci") != 0) && 47*2912Sartem (strcmp (device_type, "pci-ide") != 0))) { 48*2912Sartem if (parent == NULL) { 49*2912Sartem return (NULL); 50*2912Sartem } else { 51*2912Sartem s = (char *)hal_device_property_get_string (parent, "info.bus"); 52*2912Sartem if ((s == NULL) || (strcmp (s, "pci") != 0)) { 53*2912Sartem return (NULL); 54*2912Sartem } 55*2912Sartem } 56*2912Sartem } 57*2912Sartem 58*2912Sartem d = hal_device_new (); 59*2912Sartem devinfo_set_default_properties (d, parent, node, devfs_path); 60*2912Sartem 61*2912Sartem hal_device_property_set_string (d, "info.bus", "pci"); 62*2912Sartem 63*2912Sartem vid = pid = svid = spid = 0; 64*2912Sartem if (di_prop_lookup_ints (DDI_DEV_T_ANY, node, "vendor-id", &i) > 0) { 65*2912Sartem vid = i[0]; 66*2912Sartem } 67*2912Sartem if (di_prop_lookup_ints (DDI_DEV_T_ANY, node, "device-id", &i) > 0) { 68*2912Sartem pid = i[0]; 69*2912Sartem } 70*2912Sartem if (di_prop_lookup_ints (DDI_DEV_T_ANY, node, "subsystem-vendor-id", &i) > 0) { 71*2912Sartem svid = i[0]; 72*2912Sartem } 73*2912Sartem if (di_prop_lookup_ints (DDI_DEV_T_ANY, node, "subsystem-id", &i) > 0) { 74*2912Sartem spid = i[0]; 75*2912Sartem } 76*2912Sartem hal_device_property_set_int (d, "pci.vendor_id", vid); 77*2912Sartem hal_device_property_set_int (d, "pci.product_id", pid); 78*2912Sartem hal_device_property_set_int (d, "pci.subsys_vendor_id", svid); 79*2912Sartem hal_device_property_set_int (d, "pci.subsys_product_id", spid); 80*2912Sartem 81*2912Sartem { 82*2912Sartem char *vendor_name; 83*2912Sartem char *product_name; 84*2912Sartem char *subsys_vendor_name; 85*2912Sartem char *subsys_product_name; 86*2912Sartem 87*2912Sartem ids_find_pci (hal_device_property_get_int (d, "pci.vendor_id"), 88*2912Sartem hal_device_property_get_int (d, "pci.product_id"), 89*2912Sartem hal_device_property_get_int (d, "pci.subsys_vendor_id"), 90*2912Sartem hal_device_property_get_int (d, "pci.subsys_product_id"), 91*2912Sartem &vendor_name, &product_name, &subsys_vendor_name, 92*2912Sartem &subsys_product_name); 93*2912Sartem 94*2912Sartem if (vendor_name != NULL) { 95*2912Sartem hal_device_property_set_string (d, "pci.vendor", vendor_name); 96*2912Sartem hal_device_property_set_string (d, "info.vendor", vendor_name); 97*2912Sartem } 98*2912Sartem 99*2912Sartem if (product_name != NULL) { 100*2912Sartem hal_device_property_set_string (d, "pci.product", product_name); 101*2912Sartem hal_device_property_set_string (d, "info.product", product_name); 102*2912Sartem } 103*2912Sartem 104*2912Sartem if (subsys_vendor_name != NULL) { 105*2912Sartem hal_device_property_set_string (d, "pci.subsys_vendor", 106*2912Sartem subsys_vendor_name); 107*2912Sartem } 108*2912Sartem 109*2912Sartem if (subsys_product_name != NULL) { 110*2912Sartem hal_device_property_set_string (d, "pci.subsys_product", subsys_product_name); 111*2912Sartem } 112*2912Sartem } 113*2912Sartem 114*2912Sartem devinfo_add_enqueue (d, devfs_path, &devinfo_pci_handler); 115*2912Sartem 116*2912Sartem return (d); 117*2912Sartem } 118*2912Sartem 119