Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp13075iob; Wed, 27 Apr 2022 17:34:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4JFopyoXbtywvx36/ZuoEZwxMJ5GTTSnsmu7LMrFAYdDxca/CinO6M+zKmzNtA0lv0lCu X-Received: by 2002:a17:907:c18:b0:6f3:9c23:20fd with SMTP id ga24-20020a1709070c1800b006f39c2320fdmr15880992ejc.740.1651106058721; Wed, 27 Apr 2022 17:34:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651106058; cv=none; d=google.com; s=arc-20160816; b=q6GGS8riKctAp7DCO5TKTbYLTPxz+feZLl+GvolWEUo4OOo6c6iyD8bvAE/yDJAhKN Jp//+1O2NJ3J7ses4a2hhDX5MkmZ+/Imzw9xj5W+BAvEawWPqUItAS/5NTfWd4HD5PNj xoMpz+Plt2wzVIyVmWgcZO5wfBeYXrlFsKyMpDns9GRKgji1nVEBvx8AQeoJNsRqdh71 tBjnj1GbohJ4SE/RTcJpYTs4Ah5GNs3nJ+WH6NNHZXb6a1WGR38sqq05//iAcBpB+BAO WGTxwspv1zObyqCs/5Xz6CmyVfYsRIiWhRBQbosMQyDPeXF/aVRDy8miYbdZap59pw7/ bLvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:subject:cc:to :from:date; bh=U/w0HAWT55KBT+4FBnduUiueUGAFz4i9QGL3wosLvIc=; b=PRikHV4fzImU37MqQpOxpWR9k7YShlCY1LvNOI4FOeuE+uaaTAk5yAINCfx0CjnfVc 0rfmA7ZecErP7/N6U3LH2tzIkQYWy1ECjJpK10h9dBkhh2diZ0YgFVNYNTnwDKnO1JJA wr5hQ+bKWQfsjdEYoz0bou8GVYj+GqpsE6jLzvatQ/FHd2+S7AS5sjBIWcV7lwA/X50z Xy4gUWm2g0lN+eG+ZCtdKWy0GasdU9sd94VL+I//zBLX78U5q7kJ0Ri8vD9PVj7IuFWI K32u2jjSkv4zqSBuZPbT658pHSLgOhhJq3Tq9jBATFhqlIvgrugeGX0mWf0LHGAnHWzc ChgQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i19-20020a170906699300b006f38d0f0472si2443813ejr.365.2022.04.27.17.33.54; Wed, 27 Apr 2022 17:34:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235657AbiD0WTQ (ORCPT + 99 others); Wed, 27 Apr 2022 18:19:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237989AbiD0WTC (ORCPT ); Wed, 27 Apr 2022 18:19:02 -0400 Received: from angie.orcam.me.uk (angie.orcam.me.uk [IPv6:2001:4190:8020::34]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id ECFAC13F21 for ; Wed, 27 Apr 2022 15:15:48 -0700 (PDT) Received: by angie.orcam.me.uk (Postfix, from userid 500) id 4E5C192009C; Thu, 28 Apr 2022 00:15:47 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 480CF92009B; Wed, 27 Apr 2022 23:15:47 +0100 (BST) Date: Wed, 27 Apr 2022 23:15:47 +0100 (BST) From: "Maciej W. Rozycki" To: Paul Walmsley , Palmer Dabbelt , Albert Ou cc: Bjorn Helgaas , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] RISC-V: PCI: Avoid handing out address 0 to devices Message-ID: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,HDRS_LCASE, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For RISC-V platforms we permit assigning addresses from 0 to PCI devices, both in the memory and the I/O bus space, and we happily do so if there is no conflict, e.g.: pci 0000:07:00.0: BAR 0: assigned [io 0x0000-0x0007] pci 0000:07:00.1: BAR 0: assigned [io 0x0008-0x000f] pci 0000:06:01.0: PCI bridge to [bus 07] pci 0000:06:01.0: bridge window [io 0x0000-0x0fff] (with the SiFive HiFive Unmatched RISC-V board and a dual serial port option card based on the OxSemi OXPCIe952 device wired for the legacy UART mode). Address 0 is treated specially however in many places, for example in `pci_iomap_range' and `pci_iomap_wc_range' we require that the start address is non-zero, and even if we let such an address through, then individual device drivers could reject a request to handle a device at such an address, such as in `uart_configure_port'. Consequently given devices configured as shown above only one is actually usable: Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled serial 0000:07:00.0: enabling device (0000 -> 0001) serial: probe of 0000:07:00.0 failed with error -12 serial 0000:07:00.1: enabling device (0000 -> 0001) serial 0000:07:00.1: detected caps 00000700 should be 00000500 0000:07:00.1: ttyS0 at I/O 0x8 (irq = 39, base_baud = 15625000) is a 16C950/954 Therefore avoid handing out address 0, by bumping the lowest address available to PCI via PCIBIOS_MIN_IO and PCIBIOS_MIN_MEM up by 4 and 16 respectively, which is the minimum allocation size for I/O and memory BARs. With this in place the system in question we have: pci 0000:07:00.0: BAR 0: assigned [io 0x1000-0x1007] pci 0000:07:00.1: BAR 0: assigned [io 0x1008-0x100f] pci 0000:06:01.0: PCI bridge to [bus 07] pci 0000:06:01.0: bridge window [io 0x1000-0x1fff] and then devices work correctly: Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled serial 0000:07:00.0: enabling device (0000 -> 0001) serial 0000:07:00.0: detected caps 00000700 should be 00000500 0000:07:00.0: ttyS0 at I/O 0x1000 (irq = 38, base_baud = 15625000) is a 16C950/954 serial 0000:07:00.1: enabling device (0000 -> 0001) serial 0000:07:00.1: detected caps 00000700 should be 00000500 0000:07:00.1: ttyS1 at I/O 0x1008 (irq = 39, base_baud = 15625000) is a 16C950/954 Especially I/O space ranges are particularly valuable, because bridges only decode bits from 12 up and consequently where 16-bit addressing is in effect, as few as 16 separate ranges can be assigned to individual buses only, however a generic change to avoid handing out address 0 only has turned out controversial as per the discussion referred via the link below. Conversely sorting this out in platform code has been standard practice since forever to avoid a clash with legacy devices subtractively decoded by the southbridge where present. This can be revised should a generic solution be adopted sometime. Signed-off-by: Maciej W. Rozycki Link: https://lore.kernel.org/r/alpine.DEB.2.21.2202260044180.25061@angie.orcam.me.uk --- Hi, NB I have an OxSemi OXPCIe952 based card that can be wired to either the native or the legacy mode via a jumper block and I am so glad that I have checked whether it works in the legacy mode as well. I guess there are so few legacy-free platforms still for nobody else to notice this issue yet. Maciej --- arch/riscv/include/asm/pci.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) linux-riscv-pcibios-min.diff Index: linux-macro/arch/riscv/include/asm/pci.h =================================================================== --- linux-macro.orig/arch/riscv/include/asm/pci.h +++ linux-macro/arch/riscv/include/asm/pci.h @@ -12,8 +12,8 @@ #include -#define PCIBIOS_MIN_IO 0 -#define PCIBIOS_MIN_MEM 0 +#define PCIBIOS_MIN_IO 4 +#define PCIBIOS_MIN_MEM 16 /* RISC-V shim does not initialize PCI bus */ #define pcibios_assign_all_busses() 1