1*7ae2c17fSSeongJae Park // SPDX-License-Identifier: GPL-2.0 2*7ae2c17fSSeongJae Park /* 3*7ae2c17fSSeongJae Park * Common Primitives for DAMON Modules 4*7ae2c17fSSeongJae Park * 5*7ae2c17fSSeongJae Park * Author: SeongJae Park <sjpark@amazon.de> 6*7ae2c17fSSeongJae Park */ 7*7ae2c17fSSeongJae Park 8*7ae2c17fSSeongJae Park #include <linux/damon.h> 9*7ae2c17fSSeongJae Park 10*7ae2c17fSSeongJae Park #include "modules-common.h" 11*7ae2c17fSSeongJae Park 12*7ae2c17fSSeongJae Park /* 13*7ae2c17fSSeongJae Park * Allocate, set, and return a DAMON context for the physical address space. 14*7ae2c17fSSeongJae Park * @ctxp: Pointer to save the point to the newly created context 15*7ae2c17fSSeongJae Park * @targetp: Pointer to save the point to the newly created target 16*7ae2c17fSSeongJae Park */ damon_modules_new_paddr_ctx_target(struct damon_ctx ** ctxp,struct damon_target ** targetp)17*7ae2c17fSSeongJae Parkint damon_modules_new_paddr_ctx_target(struct damon_ctx **ctxp, 18*7ae2c17fSSeongJae Park struct damon_target **targetp) 19*7ae2c17fSSeongJae Park { 20*7ae2c17fSSeongJae Park struct damon_ctx *ctx; 21*7ae2c17fSSeongJae Park struct damon_target *target; 22*7ae2c17fSSeongJae Park 23*7ae2c17fSSeongJae Park ctx = damon_new_ctx(); 24*7ae2c17fSSeongJae Park if (!ctx) 25*7ae2c17fSSeongJae Park return -ENOMEM; 26*7ae2c17fSSeongJae Park 27*7ae2c17fSSeongJae Park if (damon_select_ops(ctx, DAMON_OPS_PADDR)) { 28*7ae2c17fSSeongJae Park damon_destroy_ctx(ctx); 29*7ae2c17fSSeongJae Park return -EINVAL; 30*7ae2c17fSSeongJae Park } 31*7ae2c17fSSeongJae Park 32*7ae2c17fSSeongJae Park target = damon_new_target(); 33*7ae2c17fSSeongJae Park if (!target) { 34*7ae2c17fSSeongJae Park damon_destroy_ctx(ctx); 35*7ae2c17fSSeongJae Park return -ENOMEM; 36*7ae2c17fSSeongJae Park } 37*7ae2c17fSSeongJae Park damon_add_target(ctx, target); 38*7ae2c17fSSeongJae Park 39*7ae2c17fSSeongJae Park *ctxp = ctx; 40*7ae2c17fSSeongJae Park *targetp = target; 41*7ae2c17fSSeongJae Park return 0; 42*7ae2c17fSSeongJae Park } 43