[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

libpciaccess: Changes to 'upstream-unstable'



 README.cygwin           |   25 ++++++
 configure.ac            |   13 ++-
 include/pciaccess.h     |    2 
 src/Makefile.am         |    5 +
 src/common_init.c       |    2 
 src/common_interface.c  |    2 
 src/freebsd_pci.c       |    2 
 src/linux_sysfs.c       |   62 ++++++++++++----
 src/netbsd_pci.c        |   26 +++++++
 src/openbsd_pci.c       |   34 +++++++--
 src/pciaccess_private.h |    1 
 src/solx_devfs.c        |    4 +
 src/x86_pci.c           |  176 +++++++++++++++++++++++++++++++++++++++++++++++-
 13 files changed, 321 insertions(+), 33 deletions(-)

New commits:
commit f99c2e4199ce37f6f94428df504427f67c3ec543
Author: Alan Coopersmith <alan.coopersmith@oracle.com>
Date:   Tue Feb 3 15:59:10 2015 -0800

    libpciaccess 0.13.3
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>

diff --git a/configure.ac b/configure.ac
index e3f7d8b..f11204f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,7 +23,7 @@
 
 # Initialize Autoconf
 AC_PREREQ([2.60])
-AC_INIT([libpciaccess],[0.13.2],
+AC_INIT([libpciaccess],[0.13.3],
         [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg&component=libpciaccess],[libpciaccess])
 AC_CONFIG_SRCDIR([Makefile.am])
 AC_CONFIG_HEADERS([config.h])

commit 9b1bf11c81881c9cc6e6145011cf229978f109f4
Author: Mark Kettenis <kettenis@openbsd.org>
Date:   Mon Sep 29 22:34:25 2014 +0200

    Use PCIOCREADMASK on OpenBSD.
    
    If the machdep.allowaperture sysctl(8) variable is set to 0, writing to PCI
    config space is not allowed.  So instead of writing 0xffffffff to the BARs
    in order to determine their size, use the PCIOCREADMASK ioctl(2) which
    returns the mask of changeable bits that was saved by the kernel when the
    devices was initially probed.
    
    Reviewed-by: Matthieu Herrb <matthieu@herbb.eu>
    Signed-off-by: Mark Kettenis <kettenis@openbsd.org>

diff --git a/src/openbsd_pci.c b/src/openbsd_pci.c
index fe034f3..4d1b5cd 100644
--- a/src/openbsd_pci.c
+++ b/src/openbsd_pci.c
@@ -81,6 +81,29 @@ pci_write(int domain, int bus, int dev, int func, uint32_t reg, uint32_t val)
 	return ioctl(pcifd[domain], PCIOCWRITE, &io);
 }
 
+static int
+pci_readmask(int domain, int bus, int dev, int func, uint32_t reg,
+    uint32_t *val)
+{
+	struct pci_io io;
+	int err;
+
+	bzero(&io, sizeof(io));
+	io.pi_sel.pc_bus = bus;
+	io.pi_sel.pc_dev = dev;
+	io.pi_sel.pc_func = func;
+	io.pi_reg = reg;
+	io.pi_width = 4;
+
+	err = ioctl(pcifd[domain], PCIOCREADMASK, &io);
+	if (err)
+		return (err);
+
+	*val = io.pi_data;
+
+	return 0;
+}
+
 /**
  * Read a VGA ROM
  *
@@ -328,11 +351,9 @@ pci_device_openbsd_probe(struct pci_device *device)
 			return err;
 
 		/* Probe the size of the region. */
-		err = pci_write(domain, bus, dev, func, bar, ~0);
+		err = pci_readmask(domain, bus, dev, func, bar, &size);
 		if (err)
 			return err;
-		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;
@@ -360,11 +381,9 @@ pci_device_openbsd_probe(struct pci_device *device)
 					return err;
 				reg64 |= (uint64_t)reg << 32;
 
-				err = pci_write(domain, bus, dev, func, bar, ~0);
+				err = pci_readmask(domain, bus, dev, func, bar, &size);
 				if (err)
 					return err;
-				pci_read(domain, bus, dev, func, bar, &size);
-				pci_write(domain, bus, dev, func, bar, reg64 >> 32);
 				size64 |= (uint64_t)size << 32;
 
 				region->base_addr = PCI_MAPREG_MEM64_ADDR(reg64);

commit b7e42643d2ee6521cf23e6dfe49a8369ba4bf9bb
Author: Matthew Green <mrg@NetBSD.org>
Date:   Sat Jul 26 22:09:30 2014 +0200

    Implement the kernel_has_driver() method for NetBSD.
    
    This has the benefit of stopping the "vesa" driver from loading on
    hardware that has been claimed by a kernel driver and thus shouldn't
    be using "vesa".
    
    Reviewed-by: Matthieu Herrb <matthieu@herrb.eu>
    Signed-off-by: Thomas Klausner <wiz@NetBSD.org>

diff --git a/src/netbsd_pci.c b/src/netbsd_pci.c
index e6dae4c..52591b0 100644
--- a/src/netbsd_pci.c
+++ b/src/netbsd_pci.c
@@ -843,6 +843,29 @@ pci_device_netbsd_unmap_legacy(struct pci_device *dev, void *addr,
 	return pci_device_netbsd_unmap_range(dev, &map);
 }
 
+static int
+pci_device_netbsd_has_kernel_driver(struct pci_device *dev)
+{
+#ifdef PCI_IOC_DRVNAME
+	/*
+	 * NetBSD PCI_IOC_DRVNAME appears at the same time as pci_drvname(3)
+	 */
+	char drvname[16];
+
+	if (dev->bus >= nbuses)
+		return 0;
+
+	/*
+	 * vga(4) should be considered "not bound".
+	 */
+	if (pci_drvname(buses[dev->bus].fd, dev->dev, dev->func,
+			drvname, sizeof drvname) == 0 &&
+	    strncmp(drvname, "vga", 3) != 0)
+		return 1;
+#endif
+	return 0;
+}
+
 static const struct pci_system_methods netbsd_pci_methods = {
 	.destroy = pci_system_netbsd_destroy,
 	.destroy_device = NULL,
@@ -867,6 +890,7 @@ static const struct pci_system_methods netbsd_pci_methods = {
 	.write8 = pci_device_netbsd_write8,
 	.map_legacy = pci_device_netbsd_map_legacy,
 	.unmap_legacy = pci_device_netbsd_unmap_legacy,
+	.has_kernel_driver = pci_device_netbsd_has_kernel_driver,
 };
 
 int

commit 1654a0462723b3b75d7a4a20bedfc653cc3e1f1a
Author: Alan Coopersmith <alan.coopersmith@oracle.com>
Date:   Wed Jul 2 16:41:10 2014 -0700

    Solaris: Fix fd leak in pci_device_solx_devfs_map_range()
    
    Caching fd's for reuse is most effective when you actually stick the
    newly opened fd in the cache, instead of letting it leak at the end
    of the function.
    
    Regression introduced by yours truly in commit 9f2d95e61896f41adb.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
    Reviewed-by: Randy Fishel <randy.fishel@oracle.com>

diff --git a/src/solx_devfs.c b/src/solx_devfs.c
index 8e7ea9b..f572393 100644
--- a/src/solx_devfs.c
+++ b/src/solx_devfs.c
@@ -724,6 +724,9 @@ pci_device_solx_devfs_map_range(struct pci_device *dev,
 			   strerror(errno));
 	    return err;
 	}
+#ifndef __sparc
+        xsvc_fd = map_fd;
+#endif
     }
 
     map->memory = mmap(NULL, map->size, prot, MAP_SHARED, map_fd, map->base);

commit ee4e253a3f1a62e2f3f89f5339590fd4e6cde7c4
Author: Alan Coopersmith <alan.coopersmith@oracle.com>
Date:   Fri May 9 19:25:10 2014 -0700

    Enable use of __attribute__((deprecated)) with Solaris Studio 12.4 compiler
    
    Support for this attribute is added in the 12.4 beta release.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>

diff --git a/include/pciaccess.h b/include/pciaccess.h
index 22faf89..1d7aa4b 100644
--- a/include/pciaccess.h
+++ b/include/pciaccess.h
@@ -59,7 +59,7 @@
 
 #include <inttypes.h>
 
-#if __GNUC__ >= 3
+#if (__GNUC__ >= 3) || (__SUNPRO_C >= 0x5130)
 #define __deprecated __attribute__((deprecated))
 #else
 #define __deprecated

commit b9c068896914b4132a24839c9ef7f9fcd6282d88
Author: Marcin Ko?cielnicki <koriakin@0x04.net>
Date:   Wed Feb 5 09:01:25 2014 +0100

    Fix IO access functions on linux+sysfs.
    
    The offsets on the resourceX files are relative to BAR base - don't add
    the base address ourselves.
    
    Reviewed-by: Adam Jackson <ajax@redhat.com>

diff --git a/src/freebsd_pci.c b/src/freebsd_pci.c
index 14ec3bc..7f5f56b 100644
--- a/src/freebsd_pci.c
+++ b/src/freebsd_pci.c
@@ -579,6 +579,7 @@ pci_device_freebsd_open_legacy_io(struct pci_io_handle *ret,
 
 	ret->base = base;
 	ret->size = size;
+	ret->is_legacy = 1;
 	return ret;
 #elif defined(PCI_MAGIC_IO_RANGE)
 	ret->memory = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED,
@@ -588,6 +589,7 @@ pci_device_freebsd_open_legacy_io(struct pci_io_handle *ret,
 
 	ret->base = base;
 	ret->size = size;
+	ret->is_legacy = 1;
 	return ret;
 #else
 	return NULL;
diff --git a/src/linux_sysfs.c b/src/linux_sysfs.c
index 97fcf36..8fca65e 100644
--- a/src/linux_sysfs.c
+++ b/src/linux_sysfs.c
@@ -759,6 +759,7 @@ pci_device_linux_sysfs_open_device_io(struct pci_io_handle *ret,
 
     ret->base = base;
     ret->size = size;
+    ret->is_legacy = 0;
 
     return ret;
 }
@@ -796,6 +797,7 @@ pci_device_linux_sysfs_open_legacy_io(struct pci_io_handle *ret,
 
     ret->base = base;
     ret->size = size;
+    ret->is_legacy = 1;
 
     return ret;
 }
@@ -813,10 +815,14 @@ pci_device_linux_sysfs_read32(struct pci_io_handle *handle, uint32_t port)
 {
     uint32_t ret;
 
-    if (handle->fd > -1)
-	pread(handle->fd, &ret, 4, port + handle->base);
-    else
+    if (handle->fd > -1) {
+	if (handle->is_legacy)
+	    pread(handle->fd, &ret, 4, port + handle->base);
+	else
+	    pread(handle->fd, &ret, 4, port);
+    } else {
 	ret = inl(port + handle->base);
+    }
 	
     return ret;
 }
@@ -826,10 +832,14 @@ pci_device_linux_sysfs_read16(struct pci_io_handle *handle, uint32_t port)
 {
     uint16_t ret;
 
-    if (handle->fd > -1)
-	pread(handle->fd, &ret, 2, port + handle->base);
-    else
+    if (handle->fd > -1) {
+	if (handle->is_legacy)
+	    pread(handle->fd, &ret, 2, port + handle->base);
+	else
+	    pread(handle->fd, &ret, 2, port);
+    } else {
 	ret = inw(port + handle->base);
+    }
 
     return ret;
 }
@@ -839,10 +849,14 @@ pci_device_linux_sysfs_read8(struct pci_io_handle *handle, uint32_t port)
 {
     uint8_t ret;
 
-    if (handle->fd > -1)
-	pread(handle->fd, &ret, 1, port + handle->base);
-    else
+    if (handle->fd > -1) {
+	if (handle->is_legacy)
+	    pread(handle->fd, &ret, 1, port + handle->base);
+	else
+	    pread(handle->fd, &ret, 1, port);
+    } else {
 	ret = inb(port + handle->base);
+    }
 
     return ret;
 }
@@ -851,30 +865,42 @@ static void
 pci_device_linux_sysfs_write32(struct pci_io_handle *handle, uint32_t port,
 			       uint32_t data)
 {
-    if (handle->fd > -1)
-	pwrite(handle->fd, &data, 4, port + handle->base);
-    else
+    if (handle->fd > -1) {
+	if (handle->is_legacy)
+	    pwrite(handle->fd, &data, 4, port + handle->base);
+	else
+	    pwrite(handle->fd, &data, 4, port);
+    } else {
 	outl(data, port + handle->base);
+    }
 }
 
 static void
 pci_device_linux_sysfs_write16(struct pci_io_handle *handle, uint32_t port,
 			       uint16_t data)
 {
-    if (handle->fd > -1)
-	pwrite(handle->fd, &data, 2, port + handle->base);
-    else
+    if (handle->fd > -1) {
+	if (handle->is_legacy)
+	    pwrite(handle->fd, &data, 2, port + handle->base);
+	else
+	    pwrite(handle->fd, &data, 2, port);
+    } else {
 	outw(data, port + handle->base);
+    }
 }
 
 static void
 pci_device_linux_sysfs_write8(struct pci_io_handle *handle, uint32_t port,
 			      uint8_t data)
 {
-    if (handle->fd > -1)
-	pwrite(handle->fd, &data, 1, port + handle->base);
-    else
+    if (handle->fd > -1) {
+	if (handle->is_legacy)
+	    pwrite(handle->fd, &data, 1, port + handle->base);
+	else
+	    pwrite(handle->fd, &data, 1, port);
+    } else {
 	outb(data, port + handle->base);
+    }
 }
 
 static int
diff --git a/src/netbsd_pci.c b/src/netbsd_pci.c
index b3f7f2d..e6dae4c 100644
--- a/src/netbsd_pci.c
+++ b/src/netbsd_pci.c
@@ -733,6 +733,7 @@ pci_device_netbsd_open_legacy_io(struct pci_io_handle *ret,
 
 	ret->base = base;
 	ret->size = size;
+	ret->is_legacy = 1;
 	return ret;
 #elif defined(__amd64__)
 	struct x86_64_iopl_args ia;
@@ -743,6 +744,7 @@ pci_device_netbsd_open_legacy_io(struct pci_io_handle *ret,
 
 	ret->base = base;
 	ret->size = size;
+	ret->is_legacy = 1;
 	return ret;
 #else
 	return NULL;
diff --git a/src/openbsd_pci.c b/src/openbsd_pci.c
index 73c68f4..fe034f3 100644
--- a/src/openbsd_pci.c
+++ b/src/openbsd_pci.c
@@ -412,6 +412,7 @@ pci_device_openbsd_open_legacy_io(struct pci_io_handle *ret,
 
 	ret->base = base;
 	ret->size = size;
+	ret->is_legacy = 1;
 	return ret;
 #elif defined(__amd64__)
 	struct amd64_iopl_args ia;
@@ -422,6 +423,7 @@ pci_device_openbsd_open_legacy_io(struct pci_io_handle *ret,
 
 	ret->base = base;
 	ret->size = size;
+	ret->is_legacy = 1;
 	return ret;
 #elif defined(PCI_MAGIC_IO_RANGE)
 	ret->memory = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED,
@@ -431,6 +433,7 @@ pci_device_openbsd_open_legacy_io(struct pci_io_handle *ret,
 
 	ret->base = base;
 	ret->size = size;
+	ret->is_legacy = 1;
 	return ret;
 #else
 	return NULL;
diff --git a/src/pciaccess_private.h b/src/pciaccess_private.h
index 339ec0f..9f4e8f9 100644
--- a/src/pciaccess_private.h
+++ b/src/pciaccess_private.h
@@ -109,6 +109,7 @@ struct pci_io_handle {
     pciaddr_t size;
     void *memory;
     int fd;
+    int is_legacy;
 };
 
 struct pci_device_private {
diff --git a/src/solx_devfs.c b/src/solx_devfs.c
index 41f5c19..8e7ea9b 100644
--- a/src/solx_devfs.c
+++ b/src/solx_devfs.c
@@ -911,6 +911,7 @@ pci_device_solx_devfs_open_legacy_io(struct pci_io_handle *ret,
     if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) == 0) {
 	ret->base = base;
 	ret->size = size;
+	ret->is_legacy = 1;
 	return ret;
     }
 #endif
diff --git a/src/x86_pci.c b/src/x86_pci.c
index 1075367..49c1cab 100644
--- a/src/x86_pci.c
+++ b/src/x86_pci.c
@@ -729,6 +729,7 @@ pci_device_x86_open_legacy_io(struct pci_io_handle *ret,
 
     ret->base = base;
     ret->size = size;
+    ret->is_legacy = 1;
 
     return ret;
 }

commit b29e9be9aff5c5a9ec5e2bcfc48044081b82742b
Author: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Date:   Wed Jan 29 18:44:40 2014 +0100

    Fix a compilation error on GNU Hurd platforms.
    
    This fixes a typo (unAMp instead of unMAp) introduced in the Windows/Cygwin
    support patch.
    
    Reviewed-by: Jon TURNEY <jon.turney@dronecode.org.uk>

diff --git a/src/x86_pci.c b/src/x86_pci.c
index b938068..1075367 100644
--- a/src/x86_pci.c
+++ b/src/x86_pci.c
@@ -658,7 +658,7 @@ static int
 pci_device_x86_unmap_range(struct pci_device *dev,
     struct pci_device_mapping *map)
 {
-    return pci_device_generic_unamp_range(dev, map);
+    return pci_device_generic_unmap_range(dev, map);
 }
 
 #endif

commit 6bfccc7ec4f0705595385f6684b6849663f781b4
Author: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Date:   Sat Jan 18 17:19:14 2014 +0100

    Windows/Cygwin: Add support through the WinIo library
    
    V2:
    - Add support for unmapping
    - Add a README.cygwin
    
    Reviewed-by: Martin Peres <martin.peres@free.fr>
    Reviewed-by: Jon TURNEY <jon.turney@dronecode.org.uk>

diff --git a/README.cygwin b/README.cygwin
new file mode 100755
index 0000000..8801329
--- /dev/null
+++ b/README.cygwin
@@ -0,0 +1,25 @@
+= libpciaccess support under Windows through WinIo and Cygwin =
+
+== Platforms supported ==
+
+The support should work on Windows NT/2000/XP/2003/Vista/7 and 2008 but has
+only been tested on Windows 7, 32 bits
+
+== Dependencies ==
+
+This support depends of WinIo which allows direct I/O port and physical
+memory access under Windows NT/2000/XP/2003/Vista/7 and 2008.
+
+== How to install WinIo ? ==
+
+First, you need to download WinIo from http://www.internals.com/. Then, you
+have to copy WinIo32.dll and WinIo32.sys to the same directory as the
+executables.
+
+== TODO ==
+
+Check and fix 64 bits support.
+
+== Contact ==
+
+If you have any problems, please send an email to samuel.pitoiset at gmail.com
diff --git a/configure.ac b/configure.ac
index fe3b78e..e3f7d8b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -95,6 +95,10 @@ case $host_os in
 	gnu*)
 		gnu=yes
 		;;
+	*cygwin*)
+		cygwin=yes
+		PCIACCESS_LIBS="$PCIACCESS_LIBS"
+		;;
 esac
 
 AM_CONDITIONAL(LINUX, [test "x$linux" = xyes])
@@ -103,6 +107,7 @@ AM_CONDITIONAL(NETBSD, [test "x$netbsd" = xyes])
 AM_CONDITIONAL(OPENBSD, [test "x$openbsd" = xyes])
 AM_CONDITIONAL(SOLARIS, [test "x$solaris" = xyes])
 AM_CONDITIONAL(GNU, [test "x$gnu" = xyes])
+AM_CONDITIONAL(CYGWIN, [test "x$cygwin" = xyes])
 
 AC_SYS_LARGEFILE
 
diff --git a/src/Makefile.am b/src/Makefile.am
index 0d71a80..3a46a85 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -56,6 +56,11 @@ OS_SUPPORT = x86_pci.c
 VGA_ARBITER = common_vgaarb_stub.c
 endif
 
+if CYGWIN
+OS_SUPPORT = x86_pci.c
+VGA_ARBITER = common_vgaarb_stub.c
+endif
+
 libpciaccess_la_SOURCES = common_bridge.c \
 	common_iterator.c \
 	common_init.c \
diff --git a/src/common_init.c b/src/common_init.c
index 7c9db9c..a127a8b 100644
--- a/src/common_init.c
+++ b/src/common_init.c
@@ -62,7 +62,7 @@ pci_system_init( void )
     err = pci_system_openbsd_create();
 #elif defined(__sun)
     err = pci_system_solx_devfs_create();
-#elif defined(__GNU__)
+#elif defined(__GNU__) || defined(__CYGWIN__)
     err = pci_system_x86_create();
 #endif
 
diff --git a/src/common_interface.c b/src/common_interface.c
index 3425edc..59778cf 100644
--- a/src/common_interface.c
+++ b/src/common_interface.c
@@ -36,7 +36,7 @@
 #include "pciaccess.h"
 #include "pciaccess_private.h"
 
-#if defined(__linux__) || defined(__GLIBC__)
+#if defined(__linux__) || defined(__GLIBC__) || defined(__CYGWIN__)
 #include <byteswap.h>
 
 #if __BYTE_ORDER == __BIG_ENDIAN
diff --git a/src/x86_pci.c b/src/x86_pci.c
index c75242e..b938068 100644
--- a/src/x86_pci.c
+++ b/src/x86_pci.c
@@ -72,6 +72,133 @@ x86_disable_io(void)
     return errno;
 }
 
+#elif defined(__CYGWIN__)
+
+#include <windows.h>
+
+/* WinIo declarations */
+typedef BYTE bool;
+typedef struct tagPhysStruct {
+    DWORD64 dwPhysMemSizeInBytes;
+    DWORD64 pvPhysAddress;
+    DWORD64 PhysicalMemoryHandle;
+    DWORD64 pvPhysMemLin;
+    DWORD64 pvPhysSection;
+} tagPhysStruct;
+
+typedef bool  (_stdcall* INITIALIZEWINIO)(void);
+typedef void  (_stdcall* SHUTDOWNWINIO)(void);
+typedef bool  (_stdcall* GETPORTVAL)(WORD,PDWORD,BYTE);
+typedef bool  (_stdcall* SETPORTVAL)(WORD,DWORD,BYTE);
+typedef PBYTE (_stdcall* MAPPHYSTOLIN)(tagPhysStruct*);
+typedef bool  (_stdcall* UNMAPPHYSMEM)(tagPhysStruct*);
+
+SHUTDOWNWINIO ShutdownWinIo;
+GETPORTVAL GetPortVal;
+SETPORTVAL SetPortVal;
+INITIALIZEWINIO InitializeWinIo;
+MAPPHYSTOLIN MapPhysToLin;
+UNMAPPHYSMEM UnmapPhysicalMemory;
+
+static int
+x86_enable_io(void)
+{
+    HMODULE lib = NULL;
+
+    if ((GetVersion() & 0x80000000) == 0) {
+      /* running on NT, try WinIo version 3 (32 or 64 bits) */
+#ifdef WIN64
+      lib = LoadLibrary("WinIo64.dll");
+#else
+      lib = LoadLibrary("WinIo32.dll");
+#endif
+    }
+
+    if (!lib) {
+      fprintf(stderr, "Failed to load WinIo library.\n");
+      return 1;
+    }
+
+#define GETPROC(n, d) 						\
+    n = (d) GetProcAddress(lib, #n); 				\
+    if (!n) { 							\
+      fprintf(stderr, "Failed to load " #n " function.\n");	\
+      return 1; 						\
+    }
+
+    GETPROC(InitializeWinIo, INITIALIZEWINIO);
+    GETPROC(ShutdownWinIo, SHUTDOWNWINIO);
+    GETPROC(GetPortVal, GETPORTVAL);
+    GETPROC(SetPortVal, SETPORTVAL);
+    GETPROC(MapPhysToLin, MAPPHYSTOLIN);
+    GETPROC(UnmapPhysicalMemory, UNMAPPHYSMEM);
+
+#undef GETPROC
+
+    if (!InitializeWinIo()) {
+      fprintf(stderr, "Failed to initialize WinIo.\n"
+		      "NOTE: WinIo.dll and WinIo.sys must be in the same directory as the executable!\n");
+      return 0;
+    }
+
+    return 0;
+}
+
+static int
+x86_disable_io(void)
+{
+    ShutdownWinIo();
+    return 1;
+}
+
+static inline uint8_t
+inb(uint16_t port)
+{
+    DWORD pv;
+
+    if (GetPortVal(port, &pv, 1))
+      return (uint8_t)pv;
+    return 0;
+}
+
+static inline uint16_t
+inw(uint16_t port)
+{
+    DWORD pv;
+
+    if (GetPortVal(port, &pv, 2))
+      return (uint16_t)pv;
+    return 0;
+}
+
+static inline uint32_t
+inl(uint16_t port)
+{
+    DWORD pv;
+
+    if (GetPortVal(port, &pv, 4))
+        return (uint32_t)pv;
+    return 0;
+}
+
+static inline void
+outb(uint8_t value, uint16_t port)
+{
+    SetPortVal(port, value, 1);
+}
+
+static inline void
+outw(uint16_t value, uint16_t port)
+{
+    SetPortVal(port, value, 2);
+}
+
+static inline void
+outl(uint32_t value, uint16_t port)
+{
+    SetPortVal(port, value, 4);
+}
+
 #else
 
 #error How to enable IO ports on this system?
@@ -471,6 +598,41 @@ pci_device_x86_probe(struct pci_device *dev)
     return 0;
 }
 
+#if defined(__CYGWIN__)
+
+static int
+pci_device_x86_map_range(struct pci_device *dev,
+    struct pci_device_mapping *map)
+{
+    tagPhysStruct phys;
+
+    phys.pvPhysAddress        = (DWORD64)(DWORD32)map->base;
+    phys.dwPhysMemSizeInBytes = map->size;
+
+    map->memory = (PDWORD)MapPhysToLin(&phys);
+    if (map->memory == NULL)
+        return EFAULT;
+
+    return 0;
+}
+
+static int
+pci_device_x86_unmap_range(struct pci_device *dev,
+    struct pci_device_mapping *map)
+{
+    tagPhysStruct phys;
+
+    phys.pvPhysAddress        = (DWORD64)(DWORD32)map->base;
+    phys.dwPhysMemSizeInBytes = map->size;
+
+    if (!UnmapPhysicalMemory(&phys))
+        return EFAULT;
+
+    return 0;
+}
+
+#else
+
 static int
 pci_device_x86_map_range(struct pci_device *dev,
     struct pci_device_mapping *map)
@@ -493,6 +655,15 @@ pci_device_x86_map_range(struct pci_device *dev,
 }
 
 static int
+pci_device_x86_unmap_range(struct pci_device *dev,
+    struct pci_device_mapping *map)
+{
+    return pci_device_generic_unamp_range(dev, map);
+}
+
+#endif
+
+static int
 pci_device_x86_read(struct pci_device *dev, void *data,
     pciaddr_t offset, pciaddr_t size, pciaddr_t *bytes_read)
 {
@@ -635,7 +806,7 @@ pci_device_x86_unmap_legacy(struct pci_device *dev, void *addr,
     map.flags = 0;
     map.memory = addr;
 
-    return pci_device_generic_unmap_range(dev, &map);
+    return pci_device_x86_unmap_range(dev, &map);
 }
 
 static const struct pci_system_methods x86_pci_methods = {
@@ -643,7 +814,7 @@ static const struct pci_system_methods x86_pci_methods = {
     .read_rom = pci_device_x86_read_rom,
     .probe = pci_device_x86_probe,
     .map_range = pci_device_x86_map_range,
-    .unmap_range = pci_device_generic_unmap_range,
+    .unmap_range = pci_device_x86_unmap_range,
     .read = pci_device_x86_read,
     .write = pci_device_x86_write,
     .fill_capabilities = pci_fill_capabilities_generic,

commit 06f562584a885eff7366dca82caf746e62b5a21f
Author: Thomas Klausner <wiz@NetBSD.org>
Date:   Wed Aug 14 19:45:46 2013 +0200

    Improve NetBSD i386 detection.
    
    Sometimes, other values are reported for the CPU part, like
    "i486--netbsdelf").
    
    From: Mark Davies <markd@NetBSD.org>
    Signed-off-by: Thomas Klausner <wiz@NetBSD.org>
    Reviewed-By:  Matt Dew <marcoz@osource.org>
    Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>

diff --git a/configure.ac b/configure.ac
index 65444b9..fe3b78e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -76,7 +76,7 @@ case $host_os in
 		;;
 	*netbsd*)
 		case $host in
-		*i386*)
+		*i[3-9]86*)
 			PCIACCESS_LIBS="$PCIACCESS_LIBS -li386 -lpci"
 			;;
 		*x86_64*|*amd64*)

commit 4427be3de93f359ab106a649a43e41319625e1e7
Author: Thomas Klausner <wiz@NetBSD.org>
Date:   Sun Jul 21 11:44:14 2013 +0200

    Fix zlib handling on NetBSD.
    
    Signed-off-by: Thomas Klausner <wiz@NetBSD.org>
    Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
    Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>

diff --git a/configure.ac b/configure.ac
index 9b7cd8c..65444b9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -77,10 +77,10 @@ case $host_os in
 	*netbsd*)
 		case $host in
 		*i386*)
-			PCIACCESS_LIBS="-li386 -lpci"
+			PCIACCESS_LIBS="$PCIACCESS_LIBS -li386 -lpci"
 			;;
 		*x86_64*|*amd64*)
-			PCIACCESS_LIBS="-lx86_64 -lpci"
+			PCIACCESS_LIBS="$PCIACCESS_LIBS -lx86_64 -lpci"
 			;;
 		esac
 		netbsd=yes


Reply to: