summaryrefslogtreecommitdiff
path: root/src/common_map.c
diff options
context:
space:
mode:
authorIan Romanick <idr@us.ibm.com>2007-08-30 17:52:02 -0700
committerIan Romanick <idr@us.ibm.com>2007-08-30 17:52:19 -0700
commit08ff9f7fbd26dd2d0e30351b556c71c272f6be6c (patch)
tree0c4849c43518d4d172b4a1f409a8e35579b13e23 /src/common_map.c
parentc87273e8e20c8bff892ded31295dba103f27dd35 (diff)
New interfaces to map memory with MTRR (or similar) support.
Added new functions pci_device_map_range and pci_device_unmap_range to handle mapping of PCI device BARs. These new interfaces allow the possiblity of MTRRs on platforms that support them. These additional APIs necessitated changing some internal interfaces. The code for FreeBSD and Solaris has been updated but has not been compiled or tested. Old interfaces are marked deprecated and will eventually be removed.
Diffstat (limited to 'src/common_map.c')
-rw-r--r--src/common_map.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/common_map.c b/src/common_map.c
new file mode 100644
index 0000000..a64577b
--- /dev/null
+++ b/src/common_map.c
@@ -0,0 +1,54 @@
+/*
+ * (C) Copyright IBM Corporation 2007
+ * 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.
+ */
+
+#include <sys/mman.h>
+#include <errno.h>
+
+#include "pciaccess.h"
+#include "pciaccess_private.h"
+
+/**
+ * \file common_map.c
+ * Platform independent memory map routines.
+ *
+ * \author Ian Romanick <idr@us.ibm.com>
+ */
+
+/**
+ * Unmap the specified region using the munmap.
+ *
+ * \param dev Device whose memory region is to be mapped.
+ * \param map Memory mapping that is to be undone.
+ *
+ * \return
+ * Zero on success or an \c errno value on failure.
+ *
+ * \sa pci_device_unmap_range
+ */
+int
+pci_device_generic_unmap_range(struct pci_device *dev,
+ struct pci_device_mapping *map)
+{
+ return (munmap(map->memory, map->size) == -1) ? errno : 0;
+}