Index: devel/libpciaccess/files/patch-src-freebsd_pci.c =================================================================== --- devel/libpciaccess/files/patch-src-freebsd_pci.c (revision 363361) +++ devel/libpciaccess/files/patch-src-freebsd_pci.c (working copy) @@ -1,5 +1,5 @@ ---- src/freebsd_pci.c.orig 2013-08-14 12:31:57.519923558 +0200 -+++ src/freebsd_pci.c 2013-08-14 12:31:36.809923955 +0200 +--- src/freebsd_pci.c.orig 2013-07-20 15:54:34.000000000 -0700 ++++ src/freebsd_pci.c 2014-07-20 09:09:04.000000000 -0700 @@ -39,6 +39,11 @@ #include #include @@ -23,7 +23,18 @@ /** * FreeBSD private pci_system structure that extends the base pci_system * structure. -@@ -105,12 +114,18 @@ +@@ -91,7 +100,9 @@ + } *freebsd_pci_sys; + + /** +- * Map a memory region for a device using /dev/mem. ++ * Map a memory region for a device using /dev/mem. Note that we set MTRRs ++ * first, if needed, so that platforms that emulate MTRRs (e.g. PowerPC) get ++ * a chance to apply them to the mmap() request. + * + * \param dev Device whose memory region is to be mapped. + * \param map Parameters of the mapping that is to be created. +@@ -105,21 +116,22 @@ { const int prot = ((map->flags & PCI_DEV_MAP_FLAG_WRITABLE) != 0) ? (PROT_READ | PROT_WRITE) : PROT_READ; @@ -42,23 +53,35 @@ if (fd == -1) return errno; -@@ -120,6 +135,7 @@ - err = errno; - } - +- map->memory = mmap(NULL, map->size, prot, MAP_SHARED, fd, map->base); +- +- if (map->memory == MAP_FAILED) { +- err = errno; +- } +- +#if !defined(__sparc64__) mrd.mr_base = map->base; mrd.mr_len = map->size; strncpy(mrd.mr_owner, "pciaccess", sizeof(mrd.mr_owner)); -@@ -140,6 +156,7 @@ +@@ -138,8 +150,17 @@ + fprintf(stderr, "failed to set mtrr: %s\n", strerror(errno)); + } } ++#endif ++ ++ map->memory = mmap(NULL, map->size, prot, MAP_SHARED, fd, map->base); ++ ++ if (map->memory == MAP_FAILED) { ++ err = errno; ++ } ++#if !defined(__sparc64__) close(fd); +#endif return err; } -@@ -148,6 +165,7 @@ +@@ -148,6 +169,7 @@ pci_device_freebsd_unmap_range( struct pci_device *dev, struct pci_device_mapping *map ) { @@ -66,7 +89,7 @@ struct mem_range_desc mrd; struct mem_range_op mro; int fd; -@@ -173,6 +191,7 @@ +@@ -173,6 +195,7 @@ fprintf(stderr, "Failed to open /dev/mem\n"); } } @@ -74,7 +97,7 @@ return pci_device_generic_unmap_range(dev, map); } -@@ -295,7 +314,11 @@ +@@ -295,7 +318,11 @@ } printf("Using rom_base = 0x%lx\n", (long)rom_base); @@ -86,7 +109,7 @@ if ( memfd == -1 ) return errno; -@@ -308,7 +331,9 @@ +@@ -308,7 +335,9 @@ memcpy( buffer, bios, dev->rom_size ); munmap( bios, dev->rom_size ); @@ -96,7 +119,7 @@ if (pci_rom) { pci_device_cfg_write_u32( dev, PCIR_BIOS, rom ); -@@ -343,7 +368,6 @@ +@@ -343,7 +372,6 @@ static int pci_device_freebsd_probe( struct pci_device * dev ) { @@ -104,7 +127,7 @@ struct pci_bar_io bar; uint8_t irq; int err, i; -@@ -563,136 +587,152 @@ +@@ -563,136 +591,152 @@ freebsd_pci_sys = NULL; } @@ -333,7 +356,7 @@ } static const struct pci_system_methods freebsd_pci_methods = { -@@ -706,9 +746,7 @@ +@@ -706,9 +750,7 @@ .write = pci_device_freebsd_write, .fill_capabilities = pci_fill_capabilities_generic, .open_legacy_io = pci_device_freebsd_open_legacy_io, @@ -343,7 +366,7 @@ .read32 = pci_device_freebsd_read32, .read16 = pci_device_freebsd_read16, .read8 = pci_device_freebsd_read8, -@@ -790,3 +828,11 @@ +@@ -790,3 +832,11 @@ return 0; }