Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp7061951rwn; Tue, 13 Sep 2022 13:14:46 -0700 (PDT) X-Google-Smtp-Source: AA6agR441h2SgF27/w1lBOPBrwm6MGJu/Zkgb9pYxSC7wi+ixNbEPNDeqp97gbvnMo6xF/jDG4lw X-Received: by 2002:a63:6683:0:b0:42b:1d69:a0ff with SMTP id a125-20020a636683000000b0042b1d69a0ffmr29285447pgc.475.1663100086377; Tue, 13 Sep 2022 13:14:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663100086; cv=none; d=google.com; s=arc-20160816; b=RYJSHOY3SJIzF6dNZACHYBlXzfMatFuKm9zYCVg7EZAGnNvGlKzwf5eHhzTH2ior21 aSXi+PXpzTd6eDIDKmyL22VbzkDkYeHL+4iQ0CgkeB4+b5Rric2GZ82OP195XzkoePQ1 xgNNxZgEwAUCE4WNM7SKanv1JahTW1A4mvUg+9NaYpBLbvXBRSI5d2RSQV/kEP2QyRUe rflelYjGtJMvGTFHFToD1ZQFwn1LCyas0yc76Mq6Zl8uRmX12eK4Ptlhu6b7xkB8whds JOaZw/vURxfOAIfLJR8oUofCdv0mADiEfauIzZd9aMRTkY+UFkDlkiQMU5lx5zXO6l18 ErRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=U4jOrSu6bqJBytWJghR6t0ljWrrZGLSB9ph/v+e9V8I=; b=qoHYA7Al2Yp5ZNGmj1KnuAH+f97MT94iQ9FX1Dd9BgSs9CtfckTuYI/CSp0dAd0u3i CfjfFg6tZRRmitZm5bueHfDem0FSgf+qPjRNR9K/9mOEbhWkxzw72cuLVcWO3pbC5/yT yZhvo+GFFvjhOIweonwnn0ywnDHbice3la3LPzWekyQksXJZVsegoI6xihxJPAY1iafO MoXcbsiRh48jG/EPrgClZsxHxL314NQ3o8M2Bm4S/QH2s3XwEOVVOb1luLvHFX7ebrVD EoGPlWoujEVIhTmzEA/oacNq1KJ5lq4zYfVOJA6L7vB4FJ7oP4ODGmU/WMCt+VEhsQDh sprg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="D/mTJk6k"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x18-20020a62fb12000000b0052e802c48c3si10928022pfm.107.2022.09.13.13.14.33; Tue, 13 Sep 2022 13:14:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="D/mTJk6k"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229965AbiIMUAO (ORCPT + 99 others); Tue, 13 Sep 2022 16:00:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230029AbiIMT7T (ORCPT ); Tue, 13 Sep 2022 15:59:19 -0400 Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8E71792D0; Tue, 13 Sep 2022 12:58:57 -0700 (PDT) Received: by mail-qk1-x733.google.com with SMTP id i3so4616430qkl.3; Tue, 13 Sep 2022 12:58:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=U4jOrSu6bqJBytWJghR6t0ljWrrZGLSB9ph/v+e9V8I=; b=D/mTJk6kZw64eyUhHPaSFfxR9Msa5UBxyOTlcsmCwhUVjiAhTk7oqnxftuemkUJs0o e/3ecILYiDZtf1ZduEhchjc87lM/UzBWANhyHjDCeSCCZZ+OsXTubHr/HBHsItOzKdH7 p/GQO/8nQMFRqeejgZsBOVzCwSXLRfYO2jhkP7CDsujDhgqd9989s5l2qAcx+CNYHM2D 3FzlZrQmr76F2aSmz5wNYnpRQxzHx962ONlutGAvPr/+dXcOvxUiHsk1k1ee7yaWbHVI 2LCJzHzqV9IGkV4gb1i+myYCzvATpnUG8sQPbUiE3I3lJUeSHhrVFH3mITfi1tyJU0b1 X7Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=U4jOrSu6bqJBytWJghR6t0ljWrrZGLSB9ph/v+e9V8I=; b=6tGerPA+8CLTaSTurXxfHH11caWZcpKkMd0d7u6ZQznwAYm2Lqstgix8JAC9XY2Ias PjBfiEnd2F57RC8cTQvztOyRLGzn+KN25OIc5glV8l8sZ8aCuSXM1z+3FOLa/rVNr8Z2 ZQ4MUlcCZoEf8JbHCUi+QirGDEZppS3zHNO/x7BcodkzQ+Of+5hOZONZxILgYLq14eOU Nhle7ekgTmWIP57OvyhCMkVxLVhoouA+fbxnT68XH9yll0MK7Lr+BRC9os5aDaCGrNpe QnkIi9LK8nZPqffy6uKUYMa7+l6fn8Q4roBC3aqYDbb4+ZDet5EPhm6DibH1EgAJoQCL bsGw== X-Gm-Message-State: ACgBeo0u1sLYwclovlWZGsAQhjYhUGpEZ5wc506+TDJwKe4CSJ8D2sva 2jos7PqMzIl8gLZjY6e3pRo= X-Received: by 2002:a05:620a:2452:b0:6bb:d8ba:ca65 with SMTP id h18-20020a05620a245200b006bbd8baca65mr24199159qkn.263.1663099136924; Tue, 13 Sep 2022 12:58:56 -0700 (PDT) Received: from stbirv-lnx-3.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id s11-20020a05620a29cb00b006b8e049cf08sm276305qkp.2.2022.09.13.12.58.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Sep 2022 12:58:56 -0700 (PDT) From: Doug Berger To: Andrew Morton Cc: Jonathan Corbet , Rob Herring , Krzysztof Kozlowski , Frank Rowand , Mike Kravetz , Muchun Song , Mike Rapoport , Christoph Hellwig , Marek Szyprowski , Robin Murphy , Borislav Petkov , "Paul E. McKenney" , Neeraj Upadhyay , Randy Dunlap , Damien Le Moal , Doug Berger , Florian Fainelli , David Hildenbrand , Zi Yan , Oscar Salvador , Hari Bathini , Kees Cook , - , KOSAKI Motohiro , Mel Gorman , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-mm@kvack.org, iommu@lists.linux.dev Subject: [PATCH 17/21] mm/dmb: introduce rmem designated-movable-block Date: Tue, 13 Sep 2022 12:55:04 -0700 Message-Id: <20220913195508.3511038-18-opendmb@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220913195508.3511038-1-opendmb@gmail.com> References: <20220913195508.3511038-1-opendmb@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This commit allows Designated Movable Blocks to be created by including reserved-memory child nodes in the device tree with the "designated-movable-block" compatible string. Signed-off-by: Doug Berger --- drivers/of/of_reserved_mem.c | 15 ++++++--- mm/dmb.c | 64 ++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 5 deletions(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 65f3b02a0e4e..0eb9e8898d7b 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "of_private.h" @@ -113,12 +114,16 @@ static int __init __reserved_mem_alloc_size(unsigned long node, nomap = of_get_flat_dt_prop(node, "no-map", NULL) != NULL; - /* Need adjust the alignment to satisfy the CMA requirement */ - if (IS_ENABLED(CONFIG_CMA) - && of_flat_dt_is_compatible(node, "shared-dma-pool") - && of_get_flat_dt_prop(node, "reusable", NULL) - && !nomap) + if (of_flat_dt_is_compatible(node, "designated-movable-block")) { + /* Need adjust the alignment to satisfy the DMB requirement */ + align = max_t(phys_addr_t, align, DMB_MIN_ALIGNMENT_BYTES); + } else if (IS_ENABLED(CONFIG_CMA) + && of_flat_dt_is_compatible(node, "shared-dma-pool") + && of_get_flat_dt_prop(node, "reusable", NULL) + && !nomap) { + /* Need adjust the alignment to satisfy the CMA requirement */ align = max_t(phys_addr_t, align, CMA_MIN_ALIGNMENT_BYTES); + } prop = of_get_flat_dt_prop(node, "alloc-ranges", &len); if (prop) { diff --git a/mm/dmb.c b/mm/dmb.c index 9d9fd31089d2..8132d18542a0 100644 --- a/mm/dmb.c +++ b/mm/dmb.c @@ -90,3 +90,67 @@ void __init dmb_init_region(struct memblock_region *region) init_reserved_pageblock(page); } } + +/* + * Support for reserved memory regions defined in device tree + */ +#ifdef CONFIG_OF_RESERVED_MEM +#include +#include +#include + +#undef pr_fmt +#define pr_fmt(fmt) fmt + +static int rmem_dmb_device_init(struct reserved_mem *rmem, struct device *dev) +{ + struct dmb *dmb; + + dmb = (struct dmb *)rmem->priv; + if (dmb->owner) + return -EBUSY; + + dmb->owner = dev; + return 0; +} + +static void rmem_dmb_device_release(struct reserved_mem *rmem, + struct device *dev) +{ + struct dmb *dmb; + + dmb = (struct dmb *)rmem->priv; + if (dmb->owner == (void *)dev) + dmb->owner = NULL; +} + +static const struct reserved_mem_ops rmem_dmb_ops = { + .device_init = rmem_dmb_device_init, + .device_release = rmem_dmb_device_release, +}; + +static int __init rmem_dmb_setup(struct reserved_mem *rmem) +{ + unsigned long node = rmem->fdt_node; + struct dmb *dmb; + int err; + + if (!of_get_flat_dt_prop(node, "reusable", NULL) || + of_get_flat_dt_prop(node, "no-map", NULL)) + return -EINVAL; + + err = dmb_reserve(rmem->base, rmem->size, &dmb); + if (err) { + pr_err("Reserved memory: unable to setup DMB region\n"); + return err; + } + + rmem->priv = dmb; + rmem->ops = &rmem_dmb_ops; + pr_info("Reserved memory: created DMB at %pa, size %ld MiB\n", + &rmem->base, (unsigned long)rmem->size / SZ_1M); + + return 0; +} +RESERVEDMEM_OF_DECLARE(dmb, "designated-movable-block", rmem_dmb_setup); +#endif -- 2.25.1