From patchwork Mon Apr 25 16:08:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Salter X-Patchwork-Id: 66595 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp1123120qge; Mon, 25 Apr 2016 09:08:48 -0700 (PDT) X-Received: by 10.66.52.112 with SMTP id s16mr50254853pao.35.1461600528459; Mon, 25 Apr 2016 09:08:48 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id by2si7670216pab.168.2016.04.25.09.08.47; Mon, 25 Apr 2016 09:08:48 -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 S933017AbcDYQIq (ORCPT + 29 others); Mon, 25 Apr 2016 12:08:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58596 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932873AbcDYQIo (ORCPT ); Mon, 25 Apr 2016 12:08:44 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 131B26F66C; Mon, 25 Apr 2016 16:08:44 +0000 (UTC) Received: from t540.localdomain.localdomain (ovpn-113-109.phx2.redhat.com [10.3.113.109]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3PG8hjJ002892; Mon, 25 Apr 2016 12:08:43 -0400 From: Mark Salter To: Corey Minyard Cc: openipmi-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org, Mark Salter Subject: [PATCH] IPMI: reserve memio regions separately Date: Mon, 25 Apr 2016 12:08:35 -0400 Message-Id: <1461600515-26617-1-git-send-email-msalter@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit d61a3ead2680 ("[PATCH] IPMI: reserve I/O ports separately") changed the way I/O ports were reserved and includes this comment in log: Some BIOSes reserve disjoint I/O regions in their ACPI tables for the IPMI controller. This causes problems when trying to register the entire I/O region. Therefore we must register each I/O port separately. There is a similar problem with memio regions on an arm64 platform (AMD Seattle). Where I see: ipmi message handler version 39.2 ipmi_si AMDI0300:00: probing via device tree ipmi_si AMDI0300:00: ipmi_si: probing via ACPI ipmi_si AMDI0300:00: [mem 0xe0010000] regsize 1 spacing 4 irq 23 ipmi_si: Adding ACPI-specified kcs state machine IPMI System Interface driver. ipmi_si: Trying ACPI-specified kcs state machine at mem \ address 0xe0010000, slave address 0x0, irq 23 ipmi_si: Could not set up I/O space The problem is that the ACPI core registers disjoint regions for the platform device: e0010000-e0010000 : AMDI0300:00 e0010004-e0010004 : AMDI0300:00 and the ipmi_si driver tries to register one region e0010000-e0010004. This patch creates helper functions for region reservation so that mem/port setup/cleanup ops can share the code which requests and releases the regions separately. Signed-off-by: Mark Salter --- drivers/char/ipmi/ipmi_si_intf.c | 74 +++++++++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 20 deletions(-) -- 1.8.3.1 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c index 7fddd86..0149397 100644 --- a/drivers/char/ipmi/ipmi_si_intf.c +++ b/drivers/char/ipmi/ipmi_si_intf.c @@ -1476,6 +1476,51 @@ static int std_irq_setup(struct smi_info *info) return rv; } +static void region_cleanup(struct smi_info *info, int num, bool is_memio) +{ + unsigned long addr = info->io.addr_data; + int idx; + + for (idx = 0; idx < num; idx++) { + if (is_memio) + release_mem_region(addr + idx * info->io.regspacing, + info->io.regsize); + else + release_region(addr + idx * info->io.regspacing, + info->io.regsize); + } +} + +static int region_setup(struct smi_info *info, bool is_memio) +{ + unsigned long addr = info->io.addr_data; + struct resource *res; + int idx, offset; + + /* + * Some BIOSes reserve disjoint I/O regions in their ACPI + * tables. This causes problems when trying to register the + * entire I/O region. Therefore we must register each I/O + * region separately. + */ + for (idx = 0; idx < info->io_size; idx++) { + offset = idx * info->io.regspacing; + if (is_memio) + res = request_mem_region(addr + offset, + info->io.regsize, DEVICE_NAME); + else + res = request_region(addr + offset, + info->io.regsize, DEVICE_NAME); + + if (res == NULL) { + /* Undo allocations */ + region_cleanup(info, idx, is_memio); + return -EIO; + } + } + return 0; +} + static unsigned char port_inb(const struct si_sm_io *io, unsigned int offset) { unsigned int addr = io->addr_data; @@ -1523,14 +1568,8 @@ static void port_outl(const struct si_sm_io *io, unsigned int offset, static void port_cleanup(struct smi_info *info) { - unsigned int addr = info->io.addr_data; - int idx; - - if (addr) { - for (idx = 0; idx < info->io_size; idx++) - release_region(addr + idx * info->io.regspacing, - info->io.regsize); - } + if (info->io.addr_data) + region_cleanup(info, info->io_size, false); } static int port_setup(struct smi_info *info) @@ -1640,23 +1679,17 @@ static void mem_outq(const struct si_sm_io *io, unsigned int offset, static void mem_cleanup(struct smi_info *info) { - unsigned long addr = info->io.addr_data; - int mapsize; - if (info->io.addr) { iounmap(info->io.addr); - mapsize = ((info->io_size * info->io.regspacing) - - (info->io.regspacing - info->io.regsize)); - - release_mem_region(addr, mapsize); + region_cleanup(info, info->io_size, true); } } static int mem_setup(struct smi_info *info) { unsigned long addr = info->io.addr_data; - int mapsize; + int mapsize, err; if (!addr) return -ENODEV; @@ -1692,6 +1725,10 @@ static int mem_setup(struct smi_info *info) return -EINVAL; } + err = region_setup(info, true); + if (err) + return err; + /* * Calculate the total amount of memory to claim. This is an * unusual looking calculation, but it avoids claiming any @@ -1702,12 +1739,9 @@ static int mem_setup(struct smi_info *info) mapsize = ((info->io_size * info->io.regspacing) - (info->io.regspacing - info->io.regsize)); - if (request_mem_region(addr, mapsize, DEVICE_NAME) == NULL) - return -EIO; - info->io.addr = ioremap(addr, mapsize); if (info->io.addr == NULL) { - release_mem_region(addr, mapsize); + region_cleanup(info, info->io_size, true); return -EIO; } return 0;