118c2aff7Sartem /***************************************************************************
218c2aff7Sartem *
318c2aff7Sartem * devinfo_pci.c : PCI devices
418c2aff7Sartem *
5*112cd14aSqz150045 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
618c2aff7Sartem * Use is subject to license terms.
718c2aff7Sartem *
818c2aff7Sartem * Licensed under the Academic Free License version 2.1
918c2aff7Sartem *
1018c2aff7Sartem **************************************************************************/
1118c2aff7Sartem
1218c2aff7Sartem #pragma ident "%Z%%M% %I% %E% SMI"
1318c2aff7Sartem
1400687e57Sartem #ifdef HAVE_CONFIG_H
1500687e57Sartem # include <config.h>
1600687e57Sartem #endif
1700687e57Sartem
1818c2aff7Sartem #include <stdio.h>
1918c2aff7Sartem #include <string.h>
2018c2aff7Sartem #include <libdevinfo.h>
2118c2aff7Sartem
2218c2aff7Sartem #include "../osspec.h"
2318c2aff7Sartem #include "../logger.h"
2418c2aff7Sartem #include "../hald.h"
2518c2aff7Sartem #include "../hald_dbus.h"
2618c2aff7Sartem #include "../device_info.h"
2718c2aff7Sartem #include "../util.h"
2818c2aff7Sartem #include "../ids.h"
2918c2aff7Sartem #include "devinfo_pci.h"
3018c2aff7Sartem
3118c2aff7Sartem HalDevice *devinfo_pci_add (HalDevice *parent, di_node_t node, char *devfs_path, char *device_type);
3218c2aff7Sartem
3318c2aff7Sartem DevinfoDevHandler devinfo_pci_handler = {
3418c2aff7Sartem devinfo_pci_add,
3518c2aff7Sartem NULL,
3618c2aff7Sartem NULL,
3718c2aff7Sartem NULL,
3818c2aff7Sartem NULL,
3918c2aff7Sartem NULL
4018c2aff7Sartem };
4118c2aff7Sartem
devinfo_pci_add(HalDevice * parent,di_node_t node,char * devfs_path,char * device_type)4218c2aff7Sartem HalDevice *devinfo_pci_add (HalDevice *parent, di_node_t node, char *devfs_path, char *device_type)
4318c2aff7Sartem {
4418c2aff7Sartem HalDevice *d;
4518c2aff7Sartem char *s;
4618c2aff7Sartem int *i;
4718c2aff7Sartem int vid, pid, svid, spid;
4818c2aff7Sartem
4918c2aff7Sartem if ((device_type == NULL) ||
5018c2aff7Sartem ((strcmp (device_type, "pci") != 0) &&
5118c2aff7Sartem (strcmp (device_type, "pci-ide") != 0))) {
5218c2aff7Sartem if (parent == NULL) {
5318c2aff7Sartem return (NULL);
5418c2aff7Sartem } else {
55*112cd14aSqz150045 s = (char *)hal_device_property_get_string (parent, "info.subsystem");
5618c2aff7Sartem if ((s == NULL) || (strcmp (s, "pci") != 0)) {
5718c2aff7Sartem return (NULL);
5818c2aff7Sartem }
5918c2aff7Sartem }
6018c2aff7Sartem }
6118c2aff7Sartem
6218c2aff7Sartem d = hal_device_new ();
6318c2aff7Sartem devinfo_set_default_properties (d, parent, node, devfs_path);
6418c2aff7Sartem
65*112cd14aSqz150045 hal_device_property_set_string (d, "info.subsystem", "pci");
6618c2aff7Sartem
6718c2aff7Sartem vid = pid = svid = spid = 0;
6818c2aff7Sartem if (di_prop_lookup_ints (DDI_DEV_T_ANY, node, "vendor-id", &i) > 0) {
6918c2aff7Sartem vid = i[0];
7018c2aff7Sartem }
7118c2aff7Sartem if (di_prop_lookup_ints (DDI_DEV_T_ANY, node, "device-id", &i) > 0) {
7218c2aff7Sartem pid = i[0];
7318c2aff7Sartem }
7418c2aff7Sartem if (di_prop_lookup_ints (DDI_DEV_T_ANY, node, "subsystem-vendor-id", &i) > 0) {
7518c2aff7Sartem svid = i[0];
7618c2aff7Sartem }
7718c2aff7Sartem if (di_prop_lookup_ints (DDI_DEV_T_ANY, node, "subsystem-id", &i) > 0) {
7818c2aff7Sartem spid = i[0];
7918c2aff7Sartem }
8018c2aff7Sartem hal_device_property_set_int (d, "pci.vendor_id", vid);
8118c2aff7Sartem hal_device_property_set_int (d, "pci.product_id", pid);
8218c2aff7Sartem hal_device_property_set_int (d, "pci.subsys_vendor_id", svid);
8318c2aff7Sartem hal_device_property_set_int (d, "pci.subsys_product_id", spid);
8418c2aff7Sartem
8518c2aff7Sartem {
8618c2aff7Sartem char *vendor_name;
8718c2aff7Sartem char *product_name;
8818c2aff7Sartem char *subsys_vendor_name;
8918c2aff7Sartem char *subsys_product_name;
9018c2aff7Sartem
9118c2aff7Sartem ids_find_pci (hal_device_property_get_int (d, "pci.vendor_id"),
9218c2aff7Sartem hal_device_property_get_int (d, "pci.product_id"),
9318c2aff7Sartem hal_device_property_get_int (d, "pci.subsys_vendor_id"),
9418c2aff7Sartem hal_device_property_get_int (d, "pci.subsys_product_id"),
9518c2aff7Sartem &vendor_name, &product_name, &subsys_vendor_name,
9618c2aff7Sartem &subsys_product_name);
9718c2aff7Sartem
9818c2aff7Sartem if (vendor_name != NULL) {
9918c2aff7Sartem hal_device_property_set_string (d, "pci.vendor", vendor_name);
10018c2aff7Sartem hal_device_property_set_string (d, "info.vendor", vendor_name);
10118c2aff7Sartem }
10218c2aff7Sartem
10318c2aff7Sartem if (product_name != NULL) {
10418c2aff7Sartem hal_device_property_set_string (d, "pci.product", product_name);
10518c2aff7Sartem hal_device_property_set_string (d, "info.product", product_name);
10618c2aff7Sartem }
10718c2aff7Sartem
10818c2aff7Sartem if (subsys_vendor_name != NULL) {
10918c2aff7Sartem hal_device_property_set_string (d, "pci.subsys_vendor",
11018c2aff7Sartem subsys_vendor_name);
11118c2aff7Sartem }
11218c2aff7Sartem
11318c2aff7Sartem if (subsys_product_name != NULL) {
11418c2aff7Sartem hal_device_property_set_string (d, "pci.subsys_product", subsys_product_name);
11518c2aff7Sartem }
11618c2aff7Sartem }
11718c2aff7Sartem
11818c2aff7Sartem devinfo_add_enqueue (d, devfs_path, &devinfo_pci_handler);
11918c2aff7Sartem
12018c2aff7Sartem return (d);
12118c2aff7Sartem }
12218c2aff7Sartem
123