Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp73619ybt; Tue, 30 Jun 2020 15:07:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKb9AVGqAGyyc3l0rCmzD1BYNRDOa59B224dI3YdfYYItM1F6RKxLeaGYY9OwE0tpfAIb6 X-Received: by 2002:a50:e8c9:: with SMTP id l9mr18314288edn.272.1593554423930; Tue, 30 Jun 2020 15:00:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593554423; cv=none; d=google.com; s=arc-20160816; b=yhPOkMB/pTaSLg7ECCVzrfBATJfrkVFeX0uLRgZ+x9yvK5lIlI+0uk/aiGwNAd8DZq /H6DoVxCXHLydJfUu7R/pjdD+hlb8yhSTP2pqCqnAueNXqFemoHhDhdEDo5Szvb+aI+g ToUfs/yzVqGA2lpNUxmBiehPOnmXL6ETMpgGmAbameKfM3HkU3rJcarFcHVdBiK0Z/Rq xcm0WevHU8RGVXEBtSDxYle1Fv0KoNcLx8cz8H7W4IHU6Hc2fP4Fk9h+mx9UFLrLR8/r ixrT4s1jE+3xfC02ApfcoGKcSO1fPMSajCOvK4V/7ZQUbe6JWs7kg3iu9xlA3PXqQHhT xlhg== 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=KgslP+iX/8ALA+yNUc2vyDrWCCZwPk9m7ONf29++UK8=; b=bLSRY+KcykPoUKzIJDxmeRHc+UDpnmU7AzJE0he3ds5JlVCtaUqpDw1BobfO8e0maE NoXGLh6cHWf6tj9ZgIpGibb6onwjNlEKCehL/Y6zZ/JAVypIZBarx3entCRCsjs4Ln7C q3O0sGMO4NIyi9kbMJ8TEuFzxko1P32/JXZqf3/JRUhdwtjliAGQCACKbGEnSNFlPBBk CqrKkipvoqPRWUFluziA6xLk/95iHkV3fsJQQgVWeg5+pnivyqZ194w5/T4kJwtPDPhL yfM4IaV2AngbGRxz6jThtTCHSR0m4muvNu+9R3L50QxdYr8BpJ9ergK2Z3I0QNB9OPFK KsSA== 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 mm15si2289300ejb.561.2020.06.30.14.59.54; Tue, 30 Jun 2020 15:00:23 -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 S1726699AbgF3U6U (ORCPT + 99 others); Tue, 30 Jun 2020 16:58:20 -0400 Received: from mout.kundenserver.de ([212.227.126.133]:50413 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726392AbgF3U6T (ORCPT ); Tue, 30 Jun 2020 16:58:19 -0400 Received: from mail-lf1-f41.google.com ([209.85.167.41]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.129]) with ESMTPSA (Nemesis) id 1N49xZ-1iqOsL3Upd-0106Tf for ; Tue, 30 Jun 2020 22:58:16 +0200 Received: by mail-lf1-f41.google.com with SMTP id u25so12249884lfm.1 for ; Tue, 30 Jun 2020 13:58:16 -0700 (PDT) X-Gm-Message-State: AOAM533cd0cnHOcf34k50qmPJjdIavBkXzY6BvmWVv2+Doe03YCwGqka z2hvWMquqbKvXDBZvhmBRruKpCBwAqxdhglIfDc= X-Received: by 2002:a19:ca48:: with SMTP id h8mr12970399lfj.161.1593550696202; Tue, 30 Jun 2020 13:58:16 -0700 (PDT) MIME-Version: 1.0 References: <20200629225932.5036-1-daniel.gutson@eclypsium.com> In-Reply-To: From: Arnd Bergmann Date: Tue, 30 Jun 2020 22:57:59 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] SPI LPC information kernel module To: Daniel Gutson Cc: Derek Kiernan , 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:nrsMriwznsm44FAhieNgecKX4Bh0Daeo89xvPyHRsDokUcblcnB gUtURX+snIroJ7if7AKDMnQSNp7QueBhXiEMrQRX6u/ZIzwmbV697cIpVTecIT8mHONa+R3 APSVxzmQIlbMaLvROdzVbLoRBm8q4W2RY8oorUm7yn8P15T3pUhTufDmO9xz0u3I2Bd/FW3 bs9F3T93C2KHLMAqD2OVQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:JcuE5QM5PZA=:wvrNAqCvaJIc1/HiUVo2Yh Oxb+LM82Ed/fICvka8+l1FgG242Sv16lyc7mpMYXhLPRqAG4DJieZgbrHgSF+LP5rPGb5Ew0C bKxiw+D816d59XS8YAUmyIFNN0PLzUUoHHbbVRd4e0/S8QWrJ2fLgZO37Dg5kY//SwecQ1VBF jTSBUS/2mZV+abl/AZFLrOi27oiVfRCL09CZntHaQ+qMHDOFBzi7nIUKt0MBOr42dkxM4DskH fuDJtwV9KiNRqOKJnEAbfeWy21jb8xmUv9B96Y6HeVts55rb0PChTcKivuj0Z8FpHKvj1a8C0 2IAFmc3a4xCrCy/goGAIfV5kw9IJuIdVRytPh/8SlzOE+BMEVXn3HvQj/TESAn6s+0ajv5Pb+ yf/1YU/qB1yhD9xmeb5ChegjXF7LF8a1cx8NTdVNemApSWlhoNQQQhy5lC0qPKKH9cxi6T/kA qkB2ZlvNhQI1nkOkEdfXp2JLbEFGAU9KpF6jLgHRk/aOv9gWfcnIEE54kbAXhJUINN7+kQpso eBSBJSy7jygZNPH0UFB0DWAJ28zmdfFtb5ZKNBsDQZ6fAhS7172ZTxHFE9zIjt00z1mwNIcx3 /4dVRtFuQADuXK4wBD8Xwd33RmVcexK9OHdldrwwTzlRr8BPDextLt3KblqbiUa6j+8y2SzB8 mXhTfug241X73J5GyVGH5LSWNJyeHqlDSxg7Bjrw3NhvMf8iye3zKENosAjTL8CDumdLvjeOS f58LH88XRBfyb506uCeVBG3mX9iE07BTPKfP/bv9r2p8p2Lw2jZtz+TV05d2QOCFv3LdWKg8N ipOJuqTgx47nYuEmefm7GsQidUJWHiY6N4RsTvjb5AVayZfR/s= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 30, 2020 at 9:08 PM Daniel Gutson wrote: > On Tue, Jun 30, 2020 at 5:58 AM Arnd Bergmann wrote: >> On Tue, Jun 30, 2020 at 12:59 AM Daniel Gutson wrote: >> The description should start with a little more background for those that >> don't already know what this driver is for. What is a "system SPI chip"? >> Is this an SPI host connected over LPC, or an LPC bus connected over >> SPI? Is there a particular spec that this follows? > > > "System SPI chip" refers to the main system firmware, which is accessed through an SPI interface. > AFAIK there's no spec for this, though it's a de-facto standard applying to the earliest days of legacy BIOS. > This driver provides visibility to the system firmware configuration access. Oh, so it isn't even the SPI controller, just a flash chip hanging off a random SPI controller, or possibly something else. I suppose it could be any MFD device, or possibly something different. >> > +int spi_read_sbase(enum PCH_Arch pch_arch __maybe_unused, >> > + enum CPU_Arch cpu_arch, struct spi_sbase *reg) >> > +{ >> > + int ret = 0; >> > + >> > + reg->register_arch.source = RegSource_CPU; >> > + reg->register_arch.cpu_arch = cpu_arch; >> > + >> > + switch (cpu_arch) { >> > + case cpu_avn: >> > + case cpu_byt: >> > + ret = read_sbase_atom_avn_byt(®->cpu_byt); >> > + break; >> > + default: >> > + ret = -EIO; >> > + } >> > + return ret; >> > +} >> > +EXPORT_SYMBOL_GPL(spi_read_sbase); >> >> This function seems to be Intel Atom specific but has a rather generic >> name for an exported symbol. > > > It 'currently' is atom specific, but as I mentioned in the mail, the idea was > to submit an initial patch with some attributes. The more platforms and fields > I need, this switch will get more and more populated. This is about reading the > SBASE register, which in my current state, is only used for Atom. I can submit > a driver with more fields where these switches get more populated, but I > thought it would be easier starting with three fields only. > > Anyways I'll give up on the exports for now until a kernel module shows up needing the reading layer. The problem is more the namespace: as the driver has almost nothing to do with spi, this is not what the function should be named. The other problem is that the function should not really exist in the first place, as no driver has any business reading the register base of a random other device that already has a driver. >> > +enum CPU_Arch { >> > + cpu_none, >> > + cpu_bdw, >> > + cpu_bdx, >> > + cpu_hsw, >> > + cpu_hsx, >> > + cpu_ivt, >> > + cpu_jkt, >> >> You might want to avoid having a central instance listing all possible >> CPUs. Instead, structure it so that the common parts know nothing >> about a specific implementation and each one can be kept in a separate >> file for easier extension. > > > CPUs differ in register structure, not only extending, but having different fields too. > All this information comes from datasheets that don't tell "this is CPU XX with these extensions", > so sometimes it is easier to copy what the datasheet says. > I didn't understand what's wrong with having a central enumeration of all available CPUs? > This is a way of polymorphism, where I can just do a single > read_[register](struct register* register) and then "browse" inside the register definition by knowing the architecture. > Could you please explain your alternative with more detail? The user wants its architecture's definition, and will not ... >> The driver that owns the MMIO region normally maps it once during its >> probe() function and then keeps a pointer around > > > This case is different. Please note that this is not a "device driver", > that's why it doesn't own the MMIO region. This driver gathers information > from the SPI controller only in the current state (it will be expanded). > That's why it maps and then unmaps in the same operation. To answer all the above points: This needs to be in a driver, and in case of pch, that driver is drivers/mtd/spi-nor/intel-spi.c. This driver already has access to the registers you need, and the information you pass corresponds to the devices that this driver manages, which in turn is where user space would logically search for it. You can read the registers in the intel_spi_probe() function and then add attributes to the mtd device in sysfs. I think a good way to handle this in a generic way would be to add members to the mtd_info structure and then have the attributes created by the mtd core code for any device that initializes those struct members, along with the existing 'type', 'size', 'flags', etc attributes. Arnd