xref: /dpdk/lib/bpf/bpf.c (revision 30a1de105a5f40d77b344a891c4a68f79e815c43)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation
3  */
4 
5 #include <stdio.h>
6 #include <errno.h>
7 #include <stdint.h>
8 
9 #include <rte_common.h>
10 
11 #include "bpf_impl.h"
12 
13 void
14 rte_bpf_destroy(struct rte_bpf *bpf)
15 {
16 	if (bpf != NULL) {
17 		if (bpf->jit.func != NULL)
18 			munmap(bpf->jit.func, bpf->jit.sz);
19 		munmap(bpf, bpf->sz);
20 	}
21 }
22 
23 int
24 rte_bpf_get_jit(const struct rte_bpf *bpf, struct rte_bpf_jit *jit)
25 {
26 	if (bpf == NULL || jit == NULL)
27 		return -EINVAL;
28 
29 	jit[0] = bpf->jit;
30 	return 0;
31 }
32 
33 int
34 bpf_jit(struct rte_bpf *bpf)
35 {
36 	int32_t rc;
37 
38 #if defined(RTE_ARCH_X86_64)
39 	rc = bpf_jit_x86(bpf);
40 #elif defined(RTE_ARCH_ARM64)
41 	rc = bpf_jit_arm64(bpf);
42 #else
43 	rc = -ENOTSUP;
44 #endif
45 
46 	if (rc != 0)
47 		RTE_BPF_LOG(WARNING, "%s(%p) failed, error code: %d;\n",
48 			__func__, bpf, rc);
49 	return rc;
50 }
51 
52 RTE_LOG_REGISTER_DEFAULT(rte_bpf_logtype, INFO);
53