aboutsummaryrefslogtreecommitdiff
path: root/platform/linux-generic/pktio/physmem/physmem.h
blob: 77dcb389443bb6c978f0b5d18abecbfcd254cbbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* Copyright (c) 2017, Linaro Limited
 * All rights reserved.
 *
 * SPDX-License-Identifier:     BSD-3-Clause
 */

#ifndef PHYSMEM_BLOCK_H
#define PHYSMEM_BLOCK_H

#include <sys/queue.h>
#include <stdint.h>

typedef enum {
	BLOCK_EMPTY = 0,
	BLOCK_AVAIL,
	BLOCK_USED
} physmem_block_type_t;

/* a block is a chunk of physically contiguous memory that can be
 * made of one or more huge pages
 */
struct physmem_block {
	LIST_ENTRY(physmem_block) next;
	void *va; /* virtual address where the block is mapped */
	void *va_reserved; /* internal */
	uint64_t pa; /* physical address where it starts */
	uint64_t size; /* the size of this memory block */
	uint64_t va_reserved_size; /* internal */
	uint32_t first; /* index of first hugepage belonging to this block
			 * in pages[] */
	uint32_t count; /* number of hugepages in this block */
	uint32_t hp_size; /* the size of the hugepages */
	uint32_t id; /* internal ID of this block, debug purposes */
	physmem_block_type_t type;
};

int physmem_block_init_global(void);
int physmem_block_term_global(void);

struct physmem_block *physmem_block_alloc(uint64_t size);
void physmem_block_free(struct physmem_block *block);
int physmem_block_map(struct physmem_block *block, void *addr);
int physmem_block_unmap(struct physmem_block *block);

/* if pages is not 0, it will print the pages associated to each block */
void physmem_block_dump(physmem_block_type_t, int pages);
int physmem_block_check(const struct physmem_block *);

#endif