From nobody Tue Oct 15 17:25:11 2024 X-Original-To: dev-commits-src-main@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 4XSgw82LzDz5YknB; Tue, 15 Oct 2024 17:25:12 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XSgw80C68z4TqB; Tue, 15 Oct 2024 17:25:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729013112; 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=bzVuSntQMEj2aA/qo/H6QpqjOHaj1S/lq8xXRkAAIMQ=; b=SGEO4Uu9Sir+92MZe2rzBbJtrgag6Xa4vq+79hJnoNtIAPR7fyPB/j11BzI9wNeVEaHffx D2r0Sro/gTd7VI/rJzqu6Moce1Lx64nwKz8sVg2AcmuxvH5j9CCqG0U2sM+AKnr45hPEZF zsfJkfd7VX65HojmLGHRQ8RZbbq0E8kJ2/1RahiTZ7FGvbeuSdNNSzVaaXP1Y/WSHyVoNw 6EvLCcU+2YQJ56GhX+jGUSAO0L5DYrGqjIPeZN3eTTByg1FIGOlqUFU+3vuS+MjZsUQvHL c+SIHjtk8XQakdZREy4Q4+emI1jzWtO6Qt8a1V+pwZiX4CxvVZmkVt0+ukWZlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729013112; 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=bzVuSntQMEj2aA/qo/H6QpqjOHaj1S/lq8xXRkAAIMQ=; b=rV1Qr9knfzZ0DU1uqhGgFT4w99kgR7pBwMGp9nqTLFka22gVcbvz36V+aHM4VqcB3prU9y j3iMUrGnDIr0xlimPsl0kz5Sa/nLpYnPHW0wnBhZgiaVNS+pcocjLlRl4FM0zkvVi9oqUf +J+7siVR8mtbDnpXsved8KGzHXIj9lerQYO5r39UKfyWVCtqW/zv++yg/OmtGnVlxwfv9M GsUFtKtsSC/G7JgQPPuHyaxHLsmATduYRw4ehpZBJNqGNVVW3z+Va1h1vEr5N4EdzpMwiW G+dOdqlLtRu3uhdtu1IsjXFgIBvEEFneXriYPUNxr7ll5/QGtzy25+fH6Paokw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1729013112; a=rsa-sha256; cv=none; b=D7+90bu1NBh04Vn7oJmpkjs06uv7LYsObb2FkYcEbgCBfReXvZ6XqkecF+luLsqQw5g2W6 /2oDyg3T4414bDanavtTkezz/JfN4jcJzo1VKxuqK3lfD3aS+hpy2ObGHE4r1u8bevO2lM OVarYbRizHMCsxvmz5xKmXCiOR5jgf3X71SeLMZW8RCEQhTBtcU+fbTwQt03Xdq0P9giTv n4w3TM1GeZbB9P9Zybr95DQOwrcmc+BuGtu6PSRRvtj3aQKnXJRAevg7keBrqp33kOR+69 HjOdz9YU+Z/uRXQQPvKuKhk3uN2nNik0Yq4yESNyBAJEP4S51tf9ccFcPzQjKw== 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 4XSgw76xmHzW5X; Tue, 15 Oct 2024 17:25:11 +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 49FHPBkj027909; Tue, 15 Oct 2024 17:25:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49FHPBK8027906; Tue, 15 Oct 2024 17:25:11 GMT (envelope-from git) Date: Tue, 15 Oct 2024 17:25:11 GMT Message-Id: <202410151725.49FHPBK8027906@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: 3e19edca9eb1 - main - dev/psci: Make SMCCC into a real driver List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: andrew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 3e19edca9eb1402afe330cb1d9d562dedca2d95a Auto-Submitted: auto-generated The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=3e19edca9eb1402afe330cb1d9d562dedca2d95a commit 3e19edca9eb1402afe330cb1d9d562dedca2d95a Author: Andrew Turner AuthorDate: 2024-10-14 14:33:59 +0000 Commit: Andrew Turner CommitDate: 2024-10-15 17:24:42 +0000 dev/psci: Make SMCCC into a real driver This will be used by other drivers that manage SMCCC firmware services to use as an attachment point. Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D46988 --- sys/dev/psci/psci.c | 10 ++++++++-- sys/dev/psci/smccc.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/sys/dev/psci/psci.c b/sys/dev/psci/psci.c index 3211c331ed6e..e445e90956ac 100644 --- a/sys/dev/psci/psci.c +++ b/sys/dev/psci/psci.c @@ -71,6 +71,7 @@ struct psci_softc { device_t dev; + device_t smccc_dev; uint32_t psci_version; uint32_t psci_fnids[PSCI_FN_MAX]; @@ -341,11 +342,16 @@ psci_attach(device_t dev, psci_initfn_t psci_init, int default_version) if (psci_init(dev, default_version)) return (ENXIO); + psci_softc = sc; + #ifdef __aarch64__ smccc_init(); -#endif + sc->smccc_dev = device_add_child(dev, "smccc", DEVICE_UNIT_ANY); + if (sc->smccc_dev == NULL) + device_printf(dev, "Unable to add SMCCC device\n"); - psci_softc = sc; + bus_generic_attach(dev); +#endif return (0); } diff --git a/sys/dev/psci/smccc.c b/sys/dev/psci/smccc.c index 21a6bd54e650..0cd3255fc911 100644 --- a/sys/dev/psci/smccc.c +++ b/sys/dev/psci/smccc.c @@ -34,7 +34,9 @@ #include #include +#include #include +#include #include #include @@ -66,6 +68,32 @@ smccc_init(void) } } +static int +smccc_probe(device_t dev) +{ + int32_t version; + + /* + * If the version is not implemented then we treat it as SMCCC 1.0 + */ + if (psci_features(SMCCC_VERSION) == PSCI_RETVAL_NOT_SUPPORTED || + (version = arm_smccc_invoke(SMCCC_VERSION, NULL)) <= 0) { + device_set_desc(dev, "ARM SMCCC v1.0"); + return (0); + } + + device_set_descf(dev, "ARM SMCCC v%d.%d", SMCCC_VERSION_MAJOR(version), + SMCCC_VERSION_MINOR(version)); + + return (0); +} + +static int +smccc_attach(device_t dev) +{ + return (bus_generic_attach(dev)); +} + uint32_t smccc_get_version(void) { @@ -107,3 +135,21 @@ smccc_arch_workaround_2(int enable) ("SMCCC arch workaround 2 called with an invalid SMCCC interface")); return (arm_smccc_invoke(SMCCC_ARCH_WORKAROUND_2, enable, NULL)); } + +static device_method_t smccc_methods[] = { + DEVMETHOD(device_probe, smccc_probe), + DEVMETHOD(device_attach, smccc_attach), + + DEVMETHOD(bus_add_child, bus_generic_add_child), + + DEVMETHOD_END +}; + +static driver_t smccc_driver = { + "smccc", + smccc_methods, + 0, +}; + +EARLY_DRIVER_MODULE(smccc, psci, smccc_driver, 0, 0, + BUS_PASS_CPU + BUS_PASS_ORDER_FIRST);