From patchwork Sat Aug 8 14:26:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 505329 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 18E1614016A for ; Sun, 9 Aug 2015 00:27:41 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b=XO0mxN15; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8C0284BE23; Sat, 8 Aug 2015 16:27:37 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cMdILqgKpkvR; Sat, 8 Aug 2015 16:27:37 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5827E4BE32; Sat, 8 Aug 2015 16:27:29 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D23D94BDF0 for ; Sat, 8 Aug 2015 16:27:21 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id H2dppoSxJq54 for ; Sat, 8 Aug 2015 16:27:21 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-ig0-f171.google.com (mail-ig0-f171.google.com [209.85.213.171]) by theia.denx.de (Postfix) with ESMTPS id 6E44E4BE05 for ; Sat, 8 Aug 2015 16:27:17 +0200 (CEST) Received: by igbpg9 with SMTP id pg9so47331560igb.0 for ; Sat, 08 Aug 2015 07:27:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=GnGuKQ85+5Cz05B0yRq4CF0vbdFHW5CZ/en0WqkX+24=; b=XO0mxN156C8Xz9FsPytmL5RTQgep+p3gQERfzwDv7lOso9KKscgdkRLw+PmAMSGzxF wDwzyhB5uS3SxdlD7u9pncYDXdjlUkYEWfn5dWEWhQKzLE0TrnEgOqGj5gXVFuzJ/zT5 wgnofSRZ7vVRWetOTfWZ1EP4ZYjTrx1KR0k0MZ8a4xTKA3yqHo0HAIZwLYFfDCwv7Rts EvIUW/XL1i0BQlHyUzH4ayIov8rfe+BXZaET3iFBVuOwpNfbXt7XJlyZ6MH3dB9RwzT3 t4PXNWyRhxmwRjKNMlUyPtiGqgEutmFIiaKQ+ALFaiR9WhHLAmOoZi8Rhw7snuqYIWuH 2c8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=GnGuKQ85+5Cz05B0yRq4CF0vbdFHW5CZ/en0WqkX+24=; b=f6YCqPbr9dGVyawvT/wbkVHybVY2TXRkpu2ptIRJbfrNm5HjoFYH0GVMLKhpwUvRmc /k4hWpH9ko2QeG9lGwO7h0VDeuOjfrMQZE+AjABcxbHDCvnqz7pUyoNW7lrN6lEwYybU aWtJGdnPEUt2o0EqDgJRouXydPqMkM4xzaEytH1n00amM7LTXewMR/L5DlyBLx76xiU9 S311xd6d21P1hlYqe1zPAbj81kbtmCZZaTSW/6qFqchrigDzeCT2a96OZNlNxt+zh2v0 rngDxZkYVzvi10WWBsT16VkcuL7xaWxGZgJUQynvFOjXMjyWWvg5JU3DF83G3ctlM3Hi f7Og== X-Gm-Message-State: ALoCoQmpYjcsfwRicMyej5TcUgvJXLDcIKXiYftrq98NEWuCRX2d+CAi+HNk8GTmDp77T3qIMtMz X-Received: by 10.50.27.39 with SMTP id q7mr3071360igg.73.1439044035997; Sat, 08 Aug 2015 07:27:15 -0700 (PDT) Received: from kaki.bld.corp.google.com ([172.29.216.32]) by smtp.gmail.com with ESMTPSA id vk8sm1848136igb.4.2015.08.08.07.27.13 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Aug 2015 07:27:13 -0700 (PDT) Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 8120B22127D; Sat, 8 Aug 2015 08:27:12 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Sat, 8 Aug 2015 08:26:57 -0600 Message-Id: <1439044022-14481-5-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.5.0.rc2.392.g76e840b In-Reply-To: <1439044022-14481-1-git-send-email-sjg@chromium.org> References: <1439044022-14481-1-git-send-email-sjg@chromium.org> Cc: Graeme Russ , Tom Rini Subject: [U-Boot] [PATCH v2 4/9] x86: Tidy up the PIRQ routing code a little X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This code could use a little tightening up. There is some repetition and an odd use of fdtdec_get_int_array(). Signed-off-by: Simon Glass Reviewed-by: Bin Meng Tested-by: Bin Meng --- Changes in v2: - Fix handling of duplicate entries arch/x86/cpu/irq.c | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/arch/x86/cpu/irq.c b/arch/x86/cpu/irq.c index 97dd000..6be2f81 100644 --- a/arch/x86/cpu/irq.c +++ b/arch/x86/cpu/irq.c @@ -125,10 +125,10 @@ static int create_pirq_routing_table(void) return -EINVAL; } - ret = fdtdec_get_int_array(blob, node, "intel,pirq-link", - &irq_router.link_base, 1); - if (ret) + ret = fdtdec_get_int(blob, node, "intel,pirq-link", -1); + if (ret == -1) return ret; + irq_router.link_base = ret; irq_router.irq_mask = fdtdec_get_int(blob, node, "intel,pirq-mask", PIRQ_BITMAP); @@ -156,18 +156,13 @@ static int create_pirq_routing_table(void) } cell = fdt_getprop(blob, node, "intel,pirq-routing", &len); - if (!cell) - return -EINVAL; - - if ((len % sizeof(struct pirq_routing)) == 0) - count = len / sizeof(struct pirq_routing); - else + if (!cell || len % sizeof(struct pirq_routing)) return -EINVAL; + count = len / sizeof(struct pirq_routing); - rt = malloc(sizeof(struct irq_routing_table)); + rt = calloc(1, sizeof(struct irq_routing_table)); if (!rt) return -ENOMEM; - memset((char *)rt, 0, sizeof(struct irq_routing_table)); /* Populate the PIRQ table fields */ rt->signature = PIRQ_SIGNATURE; @@ -181,7 +176,8 @@ static int create_pirq_routing_table(void) slot_base = rt->slots; /* Now fill in the irq_info entries in the PIRQ table */ - for (i = 0; i < count; i++) { + for (i = 0; i < count; + i++, cell += sizeof(struct pirq_routing) / sizeof(u32)) { struct pirq_routing pr; pr.bdf = fdt_addr_to_cpu(cell[0]); @@ -212,25 +208,14 @@ static int create_pirq_routing_table(void) if (slot->irq[pr.pin - 1].link != LINK_N2V(pr.pirq, irq_router.link_base)) debug("WARNING: Inconsistent PIRQ routing information\n"); - - cell += sizeof(struct pirq_routing) / - sizeof(u32); - continue; - } else { - debug("writing INT%c\n", 'A' + pr.pin - 1); - fill_irq_info(slot, PCI_BUS(pr.bdf), - PCI_DEV(pr.bdf), pr.pin, pr.pirq); - cell += sizeof(struct pirq_routing) / - sizeof(u32); continue; } + } else { + slot = slot_base + irq_entries++; } - - slot = slot_base + irq_entries; - fill_irq_info(slot, PCI_BUS(pr.bdf), PCI_DEV(pr.bdf), - pr.pin, pr.pirq); - irq_entries++; - cell += sizeof(struct pirq_routing) / sizeof(u32); + debug("writing INT%c\n", 'A' + pr.pin - 1); + fill_irq_info(slot, PCI_BUS(pr.bdf), PCI_DEV(pr.bdf), pr.pin, + pr.pirq); } rt->size = irq_entries * sizeof(struct irq_info) + 32;