From patchwork Mon Apr 18 19:50:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tommaso Merciai X-Patchwork-Id: 1920 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id E2F913F1D0 for ; Mon, 18 Apr 2022 21:50:30 +0200 (CEST) Received: by mail-ej1-f71.google.com with SMTP id nc17-20020a1709071c1100b006e8aeb94fa7sf4928817ejc.11 for ; Mon, 18 Apr 2022 12:50:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1650311430; cv=pass; d=google.com; s=arc-20160816; b=0fEMwePb0IlVOuuk9jSc3dAocpNj2UzowtQGUA8LX9JVjmGgvajz1DE6E5dFD8Eode i9lw5cGPysqGZo9dNzmDfOOFa8HCIjI3ANKkhWbK4ukT1brLCTy0ICoFIhBQEy4HoCfK MIjSDrrSMNUC1CRzL6A1d5kXdfZN3Tz0WOk+AJcgUNVyab9N1b2OjC/eYWTN3wmEq2Oa TPj+hmtNSNdGgUECp96QUDY/WtBXRP0XvxbqDd+lhKRJORrsTfn4Uk7oeN9LmKTqqP7y rSjauBZTFp7jrqQV4YyVH0det/mg2p2PBWdsyDhlI/uJ1Xi5ZkZemtDwnvVAKBSulWmB ym1A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:message-id:date:subject:cc:to :from:dkim-signature; bh=TI0trGcZ0ZHTz6RlLC37NCBkzftZpenygSSgFAgfIH0=; b=IrYZB5h8BAMiL10hSRu/KOKiEHPwxaroLVrfeXfy8+Wb5TGtyPaH2IMI3nCLlp7BcM +bFJ4UPLj4xiM5bxirsmZi6ZBqaTRCbIao9n3+fERWMBwopQHV3ChH/Bpo0woNIAuxTA K1fK9K6nhgwiGsDDtuwy6xcJYMGSZ3ir0deM1jxvFmoDZjo+UOZlEoMijGuda0Z9zuy5 BMdTKvugkldSEFMEP7qYghNTNUGQmhmrrM7h+EdVaO5e/I6zrcxMOUHax3wjRBqevQPC uyS+MKT+vKKvugAYQDnMJRIW0pNPapIkGCjD/rc1WsJaTgHReZoeDuW2+51x0cKHCwsT 8EIg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=PpwrCaZi; spf=pass (google.com: domain of tommaso.merciai@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=tommaso.merciai@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=TI0trGcZ0ZHTz6RlLC37NCBkzftZpenygSSgFAgfIH0=; b=a1S+aeIWiRqwOLgvtL86bH/idcmMSNS5wXc17CFLUg6GPz8k6WUovSy00SHoeWs1LL ak7Ymx52BkwB+abo7SrSzRzm0rH8q4anX9IvWnCpZ4R3fgtRIxDHZA8n0HT5kyi3dYI1 e6rdtwGWGzvlCcYSFmGFfmj1BDsIuPunGSv+8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:x-spam-checked-in-group:list-post:list-help :list-archive:list-unsubscribe; bh=TI0trGcZ0ZHTz6RlLC37NCBkzftZpenygSSgFAgfIH0=; b=6xPFJYKz4PC3ldV/ij1KowlC096NW2qxWPuO7H3q4Lo8Jd5iAfOxswxKx4Cmz1CT7z Rekx1TUEmPdN1YOS9mIPbkUK+QJljcBEr+DhEV+PipWC5c3tr9ByFdqZ8IbV1wwPatg4 ElcbvveNfFYoLLsl6JMBfF1X5p/55VJ9sZDDd3Nhlv7Ic/otcPLO1Cbfv/FRmkvd7Gc+ kF6tKYWzbZajajxAt5OlXUF29VXjAvYn5umHxLaY9nH1jOcN1uzqRAxvB6L16KWYISX9 RdNUVY2NRbZE/nVGLPvKYp3tJQpOWt0sa9gg59NoEl0jbqjzyJ5ZrLuIh81f+QVF9u1W aoTA== X-Gm-Message-State: AOAM533cGkXXiO9jR04qQGd5tkdSpFcAIyLSYzzOD0ngUmo/vOG4lXh7 pH3mI9UjRw9FUHm9N4we/2/fu03c X-Google-Smtp-Source: ABdhPJxYYkNLMt5p1mSOstk0cMOnNh9g+IXv/Fjuy2jRmKOnL6jxivJy5hj9yJbTyzfABR30atisbw== X-Received: by 2002:a17:907:3f86:b0:6df:ad43:583 with SMTP id hr6-20020a1709073f8600b006dfad430583mr10647243ejc.535.1650311430697; Mon, 18 Apr 2022 12:50:30 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:628e:b0:6e8:76c2:5876 with SMTP id nd14-20020a170907628e00b006e876c25876ls3641671ejc.7.gmail; Mon, 18 Apr 2022 12:50:29 -0700 (PDT) X-Received: by 2002:a17:906:79c4:b0:6cf:5489:da57 with SMTP id m4-20020a17090679c400b006cf5489da57mr10278686ejo.48.1650311429553; Mon, 18 Apr 2022 12:50:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650311429; cv=none; d=google.com; s=arc-20160816; b=0vJ1Ht7unwgRquipdNWxjHWAFAgAFxQdsbLX5TsoddSaIb0l9IX6/L99JTTtkoNFke DHkhidFVXR8iY88BI3elWzLgpu3fw3EBK3dxw2YjjZfCAyFISwN0aVGNf4lXsIBNkuNX i14PZOGHwxcPQkFo41Rx64irXW7oRuQxG9HMtIGteAphorFlnfE1wK4LDVS6MCmiqjl9 ZPhrhsEha9bIwn2CiFkwClUXA/tbvo/pJ+ckKObuZfHPNUHvhus6ZqtH2U9Y+Sz7PwNf sZShH+Pk/RPVOJ4eB3dKuedbALulG0y3kH+2sRTilFGtlLbzfHAMsGUe4evF6TUrmmZA +yGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=8W4JvjnssEQyMSZy+HrjEbTbjuY0PZ4eK5T5lTabnwU=; b=t8uK9m+cH1e0WDkH7lHRWIIq7J3nyrvLcNf6K0iGigJ+QNa80lFlWIsfKi0kTbYso8 2GWs0qzBCrh6LnAN1pyjaqhbd9SoohW4W4iqqflKCDxbo6f+cPPo6jgr2iSr4p8Oax1y UdSqKFhyu7UXnHBxs2CmhAy79X8jMJG9CTpSlsFOZB38N7U4dm+yEV0oi8t8o5JHe4lg zCyX97zc4S3PqNtdFeaSiUYVTz9HGDhc4WnMdP2/ia6sW0mIblW/pGVDEsfLv1NZZ6C9 +LbVdXmot7iJ9pIVv/aYwiS4H8Qo4xOlzyl7qpMK6LP7yaiL5z6/AIbEaJReSpn+v0r0 NxmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=PpwrCaZi; spf=pass (google.com: domain of tommaso.merciai@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=tommaso.merciai@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id ga12-20020a170906b84c00b006e89f26a2c7sor3475657ejb.116.2022.04.18.12.50.29 for (Google Transport Security); Mon, 18 Apr 2022 12:50:29 -0700 (PDT) Received-SPF: pass (google.com: domain of tommaso.merciai@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a17:907:d8d:b0:6df:b214:392a with SMTP id go13-20020a1709070d8d00b006dfb214392amr10441451ejc.669.1650311429256; Mon, 18 Apr 2022 12:50:29 -0700 (PDT) Received: from tom-ThinkPad-T14s-Gen-2i.station (net-188-217-56-163.cust.vodafonedsl.it. [188.217.56.163]) by smtp.gmail.com with ESMTPSA id o3-20020a170906774300b006e79ea98369sm4882406ejn.151.2022.04.18.12.50.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 12:50:29 -0700 (PDT) From: Tommaso Merciai To: Cc: tommaso.merciai@amarulasolutions.com, linux-amarula@amarulasolutions.com, Michael Trimarchi , Simon Glass , u-boot@lists.denx.de Subject: [PATCH] common: fdt: introduce fdt_fixup_reserved_memory Date: Mon, 18 Apr 2022 21:50:26 +0200 Message-Id: <20220418195027.11407-1-tommaso.merciai@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Original-Sender: tommaso.merciai@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=PpwrCaZi; spf=pass (google.com: domain of tommaso.merciai@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=tommaso.merciai@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The intent of fdt_fixup_reserved_memory is to reserve memory and prevent it from being included in the kernel's linear map from U-Boot. This is done by creating a no-map zone into reserved-memory region no-map (optional) - empty property Indicates the operating system must not create a virtual mapping of the region as part of its standard mapping of system memory, nor permit speculative access to it under any circumstances other than under the control of the device driver using the region. References: - Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt Signed-off-by: Tommaso Merciai Developed-by: Michael Trimarchi Tested-by: Tommaso Merciai --- common/fdt_support.c | 53 +++++++++++++++++++++++++++++++++++++++++++ include/fdt_support.h | 11 +++++++++ 2 files changed, 64 insertions(+) diff --git a/common/fdt_support.c b/common/fdt_support.c index ea18ea3f04..7cfaf4310c 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -412,6 +412,59 @@ static int fdt_pack_reg(const void *fdt, void *buf, u64 *address, u64 *size, return p - (char *)buf; } +int fdt_fixup_reserved_memory(void *blob, const char *name, u64 start[], u64 size[]) +{ + int offs, len, err; + const char *subpath; + const char *path = "/reserved-memory"; + fdt32_t address_cells = cpu_to_fdt32(fdt_address_cells(blob, 0)); + fdt32_t size_cells = cpu_to_fdt32(fdt_size_cells(blob, 0)); + u8 temp[16]; /* Up to 64-bit address + 64-bit size */ + + offs = fdt_path_offset(blob, path); + if (offs < 0) { + debug("Node %s not found\n", path); + path = "/"; + subpath = "reserved-memory"; + offs = fdt_path_offset(blob, path); + offs = fdt_add_subnode(blob, offs, subpath); + if (offs < 0) { + printf("Could not create %s%s node.\n", path, subpath); + return -1; + } + path = "/reserved-memory"; + offs = fdt_path_offset(blob, path); + + fdt_setprop(blob, offs, "#address-cells", &address_cells, sizeof(address_cells)); + fdt_setprop(blob, offs, "#size-cells", &size_cells, sizeof(size_cells)); + fdt_setprop(blob, offs, "ranges", NULL, 0); + } + + offs = fdt_add_subnode(blob, offs, name ? : "private"); + if (offs < 0) { + printf("Could not create %s%s node.\n", path, subpath); + return -1; + } + + err = fdt_setprop(blob, offs, "no-map", NULL, 0); + if (err < 0) { + printf("WARNING: could not set %s %s.\n", + "no-map", fdt_strerror(err)); + return err; + } + + len = fdt_pack_reg(blob, temp, start, size, 1); + + err = fdt_setprop(blob, offs, "reg", temp, len); + if (err < 0) { + printf("WARNING: could not set %s %s.\n", + "reg", fdt_strerror(err)); + return err; + } + + return 0; +} + #if CONFIG_NR_DRAM_BANKS > 4 #define MEMORY_BANKS_MAX CONFIG_NR_DRAM_BANKS #else diff --git a/include/fdt_support.h b/include/fdt_support.h index ac76939e81..0ade91a08f 100644 --- a/include/fdt_support.h +++ b/include/fdt_support.h @@ -93,6 +93,17 @@ void do_fixup_by_compat_u32(void *fdt, const char *compat, */ int fdt_fixup_memory(void *blob, u64 start, u64 size); +/** + * Setup the memory reserved node in the DT. Creates one if none was existing before. + * + * @param blob FDT blob to update + * @param name Reserved area name + * @param start Begin of DRAM mapping in physical memory + * @param size Size of the single memory bank + * @return 0 if ok, or -1 or -FDT_ERR_... on error + */ +int fdt_fixup_reserved_memory(void *blob, const char *name, u64 start[], u64 size[]); + /** * Fill the DT memory node with multiple memory banks. * Creates the node if none was existing before.