linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Neal Liu <neal.liu@mediatek.com>
To: Chun-Kuang Hu <chunkuang.hu@kernel.org>
Cc: Neal Liu <neal.liu@mediatek.com>,
	Rob Herring <robh+dt@kernel.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	<devicetree@vger.kernel.org>,
	wsd_upstream <wsd_upstream@mediatek.com>,
	lkml <linux-kernel@vger.kernel.org>,
	"moderated list:ARM/Mediatek SoC support" 
	<linux-mediatek@lists.infradead.org>,
	Linux ARM <linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH v4 2/2] soc: mediatek: add mtk-devapc driver
Date: Fri, 31 Jul 2020 10:47:38 +0800	[thread overview]
Message-ID: <1596163658.3932.20.camel@mtkswgap22> (raw)
In-Reply-To: <CAAOTY_9dqcQdZd5x9ckE67KKh-4d_5gN9MQYDq7b4vGCWwHoDw@mail.gmail.com>

Hi Chun-Kuang,


On Thu, 2020-07-30 at 06:47 +0800, Chun-Kuang Hu wrote:
> Hi, Neal:
> 
> Neal Liu <neal.liu@mediatek.com> 於 2020年7月29日 週三 下午4:29寫道:
> >
> > MediaTek bus fabric provides TrustZone security support and data
> > protection to prevent slaves from being accessed by unexpected
> > masters.
> > The security violation is logged and sent to the processor for
> > further analysis or countermeasures.
> >
> > Any occurrence of security violation would raise an interrupt, and
> > it will be handled by mtk-devapc driver. The violation
> > information is printed in order to find the murderer.
> >
> > Signed-off-by: Neal Liu <neal.liu@mediatek.com>
> 
> [snip]
> 
> > +
> > +static void devapc_vio_info_print(struct mtk_devapc_context *ctx)
> > +{
> > +       struct mtk_devapc_vio_info *vio_info = ctx->vio_info;
> > +
> > +       /* Print violation information */
> > +       if (vio_info->write)
> > +               dev_info(ctx->dev, "Write Violation\n");
> > +       else if (vio_info->read)
> > +               dev_info(ctx->dev, "Read Violation\n");
> > +
> > +       dev_info(ctx->dev, "Vio Addr:0x%x, High:0x%x, Bus ID:0x%x, Dom ID:%x\n",
> > +                vio_info->vio_addr, vio_info->vio_addr_high,
> > +                vio_info->master_id, vio_info->domain_id);
> > +}
> 
> devapc_vio_info_print() is small function and only called by
> devapc_extract_vio_dbg(), so I would like to merge this function into
> devapc_extract_vio_dbg() and you could drop struct mtk_devapc_vio_info
> because its member are all local variable.

This idea is okay for me. I'll update on next patch.
Thanks !

> 
> > +
> > +/*
> > + * devapc_extract_vio_dbg - extract full violation information after doing
> > + *                          shift mechanism.
> > + */
> > +static void devapc_extract_vio_dbg(struct mtk_devapc_context *ctx)
> > +{
> > +       const struct mtk_devapc_vio_dbgs *vio_dbgs;
> > +       struct mtk_devapc_vio_info *vio_info;
> > +       void __iomem *vio_dbg0_reg;
> > +       void __iomem *vio_dbg1_reg;
> > +       u32 dbg0;
> > +
> > +       vio_dbg0_reg = ctx->devapc_pd_base + ctx->offset->vio_dbg0;
> > +       vio_dbg1_reg = ctx->devapc_pd_base + ctx->offset->vio_dbg1;
> > +
> > +       vio_dbgs = ctx->vio_dbgs;
> > +       vio_info = ctx->vio_info;
> > +
> > +       /* Starts to extract violation information */
> > +       dbg0 = readl(vio_dbg0_reg);
> > +       vio_info->vio_addr = readl(vio_dbg1_reg);
> > +
> > +       vio_info->master_id = (dbg0 & vio_dbgs->mstid.mask) >>
> > +                             vio_dbgs->mstid.start;
> > +       vio_info->domain_id = (dbg0 & vio_dbgs->dmnid.mask) >>
> > +                             vio_dbgs->dmnid.start;
> > +       vio_info->write = ((dbg0 & vio_dbgs->vio_w.mask) >>
> > +                           vio_dbgs->vio_w.start) == 1;
> > +       vio_info->read = ((dbg0 & vio_dbgs->vio_r.mask) >>
> > +                         vio_dbgs->vio_r.start) == 1;
> > +       vio_info->vio_addr_high = (dbg0 & vio_dbgs->addr_h.mask) >>
> > +                                 vio_dbgs->addr_h.start;
> > +
> > +       devapc_vio_info_print(ctx);
> > +}
> > +
> 
> [snip]
> 
> > +
> > +/*
> > + * start_devapc - unmask slave's irq to start receiving devapc violation.
> > + */
> > +static void start_devapc(struct mtk_devapc_context *ctx)
> > +{
> > +       u32 vio_idx;
> > +
> > +       for (vio_idx = 0; vio_idx < ctx->vio_idx_num; vio_idx++)
> > +               mask_module_irq(ctx, vio_idx, false);
> 
> Are these bits default true? If they are default false, you need not
> to setup it to false again.

It's default value is true, which is mask.
We try to unmask it to start service.

> 
> > +}
> > +
> 
> [snip]
> 
> > diff --git a/drivers/soc/mediatek/mtk-devapc.h b/drivers/soc/mediatek/mtk-devapc.h
> > new file mode 100644
> > index 0000000..7bd7e66
> > --- /dev/null
> > +++ b/drivers/soc/mediatek/mtk-devapc.h
> > @@ -0,0 +1,54 @@
> > +/* SPDX-License-Identifier: GPL-2.0 */
> > +/*
> > + * Copyright (C) 2020 MediaTek Inc.
> > + */
> > +
> > +#ifndef __MTK_DEVAPC_H__
> > +#define __MTK_DEVAPC_H__
> > +
> > +#define VIO_MOD_TO_REG_IND(m)  ((m) / 32)
> > +#define VIO_MOD_TO_REG_OFF(m)  ((m) % 32)
> > +
> > +struct mtk_devapc_pd_offset {
> > +       u32 vio_mask;
> > +       u32 vio_sta;
> > +       u32 vio_dbg0;
> > +       u32 vio_dbg1;
> > +       u32 apc_con;
> > +       u32 vio_shift_sta;
> > +       u32 vio_shift_sel;
> > +       u32 vio_shift_con;
> > +};
> > +
> > +struct mtk_devapc_vio_dbgs_desc {
> > +       u32 mask;
> > +       u32 start;
> > +};
> > +
> > +struct mtk_devapc_vio_dbgs {
> > +       struct mtk_devapc_vio_dbgs_desc mstid;
> > +       struct mtk_devapc_vio_dbgs_desc dmnid;
> > +       struct mtk_devapc_vio_dbgs_desc vio_w;
> > +       struct mtk_devapc_vio_dbgs_desc vio_r;
> > +       struct mtk_devapc_vio_dbgs_desc addr_h;
> > +};
> > +
> > +struct mtk_devapc_vio_info {
> > +       bool read;
> > +       bool write;
> > +       u32 vio_addr;
> > +       u32 vio_addr_high;
> > +       u32 master_id;
> > +       u32 domain_id;
> > +};
> > +
> > +struct mtk_devapc_context {
> > +       struct device *dev;
> > +       u32 vio_idx_num;
> > +       void __iomem *devapc_pd_base;
> > +       struct mtk_devapc_vio_info *vio_info;
> > +       const struct mtk_devapc_pd_offset *offset;
> > +       const struct mtk_devapc_vio_dbgs *vio_dbgs;
> > +};
> > +
> > +#endif /* __MTK_DEVAPC_H__ */
> 
> Data in this header file is only used in mtk-devapc.c and mtk-devapc.c
> is a small file, so I think it's better to move data in header file
> into .c file to make code simpler.

This idea is okay for me. I'll update on next patch.
Thanks !

> 
> Regards,
> Chun-Kuang.


  reply	other threads:[~2020-07-31  2:47 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-29  8:18 [PATCH v4] Add MediaTek MT6779 devapc driver Neal Liu
2020-07-29  8:18 ` [PATCH v4 1/2] dt-bindings: devapc: add bindings for mtk-devapc Neal Liu
2020-07-29  8:18 ` [PATCH v4 2/2] soc: mediatek: add mtk-devapc driver Neal Liu
2020-07-29 16:38   ` Chun-Kuang Hu
2020-07-31  2:44     ` Neal Liu
2020-07-31 15:03       ` Chun-Kuang Hu
2020-08-03  3:32         ` Neal Liu
2020-08-03 16:13           ` Chun-Kuang Hu
2020-08-04  2:18             ` Neal Liu
2020-08-04 15:27               ` Chun-Kuang Hu
2020-07-29 22:47   ` Chun-Kuang Hu
2020-07-31  2:47     ` Neal Liu [this message]
2020-07-30 16:14   ` Chun-Kuang Hu
2020-07-31  2:52     ` Neal Liu
2020-07-31 15:55       ` Chun-Kuang Hu
2020-08-03  3:41         ` Neal Liu
2020-08-01  0:12   ` Chun-Kuang Hu
2020-08-03  4:01     ` Neal Liu
2020-08-03 16:04       ` Chun-Kuang Hu
2020-08-04  2:08         ` Neal Liu
2020-08-04 15:55           ` Chun-Kuang Hu
2020-08-01 23:50   ` Chun-Kuang Hu
2020-08-03  4:05     ` Neal Liu
2020-08-03 15:38       ` Chun-Kuang Hu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1596163658.3932.20.camel@mtkswgap22 \
    --to=neal.liu@mediatek.com \
    --cc=chunkuang.hu@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=robh+dt@kernel.org \
    --cc=wsd_upstream@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).