From patchwork Thu Feb 22 11:17:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 129204 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp481221lja; Thu, 22 Feb 2018 03:19:02 -0800 (PST) X-Google-Smtp-Source: AH8x224lXyr4tFZQ3xa1eJJ6VSZkOcgt5ZVuA4CihOZdluRK4XIqFFIa1Tb9p/6AG+h++x3u4ECI X-Received: by 2002:a17:902:2bc5:: with SMTP id l63-v6mr6361707plb.108.1519298342005; Thu, 22 Feb 2018 03:19:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519298341; cv=none; d=google.com; s=arc-20160816; b=eCZi+LtVjM4aIxUyPtUrBi12hnKDBApll3v/gIKp21vgwlOv1ISaVBnLtNMVoPoMny IXZIm8dNKuMXK4hviJ8y/++zWEgoPDUNctGOzFWqEJHJEhj3nJDcpfL/DXa3N0uhZQk4 PRtntYt2Ek+UZn3VTocP8fgf2oXw7OAD99MmDHfZeMEPOTW16ersGYSxQbhUe4B736hv rEfcxPS4JzznCgkOCes5dk+4vEBer2AT4GkYyxxixBjka1wrjNkrN/XWt/VgUvUJMyDL Y1IdOA7Np8PYVhcxuagn/NxSLZXX5Ma8TAmtfLdU6zucd7aQXrqEi6S2Zlj90S/YgCMV 7B9A== 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 e17si7343232pgo.189.2018.02.22.03.19.01; Thu, 22 Feb 2018 03:19:01 -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 S1753741AbeBVLS6 (ORCPT + 28 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(+) -- 2.16.2 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) /*