Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp582151ybt; Fri, 10 Jul 2020 07:24:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxuBbk8DwNKCgr31Xw/1SftJIqa3bxEcDQtKuNgwqauuJqtgz1uEd7U4c+O7BBKr5tpec8o X-Received: by 2002:a17:906:f1d5:: with SMTP id gx21mr60185908ejb.121.1594391049214; Fri, 10 Jul 2020 07:24:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594391049; cv=none; d=google.com; s=arc-20160816; b=wnmE8nKqtLFWhstggnh4nnfyOKt+eCIbX2UqdyWt5izCk7wBn4KZr+cBCXXQ4cyrL5 YgSuJJWOIZsFPpgx1YE6aBAXwhL14gCN3n06LWL1fwrk19+y+6izOEoU6QvfU9cH24qV HiE7TcagnZDlbDPu3IIscK9CBq/mmNdD0l2RcM0gV4BSTkfIVLvOJMjuHjsFj78kvGmt ZpjP8IrY9H5uxt6LK+NrhtSoS8zqesr39Y97S5PZ+mE45cNUI49ghAeTBUanw8Je7258 FVcqF+aHF9ndDQnpO5RNLj5IXEJZQ1+CLxvt4kaLYWrX5YpVtzqVQ4qnlvtrshOeKuJE uDtg== 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=QQ9fVgBC487/mjsef1V3u3TOGkoVm/dyFWeTnYjjegU=; b=nHFUl+BA2GiMHT/qppHMU5En7fkHU61QYJBlzBfuUHpVs8MmMiDiU5fSMPRTd5OVvi YN8vAje8JwCOhj6qDsnjsMy27cadseaBN5TrfElihrMIAej5HGo9Q2sCk2peT7LirpN1 YebU3j8npbKHBPZ/VtkDwjLoQPhaTwRa5RMAKE7ohtMUmisvLG/87t7rEvoQQC3UdwNX 36WeUrRhsY8hHlRNQpz2dxQogOPPRWKnJv4p1ygPxjuJ1Ck0KI40Qz/CWuQw9PcyAFjg SYAod9+sUWC0pBhbY9D0/fK9uit38LjTa73IizXpBr+X85J+HM1ooVqELKaNqc0uDfgP g2Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UL1+SyxR; 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 q23si4467764edg.348.2020.07.10.07.23.45; Fri, 10 Jul 2020 07:24:09 -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=UL1+SyxR; 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 S1728135AbgGJOVW (ORCPT + 99 others); Fri, 10 Jul 2020 10:21:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:59648 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727107AbgGJOVW (ORCPT ); Fri, 10 Jul 2020 10:21:22 -0400 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (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 487DB206E2; Fri, 10 Jul 2020 14:21:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594390881; bh=vnGCAMdU16YbGd612Tww4xROob47vhq+nuKzE0R1u7U=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=UL1+SyxRjmBzD1Du9SkUt3YtH0lBuwH0PEX9ZDvSM5OoR0zGw89VSy2bQLYGbBR1X wJP1GkU/519jLzUmsp2y99R4E9uTbM9dtnaXzLFM8zTj23nE8ggopTyyqtbeEgtOpb KbvFWnAXw9gyJvVfGu2kM6CwFpPdGvNdjAh3eTp4= Received: by mail-ej1-f45.google.com with SMTP id f12so6241303eja.9; Fri, 10 Jul 2020 07:21:21 -0700 (PDT) X-Gm-Message-State: AOAM533IZmtk410yFR2dvq5sEczy9PwU1VeH0pGT65p9TvYq/I0B05ZT bGEyFERf0OD9tUgm6YS3QIO+YFOLKvMRHdNmlQ== X-Received: by 2002:a17:906:9354:: with SMTP id p20mr13236833ejw.187.1594390879813; Fri, 10 Jul 2020 07:21:19 -0700 (PDT) MIME-Version: 1.0 References: <1594285927-1840-1-git-send-email-neal.liu@mediatek.com> <1594285927-1840-3-git-send-email-neal.liu@mediatek.com> <1594351423.4670.18.camel@mtkswgap22> In-Reply-To: <1594351423.4670.18.camel@mtkswgap22> From: Chun-Kuang Hu Date: Fri, 10 Jul 2020 22:21:08 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 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=8810=E6=97= =A5 =E9=80=B1=E4=BA=94 =E4=B8=8A=E5=8D=8811:23=E5=AF=AB=E9=81=93=EF=BC=9A > > Hi Chun-Kuang, > > Thanks for your review. > > On Thu, 2020-07-09 at 21:01 +0800, Chun-Kuang Hu wrote: > > Hi, Neal: > > > > Neal Liu =E6=96=BC 2020=E5=B9=B47=E6=9C=889=E6= =97=A5 =E9=80=B1=E5=9B=9B =E4=B8=8B=E5=8D=885:13=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] > > > > > + > > > +static u32 get_shift_group(struct mtk_devapc_context *devapc_ctx, > > > + int slave_type, int vio_idx) > > > > vio_idx is useless, so remove it. > > > > yes, my mistake. I'll remove it on next patch. > > > > +{ > > > + u32 vio_shift_sta; > > > + void __iomem *reg; > > > + int bit; > > > + > > > + reg =3D mtk_devapc_pd_get(devapc_ctx, slave_type, VIO_SHIFT_S= TA, 0); > > > + vio_shift_sta =3D readl(reg); > > > + > > > + for (bit =3D 0; bit < 32; bit++) { > > > + if ((vio_shift_sta >> bit) & 0x1) > > > + break; > > > + } > > > + > > > + return bit; > > > +} > > > + > > > > [snip] > > > > > + > > > +/* > > > + * devapc_violation_irq - the devapc Interrupt Service Routine (ISR)= will dump > > > + * violation information including which maste= r violates > > > + * access slave. > > > + */ > > > +static irqreturn_t devapc_violation_irq(int irq_number, > > > + struct mtk_devapc_context *de= vapc_ctx) > > > +{ > > > + const struct mtk_device_info **device_info; > > > + int slave_type_num; > > > + int vio_idx =3D -1; > > > + int slave_type; > > > + > > > + slave_type_num =3D devapc_ctx->slave_type_num; > > > + device_info =3D devapc_ctx->device_info; > > > + > > > + for (slave_type =3D 0; slave_type < slave_type_num; slave_typ= e++) { > > > > If slave_type_num is 1, I think the code should be simpler. > > slave_type_num is depends on DT data, it's not always 1. Please change commit title to "add mt6779 mtk-devapc driver". This patch is just for mt6779. If slave_type_num =3D 1 in mt6779, there is only one slave and we don't need a slave_type variable. Add slave_type_num in the patch of adding one SoC which has multiple slaves. > > > > > > + if (!mtk_devapc_dump_vio_dbg(devapc_ctx, slave_type, = &vio_idx)) > > > + continue; > > > + > > > + /* Ensure that violation info are written before > > > + * further operations > > > + */ > > > + smp_mb(); > > > + > > > + mask_module_irq(devapc_ctx, slave_type, vio_idx, true= ); > > > > Why do you mask irq? > > It has to mask slave's irq before clear violation status. > It's one of hardware design. If don't do this before clear_vio_status, what would happen? The clear would fail? > > > > > > + > > > + clear_vio_status(devapc_ctx, slave_type, vio_idx); > > > + > > > + mask_module_irq(devapc_ctx, slave_type, vio_idx, fals= e); > > > + } > > > + > > > + return IRQ_HANDLED; > > > +} > > > + > > > +/* > > > + * start_devapc - initialize devapc status and start receiving inter= rupt > > > + * while devapc violation is triggered. > > > + */ > > > > [snip] > > > > > + > > > +struct mtk_device_info { > > > + int sys_index; > > > > Useless, so remove it. > > We need to print it as our debug information. > But I did not apply it on this patch, I'll add it on next patch. I think vio address is enough to find out the murder, so remove it in this patch. If it provide another information, add it in another patch and describe clear about what is this and how to use this information. > > > > > > + int ctrl_index; > > > > Ditto. > > > > Regards, > > Chun-Kuang. > > > > > + int vio_index; > > > +}; > > > + >