2019-01-18 23:06:48 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Linaro Limited
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2020-03-25 21:41:26 +08:00
|
|
|
#define DT_DRV_COMPAT arm_mhu
|
|
|
|
|
2019-01-18 23:06:48 +08:00
|
|
|
#include <errno.h>
|
|
|
|
#include <device.h>
|
|
|
|
#include <soc.h>
|
|
|
|
#include "ipm_mhu.h"
|
|
|
|
|
|
|
|
#define DEV_CFG(dev) \
|
2020-05-29 02:44:16 +08:00
|
|
|
((const struct ipm_mhu_device_config * const)(dev)->config)
|
2019-01-18 23:06:48 +08:00
|
|
|
#define DEV_DATA(dev) \
|
2020-05-29 03:23:02 +08:00
|
|
|
((struct ipm_mhu_data *)(dev)->data)
|
2019-01-18 23:06:48 +08:00
|
|
|
#define IPM_MHU_REGS(dev) \
|
|
|
|
((volatile struct ipm_mhu_reg_map_t *)(DEV_CFG(dev))->base)
|
|
|
|
|
|
|
|
static enum ipm_mhu_cpu_id_t ipm_mhu_get_cpu_id(const struct device *d)
|
|
|
|
{
|
2020-05-28 00:26:57 +08:00
|
|
|
volatile uint32_t *p_mhu_dev_base;
|
|
|
|
volatile uint32_t *p_cpu_id;
|
2019-01-18 23:06:48 +08:00
|
|
|
|
2020-05-28 00:26:57 +08:00
|
|
|
p_mhu_dev_base = (volatile uint32_t *)IPM_MHU_REGS(d);
|
2019-01-18 23:06:48 +08:00
|
|
|
|
2020-05-28 00:26:57 +08:00
|
|
|
p_cpu_id = (volatile uint32_t *)(((uint32_t)p_mhu_dev_base &
|
2019-01-18 23:06:48 +08:00
|
|
|
SSE_200_DEVICE_BASE_REG_MSK) +
|
|
|
|
SSE_200_CPU_ID_UNIT_OFFSET);
|
|
|
|
|
|
|
|
return (enum ipm_mhu_cpu_id_t)*p_cpu_id;
|
|
|
|
}
|
|
|
|
|
2020-05-28 00:26:57 +08:00
|
|
|
static uint32_t ipm_mhu_get_status(const struct device *d,
|
2019-01-18 23:06:48 +08:00
|
|
|
enum ipm_mhu_cpu_id_t cpu_id,
|
2020-05-28 00:26:57 +08:00
|
|
|
uint32_t *status)
|
2019-01-18 23:06:48 +08:00
|
|
|
{
|
|
|
|
struct ipm_mhu_reg_map_t *p_mhu_dev;
|
|
|
|
|
|
|
|
if (status == NULL) {
|
|
|
|
return IPM_MHU_ERR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
p_mhu_dev = (struct ipm_mhu_reg_map_t *)IPM_MHU_REGS(d);
|
|
|
|
|
|
|
|
switch (cpu_id) {
|
|
|
|
case IPM_MHU_CPU1:
|
|
|
|
*status = p_mhu_dev->cpu1intr_stat;
|
|
|
|
break;
|
|
|
|
case IPM_MHU_CPU0:
|
|
|
|
default:
|
|
|
|
*status = p_mhu_dev->cpu0intr_stat;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return IPM_MHU_ERR_NONE;
|
|
|
|
}
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static int ipm_mhu_send(const struct device *d, int wait, uint32_t cpu_id,
|
2019-01-18 23:06:48 +08:00
|
|
|
const void *data, int size)
|
|
|
|
{
|
|
|
|
ARG_UNUSED(wait);
|
|
|
|
ARG_UNUSED(data);
|
2020-05-28 00:26:57 +08:00
|
|
|
const uint32_t set_val = 0x01;
|
2019-01-18 23:06:48 +08:00
|
|
|
|
|
|
|
struct ipm_mhu_reg_map_t *p_mhu_dev;
|
|
|
|
|
|
|
|
if (cpu_id >= IPM_MHU_CPU_MAX) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size > IPM_MHU_MAX_DATA_SIZE) {
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
p_mhu_dev = (struct ipm_mhu_reg_map_t *)IPM_MHU_REGS(d);
|
|
|
|
|
|
|
|
switch (cpu_id) {
|
|
|
|
case IPM_MHU_CPU1:
|
|
|
|
p_mhu_dev->cpu1intr_set = set_val;
|
|
|
|
break;
|
|
|
|
case IPM_MHU_CPU0:
|
|
|
|
default:
|
|
|
|
p_mhu_dev->cpu0intr_set = set_val;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ipm_mhu_clear_val(const struct device *d,
|
|
|
|
enum ipm_mhu_cpu_id_t cpu_id,
|
2020-05-28 00:26:57 +08:00
|
|
|
uint32_t clear_val)
|
2019-01-18 23:06:48 +08:00
|
|
|
{
|
|
|
|
struct ipm_mhu_reg_map_t *p_mhu_dev;
|
|
|
|
|
|
|
|
p_mhu_dev = (struct ipm_mhu_reg_map_t *)IPM_MHU_REGS(d);
|
|
|
|
|
|
|
|
switch (cpu_id) {
|
|
|
|
case IPM_MHU_CPU1:
|
|
|
|
p_mhu_dev->cpu1intr_clr = clear_val;
|
|
|
|
break;
|
|
|
|
case IPM_MHU_CPU0:
|
|
|
|
default:
|
|
|
|
p_mhu_dev->cpu0intr_clr = clear_val;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static uint32_t ipm_mhu_max_id_val_get(const struct device *d)
|
2019-01-18 23:06:48 +08:00
|
|
|
{
|
|
|
|
ARG_UNUSED(d);
|
|
|
|
|
|
|
|
return IPM_MHU_MAX_ID_VAL;
|
|
|
|
}
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static int ipm_mhu_init(const struct device *d)
|
2019-01-18 23:06:48 +08:00
|
|
|
{
|
|
|
|
const struct ipm_mhu_device_config *config = DEV_CFG(d);
|
|
|
|
|
|
|
|
config->irq_config_func(d);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
isr: Normalize usage of device instance through ISR
The goal of this patch is to replace the 'void *' parameter by 'struct
device *' if they use such variable or just 'const void *' on all
relevant ISRs
This will avoid not-so-nice const qualifier tweaks when device instances
will be constant.
Note that only the ISR passed to IRQ_CONNECT are of interest here.
In order to do so, the script fix_isr.py below is necessary:
from pathlib import Path
import subprocess
import pickle
import mmap
import sys
import re
import os
cocci_template = """
@r_fix_isr_0
@
type ret_type;
identifier P;
identifier D;
@@
-ret_type <!fn!>(void *P)
+ret_type <!fn!>(const struct device *P)
{
...
(
const struct device *D = (const struct device *)P;
|
const struct device *D = P;
)
...
}
@r_fix_isr_1
@
type ret_type;
identifier P;
identifier D;
@@
-ret_type <!fn!>(void *P)
+ret_type <!fn!>(const struct device *P)
{
...
const struct device *D;
...
(
D = (const struct device *)P;
|
D = P;
)
...
}
@r_fix_isr_2
@
type ret_type;
identifier A;
@@
-ret_type <!fn!>(void *A)
+ret_type <!fn!>(const void *A)
{
...
}
@r_fix_isr_3
@
const struct device *D;
@@
-<!fn!>((void *)D);
+<!fn!>(D);
@r_fix_isr_4
@
type ret_type;
identifier D;
identifier P;
@@
-ret_type <!fn!>(const struct device *P)
+ret_type <!fn!>(const struct device *D)
{
...
(
-const struct device *D = (const struct device *)P;
|
-const struct device *D = P;
)
...
}
@r_fix_isr_5
@
type ret_type;
identifier D;
identifier P;
@@
-ret_type <!fn!>(const struct device *P)
+ret_type <!fn!>(const struct device *D)
{
...
-const struct device *D;
...
(
-D = (const struct device *)P;
|
-D = P;
)
...
}
"""
def find_isr(fn):
db = []
data = None
start = 0
try:
with open(fn, 'r+') as f:
data = str(mmap.mmap(f.fileno(), 0).read())
except Exception as e:
return db
while True:
isr = ""
irq = data.find('IRQ_CONNECT', start)
while irq > -1:
p = 1
arg = 1
p_o = data.find('(', irq)
if p_o < 0:
irq = -1
break;
pos = p_o + 1
while p > 0:
if data[pos] == ')':
p -= 1
elif data[pos] == '(':
p += 1
elif data[pos] == ',' and p == 1:
arg += 1
if arg == 3:
isr += data[pos]
pos += 1
isr = isr.strip(',\\n\\t ')
if isr not in db and len(isr) > 0:
db.append(isr)
start = pos
break
if irq < 0:
break
return db
def patch_isr(fn, isr_list):
if len(isr_list) <= 0:
return
for isr in isr_list:
tmplt = cocci_template.replace('<!fn!>', isr)
with open('/tmp/isr_fix.cocci', 'w') as f:
f.write(tmplt)
cmd = ['spatch', '--sp-file', '/tmp/isr_fix.cocci', '--in-place', fn]
subprocess.run(cmd)
def process_files(path):
if path.is_file() and path.suffix in ['.h', '.c']:
p = str(path.parent) + '/' + path.name
isr_list = find_isr(p)
patch_isr(p, isr_list)
elif path.is_dir():
for p in path.iterdir():
process_files(p)
if len(sys.argv) < 2:
print("You need to provide a dir/file path")
sys.exit(1)
process_files(Path(sys.argv[1]))
And is run: ./fix_isr.py <zephyr root directory>
Finally, some files needed manual fixes such.
Fixes #27399
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-06-17 20:58:56 +08:00
|
|
|
static void ipm_mhu_isr(const struct device *d)
|
2019-01-18 23:06:48 +08:00
|
|
|
{
|
|
|
|
struct ipm_mhu_data *driver_data = DEV_DATA(d);
|
|
|
|
enum ipm_mhu_cpu_id_t cpu_id;
|
2020-05-28 00:26:57 +08:00
|
|
|
uint32_t ipm_mhu_status;
|
2019-01-18 23:06:48 +08:00
|
|
|
|
|
|
|
cpu_id = ipm_mhu_get_cpu_id(d);
|
|
|
|
|
|
|
|
ipm_mhu_get_status(d, cpu_id, &ipm_mhu_status);
|
|
|
|
ipm_mhu_clear_val(d, cpu_id, ipm_mhu_status);
|
|
|
|
|
|
|
|
if (driver_data->callback) {
|
2020-07-29 15:14:14 +08:00
|
|
|
driver_data->callback(d, driver_data->user_data, cpu_id,
|
2020-07-09 01:13:49 +08:00
|
|
|
&ipm_mhu_status);
|
2019-01-18 23:06:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static int ipm_mhu_set_enabled(const struct device *d, int enable)
|
2019-01-18 23:06:48 +08:00
|
|
|
{
|
|
|
|
ARG_UNUSED(d);
|
|
|
|
ARG_UNUSED(enable);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static int ipm_mhu_max_data_size_get(const struct device *d)
|
2019-01-18 23:06:48 +08:00
|
|
|
{
|
|
|
|
ARG_UNUSED(d);
|
|
|
|
|
|
|
|
return IPM_MHU_MAX_DATA_SIZE;
|
|
|
|
}
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static void ipm_mhu_register_cb(const struct device *d,
|
2020-07-09 01:13:49 +08:00
|
|
|
ipm_callback_t cb,
|
2020-07-29 15:14:14 +08:00
|
|
|
void *user_data)
|
2019-01-18 23:06:48 +08:00
|
|
|
{
|
|
|
|
struct ipm_mhu_data *driver_data = DEV_DATA(d);
|
|
|
|
|
|
|
|
driver_data->callback = cb;
|
2020-07-29 15:14:14 +08:00
|
|
|
driver_data->user_data = user_data;
|
2019-01-18 23:06:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct ipm_driver_api ipm_mhu_driver_api = {
|
|
|
|
.send = ipm_mhu_send,
|
|
|
|
.register_callback = ipm_mhu_register_cb,
|
|
|
|
.max_data_size_get = ipm_mhu_max_data_size_get,
|
|
|
|
.max_id_val_get = ipm_mhu_max_id_val_get,
|
|
|
|
.set_enabled = ipm_mhu_set_enabled,
|
|
|
|
};
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static void ipm_mhu_irq_config_func_0(const struct device *d);
|
2019-01-18 23:06:48 +08:00
|
|
|
|
|
|
|
static const struct ipm_mhu_device_config ipm_mhu_cfg_0 = {
|
2020-05-28 00:26:57 +08:00
|
|
|
.base = (uint8_t *)DT_INST_REG_ADDR(0),
|
2019-01-18 23:06:48 +08:00
|
|
|
.irq_config_func = ipm_mhu_irq_config_func_0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct ipm_mhu_data ipm_mhu_data_0 = {
|
|
|
|
.callback = NULL,
|
2020-07-29 15:14:14 +08:00
|
|
|
.user_data = NULL,
|
2019-01-18 23:06:48 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
DEVICE_AND_API_INIT(mhu_0,
|
2020-03-25 21:41:26 +08:00
|
|
|
DT_INST_LABEL(0),
|
2019-01-18 23:06:48 +08:00
|
|
|
&ipm_mhu_init,
|
|
|
|
&ipm_mhu_data_0,
|
|
|
|
&ipm_mhu_cfg_0, PRE_KERNEL_1,
|
|
|
|
CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
|
|
|
|
&ipm_mhu_driver_api);
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static void ipm_mhu_irq_config_func_0(const struct device *d)
|
2019-01-18 23:06:48 +08:00
|
|
|
{
|
|
|
|
ARG_UNUSED(d);
|
2020-03-25 21:41:26 +08:00
|
|
|
IRQ_CONNECT(DT_INST_IRQN(0),
|
2020-03-31 20:59:43 +08:00
|
|
|
DT_INST_IRQ(0, priority),
|
2019-01-18 23:06:48 +08:00
|
|
|
ipm_mhu_isr,
|
|
|
|
DEVICE_GET(mhu_0),
|
|
|
|
0);
|
2020-03-25 21:41:26 +08:00
|
|
|
irq_enable(DT_INST_IRQN(0));
|
2019-01-18 23:06:48 +08:00
|
|
|
}
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static void ipm_mhu_irq_config_func_1(const struct device *d);
|
2019-01-18 23:06:48 +08:00
|
|
|
|
|
|
|
static const struct ipm_mhu_device_config ipm_mhu_cfg_1 = {
|
2020-05-28 00:26:57 +08:00
|
|
|
.base = (uint8_t *)DT_INST_REG_ADDR(1),
|
2019-01-18 23:06:48 +08:00
|
|
|
.irq_config_func = ipm_mhu_irq_config_func_1,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct ipm_mhu_data ipm_mhu_data_1 = {
|
|
|
|
.callback = NULL,
|
2020-07-29 15:14:14 +08:00
|
|
|
.user_data = NULL,
|
2019-01-18 23:06:48 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
DEVICE_AND_API_INIT(mhu_1,
|
2020-03-25 21:41:26 +08:00
|
|
|
DT_INST_LABEL(1),
|
2019-01-18 23:06:48 +08:00
|
|
|
&ipm_mhu_init,
|
|
|
|
&ipm_mhu_data_1,
|
|
|
|
&ipm_mhu_cfg_1, PRE_KERNEL_1,
|
|
|
|
CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
|
|
|
|
&ipm_mhu_driver_api);
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static void ipm_mhu_irq_config_func_1(const struct device *d)
|
2019-01-18 23:06:48 +08:00
|
|
|
{
|
|
|
|
ARG_UNUSED(d);
|
2020-03-25 21:41:26 +08:00
|
|
|
IRQ_CONNECT(DT_INST_IRQN(1),
|
|
|
|
DT_INST_IRQ(1, priority),
|
2019-01-18 23:06:48 +08:00
|
|
|
ipm_mhu_isr,
|
|
|
|
DEVICE_GET(mhu_1),
|
|
|
|
0);
|
2020-03-25 21:41:26 +08:00
|
|
|
irq_enable(DT_INST_IRQN(1));
|
2019-01-18 23:06:48 +08:00
|
|
|
}
|