summaryrefslogtreecommitdiff
path: root/src/common_init.c
diff options
context:
space:
mode:
authorIan Romanick <idr@us.ibm.com>2006-03-18 00:12:48 +0000
committerIan Romanick <idr@us.ibm.com>2006-03-18 00:12:48 +0000
commit5a04522a921cd8737ef921dfd49b750a8c64dfc9 (patch)
tree3147bede119f7107fc0cab2e93ce78ef409fb590 /src/common_init.c
downloadxorg-lib-libpciaccess-5a04522a921cd8737ef921dfd49b750a8c64dfc9.tar.gz
Initial import of libpciaccess.
Diffstat (limited to 'src/common_init.c')
-rw-r--r--src/common_init.c111
1 files changed, 111 insertions, 0 deletions
diff --git a/src/common_init.c b/src/common_init.c
new file mode 100644
index 0000000..cabda5e
--- /dev/null
+++ b/src/common_init.c
@@ -0,0 +1,111 @@
+/*
+ * (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 common_init.c
+ * Platform independent routines for initializing access to the PCI system.
+ *
+ * \author Ian Romanick <idr@us.ibm.com>
+ */
+
+#include <stdlib.h>
+#include <errno.h>
+
+#include "pciaccess.h"
+#include "pciaccess_private.h"
+
+extern int pci_system_linux_sysfs_create( void );
+
+struct pci_system * pci_sys;
+
+/**
+ * Initialize the PCI subsystem for access.
+ *
+ * \return
+ * Zero on success or an errno value on failure. In particular, if no
+ * platform-specific initializers are available, \c ENOSYS will be returned.
+ *
+ * \sa pci_system_cleanup
+ */
+
+int
+pci_system_init( void )
+{
+ int err = ENOSYS;
+
+#ifdef linux
+ err = pci_system_linux_sysfs_create();
+#endif
+
+ return err;
+}
+
+
+/**
+ * Shutdown all access to the PCI subsystem.
+ *
+ * \sa pci_system_init
+ */
+void
+pci_system_cleanup( void )
+{
+ unsigned i;
+ unsigned j;
+
+
+ if ( pci_sys == NULL ) {
+ return;
+ }
+
+
+ if ( pci_sys->devices ) {
+ for ( i = 0 ; i < pci_sys->num_devices ; i++ ) {
+ for ( j = 0 ; j < 6 ; j++ ) {
+ (void) pci_device_unmap_region( & pci_sys->devices[i].base, j );
+ }
+
+ free( (char *) pci_sys->devices[i].device_string );
+ free( (char *) pci_sys->devices[i].agp );
+
+ pci_sys->devices[i].device_string = NULL;
+ pci_sys->devices[i].agp = NULL;
+
+ if ( pci_sys->methods->destroy_device != NULL ) {
+ (*pci_sys->methods->destroy_device)( & pci_sys->devices[i].base );
+ }
+ }
+
+ free( pci_sys->devices );
+ pci_sys->devices = NULL;
+ pci_sys->num_devices = 0;
+ }
+
+
+ if ( pci_sys->methods->destroy != NULL ) {
+ (*pci_sys->methods->destroy)();
+ }
+
+ free( pci_sys );
+ pci_sys = NULL;
+}