summaryrefstree
path: root/kernel/drivers/misc/mcu_ipc/mcu_ipc.h
blob: 08ddbe6f40a61029849c712ca3ac6493da8af10d (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
 * Copyright (C) 2014 Samsung Electronics Co.Ltd
 * http://www.samsung.com
 *
 * MCU IPC driver
 *
 * This program is free software; you can redistribute  it and/or modify it
 * under  the terms of  the GNU General  Public License as published by the
 * Free Software Foundation;  either version 2 of the  License, or (at your
 * option) any later version.
*/

#ifndef MCU_IPC_H
#define MCU_IPC_H

/* FIXME: will be removed */
/* Shared register with 64 * 32 words */
#define MAX_MBOX_NUM	64

enum mcu_ipc_region {
	MCU_CP,
	MCU_GNSS,
	MCU_MAX,
};

struct mcu_ipc_ipc_handler {
	void *data;
	void (*handler)(void *);
};

struct mcu_ipc_drv_data {
	char *name;
	u32 id;

	void __iomem *ioaddr;
	u32 registered_irq;
	unsigned long unmasked_irq;

	/**
	 * irq affinity cpu mask
	 */
	cpumask_var_t dmask;	/* default cpu mask */
	cpumask_var_t imask;	/* irq affinity cpu mask */

	struct device *mcu_ipc_dev;
	struct mcu_ipc_ipc_handler hd[16];
	spinlock_t lock;
	spinlock_t reg_lock;

};

static struct mcu_ipc_drv_data mcu_dat[MCU_MAX];

static inline void mcu_ipc_writel(enum mcu_ipc_region id, u32 val, long reg)
{
	writel(val, mcu_dat[id].ioaddr + reg);
}

static inline u32 mcu_ipc_readl(enum mcu_ipc_region id, long reg)
{
	return readl(mcu_dat[id].ioaddr + reg);
}

#ifdef CONFIG_ARGOS
/* kernel team needs to provide argos header file. !!!
 * As of now, there's nothing to use. */
#ifdef CONFIG_SCHED_HMP
extern struct cpumask hmp_slow_cpu_mask;
extern struct cpumask hmp_fast_cpu_mask;

static inline struct cpumask *get_default_cpu_mask(void)
{
	return &hmp_slow_cpu_mask;
}
#else
static inline struct cpumask *get_default_cpu_mask(void)
{
	return cpu_all_mask;
}
#endif

struct mcu_argos_info {
	int irq;
	u32 affinity;
};

int argos_irq_affinity_setup_label(unsigned int irq, const char *label,
		struct cpumask *affinity_cpu_mask,
		struct cpumask *default_cpu_mask);
int argos_task_affinity_setup_label(struct task_struct *p, const char *label,
		struct cpumask *affinity_cpu_mask,
		struct cpumask *default_cpu_mask);
#endif

#define mcu_dt_read_enum(np, prop, dest) \
	do { \
		u32 val; \
		if (of_property_read_u32(np, prop, &val)) \
			return -EINVAL; \
		dest = (__typeof__(dest))(val); \
	} while (0)

#define mcu_dt_read_bool(np, prop, dest) \
	do { \
		u32 val; \
		if (of_property_read_u32(np, prop, &val)) \
			return -EINVAL; \
		dest = val ? true : false; \
	} while (0)

#define mcu_dt_read_string(np, prop, dest) \
	do { \
		if (of_property_read_string(np, prop, \
				(const char **)&dest)) \
			return -EINVAL; \
	} while (0)

#define mcu_dt_read_u32(np, prop, dest) \
	do { \
		u32 val; \
		if (of_property_read_u32(np, prop, &val)) \
			return -EINVAL; \
		dest = val; \
	} while (0)
#endif