Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7550935imu; Mon, 3 Dec 2018 14:59:42 -0800 (PST) X-Google-Smtp-Source: AFSGD/UpBW9r4yTzhC4au24Rju4YO3hQsT3mQpuyZL8bn1dxyxzK1HICy4yuLnv2UfjFfV767ujg X-Received: by 2002:a17:902:6bc4:: with SMTP id m4mr16919946plt.93.1543877982285; Mon, 03 Dec 2018 14:59:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543877982; cv=none; d=google.com; s=arc-20160816; b=uDoCPhdbWG0AT13xjtBsa0NJExvcpadSrOOAyXobU14WZzSHFGEteL7hHXk6g5r7Kd vIWN7F941GWuBVpT8BX2eQ2fVayRzHLbiREM3RV2Tz8YQckdq2p9dFnIA828AT5yBJ+/ SeHnUZdAG3+hRzX9+9CJ51Z+V+EWwvxwi9jZT7jdP3khnv5klzbiZWnM6hAyOQD8Fzz/ O0Iq/cw62VXS9YwTML+qPvJWJqZIPhkMyVeWSMRmTprcEV83n6BheIwfPRoYzyipiKj/ 4VgiLuA1FDMKSnSFZBtaTjwjxJlddn6kaaxMq9dmqJNC43Kw5HqH4e1CeQ4tptQNZVfo R/Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=4FqDpHW57TB5q203dHp2+9EzIbNGW0xVxBTeIzGsoQk=; b=Fg5EFRZyRL6sBh4KmWvw6i9HDTD/1yz2/U7DkcaLyzLC/O+QwlgyHvULZU3dQqg1bs 3B5E09dG9DtJVHpJOw7YMYEH9v72RpwUtClVa3md/xnsknRNulmmu5WbfKV8nIev1nAi 0YXe7CKLz2LuzFrwL4/86ua1Pndfy3V/OkTGjzRzOx1KPUdAXSFyizSIXaZb20xHrW4w G0PAt+T31aYLwf4omINTLHvOkZe6FBso68uKJrd3n+QASmRQkSOWUvm1+5rIPojOyiU4 Ea/Tk7RpAgRgTekUv/YjmGaqwkkgFFtR3EB24buZiv7k4RJLE31HAcDCMrl0dCO4EqPj Q6uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IRcBphgE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id bb4si14194357plb.322.2018.12.03.14.59.27; Mon, 03 Dec 2018 14:59:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IRcBphgE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1725995AbeLCW5e (ORCPT + 99 others); Mon, 3 Dec 2018 17:57:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:59500 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725909AbeLCW5d (ORCPT ); Mon, 3 Dec 2018 17:57:33 -0500 Received: from localhost (unknown [69.71.4.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AC70C2145D; Mon, 3 Dec 2018 22:57:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543877852; bh=xpUXBn7bisODtn97eXlLbqefPm16ou93J84qDoiuM3U=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=IRcBphgETprKlqhF149iLwCazbPU++sTOoHY1gjzgHuHQOER4n7Gwopbupdtg52FN vNf/StcBGKnUukKYyI4BFKJ4uLUowG9LVzPCzTmeHl4VTrVS+dgSkfxAPbf8fGM/vE X51qsIfTb2fEJZAkNInT7twUs8X3tS9F1gA2pZws= Date: Mon, 3 Dec 2018 16:57:31 -0600 From: Bjorn Helgaas To: Lorenzo Pieralisi Cc: Hanjie Lin , Yixun Lan , Rob Herring , Jianxin Pan , Kevin Hilman , Shawn Lin , Philippe Ombredanne , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Yue Wang , Qiufang Dai , Jian Hu , Liang Yang , Cyrille Pitchen , Gustavo Pimentel , Carlo Caione , linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Jerome Brunet Subject: Re: [PATCH v6 2/2] PCI: amlogic: Add the Amlogic Meson PCIe controller driver Message-ID: <20181203225731.GE207198@google.com> References: <1542876836-191355-1-git-send-email-hanjie.lin@amlogic.com> <1542876836-191355-3-git-send-email-hanjie.lin@amlogic.com> <20181203164150.GA11855@e107981-ln.cambridge.arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181203164150.GA11855@e107981-ln.cambridge.arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 03, 2018 at 04:41:50PM +0000, Lorenzo Pieralisi wrote: > On Thu, Nov 22, 2018 at 04:53:54PM +0800, Hanjie Lin wrote: > > [...] > > > +static int meson_pcie_rd_own_conf(struct pcie_port *pp, int where, int size, > > + u32 *val) > > +{ > > + struct dw_pcie *pci = to_dw_pcie_from_pp(pp); > > + > > + /* > > + * there is a bug of MESON AXG pcie controller that software can not > > + * programe PCI_CLASS_DEVICE register, so we must return a fake right > > + * value to ensure driver could probe successfully. > > + */ > > + if (where == PCI_CLASS_REVISION) { > > + *val = readl(pci->dbi_base + PCI_CLASS_REVISION); > > + /* keep revision id */ > > + *val &= PCI_CLASS_REVISION_MASK; > > + *val |= PCI_CLASS_BRIDGE_PCI << 16; > > + return PCIBIOS_SUCCESSFUL; > > + } > > As I said before, this looks broken. If this code (or other drivers with > the same broken assumptions, eg dwc/pcie-qcom.c) carries out a, say, > byte sized config access of eg PCI_CLASS_DEVICE you will get junk out of > it according to your comment above. > > I would like to pick Bjorn's brain on this to see what we can really do > to fix this (and other) drivers. - Check to see whether you're reading anything in the 32-bit dword at offset 0x08. - Do the 32-bit readl(). - Insert the correct Sub-Class and Base Class code (you also throw away the Programming Interface; not sure why that is) - If you're reading something smaller than 32 bits, mask & shift as needed. pci_bridge_emul_conf_read() does something similar that you might be able to copy. Out of curiosity, what code depends on PCI_CLASS_BRIDGE_PCI? There are several places in the kernel that currently depend on it, but I think several of them *should* be checking dev->hdr_type to identify a type 1 header instead. Bjorn