OSDN Git Service

Fix build on NetBSD-4.
[android-x86/external-libpciaccess.git] / src / solx_devfs.c
index b56819c..433969f 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * (C) Copyright IBM Corporation 2006
+ * Copyright (c) 2007, 2009, 2011, 2012, 2013 Oracle and/or its affiliates.
  * All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * DEALINGS IN THE SOFTWARE.
  */
 /*
- * Copyright 2007, 2009 Sun Microsystems, Inc.  All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, and/or sell copies of the Software, and to permit persons
- * to whom the Software is furnished to do so, provided that the above
- * copyright notice(s) and this permission notice appear in all copies of
- * the Software and that both the above copyright notice(s) and this
- * permission notice appear in supporting documentation.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
- * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
- * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
- * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
- * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
- * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * Except as contained in this notice, the name of a copyright holder
- * shall not be used in advertising or otherwise to promote the sale, use
- * or other dealings in this Software without prior written authorization
- * of the copyright holder.
- */
-/*
  * Solaris devfs interfaces
  */
 
 #include <libdevinfo.h>
 #include "pci_tools.h"
 
+#ifdef __x86
+# include <sys/sysi86.h>
+# include <sys/psw.h>
+#endif
+
 #include "pciaccess.h"
 #include "pciaccess_private.h"
 
 /* #define DEBUG */
 
-#define        MAX_DEVICES     256
+#define        INITIAL_NUM_DEVICES     256
 #define        CELL_NUMS_1275  (sizeof(pci_regspec_t) / sizeof(uint_t))
 
-typedef union {
-    uint8_t bytes[16 * sizeof (uint32_t)];
-    uint32_t dwords[16];
-} pci_conf_hdr_t;
-
 typedef struct i_devnode {
     uint8_t bus;
     uint8_t dev;
@@ -89,12 +62,38 @@ typedef struct nexus {
     int fd;
     int first_bus;
     int last_bus;
+    int domain;
     char *path;                        /* for errors/debugging; fd is all we need */
+    char *dev_path;
     struct nexus *next;
 } nexus_t;
 
+typedef struct probe_info {
+    volatile size_t num_allocated_elems;
+    volatile size_t num_devices;
+    struct pci_device_private * volatile devices;
+} probe_info_t;
+
+typedef struct probe_args {
+    probe_info_t *pinfo;
+    nexus_t *nexus;
+    int ret;
+} probe_args_t;
+
+typedef struct property_info {
+    const char *name;
+    int value;
+} property_info_t;
+
 static nexus_t *nexus_list = NULL;
+#if !defined(__sparc)
 static int xsvc_fd = -1;
+#endif
+
+#ifdef __sparc
+static di_prom_handle_t di_phdl;
+static size_t  nexus_count = 0;
+#endif
 
 /*
  * Read config space in native processor endianness.  Endian-neutral
@@ -110,6 +109,10 @@ static int xsvc_fd = -1;
 # error "ISA is neither __sparc nor __x86"
 #endif
 
+#ifdef __sparc
+#define MAPPING_DEV_PATH(dev)   (((struct pci_device_private *) dev)->device_string)
+#endif
+
 /*
  * Identify problematic southbridges.  These have device id 0x5249 and
  * vendor id 0x10b9.  Check for revision ID 0 and class code 060400 as well.
@@ -130,71 +133,20 @@ static int xsvc_fd = -1;
 # define U45_SB_CLASS_RID      0x06040000
 #endif
 
-static int pci_device_solx_devfs_map_range(struct pci_device *dev,
-    struct pci_device_mapping *map);
-
-static int pci_device_solx_devfs_read_rom( struct pci_device * dev,
-    void * buffer );
-
-static int pci_device_solx_devfs_probe( struct pci_device * dev );
-
-static int pci_device_solx_devfs_read( struct pci_device * dev, void * data,
-    pciaddr_t offset, pciaddr_t size, pciaddr_t * bytes_read );
-
-static int pci_device_solx_devfs_write( struct pci_device * dev,
-    const void * data, pciaddr_t offset, pciaddr_t size,
-    pciaddr_t * bytes_written );
-
-static int probe_dev(nexus_t *nexus, pcitool_reg_t *prg_p,
-                    struct pci_system *pci_sys);
-
-static int do_probe(nexus_t *nexus, struct pci_system *pci_sys);
-
-static int probe_nexus_node(di_node_t di_node, di_minor_t minor, void *arg);
-
-static void pci_system_solx_devfs_destroy( void );
-
-static int get_config_header(int fd, uint8_t bus_no, uint8_t dev_no,
-                            uint8_t func_no, pci_conf_hdr_t *config_hdr_p);
-
-int pci_system_solx_devfs_create( void );
-
-static const struct pci_system_methods solx_devfs_methods = {
-    .destroy = pci_system_solx_devfs_destroy,
-    .destroy_device = NULL,
-    .read_rom = pci_device_solx_devfs_read_rom,
-    .probe = pci_device_solx_devfs_probe,
-    .map_range = pci_device_solx_devfs_map_range,
-    .unmap_range = pci_device_generic_unmap_range,
-
-    .read = pci_device_solx_devfs_read,
-    .write = pci_device_solx_devfs_write,
-
-    .fill_capabilities = pci_fill_capabilities_generic
-};
-
 static nexus_t *
-find_nexus_for_bus( int bus )
+find_nexus_for_bus( int domain, int bus )
 {
     nexus_t *nexus;
 
     for (nexus = nexus_list ; nexus != NULL ; nexus = nexus->next) {
-       if ((bus >= nexus->first_bus) && (bus <= nexus->last_bus)) {
+       if ((domain == nexus->domain) &&
+           (bus >= nexus->first_bus) && (bus <= nexus->last_bus)) {
            return nexus;
        }
     }
     return NULL;
 }
 
-#define GET_CONFIG_VAL_8(offset) (config_hdr.bytes[offset])
-#define GET_CONFIG_VAL_16(offset) \
-    (uint16_t) (GET_CONFIG_VAL_8(offset) + (GET_CONFIG_VAL_8(offset+1) << 8))
-#define GET_CONFIG_VAL_32(offset) \
-    (uint32_t) (GET_CONFIG_VAL_8(offset) +             \
-               (GET_CONFIG_VAL_8(offset+1) << 8) +     \
-               (GET_CONFIG_VAL_8(offset+2) << 16) +    \
-               (GET_CONFIG_VAL_8(offset+3) << 24))
-
 /*
  * Release all the resources
  * Solaris version
@@ -213,298 +165,146 @@ pci_system_solx_devfs_destroy( void )
        next = nexus->next;
        close(nexus->fd);
        free(nexus->path);
+       free(nexus->dev_path);
        free(nexus);
     }
     nexus_list = NULL;
 
+#ifdef __sparc
+    if (di_phdl != DI_PROM_HANDLE_NIL)
+       (void) di_prom_fini(di_phdl);
+#else
     if (xsvc_fd >= 0) {
        close(xsvc_fd);
        xsvc_fd = -1;
     }
+#endif
 }
 
-/*
- * Attempt to access PCI subsystem using Solaris's devfs interface.
- * Solaris version
- */
-_pci_hidden int
-pci_system_solx_devfs_create( void )
-{
-    int err = 0;
-    di_node_t di_node;
-
-
-    if (nexus_list != NULL) {
-       return 0;
-    }
-
-    /*
-     * Only allow MAX_DEVICES exists
-     * I will fix it later to get
-     * the total devices first
-     */
-    if ((pci_sys = calloc(1, sizeof (struct pci_system))) != NULL) {
-       pci_sys->methods = &solx_devfs_methods;
-
-       if ((pci_sys->devices =
-            calloc(MAX_DEVICES, sizeof (struct pci_device_private)))
-           != NULL) {
-
-           if ((di_node = di_init("/", DINFOCPYALL)) == DI_NODE_NIL) {
-               err = errno;
-               (void) fprintf(stderr, "di_init() failed: %s\n",
-                              strerror(errno));
-           } else {
-               (void) di_walk_minor(di_node, DDI_NT_REGACC, 0, pci_sys,
-                                    probe_nexus_node);
-               di_fini(di_node);
-           }
-       }
-       else {
-           err = errno;
-       }
-    } else {
-       err = errno;
-    }
-
-    if (err != 0) {
-       if (pci_sys != NULL) {
-           free(pci_sys->devices);
-           free(pci_sys);
-           pci_sys = NULL;
-       }
-    }
-
-    return (err);
-}
 
+#ifdef __sparc
 /*
- * Retrieve first 16 dwords of device's config header, except for the first
- * dword.  First 16 dwords are defined by the PCI specification.
+ * Release resources per device
  */
-static int
-get_config_header(int fd, uint8_t bus_no, uint8_t dev_no, uint8_t func_no,
-                 pci_conf_hdr_t *config_hdr_p)
+static void
+pci_system_solx_devfs_destroy_device( struct pci_device *dev )
 {
-    pcitool_reg_t cfg_prg;
-    int i;
-    int rval = 0;
-
-    /* Prepare a local pcitool_reg_t so as to not disturb the caller's. */
-    cfg_prg.offset = 0;
-    cfg_prg.acc_attr = PCITOOL_ACC_ATTR_SIZE_4 + NATIVE_ENDIAN;
-    cfg_prg.bus_no = bus_no;
-    cfg_prg.dev_no = dev_no;
-    cfg_prg.func_no = func_no;
-    cfg_prg.barnum = 0;
-    cfg_prg.user_version = PCITOOL_USER_VERSION;
-
-    /* Get dwords 1-15 of config space. They must be read as uint32_t. */
-    for (i = 1; i < (sizeof (pci_conf_hdr_t) / sizeof (uint32_t)); i++) {
-       cfg_prg.offset += sizeof (uint32_t);
-       if ((rval = ioctl(fd, PCITOOL_DEVICE_GET_REG, &cfg_prg)) != 0) {
-           break;
-       }
-       config_hdr_p->dwords[i] = (uint32_t)cfg_prg.data;
-    }
-
-    return (rval);
+   if (MAPPING_DEV_PATH(dev))
+       di_devfs_path_free((char *) MAPPING_DEV_PATH(dev));
 }
+#endif
 
 
-/*
- * Probe device's functions.  Modifies many fields in the prg_p.
- */
 static int
-probe_dev(nexus_t *nexus, pcitool_reg_t *prg_p, struct pci_system *pci_sys)
+probe_device_node(di_node_t node, void *arg)
 {
-    pci_conf_hdr_t     config_hdr;
-    boolean_t          multi_function_device;
-    int8_t             func;
-    int8_t             first_func = 0;
-    int8_t             last_func = PCI_REG_FUNC_M >> PCI_REG_FUNC_SHIFT;
-    int                        rval = 0;
-    struct pci_device *        pci_base;
-
-    /*
-     * Loop through at least func=first_func.  Continue looping through
-     * functions if there are no errors and the device is a multi-function
-     * device.
-     *
-     * (Note, if first_func == 0, header will show whether multifunction
-     * device and set multi_function_device.  If first_func != 0, then we
-     * will force the loop as the user wants a specific function to be
-     * checked.
-     */
-    for (func = first_func, multi_function_device = B_FALSE;
-        ((func <= last_func) &&
-         ((func == first_func) || (multi_function_device)));
-        func++) {
-       prg_p->func_no = func;
-
-       /*
-        * Four things can happen here:
-        *
-        * 1) ioctl comes back as EFAULT and prg_p->status is
-        *    PCITOOL_INVALID_ADDRESS.  There is no device at this location.
-        *
-        * 2) ioctl comes back successful and the data comes back as
-        *    zero.  Config space is mapped but no device responded.
-        *
-        * 3) ioctl comes back successful and the data comes back as
-        *    non-zero.  We've found a device.
-        *
-        * 4) Some other error occurs in an ioctl.
-        */
-
-       prg_p->status = PCITOOL_SUCCESS;
-       prg_p->offset = 0;
-       prg_p->data = 0;
-       prg_p->user_version = PCITOOL_USER_VERSION;
-
-       errno = 0;
-       if (((rval = ioctl(nexus->fd, PCITOOL_DEVICE_GET_REG, prg_p)) != 0) ||
-           (prg_p->data == 0xffffffff)) {
-
-           /*
-            * Accept errno == EINVAL along with status of
-            * PCITOOL_OUT_OF_RANGE because some systems
-            * don't implement the full range of config space.
-            * Leave the loop quietly in this case.
-            */
-           if ((errno == EINVAL) ||
-               (prg_p->status == PCITOOL_OUT_OF_RANGE)) {
-               break;
-           }
-
-           /*
-            * Exit silently with ENXIO as this means that there are
-            * no devices under the pci root nexus.
-            */
-           else if ((errno == ENXIO) &&
-                    (prg_p->status == PCITOOL_IO_ERROR)) {
-               break;
-           }
-
-           /*
-            * Expect errno == EFAULT along with status of
-            * PCITOOL_INVALID_ADDRESS because there won't be
-            * devices at each stop.  Quit on any other error.
-            */
-           else if (((errno != EFAULT) ||
-                     (prg_p->status != PCITOOL_INVALID_ADDRESS)) &&
-                    (prg_p->data != 0xffffffff)) {
-               break;
-           }
-
-           /*
-            * If no function at this location,
-            * just advance to the next function.
-            */
-           else {
-               rval = 0;
-           }
-
-           /*
-            * Data came back as 0.
-            * Treat as unresponsive device and check next device.
-            */
-       } else if (prg_p->data == 0) {
-           rval = 0;
-           break;      /* Func loop. */
-
-           /* Found something. */
-       } else {
-           config_hdr.dwords[0] = (uint32_t)prg_p->data;
-
-           /* Get the rest of the PCI header. */
-           if ((rval = get_config_header(nexus->fd, prg_p->bus_no,
-                                         prg_p->dev_no, prg_p->func_no,
-                                         &config_hdr)) != 0) {
-               break;
-           }
-
-           /*
-            * Special case for the type of Southbridge found on
-            * Ultra-45 and other sun4u fire workstations.
-            */
-           if ((config_hdr.dwords[0] == U45_SB_DEVID_VID) &&
-               (config_hdr.dwords[2] == U45_SB_CLASS_RID)) {
-               rval = ECANCELED;
-               break;
-           }
+    int *retbuf = NULL;
+    int len = 0, i;
+    struct pci_device  *pci_base;
+    probe_info_t *pinfo = ((probe_args_t *)arg)->pinfo;
+    nexus_t *nexus = ((probe_args_t *)arg)->nexus;
+    property_info_t property_list[] = {
+        { "class-code", 0 },
+        { "device-id", 0 },
+        { "vendor-id", 0 },
+        { "revision-id", 0},
+        { "subsystem-vendor-id", 0},
+        { "subsystem-id", 0},
+    };
+#define NUM_PROPERTIES         sizeof(property_list)/sizeof(property_info_t)
 
-           /*
-            * Found one device with bus number, device number and
-            * function number.
-            */
+    len = di_prop_lookup_ints(DDI_DEV_T_ANY, node, "reg", &retbuf);
 
-           pci_base = &pci_sys->devices[pci_sys->num_devices].base;
+#ifdef __sparc
+    if ((len <= 0) && di_phdl)
+       len = di_prom_prop_lookup_ints(di_phdl, node, "reg", &retbuf);
+#endif
 
-           /*
-            * Domain is peer bus??
-            */
-           pci_base->domain = 0;
-           pci_base->bus = prg_p->bus_no;
-           pci_base->dev = prg_p->dev_no;
-           pci_base->func = func;
+    /* Exclude usb devices */
+    if (len < 5) {
+       return DI_WALK_CONTINUE;
+    }
 
-           /*
-            * for the format of device_class, see struct pci_device;
-            */
+    pci_base = &pinfo->devices[pinfo->num_devices].base;
+
+    pci_base->domain = nexus->domain;
+    pci_base->bus = PCI_REG_BUS_G(retbuf[0]);
+    pci_base->dev = PCI_REG_DEV_G(retbuf[0]);
+    pci_base->func  = PCI_REG_FUNC_G(retbuf[0]);
+
+    /* Get property values */
+    for (i = 0; i < NUM_PROPERTIES; i++) {
+       len = di_prop_lookup_ints(DDI_DEV_T_ANY, node,
+               property_list[i].name, &retbuf);
+#ifdef __sparc
+       if ((len <= 0) && di_phdl)
+           len = di_prom_prop_lookup_ints(di_phdl, node,
+               property_list[i].name, &retbuf);
+#endif
 
-           pci_base->device_class =
-               (GET_CONFIG_VAL_8(PCI_CONF_BASCLASS) << 16) |
-               (GET_CONFIG_VAL_8(PCI_CONF_SUBCLASS) << 8) |
-               GET_CONFIG_VAL_8(PCI_CONF_PROGCLASS);
+       if (len > 0)
+           property_list[i].value = retbuf[0];
+       else {
+           /* a device must have property "class-code", "device-id", "vendor-id" */
+           if (i < 3)
+               return DI_WALK_CONTINUE;
+#ifdef DEBUG
+           fprintf(stderr, "cannot get property \"%s\" for nexus = %s :\n",
+               property_list[i].name, nexus->path);
+           fprintf(stderr, "   domain = %x, busno = %x, devno = %x, funcno = %x\n",
+               pci_base->domain, pci_base->bus, pci_base->dev, pci_base->func);
+#endif
+       }
+    }
 
-           pci_base->revision          = GET_CONFIG_VAL_8(PCI_CONF_REVID);
-           pci_base->vendor_id         = GET_CONFIG_VAL_16(PCI_CONF_VENID);
-           pci_base->device_id         = GET_CONFIG_VAL_16(PCI_CONF_DEVID);
-           pci_base->subvendor_id      = GET_CONFIG_VAL_16(PCI_CONF_SUBVENID);
-           pci_base->subdevice_id      = GET_CONFIG_VAL_16(PCI_CONF_SUBSYSID);
+    if ((property_list[1].value == 0) && (property_list[2].value == 0))
+       return DI_WALK_CONTINUE;
 
-           pci_sys->devices[pci_sys->num_devices].header_type
-                                       = GET_CONFIG_VAL_8(PCI_CONF_HEADER);
+    pci_base->device_class = property_list[0].value;
+    pci_base->device_id = property_list[1].value;
+    pci_base->vendor_id = property_list[2].value;
+    pci_base->revision = property_list[3].value;
+    pci_base->subvendor_id = property_list[4].value;
+    pci_base->subdevice_id = property_list[5].value;
 
 #ifdef DEBUG
-           fprintf(stderr,
-                   "nexus = %s, busno = %x, devno = %x, funcno = %x\n",
-                   nexus->path, prg_p->bus_no, prg_p->dev_no, func);
+    fprintf(stderr,
+           "nexus = %s, domain = %x, busno = %x, devno = %x, funcno = %x\n",
+           nexus->path, pci_base->domain, pci_base->bus, pci_base->dev, pci_base->func);
 #endif
 
-           if (pci_sys->num_devices < (MAX_DEVICES - 1)) {
-               pci_sys->num_devices++;
-           } else {
-               (void) fprintf(stderr,
-                              "Maximum number of PCI devices found,"
-                              " discarding additional devices\n");
-           }
-
-
-           /*
-            * Accommodate devices which state their
-            * multi-functionality only in their function 0 config
-            * space.  Note multi-functionality throughout probing
-            * of all of this device's functions.
-            */
-           if (config_hdr.bytes[PCI_CONF_HEADER] & PCI_HEADER_MULTI) {
-               multi_function_device = B_TRUE;
-           }
+    pinfo->num_devices++;
+    if (pinfo->num_devices == pinfo->num_allocated_elems) {
+       struct pci_device_private *new_devs;
+       size_t new_num_elems = pinfo->num_allocated_elems * 2;
+
+       new_devs = realloc(pinfo->devices,
+       new_num_elems * sizeof (struct pci_device_private));
+       if (new_devs == NULL) {
+           (void) fprintf(stderr,
+                  "Error allocating memory for PCI devices:"
+                  " %s\n discarding additional devices\n",
+                  strerror(errno));
+           ((probe_args_t *)arg)->ret = 1;
+           return (DI_WALK_TERMINATE);
        }
+       (void) memset(&new_devs[pinfo->num_devices], 0,
+               pinfo->num_allocated_elems *
+               sizeof (struct pci_device_private));
+       pinfo->num_allocated_elems = new_num_elems;
+       pinfo->devices = new_devs;
     }
 
-    return (rval);
+    return (DI_WALK_CONTINUE);
 }
-
 /*
  * This function is called from di_walk_minor() when any PROBE is processed
  */
 static int
 probe_nexus_node(di_node_t di_node, di_minor_t minor, void *arg)
 {
-    struct pci_system *pci_sys = (struct pci_system *) arg;
-    char *nexus_name;
+    probe_info_t *pinfo = (probe_info_t *)arg;
+    char *nexus_name, *nexus_dev_path;
     nexus_t *nexus;
     int fd;
     char nexus_path[MAXPATHLEN];
@@ -515,10 +315,19 @@ probe_nexus_node(di_node_t di_node, di_minor_t minor, void *arg)
     int numval;
     int pci_node = 0;
     int first_bus = 0, last_bus = PCI_REG_BUS_G(PCI_REG_BUS_M);
+    int domain = 0;
+    di_node_t rnode =  DI_NODE_NIL;
+#ifdef __sparc
+    int bus_range_found = 0;
+    int device_type_found = 0;
+    di_prom_prop_t prom_prop;
+#endif
+
 
 #ifdef DEBUG
     nexus_name = di_devfs_minor_path(minor);
     fprintf(stderr, "-- device name: %s\n", nexus_name);
+    di_devfs_path_free(nexus_name);
 #endif
 
     for (prop = di_prop_next(di_node, NULL); prop != NULL;
@@ -532,11 +341,17 @@ probe_nexus_node(di_node_t di_node, di_minor_t minor, void *arg)
 
        if (strcmp(prop_name, "device_type") == 0) {
            numval = di_prop_strings(prop, &strings);
-           if (numval != 1 || strncmp(strings, "pci", 3) != 0) {
-               /* not a PCI node, bail */
-               return (DI_WALK_CONTINUE);
+           if (numval == 1) {
+               if (strncmp(strings, "pci", 3) != 0)
+                   /* not a PCI node, bail */
+                   return (DI_WALK_CONTINUE);
+               else {
+                   pci_node = 1;
+#ifdef __sparc
+                   device_type_found =  1;
+#endif
+               }
            }
-           pci_node = 1;
        }
        else if (strcmp(prop_name, "class-code") == 0) {
            /* not a root bus node, bail */
@@ -547,14 +362,47 @@ probe_nexus_node(di_node_t di_node, di_minor_t minor, void *arg)
            if (numval == 2) {
                first_bus = ints[0];
                last_bus = ints[1];
+#ifdef __sparc
+               bus_range_found = 1;
+#endif
            }
        }
+#ifdef __sparc
+       domain = nexus_count;
+#else
+       else if (strcmp(prop_name, "pciseg") == 0) {
+           numval = di_prop_ints(prop, &ints);
+           if (numval == 1) {
+               domain = ints[0];
+           }
+       }
+#endif
+    }
+
+#ifdef __sparc
+    if ((!device_type_found) && di_phdl) {
+       numval = di_prom_prop_lookup_strings(di_phdl, di_node,
+           "device_type", &strings);
+       if (numval == 1) {
+           if (strncmp(strings, "pci", 3) != 0)
+               return (DI_WALK_CONTINUE);
+           else
+               pci_node = 1;
+       }
     }
 
-#ifdef __x86  /* sparc pci nodes don't have the device_type set */
+    if ((!bus_range_found) && di_phdl) {
+       numval = di_prom_prop_lookup_ints(di_phdl, di_node,
+           "bus-range", &ints);
+       if (numval == 2) {
+           first_bus = ints[0];
+           last_bus = ints[1];
+       }
+    }
+#endif
+
     if (pci_node != 1)
        return (DI_WALK_CONTINUE);
-#endif
 
     /* we have a PCI root bus node. */
     nexus = calloc(1, sizeof(nexus_t));
@@ -565,6 +413,11 @@ probe_nexus_node(di_node_t di_node, di_minor_t minor, void *arg)
     }
     nexus->first_bus = first_bus;
     nexus->last_bus = last_bus;
+    nexus->domain = domain;
+
+#ifdef __sparc
+    nexus_count++;
+#endif
 
     nexus_name = di_devfs_minor_path(minor);
     if (nexus_name == NULL) {
@@ -582,84 +435,52 @@ probe_nexus_node(di_node_t di_node, di_minor_t minor, void *arg)
            nexus_path, first_bus, last_bus);
 #endif
 
-    if ((fd = open(nexus_path, O_RDWR)) >= 0) {
+    if ((fd = open(nexus_path, O_RDWR | O_CLOEXEC)) >= 0) {
+       probe_args_t args;
+
        nexus->fd = fd;
        nexus->path = strdup(nexus_path);
-       if ((do_probe(nexus, pci_sys) != 0) && (errno != ENXIO)) {
-           (void) fprintf(stderr, "Error probing node %s: %s\n",
-                          nexus_path, strerror(errno));
-           (void) close(fd);
+       nexus_dev_path = di_devfs_path(di_node);
+       nexus->dev_path = strdup(nexus_dev_path);
+       di_devfs_path_free(nexus_dev_path);
+
+       if ((rnode = di_init(nexus->dev_path, DINFOCPYALL)) == DI_NODE_NIL) {
+           (void) fprintf(stderr, "di_init failed: %s\n", strerror(errno));
+           close(nexus->fd);
            free(nexus->path);
+           free(nexus->dev_path);
            free(nexus);
-       } else {
-           nexus->next = nexus_list;
-           nexus_list = nexus;
+           return (DI_WALK_TERMINATE);
        }
+
+       /* Walk through devices under the rnode */
+       args.pinfo = pinfo;
+       args.nexus = nexus;
+       args.ret = 0;
+
+       (void) di_walk_node(rnode, DI_WALK_CLDFIRST, (void *)&args, probe_device_node);
+       if (args.ret) {
+           close(nexus->fd);
+           free(nexus->path);
+           free(nexus->dev_path);
+           free(nexus);
+           di_fini(rnode);
+           return (DI_WALK_TERMINATE);
+       }
+
+       nexus->next = nexus_list;
+       nexus_list = nexus;
     } else {
        (void) fprintf(stderr, "Error opening %s: %s\n",
                       nexus_path, strerror(errno));
        free(nexus);
     }
 
-    return DI_WALK_CONTINUE;
-}
-
-
-/*
- * Solaris version
- * Probe a given nexus config space for devices.
- *
- * fd is the file descriptor of the nexus.
- * input_args contains commandline options as specified by the user.
- */
-static int
-do_probe(nexus_t *nexus, struct pci_system *pci_sys)
-{
-    pcitool_reg_t prg;
-    uint32_t bus;
-    uint8_t dev;
-    uint32_t last_bus = nexus->last_bus;
-    uint8_t last_dev = PCI_REG_DEV_M >> PCI_REG_DEV_SHIFT;
-    uint8_t first_bus = nexus->first_bus;
-    uint8_t first_dev = 0;
-    int rval = 0;
-
-    prg.barnum = 0;    /* Config space. */
-
-    /* Must read in 4-byte quantities. */
-    prg.acc_attr = PCITOOL_ACC_ATTR_SIZE_4 + NATIVE_ENDIAN;
-
-    prg.data = 0;
-
-    /*
-     * Loop through all valid bus / dev / func combinations to check for
-     * all devices, with the following exceptions:
-     *
-     * When nothing is found at function 0 of a bus / dev combination, skip
-     * the other functions of that bus / dev combination.
-     *
-     * When a found device's function 0 is probed and it is determined that
-     * it is not a multifunction device, skip probing of that device's
-     * other functions.
-     */
-    for (bus = first_bus; ((bus <= last_bus) && (rval == 0)); bus++) {
-       prg.bus_no = (uint8_t)bus;
-
-       for (dev = first_dev; ((dev <= last_dev) && (rval == 0)); dev++) {
-           prg.dev_no = dev;
-           rval = probe_dev(nexus, &prg, pci_sys);
-       }
-
-       /*
-        * Ultra-45 southbridge workaround:
-        * ECANCELED tells to skip to the next bus.
-        */
-       if (rval == ECANCELED) {
-           rval = 0;
-       }
+    if (rnode != DI_NODE_NIL) {
+       di_fini(rnode);
     }
 
-    return (rval);
+    return DI_WALK_CONTINUE;
 }
 
 static int
@@ -668,18 +489,17 @@ find_target_node(di_node_t node, void *arg)
     int *regbuf = NULL;
     int len = 0;
     uint32_t busno, funcno, devno;
-    i_devnode_t *devnode;
-    void *prop = DI_PROP_NIL;
-    int i;
-
-    devnode = (i_devnode_t *)arg;
+    i_devnode_t *devnode = (i_devnode_t *)arg;
 
     /*
      * Test the property functions, only for testing
      */
     /*
+    void *prop = DI_PROP_NIL;
+
     (void) fprintf(stderr, "start of node 0x%x\n", node->nodeid);
     while ((prop = di_prop_hw_next(node, prop)) != DI_PROP_NIL) {
+       int i;
        (void) fprintf(stderr, "name=%s: ", di_prop_name(prop));
        len = 0;
        if (!strcmp(di_prop_name(prop), "reg")) {
@@ -695,6 +515,11 @@ find_target_node(di_node_t node, void *arg)
 
     len = di_prop_lookup_ints(DDI_DEV_T_ANY, node, "reg", &regbuf);
 
+#ifdef __sparc
+    if ((len <= 0) && di_phdl)
+       len = di_prom_prop_lookup_ints(di_phdl, node, "reg", &regbuf);
+#endif
+
     if (len <= 0) {
 #ifdef DEBUG
        fprintf(stderr, "error = %x\n", errno);
@@ -724,55 +549,61 @@ find_target_node(di_node_t node, void *arg)
 static int
 pci_device_solx_devfs_probe( struct pci_device * dev )
 {
-    uint8_t  config[256];
-    int err;
+    int err = 0;
     di_node_t rnode = DI_NODE_NIL;
     i_devnode_t args = { 0, 0, 0, DI_NODE_NIL };
     int *regbuf;
     pci_regspec_t *reg;
     int i;
-    pciaddr_t bytes;
     int len = 0;
     uint ent = 0;
+    struct pci_device_private *priv =
+       (struct pci_device_private *) dev;
+    nexus_t *nexus;
 
-    err = pci_device_solx_devfs_read( dev, config, 0, 256, & bytes );
+    if ( (nexus = find_nexus_for_bus(dev->domain, dev->bus)) == NULL )
+       return ENODEV;
 
-    if ( bytes >= 64 ) {
-       struct pci_device_private *priv =
-           (struct pci_device_private *) dev;
+    pci_device_cfg_read_u8(dev, &priv->header_type, PCI_CONF_HEADER);
 
-       dev->vendor_id = (uint16_t)config[0] + ((uint16_t)config[1] << 8);
-       dev->device_id = (uint16_t)config[2] + ((uint16_t)config[3] << 8);
-       dev->device_class = (uint32_t)config[9] +
-           ((uint32_t)config[10] << 8) +
-           ((uint16_t)config[11] << 16);
+    pci_device_cfg_read_u8(dev, (uint8_t *)&dev->irq, PCI_CONF_ILINE);
 
-       /*
-        * device class code is already there.
-        * see probe_dev function.
-        */
-       dev->revision = config[8];
-       dev->subvendor_id = (uint16_t)config[44] + ((uint16_t)config[45] << 8);
-       dev->subdevice_id = (uint16_t)config[46] + ((uint16_t)config[47] << 8);
-       dev->irq = config[60];
-
-       priv->header_type = config[14];
-       /*
-        * starting to find if it is MEM/MEM64/IO
-        * using libdevinfo
-        */
-       if ((rnode = di_init("/", DINFOCPYALL)) == DI_NODE_NIL) {
-           err = errno;
-           (void) fprintf(stderr, "di_init failed: %s\n", strerror(errno));
-       } else {
-           args.bus = dev->bus;
-           args.dev = dev->dev;
-           args.func = dev->func;
-           (void) di_walk_node(rnode, DI_WALK_CLDFIRST,
-                               (void *)&args, find_target_node);
-       }
+    /*
+     * starting to find if it is MEM/MEM64/IO
+     * using libdevinfo
+     */
+    if ((rnode = di_init(nexus->dev_path, DINFOCPYALL)) == DI_NODE_NIL) {
+       err = errno;
+       (void) fprintf(stderr, "di_init failed: %s\n", strerror(errno));
+    } else {
+       args.bus = dev->bus;
+       args.dev = dev->dev;
+       args.func = dev->func;
+       (void) di_walk_node(rnode, DI_WALK_CLDFIRST,
+               (void *)&args, find_target_node);
     }
+
     if (args.node != DI_NODE_NIL) {
+       int *prop;
+#ifdef __sparc
+       di_minor_t minor;
+#endif
+
+       priv->is_primary = 0;
+
+#ifdef __sparc
+       if (minor = di_minor_next(args.node, DI_MINOR_NIL))
+           MAPPING_DEV_PATH(dev) = di_devfs_minor_path (minor);
+       else
+           MAPPING_DEV_PATH(dev) = NULL;
+#endif
+
+       if (di_prop_lookup_ints(DDI_DEV_T_ANY, args.node,
+                               "primary-controller", &prop) >= 1) {
+           if (prop[0])
+               priv->is_primary = 1;
+       }
+
        /*
         * It will succeed for sure, because it was
         * successfully called in find_target_node
@@ -781,88 +612,80 @@ pci_device_solx_devfs_probe( struct pci_device * dev )
                                  "assigned-addresses",
                                  &regbuf);
 
+#ifdef __sparc
+       if ((len <= 0) && di_phdl) {
+           len = di_prom_prop_lookup_ints(di_phdl, args.node,
+                               "assigned-addresses", &regbuf);
+       }
+#endif
     }
 
     if (len <= 0)
        goto cleanup;
 
-
     /*
-     * how to find the size of rom???
-     * if the device has expansion rom,
-     * it must be listed in the last
-     * cells because solaris find probe
-     * the base address from offset 0x10
-     * to 0x30h. So only check the last
-     * item.
-     */
-    reg = (pci_regspec_t *)&regbuf[len - CELL_NUMS_1275];
-    if (PCI_REG_REG_G(reg->pci_phys_hi) == PCI_CONF_ROM) {
-       /*
-        * rom can only be 32 bits
-        */
-       dev->rom_size = reg->pci_size_low;
-       len = len - CELL_NUMS_1275;
-    }
-    else {
-       /*
-        * size default to 64K and base address
-        * default to 0xC0000
-        */
-       dev->rom_size = 0x10000;
-    }
-
-    /*
-     * Solaris has its own BAR index.
+     * Each BAR address get its own region slot in sequence.
+     * 32 bit BAR:
+     * BAR 0x10 -> slot0, BAR 0x14 -> slot1...
+     * 64 bit BAR:
+     * BAR 0x10 -> slot0, BAR 0x18 -> slot2...,
+     * slot1 is part of BAR 0x10
      * Linux give two region slot for 64 bit address.
      */
     for (i = 0; i < len; i = i + CELL_NUMS_1275) {
 
        reg = (pci_regspec_t *)&regbuf[i];
        ent = reg->pci_phys_hi & 0xff;
-       /*
-        * G35 broken in BAR0
-        */
-       ent = (ent - PCI_CONF_BASE0) >> 2;
-       if (ent >= 6) {
+
+       if (ent > PCI_CONF_ROM) {
            fprintf(stderr, "error ent = %d\n", ent);
            break;
        }
-
        /*
-        * non relocatable resource is excluded
-        * such like 0xa0000, 0x3b0. If it is met,
-        * the loop is broken;
+        * G35 broken in BAR0
         */
-       if (!PCI_REG_REG_G(reg->pci_phys_hi))
+       if (ent < PCI_CONF_BASE0) {
+           /*
+            * VGA resource here and ignore it
+            */
            break;
+       } else if (ent == PCI_CONF_ROM) {
+           priv->rom_base = reg->pci_phys_low |
+               ((uint64_t)reg->pci_phys_mid << 32);
+           dev->rom_size = reg->pci_size_low;
+       } else {
+           ent = (ent - PCI_CONF_BASE0) >> 2;
+           /*
+            * non relocatable resource is excluded
+            * such like 0xa0000, 0x3b0. If it is met,
+            * the loop is broken;
+            */
+           if (!PCI_REG_REG_G(reg->pci_phys_hi))
+               break;
 
-       if (reg->pci_phys_hi & PCI_PREFETCH_B) {
-           dev->regions[ent].is_prefetchable = 1;
-       }
+           if (reg->pci_phys_hi & PCI_PREFETCH_B) {
+               dev->regions[ent].is_prefetchable = 1;
+           }
 
 
-       /*
-        * We split the shift count 32 into two 16 to
-        * avoid the complaining of the compiler
-        */
-       dev->regions[ent].base_addr = reg->pci_phys_low +
-           ((reg->pci_phys_mid << 16) << 16);
-       dev->regions[ent].size = reg->pci_size_low +
-           ((reg->pci_size_hi << 16) << 16);
-
-       switch (reg->pci_phys_hi & PCI_REG_ADDR_M) {
-           case PCI_ADDR_IO:
-               dev->regions[ent].is_IO = 1;
-               break;
-           case PCI_ADDR_MEM32:
-               break;
-           case PCI_ADDR_MEM64:
-               dev->regions[ent].is_64 = 1;
-               /*
-                * Skip one slot for 64 bit address
-                */
-               break;
+           dev->regions[ent].base_addr = reg->pci_phys_low |
+               ((uint64_t)reg->pci_phys_mid << 32);
+           dev->regions[ent].size = reg->pci_size_low |
+               ((uint64_t)reg->pci_size_hi << 32);
+
+           switch (reg->pci_phys_hi & PCI_REG_ADDR_M) {
+               case PCI_ADDR_IO:
+                   dev->regions[ent].is_IO = 1;
+                   break;
+               case PCI_ADDR_MEM32:
+                   break;
+               case PCI_ADDR_MEM64:
+                   dev->regions[ent].is_64 = 1;
+                   /*
+                    * Skip one slot for 64 bit address
+                    */
+                   break;
+           }
        }
     }
 
@@ -873,6 +696,71 @@ pci_device_solx_devfs_probe( struct pci_device * dev )
     return (err);
 }
 
+/**
+ * Map a memory region for a device using /dev/xsvc (x86) or fb device (sparc)
+ *
+ * \param dev   Device whose memory region is to be mapped.
+ * \param map   Parameters of the mapping that is to be created.
+ *
+ * \return
+ * Zero on success or an \c errno value on failure.
+ */
+static int
+pci_device_solx_devfs_map_range(struct pci_device *dev,
+                               struct pci_device_mapping *map)
+{
+    const int prot = ((map->flags & PCI_DEV_MAP_FLAG_WRITABLE) != 0)
+                       ? (PROT_READ | PROT_WRITE) : PROT_READ;
+    int err = 0;
+
+    const char *map_dev;
+    int                map_fd;
+
+#ifdef __sparc
+    char       map_dev_buf[128];
+
+    if (MAPPING_DEV_PATH(dev)) {
+       snprintf(map_dev_buf, sizeof (map_dev_buf), "%s%s",
+                "/devices", MAPPING_DEV_PATH(dev));
+       map_dev = map_dev_buf;
+    }
+    else
+       map_dev = "/dev/fb0";
+
+    map_fd = -1;
+#else
+    /*
+     * Still uses xsvc to do the user space mapping on x86/x64,
+     * caches open fd across multiple calls.
+     */
+    map_dev = "/dev/xsvc";
+    map_fd = xsvc_fd;
+#endif
+
+    if (map_fd < 0) {
+       if ((map_fd = open(map_dev, O_RDWR | O_CLOEXEC)) < 0) {
+           err = errno;
+           (void) fprintf(stderr, "can not open %s: %s\n", map_dev,
+                          strerror(errno));
+           return err;
+       }
+    }
+
+    map->memory = mmap(NULL, map->size, prot, MAP_SHARED, map_fd, map->base);
+    if (map->memory == MAP_FAILED) {
+       err = errno;
+
+       (void) fprintf(stderr, "map rom region =%llx failed: %s\n",
+                      (unsigned long long) map->base, strerror(errno));
+    }
+
+#ifdef __sparc
+    close (map_fd);
+#endif
+
+    return err;
+}
+
 /*
  * Solaris version: read the VGA ROM data
  */
@@ -882,15 +770,22 @@ pci_device_solx_devfs_read_rom( struct pci_device * dev, void * buffer )
     int err;
     struct pci_device_mapping prom = {
        .base = 0xC0000,
-       .size = dev->rom_size,
+       .size = 0x10000,
        .flags = 0
     };
+    struct pci_device_private *priv =
+       (struct pci_device_private *) dev;
+
+    if (priv->rom_base) {
+       prom.base = priv->rom_base;
+       prom.size = dev->rom_size;
+    }
 
     err = pci_device_solx_devfs_map_range(dev, &prom);
     if (err == 0) {
        (void) bcopy(prom.memory, buffer, dev->rom_size);
 
-       if (munmap(prom.memory, dev->rom_size) == -1) {
+       if (munmap(prom.memory, prom.size) == -1) {
            err = errno;
        }
     }
@@ -908,7 +803,9 @@ pci_device_solx_devfs_read( struct pci_device * dev, void * data,
     pcitool_reg_t cfg_prg;
     int err = 0;
     int i = 0;
-    nexus_t *nexus = find_nexus_for_bus(dev->bus);
+    nexus_t *nexus;
+
+    nexus = find_nexus_for_bus(dev->domain, dev->bus);
 
     *bytes_read = 0;
 
@@ -934,7 +831,7 @@ pci_device_solx_devfs_read( struct pci_device * dev, void * data,
                    cfg_prg.bus_no,
                    cfg_prg.dev_no,
                    cfg_prg.func_no,
-                   cfg_prg.offset);
+                   (unsigned long long) cfg_prg.offset);
            fprintf(stderr, "Failure cause = %x\n", err);
            break;
        }
@@ -960,7 +857,9 @@ pci_device_solx_devfs_write( struct pci_device * dev, const void * data,
     pcitool_reg_t cfg_prg;
     int err = 0;
     int cmd;
-    nexus_t *nexus = find_nexus_for_bus(dev->bus);
+    nexus_t *nexus;
+
+    nexus = find_nexus_for_bus(dev->domain, dev->bus);
 
     if ( bytes_written != NULL ) {
        *bytes_written = 0;
@@ -974,15 +873,19 @@ pci_device_solx_devfs_write( struct pci_device * dev, const void * data,
     switch (size) {
         case 1:
            cfg_prg.acc_attr = PCITOOL_ACC_ATTR_SIZE_1 + NATIVE_ENDIAN;
+           cfg_prg.data = *((const uint8_t *)data);
            break;
         case 2:
            cfg_prg.acc_attr = PCITOOL_ACC_ATTR_SIZE_2 + NATIVE_ENDIAN;
+           cfg_prg.data = *((const uint16_t *)data);
            break;
         case 4:
            cfg_prg.acc_attr = PCITOOL_ACC_ATTR_SIZE_4 + NATIVE_ENDIAN;
+           cfg_prg.data = *((const uint32_t *)data);
            break;
         case 8:
            cfg_prg.acc_attr = PCITOOL_ACC_ATTR_SIZE_8 + NATIVE_ENDIAN;
+           cfg_prg.data = *((const uint64_t *)data);
            break;
         default:
            return EINVAL;
@@ -992,7 +895,6 @@ pci_device_solx_devfs_write( struct pci_device * dev, const void * data,
     cfg_prg.func_no = dev->func;
     cfg_prg.barnum = 0;
     cfg_prg.user_version = PCITOOL_USER_VERSION;
-    cfg_prg.data = *((uint64_t *)data);
 
     /*
      * Check if this device is bridge device.
@@ -1011,43 +913,218 @@ pci_device_solx_devfs_write( struct pci_device * dev, const void * data,
     return (err);
 }
 
+static int pci_device_solx_devfs_boot_vga(struct pci_device *dev)
+{
+    struct pci_device_private *priv =
+       (struct pci_device_private *) dev;
+
+    return (priv->is_primary);
+
+}
+
+static struct pci_io_handle *
+pci_device_solx_devfs_open_legacy_io(struct pci_io_handle *ret,
+                                    struct pci_device *dev,
+                                    pciaddr_t base, pciaddr_t size)
+{
+#ifdef __x86
+    if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) == 0) {
+       ret->base = base;
+       ret->size = size;
+       return ret;
+    }
+#endif
+    return NULL;
+}
+
+static uint32_t
+pci_device_solx_devfs_read32(struct pci_io_handle *handle, uint32_t reg)
+{
+#ifdef __x86
+    uint16_t port = (uint16_t) (handle->base + reg);
+    uint32_t ret;
+    __asm__ __volatile__("inl %1,%0":"=a"(ret):"d"(port));
+    return ret;
+#else
+    return *(uint32_t *)((uintptr_t)handle->memory + reg);
+#endif
+}
+
+static uint16_t
+pci_device_solx_devfs_read16(struct pci_io_handle *handle, uint32_t reg)
+{
+#ifdef __x86
+    uint16_t port = (uint16_t) (handle->base + reg);
+    uint16_t ret;
+    __asm__ __volatile__("inw %1,%0":"=a"(ret):"d"(port));
+    return ret;
+#else
+    return *(uint16_t *)((uintptr_t)handle->memory + reg);
+#endif
+}
+
+static uint8_t
+pci_device_solx_devfs_read8(struct pci_io_handle *handle, uint32_t reg)
+{
+#ifdef __x86
+    uint16_t port = (uint16_t) (handle->base + reg);
+    uint8_t ret;
+    __asm__ __volatile__("inb %1,%0":"=a"(ret):"d"(port));
+    return ret;
+#else
+    return *(uint8_t *)((uintptr_t)handle->memory + reg);
+#endif
+}
+
+static void
+pci_device_solx_devfs_write32(struct pci_io_handle *handle, uint32_t reg,
+    uint32_t data)
+{
+#ifdef __x86
+      uint16_t port = (uint16_t) (handle->base + reg);
+      __asm__ __volatile__("outl %0,%1"::"a"(data), "d"(port));
+#else
+      *(uint16_t *)((uintptr_t)handle->memory + reg) = data;
+#endif
+}
+
+static void
+pci_device_solx_devfs_write16(struct pci_io_handle *handle, uint32_t reg,
+    uint16_t data)
+{
+#ifdef __x86
+      uint16_t port = (uint16_t) (handle->base + reg);
+      __asm__ __volatile__("outw %0,%1"::"a"(data), "d"(port));
+#else
+    *(uint8_t *)((uintptr_t)handle->memory + reg) = data;
+#endif
+}
+
+static void
+pci_device_solx_devfs_write8(struct pci_io_handle *handle, uint32_t reg,
+    uint8_t data)
+{
+#ifdef __x86
+      uint16_t port = (uint16_t) (handle->base + reg);
+      __asm__ __volatile__("outb %0,%1"::"a"(data), "d"(port));
+#else
+      *(uint32_t *)((uintptr_t)handle->memory + reg) = data;
+#endif
+}
 
-/**
- * Map a memory region for a device using /dev/xsvc.
- *
- * \param dev   Device whose memory region is to be mapped.
- * \param map   Parameters of the mapping that is to be created.
- *
- * \return
- * Zero on success or an \c errno value on failure.
- */
 static int
-pci_device_solx_devfs_map_range(struct pci_device *dev,
-                               struct pci_device_mapping *map)
+pci_device_solx_devfs_map_legacy(struct pci_device *dev, pciaddr_t base,
+                                pciaddr_t size, unsigned map_flags,
+                                void **addr)
+{
+    int err;
+    struct pci_device_mapping map = {
+       .base = base,
+       .size = size,
+       .flags = map_flags,
+    };
+
+    err = pci_device_solx_devfs_map_range(dev, &map);
+    if (err == 0)
+       *addr = map.memory;
+    return err;
+}
+
+static int
+pci_device_solx_devfs_unmap_legacy(struct pci_device *dev,
+                                  void *addr, pciaddr_t size)
+{
+    struct pci_device_mapping map = {
+       .memory = addr,
+       .size = size,
+    };
+
+    return pci_device_generic_unmap_range(dev, &map);
+}
+
+static const struct pci_system_methods solx_devfs_methods = {
+    .destroy = pci_system_solx_devfs_destroy,
+#ifdef __sparc
+    .destroy_device = pci_system_solx_devfs_destroy_device,
+#else
+    .destroy_device = NULL,
+#endif
+    .read_rom = pci_device_solx_devfs_read_rom,
+    .probe = pci_device_solx_devfs_probe,
+    .map_range = pci_device_solx_devfs_map_range,
+    .unmap_range = pci_device_generic_unmap_range,
+
+    .read = pci_device_solx_devfs_read,
+    .write = pci_device_solx_devfs_write,
+
+    .fill_capabilities = pci_fill_capabilities_generic,
+    .boot_vga = pci_device_solx_devfs_boot_vga,
+
+    .open_legacy_io = pci_device_solx_devfs_open_legacy_io,
+    .read32 = pci_device_solx_devfs_read32,
+    .read16 = pci_device_solx_devfs_read16,
+    .read8 = pci_device_solx_devfs_read8,
+    .write32 = pci_device_solx_devfs_write32,
+    .write16 = pci_device_solx_devfs_write16,
+    .write8 = pci_device_solx_devfs_write8,
+    .map_legacy = pci_device_solx_devfs_map_legacy,
+    .unmap_legacy = pci_device_solx_devfs_unmap_legacy,
+};
+
+/*
+ * Attempt to access PCI subsystem using Solaris's devfs interface.
+ * Solaris version
+ */
+_pci_hidden int
+pci_system_solx_devfs_create( void )
 {
-    const int prot = ((map->flags & PCI_DEV_MAP_FLAG_WRITABLE) != 0)
-                       ? (PROT_READ | PROT_WRITE) : PROT_READ;
     int err = 0;
+    di_node_t di_node;
+    probe_info_t pinfo;
+    struct pci_device_private *devices;
 
-    /*
-     * Still used xsvc to do the user space mapping
-     */
-    if (xsvc_fd < 0) {
-       if ((xsvc_fd = open("/dev/xsvc", O_RDWR)) < 0) {
-           err = errno;
-           (void) fprintf(stderr, "can not open /dev/xsvc: %s\n",
-                          strerror(errno));
-           return err;
-       }
+    if (nexus_list != NULL) {
+       return 0;
     }
 
-    map->memory = mmap(NULL, map->size, prot, MAP_SHARED, xsvc_fd, map->base);
-    if (map->memory == MAP_FAILED) {
+    if ((di_node = di_init("/", DINFOCPYALL)) == DI_NODE_NIL) {
        err = errno;
+       (void) fprintf(stderr, "di_init() failed: %s\n",
+                      strerror(errno));
+       return (err);
+    }
 
-       (void) fprintf(stderr, "map rom region =%llx failed: %s\n",
-                      map->base, strerror(errno));
+    if ((devices = calloc(INITIAL_NUM_DEVICES,
+                       sizeof (struct pci_device_private))) == NULL) {
+       err = errno;
+       di_fini(di_node);
+       return (err);
     }
 
-    return err;
+#ifdef __sparc
+    if ((di_phdl = di_prom_init()) == DI_PROM_HANDLE_NIL)
+       (void) fprintf(stderr, "di_prom_init failed: %s\n", strerror(errno));
+#endif
+
+    pinfo.num_allocated_elems = INITIAL_NUM_DEVICES;
+    pinfo.num_devices = 0;
+    pinfo.devices = devices;
+#ifdef __sparc
+    nexus_count = 0;
+#endif
+    (void) di_walk_minor(di_node, DDI_NT_REGACC, 0, &pinfo, probe_nexus_node);
+
+    di_fini(di_node);
+
+    if ((pci_sys = calloc(1, sizeof (struct pci_system))) == NULL) {
+       err = errno;
+       free(devices);
+       return (err);
+    }
+
+    pci_sys->methods = &solx_devfs_methods;
+    pci_sys->devices = pinfo.devices;
+    pci_sys->num_devices = pinfo.num_devices;
+
+    return (err);
 }