From nobody Thu Jan 20 10:17:43 2022 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 4D964196AF07; Thu, 20 Jan 2022 10:17:44 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Jfdk00BCJz4ZVH; Thu, 20 Jan 2022 10:17:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642673864; 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=LdmC2duLk0FpMPwEadVbNnLbIrp+dkGzhu+taGGUH2Y=; b=NM6Oa4qLIoBMgwHugesVtdJ/NjH/fqccx87xvWvVbnCkeQNr8Ee4Hhrts0Eo1w6yZPzMUJ LV5mR/3JB2fO0bsk4ELGQAndSdPO7drRztDiPEDG86n6CoTv03tINtNoKt8RebKbIsPj9f DW8OA0paXcGAaGNSKilDls26iZznHoyIWSJAITbALYfdyzZfcVs+dDTsxq4D/Kpf2n7Z42 HP8SPmwA05e39GcxCTJnL4lz7V6DYXcMOprr0NXJdrBoRyv/AbPa2Fvn4kJ+0yahMiLr28 fQlE2m/slvlD0Y+Ag7aDJOjctEgoOf+PuMLxSpYRyMmwlpSyAYXivxt1hnvzpg== 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 CE56026371; Thu, 20 Jan 2022 10:17:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 20KAHhWJ005286; Thu, 20 Jan 2022 10:17:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20KAHhUn005285; Thu, 20 Jan 2022 10:17:43 GMT (envelope-from git) Date: Thu, 20 Jan 2022 10:17:43 GMT Message-Id: <202201201017.20KAHhUn005285@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Michal Meloun Subject: git: f277be277de7 - stable/13 - extres/clk: Add a method to detect the HW state of the clock gate. 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mmel X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: f277be277de7f950558adee423048ec10c97a2d0 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642673864; 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=LdmC2duLk0FpMPwEadVbNnLbIrp+dkGzhu+taGGUH2Y=; b=qWgQCi43ldNztVvDa5rPPND8JOwkTLc5G/GVPSYxGb4/JktdPW9PGACsbA/L3z7tX0wpCx GOE7Be7whrIkV7uac2iUV6oXYycpC6Yij/Qowp/Zy18OCWIgH35gBsOlOvZPRn1GLkM1px +WyzuAtxeDlkyvd9p3ZesB5C5ZfagdR/HvrAM9e3WIA9EznM4E1TzHbTNjJdRIkJ3Wx/2Y HnxBre3XFQTqDiDtvbRWtYmrdAVgjH0QC44t1O6HBgHtYCgCz4rmhTEXFRt3KfdG5YWQlO uWibmM7Zoy5gYANZ6kLlTyDzJ4aOSupNI0B39oU5xWC8PAydREjDyUOm6aMYIw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642673864; a=rsa-sha256; cv=none; b=BLOLhZCfdbCjISdcxLsy/ZFSs6oj0FtlRfLgvqHzXVrexgz9lfbPF3+65xugI5xslG48O4 O2GEiG1+Rf5aI3JxpHM/c1fHHBMV864K1a/3Zo6LlBw7BH3DYRSXo/AGkuI8mILXwnqEVK V9Z+dwOkF3JQ0H/fZS566pnnfVe75L39hSCBrq2r7cSpBszuFf1wbrG2H5fZRlaTndHs63 EARu4CD9f/dh3GPS24XaEwvEwmECCXB1IkDK4RFpKVaWX26T22FVCm/ZkhOCx/X71bgq3k z4f9G1Cbcf2xNFrYjv3r5xg7o/dukaaGB/hrI8s+xaypyMYY3bhi1I7TniA6PA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mmel: URL: https://cgit.FreeBSD.org/src/commit/?id=f277be277de7f950558adee423048ec10c97a2d0 commit f277be277de7f950558adee423048ec10c97a2d0 Author: Michal Meloun AuthorDate: 2021-12-24 11:18:49 +0000 Commit: Michal Meloun CommitDate: 2022-01-20 10:14:22 +0000 extres/clk: Add a method to detect the HW state of the clock gate. - add method to read gate enable/disable staust from HW - show gate status in sysctl clock dump MFC after: 1 week (cherry picked from commit 1a74d77f851212f8cc80e6b15e30c2b252b84d48) --- sys/dev/extres/clk/clk.c | 31 +++++++++++++++++++++++++++++++ sys/dev/extres/clk/clk_gate.c | 35 +++++++++++++++++++++-------------- sys/dev/extres/clk/clknode_if.m | 11 +++++++++++ 3 files changed, 63 insertions(+), 14 deletions(-) diff --git a/sys/dev/extres/clk/clk.c b/sys/dev/extres/clk/clk.c index 839f0f842a78..f4284fcd59ba 100644 --- a/sys/dev/extres/clk/clk.c +++ b/sys/dev/extres/clk/clk.c @@ -186,6 +186,7 @@ enum clknode_sysctl_type { CLKNODE_SYSCTL_PARENTS_LIST, CLKNODE_SYSCTL_CHILDREN_LIST, CLKNODE_SYSCTL_FREQUENCY, + CLKNODE_SYSCTL_GATE, }; static int clknode_sysctl(SYSCTL_HANDLER_ARGS); @@ -531,6 +532,8 @@ clknode_create(struct clkdom * clkdom, clknode_class_t clknode_class, struct clknode *clknode; struct sysctl_oid *clknode_oid; bool replaced; + kobjop_desc_t kobj_desc; + kobj_method_t *kobj_method; KASSERT(def->name != NULL, ("clock name is NULL")); KASSERT(def->name[0] != '\0', ("clock name is empty")); @@ -640,6 +643,22 @@ clknode_create(struct clkdom * clkdom, clknode_class_t clknode_class, clknode, CLKNODE_SYSCTL_FREQUENCY, clknode_sysctl, "A", "The clock frequency"); + + /* Install gate handler only if clknode have 'set_gate' method */ + kobj_desc = &clknode_set_gate_desc; + kobj_method = kobj_lookup_method(((kobj_t)clknode)->ops->cls, NULL, + kobj_desc); + if (kobj_method != &kobj_desc->deflt && + kobj_method->func != (kobjop_t)clknode_method_set_gate) { + SYSCTL_ADD_PROC(&clknode->sysctl_ctx, + SYSCTL_CHILDREN(clknode_oid), + OID_AUTO, "gate", + CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, + clknode, CLKNODE_SYSCTL_GATE, clknode_sysctl, + "A", + "The clock gate status"); + } + SYSCTL_ADD_PROC(&clknode->sysctl_ctx, SYSCTL_CHILDREN(clknode_oid), OID_AUTO, "parent", @@ -1617,6 +1636,7 @@ clknode_sysctl(SYSCTL_HANDLER_ARGS) struct sbuf *sb; const char **parent_names; uint64_t freq; + bool enable; int ret, i; clknode = arg1; @@ -1647,6 +1667,17 @@ clknode_sysctl(SYSCTL_HANDLER_ARGS) else sbuf_printf(sb, "Error: %d ", ret); break; + case CLKNODE_SYSCTL_GATE: + ret = CLKNODE_GET_GATE(clknode, &enable); + if (ret == 0) + sbuf_printf(sb, enable ? "enabled": "disabled"); + else if (ret == ENXIO) + sbuf_printf(sb, "unimplemented"); + else if (ret == ENOENT) + sbuf_printf(sb, "unreadable"); + else + sbuf_printf(sb, "Error: %d ", ret); + break; } CLK_TOPO_UNLOCK(); diff --git a/sys/dev/extres/clk/clk_gate.c b/sys/dev/extres/clk/clk_gate.c index e0673fd81a7e..53b2242a6f6a 100644 --- a/sys/dev/extres/clk/clk_gate.c +++ b/sys/dev/extres/clk/clk_gate.c @@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$"); static int clknode_gate_init(struct clknode *clk, device_t dev); static int clknode_gate_set_gate(struct clknode *clk, bool enable); +static int clknode_gate_get_gate(struct clknode *clk, bool *enable); struct clknode_gate_sc { uint32_t offset; uint32_t shift; @@ -60,13 +61,13 @@ struct clknode_gate_sc { uint32_t on_value; uint32_t off_value; int gate_flags; - bool ungated; }; static clknode_method_t clknode_gate_methods[] = { /* Device interface */ CLKNODEMETHOD(clknode_init, clknode_gate_init), CLKNODEMETHOD(clknode_set_gate, clknode_gate_set_gate), + CLKNODEMETHOD(clknode_get_gate, clknode_gate_get_gate), CLKNODEMETHOD_END }; DEFINE_CLASS_1(clknode_gate, clknode_gate_class, clknode_gate_methods, @@ -75,18 +76,7 @@ DEFINE_CLASS_1(clknode_gate, clknode_gate_class, clknode_gate_methods, static int clknode_gate_init(struct clknode *clk, device_t dev) { - uint32_t reg; - struct clknode_gate_sc *sc; - int rv; - sc = clknode_get_softc(clk); - DEVICE_LOCK(clk); - rv = RD4(clk, sc->offset, ®); - DEVICE_UNLOCK(clk); - if (rv != 0) - return (rv); - reg = (reg >> sc->shift) & sc->mask; - sc->ungated = reg == sc->on_value ? 1 : 0; clknode_init_parent_idx(clk, 0); return(0); } @@ -99,10 +89,9 @@ clknode_gate_set_gate(struct clknode *clk, bool enable) int rv; sc = clknode_get_softc(clk); - sc->ungated = enable; DEVICE_LOCK(clk); rv = MD4(clk, sc->offset, sc->mask << sc->shift, - (sc->ungated ? sc->on_value : sc->off_value) << sc->shift); + (enable ? sc->on_value : sc->off_value) << sc->shift); if (rv != 0) { DEVICE_UNLOCK(clk); return (rv); @@ -112,6 +101,24 @@ clknode_gate_set_gate(struct clknode *clk, bool enable) return(0); } +static int +clknode_gate_get_gate(struct clknode *clk, bool *enabled) +{ + uint32_t reg; + struct clknode_gate_sc *sc; + int rv; + + sc = clknode_get_softc(clk); + DEVICE_LOCK(clk); + rv = RD4(clk, sc->offset, ®); + DEVICE_UNLOCK(clk); + if (rv != 0) + return (rv); + reg = (reg >> sc->shift) & sc->mask; + *enabled = reg == sc->on_value; + return(0); +} + int clknode_gate_register(struct clkdom *clkdom, struct clk_gate_def *clkdef) { diff --git a/sys/dev/extres/clk/clknode_if.m b/sys/dev/extres/clk/clknode_if.m index 80d67547b695..367bc0c432ed 100644 --- a/sys/dev/extres/clk/clknode_if.m +++ b/sys/dev/extres/clk/clknode_if.m @@ -70,6 +70,17 @@ METHOD int set_gate { bool enable; }; +# +# Get gate status +# Return: ENXIO - method is not implemented +# ENOENT - HW doesn't support reading of gate enable +# 0 - success +# +METHOD int get_gate { + struct clknode *clk; + bool *enabled; +}; + # # Set multiplexer #