xref: /illumos-gate/usr/src/cmd/hal/hald/solaris/devinfo_pci.c (revision 92f381329ebf1c2209df9608670666b32b291e05)
1 /***************************************************************************
2  *
3  * devinfo_pci.c : PCI 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 #include <stdio.h>
15 #include <string.h>
16 #include <libdevinfo.h>
17 
18 #include "../osspec.h"
19 #include "../logger.h"
20 #include "../hald.h"
21 #include "../hald_dbus.h"
22 #include "../device_info.h"
23 #include "../util.h"
24 #include "../ids.h"
25 #include "devinfo_pci.h"
26 
27 HalDevice *devinfo_pci_add (HalDevice *parent, di_node_t node, char *devfs_path, char *device_type);
28 
29 DevinfoDevHandler devinfo_pci_handler = {
30         devinfo_pci_add,
31 	NULL,
32 	NULL,
33 	NULL,
34 	NULL,
35         NULL
36 };
37 
38 HalDevice *devinfo_pci_add (HalDevice *parent, di_node_t node, char *devfs_path, char *device_type)
39 {
40 	HalDevice *d;
41 	char	*s;
42 	int	*i;
43 	int	vid, pid, svid, spid;
44 
45 	if ((device_type == NULL) ||
46 	    ((strcmp (device_type, "pci") != 0) &&
47 	    (strcmp (device_type, "pci-ide") != 0))) {
48 		if (parent == NULL) {
49 			return (NULL);
50 		} else {
51 			s = (char *)hal_device_property_get_string (parent, "info.bus");
52 			if ((s == NULL) || (strcmp (s, "pci") != 0)) {
53 				return (NULL);
54 			}
55 		}
56 	}
57 
58 	d = hal_device_new ();
59 	devinfo_set_default_properties (d, parent, node, devfs_path);
60 
61 	hal_device_property_set_string (d, "info.bus", "pci");
62 
63 	vid = pid = svid = spid = 0;
64         if (di_prop_lookup_ints (DDI_DEV_T_ANY, node, "vendor-id", &i) > 0) {
65 		vid = i[0];
66 	}
67         if (di_prop_lookup_ints (DDI_DEV_T_ANY, node, "device-id", &i) > 0) {
68 		pid = i[0];
69 	}
70         if (di_prop_lookup_ints (DDI_DEV_T_ANY, node, "subsystem-vendor-id", &i) > 0) {
71 		svid = i[0];
72 	}
73         if (di_prop_lookup_ints (DDI_DEV_T_ANY, node, "subsystem-id", &i) > 0) {
74 		spid = i[0];
75 	}
76 	hal_device_property_set_int (d, "pci.vendor_id", vid);
77 	hal_device_property_set_int (d, "pci.product_id", pid);
78 	hal_device_property_set_int (d, "pci.subsys_vendor_id", svid);
79 	hal_device_property_set_int (d, "pci.subsys_product_id", spid);
80 
81         {
82                 char *vendor_name;
83                 char *product_name;
84                 char *subsys_vendor_name;
85                 char *subsys_product_name;
86 
87                 ids_find_pci (hal_device_property_get_int (d, "pci.vendor_id"),
88                               hal_device_property_get_int (d, "pci.product_id"),
89                               hal_device_property_get_int (d, "pci.subsys_vendor_id"),
90                               hal_device_property_get_int (d, "pci.subsys_product_id"),
91                               &vendor_name, &product_name, &subsys_vendor_name,
92 &subsys_product_name);
93 
94                 if (vendor_name != NULL) {
95                         hal_device_property_set_string (d, "pci.vendor", vendor_name);
96                         hal_device_property_set_string (d, "info.vendor", vendor_name);
97                 }
98 
99                 if (product_name != NULL) {
100                         hal_device_property_set_string (d, "pci.product", product_name);
101                         hal_device_property_set_string (d, "info.product", product_name);
102                 }
103 
104                 if (subsys_vendor_name != NULL) {
105                         hal_device_property_set_string (d, "pci.subsys_vendor",
106 subsys_vendor_name);
107                 }
108 
109                 if (subsys_product_name != NULL) {
110                         hal_device_property_set_string (d, "pci.subsys_product", subsys_product_name);
111                 }
112         }
113 
114 	devinfo_add_enqueue (d, devfs_path, &devinfo_pci_handler);
115 
116 	return (d);
117 }
118 
119