diff options
author | Niclas Zeising <zeising@daemonic.se> | 2019-06-16 10:41:03 +0200 |
---|---|---|
committer | Niclas Zeising <zeising@daemonic.se> | 2019-07-10 18:55:15 +0200 |
commit | 976e661ee193941f9928353db365f14654a934db (patch) | |
tree | 1ebbcbbe3ea8b6ad80101a34f52fa2f676f6436c | |
parent | a1b528c4ae00972640d7a24f049c3fe9055ffe3b (diff) |
freebsd_pci: Make this work on sparc64
Make the FreeBSD libpciaccess routines work on FreeBSD. The FreeBSD
sparc64 architecture needs special treatment, similar to the
PCI_MAGIC_IO_RANGE code. However, PCI_MAGIC_IO_RANGE has been gone for
some time. Give this a chance to work on sparc64 anyway.
This code has been in the FreeBSD ports tree for some time.
-rw-r--r-- | src/common_init.c | 4 | ||||
-rw-r--r-- | src/freebsd_pci.c | 46 | ||||
-rw-r--r-- | src/pciaccess_private.h | 1 |
3 files changed, 42 insertions, 9 deletions
diff --git a/src/common_init.c b/src/common_init.c index f7b59bd..18f717d 100644 --- a/src/common_init.c +++ b/src/common_init.c @@ -77,7 +77,9 @@ pci_system_init( void ) void pci_system_init_dev_mem(int fd) { -#ifdef __OpenBSD__ +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) + pci_system_freebsd_init_dev_mem(fd); +#elif defined(__OpenBSD__) pci_system_openbsd_init_dev_mem(fd); #endif } diff --git a/src/freebsd_pci.c b/src/freebsd_pci.c index e501d0b..ab7a8df 100644 --- a/src/freebsd_pci.c +++ b/src/freebsd_pci.c @@ -82,6 +82,10 @@ #define PCIM_BAR_MEM_SPACE 0 #define PCIM_BAR_IO_SPACE 1 +#if defined(__sparc64__) +static int screenfd; +#endif + /** * FreeBSD private pci_system structure that extends the base pci_system * structure. @@ -113,12 +117,18 @@ pci_device_freebsd_map_range( struct pci_device *dev, { const int prot = ((map->flags & PCI_DEV_MAP_FLAG_WRITABLE) != 0) ? (PROT_READ | PROT_WRITE) : PROT_READ; +#if !defined(__sparc64__) struct mem_range_desc mrd; struct mem_range_op mro; +#endif int fd, err = 0; +#if defined(__sparc64__) + fd = screenfd; +#else fd = open("/dev/mem", O_RDWR | O_CLOEXEC); +#endif if (fd == -1) return errno; @@ -128,6 +138,7 @@ pci_device_freebsd_map_range( struct pci_device *dev, err = errno; } +#if !defined(__sparc64__) mrd.mr_base = map->base; mrd.mr_len = map->size; strncpy(mrd.mr_owner, "pciaccess", sizeof(mrd.mr_owner)); @@ -148,6 +159,7 @@ pci_device_freebsd_map_range( struct pci_device *dev, } close(fd); +#endif return err; } @@ -156,6 +168,7 @@ static int pci_device_freebsd_unmap_range( struct pci_device *dev, struct pci_device_mapping *map ) { +#if !defined(__sparc64__) struct mem_range_desc mrd; struct mem_range_op mro; int fd; @@ -181,6 +194,7 @@ pci_device_freebsd_unmap_range( struct pci_device *dev, fprintf(stderr, "Failed to open /dev/mem\n"); } } +#endif return pci_device_generic_unmap_range(dev, map); } @@ -299,7 +313,11 @@ pci_device_freebsd_read_rom( struct pci_device * dev, void * buffer ) } printf("Using rom_base = 0x%lx\n", (long)rom_base); +#if defined(__sparc64__) + memfd = screenfd; +#else memfd = open( "/dev/mem", O_RDONLY | O_CLOEXEC ); +#endif if ( memfd == -1 ) return errno; @@ -312,7 +330,9 @@ pci_device_freebsd_read_rom( struct pci_device * dev, void * buffer ) memcpy( buffer, bios, dev->rom_size ); munmap( bios, dev->rom_size ); +#if !defined(__sparc64__) close( memfd ); +#endif if (pci_rom) { pci_device_cfg_write_u32( dev, PCIR_BIOS, rom ); @@ -570,9 +590,9 @@ pci_device_freebsd_open_legacy_io( struct pci_io_handle *ret, struct pci_device *dev, pciaddr_t base, pciaddr_t size ) { -#if defined(PCI_MAGIC_IO_RANGE) +#if defined(__sparc64__) ret->memory = mmap( NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, - aperturefd, PCI_MAGIC_IO_RANGE + base ); + screenfd, base ); if ( ret->memory == MAP_FAILED ) return NULL; #else @@ -601,14 +621,16 @@ static void pci_device_freebsd_close_io( struct pci_device *dev, struct pci_io_handle *handle ) { +#if !defined(__sparc64__) if ( handle->fd > -1 ) close( handle->fd ); +#endif } static uint32_t pci_device_freebsd_read32( struct pci_io_handle *handle, uint32_t reg ) { -#if defined(PCI_MAGIC_IO_RANGE) +#if defined(__sparc64__) return *(uint32_t *)((uintptr_t)handle->memory + reg); #elif defined(__i386__) || defined(__amd64__) return inl( handle->base + reg ); @@ -623,7 +645,7 @@ pci_device_freebsd_read32( struct pci_io_handle *handle, uint32_t reg ) static uint16_t pci_device_freebsd_read16( struct pci_io_handle *handle, uint32_t reg ) { -#if defined(PCI_MAGIC_IO_RANGE) +#if defined(__sparc64__) return *(uint16_t *)((uintptr_t)handle->memory + reg); #elif defined(__i386__) || defined(__amd64__) return inw( handle->base + reg ); @@ -638,7 +660,7 @@ pci_device_freebsd_read16( struct pci_io_handle *handle, uint32_t reg ) static uint8_t pci_device_freebsd_read8( struct pci_io_handle *handle, uint32_t reg ) { -#if defined(PCI_MAGIC_IO_RANGE) +#if defined(__sparc64__) return *(uint8_t *)((uintptr_t)handle->memory + reg); #elif defined(__i386__) || defined(__amd64__) return inb( handle->base + reg ); @@ -654,7 +676,7 @@ static void pci_device_freebsd_write32( struct pci_io_handle *handle, uint32_t reg, uint32_t data ) { -#if defined(PCI_MAGIC_IO_RANGE) +#if defined(__sparc64__) *(uint32_t *)((uintptr_t)handle->memory + reg) = data; #elif defined(__i386__) || defined(__amd64__) outl( handle->base + reg, data ); @@ -669,7 +691,7 @@ static void pci_device_freebsd_write16( struct pci_io_handle *handle, uint32_t reg, uint16_t data ) { -#if defined(PCI_MAGIC_IO_RANGE) +#if defined(__sparc64__) *(uint16_t *)((uintptr_t)handle->memory + reg) = data; #elif defined(__i386__) || defined(__amd64__) outw( handle->base + reg, data ); @@ -684,7 +706,7 @@ static void pci_device_freebsd_write8( struct pci_io_handle *handle, uint32_t reg, uint8_t data ) { -#if defined(PCI_MAGIC_IO_RANGE) +#if defined(__sparc64__) *(uint8_t *)((uintptr_t)handle->memory + reg) = data; #elif defined(__i386__) || defined(__amd64__) outb( handle->base + reg, data ); @@ -814,3 +836,11 @@ pci_system_freebsd_create( void ) return 0; } + +void +pci_system_freebsd_init_dev_mem(int fd) +{ +#if defined(__sparc64__) + screenfd = fd; +#endif +} diff --git a/src/pciaccess_private.h b/src/pciaccess_private.h index 2f05b29..a45b093 100644 --- a/src/pciaccess_private.h +++ b/src/pciaccess_private.h @@ -185,6 +185,7 @@ extern struct pci_system * pci_sys; extern int pci_system_linux_sysfs_create( void ); extern int pci_system_freebsd_create( void ); +extern void pci_system_freebsd_init_dev_mem( int ); extern int pci_system_netbsd_create( void ); extern int pci_system_openbsd_create( void ); extern void pci_system_openbsd_init_dev_mem( int ); |