summaryrefstree
path: root/kernel/drivers/misc/tzdev/tz_iwservice.c
blob: b1f1d6bd871e4ed0870caa526927858e574eda70 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
 * Copyright (C) 2012-2017, Samsung Electronics Co., Ltd.
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <linux/errno.h>
#include <linux/mm.h>

#include "tz_hotplug.h"
#include "tz_iwio.h"
#include "tz_kthread_pool.h"
#include "tzdev.h"
#include "tzlog.h"

struct iw_service_channel {
	uint32_t cpu_mask;
	uint32_t user_cpu_mask;
} __attribute__((__packed__));

static struct iw_service_channel *iw_channel;

int tz_iwservice_alloc(void)
{
	struct iw_service_channel *ch;

	ch = tz_iwio_alloc_iw_channel(TZ_IWIO_CONNECT_SERVICE, 1, NULL, NULL, NULL);
	if (!ch)
		return -ENOMEM;

	iw_channel = ch;

	return 0;
}

unsigned long tz_iwservice_get_cpu_mask(void)
{
	if (!iw_channel)
		return 0;

	return (iw_channel->cpu_mask | iw_channel->user_cpu_mask);
}

unsigned long tz_iwservice_get_user_cpu_mask(void)
{
	if (!iw_channel)
		return 0;

	return iw_channel->user_cpu_mask;
}

static void tz_iwservice_notify_swd_cpu_mask_update(void)
{
	cpumask_t new_cpus_mask;
	unsigned long sk_cpu_mask;

	/* Check cores activation */
	sk_cpu_mask = tz_iwservice_get_cpu_mask();
	cpumask_andnot(&new_cpus_mask, to_cpumask(&sk_cpu_mask), cpu_online_mask);

	if (!cpumask_empty(&new_cpus_mask))
		tz_hotplug_notify_swd_cpu_mask_update();

	if (sk_cpu_mask)
		tz_kthread_pool_wake_up_all();
}

void tz_iwservice_handle_swd_request(void)
{
	if (!iw_channel)
		return;

	tz_iwservice_notify_swd_cpu_mask_update();
}