diff --git a/lib/libpciaccess/configure.ac b/lib/libpciaccess/configure.ac index 2eafcbd94..c5e436c69 100644 --- a/lib/libpciaccess/configure.ac +++ b/lib/libpciaccess/configure.ac @@ -78,10 +78,14 @@ case $host_os in *linux*) linux=yes ;; + *openbsd*) + openbsd=yes + ;; esac AM_CONDITIONAL(LINUX, [test "x$linux" = xyes]) AM_CONDITIONAL(FREEBSD, [test "x$freebsd" = xyes]) +AM_CONDITIONAL(OPENBSD, [test "x$openbsd" = xyes]) AC_SUBST(PCIACCESS_CFLAGS) AC_SUBST(PCIACCESS_LIBS) diff --git a/lib/libpciaccess/src/Makefile.am b/lib/libpciaccess/src/Makefile.am index 3e915920b..3ab311f0a 100644 --- a/lib/libpciaccess/src/Makefile.am +++ b/lib/libpciaccess/src/Makefile.am @@ -33,6 +33,10 @@ if FREEBSD OS_SUPPORT = freebsd_pci.c endif +if OPENBSD +OS_SUPPORT = openbsd_pci.c +endif + libpciaccess_la_SOURCES = common_bridge.c \ common_iterator.c \ common_init.c \ diff --git a/lib/libpciaccess/src/common_init.c b/lib/libpciaccess/src/common_init.c index 109bd74b0..2fc981c52 100644 --- a/lib/libpciaccess/src/common_init.c +++ b/lib/libpciaccess/src/common_init.c @@ -56,6 +56,8 @@ pci_system_init( void ) err = pci_system_linux_sysfs_create(); #elif defined(__FreeBSD__) err = pci_system_freebsd_create(); +#elif defined(__OpenBSD__) + err = pci_system_openbsd_create(); #endif return err; diff --git a/lib/libpciaccess/src/common_interface.c b/lib/libpciaccess/src/common_interface.c index 5b07d3ca8..89feb5702 100644 --- a/lib/libpciaccess/src/common_interface.c +++ b/lib/libpciaccess/src/common_interface.c @@ -50,6 +50,15 @@ # define HTOLE_32(x) (x) #endif +#elif defined(__OpenBSD__) + +#include + +#define LETOH_16(x) letoh16(x) +#define HTOLE_16(x) htole16(x) +#define LETOH_32(x) letoh32(x) +#define HTOLE_32(x) htole32(x) + #else #include diff --git a/lib/libpciaccess/src/openbsd_pci.c b/lib/libpciaccess/src/openbsd_pci.c new file mode 100644 index 000000000..80ac26adb --- /dev/null +++ b/lib/libpciaccess/src/openbsd_pci.c @@ -0,0 +1,144 @@ +/* $OpenBSD: openbsd_pci.c,v 1.1 2007/06/06 21:01:25 matthieu Exp $ */ +/* + * (C) Copyright Eric Anholt 2006 + * (C) Copyright IBM Corporation 2006 + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file openbsd_pci.c + * + * Access the kernel PCI support using /dev/pci's ioctl and mmap interface. + * + * \author Eric Anholt + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "pciaccess.h" +#include "pciaccess_private.h" + +/** + * OpenBSD private pci_system structure that extends the base pci_system + * structure. + * + * It is initialized once and used as a global, just as pci_system is used. + */ +struct openbsd_pci_system { + struct pci_system pci_sys; /* must come first */ + int pcidev; /**< fd for /dev/pci */ +} *openbsd_pci_sys; + +/** + * Map a memory region for a device using /dev/mem. + * + * \param dev Device whose memory region is to be mapped. + * \param region Region, on the range [0, 5], that is to be mapped. + * \param write_enable Map for writing (non-zero). + * + * \return + * Zero on success or an \c errno value on failure. + */ +static int +pci_device_openbsd_map(struct pci_device *dev, unsigned int region, + int write_enable) +{ +} + +/** + * Unmap the specified region. + * + * \param dev Device whose memory region is to be unmapped. + * \param region Region, on the range [0, 5], that is to be unmapped. + * + * \return + * Zero on success or an \c errno value on failure. + */ +static int +pci_device_openbsd_unmap(struct pci_device *dev, unsigned int region) +{ +} + +static int +pci_device_openbsd_read(struct pci_device *dev, void *data, + pciaddr_t offset, pciaddr_t size, pciaddr_t *bytes_read) +{ +} + +static int +pci_device_openbsd_write(struct pci_device *dev, const void *data, + pciaddr_t offset, pciaddr_t size, pciaddr_t *bytes_written) +{ +} + + +static int +pci_device_openbsd_probe(struct pci_device *dev) +{ +} + +static int +pci_device_openbsd_read_rom(struct pci_device *dev, void *buffer) +{ +} + + +static void +pci_system_openbsd_destroy(void) +{ + free(openbsd_pci_sys->pci_sys.devices); + openbsd_pci_sys = NULL; +} + +static const struct pci_system_methods openbsd_pci_methods = { + .destroy = pci_system_openbsd_destroy, + .destroy_device = NULL, + .read_rom = pci_device_openbsd_read_rom, + .probe = pci_device_openbsd_probe, + .map = pci_device_openbsd_map, + .unmap = pci_device_openbsd_unmap, + .read = pci_device_openbsd_read, + .write = pci_device_openbsd_write, + .fill_capabilities = pci_fill_capabilities_generic, +}; + +/** + * Attempt to acces the OpenBSD PCI interface. + */ +int +pci_system_openbsd_create(void) +{ + openbsd_pci_sys = calloc(1, sizeof(struct openbsd_pci_system)); + if (openbsd_pci_sys = NULL) + return ENOMEM; + pci_sys = &openbsd_pci_sys->pci_sys; + pci_sys->methods = &openbsd_pci_methods; + + return 0; +}