Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1772907ybi; Thu, 20 Jun 2019 03:34:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqwiYQBWtlTea66CwI35C2rYBf7nOn/Wn384uXgHW+JCNSQZdWMmhmny/4lhUcrFYDB2BZV6 X-Received: by 2002:a63:7ce:: with SMTP id 197mr5053189pgh.320.1561026896378; Thu, 20 Jun 2019 03:34:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561026896; cv=none; d=google.com; s=arc-20160816; b=FRBgdzjOBCGORjk+/aG/i8ao3pwCCIO0On2IxYIYiOfKYchToXgQAYvlKqIakTRxwB 837SZTrmdzKW85vXu4ny7h+bFussVnrASIPyZB9rLPkFMShKZ/sCC35Ju8J+t2q4L+Qj OOU7ag3etPGhr3VkbwiOsBhMOVyEvuQqtjvQR9lGhE06vQLHryb0XpCb/YquuycN5uqf 2TYk0vtckUCtYt8cBp8fLO9n79/W320uVF/80PUWGh2zvEBH8GuOrYjr7J2Jl71Py34s EOBqlGZtG22MRpK3ayQsyGHaDuZAYtTvszsaFB34rFbu/ic0mkCvneOopaAlXIfzfY1y OCfg== 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; bh=t7bnCQfvAaHuKMaLWXxi2TlfK6/J6DxUM2Yfv6Bfz4M=; b=A7tWUjrPXK3a1AkehQe84OtTffjg8vkV3/uTQzQesJoaKCjDcvqeKKE3s4ppks1biy SF3nzW3xG4iIvHnG3OPpUWZSCIqZftsK9Y8HXGmNqwmcei+v+ia80PQUNQz9HPf3qaXb FCq1rePKKjBOYEONImqMhpBnES5sTHriv77sJNx7jgvsBeMlQ0f1Vmgy5JuMkwUTN4RN t2JsdivPE7NXa7jLZDHdhWt1LkPq+ytQQAQWI0gLQ/Fkjyifv77sEBz6f8OiXrJQZmd/ T4NtMNmB0B4ZmbYprzyOECYOL4HEoINy1xqkWIYxDJmG53/ff6rJLA0NSTraqQu3Go/A PC4A== 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 m22si5524146pgj.527.2019.06.20.03.34.39; Thu, 20 Jun 2019 03:34:56 -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 S1730899AbfFTKdf (ORCPT + 99 others); Thu, 20 Jun 2019 06:33:35 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:18647 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726222AbfFTKdf (ORCPT ); Thu, 20 Jun 2019 06:33:35 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id D286968E86C6D27CF9A1; Thu, 20 Jun 2019 18:33:32 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.439.0; Thu, 20 Jun 2019 18:33:25 +0800 From: John Garry To: CC: , , , , , , John Garry Subject: [PATCH 2/5] lib: logic_pio: Add logic_pio_unregister_range() Date: Thu, 20 Jun 2019 18:31:53 +0800 Message-ID: <1561026716-140537-3-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1561026716-140537-1-git-send-email-john.garry@huawei.com> References: <1561026716-140537-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.212.75] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a function to unregister a logical PIO range. The method used to allocate LOGIC_PIO_CPU_MMIO regions during registration is slightly modified to ensure that we get no overlap when regions are unregistered. This is needed because the allocation scheme assumed that no regions are ever unregistered. Logical PIO space can still be leaked when unregistering certain LOGIC_PIO_CPU_MMIO regions, but this acceptable for now since there are no callers to unregister LOGIC_PIO_CPU_MMIO regions, and the logical PIO region allocation scheme would need significant work to improve this. Signed-off-by: John Garry --- include/linux/logic_pio.h | 1 + lib/logic_pio.c | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/linux/logic_pio.h b/include/linux/logic_pio.h index cbd9d8495690..88e1e6304a71 100644 --- a/include/linux/logic_pio.h +++ b/include/linux/logic_pio.h @@ -117,6 +117,7 @@ struct logic_pio_hwaddr *find_io_range_by_fwnode(struct fwnode_handle *fwnode); unsigned long logic_pio_trans_hwaddr(struct fwnode_handle *fwnode, resource_size_t hw_addr, resource_size_t size); int logic_pio_register_range(struct logic_pio_hwaddr *newrange); +void logic_pio_unregister_range(struct logic_pio_hwaddr *range); resource_size_t logic_pio_to_hwaddr(unsigned long pio); unsigned long logic_pio_trans_cpuaddr(resource_size_t hw_addr); diff --git a/lib/logic_pio.c b/lib/logic_pio.c index 761296376fbc..45eb57af2574 100644 --- a/lib/logic_pio.c +++ b/lib/logic_pio.c @@ -56,7 +56,7 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range) /* for MMIO ranges we need to check for overlap */ if (start >= range->hw_start + range->size || end < range->hw_start) { - mmio_sz += range->size; + mmio_sz = range->io_start + range->size; } else { ret = -EFAULT; goto end_register; @@ -98,6 +98,20 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range) return ret; } +/** + * logic_pio_unregister_range - unregister logical PIO range for a host + * @range: pointer to the IO range which has been already registered. + * + * Unregister a previously-registered IO range node. + */ +void logic_pio_unregister_range(struct logic_pio_hwaddr *range) +{ + mutex_lock(&io_range_mutex); + list_del_rcu(&range->list); + mutex_unlock(&io_range_mutex); + synchronize_rcu(); +} + /** * find_io_range_by_fwnode - find logical PIO range for given FW node * @fwnode: FW node handle associated with logical PIO range -- 2.17.1