Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41430C433EF for ; Fri, 3 Sep 2021 13:18:26 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B345D60FC0 for ; Fri, 3 Sep 2021 13:18:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B345D60FC0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 242D883599; Fri, 3 Sep 2021 15:17:27 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="GID3rdYg"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 11A5B834C0; Fri, 3 Sep 2021 15:17:13 +0200 (CEST) Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6EA908354D for ; Fri, 3 Sep 2021 15:16:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=thierry.reding@gmail.com Received: by mail-wm1-x32d.google.com with SMTP id l7-20020a1c2507000000b002e6be5d86b3so3558965wml.3 for ; Fri, 03 Sep 2021 06:16:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1g1B3JPj8V6DcU6aYYTFSNiY3hx6CBPjW1vielzyykk=; b=GID3rdYg4Y4WRKVrkjSkRPuxaGBuy0v0AdU/g/5Ytj2I6MHjnoFX0JyNivNdZdmGkm TZBjI0aykM2lMvDer6S/GSpW2v6G8vtylNr0KTWiPDr1VCNYffc2yYpqBmFJ/FZLABS5 Rfl89S7aFunXEiDzq6YPNzgW9pQRhlNtxSBGzc1i+OCBSLhZC1xKqAc/61Pj12RnrGsE iDM3HhZYIpqlcYMuYC0TETgqBDvCQZ7hnsA89jtDV09rUIaz0zNwb/ZlzidjVQPW6zVD 08bAZFXRu75swtNwi9STHCgMZ0VzO0o8G3fP/BjZMe+mp3q7bZzgTTKuduyh4/eIk1Sr RDaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1g1B3JPj8V6DcU6aYYTFSNiY3hx6CBPjW1vielzyykk=; b=ZytFl43K0TQ2y3DEFUr28PCegmok45EfpqceEJPGon/Abkq/wdiwukMN5tQec5DP+e pOTx2ZYDwNQQvUlBlLowGhnioqAfIqVUD0nuuegyDrI8E6dv/2c3nmRe3E4T302LkzLE KkIKne1GD0y71xKPWjvX4Pm2h8A54ft9OVcrysA6eA6C/kr9FERUotLqsH5//0O6EHN9 qP0nEtRJoD0Z+qn7GCdbvWot+7qEqAhYnI75qM7yvWuQZRtFphoeqP+KmnofN6vD3Tki D4yt60E1Ed/Sj/TFYstlmAjH5XkFMc3jcQ5MTiTftybVoO1QuTsYJm2LoH02Hixk3HKw J74w== X-Gm-Message-State: AOAM531+1I4AAR7Fu+aXlpi7d+EOoN0OS9JzQz0TH2wvZGJ6rpFJ+qRs k18lk2nyQPXWaXET9xpf2gc= X-Google-Smtp-Source: ABdhPJzxOWKcUXM2+b5jAl84XOSWpwmADjsOKq73vKq59CAO9lDEsgOPbUqNedKFfC/bl9nw6F53KQ== X-Received: by 2002:a1c:43c5:: with SMTP id q188mr293128wma.175.1630675010868; Fri, 03 Sep 2021 06:16:50 -0700 (PDT) Received: from localhost ([217.111.27.204]) by smtp.gmail.com with ESMTPSA id u25sm4270970wmj.10.2021.09.03.06.16.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Sep 2021 06:16:50 -0700 (PDT) From: Thierry Reding To: Tom Warren Cc: Simon Glass , u-boot@lists.denx.de Subject: [PATCH 8/9] ARM: tegra: Refactor DT update helpers Date: Fri, 3 Sep 2021 15:16:24 +0200 Message-Id: <20210903131625.2153838-9-thierry.reding@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210903131625.2153838-1-thierry.reding@gmail.com> References: <20210903131625.2153838-1-thierry.reding@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean From: Thierry Reding Rather than duplicate the Ethernet MAC address and carveout updating code for each board, move it to a common location and make it more reusable. Signed-off-by: Thierry Reding --- arch/arm/include/asm/arch-tegra/board.h | 10 ++ arch/arm/mach-tegra/dt-setup.c | 118 ++++++++++++++++++++++ board/nvidia/p2371-2180/p2371-2180.c | 123 ++--------------------- board/nvidia/p2771-0000/p2771-0000.c | 126 ++--------------------- board/nvidia/p3450-0000/p3450-0000.c | 127 ++---------------------- 5 files changed, 149 insertions(+), 355 deletions(-) diff --git a/arch/arm/include/asm/arch-tegra/board.h b/arch/arm/include/asm/arch-tegra/board.h index 24d0db8ced83..cd4d0ee3c953 100644 --- a/arch/arm/include/asm/arch-tegra/board.h +++ b/arch/arm/include/asm/arch-tegra/board.h @@ -30,4 +30,14 @@ void pin_mux_nand(void); /* overridable NAND pinmux setup */ void pin_mux_mmc(void); /* overridable mmc pinmux setup */ void pin_mux_display(void); /* overridable DISPLAY pinmux setup */ +/* + * Helpers for various standard DT update mechanisms. + */ + +#if defined(CONFIG_ARM64) +void ft_mac_address_setup(void *fdt); +void ft_carveout_setup(void *fdt, const char *const *nodes, + unsigned int count); +#endif + #endif diff --git a/arch/arm/mach-tegra/dt-setup.c b/arch/arm/mach-tegra/dt-setup.c index 602b20e6b7e9..894a6358a2c4 100644 --- a/arch/arm/mach-tegra/dt-setup.c +++ b/arch/arm/mach-tegra/dt-setup.c @@ -4,6 +4,9 @@ */ #include +#include +#include +#include #include /* @@ -31,3 +34,118 @@ int ft_system_setup(void *blob, struct bd_info *bd) return 0; } + +#if defined(CONFIG_ARM64) +void ft_mac_address_setup(void *fdt) +{ + const void *cboot_fdt = (const void *)cboot_boot_x0; + uint8_t mac[ETH_ALEN], local_mac[ETH_ALEN]; + const char *path; + int offset, err; + + err = cboot_get_ethaddr(cboot_fdt, local_mac); + if (err < 0) + memset(local_mac, 0, ETH_ALEN); + + path = fdt_get_alias(fdt, "ethernet"); + if (!path) + return; + + debug("ethernet alias found: %s\n", path); + + offset = fdt_path_offset(fdt, path); + if (offset < 0) { + printf("ethernet alias points to absent node %s\n", path); + return; + } + + if (is_valid_ethaddr(local_mac)) { + err = fdt_setprop(fdt, offset, "local-mac-address", local_mac, + ETH_ALEN); + if (!err) + debug("Local MAC address set: %pM\n", local_mac); + } + + if (eth_env_get_enetaddr("ethaddr", mac)) { + if (memcmp(local_mac, mac, ETH_ALEN) != 0) { + err = fdt_setprop(fdt, offset, "mac-address", mac, + ETH_ALEN); + if (!err) + debug("MAC address set: %pM\n", mac); + } + } +} + +static int ft_copy_carveout(void *dst, const void *src, const char *node) +{ + struct fdt_memory carveout; + unsigned int index = 0; + int err; + + while (true) { + const char **compatibles = NULL; + unsigned int num_compatibles; + unsigned long flags; + char *copy = NULL; + const char *name; + + err = fdtdec_get_carveout(src, node, "memory-region", index, + &carveout, &name, &compatibles, + &num_compatibles, &flags); + if (err < 0) { + if (err != -FDT_ERR_NOTFOUND) + printf("failed to get carveout for %s: %d\n", + node, err); + + return err; + } + + if (name) { + const char *ptr = strchr(name, '@'); + + if (ptr) { + copy = strndup(name, ptr - name); + name = copy; + } + } else { + name = "carveout"; + } + + err = fdtdec_set_carveout(dst, node, "memory-region", index, + &carveout, name, compatibles, + num_compatibles, flags); + if (err < 0) { + printf("failed to set carveout for %s: %d\n", node, + err); + return err; + } + + if (copy) + free(copy); + + index++; + } + + return 0; +} + +void ft_carveout_setup(void *fdt, const char * const *nodes, unsigned int count) +{ + const void *cboot_fdt = (const void *)cboot_boot_x0; + unsigned int i; + int err; + + for (i = 0; i < count; i++) { + printf("copying carveout for %s...\n", nodes[i]); + + err = ft_copy_carveout(fdt, cboot_fdt, nodes[i]); + if (err < 0) { + if (err != -FDT_ERR_NOTFOUND) + printf("failed to copy carveout for %s: %d\n", + nodes[i], err); + + continue; + } + } +} +#endif diff --git a/board/nvidia/p2371-2180/p2371-2180.c b/board/nvidia/p2371-2180/p2371-2180.c index cd5dc2de629e..816c7bec6ae4 100644 --- a/board/nvidia/p2371-2180/p2371-2180.c +++ b/board/nvidia/p2371-2180/p2371-2180.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include "../p2571/max77620_init.h" void pin_mux_mmc(void) @@ -84,125 +84,16 @@ int tegra_pcie_board_init(void) } #endif /* PCI */ -static void ft_mac_address_setup(void *fdt) -{ - const void *cboot_fdt = (const void *)cboot_boot_x0; - uint8_t mac[ETH_ALEN], local_mac[ETH_ALEN]; - const char *path; - int offset, err; - - err = cboot_get_ethaddr(cboot_fdt, local_mac); - if (err < 0) - memset(local_mac, 0, ETH_ALEN); - - path = fdt_get_alias(fdt, "ethernet"); - if (!path) - return; - - debug("ethernet alias found: %s\n", path); - - offset = fdt_path_offset(fdt, path); - if (offset < 0) { - printf("ethernet alias points to absent node %s\n", path); - return; - } - - if (is_valid_ethaddr(local_mac)) { - err = fdt_setprop(fdt, offset, "local-mac-address", local_mac, - ETH_ALEN); - if (!err) - debug("Local MAC address set: %pM\n", local_mac); - } - - if (eth_env_get_enetaddr("ethaddr", mac)) { - if (memcmp(local_mac, mac, ETH_ALEN) != 0) { - err = fdt_setprop(fdt, offset, "mac-address", mac, - ETH_ALEN); - if (!err) - debug("MAC address set: %pM\n", mac); - } - } -} - -static int ft_copy_carveout(void *dst, const void *src, const char *node) -{ - unsigned int index = 0; - int err; - - while (true) { - const char **compatibles = NULL; - unsigned int num_compatibles; - struct fdt_memory carveout; - unsigned long flags; - char *copy = NULL; - const char *name; - - err = fdtdec_get_carveout(src, node, "memory-region", index, - &carveout, &name, &compatibles, - &num_compatibles, &flags); - if (err < 0) { - if (err != -FDT_ERR_NOTFOUND) - printf("failed to get carveout for %s: %d\n", - node, err); - - return err; - } - - if (name) { - const char *ptr = strchr(name, '@'); - - if (ptr) { - copy = strndup(name, ptr - name); - name = copy; - } - } else { - name = "carveout"; - } - - err = fdtdec_set_carveout(dst, node, "memory-region", index, - &carveout, name, compatibles, - num_compatibles, flags); - if (err < 0) { - printf("failed to set carveout for %s: %d\n", node, - err); - return err; - } - - if (copy) - free(copy); - - index++; - } - - return 0; -} - -static void ft_carveout_setup(void *fdt) -{ - const void *cboot_fdt = (const void *)cboot_boot_x0; - static const char * const nodes[] = { - "/host1x@50000000/dc@54200000", - "/host1x@50000000/dc@54240000", - "/external-memory-controller@7001b000", - }; - unsigned int i; - int err; - - for (i = 0; i < ARRAY_SIZE(nodes); i++) { - err = ft_copy_carveout(fdt, cboot_fdt, nodes[i]); - if (err < 0) { - if (err != -FDT_ERR_NOTFOUND) - printf("failed to copy carveout for %s: %d\n", - nodes[i], err); - continue; - } - } -} +static const char * const nodes[] = { + "/host1x@50000000/dc@54200000", + "/host1x@50000000/dc@54240000", + "/external-memory-controller@7001b000", +}; int ft_board_setup(void *fdt, struct bd_info *bd) { ft_mac_address_setup(fdt); - ft_carveout_setup(fdt); + ft_carveout_setup(fdt, nodes, ARRAY_SIZE(nodes)); return 0; } diff --git a/board/nvidia/p2771-0000/p2771-0000.c b/board/nvidia/p2771-0000/p2771-0000.c index 46c36a22db5e..5ff89c45423e 100644 --- a/board/nvidia/p2771-0000/p2771-0000.c +++ b/board/nvidia/p2771-0000/p2771-0000.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include "../p2571/max77620_init.h" void pin_mux_mmc(void) @@ -60,128 +60,16 @@ int tegra_pcie_board_init(void) } #endif -static void ft_mac_address_setup(void *fdt) -{ - const void *cboot_fdt = (const void *)cboot_boot_x0; - uint8_t mac[ETH_ALEN], local_mac[ETH_ALEN]; - const char *path; - int offset, err; - - err = cboot_get_ethaddr(cboot_fdt, local_mac); - if (err < 0) - memset(local_mac, 0, ETH_ALEN); - - path = fdt_get_alias(fdt, "ethernet"); - if (!path) - return; - - debug("ethernet alias found: %s\n", path); - - offset = fdt_path_offset(fdt, path); - if (offset < 0) { - printf("ethernet alias points to absent node %s\n", path); - return; - } - - if (is_valid_ethaddr(local_mac)) { - err = fdt_setprop(fdt, offset, "local-mac-address", local_mac, - ETH_ALEN); - if (!err) - debug("Local MAC address set: %pM\n", local_mac); - } - - if (eth_env_get_enetaddr("ethaddr", mac)) { - if (memcmp(local_mac, mac, ETH_ALEN) != 0) { - err = fdt_setprop(fdt, offset, "mac-address", mac, - ETH_ALEN); - if (!err) - debug("MAC address set: %pM\n", mac); - } - } -} - -static int ft_copy_carveout(void *dst, const void *src, const char *node) -{ - unsigned int index = 0; - int err; - - while (true) { - const char **compatibles = NULL; - unsigned int num_compatibles; - struct fdt_memory carveout; - unsigned long flags; - char *copy = NULL; - const char *name; - - err = fdtdec_get_carveout(src, node, "memory-region", index, - &carveout, &name, &compatibles, - &num_compatibles, &flags); - if (err < 0) { - if (err != -FDT_ERR_NOTFOUND) - printf("failed to get carveout for %s: %d\n", - node, err); - - return err; - } - - if (name) { - const char *ptr = strchr(name, '@'); - - if (ptr) { - copy = strndup(name, ptr - name); - name = copy; - } - } else { - name = "carveout"; - } - - err = fdtdec_set_carveout(dst, node, "memory-region", index, - &carveout, name, compatibles, - num_compatibles, flags); - if (err < 0) { - printf("failed to set carveout for %s: %d\n", node, - err); - return err; - } - - if (copy) - free(copy); - - index++; - } - - return 0; -} - -static void ft_carveout_setup(void *fdt) -{ - const void *cboot_fdt = (const void *)cboot_boot_x0; - static const char * const nodes[] = { - "/host1x@13e00000/display-hub@15200000/display@15200000", - "/host1x@13e00000/display-hub@15200000/display@15210000", - "/host1x@13e00000/display-hub@15200000/display@15220000", - }; - unsigned int i; - int err; - - for (i = 0; i < ARRAY_SIZE(nodes); i++) { - printf("copying carveout for %s...\n", nodes[i]); - - err = ft_copy_carveout(fdt, cboot_fdt, nodes[i]); - if (err < 0) { - if (err != -FDT_ERR_NOTFOUND) - printf("failed to copy carveout for %s: %d\n", - nodes[i], err); - - continue; - } - } -} +static const char * const nodes[] = { + "/host1x@13e00000/display-hub@15200000/display@15200000", + "/host1x@13e00000/display-hub@15200000/display@15210000", + "/host1x@13e00000/display-hub@15200000/display@15220000", +}; int ft_board_setup(void *fdt, struct bd_info *bd) { ft_mac_address_setup(fdt); - ft_carveout_setup(fdt); + ft_carveout_setup(fdt, nodes, ARRAY_SIZE(nodes)); return 0; } diff --git a/board/nvidia/p3450-0000/p3450-0000.c b/board/nvidia/p3450-0000/p3450-0000.c index dd408d2ebbf8..cad36f56cff8 100644 --- a/board/nvidia/p3450-0000/p3450-0000.c +++ b/board/nvidia/p3450-0000/p3450-0000.c @@ -12,10 +12,9 @@ #include #include #include -#include -#include #include #include +#include #include "../p2571/max77620_init.h" void pin_mux_mmc(void) @@ -84,128 +83,16 @@ int tegra_pcie_board_init(void) } #endif /* PCI */ -static void ft_mac_address_setup(void *fdt) -{ - const void *cboot_fdt = (const void *)cboot_boot_x0; - uint8_t mac[ETH_ALEN], local_mac[ETH_ALEN]; - const char *path; - int offset, err; - - err = cboot_get_ethaddr(cboot_fdt, local_mac); - if (err < 0) - memset(local_mac, 0, ETH_ALEN); - - path = fdt_get_alias(fdt, "ethernet"); - if (!path) - return; - - debug("ethernet alias found: %s\n", path); - - offset = fdt_path_offset(fdt, path); - if (offset < 0) { - printf("ethernet alias points to absent node %s\n", path); - return; - } - - if (is_valid_ethaddr(local_mac)) { - err = fdt_setprop(fdt, offset, "local-mac-address", local_mac, - ETH_ALEN); - if (!err) - debug("Local MAC address set: %pM\n", local_mac); - } - - if (eth_env_get_enetaddr("ethaddr", mac)) { - if (memcmp(local_mac, mac, ETH_ALEN) != 0) { - err = fdt_setprop(fdt, offset, "mac-address", mac, - ETH_ALEN); - if (!err) - debug("MAC address set: %pM\n", mac); - } - } -} - -static int ft_copy_carveout(void *dst, const void *src, const char *node) -{ - unsigned int index = 0; - int err; - - while (true) { - const char **compatibles = NULL; - unsigned int num_compatibles; - struct fdt_memory carveout; - unsigned long flags; - char *copy = NULL; - const char *name; - - err = fdtdec_get_carveout(src, node, "memory-region", index, - &carveout, &name, &compatibles, - &num_compatibles, &flags); - if (err < 0) { - if (err != -FDT_ERR_NOTFOUND) - printf("failed to get carveout for %s: %d\n", - node, err); - - return err; - } - - if (name) { - const char *ptr = strchr(name, '@'); - - if (ptr) { - copy = strndup(name, ptr - name); - name = copy; - } - } else { - name = "carveout"; - } - - err = fdtdec_set_carveout(dst, node, "memory-region", index, - &carveout, name, compatibles, - num_compatibles, flags); - if (err < 0) { - printf("failed to set carveout for %s: %d\n", node, - err); - return err; - } - - if (copy) - free(copy); - - index++; - } - - return 0; -} - -static void ft_carveout_setup(void *fdt) -{ - const void *cboot_fdt = (const void *)cboot_boot_x0; - static const char * const nodes[] = { - "/host1x@50000000/dc@54200000", - "/host1x@50000000/dc@54240000", - "/external-memory-controller@7001b000", - }; - unsigned int i; - int err; - - for (i = 0; i < ARRAY_SIZE(nodes); i++) { - printf("copying carveout for %s...\n", nodes[i]); - - err = ft_copy_carveout(fdt, cboot_fdt, nodes[i]); - if (err < 0) { - if (err != -FDT_ERR_NOTFOUND) - printf("failed to copy carveout for %s: %d\n", - nodes[i], err); - - continue; - } - } -} +static const char * const nodes[] = { + "/host1x@50000000/dc@54200000", + "/host1x@50000000/dc@54240000", + "/external-memory-controller@7001b000", +}; int ft_board_setup(void *fdt, struct bd_info *bd) { ft_mac_address_setup(fdt); - ft_carveout_setup(fdt); + ft_carveout_setup(fdt, nodes, ARRAY_SIZE(nodes)); return 0; } -- 2.33.0