Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp166496pxa; Fri, 31 Jul 2020 08:56:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOMNIby3rzzcZRJ1YgI8Qd406ZBn9Ci0G5Wc+aAqIu1lJECknMOW4FMvheuQagjpiRpEfu X-Received: by 2002:aa7:c885:: with SMTP id p5mr4722594eds.100.1596210990748; Fri, 31 Jul 2020 08:56:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596210990; cv=none; d=google.com; s=arc-20160816; b=XCmvXDADIFqjMO5nSHMyxZvjCbXcP115H+kGJzhmNMJL9Xi0RJCyEHDSNv+goBpQtI 7QqGd4RWDgeoq2IKNQysBTJB1tXC1o8sRLV0kXDZniLHHLNCX2pUvbnDtC6nv+le+XBx 1q6nvYOl1BFoe/idSY3BO99B2e5t9pWfGfv2ume2a5Nsl19rbJyPTQlYVxXrg7tIgUjd A/tNL8+RckIvmdIYO/5prAK03yAShPRO6JEtjIQur22mzfP6fkh3hrc6ok/rjVuAi6bE 7WdwulTf5sNxbECtGCiqvUkGb+27lExZDcGu4AY3ZRVJeegOGc598h8CLzKFGDhzVMIt RLjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=rCStqhQLnwC1M9x6SMw0l6hcxzqqxNwOkdjqA933/b0=; b=OyoQtGvfmMM4vBDGwqAaZU6Xucv2C8F2mSOCg4bmyiB4SJG2mEBwUFgzZY07SCpZct OKtwjjtNPVX7wqku3ETpm/yGaUJjv0tZojeHkz+zyYVsehelHorIuDadhu9avThko2/R 08Okl8y66E+Khb1txaEGzvdTdmhloxG8pKw5SUCYa0XR6MeqO+hNUYBXOjitMbNStIHg AkJTgDZ9c8SGIRVajM4KR3LVVaDtFE2QrT6tIkTeB/Yy1JlNhLAEMjjLGsKtLly8puhJ ypKbvSVF/ZZI4+7mKENjSoj6UG10HeuMUWNsdpshyoidm5HDmIuYRYys5i1iVE473z2c Qy7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dGIUQu1j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t15si5685452ejx.660.2020.07.31.08.56.07; Fri, 31 Jul 2020 08:56:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dGIUQu1j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387504AbgGaPzh (ORCPT + 99 others); Fri, 31 Jul 2020 11:55:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:55830 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726841AbgGaPzh (ORCPT ); Fri, 31 Jul 2020 11:55:37 -0400 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 724DD22B40; Fri, 31 Jul 2020 15:55:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596210936; bh=J9+siusKNMgqbpz/tIFkjD2Z8De5SqX8GkR1C4h8230=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=dGIUQu1jbUUxwH5rNXVUSew0VW7xzb9z6seOM7jOMSR8GUvwf7QuYFyTKi8qefnzh dcfB3/3KbfK0b4Y0V+NZDUf6Kvcrin+hg9mdRhQ/vYzVpaAp3uw0Ww0nO+KcUMKbBo TNm9aew2dfnUY0dckAe9MYp/u3on5mWvf7WNbII8= Received: by mail-ed1-f49.google.com with SMTP id c15so13013092edj.3; Fri, 31 Jul 2020 08:55:36 -0700 (PDT) X-Gm-Message-State: AOAM530+Rr7NBN6+CZlJAY9tIo/IM6gyQwuYBOSAVIbjDCpuq8sETQK6 /3nfzqo7IE7egRpKkPUldq5fqy0XjSL0/UtkqA== X-Received: by 2002:a50:9e6f:: with SMTP id z102mr4608208ede.300.1596210935010; Fri, 31 Jul 2020 08:55:35 -0700 (PDT) MIME-Version: 1.0 References: <1596010690-13178-1-git-send-email-neal.liu@mediatek.com> <1596010690-13178-3-git-send-email-neal.liu@mediatek.com> <1596163970.3932.24.camel@mtkswgap22> In-Reply-To: <1596163970.3932.24.camel@mtkswgap22> From: Chun-Kuang Hu Date: Fri, 31 Jul 2020 23:55:23 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4 2/2] soc: mediatek: add mtk-devapc driver To: Neal Liu Cc: Chun-Kuang Hu , Rob Herring , Matthias Brugger , devicetree@vger.kernel.org, wsd_upstream , lkml , "moderated list:ARM/Mediatek SoC support" , Linux ARM Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Neal: Neal Liu =E6=96=BC 2020=E5=B9=B47=E6=9C=8831=E6=97= =A5 =E9=80=B1=E4=BA=94 =E4=B8=8A=E5=8D=8810:52=E5=AF=AB=E9=81=93=EF=BC=9A > > Hi Chun-Kuang, > > On Fri, 2020-07-31 at 00:14 +0800, Chun-Kuang Hu wrote: > > Hi, Neal: > > > > Neal Liu =E6=96=BC 2020=E5=B9=B47=E6=9C=8829=E6= =97=A5 =E9=80=B1=E4=B8=89 =E4=B8=8B=E5=8D=884:29=E5=AF=AB=E9=81=93=EF=BC=9A > > > > > > 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 > > > --- > > > > [snip] > > > > > + > > > +/* > > > + * 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 =3D ctx->devapc_pd_base + ctx->offset->vio_dbg0; > > > + vio_dbg1_reg =3D ctx->devapc_pd_base + ctx->offset->vio_dbg1; > > > + > > > + vio_dbgs =3D ctx->vio_dbgs; > > > + vio_info =3D ctx->vio_info; > > > + > > > + /* Starts to extract violation information */ > > > + dbg0 =3D readl(vio_dbg0_reg); > > > + vio_info->vio_addr =3D readl(vio_dbg1_reg); > > > + > > > + vio_info->master_id =3D (dbg0 & vio_dbgs->mstid.mask) >> > > > + vio_dbgs->mstid.start; > > > + vio_info->domain_id =3D (dbg0 & vio_dbgs->dmnid.mask) >> > > > + vio_dbgs->dmnid.start; > > > + vio_info->write =3D ((dbg0 & vio_dbgs->vio_w.mask) >> > > > + vio_dbgs->vio_w.start) =3D=3D 1; > > > + vio_info->read =3D ((dbg0 & vio_dbgs->vio_r.mask) >> > > > + vio_dbgs->vio_r.start) =3D=3D 1; > > > + vio_info->vio_addr_high =3D (dbg0 & vio_dbgs->addr_h.mask) >> > > > + vio_dbgs->addr_h.start; > > > > > > I would like to define the type of ctx->vio_info to be > > > > struct mtk_devapc_vio_dbgs { > > u32 mstid:16; > > u32 dmnid:6; > > u32 vio_w:1; > > u32 vio_r:1; > > u32 addr_h:4; > > u32 resv:4; > > }; > > > > so the code would like the simple way > > > > ctx->vio_info =3D (struct mtk_devapc_vio_dbgs)readl(vio_dbg1_reg); > > > > This idea looks great! Is there any possible to pass the bit layout by > DT data, and still make this operation simple? > Why am I asking this question is because this bit layout is platform > dependent. I doubt these info would be in a single 32-bits register for all future SoC. If they are not in single 32-bits register, you may create a vio_dbgs_type in DT data, and the code may be if (ctx->vio_dbgs_type =3D=3D VIO_DBGS_TYPE_MTxxxx) { ctx->vio_info =3D (struct mtk_devapc_vio_dbgs)readl(vio_dbg1_reg); } else if (ctx->vio_dbgs_type =3D=3D VIO_DBGS_TYPE_MTyyyy) { ctx->vio_info->mstid =3D readl(vio_mstid_reg); ctx->vio_info->dmnid =3D readl(vio_dmnid_reg); ctx->vio_info->vio_w =3D readl(vio_vio_w_reg); ctx->vio_info->vio_r =3D readl(vio_vio_r_reg); } I think we need not to consider how the future would be. Once the second SoC driver is upstreaming, we could find out the best solution for it. Regards, Chun-Kuang. > > > Regards, > > Chun-Kuang. > > > > > + > > > + devapc_vio_info_print(ctx); > > > +} > > > + >