xref: /pciutils/lib/physmem.h (revision 03b2f847)
17d347ab7SPali Rohár /*
27d347ab7SPali Rohár  *      The PCI Library -- Physical memory mapping API
37d347ab7SPali Rohár  *
47d347ab7SPali Rohár  *      Copyright (c) 2023 Pali Rohár <[email protected]>
57d347ab7SPali Rohár  *
67d347ab7SPali Rohár  *      Can be freely distributed and used under the terms of the GNU GPL v2+
77d347ab7SPali Rohár  *
87d347ab7SPali Rohár  *      SPDX-License-Identifier: GPL-2.0-or-later
97d347ab7SPali Rohár  */
107d347ab7SPali Rohár 
117d347ab7SPali Rohár struct physmem;
127d347ab7SPali Rohár 
137d347ab7SPali Rohár void physmem_init_config(struct pci_access *a);
147d347ab7SPali Rohár int physmem_access(struct pci_access *a, int w);
157d347ab7SPali Rohár struct physmem *physmem_open(struct pci_access *a, int w);
167d347ab7SPali Rohár void physmem_close(struct physmem *physmem);
177d347ab7SPali Rohár long physmem_get_pagesize(struct physmem *physmem);
18*03b2f847SPali Rohár 
19*03b2f847SPali Rohár /*
20*03b2f847SPali Rohár  * physmem_map returns ptr on success, (void *)-1 on error and sets errno compatible with POSIX mmap():
21*03b2f847SPali Rohár  * - EBADF - invalid physmem argument
22*03b2f847SPali Rohár  * - EINVAL - invalid or unaligned addr argument
23*03b2f847SPali Rohár  * - EACCES - write access requested but physmem was opened without write access
24*03b2f847SPali Rohár  * - ENOSYS - physmem argument does not support physical address mapping at all
25*03b2f847SPali Rohár  * - ENXIO - addr/length range was rejected by system (e.g. range not accessible or not available)
26*03b2f847SPali Rohár  * - 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*03b2f847SPali Rohár  * - EACCES - generic unknown error for djgpp and windows
28*03b2f847SPali Rohár  */
297d347ab7SPali Rohár void *physmem_map(struct physmem *physmem, u64 addr, size_t length, int w);
30*03b2f847SPali Rohár 
31*03b2f847SPali Rohár /*
32*03b2f847SPali Rohár  * Unmap physical memory mapping, ptr and length must be exactly same as for physmem_map(), unmapping just subrange is not allowed.
33*03b2f847SPali Rohár  * physmem_unmap returns 0 on success, -1 on error and sets errno:
34*03b2f847SPali Rohár  * - EBADF - invalid physmem argument
35*03b2f847SPali Rohár  * - EINVAL - invalid ptr/length argument
36*03b2f847SPali Rohár  * - EPERM - ptr/length range cannot be unmapped due to access permission checks (e.g. page marked as immutable)
37*03b2f847SPali Rohár  * - ENOSYS - physmem argument does not support physical address unmapping at all (e.g. every mapping stays active until application terminates)
38*03b2f847SPali Rohár  * - EACCES - generic unknown error for djgpp and windows
39*03b2f847SPali Rohár  */
407d347ab7SPali Rohár int physmem_unmap(struct physmem *physmem, void *ptr, size_t length);
41