12912Sartem /*************************************************************************** 22912Sartem * 32912Sartem * devinfo_pci.c : PCI 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 12*2916Sartem #pragma ident "%Z%%M% %I% %E% SMI" 132912Sartem 142912Sartem #include <stdio.h> 152912Sartem #include <string.h> 162912Sartem #include <libdevinfo.h> 172912Sartem 182912Sartem #include "../osspec.h" 192912Sartem #include "../logger.h" 202912Sartem #include "../hald.h" 212912Sartem #include "../hald_dbus.h" 222912Sartem #include "../device_info.h" 232912Sartem #include "../util.h" 242912Sartem #include "../ids.h" 252912Sartem #include "devinfo_pci.h" 262912Sartem 272912Sartem HalDevice *devinfo_pci_add (HalDevice *parent, di_node_t node, char *devfs_path, char *device_type); 282912Sartem 292912Sartem DevinfoDevHandler devinfo_pci_handler = { 302912Sartem devinfo_pci_add, 312912Sartem NULL, 322912Sartem NULL, 332912Sartem NULL, 342912Sartem NULL, 352912Sartem NULL 362912Sartem }; 372912Sartem 382912Sartem HalDevice *devinfo_pci_add (HalDevice *parent, di_node_t node, char *devfs_path, char *device_type) 392912Sartem { 402912Sartem HalDevice *d; 412912Sartem char *s; 422912Sartem int *i; 432912Sartem int vid, pid, svid, spid; 442912Sartem 452912Sartem if ((device_type == NULL) || 462912Sartem ((strcmp (device_type, "pci") != 0) && 472912Sartem (strcmp (device_type, "pci-ide") != 0))) { 482912Sartem if (parent == NULL) { 492912Sartem return (NULL); 502912Sartem } else { 512912Sartem s = (char *)hal_device_property_get_string (parent, "info.bus"); 522912Sartem if ((s == NULL) || (strcmp (s, "pci") != 0)) { 532912Sartem return (NULL); 542912Sartem } 552912Sartem } 562912Sartem } 572912Sartem 582912Sartem d = hal_device_new (); 592912Sartem devinfo_set_default_properties (d, parent, node, devfs_path); 602912Sartem 612912Sartem hal_device_property_set_string (d, "info.bus", "pci"); 622912Sartem 632912Sartem vid = pid = svid = spid = 0; 642912Sartem if (di_prop_lookup_ints (DDI_DEV_T_ANY, node, "vendor-id", &i) > 0) { 652912Sartem vid = i[0]; 662912Sartem } 672912Sartem if (di_prop_lookup_ints (DDI_DEV_T_ANY, node, "device-id", &i) > 0) { 682912Sartem pid = i[0]; 692912Sartem } 702912Sartem if (di_prop_lookup_ints (DDI_DEV_T_ANY, node, "subsystem-vendor-id", &i) > 0) { 712912Sartem svid = i[0]; 722912Sartem } 732912Sartem if (di_prop_lookup_ints (DDI_DEV_T_ANY, node, "subsystem-id", &i) > 0) { 742912Sartem spid = i[0]; 752912Sartem } 762912Sartem hal_device_property_set_int (d, "pci.vendor_id", vid); 772912Sartem hal_device_property_set_int (d, "pci.product_id", pid); 782912Sartem hal_device_property_set_int (d, "pci.subsys_vendor_id", svid); 792912Sartem hal_device_property_set_int (d, "pci.subsys_product_id", spid); 802912Sartem 812912Sartem { 822912Sartem char *vendor_name; 832912Sartem char *product_name; 842912Sartem char *subsys_vendor_name; 852912Sartem char *subsys_product_name; 862912Sartem 872912Sartem ids_find_pci (hal_device_property_get_int (d, "pci.vendor_id"), 882912Sartem hal_device_property_get_int (d, "pci.product_id"), 892912Sartem hal_device_property_get_int (d, "pci.subsys_vendor_id"), 902912Sartem hal_device_property_get_int (d, "pci.subsys_product_id"), 912912Sartem &vendor_name, &product_name, &subsys_vendor_name, 922912Sartem &subsys_product_name); 932912Sartem 942912Sartem if (vendor_name != NULL) { 952912Sartem hal_device_property_set_string (d, "pci.vendor", vendor_name); 962912Sartem hal_device_property_set_string (d, "info.vendor", vendor_name); 972912Sartem } 982912Sartem 992912Sartem if (product_name != NULL) { 1002912Sartem hal_device_property_set_string (d, "pci.product", product_name); 1012912Sartem hal_device_property_set_string (d, "info.product", product_name); 1022912Sartem } 1032912Sartem 1042912Sartem if (subsys_vendor_name != NULL) { 1052912Sartem hal_device_property_set_string (d, "pci.subsys_vendor", 1062912Sartem subsys_vendor_name); 1072912Sartem } 1082912Sartem 1092912Sartem if (subsys_product_name != NULL) { 1102912Sartem hal_device_property_set_string (d, "pci.subsys_product", subsys_product_name); 1112912Sartem } 1122912Sartem } 1132912Sartem 1142912Sartem devinfo_add_enqueue (d, devfs_path, &devinfo_pci_handler); 1152912Sartem 1162912Sartem return (d); 1172912Sartem } 1182912Sartem 119