From owner-svn-src-all@freebsd.org Tue Mar 19 15:42:13 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 3280F1553EC5; Tue, 19 Mar 2019 15:42:13 +0000 (UTC) (envelope-from mmel@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id C30E68A363; Tue, 19 Mar 2019 15:42:12 +0000 (UTC) (envelope-from mmel@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 917A7B3F8; Tue, 19 Mar 2019 15:42:12 +0000 (UTC) (envelope-from mmel@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x2JFgCa1096003; Tue, 19 Mar 2019 15:42:12 GMT (envelope-from mmel@FreeBSD.org) Received: (from mmel@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x2JFgCQZ096002; Tue, 19 Mar 2019 15:42:12 GMT (envelope-from mmel@FreeBSD.org) Message-Id: <201903191542.x2JFgCQZ096002@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mmel set sender to mmel@FreeBSD.org using -f From: Michal Meloun Date: Tue, 19 Mar 2019 15:42:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r345299 - head/sys/dev/psci X-SVN-Group: head X-SVN-Commit-Author: mmel X-SVN-Commit-Paths: head/sys/dev/psci X-SVN-Commit-Revision: 345299 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: C30E68A363 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.998,0]; NEURAL_HAM_SHORT(-0.96)[-0.963,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Mar 2019 15:42:13 -0000 Author: mmel Date: Tue Mar 19 15:42:11 2019 New Revision: 345299 URL: https://svnweb.freebsd.org/changeset/base/345299 Log: PSCI: Don't take missing implementation of psci get_version() as fatal. Minimalistic PSCI implementation in U-Boot doesn't implement get_version() method for some SoC. In this case, use PSCI version declared by 'psci' node in DT as fallback. MFC after: 2 weeks Modified: head/sys/dev/psci/psci.c head/sys/dev/psci/psci.h Modified: head/sys/dev/psci/psci.c ============================================================================== --- head/sys/dev/psci/psci.c Tue Mar 19 15:03:20 2019 (r345298) +++ head/sys/dev/psci/psci.c Tue Mar 19 15:42:11 2019 (r345299) @@ -79,9 +79,9 @@ struct psci_softc { }; #ifdef FDT -static int psci_v0_1_init(device_t dev); +static int psci_v0_1_init(device_t dev, int default_version); #endif -static int psci_v0_2_init(device_t dev); +static int psci_v0_2_init(device_t dev, int default_version); struct psci_softc *psci_softc = NULL; @@ -96,15 +96,35 @@ struct psci_softc *psci_softc = NULL; #endif #ifdef FDT +struct psci_init_def { + int default_version; + psci_initfn_t psci_init; +}; + +static struct psci_init_def psci_v1_0_init_def = { + .default_version = (1 << 16) | 0, + .psci_init = psci_v0_2_init +}; + +static struct psci_init_def psci_v0_2_init_def = { + .default_version = (0 << 16) | 2, + .psci_init = psci_v0_2_init +}; + +static struct psci_init_def psci_v0_1_init_def = { + .default_version = (0 << 16) | 1, + .psci_init = psci_v0_1_init +}; + static struct ofw_compat_data compat_data[] = { - {"arm,psci-1.0", (uintptr_t)psci_v0_2_init}, - {"arm,psci-0.2", (uintptr_t)psci_v0_2_init}, - {"arm,psci", (uintptr_t)psci_v0_1_init}, + {"arm,psci-1.0", (uintptr_t)&psci_v1_0_init_def}, + {"arm,psci-0.2", (uintptr_t)&psci_v0_2_init_def}, + {"arm,psci", (uintptr_t)&psci_v0_1_init_def}, {NULL, 0} }; #endif -static int psci_attach(device_t, psci_initfn_t); +static int psci_attach(device_t, psci_initfn_t, int); static void psci_shutdown(void *, int); static int psci_find_callfn(psci_callfn_t *); @@ -198,12 +218,13 @@ static int psci_fdt_attach(device_t dev) { const struct ofw_compat_data *ocd; - psci_initfn_t psci_init; + struct psci_init_def *psci_init_def; ocd = ofw_bus_search_compatible(dev, compat_data); - psci_init = (psci_initfn_t)ocd->ocd_data; + psci_init_def = (struct psci_init_def *)ocd->ocd_data; - return (psci_attach(dev, psci_init)); + return (psci_attach(dev, psci_init_def->psci_init, + psci_init_def->default_version)); } #endif @@ -304,12 +325,12 @@ static int psci_acpi_attach(device_t dev) { - return (psci_attach(dev, psci_v0_2_init)); + return (psci_attach(dev, psci_v0_2_init, PSCI_RETVAL_NOT_SUPPORTED)); } #endif static int -psci_attach(device_t dev, psci_initfn_t psci_init) +psci_attach(device_t dev, psci_initfn_t psci_init, int default_version) { struct psci_softc *sc = device_get_softc(dev); @@ -317,7 +338,7 @@ psci_attach(device_t dev, psci_initfn_t psci_init) return (ENXIO); KASSERT(psci_init != NULL, ("PSCI init function cannot be NULL")); - if (psci_init(dev)) + if (psci_init(dev, default_version)) return (ENXIO); psci_softc = sc; @@ -464,7 +485,7 @@ psci_reset(void) #ifdef FDT /* Only support PSCI 0.1 on FDT */ static int -psci_v0_1_init(device_t dev) +psci_v0_1_init(device_t dev, int default_version __unused) { struct psci_softc *sc = device_get_softc(dev); int psci_fn; @@ -510,7 +531,7 @@ psci_v0_1_init(device_t dev) #endif static int -psci_v0_2_init(device_t dev) +psci_v0_2_init(device_t dev, int default_version) { struct psci_softc *sc = device_get_softc(dev); int version; @@ -529,8 +550,20 @@ psci_v0_2_init(device_t dev) version = _psci_get_version(sc); - if (version == PSCI_RETVAL_NOT_SUPPORTED) - return (1); + /* + * U-Boot PSCI implementation doesn't have psci_get_version() + * method implemented for many boards. In this case, use the version + * readed from FDT as fallback. No fallback method for ACPI. + */ + if (version == PSCI_RETVAL_NOT_SUPPORTED) { + if (default_version == PSCI_RETVAL_NOT_SUPPORTED) + return (1); + + version = default_version; + printf("PSCI get_version() function is not implemented, " + " assuming v%d.%d\n", PSCI_VER_MAJOR(version), + PSCI_VER_MINOR(version)); + } sc->psci_version = version; if ((PSCI_VER_MAJOR(version) == 0 && PSCI_VER_MINOR(version) == 2) || Modified: head/sys/dev/psci/psci.h ============================================================================== --- head/sys/dev/psci/psci.h Tue Mar 19 15:03:20 2019 (r345298) +++ head/sys/dev/psci/psci.h Tue Mar 19 15:42:11 2019 (r345299) @@ -31,7 +31,7 @@ #include -typedef int (*psci_initfn_t)(device_t dev); +typedef int (*psci_initfn_t)(device_t dev, int default_version); typedef int (*psci_callfn_t)(register_t, register_t, register_t, register_t); extern int psci_present;