From patchwork Wed Jul 31 18:16:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregor Haas X-Patchwork-Id: 1967257 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=pYbxkHE3; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=QSf69CsE; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WZ0fz3Zg9z20FK for ; Thu, 1 Aug 2024 04:16:59 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=JUekLn25zyBIOIsouGHCu6KWGnXscwuAoBodwA+/x9M=; b=pYbxkHE3N9HA5Y OOoWhdb7VrvxhjOaEgMCiEW9+JGuy8r54935riQcoyyBc0LiRrXkXofhlu+65nrtluS5jjlYplQx3 wtXO3BL+DkRsH9J6UzEu/riz7Nog+WcmTBi0U0z3t5HQzC5H3nO54kKvYzttgVSpImSd/k/Ua9yiy gfMyFseEqoxHP+X4CAxuyWVkSv0UuYH5wDzxuTOHrSnoN8lqI1r9XykZr5wXDF37cvdU91Rc72bn3 ikOQvkYiUc0HFReJidFHO22EY8L09hxYB04iddHYaXvrCfZlXZGgRHAdJJaMfSQdr7K07Rvt8OMMu XWUyFzKpm1BS8yVO5o+g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZDsW-000000026fF-1rix; Wed, 31 Jul 2024 18:16:48 +0000 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZDsT-000000026dS-34bA for opensbi@lists.infradead.org; Wed, 31 Jul 2024 18:16:47 +0000 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1fd640a6454so45987095ad.3 for ; Wed, 31 Jul 2024 11:16:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722449805; x=1723054605; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wMPQnMNsezHWrX53AMt/eHKOnpHJBaVjm8qopUPTs0o=; b=QSf69CsEBT4pwMNcnpEUV/qiljUrUmXqhgbDfTkn+VXu4AT1aMJTlyKSs9TCiIk4aN nWdFysPoiN9n/gbh5RP9v/uWVHxdHYTY5AoKJy92Zqc4ytDMUp/FNH+eY7quOTPlZMia vmAgpgktbwkVxTTdDtVGR4KLEEe+qFyCi0KDTEQBRV4ucxHmQpn0zCoPiGzBwDtohsmV 7FZRzFb6RLX64F27JFvXq1RjcpPCElAch0skb3YWPLtzK1NM+l/tKldCMGSY1Ox1tJZ9 mVcr8UQUF384jC1HNNZZPH10wotVUvrML//30lo4Y5ja8dSblVFcW/eUOxvMH0m5QYnj JOnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722449805; x=1723054605; 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:message-id:reply-to; bh=wMPQnMNsezHWrX53AMt/eHKOnpHJBaVjm8qopUPTs0o=; b=X2ZiIwMtnbbLOqtWrxNNhoEAqL3O4//Q1lLQIgDOhNNr/wgtZtuloR8GDChHsu/jwP EE2urtR/UJFF4qRzLN7WyVoVzkJfm4XFVf0/NR26GA767Ha9MIvAiJOmauyNWICSLJb+ 2Uir2luVolgRAAw6vb5YK3ZemYfF8MPCQAHROUkYEv88HN2e35Sx1KgZd0n0c8x+rzfs a8jrSh017GbNr+8rwJqdKz1kd6lg8ZxSNNyfbIwzgt1MqIEvXnQR8QGPwZJY3Af8Z+h5 YcRJrKGWAxKiIjMryKSznvIVReYMLIJZXX/dfNkEr4zyDbAE4Bwg8ECAajMzjbozj3yi sfsw== X-Gm-Message-State: AOJu0YyFWDQqmYrnxgThKl3+4T9WPsfwaCDR25n5wqF7bRq829885n7+ WSzhjQECd32X3popFKx9Kc+n4l7BikryaGeVbI1VGgzni/D4XzdLfGQJRCJ0 X-Google-Smtp-Source: AGHT+IGpZFnHVYGwKLfyY0MwMGDxCIJGfer14ZwMxHfeiTWZy8tqg5TX/pEnsroGLJoYth1LEXgYiQ== X-Received: by 2002:a17:902:f9c3:b0:1fc:60f1:1905 with SMTP id d9443c01a7336-1ff4d279f94mr1297125ad.61.1722449804698; Wed, 31 Jul 2024 11:16:44 -0700 (PDT) Received: from localhost ([136.27.11.53]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-1fed7fb497esm122723875ad.268.2024.07.31.11.16.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 Jul 2024 11:16:44 -0700 (PDT) From: Gregor Haas To: opensbi@lists.infradead.org Cc: atishp@rivosinc.com, Gregor Haas Subject: [PATCH 4/8] lib: sbi: memregion: Introduce memregion_start/end macros Date: Wed, 31 Jul 2024 11:16:25 -0700 Message-ID: <20240731181629.269898-5-gregorhaas1997@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240731181629.269898-1-gregorhaas1997@gmail.com> References: <20240731181629.269898-1-gregorhaas1997@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240731_111645_799530_527DDDB6 X-CRM114-Status: GOOD ( 10.60 ) X-Spam-Score: -1.8 (-) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Various disparate parts of the memregion handling code calculate the base and bounds of memregions. Standardize these calculations into two new macros: memregion_start() and memregion_end(). This will [...] Content analysis details: (-1.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:635 listed in] [list.dnswl.org] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [gregorhaas1997(at)gmail.com] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [gregorhaas1997(at)gmail.com] X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Various disparate parts of the memregion handling code calculate the base and bounds of memregions. Standardize these calculations into two new macros: memregion_start() and memregion_end(). This will reduce the amount of code changes later, when we make memregions keep track of raw sizes rather than rounded orders. --- include/sbi/sbi_memregion.h | 6 ++++++ lib/sbi/sbi_memregion.c | 23 ++++++++++------------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/include/sbi/sbi_memregion.h b/include/sbi/sbi_memregion.h index 0aa9a44..6e1b771 100644 --- a/include/sbi/sbi_memregion.h +++ b/include/sbi/sbi_memregion.h @@ -145,6 +145,12 @@ struct sbi_memregion { unsigned long flags; }; +#define memregion_start(reg) \ + ((reg)->base) + +#define memregion_end(reg) \ + ((reg)->order < __riscv_xlen) ? \ + (reg)->base + ((1UL << (reg)->order) - 1) : -1UL; /** * Initialize a domain memory region based on it's physical * address and size. diff --git a/lib/sbi/sbi_memregion.c b/lib/sbi/sbi_memregion.c index 4abd20a..8978793 100644 --- a/lib/sbi/sbi_memregion.c +++ b/lib/sbi/sbi_memregion.c @@ -37,10 +37,10 @@ void sbi_memregion_init(unsigned long addr, static bool is_region_subset(const struct sbi_memregion *regA, const struct sbi_memregion *regB) { - ulong regA_start = regA->base; - ulong regA_end = regA->base + (BIT(regA->order) - 1); - ulong regB_start = regB->base; - ulong regB_end = regB->base + (BIT(regB->order) - 1); + ulong regA_start = memregion_start(regA); + ulong regA_end = memregion_end(regA); + ulong regB_start = memregion_start(regB); + ulong regB_end = memregion_end(regB); if ((regB_start <= regA_start) && (regA_start < regB_end) && @@ -217,9 +217,8 @@ bool sbi_domain_check_addr(const struct sbi_domain *dom, (rflags & SBI_MEMREGION_SU_ACCESS_MASK) >> SBI_MEMREGION_SU_ACCESS_SHIFT); - rstart = reg->base; - rend = (reg->order < __riscv_xlen) ? - rstart + ((1UL << reg->order) - 1) : -1UL; + rstart = memregion_start(reg); + rend = memregion_end(reg); if (rstart <= addr && addr <= rend) { rmmio = (rflags & SBI_MEMREGION_MMIO) ? true : false; if (mmio != rmmio) @@ -239,9 +238,8 @@ static const struct sbi_memregion *find_region( struct sbi_memregion *reg; sbi_domain_for_each_memregion(dom, reg) { - rstart = reg->base; - rend = (reg->order < __riscv_xlen) ? - rstart + ((1UL << reg->order) - 1) : -1UL; + rstart = memregion_start(reg); + rend = memregion_end(reg); if (rstart <= addr && addr <= rend) return reg; } @@ -307,9 +305,8 @@ void sbi_domain_dump_memregions(const struct sbi_domain *dom, const char *suffix int i = 0, k; sbi_domain_for_each_memregion(dom, reg) { - rstart = reg->base; - rend = (reg->order < __riscv_xlen) ? - rstart + ((1UL << reg->order) - 1) : -1UL; + rstart = memregion_start(reg); + rend = memregion_end(reg); sbi_printf("Domain%d Region%02d %s: 0x%" PRILX "-0x%" PRILX " ", dom->index, i, suffix, rstart, rend);