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