scratch.c 3.21 KB
Newer Older
Swann Perarnau's avatar
Swann Perarnau committed
1 2 3 4 5 6 7 8 9 10
/*******************************************************************************
 * Copyright 2019 UChicago Argonne, LLC.
 * (c.f. AUTHORS, LICENSE)
 *
 * This file is part of the AML project.
 * For more info, see https://xgitlab.cels.anl.gov/argo/aml
 *
 * SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/

11
#include "aml.h"
12 13 14 15 16 17 18 19 20 21 22
#include <assert.h>

/*******************************************************************************
 * Generic Scratchpad API:
 * Most of the stuff is dispatched to a different layer, using type-specific
 * functions.
 *
 * As for DMA, the API is slightly different than the functions below, as we
 * abstract the request creation after this layer.
 ******************************************************************************/

23 24 25
int aml_scratch_pull(struct aml_scratch *scratch,
		     struct aml_layout **dest, int *scratchid,
		     struct aml_layout *src, int srcid)
26 27
{
	struct aml_scratch_request *req;
28
	int ret;
29

30 31 32 33
	if (scratch == NULL || dest == NULL || scratchid == NULL
	    || src == NULL)
		return -AML_EINVAL;
	
34
	ret = scratch->ops->create_request(scratch->data, &req,
35 36 37 38 39 40
					   AML_SCRATCH_REQUEST_TYPE_PULL,
					   dest, scratchid, src, srcid);
	if (ret)
		return ret;

	return scratch->ops->wait_request(scratch->data, req);
41 42 43
}

int aml_scratch_async_pull(struct aml_scratch *scratch,
44 45 46
			   struct aml_scratch_request **req,
			   struct aml_layout **dest, int *scratchid,
			   struct aml_layout *src, int srcid)
47
{
48 49 50
	if (scratch == NULL || dest == NULL || scratchid == NULL
	    || src == NULL)
		return -AML_EINVAL;
51

52 53 54
	return scratch->ops->create_request(scratch->data, req,
					    AML_SCRATCH_REQUEST_TYPE_PULL,
					    dest, scratchid, src, srcid);
55 56
}

57 58 59
int aml_scratch_push(struct aml_scratch *scratch,
		     struct aml_layout **dest, int *destid,
		     struct aml_layout *src, int srcid)
60 61 62
{
	struct aml_scratch_request *req;
	int ret;
63

64 65 66 67
	if (scratch == NULL || dest == NULL || destid == NULL
	    || src == NULL)
		return -AML_EINVAL;

68
	ret = scratch->ops->create_request(scratch->data, &req,
69 70 71 72 73 74
					   AML_SCRATCH_REQUEST_TYPE_PUSH,
					   dest, destid, src, srcid);
	if (ret)
		return ret;

	return scratch->ops->wait_request(scratch->data, req);
75 76 77
}


78
int aml_scratch_async_push(struct aml_scratch *scratch,
79 80 81
			   struct aml_scratch_request **req,
			   struct aml_layout **dest, int *destid,
			   struct aml_layout *src, int srcid)
82
{
83 84 85
	if (scratch == NULL || dest == NULL || destid == NULL
	    || src == NULL)
		return -AML_EINVAL;
86

87 88 89
	return scratch->ops->create_request(scratch->data, req,
					    AML_SCRATCH_REQUEST_TYPE_PUSH,
					    dest, destid, src, srcid);
90 91
}

92 93
int aml_scratch_cancel(struct aml_scratch *scratch,
		       struct aml_scratch_request *req)
94
{
95 96
	if (scratch == NULL || req == NULL)
		return -AML_EINVAL;
97 98 99
	return scratch->ops->destroy_request(scratch->data, req);
}

100 101
int aml_scratch_wait(struct aml_scratch *scratch,
		     struct aml_scratch_request *req)
102
{
103 104
	if (scratch == NULL || req == NULL)
		return -AML_EINVAL;
105 106
	return scratch->ops->wait_request(scratch->data, req);
}
107

108 109
int aml_scratch_release(struct aml_scratch *scratch, int scratchid)
{
110 111
	if (scratch == NULL)
		return -AML_EINVAL;
112 113
	return scratch->ops->release(scratch->data, scratchid);
}