Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2035727ybh; Fri, 17 Jul 2020 07:49:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXHqs712qZf3WmRpGIwARtRQC0p5EAvklNN9oIeVqHdvi09/BwhClvPiYVnGw9oHmRT2Fi X-Received: by 2002:a17:906:d143:: with SMTP id br3mr8717881ejb.268.1594997350497; Fri, 17 Jul 2020 07:49:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594997350; cv=none; d=google.com; s=arc-20160816; b=G7fJY0sUWK/+HfyI47XyHcXnGaw+5jHjZGVVBPUhnFuQH5opbHMCw50wr1zvTY0LQU X/CY0BQEpNZCfVCyNeuQREHePlpG+llvuGj06qJ1al9O1oJy2B0hykeGc500rHzRSqWH BwyblLsf3R+h6jLVlP0RB1ngOcIypHtC2sgBKkkkkP7y5mjDAAkj+GKwG1BfnTz6o7zT WLk7ICuwUKFyL7q4GL4jIEWfiyWo+Sf/OK3U0/Z4FTwG5KM9Fw/ExaUjDY01f6kizqHR dhjNuXPau/+JmnSpxZeDPMR2kuW5WOys47PK9Bu9DJHMXnezBw+AYDLUCzs379utMn+j W3Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=vcLE1wBCwwpCksyJn8rfQ4iJVOtzEv7z1a6nIzPQ7Fg=; b=cxDU9ZOPYnIfKj3CEM0h8+5Vzf+1yCATD3wD2H/2NVjLTsKsnhbfuLFGlXDX1r+Yhm tNZbTkUgVrPUHAU+07S9XJshSXlXDf2F/KM3jidHMyIYpYQTI0EEOsvsGnSomPGlJi79 MpupzXtJ8gnkDSJ5nWiZU2kEKanjPH/+dP/unfSCQORo0enfkXaZqgQrAlQxsMkn9kSP VF9WByiu2tlf3XXTeP1SFhIMmVywfecSATZTQDHp2SBu+WpbQ9InMm7RroKjgTf1PHNZ 3DvNUPATgVJ1of42HtzTZ/RTV9pRr57at726ntq1Kx27xRFceIJUsFWQ7FKNc2r+ZouL VTxg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r3si5431479ejr.664.2020.07.17.07.48.46; Fri, 17 Jul 2020 07:49:10 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726344AbgGQOsa (ORCPT + 99 others); Fri, 17 Jul 2020 10:48:30 -0400 Received: from mout.kundenserver.de ([212.227.126.134]:52801 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726210AbgGQOs3 (ORCPT ); Fri, 17 Jul 2020 10:48:29 -0400 Received: from mail-qt1-f178.google.com ([209.85.160.178]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.129]) with ESMTPSA (Nemesis) id 1MUl4z-1kMbVr2E53-00QkxK for ; Fri, 17 Jul 2020 16:48:26 +0200 Received: by mail-qt1-f178.google.com with SMTP id j10so7769140qtq.11 for ; Fri, 17 Jul 2020 07:48:26 -0700 (PDT) X-Gm-Message-State: AOAM532fMUsm5a4dluc6dFQX+tkYx7ogpU0AE2wgJCtnHPFkCkEXyEAq KHaul4rr4rKBqmx2VaC7a9kTTDhIu/93x2iZFH0= X-Received: by 2002:ac8:2b98:: with SMTP id m24mr10840018qtm.7.1594997305357; Fri, 17 Jul 2020 07:48:25 -0700 (PDT) MIME-Version: 1.0 References: <20200716223627.253936-1-daniel.gutson@eclypsium.com> In-Reply-To: <20200716223627.253936-1-daniel.gutson@eclypsium.com> From: Arnd Bergmann Date: Fri, 17 Jul 2020 16:48:09 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] [PATCH] Firmware security information in SYSFS To: Daniel Gutson Cc: Derek Kiernan , Tudor Ambarus , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Mika Westerberg , Greg Kroah-Hartman , Mauro Carvalho Chehab , "linux-kernel@vger.kernel.org" , Richard Hughes , Alex Bazhaniuk Content-Type: text/plain; charset="UTF-8" X-Provags-ID: V03:K1:Y15CeUDDR3n/zN/hWqhVNMaWLrQLdLhuiw1zysYkWn3grGd2ML8 FAjjCrVufncXDPps1MEOKyVwL6s/4JvGpUXOQmkR+eqfXxUf9zeLNjiau1SMM3KNwft9aaX AnQks19xUZ99sBwMh+Fhk5qgs38yDJ7ugdCICz1bPlizVSX92kMHbCQZMDgiGYuWI6jT9za kwzVeUOvuCjiLqlKQnOkQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:IFi9cgwujf0=:qYENg35n0W82/3fDPzlth3 knCbi8ToGJUsmg3KLbpL+f6sQtWNWOuswQsEtAVjLaCFZaeuvYtGNK43uQMm2LU82hGCtc0Iw OWERsZ6rBHjpAJ1UOOcffzpNm9dSd2IDqp8ImDaN+3NVuNHUi8yHFHuxMERRtJnPMh4wzpSZV Ti9NHWfswUnyj/clnhBsEXgl96VIQruvl98fz6uDV+l16ctureuNfJY3LF6InO7Iv6lPMbM+m 36lhBNWQoGt4Iak63NUW/s2uw/9+lgWiN2nSJBRwYPkL37wlw4ChKnxYn6RAL1zU2klJkXoet MZrCSOnIBHSbuaZxgyeZjUYY4dMcQhTVbWQLUDt3otWaNHXTx9KgdeBJrgSvD7v/CX6cJFGt8 cwJEWtbT96lQKiG/jKDkFIywkZ8jNNxOwyUK9oM8EYu6xoG2Db59HaapmNXEjKgWtMlpRlYTl iSBbnIB1t/EpF+f37VmmVFzX9B6RuUHjKAFEEAc4hGMW3ei305U0GSS4YpnPBgaD/lGktltop 9IMhz0GRNZP5FGbnI6odCCJkvzaCaxFBVVt+JZvNEn4K1bpKz70drLGatlDsz7qSK8DDdkjwd 0Aywe25SRzDAaup2ICpQWismHS99XncztnVTssEUMIgGXuETaTfpTd5Ez7+g6Z3aYmbrh05wX aniIHmQKr9KjltdxikC/rD7MIkAOrOzkZa3kNfitMdYNmvGZlxfrXTQl/KSBerOufyf2D8XaM 4b7VeQs7NwQqJOwo4towFO7QSF8VqNuH2b9ssh7WmthlL79BlqmO24JsVPg0Ic2RV8ux3StpY F9IqkHbai4vfmepTiEZ/+ntbrKu7k6iPUxtgTI1xtpoWhVH6uBASBwd8P+4q1USAQC0Z5B5Or Q5htdXXcWwcv8GUNi14Kp1rJ14l8WYhpQJByldKHAYlDtBEduoG2vwW4TRl385+qJqpvcvvuE otZZid2hAsv89O60jRGvlru5yk0AZ/tEFYU1EoUjPsbOS+sQuEvEB Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 17, 2020 at 12:36 AM Daniel Gutson wrote: > > +static ssize_t internal_callback(struct kobject *kobj, > + struct kobj_attribute *attr, char *buf) > +{ > + struct firmware_security_data *fwsd = > + container_of(attr, struct firmware_security_data, kobj_attr); > + return fwsd->callback(buf, fwsd->private_data); > +} > + > +int register_firmware_security_data_callback( > + const char *name, ssize_t (*callback)(char *buf, void *private_data), > + void *private_data) Why do you have a callback interface here? I would have expected all the data to be static during the kernel run time, so just passing the information here would make it much simpler. > +static ssize_t cnl_read_field(char *buf, struct pci_dev *pdev, u32 mask) > +{ > + u32 bcr; > + > + if (pci_read_config_dword(pdev, BCR, &bcr) != PCIBIOS_SUCCESSFUL) > + return -EIO; > + > + return sprintf(buf, "%d\n", (int)!!(bcr & mask)); > +} > + > +static ssize_t cnl_wpd_firmware_security_callbacks(char *buf, > + void *private_data) > +{ > + return cnl_read_field(buf, (struct pci_dev *)private_data, BCR_WPD); > +} > + > +static ssize_t cnl_ble_firmware_security_callbacks(char *buf, > + void *private_data) > +{ > + return cnl_read_field(buf, (struct pci_dev *)private_data, BCR_BLE); > +} > + > +static ssize_t cnl_smm_bwp_firmware_security_callbacks(char *buf, > + void *private_data) > +{ > + return cnl_read_field(buf, (struct pci_dev *)private_data, BCR_SMM_BWP); > +} > + > +static void register_firmware_security_data_callbacks(struct pci_dev *pdev) > +{ > + register_firmware_security_data_callback( > + "bioswe", &cnl_wpd_firmware_security_callbacks, pdev); > + register_firmware_security_data_callback( > + "ble", &cnl_ble_firmware_security_callbacks, pdev); > + register_firmware_security_data_callback( > + "smm_bwp", &cnl_smm_bwp_firmware_security_callbacks, pdev); > +} All of this should probably become a single function that reads the registers and then passes the contents into whatever common function you have that makes them visible to user space. > @@ -76,7 +119,7 @@ static const struct pci_device_id intel_spi_pci_ids[] = { > { PCI_VDEVICE(INTEL, 0xa224), (unsigned long)&bxt_info }, > { PCI_VDEVICE(INTEL, 0xa324), (unsigned long)&cnl_info }, > { PCI_VDEVICE(INTEL, 0xa3a4), (unsigned long)&bxt_info }, > - { }, > + {}, > }; ... > #include "intel-spi.h" > > @@ -48,17 +49,17 @@ > > #define FADDR 0x08 > #define DLOCK 0x0c > -#define FDATA(n) (0x10 + ((n) * 4)) > +#define FDATA(n) (0x10 + ((n)*4)) > > #define FRACC 0x50 > > -#define FREG(n) (0x54 + ((n) * 4)) > +#define FREG(n) (0x54 + ((n)*4)) > #define FREG_BASE_MASK 0x3fff > #define FREG_LIMIT_SHIFT 16 > #define FREG_LIMIT_MASK (0x03fff << FREG_LIMIT_SHIFT) > Accidental whitespace change, please skip these changes? > @@ -161,7 +164,8 @@ struct intel_spi { > > static bool writeable; > module_param(writeable, bool, 0); > -MODULE_PARM_DESC(writeable, "Enable write access to SPI flash chip (default=0)"); > +MODULE_PARM_DESC(writeable, > + "Enable write access to SPI flash chip (default=0)"); > > static void intel_spi_dump_regs(struct intel_spi *ispi) > { This looks like a useful change, but it should be a separate patch. > @@ -179,8 +183,8 @@ static void intel_spi_dump_regs(struct intel_spi *ispi) > dev_dbg(ispi->dev, "DLOCK=0x%08x\n", readl(ispi->base + DLOCK)); > > for (i = 0; i < 16; i++) > - dev_dbg(ispi->dev, "FDATA(%d)=0x%08x\n", > - i, readl(ispi->base + FDATA(i))); > + dev_dbg(ispi->dev, "FDATA(%d)=0x%08x\n", i, > + readl(ispi->base + FDATA(i))); > > dev_dbg(ispi->dev, "FRACC=0x%08x\n", readl(ispi->base + FRACC)); > > @@ -220,9 +224,8 @@ static void intel_spi_dump_regs(struct intel_spi *ispi) > base = value & PR_BASE_MASK; > > dev_dbg(ispi->dev, " %02d base: 0x%08x limit: 0x%08x [%c%c]\n", > - i, base << 12, (limit << 12) | 0xfff, > - value & PR_WPE ? 'W' : '.', > - value & PR_RPE ? 'R' : '.'); > + i, base << 12, (limit << 12) | 0xfff, > + value & PR_WPE ? 'W' : '.', value & PR_RPE ? 'R' : '.'); > } > > dev_dbg(ispi->dev, "Flash regions:\n"); More whitespace changes. Arnd