Received: by 10.223.185.116 with SMTP id b49csp1795987wrg; Thu, 22 Feb 2018 03:20:21 -0800 (PST) X-Google-Smtp-Source: AH8x226i9nhzJF+c6hP72EyVoOFsY3vYiX09zTAYWgE11xozQU+vAVo1/F/9+LOR2RfQZZT6YytB X-Received: by 10.99.117.28 with SMTP id q28mr5393382pgc.187.1519298421090; Thu, 22 Feb 2018 03:20:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519298421; cv=none; d=google.com; s=arc-20160816; b=ezvS6gS6H1kAviUEQrcuAtlzZ/y76yDqs5PN9UFBg3azIfR87cSQeL0WbHO3Lq7bx+ QWz+6VMB+YqjnktIPbl7o6nXB8jef42g1+bhN5eTZlk1yBkAN9DjwVCePG1nr2JgnYVD g22Tz3059uE3AiuZV98QzvVk9xD0sRdY30Ep9knMhC0bQL2u1WoR/x0572iGHWbJGY/R O7BxuZu5JW+ydfi0ZnL8HoAjwfZ2VGiZlMS/S36xAmb79JkbZThWZVKaMD6bULTG0LrA ARGtgNw5QfejnkJcKdzmKlBAePYulwQjBDHcJi+EfTvNW9O1bnn6Oh5FTezIeMSFGxRC k3QQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=7A4jfFU8caPfA3i6HwoNwb39+7mY+fpdaRh+dIM26SA=; b=sHna3nLwmLNSXBvbmyTajqQPwgIhkDY5usP9zwWB9qUW/GmFBegU1x7ZIGqNaSopSB EAWOywS20DsDSr6ChyYmi435j11FdPbHTe1viwMiK0pCMvy2D6U0/VXfo4oK8nzAzIB4 qwiVHdEmV3oBpkoGDdTj/niDRbtEIvxjDAJKKi31wUfz0uRzdvH8mhIUygjjMymRKjAm RwdCgolLgzWhxzBhnZnR50TkMoZBr0f4eHYOLWjZ0/oOqxGR8wQGSMdIT4n01KVPPtt+ bZ7cIclhbPVuAjRDSGEskc9SnAOSlHusK1wma+BHCAiQdMH/rRk9s3g/ZykmDzQavoLr wEEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bsOk7Z96; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j61-v6si2619148plb.395.2018.02.22.03.20.06; Thu, 22 Feb 2018 03:20:21 -0800 (PST) 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; dkim=pass header.i=@linaro.org header.s=google header.b=bsOk7Z96; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753737AbeBVLS6 (ORCPT + 99 others); Thu, 22 Feb 2018 06:18:58 -0500 Received: from mail-it0-f65.google.com ([209.85.214.65]:54940 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753531AbeBVLS4 (ORCPT ); Thu, 22 Feb 2018 06:18:56 -0500 Received: by mail-it0-f65.google.com with SMTP id p204so5842380itc.4 for ; Thu, 22 Feb 2018 03:18:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7A4jfFU8caPfA3i6HwoNwb39+7mY+fpdaRh+dIM26SA=; b=bsOk7Z96vGfOWYpv0peGIIWdiLR7zmtZcYqg2t2o8PJDyqaTz98JrH+V0lO+l9vpXU uj/c288M6NSvLMG3/g2ydpCZMVcmBkz+U9W42a1UqV2XDKItPQzdn/oidTw9gheE5tKh VwC1YGO+4LwNHu5SnwNY92ea3JCzIwYfdQcos= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7A4jfFU8caPfA3i6HwoNwb39+7mY+fpdaRh+dIM26SA=; b=b6zSaWMzu/m/SJgJz9tgChJLh3PQREEVRovdqIZwDyFfUD2XHcHBGYWydRvjLkeOZm hBtj2IwgopDvoKNQ5XhHHCUWuKHyhkbHXw7/d8UBQ7q8Kb0Liap7oPLCm656B5FrrGr3 fmEyvliHRItXlqzxXs2maQKOBX39cCp5WMmzSJB5wLF24b/qXJQ7wqIG/FI/HDQXWF/4 SL+K7s0mpNu1o5PWhwS3fNXEwTx6ua2VmXbeajSXyx8B986RhZPFF7lEux81HhlpUZmE 0JePZ6Qf6RctF8QskMwroLVRThM+cneTo9g/nHAER4D7xQntzYs3xqzoVGQjDXJGz99T G44A== X-Gm-Message-State: APf1xPD3JxoASCO4LdTRU+Nrj0puaPB9TsN/Nr/ekVIZxOBIZQFO9Bst gqlPJKFPhCxGmaFoL0fVPXIiEg== X-Received: by 10.36.147.133 with SMTP id y127mr7130430itd.12.1519298336341; Thu, 22 Feb 2018 03:18:56 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id y6sm27550818iod.7.2018.02.22.03.18.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Feb 2018 03:18:55 -0800 (PST) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, bauerman@linux.vnet.ibm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, mpe@ellerman.id.au, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org, julien.thierry@arm.com Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro , Linus Torvalds Subject: [PATCH v8 01/13] resource: add walk_system_ram_res_rev() Date: Thu, 22 Feb 2018 20:17:20 +0900 Message-Id: <20180222111732.23051-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180222111732.23051-1-takahiro.akashi@linaro.org> References: <20180222111732.23051-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This function, being a variant of walk_system_ram_res() introduced in commit 8c86e70acead ("resource: provide new functions to walk through resources"), walks through a list of all the resources of System RAM in reversed order, i.e., from higher to lower. It will be used in kexec_file implementation on arm64. Signed-off-by: AKASHI Takahiro Cc: Vivek Goyal Cc: Andrew Morton Cc: Linus Torvalds --- include/linux/ioport.h | 3 +++ kernel/resource.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/include/linux/ioport.h b/include/linux/ioport.h index da0ebaec25f0..f12d95fe038b 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -277,6 +277,9 @@ extern int walk_system_ram_res(u64 start, u64 end, void *arg, int (*func)(struct resource *, void *)); extern int +walk_system_ram_res_rev(u64 start, u64 end, void *arg, + int (*func)(struct resource *, void *)); +extern int walk_iomem_res_desc(unsigned long desc, unsigned long flags, u64 start, u64 end, void *arg, int (*func)(struct resource *, void *)); diff --git a/kernel/resource.c b/kernel/resource.c index e270b5048988..bdaa93407f4c 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include @@ -486,6 +488,61 @@ int walk_mem_res(u64 start, u64 end, void *arg, arg, func); } +int walk_system_ram_res_rev(u64 start, u64 end, void *arg, + int (*func)(struct resource *, void *)) +{ + struct resource res, *rams; + int rams_size = 16, i; + int ret = -1; + + /* create a list */ + rams = vmalloc(sizeof(struct resource) * rams_size); + if (!rams) + return ret; + + res.start = start; + res.end = end; + res.flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY; + i = 0; + while ((res.start < res.end) && + (!find_next_iomem_res(&res, IORES_DESC_NONE, true))) { + if (i >= rams_size) { + /* re-alloc */ + struct resource *rams_new; + int rams_new_size; + + rams_new_size = rams_size + 16; + rams_new = vmalloc(sizeof(struct resource) + * rams_new_size); + if (!rams_new) + goto out; + + memcpy(rams_new, rams, + sizeof(struct resource) * rams_size); + vfree(rams); + rams = rams_new; + rams_size = rams_new_size; + } + + rams[i].start = res.start; + rams[i++].end = res.end; + + res.start = res.end + 1; + res.end = end; + } + + /* go reverse */ + for (i--; i >= 0; i--) { + ret = (*func)(&rams[i], arg); + if (ret) + break; + } + +out: + vfree(rams); + return ret; +} + #if !defined(CONFIG_ARCH_HAS_WALK_MEMORY) /* -- 2.16.2