xref: /libpciaccess/src/common_map.c (revision d898072e)
108ff9f7fSIan Romanick /*
208ff9f7fSIan Romanick  * (C) Copyright IBM Corporation 2007
308ff9f7fSIan Romanick  * All Rights Reserved.
408ff9f7fSIan Romanick  *
508ff9f7fSIan Romanick  * Permission is hereby granted, free of charge, to any person obtaining a
608ff9f7fSIan Romanick  * copy of this software and associated documentation files (the "Software"),
708ff9f7fSIan Romanick  * to deal in the Software without restriction, including without limitation
808ff9f7fSIan Romanick  * on the rights to use, copy, modify, merge, publish, distribute, sub
908ff9f7fSIan Romanick  * license, and/or sell copies of the Software, and to permit persons to whom
1008ff9f7fSIan Romanick  * the Software is furnished to do so, subject to the following conditions:
1108ff9f7fSIan Romanick  *
1208ff9f7fSIan Romanick  * The above copyright notice and this permission notice (including the next
1308ff9f7fSIan Romanick  * paragraph) shall be included in all copies or substantial portions of the
1408ff9f7fSIan Romanick  * Software.
1508ff9f7fSIan Romanick  *
1608ff9f7fSIan Romanick  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1708ff9f7fSIan Romanick  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1808ff9f7fSIan Romanick  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
1908ff9f7fSIan Romanick  * IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2008ff9f7fSIan Romanick  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2108ff9f7fSIan Romanick  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2208ff9f7fSIan Romanick  * DEALINGS IN THE SOFTWARE.
2308ff9f7fSIan Romanick  */
2408ff9f7fSIan Romanick 
25*d898072eSMark Kettenis #include <sys/types.h>
2608ff9f7fSIan Romanick #include <sys/mman.h>
2708ff9f7fSIan Romanick #include <errno.h>
2808ff9f7fSIan Romanick 
2908ff9f7fSIan Romanick #include "pciaccess.h"
3008ff9f7fSIan Romanick #include "pciaccess_private.h"
3108ff9f7fSIan Romanick 
3208ff9f7fSIan Romanick /**
3308ff9f7fSIan Romanick  * \file common_map.c
3408ff9f7fSIan Romanick  * Platform independent memory map routines.
3508ff9f7fSIan Romanick  *
3608ff9f7fSIan Romanick  * \author Ian Romanick <[email protected]>
3708ff9f7fSIan Romanick  */
3808ff9f7fSIan Romanick 
3908ff9f7fSIan Romanick /**
4008ff9f7fSIan Romanick  * Unmap the specified region using the munmap.
4108ff9f7fSIan Romanick  *
4208ff9f7fSIan Romanick  * \param dev    Device whose memory region is to be mapped.
4308ff9f7fSIan Romanick  * \param map    Memory mapping that is to be undone.
4408ff9f7fSIan Romanick  *
4508ff9f7fSIan Romanick  * \return
4608ff9f7fSIan Romanick  * Zero on success or an \c errno value on failure.
4708ff9f7fSIan Romanick  *
4808ff9f7fSIan Romanick  * \sa pci_device_unmap_range
4908ff9f7fSIan Romanick  */
50adc46f65SJulien Cristau _pci_hidden int
pci_device_generic_unmap_range(struct pci_device * dev,struct pci_device_mapping * map)5108ff9f7fSIan Romanick pci_device_generic_unmap_range(struct pci_device *dev,
5208ff9f7fSIan Romanick 			       struct pci_device_mapping *map)
5308ff9f7fSIan Romanick {
5408ff9f7fSIan Romanick     return (munmap(map->memory, map->size) == -1) ? errno : 0;
5508ff9f7fSIan Romanick }
56