Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp647743imm; Fri, 17 Aug 2018 04:26:28 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzYq7WxjVK96HCc+EBWxnm2X7I2Vqf+2KvmDLp0+5U9DQHZ7OUv0ANS1ruycL51iwmmpRMK X-Received: by 2002:aa7:850b:: with SMTP id v11-v6mr35814828pfn.165.1534505188797; Fri, 17 Aug 2018 04:26:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534505188; cv=none; d=google.com; s=arc-20160816; b=k6bbX62xjrBzRjNDs2Olu6v1eZYtSW90/ugaqexQ8IvFA8mYaiqLYqSVSuIByqyGxg qlGo2rQwT2ej6heP2W/NKSg4sPgKoq/uhhJXvT1nQ7gfN4joqRZCzdRu9q90CxMM+s4B hKUrtWuUQA0cMt4SEN3jS3npDZPLTUCaMoO5Meyv6Mv0HeQZvMGP6rUPXIAxexvnHKVY IBO1Q8NroPEvJT2KV9MAQZV7t36v2gMYyP1k6xGckc5RpGHeLRO5b3U4YGoETT6vpnAO Vbsz4d4XY0/OLcmUxP8co1UUQvEgzFORDJZwQzT0GOr34vijiYJYkRArWZPfslGFY5if C64w== 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:arc-authentication-results; bh=pqgIuVKvR7B9YaQNmtLoo36i9IGTU2q0FFyy86lC4u0=; b=lxAXWjtDQA+arTZGmTHMWM+mQ9Oqvgj9kh8d7RnWouqZZuAYvQRSJdZHUhZw+SF5G+ j3yuzfqBlicvOR5zqaWnrdhePZMalBA+dntefA+ijGWE24DIe+teWWaE2DHrGY5srXKf j5SO2ripeUy4IfFymnFYmo5oAci0UvvOWoCzdM7h4xlt/vrNjyUtEwsF4aM6rqTpMTqF N5v2rbesvuuLaOXtEFwzzM4Amj6t1Yflhe4dCH2CeChX/ZZjioK/Zn+myaYe3lOlvjo2 WGj4UllbODqzNsjMYes3AnCAL5pqbus+gwrR4qX1PMMQI14+mQnL0nhlMsjqN56TwGz7 d8lA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m9-v6si1896497pga.456.2018.08.17.04.26.14; Fri, 17 Aug 2018 04:26:28 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726797AbeHQO1k (ORCPT + 99 others); Fri, 17 Aug 2018 10:27:40 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:46266 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726134AbeHQO1k (ORCPT ); Fri, 17 Aug 2018 10:27:40 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3201F7A9; Fri, 17 Aug 2018 04:24:35 -0700 (PDT) Received: from e107981-ln.cambridge.arm.com (e107981-ln.emea.arm.com [10.4.13.117]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 898073F5BD; Fri, 17 Aug 2018 04:24:33 -0700 (PDT) Date: Fri, 17 Aug 2018 12:24:24 +0100 From: Lorenzo Pieralisi To: "Luck, Tony" Cc: Bjorn Helgaas , linux-kernel@vger.kernel.org, Jayachandran C , Sinan Kaya , Tomasz Nowicki , Arnd Bergmann , Boris Brezillon , Miquel Raynal Subject: Re: how to fix acpi_pci_root_remap_iospace? Message-ID: <20180817112424.GA31375@e107981-ln.cambridge.arm.com> References: <20180816204506.GA21144@agluck-desk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180816204506.GA21144@agluck-desk> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 16, 2018 at 01:45:07PM -0700, Luck, Tony wrote: > Bjorn, > > Back in commit: > > 0a70abb38062 ("PCI/ACPI: Support I/O resources when parsing host bridge resources") > > we added acpi_pci_root_remap_iospace(). On ia64 this was a no-op because ia64 > didn't define PCI_IOBASE, so the entire body of the function was skipped. > > But in the current merge window commit: > > 0bbf47eab469 ("ia64: use asm-generic/io.h") > > ended up defining PCI_IOBASE for us, and now we die horribly > in early boot with: > > kernel BUG at lib/ioremap.c:72! > > > Is PCI_IOBASE the right thing to check for to decide whether > acpi_pci_root_remap_iospace() needs to do anything? > > The ugly fix would be: > > > diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c > index 7433035ded95..de06377de13b 100644 > --- a/drivers/acpi/pci_root.c > +++ b/drivers/acpi/pci_root.c > @@ -741,7 +741,7 @@ static void acpi_pci_root_validate_resources(struct device *dev, > static void acpi_pci_root_remap_iospace(struct fwnode_handle *fwnode, > struct resource_entry *entry) > { > -#ifdef PCI_IOBASE > +#if defined(PCI_IOBASE) && !defined(CONFIG_IA64) > struct resource *res = entry->res; > resource_size_t cpu_addr = res->start; > resource_size_t pci_addr = cpu_addr - entry->offset; > > or we can do some other juggling with defines to get the > same outcome. > > -Tony If that gives too much trouble we could move acpi_pci_root_remap_iospace() to arch/arm64 too (patch compile tested below) given that at the moment it is generic in theory, just let me know what's the best course of action. Lorenzo -- >8 -- diff --git a/arch/arm64/kernel/pci.c b/arch/arm64/kernel/pci.c index 0e2ea1c78542..06e27879087b 100644 --- a/arch/arm64/kernel/pci.c +++ b/arch/arm64/kernel/pci.c @@ -98,13 +98,46 @@ int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge) return 0; } +static void acpi_pci_root_remap_iospace(struct fwnode_handle *fwnode, + struct resource_entry *entry) +{ + struct resource *res = entry->res; + resource_size_t cpu_addr = res->start; + resource_size_t pci_addr = cpu_addr - entry->offset; + resource_size_t length = resource_size(res); + unsigned long port; + + if (pci_register_io_range(fwnode, cpu_addr, length)) + goto err; + + port = pci_address_to_pio(cpu_addr); + if (port == (unsigned long)-1) + goto err; + + res->start = port; + res->end = port + length - 1; + entry->offset = port - pci_addr; + + if (pci_remap_iospace(res, cpu_addr) < 0) + goto err; + + pr_info("Remapped I/O %pa to %pR\n", &cpu_addr, res); + return; +err: + res->flags |= IORESOURCE_DISABLED; +} + static int pci_acpi_root_prepare_resources(struct acpi_pci_root_info *ci) { struct resource_entry *entry, *tmp; + struct acpi_device *device = ci->bridge; int status; status = acpi_pci_probe_root_resources(ci); resource_list_for_each_entry_safe(entry, tmp, &ci->resources) { + if (entry->res->flags & IORESOURCE_IO) + acpi_pci_root_remap_iospace(&device->fwnode, entry); + if (!(entry->res->flags & IORESOURCE_WINDOW)) resource_list_destroy_entry(entry); } diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c index 7433035ded95..0f9fb87b6e26 100644 --- a/drivers/acpi/pci_root.c +++ b/drivers/acpi/pci_root.c @@ -738,37 +738,6 @@ static void acpi_pci_root_validate_resources(struct device *dev, } } -static void acpi_pci_root_remap_iospace(struct fwnode_handle *fwnode, - struct resource_entry *entry) -{ -#ifdef PCI_IOBASE - struct resource *res = entry->res; - resource_size_t cpu_addr = res->start; - resource_size_t pci_addr = cpu_addr - entry->offset; - resource_size_t length = resource_size(res); - unsigned long port; - - if (pci_register_io_range(fwnode, cpu_addr, length)) - goto err; - - port = pci_address_to_pio(cpu_addr); - if (port == (unsigned long)-1) - goto err; - - res->start = port; - res->end = port + length - 1; - entry->offset = port - pci_addr; - - if (pci_remap_iospace(res, cpu_addr) < 0) - goto err; - - pr_info("Remapped I/O %pa to %pR\n", &cpu_addr, res); - return; -err: - res->flags |= IORESOURCE_DISABLED; -#endif -} - int acpi_pci_probe_root_resources(struct acpi_pci_root_info *info) { int ret; @@ -789,10 +758,6 @@ int acpi_pci_probe_root_resources(struct acpi_pci_root_info *info) "no IO and memory resources present in _CRS\n"); else { resource_list_for_each_entry_safe(entry, tmp, list) { - if (entry->res->flags & IORESOURCE_IO) - acpi_pci_root_remap_iospace(&device->fwnode, - entry); - if (entry->res->flags & IORESOURCE_DISABLED) resource_list_destroy_entry(entry); else