summaryrefslogtreecommitdiff
path: root/sound/soc/intel/catpt/loader.c
blob: 3a7e5b396a86abcc3e25322f10ebae4565a10a3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// SPDX-License-Identifier: GPL-2.0-only
//
// Copyright(c) 2020 Intel Corporation. All rights reserved.
//
// Author: Cezary Rojewski <cezary.rojewski@intel.com>
//

#include <linux/dma-mapping.h>
#include <linux/slab.h>
#include "core.h"

void catpt_sram_init(struct resource *sram, u32 start, u32 size)
{
	sram->start = start;
	sram->end = start + size - 1;
}

void catpt_sram_free(struct resource *sram)
{
	struct resource *res, *save;

	for (res = sram->child; res;) {
		save = res->sibling;
		release_resource(res);
		kfree(res);
		res = save;
	}
}

struct resource *
catpt_request_region(struct resource *root, resource_size_t size)
{
	struct resource *res = root->child;
	resource_size_t addr = root->start;

	for (;;) {
		if (res->start - addr >= size)
			break;
		addr = res->end + 1;
		res = res->sibling;
		if (!res)
			return NULL;
	}

	return __request_region(root, addr, size, NULL, 0);
}