From patchwork Mon May 18 12:59:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanjun Guo X-Patchwork-Id: 48694 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id BCECA2121F for ; Mon, 18 May 2015 13:03:12 +0000 (UTC) Received: by wixv7 with SMTP id v7sf22881696wix.0 for ; Mon, 18 May 2015 06:03:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=pIkNAFA2Kmd0X9g+kh77Hr9jDEn2wV+2Vb411K9MNhM=; b=PYRW0rfrQ1a0qIgoIJf4iozfjfoFW/Nou+4zbkdMY7Ex0SadFTNFsMDQepC/U9ucO+ vrIYQwQ6QUod8kD+W0tjSDWGx+McA8zwlJua2brBM/GsXFBboYnimA1tONkOAZHWuLNP dnXvNpz8+f2UPyie/BsYw4j5l66BUKqmTgmS1alXQ1Vbxaz7L9HydpioPIoJqtnuuElv ybCgeVqB3Rby8wq0z7obQ4fxhhp6rtI9k6DtzrFPiR5p/lkMwAuOHqTL59XTo7aSeojc wrKlyaqJeQ7ELkEirl+2g0c13X2KU5CL3LnZLZVdso3d/vi9zd9JZ7auY6e05Xigr/x9 JhSQ== X-Gm-Message-State: ALoCoQlOIE5OgVv9HJ/42StBZFxFzjLKE8PQuFPWh5tE3IbQKQ+xmL0g0IuKSTdeEaBHbp9C0gHK X-Received: by 10.112.142.170 with SMTP id rx10mr17793858lbb.12.1431954191819; Mon, 18 May 2015 06:03:11 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.207.65 with SMTP id lu1ls696707lac.104.gmail; Mon, 18 May 2015 06:03:11 -0700 (PDT) X-Received: by 10.112.78.105 with SMTP id a9mr17191334lbx.70.1431954191663; Mon, 18 May 2015 06:03:11 -0700 (PDT) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com. [209.85.215.51]) by mx.google.com with ESMTPS id as7si6653117lbc.107.2015.05.18.06.03.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 May 2015 06:03:11 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by labbd9 with SMTP id bd9so218986815lab.2 for ; Mon, 18 May 2015 06:03:11 -0700 (PDT) X-Received: by 10.112.150.100 with SMTP id uh4mr16936841lbb.112.1431954191275; Mon, 18 May 2015 06:03:11 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp69703lbb; Mon, 18 May 2015 06:03:09 -0700 (PDT) X-Received: by 10.67.4.138 with SMTP id ce10mr44312392pad.102.1431954189069; Mon, 18 May 2015 06:03:09 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id pc7si11160079pac.69.2015.05.18.06.03.08; Mon, 18 May 2015 06:03:09 -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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752165AbbERNDF (ORCPT + 7 others); Mon, 18 May 2015 09:03:05 -0400 Received: from mail-pa0-f42.google.com ([209.85.220.42]:33868 "EHLO mail-pa0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752831AbbERNA0 (ORCPT ); Mon, 18 May 2015 09:00:26 -0400 Received: by pabru16 with SMTP id ru16so151475967pab.1 for ; Mon, 18 May 2015 06:00:25 -0700 (PDT) X-Received: by 10.68.125.130 with SMTP id mq2mr43244262pbb.121.1431954025327; Mon, 18 May 2015 06:00:25 -0700 (PDT) Received: from localhost ([180.150.148.224]) by mx.google.com with ESMTPSA id dp7sm10074947pdb.10.2015.05.18.06.00.24 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 18 May 2015 06:00:24 -0700 (PDT) From: Hanjun Guo To: Marc Zyngier , Jason Cooper , Will Deacon , Catalin Marinas , "Rafael J. Wysocki" Cc: Jiang Liu , Lorenzo Pieralisi , Arnd Bergmann , Tomasz Nowicki , Grant Likely , Thomas Gleixner , Olof Johansson , linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linaro-acpi@lists.linaro.org, Hanjun Guo Subject: [PATCH 11/11] irqchip / GICv3 / ACPI: Consolidate GICv3 ACPI related init code Date: Mon, 18 May 2015 20:59:21 +0800 Message-Id: <1431953961-22706-12-git-send-email-hanjun.guo@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1431953961-22706-1-git-send-email-hanjun.guo@linaro.org> References: <1431953961-22706-1-git-send-email-hanjun.guo@linaro.org> Sender: linux-acpi-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: hanjun.guo@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Move GICv3 ACPI related init code in irq-gic.c to irq-gic-acpi.c, this can make the ACPI related GIC init code slef-contained as GICV2 did. Signed-off-by: Hanjun Guo --- drivers/irqchip/irq-gic-acpi.c | 109 +++++++++++++++++++++++++++++ drivers/irqchip/irq-gic-v3.c | 140 ++----------------------------------- include/linux/irqchip/arm-gic-v3.h | 10 +++ 3 files changed, 123 insertions(+), 136 deletions(-) diff --git a/drivers/irqchip/irq-gic-acpi.c b/drivers/irqchip/irq-gic-acpi.c index 8463e48..75c4893 100644 --- a/drivers/irqchip/irq-gic-acpi.c +++ b/drivers/irqchip/irq-gic-acpi.c @@ -207,3 +207,112 @@ gic_v2_acpi_init(struct acpi_table_header *table) return 0; } IRQCHIP_ACPI_DECLARE(gic_v2, ACPI_SIG_MADT, gic_v2_acpi_init); + +static struct redist_region *redist_regs __initdata; +static u32 nr_redist_regions __initdata; + +static int __init +gic_acpi_register_redist(u64 phys_base, u64 size) +{ + struct redist_region *redist_regs_new; + void __iomem *redist_base; + + redist_regs_new = krealloc(redist_regs, + sizeof(*redist_regs) * (nr_redist_regions + 1), + GFP_KERNEL); + if (!redist_regs_new) { + pr_err("Couldn't allocate resource for GICR region\n"); + return -ENOMEM; + } + + redist_regs = redist_regs_new; + + redist_base = ioremap(phys_base, size); + if (!redist_base) { + pr_err("Couldn't map GICR region @%llx\n", phys_base); + return -ENOMEM; + } + + redist_regs[nr_redist_regions].phys_base = phys_base; + redist_regs[nr_redist_regions].redist_base = redist_base; + nr_redist_regions++; + return 0; +} + +static int __init +gic_acpi_parse_madt_redist(struct acpi_subtable_header *header, + const unsigned long end) +{ + struct acpi_madt_generic_redistributor *redist; + + if (BAD_MADT_ENTRY(header, end)) + return -EINVAL; + + redist = (struct acpi_madt_generic_redistributor *)header; + if (!redist->base_address) + return -EINVAL; + + return gic_acpi_register_redist(redist->base_address, redist->length); +} + +static int __init +gic_v3_acpi_init(struct acpi_table_header *table) +{ + int count, i, err = 0; + void __iomem *dist_base; + + if (acpi_gic_version() < ACPI_MADT_GIC_VER_V3) + return -ENODEV; + + /* Get distributor base address */ + count = acpi_parse_entries(ACPI_SIG_MADT, + sizeof(struct acpi_table_madt), + acpi_gic_parse_distributor, table, + ACPI_MADT_TYPE_GENERIC_DISTRIBUTOR, 0); + if (count <= 0) { + pr_err("No valid GICD entry exist\n"); + return -EINVAL; + } else if (count > 1) { + pr_err("More than one GICD entry detected\n"); + return -EINVAL; + } + + dist_base = ioremap(dist_phy_base, ACPI_GICV3_DIST_MEM_SIZE); + if (!dist_base) { + pr_err("Unable to map GICD registers\n"); + return -ENOMEM; + } + + err = detect_distributor(dist_base); + if (err) { + pr_err("No distributor detected at @%p, giving up", dist_base); + goto out_dist_unmap; + } + + /* Collect redistributor base addresses */ + count = acpi_parse_entries(ACPI_SIG_MADT, + sizeof(struct acpi_table_madt), + gic_acpi_parse_madt_redist, table, + ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR, 0); + if (count <= 0) { + pr_info("No valid GICR entries exist\n"); + err = -EINVAL; + goto out_redist_unmap; + } + + err = gicv3_init_bases(dist_base, redist_regs, nr_redist_regions, 0, NULL); + if (err) + goto out_redist_unmap; + + return 0; + +out_redist_unmap: + for (i = 0; i < nr_redist_regions; i++) + if (redist_regs[i].redist_base) + iounmap(redist_regs[i].redist_base); + kfree(redist_regs); +out_dist_unmap: + iounmap(dist_base); + return err; +} +IRQCHIP_ACPI_DECLARE(gic_v3, ACPI_SIG_MADT, gic_v3_acpi_init); diff --git a/drivers/irqchip/irq-gic-v3.c b/drivers/irqchip/irq-gic-v3.c index e7f134e..a8382f4 100644 --- a/drivers/irqchip/irq-gic-v3.c +++ b/drivers/irqchip/irq-gic-v3.c @@ -36,11 +36,6 @@ #include "irq-gic-common.h" #include "irqchip.h" -struct redist_region { - void __iomem *redist_base; - phys_addr_t phys_base; -}; - struct gic_chip_data { void __iomem *dist_base; struct redist_region *redist_regions; @@ -773,7 +768,7 @@ static const struct irq_domain_ops gic_irq_domain_ops = { .free = gic_irq_domain_free, }; -static int __init gic_init_bases(void __iomem *dist_base, +int __init gicv3_init_bases(void __iomem *dist_base, struct redist_region *rdist_regs, u32 nr_redist_regions, u64 redist_stride, @@ -808,6 +803,7 @@ static int __init gic_init_bases(void __iomem *dist_base, goto out_free; } + set_acpi_core_irqdomain(gic_data.domain); set_handle_irq(gic_handle_irq); if (IS_ENABLED(CONFIG_ARM_GIC_V3_ITS) && gic_dist_supports_lpis()) @@ -827,7 +823,7 @@ out_free: return err; } -static int __init detect_distributor(void __iomem *dist_base) +int __init detect_distributor(void __iomem *dist_base) { u32 reg = readl_relaxed(dist_base + GICD_PIDR2) & GIC_PIDR2_ARCH_MASK; @@ -887,7 +883,7 @@ static int __init gic_of_init(struct device_node *node, struct device_node *pare if (of_property_read_u64(node, "redistributor-stride", &redist_stride)) redist_stride = 0; - err = gic_init_bases(dist_base, rdist_regs, nr_redist_regions, + err = gicv3_init_bases(dist_base, rdist_regs, nr_redist_regions, redist_stride, node); if (!err) return 0; @@ -904,131 +900,3 @@ out_unmap_dist: IRQCHIP_DECLARE(gic_v3, "arm,gic-v3", gic_of_init); #endif - -#ifdef CONFIG_ACPI -static struct redist_region *redist_regs __initdata; -static u32 nr_redist_regions __initdata; -static phys_addr_t dist_phy_base __initdata; - -static int __init -gic_acpi_register_redist(u64 phys_base, u64 size) -{ - struct redist_region *redist_regs_new; - void __iomem *redist_base; - - redist_regs_new = krealloc(redist_regs, - sizeof(*redist_regs) * (nr_redist_regions + 1), - GFP_KERNEL); - if (!redist_regs_new) { - pr_err("Couldn't allocate resource for GICR region\n"); - return -ENOMEM; - } - - redist_regs = redist_regs_new; - - redist_base = ioremap(phys_base, size); - if (!redist_base) { - pr_err("Couldn't map GICR region @%llx\n", phys_base); - return -ENOMEM; - } - - redist_regs[nr_redist_regions].phys_base = phys_base; - redist_regs[nr_redist_regions].redist_base = redist_base; - nr_redist_regions++; - return 0; -} - -static int __init -gic_acpi_parse_madt_redist(struct acpi_subtable_header *header, - const unsigned long end) -{ - struct acpi_madt_generic_redistributor *redist; - - if (BAD_MADT_ENTRY(header, end)) - return -EINVAL; - - redist = (struct acpi_madt_generic_redistributor *)header; - if (!redist->base_address) - return -EINVAL; - - return gic_acpi_register_redist(redist->base_address, redist->length); -} - -static int __init -gic_acpi_parse_madt_distributor(struct acpi_subtable_header *header, - const unsigned long end) -{ - struct acpi_madt_generic_distributor *dist; - - dist = (struct acpi_madt_generic_distributor *)header; - - if (BAD_MADT_ENTRY(dist, end)) - return -EINVAL; - - dist_phy_base = dist->base_address; - return 0; -} - -static int __init -gic_v3_acpi_init(struct acpi_table_header *table) -{ - int count, i, err = 0; - void __iomem *dist_base; - - if (acpi_gic_version() < ACPI_MADT_GIC_VER_V3) - return -ENODEV; - - /* Get distributor base address */ - count = acpi_parse_entries(ACPI_SIG_MADT, - sizeof(struct acpi_table_madt), - gic_acpi_parse_madt_distributor, table, - ACPI_MADT_TYPE_GENERIC_DISTRIBUTOR, 0); - if (count <= 0) { - pr_err("No valid GICD entry exist\n"); - return -EINVAL; - } else if (count > 1) { - pr_err("More than one GICD entry detected\n"); - return -EINVAL; - } - - dist_base = ioremap(dist_phy_base, ACPI_GICV3_DIST_MEM_SIZE); - if (!dist_base) { - pr_err("Unable to map GICD registers\n"); - return -ENOMEM; - } - - err = detect_distributor(dist_base); - if (err) { - pr_err("No distributor detected at @%p, giving up", dist_base); - goto out_dist_unmap; - } - - /* Collect redistributor base addresses */ - count = acpi_parse_entries(ACPI_SIG_MADT, - sizeof(struct acpi_table_madt), - gic_acpi_parse_madt_redist, table, - ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR, 0); - if (count <= 0) { - pr_info("No valid GICR entries exist\n"); - err = -EINVAL; - goto out_redist_unmap; - } - - err = gic_init_bases(dist_base, redist_regs, nr_redist_regions, 0, NULL); - if (err) - goto out_redist_unmap; - - acpi_irq_domain = gic_data.domain; - return 0; - -out_redist_unmap: - for (i = 0; i < nr_redist_regions; i++) - if (redist_regs[i].redist_base) - iounmap(redist_regs[i].redist_base); - kfree(redist_regs); -out_dist_unmap: - iounmap(dist_base); - return err; -} -IRQCHIP_ACPI_DECLARE(gic_v3, ACPI_SIG_MADT, gic_v3_acpi_init); -#endif diff --git a/include/linux/irqchip/arm-gic-v3.h b/include/linux/irqchip/arm-gic-v3.h index ffbc034..37ef420 100644 --- a/include/linux/irqchip/arm-gic-v3.h +++ b/include/linux/irqchip/arm-gic-v3.h @@ -378,6 +378,11 @@ struct rdists { u64 flags; }; +struct redist_region { + void __iomem *redist_base; + phys_addr_t phys_base; +}; + static inline void gic_write_eoir(u64 irq) { asm volatile("msr_s " __stringify(ICC_EOIR1_EL1) ", %0" : : "r" (irq)); @@ -389,6 +394,11 @@ int its_cpu_init(void); int its_init(struct device_node *node, struct rdists *rdists, struct irq_domain *domain); +int gicv3_init_bases(void __iomem *dist_base, struct redist_region *rdist_regs, + u32 nr_redist_regions, u64 redist_stride, + struct device_node *node); + +int detect_distributor(void __iomem *dist_base); #endif #endif