aml.h 42.2 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 12 13
#ifndef AML_H
#define AML_H 1

14
#include <assert.h>
15 16 17 18 19 20 21
#include <inttypes.h>
#include <numa.h>
#include <numaif.h>
#include <pthread.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
22
#include <stdlib.h>
23 24 25
#include <sys/mman.h>
#include <unistd.h>

26
/* Used by mbind */
27 28 29 30
#ifndef PAGE_SIZE
#define PAGE_SIZE 4096
#endif

31 32 33
#include "aml/utils/version.h"
#include "aml/utils/bitmap.h"
#include "aml/utils/vector.h"
34

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
/*******************************************************************************
 * General functions:
 * Initialize internal structures, cleanup everything at the end.
 ******************************************************************************/

/*
 * Initializes the library.
 * "argc": pointer to the main()'s argc argument; contents can get modified.
 * "argv": pointer to the main()'s argv argument; contents can get modified.
 * Returns 0 if successful; an error code otherwise.
 */
int aml_init(int *argc, char **argv[]);
/*
 * Terminates the library.
 * Returns 0 if successful; an error code otherwise.
 */
int aml_finalize(void);
52

53 54 55 56 57 58 59 60
/*******************************************************************************
 * Forward Declarations:
 ******************************************************************************/

struct aml_area;

/*******************************************************************************
 * Arenas:
61 62
 * In-memory allocator implementation. Dispatches actual memory mappings back to
 * areas.
63 64
 ******************************************************************************/

65
/* Arena Flags: access to useful jemalloc flags, with the same values. */
66
/* If passed as a flag to arena's mallocx()/reallocx() routines, the newly
67 68
 * allocated memory will be 0-initialized. */
#define AML_ARENA_FLAG_ZERO ((int)0x40)
69 70
/* As a flag to arena mallocx/reallocx, will align on (1<<a). */
#define AML_ARENA_FLAG_ALIGN(a) ((int)(a))
71 72 73 74 75

/* opaque handle to configuration data */
struct aml_arena_data;

struct aml_arena_ops {
76 77 78 79 80 81 82
	int (*register_arena)(struct aml_arena_data *arena,
			      struct aml_area *area);
	int (*deregister_arena)(struct aml_arena_data *arena);
	void *(*mallocx)(struct aml_arena_data *arena, size_t size, int flags);
	void (*dallocx)(struct aml_arena_data *arena, void *ptr, int flags);
	void *(*reallocx)(struct aml_arena_data *arena, void *ptr, size_t size,
			  int flags);
83 84
};

85
struct aml_arena {
86 87
	struct aml_arena_ops *ops;
	struct aml_arena_data *data;
88 89
};

90 91 92 93 94 95 96
/*
 * Registers a new memory arena with the system.  After this call the arena
 * is ready for use.
 * "arena": an initialized arena structure (see aml_arena_jemalloc_create()).
 * "area": a memory area that will be used as the backing store.
 * Returns 0 if successful; an error code otherwise.
 */
97
int aml_arena_register(struct aml_arena *arena, struct aml_area *area);
98 99 100 101 102 103 104
/*
 * Unregisters a memory arena from the system.  Also purges the contents of
 * the memory, so any buffers allocated from the arena should be considered
 * invalid after this call.
 * "arena": a registered arena structure (see aml_arena_register()).
 * Returns 0 if successful; an error code otherwise.
 */
105
int aml_arena_deregister(struct aml_arena *arena);
106 107 108 109 110 111 112
/*
 * Allocates a new memory buffer from the arena.
 * "arena": a registered arena structure (see aml_arena_register()).
 * "size": the buffer size in bytes; if 0 is passed, NULL will be returned.
 * "flags": see AML_ARENA_FLAG_*.
 * Returns a pointer to the newly allocated memory buffer; NULL if unsuccessful.
 */
113
void *aml_arena_mallocx(struct aml_arena *arena, size_t size, int flags);
114 115 116 117 118 119
/*
 * Releases a memory buffer back to the arena.
 * "arena": a registered arena structure (see aml_arena_register()).
 * "ptr": a pointer to the memory buffer or NULL (resulting in a no-op).
 * "flags": see AML_ARENA_FLAG_* (currently unused).
 */
120
void aml_arena_dallocx(struct aml_arena *arena, void *ptr, int flags);
121 122 123 124 125 126 127 128 129 130
/*
 * Changes the size of a previously allocated memory buffer.
 * "arena": a registered arena structure (see aml_arena_register()).
 * "ptr": a pointer to the memory buffer; if NULL is passed, acts just like
 *        aml_arena_mallocx().
 * "size": the new buffer size in bytes; if 0 is passed, acts just like
 *         aml_arena_dallocx() and returns NULL.
 * "flags": see AML_ARENA_FLAG_*.
 * Returns a pointer to the resized memory buffer; NULL if unsuccessful.
 */
131 132
void *aml_arena_reallocx(struct aml_arena *arena, void *ptr, size_t size,
			 int flags);
133 134 135 136 137 138 139 140 141 142

/*******************************************************************************
 * Jemalloc Arena:
 ******************************************************************************/
extern struct aml_arena_ops aml_arena_jemalloc_ops;

struct aml_arena_jemalloc_data {
	unsigned int uid;
	int flags;
};
143

144 145 146 147 148 149 150 151 152 153 154
#define AML_ARENA_JEMALLOC_DECL(name) \
	struct aml_arena_jemalloc_data __ ##name## _inner_data; \
	struct aml_arena name = { \
		&aml_arena_jemalloc_ops, \
		(struct aml_arena_data *)&__ ## name ## _inner_data, \
	};

#define AML_ARENA_JEMALLOC_ALLOCSIZE \
	(sizeof(struct aml_arena_jemalloc_data) + \
	 sizeof(struct aml_arena))

155 156
/* Arena types passed to jemalloc arena's create()/init()/vinit() routines.  */
/* Standard arena type.  */
157
#define AML_ARENA_JEMALLOC_TYPE_REGULAR 0
158
/* Arena type allocating memory-aligned buffers.  */
159
#define AML_ARENA_JEMALLOC_TYPE_ALIGNED 1
160
/* Arena type identical to an existing arena.  */
161 162
#define AML_ARENA_JEMALLOC_TYPE_GENERIC 2

163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
/*
 * Allocates and initializes a new jemalloc arena.
 * "arena": an address where the pointer to the newly allocated arena structure
 *          will be stored.
 * "type": see AML_ARENA_JEMALLOC_TYPE_*.
 * Variadic arguments:
 * - if AML_ARENA_JEMALLOC_TYPE_REGULAR is passed as "type", no additional
 *   arguments are needed.
 * - if AML_ARENA_JEMALLOC_TYPE_ALIGNED is passed as "type", an alignment
 *   argument of type size_t and value that is a power of 2 must be provided.
 * - if AML_ARENA_JEMALLOC_TYPE_GENERIC is passed as "type", a pointer argument
 *   to type "aml_arena_data" (obtained from the "data" field of an existing
 *   jemalloc arena structure) must be provided.
 * Returns 0 if successful; an error code otherwise.
 */
178
int aml_arena_jemalloc_create(struct aml_arena **arena, int type, ...);
179 180
/*
 * Initializes a jemalloc arena.  This is a varargs-variant of the
181
 * aml_arena_jemalloc_vinit() routine.
182 183 184 185 186
 * "arena": an allocated jemalloc arena structure.
 * "type": see aml_arena_jemalloc_create().
 * Variadic arguments: see aml_arena_jemalloc_create().
 * Returns 0 if successful; an error code otherwise.
 */
187
int aml_arena_jemalloc_init(struct aml_arena *arena, int type, ...);
188 189 190 191 192 193 194
/*
 * Initializes a jemalloc arena.
 * "arena": an allocated jemalloc arena structure.
 * "type": see aml_arena_jemalloc_create().
 * "args": see the variadic arguments of aml_arena_jemalloc_create().
 * Returns 0 if successful; an error code otherwise.
 */
195
int aml_arena_jemalloc_vinit(struct aml_arena *arena, int type, va_list args);
196 197 198 199 200
/*
 * Tears down an initialized jemalloc arena.
 * "arena": an initialized jemalloc arena structure.
 * Returns 0 if successful; an error code otherwise.
 */
201
int aml_arena_jemalloc_destroy(struct aml_arena *arena);
202

203 204
/*******************************************************************************
 * Areas:
205
 * embeds information about a byte-addressable physical memory location as well
206 207
 * as binding policies over it.
 ******************************************************************************/
208

209 210 211 212
/* opaque handle to configuration data */
struct aml_area_data;

struct aml_area_ops {
213 214 215
	void *(*malloc)(struct aml_area_data *area, size_t size);
	void (*free)(struct aml_area_data *area, void *ptr);
	void *(*calloc)(struct aml_area_data *area, size_t num, size_t size);
216
	void *(*memalign)(struct aml_area_data *area, size_t align, size_t size);
217 218 219 220
	void *(*realloc)(struct aml_area_data *area, void *ptr, size_t size);
	void *(*acquire)(struct aml_area_data *area, size_t size);
	void (*release)(struct aml_area_data *area, void *ptr);
	void *(*mmap)(struct aml_area_data *area, void *ptr, size_t size);
Kamil Iskra's avatar
Kamil Iskra committed
221
	int (*available)(const struct aml_area_data *area);
222 223
};

224
struct aml_area {
225 226
	struct aml_area_ops *ops;
	struct aml_area_data *data;
227 228
};

229 230 231 232 233 234 235 236
/*******************************************************************************
 * POSIX Area:
 ******************************************************************************/

extern struct aml_area_ops aml_area_posix_ops;

struct aml_area_posix_data {
};
237

238 239 240 241 242 243 244 245 246 247 248
#define AML_AREA_POSIX_DECL(name) \
	struct aml_area_posix_data __ ##name## _inner_data; \
	struct aml_area name = { \
		&aml_area_posix_ops, \
		(struct aml_area_data *)&__ ## name ## _inner_data, \
	};

#define AML_AREA_POSIX_ALLOCSIZE \
	(sizeof(struct aml_area_posix_data) + \
	 sizeof(struct aml_area))

249 250 251 252 253 254
/*
 * Allocates and initializes a new POSIX memory area.
 * "area": an address where the pointer to the newly allocated area structure
 *         will be stored.
 * Returns 0 if successful; an error code otherwise.
 */
255
int aml_area_posix_create(struct aml_area **area);
256 257 258 259 260
/*
 * Initializes a POSIX memory area.
 * "area": an allocated POSIX memory area structure.
 * Returns 0 if successful; an error code otherwise.
 */
261
int aml_area_posix_vinit(struct aml_area *area);
262 263 264 265 266 267
/*
 * Initializes a POSIX memory area.  This is identical to the
 * aml_area_posix_vinit() routine.
 * "area": an allocated POSIX memory area structure.
 * Returns 0 if successful; an error code otherwise.
 */
268
int aml_area_posix_init(struct aml_area *area);
269 270 271 272 273
/*
 * Tears down an initialized POSIX memory area.
 * "area": an initialized POSIX memory area structure.
 * Returns 0 if successful; an error code otherwise.
 */
274
int aml_area_posix_destroy(struct aml_area *area);
275 276

/*******************************************************************************
277 278 279 280 281 282 283 284 285 286 287
 * Linux Area:
 ******************************************************************************/

extern struct aml_area_ops aml_area_linux_ops;

struct aml_area_linux_manager_data {
	struct aml_arena *pool;
	size_t pool_size;
};

struct aml_area_linux_manager_ops {
Kamil Iskra's avatar
Kamil Iskra committed
288
	struct aml_arena *(*get_arena)(const struct aml_area_linux_manager_data *data);
289 290 291 292
};

extern struct aml_area_linux_manager_ops aml_area_linux_manager_single_ops;

293 294 295 296 297 298 299
/*
 * Initializes a Linux memory area manager.  A manager determines which arena
 * to use for allocations.
 * "data": an allocated Linux manager structure.
 * "arena": an arena to use for future allocations.
 * Returns 0 if successful; an error code otherwise.
 */
300 301
int aml_area_linux_manager_single_init(struct aml_area_linux_manager_data *data,
				       struct aml_arena *arena);
302 303 304 305 306
/*
 * Tears down an initialized Linux memory area manager.
 * "data": an initialized Linux manager structure.
 * Returns 0 if successful; an error code otherwise.
 */
307
int aml_area_linux_manager_single_destroy(struct aml_area_linux_manager_data *data);
308 309

struct aml_area_linux_mbind_data {
310
	struct aml_bitmap nodemask;
311 312 313 314
	int policy;
};

struct aml_area_linux_mbind_ops {
315 316 317 318 319
	int (*pre_bind)(struct aml_area_linux_mbind_data *data);
	int (*post_bind)(struct aml_area_linux_mbind_data *data, void *ptr,
			 size_t size);
};

320 321 322
/*
 * Sets memory policy of a Linux memory area.
 * "data": an initialized Linux memory policy structure.
323
 * "policy", "nodemask": see aml_area_linux_mbind_init().
324 325
 * Returns 0 if successful; an error code otherwise.
 */
326
int aml_area_linux_mbind_setdata(struct aml_area_linux_mbind_data *data,
327
				 int policy, const struct aml_bitmap *nodemask);
328 329 330 331 332 333 334 335
/*
 * Sets current memory policy before memory allocation using the Linux memory
 * area.
 * This variant is used with AML_AREA_LINUX_MBIND_TYPE_REGULAR mbind type (see
 * aml_area_linux_create()) and is basically a no-op.
 * "data": an initialized Linux memory policy structure.
 * Returns 0 if successful; an error code otherwise.
 */
336
int aml_area_linux_mbind_regular_pre_bind(struct aml_area_linux_mbind_data *data);
337 338 339 340 341 342 343 344 345 346
/*
 * Sets current memory policy on a new memory region allocated using the Linux
 * memory area.
 * This variant is used with AML_AREA_LINUX_MBIND_TYPE_REGULAR mbind type (see
 * aml_area_linux_create()).
 * "data": an initialized Linux memory policy structure.
 * "ptr": an address of the newly allocated memory region.
 * "size": the size of the newly allocated memory region.
 * Returns 0 if successful; an error code otherwise.
 */
347 348
int aml_area_linux_mbind_regular_post_bind(struct aml_area_linux_mbind_data *data,
					   void *ptr, size_t size);
349 350 351 352 353 354 355 356
/*
 * Sets current memory policy before memory allocation using the Linux memory
 * area.
 * This variant is used with AML_AREA_LINUX_MBIND_TYPE_MEMPOLICY mbind type (see
 * aml_area_linux_create()).
 * "data": an initialized Linux memory policy structure.
 * Returns 0 if successful; an error code otherwise.
 */
357
int aml_area_linux_mbind_mempolicy_pre_bind(struct aml_area_linux_mbind_data *data);
358 359 360 361 362 363 364 365 366 367
/*
 * Sets current memory policy on a new memory region allocated using the Linux
 * memory area.
 * This variant is used with AML_AREA_LINUX_MBIND_TYPE_MEMPOLICY mbind type (see
 * aml_area_linux_create()).
 * "data": an initialized Linux memory policy structure.
 * "ptr": an address of the newly allocated memory region.
 * "size": the size of the newly allocated memory region.
 * Returns 0 if successful; an error code otherwise.
 */
368 369
int aml_area_linux_mbind_mempolicy_post_bind(struct aml_area_linux_mbind_data *data,
					   void *ptr, size_t size);
370 371 372 373 374 375 376 377 378
/*
 * Initializes memory policy of a Linux memory area.
 * "data": an allocated Linux memory policy structure.
 * "policy": see MPOL_* in mbind(2).
 * "nodemask": an AML_MAX_NUMA_NODES-bit array (a AML_NODEMASK_SZ-element array)
 *             containing the NUMA node mask to use (see mbind(2) for more
 *             information).
 * Returns 0 if successful; an error code otherwise.
 */
379
int aml_area_linux_mbind_init(struct aml_area_linux_mbind_data *data,
380
			      int policy, const struct aml_bitmap *nodemask);
381 382 383 384 385
/*
 * Tears down an initialized Linx memory policy.
 * "data": an initialized Linux memory policy structure.
 * Returns 0 if successful; an error code otherwise.
 */
386
int aml_area_linux_mbind_destroy(struct aml_area_linux_mbind_data *data);
387 388 389 390 391 392 393 394 395 396 397 398

extern struct aml_area_linux_mbind_ops aml_area_linux_mbind_regular_ops;
extern struct aml_area_linux_mbind_ops aml_area_linux_mbind_mempolicy_ops;

struct aml_area_linux_mmap_data {
	int prot;
	int flags;
	int fildes;
	off_t off;
};

struct aml_area_linux_mmap_ops {
399 400
	void *(*mmap)(struct aml_area_linux_mmap_data *data, void *ptr,
		      size_t size);
401 402
};

403 404 405 406 407 408 409 410 411
/*
 * Allocates a memory region from a Linux memory area.
 * "data": an initialized Linux memory map structure.
 * "ptr": an address where the new memory region should be allocated (hint only;
 *        can be NULL to let the kernel decide).
 * "size": the requested size of thew new memory region to allocate.
 * Returns the address of the newly allocated region or MAP_FAILED (see mmap(2))
 * if unsuccessful.
 */
412 413
void *aml_area_linux_mmap_generic(struct aml_area_linux_mmap_data *data,
				  void *ptr, size_t size);
414 415 416 417 418 419 420 421
/*
 * Initializes memory map of a Linux memory area to use an anonymous
 * (0-initialized) mapping.
 * This variant is used with AML_AREA_LINUX_MMAP_TYPE_ANONYMOUS map type (see
 * aml_area_linux_create()).
 * "data": an allocated Linux memory map structure.
 * Returns 0 if successful; an error code otherwise.
 */
422
int aml_area_linux_mmap_anonymous_init(struct aml_area_linux_mmap_data *data);
423 424 425 426 427 428 429 430 431 432
/*
 * Initializes memory map of a Linux memory area to use an existing file
 * mapping.
 * This variant is used with AML_AREA_LINUX_MMAP_TYPE_FD map type (see
 * aml_area_linux_create()).
 * "data": an allocated Linux memory map structure.
 * "fd": an open file descriptor.
 * "offset": the offset within the file to allocate from.
 * Returns 0 if successful; an error code otherwise.
 */
433
int aml_area_linux_mmap_fd_init(struct aml_area_linux_mmap_data *data, int fd,
434
				off_t offset);
435 436 437 438 439 440 441 442 443 444 445 446
/*
 * Initializes memory map of a Linux memory area to use a newly created,
 * temporary file mapping.
 * This variant is used with AML_AREA_LINUX_MMAP_TYPE_TMPFILE map type (see
 * aml_area_linux_create()).
 * "data": an allocated Linux memory map structure.
 * "template": a file name template, ending in "XXXXXX"; the last six characters
 *             will be replaced with the actual name on successful file creation
 *             (see mkstemp(3) for more information).
 * "max": the size of the temporary file to create.
 * Returns 0 if successful; an error code otherwise.
 */
447 448
int aml_area_linux_mmap_tmpfile_init(struct aml_area_linux_mmap_data *data,
				     char *template, size_t max);
449 450 451 452 453 454 455
/*
 * Tears down an initialized Linux memory map.
 * This variant is used with AML_AREA_LINUX_MMAP_TYPE_ANONYMOUS map type (see
 * aml_area_linux_create()).
 * "data": an initialized Linux memory map structure.
 * Returns 0 if successful; an error code otherwise.
 */
456
int aml_area_linux_mmap_anonymous_destroy(struct aml_area_linux_mmap_data *data);
457 458 459 460 461 462 463
/*
 * Tears down an initialized Linux memory map.
 * This variant is used with AML_AREA_LINUX_MMAP_TYPE_FD map type (see
 * aml_area_linux_create()).
 * "data": an initialized Linux memory map structure.
 * Returns 0 if successful; an error code otherwise.
 */
464
int aml_area_linux_mmap_fd_destroy(struct aml_area_linux_mmap_data *data);
465 466 467 468 469 470 471
/*
 * Tears down an initialized Linux memory map.
 * This variant is used with AML_AREA_LINUX_MMAP_TYPE_TMPFILE map type (see
 * aml_area_linux_create()).
 * "data": an initialized Linux memory map structure.
 * Returns 0 if successful; an error code otherwise.
 */
472
int aml_area_linux_mmap_tmpfile_destroy(struct aml_area_linux_mmap_data *data);
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492

extern struct aml_area_linux_mmap_ops aml_area_linux_mmap_generic_ops;

struct aml_area_linux_data {
	struct aml_area_linux_manager_data manager;
	struct aml_area_linux_mbind_data mbind;
	struct aml_area_linux_mmap_data mmap;
};

struct aml_area_linux_ops {
	struct aml_area_linux_manager_ops manager;
	struct aml_area_linux_mbind_ops mbind;
	struct aml_area_linux_mmap_ops mmap;
};

struct aml_area_linux {
	struct aml_area_linux_data data;
	struct aml_area_linux_ops ops;
};

493 494 495 496 497 498 499 500 501 502 503
#define AML_AREA_LINUX_DECL(name) \
	struct aml_area_linux __ ##name## _inner_data; \
	struct aml_area name = { \
		&aml_area_linux_ops, \
		(struct aml_area_data *)&__ ## name ## _inner_data, \
	};

#define AML_AREA_LINUX_ALLOCSIZE \
	(sizeof(struct aml_area_linux) + \
	 sizeof(struct aml_area))

504 505 506
/* Linux memory area manager types, passed to Linux memory area's
   create()/init()/vinit() routines.  */
/* Single-arena manager.  */
507 508
#define AML_AREA_LINUX_MANAGER_TYPE_SINGLE 0

509 510 511
/* Linux memory area mbind types, passed to Linux memory area's
   create()/init()/vinit() routines.  */
/* Regular type using mbind() after mmap().  */
512
#define AML_AREA_LINUX_MBIND_TYPE_REGULAR 0
513 514
/* Calls set_mempolicy() before and after mmap() to change the memory policy
   globally.  */
515 516
#define AML_AREA_LINUX_MBIND_TYPE_MEMPOLICY 1

517 518 519
/* Linux memory area map types, passed to Linux memory area's
   create()/init()/vinit() routines.  */
/* Zero-initialized, anonymous mapping.  */
520
#define AML_AREA_LINUX_MMAP_TYPE_ANONYMOUS 0
521
/* Mapping using an existing file.  */
522
#define AML_AREA_LINUX_MMAP_TYPE_FD 1
523
/* Mapping using a newly created temporary file.  */
524 525
#define AML_AREA_LINUX_MMAP_TYPE_TMPFILE 2

526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
/*
 * Allocates and initializes a new Linux memory area.
 * "area": an address where the pointer to the newly allocated Linux memory area
 *         will be stored.
 * "manager_type": see AML_AREA_LINUX_MANAGER_TYPE_*.
 * "mbind_type": see AML_AREA_LINUX_MBIND_TYPE_*.
 * "mmap_type": see AML_AREA_LINUX_MMAP_TYPE_*.
 * Variadic arguments:
 * - "policy": an argument of type int; see aml_area_linux_mbind_init().
 * - "nodemask": an argument of type const unsigned long*;
 *               see aml_area_linux_mbind_init().
 * - if AML_AREA_LINUX_MMAP_TYPE_ANONYMOUS is passed as "mmap_type", no
 *   additional arguments are needed.
 * - if AML_AREA_LINUX_MMAP_TYPE_FD is passed as "mmap_type", two additional
 *   arguments are needed:
 *   - "fd": an argument of type int; see aml_area_linux_mmap_fd_init().
 *   - "offset": an argument of type off_t; see aml_area_linux_mmap_fd_init().
 * - if AML_AREA_LINUX_MMAP_TYPE_TMPFILE is passed as "mmap_type", two
 *   additional arguments are needed:
 *   - template: an argument of type char*; see
 *     aml_area_linux_mmap_tmpfile_init().
 *   - max: an argument of type size_t; see aml_area_linux_mmap_tmpfile_init().
 * Returns 0 if successful; an error code otherwise.
 */
550 551
int aml_area_linux_create(struct aml_area **area, int manager_type,
			  int mbind_type, int mmap_type, ...);
552 553 554 555 556 557 558 559
/*
 * Initializes a Linux memory area.  This is a varargs-variant of the
 * aml_area_linux_vinit() routine.
 * "area": an allocated Linux memory area structure.
 * "manager_type", "mbind_type", "mmap_type": see aml_area_linux_create().
 * Variadic arguments: see aml_area_linux_create().
 * Returns 0 if successful; an error code otherwise.
 */
560 561
int aml_area_linux_init(struct aml_area *area, int manager_type, int mbind_type,
			int mmap_type, ...);
562 563 564 565 566 567 568
/*
 * Initializes a Linux memory area.
 * "area": an allocated Linux memory area structure.
 * "manager_type", "mbind_type", "mmap_type": see aml_area_linux_create().
 * "args": see the variadic arguments of aml_area_linux_create().
 * Returns 0 if successful; an error code otherwise.
 */
569 570
int aml_area_linux_vinit(struct aml_area *area, int manager_type,
			 int mbind_type, int mmap_type, va_list args);
571 572 573 574 575
/*
 * Tears down an initialized Linux memory area.
 * "area": an initialized Linux memory area structure.
 * Returns 0 if successful; an error code otherwise.
 */
576
int aml_area_linux_destroy(struct aml_area *area);
577 578 579 580 581

/*******************************************************************************
 * Generic Area API:
 * Low-level, direct access to area logic.
 * For memory allocation function, follows the POSIX spec.
582
 ******************************************************************************/
583

584 585 586 587 588 589
/*
 * Allocates a new memory buffer from a memory area.
 * "area": an initialized memory area structure.
 * "size": the buffer size in bytes; if 0 is passed, NULL will be returned.
 * Returns a pointer to the newly allocated memory buffer; NULL if unsuccessful.
 */
590
void *aml_area_malloc(struct aml_area *area, size_t size);
591 592 593 594 595
/*
 * Releases a memory buffer back to the memory area.
 * "area": an initialized memory area structure.
 * "ptr": a pointer to the memory buffer or NULL (resulting in a no-op).
 */
596
void aml_area_free(struct aml_area *area, void *ptr);
597 598 599 600 601 602 603 604 605
/*
 * Allocates a new, zero-initialized memory buffer from a memory area.
 * "area": an initialized memory area structure.
 * "num": the number of elements of size "size" to allocate; if 0 is passed,
 *        NULL will be returned
 * "size": the size of each individual element to allocate, in bytes; if 0 is
 *         passed, NULL will be returned.
 * Returns a pointer to the newly allocated memory buffer; NULL if unsuccessful.
 */
606
void *aml_area_calloc(struct aml_area *area, size_t num, size_t size);
607 608 609 610 611 612 613 614
/*
 * Allocates a new, aligned, memory buffer from a memory area.
 * "area": an initialized memory area structure.
 * "align": an alignment for the returned pointer.
 * "size": the buffer size in bytes; if 0 is passed, NULL will be returned.
 * Returns a pointer to the newly allocated memory buffer; NULL if unsuccessful.
 */
void *aml_area_memalign(struct aml_area *area, size_t align, size_t size);
615 616 617 618 619 620 621 622 623
/*
 * Changes the size of a previously allocated memory buffer.
 * "area": an initialized memory area structure.
 * "ptr": a pointer to the memory buffer; if NULL is passed, acts just like
 *        aml_area_malloc().
 * "size": the new buffer size in bytes; if 0 is passed, acts just like
 *         aml_area_free() and returns NULL.
 * Returns a pointer to the resized memory buffer; NULL if unsuccessful.
 */
624
void *aml_area_realloc(struct aml_area *area, void *ptr, size_t size);
625
/* FIXME! */
626
void *aml_area_acquire(struct aml_area *area, size_t size);
627
/* FIXME! */
628
void aml_area_release(struct aml_area *area, void *ptr);
629 630 631 632 633 634 635 636 637 638
/*
 * Allocates a memory region from a Linux memory area, respecting memory policy
 * settings (see aml_area_linux_mbind_init()).
 * "area": an initialized memory area structure.
 * "ptr": an address where the new memory region should be allocated (hint only;
 *        can be NULL to let the kernel decide).
 * "size": the requested size of thew new memory region to allocate.
 * Returns the address of the newly allocated region or MAP_FAILED (see mmap(2))
 * if unsuccessful.
 */
639
void *aml_area_mmap(struct aml_area *area, void *ptr, size_t size);
640
/* FIXME! */
Kamil Iskra's avatar
Kamil Iskra committed
641
int aml_area_available(const struct aml_area *area);
642

643 644 645 646 647 648 649 650 651 652 653 654 655 656 657
/*******************************************************************************
 * Tiling:
 * Representation of a data structure organization in memory.
 ******************************************************************************/

/* opaque handle to all tilings */
struct aml_tiling_data;
struct aml_tiling_iterator_data;

/*forward declarations */
struct aml_tiling_iterator_ops;
struct aml_tiling_iterator;


struct aml_tiling_ops {
658 659 660 661 662 663 664
	int (*create_iterator)(struct aml_tiling_data *tiling,
			       struct aml_tiling_iterator **iterator,
			       int flags);
	int (*init_iterator)(struct aml_tiling_data *tiling,
			     struct aml_tiling_iterator *iterator, int flags);
	int (*destroy_iterator)(struct aml_tiling_data *tiling,
				struct aml_tiling_iterator *iterator);
665
	int (*tileid)(const struct aml_tiling_data *tiling, va_list);
Kamil Iskra's avatar
Kamil Iskra committed
666 667 668
	size_t (*tilesize)(const struct aml_tiling_data *tiling, int tileid);
	void* (*tilestart)(const struct aml_tiling_data *tiling,
			   const void *ptr, int tileid);
669
	int (*ndims)(const struct aml_tiling_data *tiling, va_list);
670 671 672 673 674 675 676
};

struct aml_tiling {
	struct aml_tiling_ops *ops;
	struct aml_tiling_data *data;
};

677 678 679 680 681 682 683 684 685 686 687
/*
 * Provides the tile id of a tile.
 * "tiling": an initialized tiling structure.
 * Variadic arguments:
 *  - a list of size_t coordinates, one per dimension of the tiling.
 * Returns the id of the tile (that is, its order in memory), to use with other
 * functions.
 * Returns -1 in case of invalid coordinates.
 */
int aml_tiling_tileid(const struct aml_tiling *tiling, ...);

688 689 690 691 692 693 694
/*
 * Provides the information on the size of a tile.
 * "tiling": an initialized tiling structure.
 * "tileid": an identifier of a tile (a value between 0 and the number of tiles
 *           minus 1).
 * Returns the size of a tile.
 */
Kamil Iskra's avatar
Kamil Iskra committed
695
size_t aml_tiling_tilesize(const struct aml_tiling *tiling, int tileid);
696

697 698 699 700 701 702 703 704 705 706
/*
 * Provides the information on the location of a tile in memory.
 * "tiling": an initialized tiling structure.
 * "ptr": an address of the start of the complete user data structure that this
 *        tiling describes.
 * "tileid": an identifier of a tile (a value between 0 and the number of tiles
 *           minus 1).
 * Returns the address of the start of the tile identified by "tileid", within
 * the provided user data structure.
 */
Kamil Iskra's avatar
Kamil Iskra committed
707 708
void* aml_tiling_tilestart(const struct aml_tiling *tiling, const void *ptr,
			   int tileid);
709

710 711 712 713 714 715 716 717 718 719
/*
 * Provides the dimensions of the entire tiling in tiles.
 * "tiling": an initialized tiling structure.
 * Variadic arguments:
 *  - a list of (size_t *), one per dimension of the tiling.
 *  Will contain the size of each dimension in tiles upon return.
 * Returns 0 if successful, an error code otherwise.
 */
int aml_tiling_ndims(const struct aml_tiling *tiling, ...);

720 721 722 723 724 725 726 727
/*
 * Allocates and initializes a new tiling iterator.
 * "tiling": an initialized tiling structure.
 * "iterator": an address where the pointer to the newly allocated iterator
 *             structure will be stored.
 * "flags": reserved for future use; pass 0 for now.
 * Returns 0 if successful; an error code otherwise.
 */
728 729 730
int aml_tiling_create_iterator(struct aml_tiling *tiling,
			       struct aml_tiling_iterator **iterator,
			       int flags);
731 732 733 734 735 736 737
/*
 * Initializes a tiling iterator.
 * "tiling": an initialized tiling structure.
 * "iterator": an allocated tiling iterator structure.
 * "flags": reserved for future use; pass 0 for now.
 * Returns 0 if successful; an error code otherwise.
 */
738 739
int aml_tiling_init_iterator(struct aml_tiling *tiling,
			     struct aml_tiling_iterator *iterator, int flags);
740 741 742
/*
 * Tears down an initialized tiling iterator.
 * "tiling": an initialized tiling structure.
743
 * "iterator": an initialized tiling iterator structure.
744 745
 * Returns 0 if successful; an error code otherwise.
 */
746 747
int aml_tiling_destroy_iterator(struct aml_tiling *tiling,
				struct aml_tiling_iterator *iterator);
748 749

struct aml_tiling_iterator_ops {
750 751
	int (*reset)(struct aml_tiling_iterator_data *iterator);
	int (*next)(struct aml_tiling_iterator_data *iterator);
Kamil Iskra's avatar
Kamil Iskra committed
752 753 754
	int (*end)(const struct aml_tiling_iterator_data *iterator);
	int (*get)(const struct aml_tiling_iterator_data *iterator,
		   va_list args);
755 756 757 758 759 760 761
};

struct aml_tiling_iterator {
	struct aml_tiling_iterator_ops *ops;
	struct aml_tiling_iterator_data *data;
};

762 763
/*
 * Resets a tiling iterator to the first tile.
764
 * "iterator": an initialized tiling iterator structure.
765 766
 * Returns 0 if successful; an error code otherwise.
 */
767
int aml_tiling_iterator_reset(struct aml_tiling_iterator *iterator);
768 769
/*
 * Advances a tiling iterator to the next tile.
770
 * "iterator": an initialized tiling iterator structure.
771 772
 * Returns 0 if successful; an error code otherwise.
 */
773
int aml_tiling_iterator_next(struct aml_tiling_iterator *iterator);
774 775
/*
 * Checks whether the iterator is past the last tile.
776
 * "iterator": an initialized tiling iterator structure.
777 778 779
 * Returns 0 if the iterator points at a valid tile; 1 if it's past the last
 * tile.
 */
Kamil Iskra's avatar
Kamil Iskra committed
780
int aml_tiling_iterator_end(const struct aml_tiling_iterator *iterator);
781 782
/*
 * Queries the iterator.
783
 * "iterator": an initialized tiling iterator structure.
784 785 786 787 788
 * Variadic arguments:
 * - "x": an argument of type unsigned long*; on return gets filled with the
 *        identifier of the tile currently pointed to.
 * Returns 0 if successful; an error code otherwise.
 */
Kamil Iskra's avatar
Kamil Iskra committed
789
int aml_tiling_iterator_get(const struct aml_tiling_iterator *iterator, ...);
790

791 792
/* Tiling types passed to the tiling create()/init()/vinit() routines.  */
/* Regular, linear tiling with uniform tile sizes.  */
793
#define AML_TILING_TYPE_1D 0
794 795
#define AML_TILING_TYPE_2D_ROWMAJOR 1
#define AML_TILING_TYPE_2D_COLMAJOR 2
796

797 798 799 800 801 802 803 804 805 806
/*
 * Allocates and initializes a new tiling.
 * "tiling": an address where the pointer to the newly allocated tiling
 *           structure will be stored.
 * "type": see AML_TILING_TYPE_*.
 * Variadic arguments:
 * - if "type" equals AML_TILING_TYPE_1D, two additional arguments are needed:
 *   - "tilesize": an argument of type size_t; provides the size of each tile.
 *   - "totalsize": an argument of type size_t; provides the size of the
 *                  complete user data structure to be tiled.
807 808
 * - if "type" equals AML_TILING_TYPE_2D, four additional arguments are needed:
 *   - "tilesize": an argument of type size_t; provides the size of a tile.
809 810
 *   - "totalsize": an argument of type size_t; provides the size of the
 *                  complete user data structure to be tiled.
811 812
 *   - "rowsize": an argument of type size_t; the number of tiles in a row
 *   - "colsize": an argument of type size_t; the number of tiles in a column
813 814
 * Returns 0 if successful; an error code otherwise.
 */
815
int aml_tiling_create(struct aml_tiling **tiling, int type, ...);
816 817 818 819 820 821 822 823
/*
 * Initializes a tiling.  This is a varargs-variant of the aml_tiling_vinit()
 * routine.
 * "tiling": an allocated tiling structure.
 * "type": see aml_tiling_create().
 * Variadic arguments: see aml_tiling_create().
 * Returns 0 if successful; an error code otherwise.
 */
824
int aml_tiling_init(struct aml_tiling *tiling, int type, ...);
825 826 827 828 829 830 831
/*
 * Initializes a tiling.
 * "tiling": an allocated tiling structure.
 * "type": see aml_tiling_create().
 * "args": see the variadic arguments of aml_tiling_create().
 * Returns 0 if successful; an error code otherwise.
 */
832
int aml_tiling_vinit(struct aml_tiling *tiling, int type, va_list args);
833 834 835 836 837 838
/*
 * Tears down an initialized tiling.
 * "tiling": an initialized tiling structure.
 * "type": see aml_tiling_create().
 * Returns 0 if successful; an error code otherwise.
 */
839
int aml_tiling_destroy(struct aml_tiling *tiling, int type);
840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878

/*******************************************************************************
 * Tiling 1D:
 ******************************************************************************/

extern struct aml_tiling_ops aml_tiling_1d_ops;
extern struct aml_tiling_iterator_ops aml_tiling_iterator_1d_ops;

struct aml_tiling_1d_data {
	size_t blocksize;
	size_t totalsize;
};

struct aml_tiling_iterator_1d_data {
	size_t i;
	struct aml_tiling_1d_data *tiling;
};

#define AML_TILING_1D_DECL(name) \
	struct aml_tiling_1d_data __ ##name## _inner_data; \
	struct aml_tiling name = { \
		&aml_tiling_1d_ops, \
		(struct aml_tiling_data *)&__ ## name ## _inner_data, \
	};

#define AML_TILING_ITERATOR_1D_DECL(name) \
	struct aml_tiling_iterator_1d_data __ ##name## _inner_data; \
	struct aml_tiling_iterator name = { \
		&aml_tiling_iterator_1d_ops, \
		(struct aml_tiling_iterator_data *)&__ ## name ## _inner_data, \
	};

#define AML_TILING_1D_ALLOCSIZE (sizeof(struct aml_tiling_1d_data) + \
				 sizeof(struct aml_tiling))

#define AML_TILING_ITERATOR_1D_ALLOCSIZE \
	(sizeof(struct aml_tiling_iterator_1d_data) + \
	 sizeof(struct aml_tiling_iterator))

879 880
/*******************************************************************************
 * Tiling 2D:
881
 * a contiguous memory area composed of contiguous tiles arranged in 2D grid.
882 883
 ******************************************************************************/

884 885
extern struct aml_tiling_ops aml_tiling_2d_rowmajor_ops;
extern struct aml_tiling_ops aml_tiling_2d_colmajor_ops;
886 887 888 889 890
extern struct aml_tiling_iterator_ops aml_tiling_iterator_2d_ops;

struct aml_tiling_2d_data {
	size_t blocksize;
	size_t totalsize;
891
	size_t ndims[2]; /* # number of rows, # number of cols (in tiles) */
892 893 894 895 896 897 898
};

struct aml_tiling_iterator_2d_data {
	size_t i;
	struct aml_tiling_2d_data *tiling;
};

899 900 901 902 903 904 905 906
#define AML_TILING_2D_ROWMAJOR_DECL(name) \
	struct aml_tiling_2d_data __ ##name## _inner_data; \
	struct aml_tiling name = { \
		&aml_tiling_2d_rowmajor_ops, \
		(struct aml_tiling_data *)&__ ## name ## _inner_data, \
	};

#define AML_TILING_2D_COLMAJOR_DECL(name) \
907 908
	struct aml_tiling_2d_data __ ##name## _inner_data; \
	struct aml_tiling name = { \
909
		&aml_tiling_2d_colmajor_ops, \
910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926
		(struct aml_tiling_data *)&__ ## name ## _inner_data, \
	};

#define AML_TILING_ITERATOR_2D_DECL(name) \
	struct aml_tiling_iterator_2d_data __ ##name## _inner_data; \
	struct aml_tiling_iterator name = { \
		&aml_tiling_iterator_2d_ops, \
		(struct aml_tiling_iterator_data *)&__ ## name ## _inner_data, \
	};

#define AML_TILING_2D_ALLOCSIZE (sizeof(struct aml_tiling_2d_data) + \
				 sizeof(struct aml_tiling))

#define AML_TILING_ITERATOR_2D_ALLOCSIZE \
	(sizeof(struct aml_tiling_iterator_2d_data) + \
	 sizeof(struct aml_tiling_iterator))

927 928 929 930 931
/*******************************************************************************
 * DMA:
 * Management of low-level movement of memory.
 ******************************************************************************/

932 933
/* Internal macros used for tracking DMA request types.  */
/* Invalid request type.  Used for marking inactive requests in the vector.  */
934
#define AML_DMA_REQUEST_TYPE_INVALID -1
935
/* Copy request type.  Uses memcpy() for data migration.  */
936 937
#define AML_DMA_REQUEST_TYPE_COPY 0

938
struct aml_dma_request;
939 940 941
struct aml_dma_data;

struct aml_dma_ops {
942
	int (*create_request)(struct aml_dma_data *dma,
943
			      struct aml_dma_request **req, int type,
944 945 946 947 948
			      va_list args);
	int (*destroy_request)(struct aml_dma_data *dma,
			       struct aml_dma_request *req);
	int (*wait_request)(struct aml_dma_data *dma,
			    struct aml_dma_request *req);
949 950 951 952 953 954 955
};

struct aml_dma {
	struct aml_dma_ops *ops;
	struct aml_dma_data *data;
};

956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971
/*
 * Requests a synchronous data copy between two different tiles, using
 * memcpy() or equivalent.
 * "dma": an initialized DMA structure.
 * Variadic arguments:
 * - "dt": an argument of type struct aml_tiling*; the destination tiling
 *         structure.
 * - "dptr": an argument of type void*; the start address of the complete
 *           destination user data structure.
 * - "dtid": an argument of type int; the destination tile identifier.
 * - "st": an argument of type struct aml_tiling*; the source tiling structure.
 * - "sptr": an argument of type void*; the start address of the complete
 *           source user data structure.
 * - "stid": an argument of type int; the source tile identifier.
 * Returns 0 if successful; an error code otherwise.
 */
972
int aml_dma_copy(struct aml_dma *dma, ...);
973 974 975 976 977 978 979 980 981
/*
 * Requests a data copy between two different tiles.  This is an asynchronous
 * version of aml_dma_copy().
 * "dma": an initialized DMA structure.
 * "req": an address where the pointer to the newly assigned DMA request will be
 *        stored.
 * Variadic arguments: see aml_dma_copy().
 * Returns 0 if successful; an error code otherwise.
 */
982
int aml_dma_async_copy(struct aml_dma *dma, struct aml_dma_request **req, ...);
983 984 985 986 987 988
/*
 * Waits for an asynchronous DMA request to complete.
 * "dma": an initialized DMA structure.
 * "req": a DMA request obtained using aml_dma_async_*() calls.
 * Returns 0 if successful; an error code otherwise.
 */
989
int aml_dma_wait(struct aml_dma *dma, struct aml_dma_request *req);
990 991 992 993 994 995
/*
 * Tears down an asynchronous DMA request before it completes.
 * "dma": an initialized DMA structure.
 * "req": a DMA request obtained using aml_dma_async_*() calls.
 * Returns 0 if successful; an error code otherwise.
 */
996
int aml_dma_cancel(struct aml_dma *dma, struct aml_dma_request *req);
997

998 999
/*******************************************************************************
 * Scratchpad:
1000
 * Use an area to stage data from another area in and out.
1001 1002 1003 1004 1005 1006
 * A dma handles the movement itself.
 ******************************************************************************/

struct aml_scratch_request;
struct aml_scratch_data;

1007 1008
/* Internal macros used for tracking scratchpad request types.  */
/* Invalid request type.  Used for marking inactive requests in the vector.  */
1009
#define AML_SCRATCH_REQUEST_TYPE_INVALID -1
1010
/* Push from the scratchpad to regular memory.  */
1011
#define AML_SCRATCH_REQUEST_TYPE_PUSH 0
1012
/* Pull from regular memory to the scratchpad.  */
1013
#define AML_SCRATCH_REQUEST_TYPE_PULL 1
1014 1015
/* No-op/empty request */
#define AML_SCRATCH_REQUEST_TYPE_NOOP 2
1016 1017 1018 1019 1020 1021 1022 1023 1024

struct aml_scratch_ops {
	int (*create_request)(struct aml_scratch_data *scratch,
			      struct aml_scratch_request **req, int type,
			      va_list args);
	int (*destroy_request)(struct aml_scratch_data *scratch,
			       struct aml_scratch_request *req);
	int (*wait_request)(struct aml_scratch_data *scratch,
			    struct aml_scratch_request *req);
1025
	void *(*baseptr)(const struct aml_scratch_data *scratch);
1026
	int (*release)(struct aml_scratch_data *scratch, int scratchid);
1027 1028 1029 1030 1031 1032 1033
};

struct aml_scratch {
	struct aml_scratch_ops *ops;
	struct aml_scratch_data *data;
};

1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046
/*
 * Requests a synchronous pull from regular memory to the scratchpad.
 * "scratch": an initialized scratchpad structure.
 * Variadic arguments:
 * - "scratchptr": an argument of type void*; the scratchpad base pointer (see
 *                 aml_scratch_baseptr()).
 * - "scratchid": an argument of type int*; gets filled with the scratch tile
 *                identifier where the data will be pulled into.
 * - "srcptr": an argument of type void*; the start address of the complete
 *             source user data structure.
 * - "srcid": an argument of type int; the source tile identifier.
 * Returns 0 if successful; an error code otherwise.
 */
1047
int aml_scratch_pull(struct aml_scratch *scratch, ...);
1048 1049 1050 1051 1052 1053 1054 1055 1056
/*
 * Requests a pull from regular memory to the scratchpad.  This is an
 * asynchronous version of aml_scratch_pull().
 * "scratch": an initialized scratchpad structure.
 * "req": an address where the pointer to the newly assigned scratch request
 *        will be stored.
 * Variadic arguments: see aml_scratch_pull().
 * Returns 0 if successful; an error code otherwise.
 */
1057 1058
int aml_scratch_async_pull(struct aml_scratch *scratch,
			   struct aml_scratch_request **req, ...);
1059 1060 1061 1062
/*
 * Requests a synchronous push from the scratchpad to regular memory.
 * "scratch": an initialized scratchpad structure.
 * Variadic arguments:
1063 1064 1065
 * - "dstptr": an argument of type void*; the start address of the complete
 *             destination user data structure.
 * - "dstid": an argument of type int*; gets filled with the destination tile
1066 1067 1068 1069 1070 1071 1072
 *            identifier where the data will be pushed into (and where it was
 *            pulled from in the first place).
 * - "scratchptr": an argument of type void*; the scratchpad base pointer (see
 *                 aml_scratch_baseptr()).
 * - "scratchid": an argument of type int; the scratchpad tile identifier.
 * Returns 0 if successful; an error code otherwise.
 */
1073
int aml_scratch_push(struct aml_scratch *scratch, ...);
1074 1075 1076 1077 1078 1079 1080 1081 1082
/*
 * Requests a push from the scratchpad to regular memory.  This is an
 * asynchronous version of aml_scratch_push().
 * "scratch": an initialized scratchpad structure.
 * "req": an address where the pointer to the newly assigned scratch request
 *        will be stored.
 * Variadic arguments: see aml_scratch_push().
 * Returns 0 if successful; an error code otherwise.
 */
1083 1084
int aml_scratch_async_push(struct aml_scratch *scratch,
			   struct aml_scratch_request **req, ...);
1085 1086 1087 1088 1089 1090
/*
 * Waits for an asynchronous scratch request to complete.
 * "scratch": an initialized scratchpad structure.
 * "req": a scratch request obtained using aml_scratch_async_*() calls.
 * Returns 0 if successful; an error code otherwise.
 */
1091 1092
int aml_scratch_wait(struct aml_scratch *scratch,
		     struct aml_scratch_request *req);
1093

1094 1095
/*
 * Tears down an asynchronous scratch request before it completes.
1096
 * "scratch": an initialized scratchpad structure.
1097 1098 1099
 * "req": a scratch request obtained using aml_scratch_async_*() calls.
 * Returns 0 if successful; an error code otherwise.
 */
1100 1101
int aml_scratch_cancel(struct aml_scratch *scratch,
		       struct aml_scratch_request *req);
1102 1103
/*
 * Provides the location of the scratchpad.
1104
 * "scratch": an initialized scratchpad structure.
1105 1106
 * Returns a base pointer to the scratchpad memory buffer.
 */
1107
void* aml_scratch_baseptr(const struct aml_scratch *scratch);
1108

1109 1110 1111
/*
 * Release a scratch tile for immediate reuse.
 * "scratch": an initialized scratchpad structure.
1112 1113
 * "scratchid": a scratchpad tile identifier.
 * Returns 0 if successful; an error code otherwise.
1114 1115 1116
 */
int aml_scratch_release(struct aml_scratch *scratch, int scratchid);

1117
#endif