]> mj.ucw.cz Git - pciutils.git/blob - lib/physmem.h
libpci: Update manpage documentation for devmem.path
[pciutils.git] / lib / physmem.h
1 /*
2  *      The PCI Library -- Physical memory mapping API
3  *
4  *      Copyright (c) 2023 Pali Rohár <pali@kernel.org>
5  *
6  *      Can be freely distributed and used under the terms of the GNU GPL v2+
7  *
8  *      SPDX-License-Identifier: GPL-2.0-or-later
9  */
10
11 struct physmem;
12
13 void physmem_init_config(struct pci_access *a);
14 int physmem_access(struct pci_access *a, int w);
15 struct physmem *physmem_open(struct pci_access *a, int w);
16 void physmem_close(struct physmem *physmem);
17 long physmem_get_pagesize(struct physmem *physmem);
18
19 /*
20  * physmem_map returns ptr on success, (void *)-1 on error and sets errno compatible with POSIX mmap():
21  * - EBADF - invalid physmem argument
22  * - EINVAL - invalid or unaligned addr argument
23  * - EACCES - write access requested but physmem was opened without write access
24  * - ENOSYS - physmem argument does not support physical address mapping at all
25  * - ENXIO - addr/length range was rejected by system (e.g. range not accessible or not available)
26  * - EOVERFLOW - addr/length range is out of the physical address space (e.g. does not fit into signed 32-bit off_t type on 32-bit systems)
27  * - EACCES - generic unknown error for djgpp and windows
28  */
29 void *physmem_map(struct physmem *physmem, u64 addr, size_t length, int w);
30
31 /*
32  * Unmap physical memory mapping, ptr and length must be exactly same as for physmem_map(), unmapping just subrange is not allowed.
33  * physmem_unmap returns 0 on success, -1 on error and sets errno:
34  * - EBADF - invalid physmem argument
35  * - EINVAL - invalid ptr/length argument
36  * - EPERM - ptr/length range cannot be unmapped due to access permission checks (e.g. page marked as immutable)
37  * - ENOSYS - physmem argument does not support physical address unmapping at all (e.g. every mapping stays active until application terminates)
38  * - EACCES - generic unknown error for djgpp and windows
39  */
40 int physmem_unmap(struct physmem *physmem, void *ptr, size_t length);