linux-seq.h 3.36 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/*******************************************************************************
 * 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
*******************************************************************************/

#ifndef AML_DMA_LINUX_SEQ_H
#define AML_DMA_LINUX_SEQ_H 1

14
/**
15
 * @defgroup aml_dma_linux_seq "AML Sequential DMA"
16 17
 * @brief Sequential DMA implementation.
 *
18
 * DMA logic implemented based on general linux API, with the caller thread
19 20 21 22
 * used as the only execution thread. This DMA implementation moves between
 * pointers allocated with an aml_area_linux.
 * @{
 **/
23

24 25 26 27
/**
 * Default table of dma request operations for linux
 * sequential dma.
 **/
28 29
extern struct aml_dma_ops aml_dma_linux_seq_ops;

30
/** Inside of a sequential request for linux movement. **/
31
struct aml_dma_request_linux_seq {
32 33 34 35
	/**
	 * The type of dma request
	 * @see <aml.h>
	 **/
36
	int type;
37
	/** The destination pointer of the data movement **/
38
	struct aml_layout *dest;
39
	/** The source pointer of the data movement **/
40
	struct aml_layout *src;
41 42
	/** The operator being used **/
	aml_dma_operator op;
43 44
	/** Argument for operator **/
	void *op_arg;
45 46
};

47
/** Inner data of sequential linux aml_dma implementation **/
48
struct aml_dma_linux_seq_data {
49 50 51 52 53
	/**
	 * Queue of submitted requests.
	 * Requests may be submitted concurrently but will all
	 * be performed by a single thread.
	 **/
54
	struct aml_vector *requests;
55
	/** Lock for queuing requests concurrently **/
56
	pthread_mutex_t lock;
57 58
	/** default operator **/
	aml_dma_operator default_op;
59 60
	/** default op_arg **/
	void *default_op_arg;
61 62
};

63
/** Declaration of available linux sequential dma operations **/
64
struct aml_dma_linux_seq_ops {
65 66 67 68 69
	/**
	 * Perform a sequential copy between source and destination
	 * pointers allocated with an aml_area_linux.
	 * @see aml_area
	 **/
70
	int (*do_copy)(struct aml_dma_linux_seq_data *dma,
71
		       struct aml_dma_request_linux_seq *req);
72 73
};

74 75
/**
 * aml_dma structure for linux based, sequential dma movement.
76
 * Needs to be initialized with aml_dma_linux_seq_create().
77 78
 * Can be passed to generic aml_dma_*() functions.
 **/
79 80 81 82 83
struct aml_dma_linux_seq {
	struct aml_dma_linux_seq_ops ops;
	struct aml_dma_linux_seq_data data;
};

84

85
/**
86
 * Allocates and initializes a new sequential DMA.
87 88 89 90 91
 *
 * @param dma an address where the pointer to the newly allocated DMA structure
 * will be stored.
 * @param nbreqs the initial number of slots for asynchronous requests that are
 * in-flight (will be increased automatically if necessary).
92
 * @param op: default operator
93 94 95
 *
 * @return 0 if successful; an error code otherwise.
 **/
96
int aml_dma_linux_seq_create(struct aml_dma **dma, size_t nbreqs,
97
			     aml_dma_operator op, void *op_arg);
98 99 100 101

/**
 * Tears down a sequential DMA created with aml_dma_linux_seq_create.
 * @param dma the address of a pointer to a sequential dma. Will be NULL after.
102
 */
103
void aml_dma_linux_seq_destroy(struct aml_dma **dma);
104

105 106 107 108 109 110
/**
 * Performs a copy request.
 * @param dma: the dma_linux_seq_data associated with a linux_seq dma.
 * @param req: a valid linux_seq request.
 * @return 0 if successful; an error code otherwise.
 **/
111
int aml_dma_linux_seq_do_copy(struct aml_dma_linux_seq_data *dma,
112
			      struct aml_dma_request_linux_seq *req);
113

114 115 116
/**
 * @}
 **/
117
#endif // AML_DMA_LINUX_SEQ_H