2 * (C) Copyright IBM Corporation 2006
3 * Copyright (c) 2007, 2009, 2011, 2012, 2013 Oracle and/or its affiliates.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * on the rights to use, copy, modify, merge, publish, distribute, sub
10 * license, and/or sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 * IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
26 * Solaris devfs interfaces
33 #include <sys/types.h>
38 #include <libdevinfo.h>
39 #include "pci_tools.h"
42 # include <sys/sysi86.h>
46 #include "pciaccess.h"
47 #include "pciaccess_private.h"
51 #define INITIAL_NUM_DEVICES 256
52 #define CELL_NUMS_1275 (sizeof(pci_regspec_t) / sizeof(uint_t))
54 typedef struct i_devnode {
61 typedef struct nexus {
66 char *path; /* for errors/debugging; fd is all we need */
71 typedef struct probe_info {
72 volatile size_t num_allocated_elems;
73 volatile size_t num_devices;
74 struct pci_device_private * volatile devices;
77 typedef struct probe_args {
83 typedef struct property_info {
88 static nexus_t *nexus_list = NULL;
90 static int xsvc_fd = -1;
94 static di_prom_handle_t di_phdl;
95 static size_t nexus_count = 0;
99 * Read config space in native processor endianness. Endian-neutral
100 * processing can then take place. On big endian machines, MSB and LSB
101 * of little endian data end up switched if read as little endian.
102 * They are in correct order if read as big endian.
105 # define NATIVE_ENDIAN PCITOOL_ACC_ATTR_ENDN_BIG
107 # define NATIVE_ENDIAN PCITOOL_ACC_ATTR_ENDN_LTL
109 # error "ISA is neither __sparc nor __x86"
113 #define MAPPING_DEV_PATH(dev) (((struct pci_device_private *) dev)->device_string)
117 * Identify problematic southbridges. These have device id 0x5249 and
118 * vendor id 0x10b9. Check for revision ID 0 and class code 060400 as well.
119 * Values are little endian, so they are reversed for SPARC.
121 * Check for these southbridges on all architectures, as the issue is a
122 * southbridge issue, independent of processor.
124 * If one of these is found during probing, skip probing other devs/funcs on
125 * the rest of the bus, since the southbridge and all devs underneath will
126 * otherwise disappear.
128 #if (NATIVE_ENDIAN == PCITOOL_ACC_ATTR_ENDN_BIG)
129 # define U45_SB_DEVID_VID 0xb9104952
130 # define U45_SB_CLASS_RID 0x00000406
132 # define U45_SB_DEVID_VID 0x524910b9
133 # define U45_SB_CLASS_RID 0x06040000
137 find_nexus_for_bus( int domain, int bus )
141 for (nexus = nexus_list ; nexus != NULL ; nexus = nexus->next) {
142 if ((domain == nexus->domain) &&
143 (bus >= nexus->first_bus) && (bus <= nexus->last_bus)) {
151 * Release all the resources
155 pci_system_solx_devfs_destroy( void )
158 * The memory allocated for pci_sys & devices in create routines
159 * will be freed in pci_system_cleanup.
160 * Need to free system-specific allocations here.
162 nexus_t *nexus, *next;
164 for (nexus = nexus_list ; nexus != NULL ; nexus = next) {
168 free(nexus->dev_path);
174 if (di_phdl != DI_PROM_HANDLE_NIL)
175 (void) di_prom_fini(di_phdl);
187 * Release resources per device
190 pci_system_solx_devfs_destroy_device( struct pci_device *dev )
192 if (MAPPING_DEV_PATH(dev))
193 di_devfs_path_free((char *) MAPPING_DEV_PATH(dev));
199 probe_device_node(di_node_t node, void *arg)
203 struct pci_device *pci_base;
204 probe_info_t *pinfo = ((probe_args_t *)arg)->pinfo;
205 nexus_t *nexus = ((probe_args_t *)arg)->nexus;
206 property_info_t property_list[] = {
211 { "subsystem-vendor-id", 0},
212 { "subsystem-id", 0},
214 #define NUM_PROPERTIES sizeof(property_list)/sizeof(property_info_t)
216 len = di_prop_lookup_ints(DDI_DEV_T_ANY, node, "reg", &retbuf);
219 if ((len <= 0) && di_phdl)
220 len = di_prom_prop_lookup_ints(di_phdl, node, "reg", &retbuf);
223 /* Exclude usb devices */
225 return DI_WALK_CONTINUE;
228 pci_base = &pinfo->devices[pinfo->num_devices].base;
230 pci_base->domain = nexus->domain;
231 pci_base->bus = PCI_REG_BUS_G(retbuf[0]);
232 pci_base->dev = PCI_REG_DEV_G(retbuf[0]);
233 pci_base->func = PCI_REG_FUNC_G(retbuf[0]);
235 /* Get property values */
236 for (i = 0; i < NUM_PROPERTIES; i++) {
237 len = di_prop_lookup_ints(DDI_DEV_T_ANY, node,
238 property_list[i].name, &retbuf);
240 if ((len <= 0) && di_phdl)
241 len = di_prom_prop_lookup_ints(di_phdl, node,
242 property_list[i].name, &retbuf);
246 property_list[i].value = retbuf[0];
248 /* a device must have property "class-code", "device-id", "vendor-id" */
250 return DI_WALK_CONTINUE;
252 fprintf(stderr, "cannot get property \"%s\" for nexus = %s :\n",
253 property_list[i].name, nexus->path);
254 fprintf(stderr, " domain = %x, busno = %x, devno = %x, funcno = %x\n",
255 pci_base->domain, pci_base->bus, pci_base->dev, pci_base->func);
260 if ((property_list[1].value == 0) && (property_list[2].value == 0))
261 return DI_WALK_CONTINUE;
263 pci_base->device_class = property_list[0].value;
264 pci_base->device_id = property_list[1].value;
265 pci_base->vendor_id = property_list[2].value;
266 pci_base->revision = property_list[3].value;
267 pci_base->subvendor_id = property_list[4].value;
268 pci_base->subdevice_id = property_list[5].value;
272 "nexus = %s, domain = %x, busno = %x, devno = %x, funcno = %x\n",
273 nexus->path, pci_base->domain, pci_base->bus, pci_base->dev, pci_base->func);
276 pinfo->num_devices++;
277 if (pinfo->num_devices == pinfo->num_allocated_elems) {
278 struct pci_device_private *new_devs;
279 size_t new_num_elems = pinfo->num_allocated_elems * 2;
281 new_devs = realloc(pinfo->devices,
282 new_num_elems * sizeof (struct pci_device_private));
283 if (new_devs == NULL) {
284 (void) fprintf(stderr,
285 "Error allocating memory for PCI devices:"
286 " %s\n discarding additional devices\n",
288 ((probe_args_t *)arg)->ret = 1;
289 return (DI_WALK_TERMINATE);
291 (void) memset(&new_devs[pinfo->num_devices], 0,
292 pinfo->num_allocated_elems *
293 sizeof (struct pci_device_private));
294 pinfo->num_allocated_elems = new_num_elems;
295 pinfo->devices = new_devs;
298 return (DI_WALK_CONTINUE);
301 * This function is called from di_walk_minor() when any PROBE is processed
304 probe_nexus_node(di_node_t di_node, di_minor_t minor, void *arg)
306 probe_info_t *pinfo = (probe_info_t *)arg;
307 char *nexus_name, *nexus_dev_path;
310 char nexus_path[MAXPATHLEN];
317 int first_bus = 0, last_bus = PCI_REG_BUS_G(PCI_REG_BUS_M);
319 di_node_t rnode = DI_NODE_NIL;
321 int bus_range_found = 0;
322 int device_type_found = 0;
323 di_prom_prop_t prom_prop;
328 nexus_name = di_devfs_minor_path(minor);
329 fprintf(stderr, "-- device name: %s\n", nexus_name);
330 di_devfs_path_free(nexus_name);
333 for (prop = di_prop_next(di_node, NULL); prop != NULL;
334 prop = di_prop_next(di_node, prop)) {
336 const char *prop_name = di_prop_name(prop);
339 fprintf(stderr, " property: %s\n", prop_name);
342 if (strcmp(prop_name, "device_type") == 0) {
343 numval = di_prop_strings(prop, &strings);
345 if (strncmp(strings, "pci", 3) != 0)
346 /* not a PCI node, bail */
347 return (DI_WALK_CONTINUE);
351 device_type_found = 1;
356 else if (strcmp(prop_name, "class-code") == 0) {
357 /* not a root bus node, bail */
358 return (DI_WALK_CONTINUE);
360 else if (strcmp(prop_name, "bus-range") == 0) {
361 numval = di_prop_ints(prop, &ints);
371 domain = nexus_count;
373 else if (strcmp(prop_name, "pciseg") == 0) {
374 numval = di_prop_ints(prop, &ints);
383 if ((!device_type_found) && di_phdl) {
384 numval = di_prom_prop_lookup_strings(di_phdl, di_node,
385 "device_type", &strings);
387 if (strncmp(strings, "pci", 3) != 0)
388 return (DI_WALK_CONTINUE);
394 if ((!bus_range_found) && di_phdl) {
395 numval = di_prom_prop_lookup_ints(di_phdl, di_node,
405 return (DI_WALK_CONTINUE);
407 /* we have a PCI root bus node. */
408 nexus = calloc(1, sizeof(nexus_t));
410 (void) fprintf(stderr, "Error allocating memory for nexus: %s\n",
412 return (DI_WALK_TERMINATE);
414 nexus->first_bus = first_bus;
415 nexus->last_bus = last_bus;
416 nexus->domain = domain;
422 nexus_name = di_devfs_minor_path(minor);
423 if (nexus_name == NULL) {
424 (void) fprintf(stderr, "Error getting nexus path: %s\n",
427 return (DI_WALK_CONTINUE);
430 snprintf(nexus_path, sizeof(nexus_path), "/devices%s", nexus_name);
431 di_devfs_path_free(nexus_name);
434 fprintf(stderr, "nexus = %s, bus-range = %d - %d\n",
435 nexus_path, first_bus, last_bus);
438 if ((fd = open(nexus_path, O_RDWR | O_CLOEXEC)) >= 0) {
442 nexus->path = strdup(nexus_path);
443 nexus_dev_path = di_devfs_path(di_node);
444 nexus->dev_path = strdup(nexus_dev_path);
445 di_devfs_path_free(nexus_dev_path);
447 if ((rnode = di_init(nexus->dev_path, DINFOCPYALL)) == DI_NODE_NIL) {
448 (void) fprintf(stderr, "di_init failed: %s\n", strerror(errno));
451 free(nexus->dev_path);
453 return (DI_WALK_TERMINATE);
456 /* Walk through devices under the rnode */
461 (void) di_walk_node(rnode, DI_WALK_CLDFIRST, (void *)&args, probe_device_node);
465 free(nexus->dev_path);
468 return (DI_WALK_TERMINATE);
471 nexus->next = nexus_list;
474 (void) fprintf(stderr, "Error opening %s: %s\n",
475 nexus_path, strerror(errno));
479 if (rnode != DI_NODE_NIL) {
483 return DI_WALK_CONTINUE;
487 find_target_node(di_node_t node, void *arg)
491 uint32_t busno, funcno, devno;
492 i_devnode_t *devnode = (i_devnode_t *)arg;
495 * Test the property functions, only for testing
498 void *prop = DI_PROP_NIL;
500 (void) fprintf(stderr, "start of node 0x%x\n", node->nodeid);
501 while ((prop = di_prop_hw_next(node, prop)) != DI_PROP_NIL) {
503 (void) fprintf(stderr, "name=%s: ", di_prop_name(prop));
505 if (!strcmp(di_prop_name(prop), "reg")) {
506 len = di_prop_ints(prop, ®buf);
508 for (i = 0; i < len; i++) {
509 fprintf(stderr, "0x%0x.", regbuf[i]);
511 fprintf(stderr, "\n");
513 (void) fprintf(stderr, "end of node 0x%x\n", node->nodeid);
516 len = di_prop_lookup_ints(DDI_DEV_T_ANY, node, "reg", ®buf);
519 if ((len <= 0) && di_phdl)
520 len = di_prom_prop_lookup_ints(di_phdl, node, "reg", ®buf);
525 fprintf(stderr, "error = %x\n", errno);
526 fprintf(stderr, "can not find assigned-address\n");
528 return (DI_WALK_CONTINUE);
531 busno = PCI_REG_BUS_G(regbuf[0]);
532 devno = PCI_REG_DEV_G(regbuf[0]);
533 funcno = PCI_REG_FUNC_G(regbuf[0]);
535 if ((busno == devnode->bus) &&
536 (devno == devnode->dev) &&
537 (funcno == devnode->func)) {
538 devnode->node = node;
540 return (DI_WALK_TERMINATE);
543 return (DI_WALK_CONTINUE);
550 pci_device_solx_devfs_probe( struct pci_device * dev )
553 di_node_t rnode = DI_NODE_NIL;
554 i_devnode_t args = { 0, 0, 0, DI_NODE_NIL };
560 struct pci_device_private *priv =
561 (struct pci_device_private *) dev;
564 if ( (nexus = find_nexus_for_bus(dev->domain, dev->bus)) == NULL )
567 pci_device_cfg_read_u8(dev, &priv->header_type, PCI_CONF_HEADER);
569 pci_device_cfg_read_u8(dev, (uint8_t *)&dev->irq, PCI_CONF_ILINE);
572 * starting to find if it is MEM/MEM64/IO
575 if ((rnode = di_init(nexus->dev_path, DINFOCPYALL)) == DI_NODE_NIL) {
577 (void) fprintf(stderr, "di_init failed: %s\n", strerror(errno));
581 args.func = dev->func;
582 (void) di_walk_node(rnode, DI_WALK_CLDFIRST,
583 (void *)&args, find_target_node);
586 if (args.node != DI_NODE_NIL) {
592 priv->is_primary = 0;
595 if (minor = di_minor_next(args.node, DI_MINOR_NIL))
596 MAPPING_DEV_PATH(dev) = di_devfs_minor_path (minor);
598 MAPPING_DEV_PATH(dev) = NULL;
601 if (di_prop_lookup_ints(DDI_DEV_T_ANY, args.node,
602 "primary-controller", &prop) >= 1) {
604 priv->is_primary = 1;
608 * It will succeed for sure, because it was
609 * successfully called in find_target_node
611 len = di_prop_lookup_ints(DDI_DEV_T_ANY, args.node,
612 "assigned-addresses",
616 if ((len <= 0) && di_phdl) {
617 len = di_prom_prop_lookup_ints(di_phdl, args.node,
618 "assigned-addresses", ®buf);
627 * Each BAR address get its own region slot in sequence.
629 * BAR 0x10 -> slot0, BAR 0x14 -> slot1...
631 * BAR 0x10 -> slot0, BAR 0x18 -> slot2...,
632 * slot1 is part of BAR 0x10
633 * Linux give two region slot for 64 bit address.
635 for (i = 0; i < len; i = i + CELL_NUMS_1275) {
637 reg = (pci_regspec_t *)®buf[i];
638 ent = reg->pci_phys_hi & 0xff;
640 if (ent > PCI_CONF_ROM) {
641 fprintf(stderr, "error ent = %d\n", ent);
647 if (ent < PCI_CONF_BASE0) {
649 * VGA resource here and ignore it
652 } else if (ent == PCI_CONF_ROM) {
653 priv->rom_base = reg->pci_phys_low |
654 ((uint64_t)reg->pci_phys_mid << 32);
655 dev->rom_size = reg->pci_size_low;
657 ent = (ent - PCI_CONF_BASE0) >> 2;
659 * non relocatable resource is excluded
660 * such like 0xa0000, 0x3b0. If it is met,
661 * the loop is broken;
663 if (!PCI_REG_REG_G(reg->pci_phys_hi))
666 if (reg->pci_phys_hi & PCI_PREFETCH_B) {
667 dev->regions[ent].is_prefetchable = 1;
671 dev->regions[ent].base_addr = reg->pci_phys_low |
672 ((uint64_t)reg->pci_phys_mid << 32);
673 dev->regions[ent].size = reg->pci_size_low |
674 ((uint64_t)reg->pci_size_hi << 32);
676 switch (reg->pci_phys_hi & PCI_REG_ADDR_M) {
678 dev->regions[ent].is_IO = 1;
683 dev->regions[ent].is_64 = 1;
685 * Skip one slot for 64 bit address
693 if (rnode != DI_NODE_NIL) {
700 * Map a memory region for a device using /dev/xsvc (x86) or fb device (sparc)
702 * \param dev Device whose memory region is to be mapped.
703 * \param map Parameters of the mapping that is to be created.
706 * Zero on success or an \c errno value on failure.
709 pci_device_solx_devfs_map_range(struct pci_device *dev,
710 struct pci_device_mapping *map)
712 const int prot = ((map->flags & PCI_DEV_MAP_FLAG_WRITABLE) != 0)
713 ? (PROT_READ | PROT_WRITE) : PROT_READ;
720 char map_dev_buf[128];
722 if (MAPPING_DEV_PATH(dev)) {
723 snprintf(map_dev_buf, sizeof (map_dev_buf), "%s%s",
724 "/devices", MAPPING_DEV_PATH(dev));
725 map_dev = map_dev_buf;
728 map_dev = "/dev/fb0";
733 * Still uses xsvc to do the user space mapping on x86/x64,
734 * caches open fd across multiple calls.
736 map_dev = "/dev/xsvc";
741 if ((map_fd = open(map_dev, O_RDWR | O_CLOEXEC)) < 0) {
743 (void) fprintf(stderr, "can not open %s: %s\n", map_dev,
749 map->memory = mmap(NULL, map->size, prot, MAP_SHARED, map_fd, map->base);
750 if (map->memory == MAP_FAILED) {
753 (void) fprintf(stderr, "map rom region =%llx failed: %s\n",
754 (unsigned long long) map->base, strerror(errno));
765 * Solaris version: read the VGA ROM data
768 pci_device_solx_devfs_read_rom( struct pci_device * dev, void * buffer )
771 struct pci_device_mapping prom = {
776 struct pci_device_private *priv =
777 (struct pci_device_private *) dev;
779 if (priv->rom_base) {
780 prom.base = priv->rom_base;
781 prom.size = dev->rom_size;
784 err = pci_device_solx_devfs_map_range(dev, &prom);
786 (void) bcopy(prom.memory, buffer, dev->rom_size);
788 if (munmap(prom.memory, prom.size) == -1) {
796 * solaris version: Read the configurations space of the devices
799 pci_device_solx_devfs_read( struct pci_device * dev, void * data,
800 pciaddr_t offset, pciaddr_t size,
801 pciaddr_t * bytes_read )
803 pcitool_reg_t cfg_prg;
808 nexus = find_nexus_for_bus(dev->domain, dev->bus);
812 if ( nexus == NULL ) {
816 cfg_prg.offset = offset;
817 cfg_prg.acc_attr = PCITOOL_ACC_ATTR_SIZE_1 + NATIVE_ENDIAN;
818 cfg_prg.bus_no = dev->bus;
819 cfg_prg.dev_no = dev->dev;
820 cfg_prg.func_no = dev->func;
822 cfg_prg.user_version = PCITOOL_USER_VERSION;
824 for (i = 0; i < size; i += PCITOOL_ACC_ATTR_SIZE(PCITOOL_ACC_ATTR_SIZE_1))
826 cfg_prg.offset = offset + i;
828 if ((err = ioctl(nexus->fd, PCITOOL_DEVICE_GET_REG, &cfg_prg)) != 0) {
829 fprintf(stderr, "read bdf<%s,%x,%x,%x,%llx> config space failure\n",
834 (unsigned long long) cfg_prg.offset);
835 fprintf(stderr, "Failure cause = %x\n", err);
839 ((uint8_t *)data)[i] = (uint8_t)cfg_prg.data;
841 * DWORDS Offset or bytes Offset ??
853 pci_device_solx_devfs_write( struct pci_device * dev, const void * data,
854 pciaddr_t offset, pciaddr_t size,
855 pciaddr_t * bytes_written )
857 pcitool_reg_t cfg_prg;
862 nexus = find_nexus_for_bus(dev->domain, dev->bus);
864 if ( bytes_written != NULL ) {
868 if ( nexus == NULL ) {
872 cfg_prg.offset = offset;
875 cfg_prg.acc_attr = PCITOOL_ACC_ATTR_SIZE_1 + NATIVE_ENDIAN;
876 cfg_prg.data = *((const uint8_t *)data);
879 cfg_prg.acc_attr = PCITOOL_ACC_ATTR_SIZE_2 + NATIVE_ENDIAN;
880 cfg_prg.data = *((const uint16_t *)data);
883 cfg_prg.acc_attr = PCITOOL_ACC_ATTR_SIZE_4 + NATIVE_ENDIAN;
884 cfg_prg.data = *((const uint32_t *)data);
887 cfg_prg.acc_attr = PCITOOL_ACC_ATTR_SIZE_8 + NATIVE_ENDIAN;
888 cfg_prg.data = *((const uint64_t *)data);
893 cfg_prg.bus_no = dev->bus;
894 cfg_prg.dev_no = dev->dev;
895 cfg_prg.func_no = dev->func;
897 cfg_prg.user_version = PCITOOL_USER_VERSION;
900 * Check if this device is bridge device.
901 * If it is, it is also a nexus node???
902 * It seems that there is no explicit
903 * PCI nexus device for X86, so not applicable
904 * from pcitool_bus_reg_ops in pci_tools.c
906 cmd = PCITOOL_DEVICE_SET_REG;
908 if ((err = ioctl(nexus->fd, cmd, &cfg_prg)) != 0) {
911 *bytes_written = size;
916 static int pci_device_solx_devfs_boot_vga(struct pci_device *dev)
918 struct pci_device_private *priv =
919 (struct pci_device_private *) dev;
921 return (priv->is_primary);
925 static struct pci_io_handle *
926 pci_device_solx_devfs_open_legacy_io(struct pci_io_handle *ret,
927 struct pci_device *dev,
928 pciaddr_t base, pciaddr_t size)
931 if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) == 0) {
941 pci_device_solx_devfs_read32(struct pci_io_handle *handle, uint32_t reg)
944 uint16_t port = (uint16_t) (handle->base + reg);
946 __asm__ __volatile__("inl %1,%0":"=a"(ret):"d"(port));
949 return *(uint32_t *)((uintptr_t)handle->memory + reg);
954 pci_device_solx_devfs_read16(struct pci_io_handle *handle, uint32_t reg)
957 uint16_t port = (uint16_t) (handle->base + reg);
959 __asm__ __volatile__("inw %1,%0":"=a"(ret):"d"(port));
962 return *(uint16_t *)((uintptr_t)handle->memory + reg);
967 pci_device_solx_devfs_read8(struct pci_io_handle *handle, uint32_t reg)
970 uint16_t port = (uint16_t) (handle->base + reg);
972 __asm__ __volatile__("inb %1,%0":"=a"(ret):"d"(port));
975 return *(uint8_t *)((uintptr_t)handle->memory + reg);
980 pci_device_solx_devfs_write32(struct pci_io_handle *handle, uint32_t reg,
984 uint16_t port = (uint16_t) (handle->base + reg);
985 __asm__ __volatile__("outl %0,%1"::"a"(data), "d"(port));
987 *(uint16_t *)((uintptr_t)handle->memory + reg) = data;
992 pci_device_solx_devfs_write16(struct pci_io_handle *handle, uint32_t reg,
996 uint16_t port = (uint16_t) (handle->base + reg);
997 __asm__ __volatile__("outw %0,%1"::"a"(data), "d"(port));
999 *(uint8_t *)((uintptr_t)handle->memory + reg) = data;
1004 pci_device_solx_devfs_write8(struct pci_io_handle *handle, uint32_t reg,
1008 uint16_t port = (uint16_t) (handle->base + reg);
1009 __asm__ __volatile__("outb %0,%1"::"a"(data), "d"(port));
1011 *(uint32_t *)((uintptr_t)handle->memory + reg) = data;
1016 pci_device_solx_devfs_map_legacy(struct pci_device *dev, pciaddr_t base,
1017 pciaddr_t size, unsigned map_flags,
1021 struct pci_device_mapping map = {
1027 err = pci_device_solx_devfs_map_range(dev, &map);
1034 pci_device_solx_devfs_unmap_legacy(struct pci_device *dev,
1035 void *addr, pciaddr_t size)
1037 struct pci_device_mapping map = {
1042 return pci_device_generic_unmap_range(dev, &map);
1045 static const struct pci_system_methods solx_devfs_methods = {
1046 .destroy = pci_system_solx_devfs_destroy,
1048 .destroy_device = pci_system_solx_devfs_destroy_device,
1050 .destroy_device = NULL,
1052 .read_rom = pci_device_solx_devfs_read_rom,
1053 .probe = pci_device_solx_devfs_probe,
1054 .map_range = pci_device_solx_devfs_map_range,
1055 .unmap_range = pci_device_generic_unmap_range,
1057 .read = pci_device_solx_devfs_read,
1058 .write = pci_device_solx_devfs_write,
1060 .fill_capabilities = pci_fill_capabilities_generic,
1061 .boot_vga = pci_device_solx_devfs_boot_vga,
1063 .open_legacy_io = pci_device_solx_devfs_open_legacy_io,
1064 .read32 = pci_device_solx_devfs_read32,
1065 .read16 = pci_device_solx_devfs_read16,
1066 .read8 = pci_device_solx_devfs_read8,
1067 .write32 = pci_device_solx_devfs_write32,
1068 .write16 = pci_device_solx_devfs_write16,
1069 .write8 = pci_device_solx_devfs_write8,
1070 .map_legacy = pci_device_solx_devfs_map_legacy,
1071 .unmap_legacy = pci_device_solx_devfs_unmap_legacy,
1075 * Attempt to access PCI subsystem using Solaris's devfs interface.
1079 pci_system_solx_devfs_create( void )
1084 struct pci_device_private *devices;
1086 if (nexus_list != NULL) {
1090 if ((di_node = di_init("/", DINFOCPYALL)) == DI_NODE_NIL) {
1092 (void) fprintf(stderr, "di_init() failed: %s\n",
1097 if ((devices = calloc(INITIAL_NUM_DEVICES,
1098 sizeof (struct pci_device_private))) == NULL) {
1105 if ((di_phdl = di_prom_init()) == DI_PROM_HANDLE_NIL)
1106 (void) fprintf(stderr, "di_prom_init failed: %s\n", strerror(errno));
1109 pinfo.num_allocated_elems = INITIAL_NUM_DEVICES;
1110 pinfo.num_devices = 0;
1111 pinfo.devices = devices;
1115 (void) di_walk_minor(di_node, DDI_NT_REGACC, 0, &pinfo, probe_nexus_node);
1119 if ((pci_sys = calloc(1, sizeof (struct pci_system))) == NULL) {
1125 pci_sys->methods = &solx_devfs_methods;
1126 pci_sys->devices = pinfo.devices;
1127 pci_sys->num_devices = pinfo.num_devices;