From nobody Mon Oct 18 19:19:19 2021 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 ECB7517F81DE; Mon, 18 Oct 2021 19:19:20 +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 4HY6BJ2SySz4cQ3; Mon, 18 Oct 2021 19:19:19 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 B8C0525E45; Mon, 18 Oct 2021 19:19:19 +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 19IJJJmt080231; Mon, 18 Oct 2021 19:19:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 19IJJJYk080230; Mon, 18 Oct 2021 19:19:19 GMT (envelope-from git) Date: Mon, 18 Oct 2021 19:19:19 GMT Message-Id: <202110181919.19IJJJYk080230@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Adrian Chadd Subject: git: 02438ce5fd18 - main - ipq4018: add initial IPQ4018/IPQ4019 support 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: adrian X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 02438ce5fd1892e3f59e4f1e83a0ac810396853f Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by adrian: URL: https://cgit.FreeBSD.org/src/commit/?id=02438ce5fd1892e3f59e4f1e83a0ac810396853f commit 02438ce5fd1892e3f59e4f1e83a0ac810396853f Author: Adrian Chadd AuthorDate: 2021-10-16 18:47:44 +0000 Commit: Adrian Chadd CommitDate: 2021-10-18 19:19:00 +0000 ipq4018: add initial IPQ4018/IPQ4019 support This is for the Qualcomm Atheros quad-core ARMv7 SoC with built-in 2x2 2GHz and 5GHz ath10k devices. It's enough (with an upcoming set of config files) to netboot on an ASUS router I have here and get to a single core mountroot prompt. --- sys/arm/qualcomm/ipq4018_machdep.c | 194 +++++++++++++++++++++++++++++++++++++ sys/arm/qualcomm/ipq4018_machdep.h | 38 ++++++++ sys/arm/qualcomm/ipq4018_mp.c | 61 ++++++++++++ sys/arm/qualcomm/ipq4018_reg.h | 42 ++++++++ sys/arm/qualcomm/std.ipq4018 | 2 + 5 files changed, 337 insertions(+) diff --git a/sys/arm/qualcomm/ipq4018_machdep.c b/sys/arm/qualcomm/ipq4018_machdep.c new file mode 100644 index 000000000000..b3f841575ebb --- /dev/null +++ b/sys/arm/qualcomm/ipq4018_machdep.c @@ -0,0 +1,194 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2021 Adrian Chadd + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "opt_platform.h" + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include "platform_if.h" + +static int +ipq4018_attach(platform_t plat) +{ + return (0); +} + +static void +ipq4018_late_init(platform_t plat) +{ + /* + * XXX FIXME This is needed because we're not parsing + * the fdt reserved memory regions in a consistent way + * between arm/arm64. Once the reserved region parsing + * is fixed up this will become unneccessary. + * + * These cover the SRAM/TZ regions that are not fully + * accessible from the OS. They're in the ipq4018.dtsi + * tree. + * + * Without these, the system fails to boot because we + * aren't parsing the regions correctly. + * + * These will be unnecessary once the parser and setup + * code is fixed. + */ + physmem_exclude_region(IPQ4018_MEM_SMEM_START, + IPQ4018_MEM_SMEM_SIZE, + EXFLAG_NODUMP | EXFLAG_NOALLOC); + physmem_exclude_region(IPQ4018_MEM_TZ_START, + IPQ4018_MEM_TZ_SIZE, + EXFLAG_NODUMP | EXFLAG_NOALLOC); +} + +static int +ipq4018_devmap_init(platform_t plat) +{ + /* + * This covers the boot UART. Without it we can't boot successfully: + * there's a mutex uninit panic in subr_vmem.c that occurs when doing + * a call to pmap_mapdev() when the bus space code is doing its thing. + */ + devmap_add_entry(IPQ4018_MEM_UART1_START, IPQ4018_MEM_UART1_SIZE); + return (0); +} + +static void +ipq4018_cpu_reset(platform_t plat) +{ +} + +/* + * Early putc routine for EARLY_PRINTF support. To use, add to kernel config: + * option SOCDEV_PA=0x07800000 + * option SOCDEV_VA=0x07800000 + * option EARLY_PRINTF + * Resist the temptation to change the #if 0 to #ifdef EARLY_PRINTF here. It + * makes sense now, but if multiple SOCs do that it will make early_putc another + * duplicate symbol to be eliminated on the path to a generic kernel. + */ +#if 0 +void +qca_msm_early_putc(int c) +{ + static int is_init = 0; + + int limit; +/* + * This must match what's put into SOCDEV_VA. You have to change them + * both together. + * + * XXX TODO I should really go and just make UART_BASE here depend upon + * SOCDEV_VA so they move together. + */ +#define UART_BASE IPQ4018_MEM_UART1_START + volatile uint32_t * UART_DM_TF0 = (uint32_t *)(UART_BASE + 0x70); + volatile uint32_t * UART_DM_SR = (uint32_t *)(UART_BASE + 0x08); +#define UART_DM_SR_TXEMT (1 << 3) +#define UART_DM_SR_TXRDY (1 << 2) + volatile uint32_t * UART_DM_ISR = (uint32_t *)(UART_BASE + 0x14); + volatile uint32_t * UART_DM_CR = (uint32_t *)(UART_BASE + 0x10); +#define UART_DM_TX_READY (1 << 7) +#define UART_DM_CLEAR_TX_READY 0x300 + volatile uint32_t * UART_DM_NO_CHARS_FOR_TX = (uint32_t *)(UART_BASE + 0x40); + volatile uint32_t * UART_DM_TFWR = (uint32_t *)(UART_BASE + 0x1c); +#define UART_DM_TFW_VALUE 0 + volatile uint32_t * UART_DM_IPR = (uint32_t *)(UART_BASE + 0x18); +#define UART_DM_STALE_TIMEOUT_LSB 0xf + + if (is_init == 0) { + is_init = 1; + *UART_DM_TFWR = UART_DM_TFW_VALUE; + wmb(); + *UART_DM_IPR = UART_DM_STALE_TIMEOUT_LSB; + wmb(); + } + + /* Wait until TXFIFO is empty via ISR */ + limit = 100000; + if ((*UART_DM_SR & UART_DM_SR_TXEMT) == 0) { + while (((*UART_DM_ISR & UART_DM_TX_READY) == 0) && --limit) { + /* Note - can't use DELAY here yet, too early */ + rmb(); + } + *UART_DM_CR = UART_DM_CLEAR_TX_READY; + wmb(); + } + + /* FIFO is ready. Say we're going to write one byte */ + *UART_DM_NO_CHARS_FOR_TX = 1; + wmb(); + + limit = 100000; + while (((*UART_DM_SR & UART_DM_SR_TXRDY) == 0) && --limit) { + /* Note - can't use DELAY here yet, too early */ + rmb(); + } + + /* Put character in first fifo slot */ + *UART_DM_TF0 = c; + wmb(); +} +early_putc_t *early_putc = qca_msm_early_putc; +#endif + +static platform_method_t ipq4018_methods[] = { + PLATFORMMETHOD(platform_attach, ipq4018_attach), + PLATFORMMETHOD(platform_devmap_init, ipq4018_devmap_init), + PLATFORMMETHOD(platform_late_init, ipq4018_late_init), + PLATFORMMETHOD(platform_cpu_reset, ipq4018_cpu_reset), + +#ifdef SMP + PLATFORMMETHOD(platform_mp_start_ap, ipq4018_mp_start_ap), + PLATFORMMETHOD(platform_mp_setmaxid, ipq4018_mp_setmaxid), +#endif + + PLATFORMMETHOD_END, +}; + +FDT_PLATFORM_DEF2(ipq4018, ipq4018_ac58u, "ASUS RT-AC58U", 0, + "asus,rt-ac58u", 80); diff --git a/sys/arm/qualcomm/ipq4018_machdep.h b/sys/arm/qualcomm/ipq4018_machdep.h new file mode 100644 index 000000000000..8fbd26de14a8 --- /dev/null +++ b/sys/arm/qualcomm/ipq4018_machdep.h @@ -0,0 +1,38 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2021 Adrian Chadd + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef IPQ4018_MACHDEP_H +#define IPQ4018_MACHDEP_H + +#include + +void ipq4018_mp_setmaxid(platform_t plat); +void ipq4018_mp_start_ap(platform_t plat); + +#endif diff --git a/sys/arm/qualcomm/ipq4018_mp.c b/sys/arm/qualcomm/ipq4018_mp.c new file mode 100644 index 000000000000..37b7cc3e097d --- /dev/null +++ b/sys/arm/qualcomm/ipq4018_mp.c @@ -0,0 +1,61 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2021 Adrian Chadd + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "opt_platform.h" + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include +#include + +#include + +#include "platform_if.h" + +void +ipq4018_mp_setmaxid(platform_t plat) +{ +} + +void +ipq4018_mp_start_ap(platform_t plat) +{ +} diff --git a/sys/arm/qualcomm/ipq4018_reg.h b/sys/arm/qualcomm/ipq4018_reg.h new file mode 100644 index 000000000000..945d650dcfd6 --- /dev/null +++ b/sys/arm/qualcomm/ipq4018_reg.h @@ -0,0 +1,42 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2021 Adrian Chadd + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef IPQ4018_REG_H +#define IPQ4018_REG_H + +#define IPQ4018_MEM_SMEM_START 0x87e00000 +#define IPQ4018_MEM_SMEM_SIZE 0x00080000 + +#define IPQ4018_MEM_TZ_START 0x87e80000 +#define IPQ4018_MEM_TZ_SIZE 0x00180000 + +#define IPQ4018_MEM_UART1_START 0x078af000 +#define IPQ4018_MEM_UART1_SIZE 0x00001000 + +#endif diff --git a/sys/arm/qualcomm/std.ipq4018 b/sys/arm/qualcomm/std.ipq4018 new file mode 100644 index 000000000000..9a9801fa6415 --- /dev/null +++ b/sys/arm/qualcomm/std.ipq4018 @@ -0,0 +1,2 @@ +arm/qualcomm/ipq4018_machdep.c standard +arm/qualcomm/ipq4018_mp.c optional smp