From patchwork Tue Feb 18 12:34:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfgang Wallner X-Patchwork-Id: 1239995 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=br-automation.com Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48ML1z2NRtz9sRG for ; Tue, 18 Feb 2020 23:36:23 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 93520813A5; Tue, 18 Feb 2020 13:36:17 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=br-automation.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 0CE83813A8; Tue, 18 Feb 2020 13:36:16 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SUBJ_OBFU_PUNCT_FEW,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from mail2.br-automation.com (mail2.br-automation.com [213.33.116.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id BEF05812F9 for ; Tue, 18 Feb 2020 13:36:12 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=br-automation.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=wolfgang.wallner@br-automation.com X-AuditID: c0a80110-4d9ff70000001e77-63-5e4bda3b7f8d Received: from brsmtp01.br-automation.co.at (Unknown_Domain [192.168.1.60]) by mail2.br-automation.com () with SMTP id DA.37.07799.B3ADB4E5; Tue, 18 Feb 2020 13:36:11 +0100 (CET) From: "Wolfgang Wallner" To: u-boot@lists.denx.de Cc: "Simon Glass" , "Bin Meng" , "Anatolij Gustschin" ,"Wolfgang Wallner" ,"Aiden Park" ,"=?ISO-8859-1?Q?Patrik_Dahlstr=F6m?=" Subject: [RFC PATCH] serial: ns16550: Move PCI access from ofdata_to_platdata() to probe() Date: Tue, 18 Feb 2020 13:34:24 +0100 Message-Id: <20200218123424.85618-1-wolfgang.wallner@br-automation.com> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 X-MIMETrack: Itemize by SMTP Server on BRSMTPINTERN2/InternSMTP(Release 10.0.1FP3|August 09, 2019) at 18/02/2020 13:36:11, Serialize by Router on BRSMTPINTERN2/InternSMTP(Release 10.0.1FP3|August 09, 2019) at 18/02/2020 13:36:11, Itemize by SMTP Server on BRSMTP01/Eggelsberg/AT/B&R(Release 10.0.1FP3|August 09, 2019) at 02/18/2020 01:36:11 PM X-TNEFEvaluated: 1 X-Disclaimed: 10099 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrDLMWRmVeSWpSXmKPExsVyYAWjja71Le84g6V3rS3W313CaPHr1mZm i6k98RY7fu1gs/i2ZRujxdu9newObB6zGy6yeNz8/5TVY96sEyweO2fdZfdYvOclk8fZOzsY A9iiuGxSUnMyy1KL9O0SuDJmvnMtWCpd0Tirk7GBsUW8i5GTQ0LAROLn+lfMXYxcHEICWxgl /r/awQaSYBOwlWg8shXMFhGQkPjVf5URpIhZoItJYsuiTewgCWGBKInXcxYzgtgsAqoSM8+s BWvgFXCX6JlxGsxmFtCWWLbwNTPENnmJ2Y2noWoEJU7OfMICMlRC4DaTxPrTa1ghioQkTi8+ C9UgLPGt9QHrBEa+WUhmzULSv4CRaRWjeG5iZo6RXlKRbmJpSX5uYklmfp5ecn7uJkZIiArs YNz9RvsQIxMH4yFGCQ5mJRFeb3GvOCHelMTKqtSi/Pii0pzU4kOM0hwsSuK8vle14oQE0hNL UrNTUwtSi2CyTBycUg2MKYuWB1W5bVs19X2V5PK2WfLlRffMP6m4Hu72iTK4sVjTv27DlG2e ZytDpZTWs54su31E99fRGdOmPzAMajpw9+bVuEg14aJZ9psn1Gff+rZmoXJ1zba/epeTilXE Dny7l3Sm7fCcWxs33L+b5br6ciHbJLEX+m+DDJzqUg2s+4/1+ydsdrs5SYmlOCPRUIu5qDgR ANBIng4/AgAA X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.1 at phobos.denx.de X-Virus-Status: Clean Currently the ofdata_to_platdata() method calls dev_read_addr_pci(), which potentially accesses the parent PCI bus. If this happens before the parent PCI bus is probed the resulting address will be wrong. This behavior was triggered by commit 82de42fa1468 ("dm: core: Allocate parent data separate from probing parent"). According to a comment in drivers/pci/pci-uclass.c [1] accessing the PCI parent bus in ofdata_to_platdata() is not allowed, and the access should be moved to the probe() function. Move the call to dev_read_addr_pci() and the related handling of the 'addr' value from the ofdata_to_platdata() to the probe() method. While moving the code, the comment /* try Processor Local Bus device first */ was dropped. It was initially added with commit 3db886a5bf38 ("serial: ns16550: Support ns16550 compatible pci uart devices") and later made obsolete with commit 33c215af4b9d ("dm: pci: Add a function to read a PCI BAR"). [1] Comment in drivers/pci/pci-uclass.c: "A common cause of this problem is that this function is called in the ofdata_to_platdata() method of @dev. Accessing the PCI bus in that method is not allowed, since it has not yet been probed. To fix this, move that access to the probe() method of @dev instead." Signed-off-by: Wolfgang Wallner Fixes: 82de42fa1468 ("dm: core: Allocate parent data separate from probing parent") Reviewed-by: Simon Glass Reviewed-by: Bin Meng Tested-by: Bin Meng --- The discussion leading to this patch is located at https://lists.denx.de/pipermail/u-boot/2020-February/399811.html drivers/serial/ns16550.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c index 1fcbc35015..07b32abd38 100644 --- a/drivers/serial/ns16550.c +++ b/drivers/serial/ns16550.c @@ -484,12 +484,24 @@ int ns16550_serial_probe(struct udevice *dev) struct NS16550 *const com_port = dev_get_priv(dev); struct reset_ctl_bulk reset_bulk; int ret; + fdt_addr_t addr; + + com_port->plat = dev_get_platdata(dev); + + addr = dev_read_addr_pci(dev); + if (addr == FDT_ADDR_T_NONE) + return -EINVAL; + +#ifdef CONFIG_SYS_NS16550_PORT_MAPPED + com_port->plat->base = addr; +#else + com_port->plat->base = (unsigned long)map_physmem(addr, 0, MAP_NOCACHE); +#endif ret = reset_get_bulk(dev, &reset_bulk); if (!ret) reset_deassert_bulk(&reset_bulk); - com_port->plat = dev_get_platdata(dev); NS16550_init(com_port, -1); return 0; @@ -507,21 +519,9 @@ int ns16550_serial_ofdata_to_platdata(struct udevice *dev) { struct ns16550_platdata *plat = dev->platdata; const u32 port_type = dev_get_driver_data(dev); - fdt_addr_t addr; struct clk clk; int err; - /* try Processor Local Bus device first */ - addr = dev_read_addr_pci(dev); - if (addr == FDT_ADDR_T_NONE) - return -EINVAL; - -#ifdef CONFIG_SYS_NS16550_PORT_MAPPED - plat->base = addr; -#else - plat->base = (unsigned long)map_physmem(addr, 0, MAP_NOCACHE); -#endif - plat->reg_offset = dev_read_u32_default(dev, "reg-offset", 0); plat->reg_shift = dev_read_u32_default(dev, "reg-shift", 0); plat->reg_width = dev_read_u32_default(dev, "reg-io-width", 1);