]> git.ipfire.org Git - thirdparty/pciutils.git/blame - lib/physmem.h
lspci: add VirtIO SharedMemory capability support
[thirdparty/pciutils.git] / lib / physmem.h
CommitLineData
7d347ab7
PR
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
11struct physmem;
12
13void physmem_init_config(struct pci_access *a);
14int physmem_access(struct pci_access *a, int w);
15struct physmem *physmem_open(struct pci_access *a, int w);
16void physmem_close(struct physmem *physmem);
17long physmem_get_pagesize(struct physmem *physmem);
03b2f847
PR
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 */
7d347ab7 29void *physmem_map(struct physmem *physmem, u64 addr, size_t length, int w);
03b2f847
PR
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 */
7d347ab7 40int physmem_unmap(struct physmem *physmem, void *ptr, size_t length);