xref: /kvm-unit-tests/lib/s390x/malloc_io.h (revision 3054ca26152d01aed6e4a9b7dc03e447882aeccc)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * I/O allocations
4  *
5  * Copyright (c) 2021 IBM Corp
6  *
7  * Authors:
8  *  Pierre Morel <pmorel@linux.ibm.com>
9  *
10  */
11 #ifndef _S390X_MALLOC_IO_H_
12 #define _S390X_MALLOC_IO_H_
13 
14 /*
15  * Allocates a page aligned page bound range of contiguous real or
16  * absolute memory in the DMA31 region large enough to contain size
17  * bytes.
18  * If Protected Virtualisation facility is present, shares the pages
19  * with the host.
20  * If all the pages for the specified size cannot be reserved,
21  * the function rewinds the partial allocation and a NULL pointer
22  * is returned.
23  *
24  * @size: the minimal size allocated in byte.
25  * @flags: the flags used for the underlying page allocator.
26  *
27  * Errors:
28  *   The allocation will assert the size parameter, will fail if the
29  *   underlying page allocator fail or in the case of protected
30  *   virtualisation if the sharing of the pages fails.
31  *
32  * Returns a pointer to the first page in case of success, NULL otherwise.
33  */
34 void *alloc_io_mem(int size, int flags);
35 
36 /*
37  * Frees a previously memory space allocated by alloc_io_mem.
38  * If Protected Virtualisation facility is present, unshares the pages
39  * with the host.
40  * The address must be aligned on a page boundary otherwise an assertion
41  * breaks the program.
42  */
43 void free_io_mem(void *p, int size);
44 
45 #endif /* _S390X_MALLOC_IO_H_ */
46