xref: /onnv-gate/usr/src/cmd/hal/hald/solaris/devinfo_pci.c (revision 6112:28ee9a48b832)
12912Sartem /***************************************************************************
22912Sartem  *
32912Sartem  * devinfo_pci.c : PCI devices
42912Sartem  *
5*6112Sqz150045  * Copyright 2008 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 
143121Sartem #ifdef HAVE_CONFIG_H
153121Sartem #  include <config.h>
163121Sartem #endif
173121Sartem 
182912Sartem #include <stdio.h>
192912Sartem #include <string.h>
202912Sartem #include <libdevinfo.h>
212912Sartem 
222912Sartem #include "../osspec.h"
232912Sartem #include "../logger.h"
242912Sartem #include "../hald.h"
252912Sartem #include "../hald_dbus.h"
262912Sartem #include "../device_info.h"
272912Sartem #include "../util.h"
282912Sartem #include "../ids.h"
292912Sartem #include "devinfo_pci.h"
302912Sartem 
312912Sartem HalDevice *devinfo_pci_add (HalDevice *parent, di_node_t node, char *devfs_path, char *device_type);
322912Sartem 
332912Sartem DevinfoDevHandler devinfo_pci_handler = {
342912Sartem         devinfo_pci_add,
352912Sartem 	NULL,
362912Sartem 	NULL,
372912Sartem 	NULL,
382912Sartem 	NULL,
392912Sartem         NULL
402912Sartem };
412912Sartem 
devinfo_pci_add(HalDevice * parent,di_node_t node,char * devfs_path,char * device_type)422912Sartem HalDevice *devinfo_pci_add (HalDevice *parent, di_node_t node, char *devfs_path, char *device_type)
432912Sartem {
442912Sartem 	HalDevice *d;
452912Sartem 	char	*s;
462912Sartem 	int	*i;
472912Sartem 	int	vid, pid, svid, spid;
482912Sartem 
492912Sartem 	if ((device_type == NULL) ||
502912Sartem 	    ((strcmp (device_type, "pci") != 0) &&
512912Sartem 	    (strcmp (device_type, "pci-ide") != 0))) {
522912Sartem 		if (parent == NULL) {
532912Sartem 			return (NULL);
542912Sartem 		} else {
55*6112Sqz150045 			s = (char *)hal_device_property_get_string (parent, "info.subsystem");
562912Sartem 			if ((s == NULL) || (strcmp (s, "pci") != 0)) {
572912Sartem 				return (NULL);
582912Sartem 			}
592912Sartem 		}
602912Sartem 	}
612912Sartem 
622912Sartem 	d = hal_device_new ();
632912Sartem 	devinfo_set_default_properties (d, parent, node, devfs_path);
642912Sartem 
65*6112Sqz150045 	hal_device_property_set_string (d, "info.subsystem", "pci");
662912Sartem 
672912Sartem 	vid = pid = svid = spid = 0;
682912Sartem         if (di_prop_lookup_ints (DDI_DEV_T_ANY, node, "vendor-id", &i) > 0) {
692912Sartem 		vid = i[0];
702912Sartem 	}
712912Sartem         if (di_prop_lookup_ints (DDI_DEV_T_ANY, node, "device-id", &i) > 0) {
722912Sartem 		pid = i[0];
732912Sartem 	}
742912Sartem         if (di_prop_lookup_ints (DDI_DEV_T_ANY, node, "subsystem-vendor-id", &i) > 0) {
752912Sartem 		svid = i[0];
762912Sartem 	}
772912Sartem         if (di_prop_lookup_ints (DDI_DEV_T_ANY, node, "subsystem-id", &i) > 0) {
782912Sartem 		spid = i[0];
792912Sartem 	}
802912Sartem 	hal_device_property_set_int (d, "pci.vendor_id", vid);
812912Sartem 	hal_device_property_set_int (d, "pci.product_id", pid);
822912Sartem 	hal_device_property_set_int (d, "pci.subsys_vendor_id", svid);
832912Sartem 	hal_device_property_set_int (d, "pci.subsys_product_id", spid);
842912Sartem 
852912Sartem         {
862912Sartem                 char *vendor_name;
872912Sartem                 char *product_name;
882912Sartem                 char *subsys_vendor_name;
892912Sartem                 char *subsys_product_name;
902912Sartem 
912912Sartem                 ids_find_pci (hal_device_property_get_int (d, "pci.vendor_id"),
922912Sartem                               hal_device_property_get_int (d, "pci.product_id"),
932912Sartem                               hal_device_property_get_int (d, "pci.subsys_vendor_id"),
942912Sartem                               hal_device_property_get_int (d, "pci.subsys_product_id"),
952912Sartem                               &vendor_name, &product_name, &subsys_vendor_name,
962912Sartem &subsys_product_name);
972912Sartem 
982912Sartem                 if (vendor_name != NULL) {
992912Sartem                         hal_device_property_set_string (d, "pci.vendor", vendor_name);
1002912Sartem                         hal_device_property_set_string (d, "info.vendor", vendor_name);
1012912Sartem                 }
1022912Sartem 
1032912Sartem                 if (product_name != NULL) {
1042912Sartem                         hal_device_property_set_string (d, "pci.product", product_name);
1052912Sartem                         hal_device_property_set_string (d, "info.product", product_name);
1062912Sartem                 }
1072912Sartem 
1082912Sartem                 if (subsys_vendor_name != NULL) {
1092912Sartem                         hal_device_property_set_string (d, "pci.subsys_vendor",
1102912Sartem subsys_vendor_name);
1112912Sartem                 }
1122912Sartem 
1132912Sartem                 if (subsys_product_name != NULL) {
1142912Sartem                         hal_device_property_set_string (d, "pci.subsys_product", subsys_product_name);
1152912Sartem                 }
1162912Sartem         }
1172912Sartem 
1182912Sartem 	devinfo_add_enqueue (d, devfs_path, &devinfo_pci_handler);
1192912Sartem 
1202912Sartem 	return (d);
1212912Sartem }
1222912Sartem 
123