1 /***************************************************************************
3 * devinfo_pci.c : PCI devices
5 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
6 * Use is subject to license terms.
8 * Licensed under the Academic Free License version 2.1
10 **************************************************************************/
12 #pragma ident "%Z%%M% %I% %E% SMI"
20 #include <libdevinfo.h>
22 #include "../osspec.h"
23 #include "../logger.h"
25 #include "../hald_dbus.h"
26 #include "../device_info.h"
29 #include "devinfo_pci.h"
31 HalDevice
*devinfo_pci_add (HalDevice
*parent
, di_node_t node
, char *devfs_path
, char *device_type
);
33 DevinfoDevHandler devinfo_pci_handler
= {
42 HalDevice
*devinfo_pci_add (HalDevice
*parent
, di_node_t node
, char *devfs_path
, char *device_type
)
47 int vid
, pid
, svid
, spid
;
49 if ((device_type
== NULL
) ||
50 ((strcmp (device_type
, "pci") != 0) &&
51 (strcmp (device_type
, "pci-ide") != 0))) {
55 s
= (char *)hal_device_property_get_string (parent
, "info.subsystem");
56 if ((s
== NULL
) || (strcmp (s
, "pci") != 0)) {
62 d
= hal_device_new ();
63 devinfo_set_default_properties (d
, parent
, node
, devfs_path
);
65 hal_device_property_set_string (d
, "info.subsystem", "pci");
67 vid
= pid
= svid
= spid
= 0;
68 if (di_prop_lookup_ints (DDI_DEV_T_ANY
, node
, "vendor-id", &i
) > 0) {
71 if (di_prop_lookup_ints (DDI_DEV_T_ANY
, node
, "device-id", &i
) > 0) {
74 if (di_prop_lookup_ints (DDI_DEV_T_ANY
, node
, "subsystem-vendor-id", &i
) > 0) {
77 if (di_prop_lookup_ints (DDI_DEV_T_ANY
, node
, "subsystem-id", &i
) > 0) {
80 hal_device_property_set_int (d
, "pci.vendor_id", vid
);
81 hal_device_property_set_int (d
, "pci.product_id", pid
);
82 hal_device_property_set_int (d
, "pci.subsys_vendor_id", svid
);
83 hal_device_property_set_int (d
, "pci.subsys_product_id", spid
);
88 char *subsys_vendor_name
;
89 char *subsys_product_name
;
91 ids_find_pci (hal_device_property_get_int (d
, "pci.vendor_id"),
92 hal_device_property_get_int (d
, "pci.product_id"),
93 hal_device_property_get_int (d
, "pci.subsys_vendor_id"),
94 hal_device_property_get_int (d
, "pci.subsys_product_id"),
95 &vendor_name
, &product_name
, &subsys_vendor_name
,
96 &subsys_product_name
);
98 if (vendor_name
!= NULL
) {
99 hal_device_property_set_string (d
, "pci.vendor", vendor_name
);
100 hal_device_property_set_string (d
, "info.vendor", vendor_name
);
103 if (product_name
!= NULL
) {
104 hal_device_property_set_string (d
, "pci.product", product_name
);
105 hal_device_property_set_string (d
, "info.product", product_name
);
108 if (subsys_vendor_name
!= NULL
) {
109 hal_device_property_set_string (d
, "pci.subsys_vendor",
113 if (subsys_product_name
!= NULL
) {
114 hal_device_property_set_string (d
, "pci.subsys_product", subsys_product_name
);
118 devinfo_add_enqueue (d
, devfs_path
, &devinfo_pci_handler
);