head 1.16; access; symbols pkgsrc-2013Q2:1.15.0.2 pkgsrc-2013Q2-base:1.15 pkgsrc-2013Q1:1.13.0.4 pkgsrc-2013Q1-base:1.13 pkgsrc-2012Q4:1.13.0.2 pkgsrc-2012Q4-base:1.13 pkgsrc-2012Q3:1.12.0.2 pkgsrc-2012Q3-base:1.12 pkgsrc-2012Q2:1.10.0.10 pkgsrc-2012Q2-base:1.10 pkgsrc-2012Q1:1.10.0.8 pkgsrc-2012Q1-base:1.10 pkgsrc-2011Q4:1.10.0.6 pkgsrc-2011Q4-base:1.10 pkgsrc-2011Q3:1.10.0.4 pkgsrc-2011Q3-base:1.10 pkgsrc-2011Q2:1.10.0.2 pkgsrc-2011Q2-base:1.10 pkgsrc-2011Q1:1.7.0.2 pkgsrc-2011Q1-base:1.7 pkgsrc-2010Q4:1.6.0.6 pkgsrc-2010Q4-base:1.6 pkgsrc-2010Q3:1.6.0.4 pkgsrc-2010Q3-base:1.6 pkgsrc-2010Q2:1.6.0.2 pkgsrc-2010Q2-base:1.6 pkgsrc-2010Q1:1.5.0.8 pkgsrc-2010Q1-base:1.5 pkgsrc-2009Q4:1.5.0.6 pkgsrc-2009Q4-base:1.5 pkgsrc-2009Q3:1.5.0.4 pkgsrc-2009Q3-base:1.5 pkgsrc-2009Q2:1.5.0.2 pkgsrc-2009Q2-base:1.5 pkgsrc-2009Q1:1.3.0.4 pkgsrc-2009Q1-base:1.3 pkgsrc-2008Q4:1.3.0.2 pkgsrc-2008Q4-base:1.3 pkgsrc-base:1.1.1.1 TNF:1.1.1; locks; strict; comment @# @; 1.16 date 2013.07.21.09.42.40; author wiz; state dead; branches; next 1.15; commitid yJ0Uk7GvWkiITjYw; 1.15 date 2013.06.04.10.16.00; author obache; state Exp; branches; next 1.14; commitid ghSqj5itAJMKBhSw; 1.14 date 2013.06.03.14.19.38; author wiz; state Exp; branches; next 1.13; commitid RggxlFZ3nOVeZaSw; 1.13 date 2012.10.12.00.37.05; author taca; state Exp; branches; next 1.12; 1.12 date 2012.07.15.08.12.42; author wiz; state Exp; branches 1.12.2.1; next 1.11; 1.11 date 2012.07.14.23.42.13; author wiz; state Exp; branches; next 1.10; 1.10 date 2011.05.09.15.26.16; author taca; state Exp; branches; next 1.9; 1.9 date 2011.05.09.14.06.46; author taca; state Exp; branches; next 1.8; 1.8 date 2011.05.07.10.06.34; author shattered; state Exp; branches; next 1.7; 1.7 date 2011.02.10.16.20.45; author pooka; state Exp; branches; next 1.6; 1.6 date 2010.04.09.08.09.11; author tnn; state Exp; branches; next 1.5; 1.5 date 2009.05.25.20.11.05; author drochner; state Exp; branches; next 1.4; 1.4 date 2009.05.18.19.09.01; author hasso; state Exp; branches; next 1.3; 1.3 date 2008.10.30.21.06.32; author bjs; state Exp; branches; next 1.2; 1.2 date 2008.10.30.21.00.37; author bjs; state Exp; branches; next 1.1; 1.1 date 2008.10.30.20.58.11; author bjs; state Exp; branches 1.1.1.1; next ; 1.12.2.1 date 2012.10.12.08.43.45; author tron; state Exp; branches; next ; 1.1.1.1 date 2008.10.30.20.58.11; author bjs; state Exp; branches; next ; desc @@ 1.16 log @Update to 0.13.2. Set LICENSE. This release provides a lot of platform-specific improvements for various platforms, including Solaris (SPARC & x64), FreeBSD, NetBSD, and Hurd. It also provides some platform-independent fixes & code cleanup. Adam Jackson (1): configure: Remove AM_MAINTAINER_MODE Alan Coopersmith (10): Solaris: Implement map_legacy & legacy_io functions Solaris: refactor pci_device_solx_devfs_map_range to reduce code duplication Bug 63583 - add legacy IO routines for FreeBSD Define PCI_MATCH_ANY as an unsigned int pci_id_file_open: move variable inside the #ifndef that uses it pci_device_solx_devfs_read: fix sign conversion/comparison warnings Solaris: Remove #defines for Ultra 45 southbridge device ids pci_device_solx_devfs_probe: implicit conversion changes signedness warnings Resync COPYING file with copyrights/licenses from code libpciaccess 0.13.2 Colin Walters (1): autogen.sh: Implement GNOME Build API Egbert Eich (1): PCI: set correct mask value when matching for bridges. Henry Zhao (5): libpciaccess: implementation of boot_vga in Solaris libpciaccess: sparc rom read fix scanpci: print meaningful info on BASEROM Solaris: Add domain support for sparc platform Solaris: probe improvement John Martin (1): Fix Sun bug #7035791: scanpci should report 64 bit registers Mark Logan (1): libpciaccess: fix memory usage errors Samuel Thibault (1): Implement legacy io & map for x86 backend Thomas Klausner (6): Protect config.h like usual. Move 'const' to correct place, so it has meaning. Update NetBSD support. Enable boot_vga support only if WSDISPLAYIO_GET_BUSID is defined. Fix build on NetBSD-4. Support more pci functions on NetBSD. @ text @$NetBSD: patch-ac,v 1.15 2013/06/04 10:16:00 obache Exp $ Improve NetBSD support. From Michael Lorenz . Enable boot_vga support only if WSDISPLAYIO_GET_BUSID is defined. --- src/netbsd_pci.c.orig 2012-04-09 10:02:57.000000000 -0700 +++ src/netbsd_pci.c 2013-06-02 06:52:58.000000000 -0700 @@@@ -1,6 +1,7 @@@@ /* * Copyright (c) 2008 Juan Romero Pardines * Copyright (c) 2008 Mark Kettenis + * Copyright (c) 2009 Michael Lorenz * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@@@ -20,8 +21,22 @@@@ #include #include +#include "config.h" + +#ifdef HAVE_MTRR #include #include +#ifdef _X86_SYSARCH_L +#define netbsd_set_mtrr(mr, num) _X86_SYSARCH_L(set_mtrr)(mr, num) +#else +#ifdef __i386__ +#define netbsd_set_mtrr(mr, num) i386_set_mtrr((mr), (num)) +#endif +#ifdef __amd64__ +#define netbsd_set_mtrr(mr, num) x86_64_set_mtrr((mr), (num)) +#endif +#endif +#endif #include #include @@@@ -35,126 +50,152 @@@@ #include +#include +#include + #include "pciaccess.h" #include "pciaccess_private.h" -static int pcifd; +typedef struct _pcibus { + int fd; /* /dev/pci* */ + int num; /* bus number */ + int maxdevs; /* maximum number of devices */ +} PciBus; + +static PciBus buses[32]; /* indexed by pci_device.domain */ +static int nbuses = 0; /* number of buses found */ + +/* + * NetBSD's userland has a /dev/pci* entry for each bus but userland has no way + * to tell if a bus is a subordinate of another one or if it's on a different + * host bridge. On some architectures ( macppc for example ) all root buses have + * bus number 0 but on sparc64 for example the two roots in an Ultra60 have + * different bus numbers - one is 0 and the other 128. + * With each /dev/pci* we can map everything on the same root and we can also + * see all devices on the same root, trying to do that causes problems though: + * - since we can't tell which /dev/pci* is a subordinate we would find some + * devices more than once + * - we would have to guess subordinate bus numbers which is a waste of time + * since we can ask each /dev/pci* for its bus number so we can scan only the + * buses we know exist, not all 256 which may exist in each domain. + * - some bus_space_mmap() methods may limit mappings to address ranges which + * belong to known devices on that bus only. + * Each host bridge may or may not have its own IO range, to avoid guesswork + * here each /dev/pci* will let userland map its appropriate IO range at + * PCI_MAGIC_IO_RANGE if defined in + * With all this we should be able to use any PCI graphics device on any PCI + * bus on any architecture as long as Xorg has a driver, without allowing + * arbitrary mappings via /dev/mem and without userland having to know or care + * about translating bus addresses to physical addresses or the other way + * around. + */ static int -pci_read(int bus, int dev, int func, uint32_t reg, uint32_t *val) +pci_read(int domain, int bus, int dev, int func, uint32_t reg, uint32_t *val) { - struct pciio_bdf_cfgreg io; - int err; + uint32_t rval; - bzero(&io, sizeof(io)); - io.bus = bus; - io.device = dev; - io.function = func; - io.cfgreg.reg = reg; + if ((domain < 0) || (domain > nbuses)) + return -1; - err = ioctl(pcifd, PCI_IOC_BDF_CFGREAD, &io); - if (err) - return (err); + if (pcibus_conf_read(buses[domain].fd, (unsigned int)bus, + (unsigned int)dev, (unsigned int)func, reg, &rval) == -1) + return (-1); - *val = io.cfgreg.val; + *val = rval; return 0; } static int -pci_write(int bus, int dev, int func, uint32_t reg, uint32_t val) +pci_write(int domain, int bus, int dev, int func, uint32_t reg, uint32_t val) { - struct pciio_bdf_cfgreg io; - bzero(&io, sizeof(io)); - io.bus = bus; - io.device = dev; - io.function = func; - io.cfgreg.reg = reg; - io.cfgreg.val = val; + if ((domain < 0) || (domain > nbuses)) + return -1; - return ioctl(pcifd, PCI_IOC_BDF_CFGWRITE, &io); + return pcibus_conf_write(buses[domain].fd, (unsigned int)bus, + (unsigned int)dev, (unsigned int)func, reg, val); } static int -pci_nfuncs(int bus, int dev) +pci_nfuncs(int domain, int bus, int dev) { uint32_t hdr; - if (pci_read(bus, dev, 0, PCI_BHLC_REG, &hdr) != 0) + if ((domain < 0) || (domain > nbuses)) + return -1; + + if (pci_read(domain, bus, dev, 0, PCI_BHLC_REG, &hdr) != 0) return -1; return (PCI_HDRTYPE_MULTIFN(hdr) ? 8 : 1); } +/*ARGSUSED*/ static int pci_device_netbsd_map_range(struct pci_device *dev, struct pci_device_mapping *map) { - struct mtrr mtrr; - int fd, error, nmtrr, prot = PROT_READ; +#ifdef HAVE_MTRR + struct mtrr m; + int n = 1; +#endif + int prot, ret = 0; - if ((fd = open("/dev/mem", O_RDWR | O_CLOEXEC)) == -1) - return errno; + prot = PROT_READ; if (map->flags & PCI_DEV_MAP_FLAG_WRITABLE) prot |= PROT_WRITE; - - map->memory = mmap(NULL, map->size, prot, MAP_SHARED, - fd, map->base); + map->memory = mmap(NULL, (size_t)map->size, prot, MAP_SHARED, + buses[dev->domain].fd, (off_t)map->base); if (map->memory == MAP_FAILED) return errno; +#ifdef HAVE_MTRR + memset(&m, 0, sizeof(m)); + /* No need to set an MTRR if it's the default mode. */ if ((map->flags & PCI_DEV_MAP_FLAG_CACHABLE) || (map->flags & PCI_DEV_MAP_FLAG_WRITE_COMBINE)) { - mtrr.base = map->base; - mtrr.len = map->size; - mtrr.flags = MTRR_VALID; - + m.base = map->base; + m.flags = MTRR_VALID | MTRR_PRIVATE; + m.len = map->size; + m.owner = getpid(); if (map->flags & PCI_DEV_MAP_FLAG_CACHABLE) - mtrr.type = MTRR_TYPE_WB; + m.type = MTRR_TYPE_WB; if (map->flags & PCI_DEV_MAP_FLAG_WRITE_COMBINE) - mtrr.type = MTRR_TYPE_WC; -#ifdef __i386__ - error = i386_set_mtrr(&mtrr, &nmtrr); -#endif -#ifdef __amd64__ - error = x86_64_set_mtrr(&mtrr, &nmtrr); -#endif - if (error) { - close(fd); - return errno; + m.type = MTRR_TYPE_WC; + + if ((netbsd_set_mtrr(&m, &n)) == -1) { + fprintf(stderr, "mtrr set failed: %s\n", + strerror(errno)); } } +#endif - close(fd); - - return 0; + return ret; } static int pci_device_netbsd_unmap_range(struct pci_device *dev, struct pci_device_mapping *map) { - struct mtrr mtrr; - int nmtrr, error; +#ifdef HAVE_MTRR + struct mtrr m; + int n = 1; + + memset(&m, 0, sizeof(m)); if ((map->flags & PCI_DEV_MAP_FLAG_CACHABLE) || (map->flags & PCI_DEV_MAP_FLAG_WRITE_COMBINE)) { - mtrr.base = map->base; - mtrr.len = map->size; - mtrr.type = MTRR_TYPE_UC; - mtrr.flags = 0; /* clear/set MTRR */ -#ifdef __i386__ - error = i386_set_mtrr(&mtrr, &nmtrr); -#endif -#ifdef __amd64__ - error = x86_64_set_mtrr(&mtrr, &nmtrr); -#endif - if (error) - return errno; + m.base = map->base; + m.flags = 0; + m.len = map->size; + m.type = MTRR_TYPE_UC; + (void)netbsd_set_mtrr(&m, &n); } +#endif return pci_device_generic_unmap_range(dev, map); } @@@@ -163,25 +204,23 @@@@ static int pci_device_netbsd_read(struct pci_device *dev, void *data, pciaddr_t offset, pciaddr_t size, pciaddr_t *bytes_read) { - struct pciio_bdf_cfgreg io; - - io.bus = dev->bus; - io.device = dev->dev; - io.function = dev->func; + u_int reg, rval; *bytes_read = 0; while (size > 0) { - int toread = MIN(size, 4 - (offset & 0x3)); + size_t toread = MIN(size, 4 - (offset & 0x3)); - io.cfgreg.reg = (offset & ~0x3); + reg = (u_int)(offset & ~0x3); - if (ioctl(pcifd, PCI_IOC_BDF_CFGREAD, &io) == -1) + if ((pcibus_conf_read(buses[dev->domain].fd, + (unsigned int)dev->bus, (unsigned int)dev->dev, + (unsigned int)dev->func, reg, &rval)) == -1) return errno; - io.cfgreg.val = htole32(io.cfgreg.val); - io.cfgreg.val >>= ((offset & 0x3) * 8); + rval = htole32(rval); + rval >>= ((offset & 0x3) * 8); - memcpy(data, &io.cfgreg.val, toread); + memcpy(data, &rval, toread); offset += toread; data = (char *)data + toread; @@@@ -196,25 +235,23 @@@@ static int pci_device_netbsd_write(struct pci_device *dev, const void *data, pciaddr_t offset, pciaddr_t size, pciaddr_t *bytes_written) { - struct pciio_bdf_cfgreg io; + u_int reg, val; if ((offset % 4) != 0 || (size % 4) != 0) return EINVAL; - io.bus = dev->bus; - io.device = dev->dev; - io.function = dev->func; - *bytes_written = 0; while (size > 0) { - io.cfgreg.reg = offset; - memcpy(&io.cfgreg.val, data, 4); + reg = (u_int)offset; + memcpy(&val, data, 4); - if (ioctl(pcifd, PCI_IOC_BDF_CFGWRITE, &io) == -1) + if ((pcibus_conf_write(buses[dev->domain].fd, + (unsigned int)dev->bus, (unsigned int)dev->dev, + (unsigned int)dev->func, reg, val)) == -1) return errno; offset += 4; - data = (char *)data + 4; + data = (const char *)data + 4; size -= 4; *bytes_written += 4; } @@@@ -222,10 +259,53 @@@@ pci_device_netbsd_write(struct pci_devic return 0; } +#if defined(WSDISPLAYIO_GET_BUSID) +static int +pci_device_netbsd_boot_vga(struct pci_device *dev) +{ + int ret; + struct wsdisplayio_bus_id busid; + int fd; + + fd = open("/dev/ttyE0", O_RDONLY); + if (fd == -1) { + fprintf(stderr, "failed to open /dev/ttyE0: %s\n", + strerror(errno)); + return 0; + } + + ret = ioctl(fd, WSDISPLAYIO_GET_BUSID, &busid); + close(fd); + if (ret == -1) { + fprintf(stderr, "ioctl WSDISPLAYIO_GET_BUSID failed: %s\n", + strerror(errno)); + return 0; + } + + if (busid.bus_type != WSDISPLAYIO_BUS_PCI) + return 0; + + if (busid.ubus.pci.domain != dev->domain) + return 0; + if (busid.ubus.pci.bus != dev->bus) + return 0; + if (busid.ubus.pci.device != dev->dev) + return 0; + if (busid.ubus.pci.function != dev->func) + return 0; + + return 1; +} +#endif + static void pci_system_netbsd_destroy(void) { - close(pcifd); + int i; + + for (i = 0; i < nbuses; i++) { + close(buses[i].fd); + } free(pci_sys); pci_sys = NULL; } @@@@ -233,17 +313,34 @@@@ pci_system_netbsd_destroy(void) static int pci_device_netbsd_probe(struct pci_device *device) { - struct pci_device_private *priv = (struct pci_device_private *)device; + struct pci_device_private *priv = + (struct pci_device_private *)(void *)device; struct pci_mem_region *region; uint64_t reg64, size64; uint32_t bar, reg, size; - int bus, dev, func, err; + int bus, dev, func, err, domain; + domain = device->domain; bus = device->bus; dev = device->dev; func = device->func; - err = pci_read(bus, dev, func, PCI_BHLC_REG, ®); + /* Enable the device if necessary */ + err = pci_read(domain, bus, dev, func, PCI_COMMAND_STATUS_REG, ®); + if (err) + return err; + if ((reg & (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE | PCI_COMMAND_MASTER_ENABLE)) != + (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE | PCI_COMMAND_MASTER_ENABLE)) { + reg |= PCI_COMMAND_IO_ENABLE | + PCI_COMMAND_MEM_ENABLE | + PCI_COMMAND_MASTER_ENABLE; + err = pci_write(domain, bus, dev, func, PCI_COMMAND_STATUS_REG, + reg); + if (err) + return err; + } + + err = pci_read(domain, bus, dev, func, PCI_BHLC_REG, ®); if (err) return err; @@@@ -254,16 +351,16 @@@@ pci_device_netbsd_probe(struct pci_devic region = device->regions; for (bar = PCI_MAPREG_START; bar < PCI_MAPREG_END; bar += sizeof(uint32_t), region++) { - err = pci_read(bus, dev, func, bar, ®); + err = pci_read(domain, bus, dev, func, bar, ®); if (err) return err; /* Probe the size of the region. */ - err = pci_write(bus, dev, func, bar, ~0); + err = pci_write(domain, bus, dev, func, bar, (unsigned int)~0); if (err) return err; - pci_read(bus, dev, func, bar, &size); - pci_write(bus, dev, func, bar, reg); + pci_read(domain, bus, dev, func, bar, &size); + pci_write(domain, bus, dev, func, bar, reg); if (PCI_MAPREG_TYPE(reg) == PCI_MAPREG_TYPE_IO) { region->is_IO = 1; @@@@ -286,66 +383,524 @@@@ pci_device_netbsd_probe(struct pci_devic bar += sizeof(uint32_t); - err = pci_read(bus, dev, func, bar, ®); + err = pci_read(domain, bus, dev, func, bar, ®); if (err) return err; reg64 |= (uint64_t)reg << 32; - err = pci_write(bus, dev, func, bar, ~0); + err = pci_write(domain, bus, dev, func, bar, + (unsigned int)~0); if (err) return err; - pci_read(bus, dev, func, bar, &size); - pci_write(bus, dev, func, bar, reg64 >> 32); + pci_read(domain, bus, dev, func, bar, &size); + pci_write(domain, bus, dev, func, bar, + (unsigned int)(reg64 >> 32)); size64 |= (uint64_t)size << 32; - region->base_addr = PCI_MAPREG_MEM64_ADDR(reg64); - region->size = PCI_MAPREG_MEM64_SIZE(size64); + region->base_addr = + (unsigned long)PCI_MAPREG_MEM64_ADDR(reg64); + region->size = + (unsigned long)PCI_MAPREG_MEM64_SIZE(size64); region++; break; } } } + /* Probe expansion ROM if present */ + err = pci_read(domain, bus, dev, func, PCI_MAPREG_ROM, ®); + if (err) + return err; + if (reg != 0) { + err = pci_write(domain, bus, dev, func, PCI_MAPREG_ROM, + (uint32_t)(~PCI_MAPREG_ROM_ENABLE)); + if (err) + return err; + pci_read(domain, bus, dev, func, PCI_MAPREG_ROM, &size); + pci_write(domain, bus, dev, func, PCI_MAPREG_ROM, reg); + if ((reg & PCI_MAPREG_MEM_ADDR_MASK) != 0) { + priv->rom_base = reg & PCI_MAPREG_MEM_ADDR_MASK; + device->rom_size = -(size & PCI_MAPREG_MEM_ADDR_MASK); + } + } + return 0; } +/** + * Read a VGA rom using the 0xc0000 mapping. + * + * This function should be extended to handle access through PCI resources, + * which should be more reliable when available. + */ +static int +pci_device_netbsd_read_rom(struct pci_device *dev, void *buffer) +{ + struct pci_device_private *priv = (struct pci_device_private *)(void *)dev; + void *bios; + pciaddr_t rom_base; + size_t rom_size; + uint32_t bios_val, command_val; + int pci_rom; + + if (((priv->base.device_class >> 16) & 0xff) != PCI_CLASS_DISPLAY || + ((priv->base.device_class >> 8) & 0xff) != PCI_SUBCLASS_DISPLAY_VGA) + return ENOSYS; + + if (priv->rom_base == 0) { +#if defined(__amd64__) || defined(__i386__) + /* + * We need a way to detect when this isn't the console and reject + * this request outright. + */ + rom_base = 0xc0000; + rom_size = 0x10000; + pci_rom = 0; +#else + return ENOSYS; +#endif + } else { + rom_base = priv->rom_base; + rom_size = dev->rom_size; + pci_rom = 1; + if ((pcibus_conf_read(buses[dev->domain].fd, (unsigned int)dev->bus, + (unsigned int)dev->dev, (unsigned int)dev->func, + PCI_COMMAND_STATUS_REG, &command_val)) == -1) + return errno; + if ((command_val & PCI_COMMAND_MEM_ENABLE) == 0) { + if ((pcibus_conf_write(buses[dev->domain].fd, + (unsigned int)dev->bus, (unsigned int)dev->dev, + (unsigned int)dev->func, PCI_COMMAND_STATUS_REG, + command_val | PCI_COMMAND_MEM_ENABLE)) == -1) + return errno; + } + if ((pcibus_conf_read(buses[dev->domain].fd, (unsigned int)dev->bus, + (unsigned int)dev->dev, (unsigned int)dev->func, + PCI_MAPREG_ROM, &bios_val)) == -1) + return errno; + if ((bios_val & PCI_MAPREG_ROM_ENABLE) == 0) { + if ((pcibus_conf_write(buses[dev->domain].fd, + (unsigned int)dev->bus, + (unsigned int)dev->dev, (unsigned int)dev->func, + PCI_MAPREG_ROM, bios_val | PCI_MAPREG_ROM_ENABLE)) == -1) + return errno; + } + } + + fprintf(stderr, "Using rom_base = 0x%lx 0x%lx (pci_rom=%d)\n", + (long)rom_base, (long)rom_size, pci_rom); + + bios = mmap(NULL, rom_size, PROT_READ, MAP_SHARED, buses[dev->domain].fd, + (off_t)rom_base); + if (bios == MAP_FAILED) { + int serrno = errno; + return serrno; + } + + memcpy(buffer, bios, rom_size); + + munmap(bios, rom_size); + + if (pci_rom) { + if ((command_val & PCI_COMMAND_MEM_ENABLE) == 0) { + if ((pcibus_conf_write(buses[dev->domain].fd, + (unsigned int)dev->bus, + (unsigned int)dev->dev, (unsigned int)dev->func, + PCI_COMMAND_STATUS_REG, command_val)) == -1) + return errno; + } + if ((bios_val & PCI_MAPREG_ROM_ENABLE) == 0) { + if ((pcibus_conf_write(buses[dev->domain].fd, + (unsigned int)dev->bus, + (unsigned int)dev->dev, (unsigned int)dev->func, + PCI_MAPREG_ROM, bios_val)) == -1) + return errno; + } + } + + return 0; +} + +#if defined(__i386__) || defined(__amd64__) +#include +//#include + +/* + * Functions to provide access to x86 programmed I/O instructions. + * + * The in[bwl]() and out[bwl]() functions are split into two varieties: one to + * use a small, constant, 8-bit port number, and another to use a large or + * variable port number. The former can be compiled as a smaller instruction. + */ + + +#ifdef __OPTIMIZE__ + +#define __use_immediate_port(port) \ + (__builtin_constant_p((port)) && (port) < 0x100) + +#else + +#define __use_immediate_port(port) 0 + +#endif + + +#define inb(port) \ + (/* CONSTCOND */ __use_immediate_port(port) ? __inbc(port) : __inb(port)) + +static __inline u_int8_t +__inbc(unsigned port) +{ + u_int8_t data; + __asm __volatile("inb %w1,%0" : "=a" (data) : "id" (port)); + return data; +} + +static __inline u_int8_t +__inb(unsigned port) +{ + u_int8_t data; + __asm __volatile("inb %w1,%0" : "=a" (data) : "d" (port)); + return data; +} + +static __inline void +insb(unsigned port, void *addr, int cnt) +{ + void *dummy1; + int dummy2; + __asm __volatile("cld\n\trepne\n\tinsb" : + "=D" (dummy1), "=c" (dummy2) : + "d" (port), "0" (addr), "1" (cnt) : + "memory"); +} + +#define inw(port) \ + (/* CONSTCOND */ __use_immediate_port(port) ? __inwc(port) : __inw(port)) + +static __inline u_int16_t +__inwc(unsigned port) +{ + u_int16_t data; + __asm __volatile("inw %w1,%0" : "=a" (data) : "id" (port)); + return data; +} + +static __inline u_int16_t +__inw(unsigned port) +{ + u_int16_t data; + __asm __volatile("inw %w1,%0" : "=a" (data) : "d" (port)); + return data; +} + +static __inline void +insw(unsigned port, void *addr, int cnt) +{ + void *dummy1; + int dummy2; + __asm __volatile("cld\n\trepne\n\tinsw" : + "=D" (dummy1), "=c" (dummy2) : + "d" (port), "0" (addr), "1" (cnt) : + "memory"); +} + +#define inl(port) \ + (/* CONSTCOND */ __use_immediate_port(port) ? __inlc(port) : __inl(port)) + +static __inline u_int32_t +__inlc(unsigned port) +{ + u_int32_t data; + __asm __volatile("inl %w1,%0" : "=a" (data) : "id" (port)); + return data; +} + +static __inline u_int32_t +__inl(unsigned port) +{ + u_int32_t data; + __asm __volatile("inl %w1,%0" : "=a" (data) : "d" (port)); + return data; +} + +static __inline void +insl(unsigned port, void *addr, int cnt) +{ + void *dummy1; + int dummy2; + __asm __volatile("cld\n\trepne\n\tinsl" : + "=D" (dummy1), "=c" (dummy2) : + "d" (port), "0" (addr), "1" (cnt) : + "memory"); +} + +#define outb(port, data) \ + (/* CONSTCOND */__use_immediate_port(port) ? __outbc(port, data) : \ + __outb(port, data)) + +static __inline void +__outbc(unsigned port, u_int8_t data) +{ + __asm __volatile("outb %0,%w1" : : "a" (data), "id" (port)); +} + +static __inline void +__outb(unsigned port, u_int8_t data) +{ + __asm __volatile("outb %0,%w1" : : "a" (data), "d" (port)); +} + +static __inline void +outsb(unsigned port, const void *addr, int cnt) +{ + void *dummy1; + int dummy2; + __asm __volatile("cld\n\trepne\n\toutsb" : + "=S" (dummy1), "=c" (dummy2) : + "d" (port), "0" (addr), "1" (cnt)); +} + +#define outw(port, data) \ + (/* CONSTCOND */ __use_immediate_port(port) ? __outwc(port, data) : \ + __outw(port, data)) + +static __inline void +__outwc(unsigned port, u_int16_t data) +{ + __asm __volatile("outw %0,%w1" : : "a" (data), "id" (port)); +} + +static __inline void +__outw(unsigned port, u_int16_t data) +{ + __asm __volatile("outw %0,%w1" : : "a" (data), "d" (port)); +} + +static __inline void +outsw(unsigned port, const void *addr, int cnt) +{ + void *dummy1; + int dummy2; + __asm __volatile("cld\n\trepne\n\toutsw" : + "=S" (dummy1), "=c" (dummy2) : + "d" (port), "0" (addr), "1" (cnt)); +} + +#define outl(port, data) \ + (/* CONSTCOND */ __use_immediate_port(port) ? __outlc(port, data) : \ + __outl(port, data)) + +static __inline void +__outlc(unsigned port, u_int32_t data) +{ + __asm __volatile("outl %0,%w1" : : "a" (data), "id" (port)); +} + +static __inline void +__outl(unsigned port, u_int32_t data) +{ + __asm __volatile("outl %0,%w1" : : "a" (data), "d" (port)); +} + +static __inline void +outsl(unsigned port, const void *addr, int cnt) +{ + void *dummy1; + int dummy2; + __asm __volatile("cld\n\trepne\n\toutsl" : + "=S" (dummy1), "=c" (dummy2) : + "d" (port), "0" (addr), "1" (cnt)); +} + +#endif + + +static struct pci_io_handle * +pci_device_netbsd_open_legacy_io(struct pci_io_handle *ret, + struct pci_device *dev, pciaddr_t base, pciaddr_t size) +{ +#if defined(__i386__) + struct i386_iopl_args ia; + + ia.iopl = 1; + if (sysarch(I386_IOPL, &ia)) + return NULL; + + ret->base = base; + ret->size = size; + return ret; +#elif defined(__amd64__) + struct x86_64_iopl_args ia; + + ia.iopl = 1; + if (sysarch(X86_64_IOPL, &ia)) + return NULL; + + ret->base = base; + ret->size = size; + return ret; +#elif defined(PCI_MAGIC_IO_RANGE) + ret->memory = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, + aperturefd, PCI_MAGIC_IO_RANGE + base); + if (ret->memory == MAP_FAILED) + return NULL; + + ret->base = base; + ret->size = size; + return ret; +#else + return NULL; +#endif +} + +static uint32_t +pci_device_netbsd_read32(struct pci_io_handle *handle, uint32_t reg) +{ +#if defined(__i386__) || defined(__amd64__) + return inl(handle->base + reg); +#else + return *(uint32_t *)((uintptr_t)handle->memory + reg); +#endif +} + +static uint16_t +pci_device_netbsd_read16(struct pci_io_handle *handle, uint32_t reg) +{ +#if defined(__i386__) || defined(__amd64__) + return inw(handle->base + reg); +#else + return *(uint16_t *)((uintptr_t)handle->memory + reg); +#endif +} + +static uint8_t +pci_device_netbsd_read8(struct pci_io_handle *handle, uint32_t reg) +{ +#if defined(__i386__) || defined(__amd64__) + return inb(handle->base + reg); +#else + return *(uint8_t *)((uintptr_t)handle->memory + reg); +#endif +} + +static void +pci_device_netbsd_write32(struct pci_io_handle *handle, uint32_t reg, + uint32_t data) +{ +#if defined(__i386__) || defined(__amd64__) + outl(handle->base + reg, data); +#else + *(uint16_t *)((uintptr_t)handle->memory + reg) = data; +#endif +} + +static void +pci_device_netbsd_write16(struct pci_io_handle *handle, uint32_t reg, + uint16_t data) +{ +#if defined(__i386__) || defined(__amd64__) + outw(handle->base + reg, data); +#else + *(uint8_t *)((uintptr_t)handle->memory + reg) = data; +#endif +} + +static void +pci_device_netbsd_write8(struct pci_io_handle *handle, uint32_t reg, + uint8_t data) +{ +#if defined(__i386__) || defined(__amd64__) + outb(handle->base + reg, data); +#else + *(uint32_t *)((uintptr_t)handle->memory + reg) = data; +#endif +} + +static int +pci_device_netbsd_map_legacy(struct pci_device *dev, pciaddr_t base, + pciaddr_t size, unsigned map_flags, void **addr) +{ + struct pci_device_mapping map; + int err; + + map.base = base; + map.size = size; + map.flags = map_flags; + map.memory = NULL; + err = pci_device_netbsd_map_range(dev, &map); + *addr = map.memory; + + return err; +} + +static int +pci_device_netbsd_unmap_legacy(struct pci_device *dev, void *addr, + pciaddr_t size) +{ + struct pci_device_mapping map; + + map.memory = addr; + map.size = size; + map.flags = 0; + return pci_device_netbsd_unmap_range(dev, &map); +} + static const struct pci_system_methods netbsd_pci_methods = { - pci_system_netbsd_destroy, - NULL, - NULL, - pci_device_netbsd_probe, - pci_device_netbsd_map_range, - pci_device_netbsd_unmap_range, - pci_device_netbsd_read, - pci_device_netbsd_write, - pci_fill_capabilities_generic + .destroy = pci_system_netbsd_destroy, + .destroy_device = NULL, + .read_rom = pci_device_netbsd_read_rom, + .probe = pci_device_netbsd_probe, + .map_range = pci_device_netbsd_map_range, + .unmap_range = pci_device_netbsd_unmap_range, + .read = pci_device_netbsd_read, + .write = pci_device_netbsd_write, + .fill_capabilities = pci_fill_capabilities_generic, +#if defined(WSDISPLAYIO_GET_BUSID) + .boot_vga = pci_device_netbsd_boot_vga, +#else + .boot_vga = NULL, +#endif + .open_legacy_io = pci_device_netbsd_open_legacy_io, + .read32 = pci_device_netbsd_read32, + .read16 = pci_device_netbsd_read16, + .read8 = pci_device_netbsd_read8, + .write32 = pci_device_netbsd_write32, + .write16 = pci_device_netbsd_write16, + .write8 = pci_device_netbsd_write8, + .map_legacy = pci_device_netbsd_map_legacy, + .unmap_legacy = pci_device_netbsd_unmap_legacy, }; int pci_system_netbsd_create(void) { struct pci_device_private *device; - int bus, dev, func, ndevs, nfuncs; + int bus, dev, func, ndevs, nfuncs, domain, pcifd; uint32_t reg; - - pcifd = open("/dev/pci0", O_RDWR | O_CLOEXEC); - if (pcifd == -1) - return ENXIO; + char netbsd_devname[32]; + struct pciio_businfo businfo; pci_sys = calloc(1, sizeof(struct pci_system)); - if (pci_sys == NULL) { - close(pcifd); - return ENOMEM; - } pci_sys->methods = &netbsd_pci_methods; ndevs = 0; - for (bus = 0; bus < 256; bus++) { - for (dev = 0; dev < 32; dev++) { - nfuncs = pci_nfuncs(bus, dev); + nbuses = 0; + snprintf(netbsd_devname, 32, "/dev/pci%d", nbuses); + pcifd = open(netbsd_devname, O_RDWR); + while (pcifd > 0) { + ioctl(pcifd, PCI_IOC_BUSINFO, &businfo); + buses[nbuses].fd = pcifd; + buses[nbuses].num = bus = businfo.busno; + buses[nbuses].maxdevs = businfo.maxdevs; + domain = nbuses; + nbuses++; + for (dev = 0; dev < businfo.maxdevs; dev++) { + nfuncs = pci_nfuncs(domain, bus, dev); for (func = 0; func < nfuncs; func++) { - if (pci_read(bus, dev, func, PCI_ID_REG, + if (pci_read(domain, bus, dev, func, PCI_ID_REG, ®) != 0) continue; if (PCI_VENDOR(reg) == PCI_VENDOR_INVALID || @@@@ -355,37 +910,43 @@@@ pci_system_netbsd_create(void) ndevs++; } } + snprintf(netbsd_devname, 32, "/dev/pci%d", nbuses); + pcifd = open(netbsd_devname, O_RDWR); } pci_sys->num_devices = ndevs; pci_sys->devices = calloc(ndevs, sizeof(struct pci_device_private)); if (pci_sys->devices == NULL) { + int i; + + for (i = 0; i < nbuses; i++) + close(buses[i].fd); free(pci_sys); - close(pcifd); return ENOMEM; } device = pci_sys->devices; - for (bus = 0; bus < 256; bus++) { - for (dev = 0; dev < 32; dev++) { - nfuncs = pci_nfuncs(bus, dev); + for (domain = 0; domain < nbuses; domain++) { + bus = buses[domain].num; + for (dev = 0; dev < buses[domain].maxdevs; dev++) { + nfuncs = pci_nfuncs(domain, bus, dev); for (func = 0; func < nfuncs; func++) { - if (pci_read(bus, dev, func, PCI_ID_REG, - ®) != 0) + if (pci_read(domain, bus, dev, func, + PCI_ID_REG, ®) != 0) continue; if (PCI_VENDOR(reg) == PCI_VENDOR_INVALID || PCI_VENDOR(reg) == 0) continue; - device->base.domain = 0; + device->base.domain = domain; device->base.bus = bus; device->base.dev = dev; device->base.func = func; device->base.vendor_id = PCI_VENDOR(reg); device->base.device_id = PCI_PRODUCT(reg); - if (pci_read(bus, dev, func, PCI_CLASS_REG, - ®) != 0) + if (pci_read(domain, bus, dev, func, + PCI_CLASS_REG, ®) != 0) continue; device->base.device_class = @@@@ -393,8 +954,8 @@@@ pci_system_netbsd_create(void) PCI_SUBCLASS(reg) << 8; device->base.revision = PCI_REVISION(reg); - if (pci_read(bus, dev, func, PCI_SUBSYS_ID_REG, - ®) != 0) + if (pci_read(domain, bus, dev, func, + PCI_SUBSYS_ID_REG, ®) != 0) continue; device->base.subvendor_id = PCI_VENDOR(reg); @ 1.15 log @fixes missing `,' for legacy NetBSD case. @ text @d1 1 a1 1 $NetBSD: patch-ac,v 1.14 2013/06/03 14:19:38 wiz Exp $ @ 1.14 log @Fixes from Chuck Silvers based on openbsd_pci.c. Bump PKGREVISION. @ text @d1 1 a1 1 $NetBSD: patch-ac,v 1.13 2012/10/12 00:37:05 taca Exp $ d933 1 a933 1 + .boot_vga = NULL @ 1.13 log @Fix build problem on NetBSD 4.0, simply revert the part of "#ifdef _X86_SYSARCH_L" from revision 1.8. @ text @d1 1 a1 1 $NetBSD: patch-ac,v 1.12 2012/07/15 08:12:42 wiz Exp $ d6 2 a7 2 --- src/netbsd_pci.c.orig 2012-04-09 17:02:57.000000000 +0000 +++ src/netbsd_pci.c d437 1 a437 1 @@@@ -286,66 +383,189 @@@@ pci_device_netbsd_probe(struct pci_devic d585 326 d935 9 d990 1 a990 1 @@@@ -355,37 +575,43 @@@@ pci_system_netbsd_create(void) d1043 1 a1043 1 @@@@ -393,8 +619,8 @@@@ pci_system_netbsd_create(void) @ 1.12 log @Try fixing build on NetBSD 5 (PR 46705). @ text @d1 1 a1 1 $NetBSD: patch-ac,v 1.11 2012/07/14 23:42:13 wiz Exp $ d16 1 a16 1 @@@@ -20,8 +21,13 @@@@ d25 1 d27 8 d39 1 a39 1 @@@@ -35,126 +41,152 @@@@ d255 1 a255 1 @@@@ -163,25 +195,23 @@@@ static int d290 1 a290 1 @@@@ -196,25 +226,23 @@@@ static int d323 1 a323 1 @@@@ -222,10 +250,53 @@@@ pci_device_netbsd_write(struct pci_devic d378 1 a378 1 @@@@ -233,17 +304,34 @@@@ pci_system_netbsd_destroy(void) d416 1 a416 1 @@@@ -254,16 +342,16 @@@@ pci_device_netbsd_probe(struct pci_devic d437 1 a437 1 @@@@ -286,66 +374,189 @@@@ pci_device_netbsd_probe(struct pci_devic d655 1 a655 1 @@@@ -355,37 +566,43 @@@@ pci_system_netbsd_create(void) d708 1 a708 1 @@@@ -393,8 +610,8 @@@@ pci_system_netbsd_create(void) @ 1.12.2.1 log @Pullup ticket #3945 - requested by taca sysutils/libpciaccess: build fix Revisions pulled up: - sysutils/libpciaccess/distinfo 1.16 - sysutils/libpciaccess/patches/patch-ac 1.13 --- Module Name: pkgsrc Committed By: taca Date: Fri Oct 12 00:37:05 UTC 2012 Modified Files: pkgsrc/sysutils/libpciaccess: distinfo pkgsrc/sysutils/libpciaccess/patches: patch-ac Log Message: Fix build problem on NetBSD 4.0, simply revert the part of "#ifdef _X86_SYSARCH_L" from revision 1.8. @ text @d1 1 a1 1 $NetBSD$ d16 1 a16 1 @@@@ -20,8 +21,22 @@@@ a24 1 +#ifdef _X86_SYSARCH_L a25 8 +#else +#ifdef __i386__ +#define netbsd_set_mtrr(mr, num) i386_set_mtrr((mr), (num)) +#endif +#ifdef __amd64__ +#define netbsd_set_mtrr(mr, num) x86_64_set_mtrr((mr), (num)) +#endif +#endif d30 1 a30 1 @@@@ -35,126 +50,152 @@@@ d246 1 a246 1 @@@@ -163,25 +204,23 @@@@ static int d281 1 a281 1 @@@@ -196,25 +235,23 @@@@ static int d314 1 a314 1 @@@@ -222,10 +259,53 @@@@ pci_device_netbsd_write(struct pci_devic d369 1 a369 1 @@@@ -233,17 +313,34 @@@@ pci_system_netbsd_destroy(void) d407 1 a407 1 @@@@ -254,16 +351,16 @@@@ pci_device_netbsd_probe(struct pci_devic d428 1 a428 1 @@@@ -286,66 +383,189 @@@@ pci_device_netbsd_probe(struct pci_devic d646 1 a646 1 @@@@ -355,37 +575,43 @@@@ pci_system_netbsd_create(void) d699 1 a699 1 @@@@ -393,8 +619,8 @@@@ pci_system_netbsd_create(void) @ 1.11 log @Update to 0.13.1. Update patch-ac (netbsd_pci.c) using current version of the file from xsrc. meta-pkgs/modular-xorg still builds. Changes: 0.12.0: pciaccess 0.12.0 release, contains a fix for a major MTRR issue from Thomas, along with a use after free, generic x86 backend, a few vgaarb fixes, and some packaging magic. Alan Coopersmith (3): Update Sun license notices to current X.Org standard form Delay allocation of agp_info so we don't leak it on prior errors Let libtool handle library flags for scanpci on Solaris Dave Airlie (2): pciaccess: fix use after free. libpciaccess 0.12.0 - bump version for release Gaetan Nadon (2): config: remove the pkgconfig pc.in file from EXTRA_DIST config: update AC_PREREQ statement to 2.60 Julien Cristau (1): COPYING: add Red Hat's copyright notice Samuel Thibault (1): libpciaccess x86 backend Thomas Hellstrom (1): Fix long standing MTRR bug. Tiago Vignatti (2): vgaarb: decode should send new information to the kernel vgaarb: read back vga count when setting new decoding 0.12.1: This bug fix release corrects a couple bugs in the device probing code, as well as providing various build configuration improvements. Alan Coopersmith (4): Sun's copyrights belong to Oracle now config: replace deprecated AM_CONFIG_HEADER with AC_CONFIG_HEADERS config: remove AC_PROG_CC as it overrides AC_PROG_C_C99 libpciaccess 0.12.1 Bryce Harrington (1): Fix detection of multi-function cards Gaetan Nadon (8): config: upgrade AC_DEFINE_DIR to AX_DEFINE_DIR config: provide a makefile for scanpci dev tool scanpci.c: remove offending whitespace as reported by git diff config: provide a makefile for scanpci man pages config: replace INCLUDES, which is deprecated, with AM_CPPFLAGS include: add a Makefile to install and distribute header file config: use LDADD to obtain appropriate dependencies config: replace deprecated AC_HELP_STRING with AS_HELP_STRING Jesse Barnes (1): Revert "Don't try to use bogus bridge data" 0.13.0: Adam Jackson (1): linux: Don't use /dev/port Alan Coopersmith (3): Solaris: reorder functions to remove need for lots of static prototypes Close pci.ids file when bailing out because realloc failed solx_devfs.c: fix gcc warnings about casting away const when reading data Daniel Drake (1): delete_io_handle: fix deletion of last handle Henry Zhao (1): Solaris: improve support for sparc platform Jeremy Huddleston (1): configure.ac: Bump to 0.13 Mark Kettenis (3): OpenBSD: Indicate that devices need access to legacy VGA resources. Add VGA Arbiter support for OpenBSD. OpenBSD: Implement map_legacy and legacy_io Mathias Krause (1): Use correct type for pci_id file accessor functions 0.13.1: Adam Jackson (2): Use O_CLOEXEC for internal file descriptors linux: Fix out[bwl] macros on non-I/O architectures Julien Cristau (1): Bump to 0.13.1 Matthieu Herrb (1): Fix pci_io_handle allocation routines. Thordur Bjornsson (1): Fix openbsd_pci.c:pci_device_vgaarb_set_target(); @ text @d1 1 a1 1 $NetBSD: patch-ac,v 1.10 2011/05/09 15:26:16 taca Exp $ d4 1 d314 1 a314 1 @@@@ -222,10 +250,51 @@@@ pci_device_netbsd_write(struct pci_devic d318 1 d355 1 d369 1 a369 1 @@@@ -233,17 +302,34 @@@@ pci_system_netbsd_destroy(void) d407 1 a407 1 @@@@ -254,16 +340,16 @@@@ pci_device_netbsd_probe(struct pci_devic d428 1 a428 1 @@@@ -286,66 +372,185 @@@@ pci_device_netbsd_probe(struct pci_devic d595 1 d597 3 d646 1 a646 1 @@@@ -355,37 +560,43 @@@@ pci_system_netbsd_create(void) d699 1 a699 1 @@@@ -393,8 +604,8 @@@@ pci_system_netbsd_create(void) @ 1.10 log @Revert previous commit; I didn't noticed revision 1.8 of patches/patch-ac. @ text @d1 1 a1 1 $NetBSD: patch-ac,v 1.8 2011/05/07 10:06:34 shattered Exp $ d3 3 a5 1 --- src/netbsd_pci.c.orig 2009-02-17 00:10:20.000000000 +0000 d15 1 a15 1 @@@@ -20,12 +21,26 @@@@ d24 1 a24 10 +#ifdef _X86_SYSARCH_L +#define netbsd_set_mtrr(mr, num) _X86_SYSARCH_L(set_mtrr)((mr), (num)) +#else +#ifdef __i386__ +#define netbsd_set_mtrr(mr, num) i386_set_mtrr((mr), (num)) +#endif +#ifdef __amd64__ +#define netbsd_set_mtrr(mr, num) x86_64_set_mtrr((mr), (num)) +#endif +#endif a26 1 +#include d29 1 a29 5 -#include #include #include @@@@ -35,126 +50,162 @@@@ d34 1 d150 1 a150 1 + int prot, fd, ret = 0; d152 1 a152 1 - if ((fd = open("/dev/mem", O_RDWR)) == -1) d158 3 d163 2 a164 13 + if (map->memory == MAP_FAILED) { + fd = open("/dev/mem", O_RDWR); + if (fd == -1) + return errno; + map->memory = mmap(NULL, map->size, prot, MAP_SHARED, fd, + (off_t)map->base); + if (map->memory == MAP_FAILED) { + ret = errno; + close(fd); + return ret; + } + close(fd); + } a165 4 - map->memory = mmap(NULL, map->size, prot, MAP_SHARED, - fd, map->base); - if (map->memory == MAP_FAILED) - return errno; d168 1 a168 1 d245 1 a245 1 @@@@ -163,25 +214,23 @@@@ static int d280 1 a280 1 @@@@ -196,25 +245,23 @@@@ static int d301 1 a301 1 - if (ioctl(pcifd, PCI_IOC_BDF_CFGWRITE, &io) == -1) d313 41 a353 1 @@@@ -225,7 +272,11 @@@@ pci_device_netbsd_write(struct pci_devic d366 1 a366 1 @@@@ -233,17 +284,34 @@@@ pci_system_netbsd_destroy(void) d404 1 a404 1 @@@@ -254,16 +322,16 @@@@ pci_device_netbsd_probe(struct pci_devic d425 1 a425 1 @@@@ -286,66 +354,188 @@@@ pci_device_netbsd_probe(struct pci_devic d493 1 a493 1 + int pci_rom, memfd; d539 2 a540 5 + fprintf(stderr, "Using rom_base = 0x%lx (pci_rom=%d)\n", (long)rom_base, + pci_rom); + memfd = open("/dev/mem", O_RDONLY); + if (memfd == -1) + return errno; d542 2 a543 1 + bios = mmap(NULL, rom_size, PROT_READ, MAP_SHARED, memfd, (off_t)rom_base); a545 1 + close(memfd); a551 1 + close(memfd); d591 2 a592 1 + .fill_capabilities = pci_fill_capabilities_generic d603 1 a603 1 - pcifd = open("/dev/pci0", O_RDWR); d639 1 a639 1 @@@@ -355,37 +545,43 @@@@ pci_system_netbsd_create(void) d692 1 a692 1 @@@@ -393,8 +589,8 @@@@ pci_system_netbsd_create(void) @ 1.9 log @Fix build problem on NetBSD 4_STABLE which dosen't have _X86_SYSARCH_L() cpp macro. @ text @d1 1 a1 1 $NetBSD: patch-ac,v 1.7 2011/02/10 16:20:45 pooka Exp $ d22 11 a33 11 +# ifdef _X86_SYSARCH_L +# define netbsd_set_mtrr(mr, num) _X86_SYSARCH_L(set_mtrr)(mr, num) +# else +# ifdef i386 +# define netbsd_set_mtrr(mr, num) i386_set_mtrr((mr), (num)) +# elif amd64 +# define netbsd_set_mtrr(mr, num) x86_64_set_mtrr((mr), (num)) +# endif +# endif +#endif + @ 1.8 log @PR/44785 -- fix build on NetBSD 4 @ text @d1 1 a1 1 $NetBSD$ d22 10 a31 5 +#ifdef _X86_SYSARCH_L +#define netbsd_set_mtrr(mr, num) _X86_SYSARCH_L(set_mtrr)((mr), (num)) +#else +#ifdef __i386__ +#define netbsd_set_mtrr(mr, num) i386_set_mtrr((mr), (num)) d33 1 a33 6 +#ifdef __amd64__ +#define netbsd_set_mtrr(mr, num) x86_64_set_mtrr((mr), (num)) +#endif +#endif +#endif @ 1.7 log @Make HAVE_MTRR actually work. This increases my X performance so much it's borderline not funny anymore. (tested on a similar patch to libpciaccess 0.10.8, since my X still refuses to start with libpciaccess 0.11) from jmcneill @ text @d1 1 a1 1 $NetBSD$ d3 2 a4 2 --- src/netbsd_pci.c.orig 2009-02-17 01:10:20.000000000 +0100 +++ src/netbsd_pci.c 2011-02-10 17:12:57.000000000 +0100 d13 1 a13 1 @@@@ -20,12 +21,17 @@@@ d22 10 a31 1 +#define netbsd_set_mtrr(mr, num) _X86_SYSARCH_L(set_mtrr)(mr, num) d41 1 a41 1 @@@@ -35,126 +41,162 @@@@ d268 1 a268 1 @@@@ -163,25 +205,23 @@@@ d303 1 a303 1 @@@@ -196,25 +236,23 @@@@ d336 1 a336 1 @@@@ -225,7 +263,11 @@@@ d349 1 a349 1 @@@@ -233,17 +275,34 @@@@ d387 1 a387 1 @@@@ -254,16 +313,16 @@@@ d408 1 a408 1 @@@@ -286,66 +345,188 @@@@ d625 1 a625 1 @@@@ -355,37 +536,43 @@@@ d678 1 a678 1 @@@@ -393,8 +580,8 @@@@ @ 1.6 log @Update to libpciaccess-0.11. Synced the netbsd support patch from xsrc HEAD, with a minor tweak: Now we first try to map memory in the newfangled /dev/pciN way. If that fails, then we fall back to /dev/mem. We need to do this to deal with netbsd-5 and earlier. Add NetBSD/sparc64 to the list of supported platforms. Upstream changes: 0.11.0: Add pci_device_get_parent_bridge() I/O port access routines Fix pci_device_open_io() to actually return something useful Fix I/O handle array allocator to work for devices past the first libpciaccess 0.11.0 .gitignore: use common defaults with custom section # 24239 Makefile.am: ChangeLog not required: EXTRA_DIST or *CLEANFILES #24432 Deploy the new XORG_DEFAULT_OPTIONS #24242 INSTALL, NEWS, README or AUTHORS files are missing/incorrect #24206 Makefile.am: add ChangeLog and INSTALL on MAINTAINERCLEANFILES 0.10.9: vgaarb: check pci_sys exists before initing vga arb shutup stupid gcc warning, strtok_r ignores the first parameter Free return value from scandir instead of leaking it. vgaarb: check for fd before close it vgaarb: fix newbie typo @ text @d1 1 a1 1 $NetBSD$ d3 2 a4 2 --- src/netbsd_pci.c.orig 2009-02-17 00:10:20.000000000 +0000 +++ src/netbsd_pci.c d13 1 a13 1 @@@@ -20,12 +21,15 @@@@ d17 2 d32 1 a32 1 @@@@ -35,126 +39,160 @@@@ d160 1 a160 5 - map->memory = mmap(NULL, map->size, prot, MAP_SHARED, - fd, map->base); - if (map->memory == MAP_FAILED) - return errno; d175 5 a179 1 + d190 1 a190 3 - if (map->flags & PCI_DEV_MAP_FLAG_CACHABLE) - mtrr.type = MTRR_TYPE_WB; + m.base = base; d192 1 a192 1 + m.len = size; d194 2 a195 1 + if (map->flags & PCI_DEV_MAP_FLAG_CACHEABLE) a207 2 - } - } d209 7 d218 1 a218 5 + if ((netbsd_set_mtrr(&m, &n)) == -1) + ret = errno; + } +#endif d251 1 a251 1 + m.len = size; d259 1 a259 1 @@@@ -163,25 +201,23 @@@@ static int d294 1 a294 1 @@@@ -196,25 +232,23 @@@@ static int d327 1 a327 1 @@@@ -225,7 +259,11 @@@@ pci_device_netbsd_write(struct pci_devic d340 1 a340 1 @@@@ -233,17 +271,34 @@@@ pci_system_netbsd_destroy(void) d378 1 a378 1 @@@@ -254,16 +309,16 @@@@ pci_device_netbsd_probe(struct pci_devic d399 1 a399 1 @@@@ -286,66 +341,188 @@@@ pci_device_netbsd_probe(struct pci_devic d616 1 a616 1 @@@@ -355,37 +532,43 @@@@ pci_system_netbsd_create(void) d669 1 a669 1 @@@@ -393,8 +576,8 @@@@ pci_system_netbsd_create(void) @ 1.5 log @Add a minimal implementation of the read_rom method for NetBSD, just good enough to get newer xorg servers running. (I need to double-check the PCI spec, but it is well possible that we can't do much better anyway: ISTR the PCI spec allows devices to share decoding ressources between ROM and runtime logics, which means there is no safe way to read the original ROM at runtime. Correct me if I'm wrong.) @ text @d3 1 a3 1 --- src/netbsd_pci.c.orig 2008-12-20 04:21:22.000000000 +0100 d5 9 a13 1 @@@@ -20,12 +20,15 @@@@ d30 1 a30 1 @@@@ -35,6 +38,8 @@@@ d39 35 a73 1 @@@@ -43,20 +48,12 @@@@ static int pcifd; d75 2 a76 1 pci_read(int bus, int dev, int func, uint32_t reg, uint32_t *val) d80 2 a81 1 - d87 2 a88 1 + uint32_t rval; d93 2 a94 1 + if (pcibus_conf_read(pcifd, bus, dev, func, reg, &rval) == -1) d102 1 a102 1 @@@@ -64,16 +61,7 @@@@ pci_read(int bus, int dev, int func, uin d104 2 a105 1 pci_write(int bus, int dev, int func, uint32_t reg, uint32_t val) d108 1 a108 1 - d115 3 a117 1 - d119 18 a136 1 + return pcibus_conf_write(pcifd, bus, dev, func, reg, val); d139 1 a140 1 @@@@ -91,70 +79,68 @@@@ static int d158 2 a159 2 - map->memory = mmap(NULL, map->size, prot, MAP_SHARED, d161 17 a177 7 + fd = open("/dev/mem", O_RDWR); + if (fd == -1) + return errno; + map->memory = mmap(NULL, map->size, prot, MAP_SHARED, fd, map->base); if (map->memory == MAP_FAILED) return errno; d180 1 a180 1 + d208 1 d210 2 a211 1 + d214 1 a214 1 } a216 2 close(fd); d257 1 a257 1 @@@@ -163,25 +149,22 @@@@ static int d270 2 a271 1 int toread = MIN(size, 4 - (offset & 0x3)); d274 1 a274 1 + reg = (offset & ~0x3); d277 3 a279 2 + if ((pcibus_conf_read(pcifd, dev->bus, dev->dev, dev->func, + reg, &rval)) == -1) d292 1 a292 1 @@@@ -196,21 +179,18 @@@@ static int d310 1 a310 1 + reg = offset; d314 3 a316 2 + if ((pcibus_conf_write(pcifd, dev->bus, dev->dev, dev->func, + reg, val)) == -1) d320 128 a447 1 @@@@ -222,6 +202,26 @@@@ pci_device_netbsd_write(struct pci_devic d451 6 d458 1 a458 1 +pci_device_netbsd_read_rom(struct pci_device *device, void *buf) d460 10 a469 1 + int fd, res, err; d471 36 a506 2 + fd = open("/dev/mem", O_RDONLY, 0); + if (fd < 0) d508 20 d529 14 a542 6 + lseek(fd, 0xc0000, SEEK_SET); + res = read(fd, buf, 64*1024); + if (res < 0) { + err = errno; + close(fd); + return err; d544 3 a546 2 + close(fd); + return 0; a548 4 static void pci_system_netbsd_destroy(void) { @@@@ -312,7 +312,7 @@@@ pci_device_netbsd_probe(struct pci_devic d550 2 a551 2 pci_system_netbsd_destroy, NULL, d553 125 a677 4 + pci_device_netbsd_read_rom, pci_device_netbsd_probe, pci_device_netbsd_map_range, pci_device_netbsd_unmap_range, @ 1.4 log @Update to 0.10.6. Fix build on DragonFly. Changes since 0.10.5: Alan Coopersmith (12): Fill in byte swapping routines for big-endian Solaris machines Don't open/gzopen pci.ids if we're not going to read it Add AC_SYS_LARGEFILE to configure.ac Solaris: Use bus-range properties to limit busses scanned on each node Add README with pointers to mailing list, bugzilla & git repos Fix const mismatch compiler warnings in Solaris backend Sun bug 6811468: pci_device_solx_devfs_probe accesses freed memory Move included m4 to a subdir so we can more easily update from upstream Fix $CWARNFLAGS addition Fix unused variable warnings in Solaris code Resync COPYING file with code copyright notices Version bump: 0.10.6 Darren Smith (1): Be more paranoid about reading bridge info (#20786) Mark Kettenis (1): Make libpciaccess on OpenBSD domain-aware. Matthieu Herrb (3): Fix a logic error in pci_device_openbsd_write(). Sync with OpenBSD code. Fix a logic error in pci_device_netbsd_write() Owain Ainsworth (1): openbsd_pci.c: use the correct size when mapping the legacy vga rom. Paulo Cesar Pereira de Andrade (1): Janitor: Correct make distcheck and compiler warnings. Robert Noland (1): FreeBSD: Incorporate several fixes that have accumulated. edward shu (1): Sun bug 6785726: libpciaccess needs to use the correct BAR index on solaris Changes since 0.10.4: Julien Cristau (2): Make --without-zlib work Bump to 0.10.5 Robert Noland (1): Fix FreeBSD systems which support pci domains. @ text @d1 1 a1 1 $NetBSD: patch-ac,v 1.3 2008/10/30 21:06:32 bjs Exp $ d3 2 a4 2 --- src/netbsd_pci.c.orig 2008-12-20 05:21:22 +0200 +++ src/netbsd_pci.c 2009-05-18 08:38:14 +0300 d37 1 a37 2 + uint32_t rval; d43 1 a43 2 + if (pcibus_conf_read(pcifd, bus, dev, func, reg, &rval) == -1) + return (-1); d48 3 a50 1 - d241 36 @ 1.3 log @Add support for compressed pci.ids file via zlib. @ text @d1 1 a1 1 $NetBSD: patch-ac,v 1.2 2008/10/30 21:00:37 bjs Exp $ d3 2 a4 2 --- src/netbsd_pci.c.orig 2008-10-15 18:35:53.000000000 -0400 +++ src/netbsd_pci.c d221 1 a221 1 if ((offset % 4) == 0 || (size % 4) == 0) d237 1 a237 1 + reg, val)) == -1) @ 1.2 log @Remove superfluous hunk of patch-ac. @ text @d1 1 a1 1 $NetBSD: patch-ac,v 1.1.1.1 2008/10/30 20:58:11 bjs Exp $ d5 1 a5 1 @@@@ -20,12 +19,15 @@@@ d22 1 a22 1 @@@@ -35,6 +37,8 @@@@ d31 1 a31 1 @@@@ -43,20 +47,12 @@@@ static int pcifd; d56 1 a56 1 @@@@ -64,16 +60,7 @@@@ pci_read(int bus, int dev, int func, uin d74 1 a74 1 @@@@ -91,70 +78,68 @@@@ static int d181 1 a181 1 @@@@ -163,25 +148,22 @@@@ static int d214 1 a214 1 @@@@ -196,21 +178,18 @@@@ static int @ 1.1 log @Initial revision @ text @d1 1 a1 1 $NetBSD$ a4 7 @@@@ -1,5 +1,4 @@@@ -/* - * Copyright (c) 2008 Juan Romero Pardines +/* Copyright (c) 2008 Blair Sadewitz * Copyright (c) 2008 Mark Kettenis * * Permission to use, copy, modify, and distribute this software for any @ 1.1.1.1 log @Import libpciaccess-0.10.4 (X.org PCI wrapper library) + patches. Tested on NetBSD-current (i386 and amd64); support for other architectures is in the works. Currently this should work with: ONLY_FOR_PLATFORM= FreeBSD-*-i386 NetBSD-*-i386 OpenBSD-*-i386 ONLY_FOR_PLATFORM+= FreeBSD-*-x86_64 NetBSD-*-x86_64 OpenBSD-*-x86_64 ONLY_FOR_PLATFORM+= DragonFly-i386-* DragonFly-x86_64-* ONLY_FOR_PLATFORM+= Linux-*-* SunOS-*-* @ text @@