From nobody Sat Nov 09 20:19:16 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Xm6bT2Xc8z5ccqV; Sat, 09 Nov 2024 20:19:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Xm6bT14R6z4fDb; Sat, 9 Nov 2024 20:19:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1731183557; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=anIVAgU6NpIrHor5cyZcDV7IN2feHJsfix6CoIBH4e8=; b=qE5Pd9r1C1y7pOLSOc/DePTv5Y3XktI/je82hbFfsipBvFRC6GUGZ2rPL7vskK6zKU0Q/B +mck4hKSF15WG+egnNBJIspKtNp1ooSNmrwL3FuOhUIQ0zRtZEJFnL22xs4TbSHyfE4aZ2 Qk5/+h06LY2YwL0YZPAazElnoJELRGkr0aOORB6wbWjZhCcNscd0LO1w1RIBhmbhpHBFA+ 3FUuSERdqlyLiGPWhpMuxAfJ+LF6UI0HMw/Nlw6/49C6rJKmp75PAZK58oeBWXP9tLAp+4 NgfqO4KdmuUAbsBQk8NO/Omh9C+A3QjxrcwIWksEUy993lisALhaw/aCBo4Dzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1731183557; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=anIVAgU6NpIrHor5cyZcDV7IN2feHJsfix6CoIBH4e8=; b=lV6vzq8F5pHWHjjF8Ido/wGSNrcyy1br9ed0z9fGywy2l3LEL7KHTCuHbF9JcEOgQ/Qxfi Cfq/neDUCrOEDDOfD+rQc7zoP4kuLlMIs0wdw2yW2S45WTLlpejaqd3ntlBlimumdtHYyH vzD1K2pSJRz7UXSfv8wilU+er98//Cl4Taq8kseoi6HPcnGSfA8SmaGr4Z9UIsHRQXd0OF YzscCHTCrVSnfG8cFAsslqES3PhBH3fYjEUq11keS4PwSk4bF2ZN1LU+tkbsn6t5DqetfA k+iWFLoGRhrzX0d3c2R4kJe7ERH6gqBP5G6HSQRkl6JybYp20BZY2xSs8TJ8fA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1731183557; a=rsa-sha256; cv=none; b=r+LG8B4o79kHxqSc96ELpZe0iOwvLZfLbfS360G8CPqH+bu+huF1ul4FONyFAh5b7we3Q+ ZSVdkYSOKEbM4el503f3c+sK4I0y46a09BVycqJWbMKUtHqfmtTpsMx61h3BDmufWecSyQ O8srluCyVjpfm1UPEBGBxPvzZls/1ZFuNQXiiQCmMs5CyQd4jUkDKhUFYdrt4H4wbr3YnR V4D+ZUKyNuyEbgWtzAmvGvzkYRt33I9zSalD3H2S7hCAMGzCnyxie6v3fDpr9WpNjfn9dl GvSOC/A95hYLVk9u9q8WK2AcxcojXZj4eXqXMHDwlehRZ+qqXoV5jXVVhVxheg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Xm6bS6hcyz1RBX; Sat, 9 Nov 2024 20:19:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4A9KJG3j033564; Sat, 9 Nov 2024 20:19:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4A9KJGZB033561; Sat, 9 Nov 2024 20:19:16 GMT (envelope-from git) Date: Sat, 9 Nov 2024 20:19:16 GMT Message-Id: <202411092019.4A9KJGZB033561@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 83217f087be7 - stable/14 - amdiommu: changes for stable/14 merge List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 83217f087be7de6e250039ca757e5d37facff72a Auto-Submitted: auto-generated The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=83217f087be7de6e250039ca757e5d37facff72a commit 83217f087be7de6e250039ca757e5d37facff72a Author: Konstantin Belousov AuthorDate: 2024-11-09 19:29:26 +0000 Commit: Konstantin Belousov CommitDate: 2024-11-09 19:31:25 +0000 amdiommu: changes for stable/14 merge to accomodate lack of ilog2() on stable/14. Done as separate commit to ease future cherry-picks. Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation --- sys/x86/iommu/amd_cmd.c | 4 ++-- sys/x86/iommu/amd_ctx.c | 2 +- sys/x86/iommu/amd_drv.c | 2 +- sys/x86/iommu/amd_event.c | 2 +- sys/x86/iommu/amd_intrmap.c | 2 +- sys/x86/iommu/x86_iommu.h | 10 ++++++++++ 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/sys/x86/iommu/amd_cmd.c b/sys/x86/iommu/amd_cmd.c index bbc2a8e0ad9f..384d92066e36 100644 --- a/sys/x86/iommu/amd_cmd.c +++ b/sys/x86/iommu/amd_cmd.c @@ -320,7 +320,7 @@ amdiommu_init_cmd(struct amdiommu_unit *unit) { uint64_t qi_sz, rv; - unit->x86c.qi_buf_maxsz = ilog2(AMDIOMMU_CMDBUF_MAX / PAGE_SIZE); + unit->x86c.qi_buf_maxsz = ilog2_local(AMDIOMMU_CMDBUF_MAX / PAGE_SIZE); unit->x86c.qi_cmd_sz = AMDIOMMU_CMD_SZ; iommu_qi_common_init(AMD2IOMMU(unit), amdiommu_qi_task); get_x86_iommu()->qi_ensure = amdiommu_cmd_ensure; @@ -334,7 +334,7 @@ amdiommu_init_cmd(struct amdiommu_unit *unit) * See the description of the ComLen encoding for Command * buffer Base Address Register. */ - qi_sz = ilog2(unit->x86c.inv_queue_size / PAGE_SIZE) + 8; + qi_sz = ilog2_local(unit->x86c.inv_queue_size / PAGE_SIZE) + 8; rv |= qi_sz << AMDIOMMU_CMDBUF_BASE_SZSHIFT; AMDIOMMU_LOCK(unit); diff --git a/sys/x86/iommu/amd_ctx.c b/sys/x86/iommu/amd_ctx.c index b3e85350a995..81e284373fc8 100644 --- a/sys/x86/iommu/amd_ctx.c +++ b/sys/x86/iommu/amd_ctx.c @@ -462,7 +462,7 @@ dte_entry_init_one(struct amdiommu_dte *dtep, struct amdiommu_ctx *ctx, if (unit->irte_enabled) { dtep->iv = 1; dtep->i = 0; - dtep->inttablen = ilog2(unit->irte_nentries); + dtep->inttablen = ilog2_local(unit->irte_nentries); dtep->intrroot = pmap_kextract(unit->irte_x2apic ? (vm_offset_t)ctx->irtx2 : (vm_offset_t)ctx->irtb) >> 6; diff --git a/sys/x86/iommu/amd_drv.c b/sys/x86/iommu/amd_drv.c index 395cefc65caa..5db7a5225538 100644 --- a/sys/x86/iommu/amd_drv.c +++ b/sys/x86/iommu/amd_drv.c @@ -236,7 +236,7 @@ amdiommu_create_dev_tbl(struct amdiommu_unit *sc) sc->devtbl_obj->domain.dr_policy = DOMAINSET_PREF(dom); sc->hw_ctrl &= ~AMDIOMMU_CTRL_DEVTABSEG_MASK; - sc->hw_ctrl |= (uint64_t)segnum_log << ilog2(AMDIOMMU_CTRL_DEVTABSEG_2); + sc->hw_ctrl |= (uint64_t)segnum_log << 34; /* ilog2(AMDIOMMU_CTRL_DEVTABSEG_2) */ sc->hw_ctrl |= AMDIOMMU_CTRL_COHERENT; amdiommu_write8(sc, AMDIOMMU_CTRL, sc->hw_ctrl); diff --git a/sys/x86/iommu/amd_event.c b/sys/x86/iommu/amd_event.c index 4a52e42260c2..d4be79474c6a 100644 --- a/sys/x86/iommu/amd_event.c +++ b/sys/x86/iommu/amd_event.c @@ -285,7 +285,7 @@ amdiommu_init_event(struct amdiommu_unit *unit) "amdiommu%d event taskq", unit->iommu.unit); base_reg = pmap_kextract((vm_offset_t)unit->event_log) | - (((uint64_t)0x8 + ilog2(unit->event_log_size / + (((uint64_t)0x8 + ilog2_local(unit->event_log_size / AMDIOMMU_EVNTLOG_MIN)) << AMDIOMMU_EVNTLOG_BASE_SZSHIFT); AMDIOMMU_LOCK(unit); /* diff --git a/sys/x86/iommu/amd_intrmap.c b/sys/x86/iommu/amd_intrmap.c index a4c1a7836268..c5c1706f1f3e 100644 --- a/sys/x86/iommu/amd_intrmap.c +++ b/sys/x86/iommu/amd_intrmap.c @@ -374,7 +374,7 @@ amdiommu_init_irt(struct amdiommu_unit *unit) nentries = 32; TUNABLE_INT_FETCH("hw.iommu.amd.ir_num", &nentries); - nentries = roundup_pow_of_two(nentries); + nentries = roundup_pow_of_two_local(nentries); if (nentries < 1) nentries = 1; if (nentries > 2048) diff --git a/sys/x86/iommu/x86_iommu.h b/sys/x86/iommu/x86_iommu.h index eb4a9907a5d6..835a4623a95e 100644 --- a/sys/x86/iommu/x86_iommu.h +++ b/sys/x86/iommu/x86_iommu.h @@ -200,4 +200,14 @@ void iommu_db_print_ctx(struct iommu_ctx *ctx); void iommu_db_domain_print_contexts(struct iommu_domain *iodom); void iommu_db_domain_print_mappings(struct iommu_domain *iodom); +static __inline __pure2 int +ilog2_local(int n) +{ + KASSERT(n != 0, ("ilog argument must be nonzero")); + return (8 * sizeof(n) - 1 - __builtin_clz((u_int)n)); +} + +#define order_base_2_local(n) ilog2_local(2*(n)-1) +#define roundup_pow_of_two_local(n) ((__typeof(n))1 << order_base_2_local(n)) + #endif