summaryrefslogtreecommitdiff
path: root/board/kukui_scp/isp_p1_srv.c
blob: 5c2ae7c2e99103f8b5d93852fc27e42fd1224ba1 (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
82
83
/* Copyright 2018 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "console.h"
#include "dma.h"
#include "hooks.h"
#include "ipi_chip.h"
#include "isp_p1_srv.h"
#include "queue.h"
#include "queue_policies.h"
#include "registers.h"
#include "task.h"
#include "util.h"

#define CPRINTS(format, args...) cprints(CC_IPI, format, ##args)

/* Forwad declaration. */
static struct consumer const event_isp_consumer;
static void event_isp_written(struct consumer const *consumer, size_t count);

static struct queue const event_isp_queue = QUEUE_DIRECT(8,
	struct isp_msg, null_producer, event_isp_consumer);

static struct consumer const event_isp_consumer = {
	.queue = &event_isp_queue,
	.ops = &((struct consumer_ops const) {
		.written = event_isp_written,
	}),
};

/* Stub functions only provided by private overlays. */
#ifndef HAVE_PRIVATE_MT8183
void isp_msg_handler(void *data) {}
#endif

static void event_isp_written(struct consumer const *consumer, size_t count)
{
	task_wake(TASK_ID_ISP_SERVICE);
}

static void isp_ipi_msg_handler(int id, void *data, uint32_t len)
{
	struct isp_msg rsv_msg;

	if (!len)
		return;

	rsv_msg.id = id;
	memcpy(rsv_msg.msg, data, MIN(len, sizeof(rsv_msg.msg)));

	/*
	 * If there is no other IPI handler touch this queue, we don't need to
	 * interrupt_disable() or task_disable_irq().
	 */
	if (!queue_add_unit(&event_isp_queue, &rsv_msg))
		CPRINTS("Could not send isp %d to the queue", id);
}
DECLARE_IPI(IPI_ISP_CMD, isp_ipi_msg_handler, 0);
DECLARE_IPI(IPI_ISP_FRAME, isp_ipi_msg_handler, 0);

/* This function renames from isp_service_entry. */
void isp_service_task(void *u)
{
	struct isp_msg rsv_msg;
	size_t size;

	while (1) {
		/*
		 * Queue unit is added in IPI handler, which is in ISR context.
		 * Disable IRQ to prevent a clobbered queue.
		 */
		ipi_disable_irq(SCP_IRQ_IPC0);
		size = queue_remove_unit(&event_isp_queue, &rsv_msg);
		ipi_enable_irq(SCP_IRQ_IPC0);

		if (!size)
			task_wait_event(-1);
		else
			isp_msg_handler(&rsv_msg);
	}
}