From patchwork Fri Oct 27 16:11:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriele Paoloni X-Patchwork-Id: 117369 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp948589qgn; Fri, 27 Oct 2017 09:15:25 -0700 (PDT) X-Google-Smtp-Source: ABhQp+TKgqTR3rSVwltYUc+Mv0edJa12n4N5TuK7ttgVe3W5edd1izR6PG/DMTVF885KkU3DQvq+ X-Received: by 10.84.128.70 with SMTP id 64mr757168pla.329.1509120925723; Fri, 27 Oct 2017 09:15:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509120925; cv=none; d=google.com; s=arc-20160816; b=U6dLTsycYieazvrDwfcez9ZnidSW5HZ2fXkoVjLd88Cn9C2gHzWklmaTMVU4TqbTDb pRw/fWYjFYGIX4bMtcYFbX3eLzdIJQEXSqSwAd7IQAndrWQ3zkL+ykzFz72SsbKur1+g mcH0LVihNMeZUMSjCkqD/P0lPE7g0/og+WAmM2gpkzcUQ3jk2xPTadZoBw0J/70cJCaJ hw5eormFenG41WApcOzFF9dwegG3jM0jwg+BdLDNSM6/EoNZ8FuEPIIEDNmAZnyINHfl umlJlPhrNiqgVcphW8S0pSOwlxhErOW93jY4kZW7n0zzd+ylQLm5u4oWHb98EoRVV53X 6lcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=EJE/1TpJwu9/Md/5Z3oL2SiFEEqwOTHYiAWn4Om2sSc=; b=xLfi+GHcG/AhTMKUwwl9m5d/oPboTKnSXx57jzsSEBTY8iyP/tpAZx5AhlKlDW8MPx yCHk5t8XIHHs+zEOQ+SRLiNiGPimYNWAGY8PhRg/F31J9tIE9i3DMyCkt58PNgxea7T9 KXhObnjIaJ4NKmE6PVnG9QrwwXOMzuybOrGezYHCAA56yWavF/KohIcE5v2XxaAr+KJM qgbHqBwwJhJ+qeLeVjk6NIqZ4Wfn27sApxq3eS4Jm0I57ZKv7tE9OR7RLTG3ZyZGGvIm eP6HGGYoJoezkR9mVicDW350rX2u8ZldzHYriDzOW3afpFmhYpoT3D2pr4nIVCnCqqSI h1gQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-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 g2si4567812pll.718.2017.10.27.09.15.25; Fri, 27 Oct 2017 09:15:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-acpi-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-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751638AbdJ0QPY (ORCPT + 7 others); Fri, 27 Oct 2017 12:15:24 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:9452 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752664AbdJ0QO7 (ORCPT ); Fri, 27 Oct 2017 12:14:59 -0400 Received: from 172.30.72.58 (EHLO DGGEMS414-HUB.china.huawei.com) ([172.30.72.58]) by dggrg04-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DJX16564; Sat, 28 Oct 2017 00:14:39 +0800 (CST) Received: from G00308965-DELL1.china.huawei.com (10.202.226.113) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.361.1; Sat, 28 Oct 2017 00:12:42 +0800 From: Gabriele Paoloni To: , , , , , , , , CC: , , , , , , , , , , , Subject: [PATCH v10 4/9] PCI: Apply the new generic I/O management on PCI IO hosts Date: Fri, 27 Oct 2017 17:11:22 +0100 Message-ID: <1509120687-7352-5-git-send-email-gabriele.paoloni@huawei.com> X-Mailer: git-send-email 2.7.1.windows.1 In-Reply-To: <1509120687-7352-1-git-send-email-gabriele.paoloni@huawei.com> References: <1509120687-7352-1-git-send-email-gabriele.paoloni@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.202.226.113] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020204.59F35B6F.009E, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: bad2eceb1bc65310c4673d45007ddb07 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: gabriele paoloni After introducing the new generic I/O space management(LOGIC_PIO), the original PCI MMIO relevant helpers need to be updated based on the new interfaces defined in LOGIC_PIO. This patch adapts the corresponding code to match the changes introduced by LOGIC_PIO. Signed-off-by: zhichang.yuan Signed-off-by: Gabriele Paoloni Signed-off-by: Arnd Bergmann #earlier draft Acked-by: Bjorn Helgaas --- drivers/pci/pci.c | 95 +++++++++--------------------------------------- include/asm-generic/io.h | 2 +- 2 files changed, 18 insertions(+), 79 deletions(-) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index bcecb47..a1ae4d3 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -3255,17 +3256,6 @@ int pci_request_regions_exclusive(struct pci_dev *pdev, const char *res_name) } EXPORT_SYMBOL(pci_request_regions_exclusive); -#ifdef PCI_IOBASE -struct io_range { - struct list_head list; - phys_addr_t start; - resource_size_t size; -}; - -static LIST_HEAD(io_range_list); -static DEFINE_SPINLOCK(io_range_lock); -#endif - /* * Record the PCI IO range (expressed as CPU physical address + size). * Return a negative value if an error has occured, zero otherwise @@ -3273,51 +3263,28 @@ static DEFINE_SPINLOCK(io_range_lock); int pci_register_io_range(struct fwnode_handle *fwnode, phys_addr_t addr, resource_size_t size) { - int err = 0; - + int ret = 0; #ifdef PCI_IOBASE - struct io_range *range; - resource_size_t allocated_size = 0; - - /* check if the range hasn't been previously recorded */ - spin_lock(&io_range_lock); - list_for_each_entry(range, &io_range_list, list) { - if (addr >= range->start && addr + size <= range->start + size) { - /* range already registered, bail out */ - goto end_register; - } - allocated_size += range->size; - } + struct logic_pio_hwaddr *range; - /* range not registed yet, check for available space */ - if (allocated_size + size - 1 > IO_SPACE_LIMIT) { - /* if it's too big check if 64K space can be reserved */ - if (allocated_size + SZ_64K - 1 > IO_SPACE_LIMIT) { - err = -E2BIG; - goto end_register; - } - - size = SZ_64K; - pr_warn("Requested IO range too big, new size set to 64K\n"); - } + if (!size || addr + size < addr) + return -EINVAL; - /* add the range to the list */ range = kzalloc(sizeof(*range), GFP_ATOMIC); - if (!range) { - err = -ENOMEM; - goto end_register; - } + if (!range) + return -ENOMEM; - range->start = addr; + range->fwnode = fwnode; range->size = size; + range->hw_start = addr; + range->flags = PIO_CPU_MMIO; - list_add_tail(&range->list, &io_range_list); - -end_register: - spin_unlock(&io_range_lock); + ret = logic_pio_register_range(range); + if (ret) + kfree(range); #endif - return err; + return ret; } phys_addr_t pci_pio_to_address(unsigned long pio) @@ -3325,21 +3292,10 @@ phys_addr_t pci_pio_to_address(unsigned long pio) phys_addr_t address = (phys_addr_t)OF_BAD_ADDR; #ifdef PCI_IOBASE - struct io_range *range; - resource_size_t allocated_size = 0; - - if (pio > IO_SPACE_LIMIT) + if (pio >= MMIO_UPPER_LIMIT) return address; - spin_lock(&io_range_lock); - list_for_each_entry(range, &io_range_list, list) { - if (pio >= allocated_size && pio < allocated_size + range->size) { - address = range->start + pio - allocated_size; - break; - } - allocated_size += range->size; - } - spin_unlock(&io_range_lock); + address = logic_pio_to_hwaddr(pio); #endif return address; @@ -3348,25 +3304,8 @@ phys_addr_t pci_pio_to_address(unsigned long pio) unsigned long __weak pci_address_to_pio(phys_addr_t address) { #ifdef PCI_IOBASE - struct io_range *res; - resource_size_t offset = 0; - unsigned long addr = -1; - - spin_lock(&io_range_lock); - list_for_each_entry(res, &io_range_list, list) { - if (address >= res->start && address < res->start + res->size) { - addr = address - res->start + offset; - break; - } - offset += res->size; - } - spin_unlock(&io_range_lock); - - return addr; + return logic_pio_trans_cpuaddr(address); #else - if (address > IO_SPACE_LIMIT) - return (unsigned long)-1; - return (unsigned long) address; #endif } diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h index 334e5db..3980577 100644 --- a/include/asm-generic/io.h +++ b/include/asm-generic/io.h @@ -925,7 +925,7 @@ static inline void iounmap(void __iomem *addr) #define ioport_map ioport_map static inline void __iomem *ioport_map(unsigned long port, unsigned int nr) { - return PCI_IOBASE + (port & IO_SPACE_LIMIT); + return PCI_IOBASE + (port & MMIO_UPPER_LIMIT); } #endif