From patchwork Mon Apr 11 16:26:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ovidiu Panait X-Patchwork-Id: 1615846 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=ps9h2Z5h; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KcZ6h5GPVz9sDX for ; Tue, 12 Apr 2022 02:28:44 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AAEC683E63; Mon, 11 Apr 2022 18:27:34 +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="ps9h2Z5h"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id ABEF783E51; Mon, 11 Apr 2022 18:27:07 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) (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 5213383BC9 for ; Mon, 11 Apr 2022 18:26:58 +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=ovpanait@gmail.com Received: by mail-ed1-x52a.google.com with SMTP id z12so6547266edl.2 for ; Mon, 11 Apr 2022 09:26:58 -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=3uIcIzT6207KtUgQKhrs+Ief9H8OnBGUPo4Qe6C15rs=; b=ps9h2Z5hZX6zAom6wEAMYv/0YHXBMkmCW1BqRvPV4+VvXW/GNfnztWPxDgkdYYvPYi 5QXjl6oVqGGuyirfxv6lyYIBQmsMBU7f6g+QfUBDy8g5GFhtx3GbTOs23MiOwwCXjPu2 3VQvZIM25juZC/IdttQZs4El+MvpnQ+bmSZUmvsMXXuImVmvovPgR2IVIJl5DtT2qWKV 2iroXOhCAuvYjfhdMxazGJG8Vsm3RSaUTUKgzJoSnL+ObEKakV5kgVG7UytLcMG79qzy AgHxZ1fReS3dLY+n07cxY1v0Q6hBiD14iMHaI5AADMpafEx34Vo9E/V19CW+g7DYqH94 Ablg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3uIcIzT6207KtUgQKhrs+Ief9H8OnBGUPo4Qe6C15rs=; b=ykFPh1a5gnz+TcwxflhO+eEykCV2amJ9Tbl2zn0mY/TdkPs4RP10x6HkEOM+SffWVQ L3ixGvsPv7KPpsA5zH5VfVr+upwok61wdhkY3E5O+GVbOI7O3QIAGuCKY1W2vFVJArzn RFERAjaxLfFJVeVE4SPapkF7MB2eP8i/7ay0/9WBQswELHJOr6wa3cw6deOlwynFuyUS vdRrTJFU6B0fy1JHndkTEHAUjBlRRe/mqqK+7kaFmq0rudEb3NygQbhil+H3bDdc4hZ2 ZotX37UZkI0+pnIDobpX1fg3Ht0VZmXL1DT6wtiPC3ZjUdV9DCaVoDJFTDh2P9QRdP9c Ggag== X-Gm-Message-State: AOAM533KaV3Xwmh0+zLU3es8bs0neCy48+IcchOBsZLGgloZK22CZfJG sYa7FaXu1BSzDEExnrJaGeyojXiCOH3InA== X-Google-Smtp-Source: ABdhPJz7ZxAO8+OrAr32o1rxjQwucSWlMcPOEw4k8KNRdf3e3FoDhQnJrgpxoavuQfWln6U9aZEjSA== X-Received: by 2002:a50:bf0f:0:b0:410:c512:cb6f with SMTP id f15-20020a50bf0f000000b00410c512cb6fmr34414350edk.262.1649694417978; Mon, 11 Apr 2022 09:26:57 -0700 (PDT) Received: from wsdell.corp.ad.wrs.com ([2a02:2f0e:c41b:f600:4ab1:7aea:1e9:311a]) by smtp.gmail.com with ESMTPSA id y26-20020a1709063a9a00b006e0c272e263sm12111417ejd.71.2022.04.11.09.26.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 09:26:57 -0700 (PDT) From: Ovidiu Panait To: u-boot@lists.denx.de Cc: Ovidiu Panait , Michal Simek , Michal Simek Subject: [PATCH 09/10] cpu: microblaze: add driver for CPU Date: Mon, 11 Apr 2022 19:26:33 +0300 Message-Id: <20220411162634.69647-9-ovpanait@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220411162634.69647-1-ovpanait@gmail.com> References: <20220411162634.69647-1-ovpanait@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.5 at phobos.denx.de X-Virus-Status: Clean Add a basic CPU driver that retrieves information about the microblaze CPU core. At this time, only data related to instruction/data caches is extracted from fdt. Signed-off-by: Ovidiu Panait --- arch/microblaze/include/asm/cache.h | 5 + arch/microblaze/include/asm/microblaze_cpu.h | 53 +++++++++ drivers/cpu/Kconfig | 6 + drivers/cpu/Makefile | 1 + drivers/cpu/microblaze_cpu.c | 109 +++++++++++++++++++ 5 files changed, 174 insertions(+) create mode 100644 arch/microblaze/include/asm/microblaze_cpu.h create mode 100644 drivers/cpu/microblaze_cpu.c diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h index c39b66dd7d..58ec69603e 100644 --- a/arch/microblaze/include/asm/cache.h +++ b/arch/microblaze/include/asm/cache.h @@ -23,4 +23,9 @@ */ void flush_cache_all(void); +enum cache_type { + DCACHE, + ICACHE +}; + #endif /* __MICROBLAZE_CACHE_H__ */ diff --git a/arch/microblaze/include/asm/microblaze_cpu.h b/arch/microblaze/include/asm/microblaze_cpu.h new file mode 100644 index 0000000000..8aad966e54 --- /dev/null +++ b/arch/microblaze/include/asm/microblaze_cpu.h @@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2022, Ovidiu Panait + */ + +#ifndef __MICROBLAZE_CPU_H +#define __MICROBLAZE_CPU_H + +#include + +/** + * struct microblaze_cpu_plat - Platform data for microblaze processor core. + * + * @icache_size: Size of instruction cache memory in bytes. + * @icache_line_length: Instruction cache line length in bytes. + * @dcache_size: Size of data cache memory in bytes. + * @dcache_line_length: Data cache line length in bytes. + */ +struct microblaze_cpu_plat { + u32 icache_size; + u32 icache_line_length; + + u32 dcache_size; + u32 dcache_line_length; +}; + +/** + * microblaze_cpu_get_cacheline_size() - Get the cache line size + * + * Returns the cache line size in bytes for the cache memory type specified in + * @type (dcache or icache). Probes the first UCLASS CPU device via + * uclass_get_device() if not already active. + * + * @type: Cache type (dcache or icache) + * Return: + * >= 0 if OK, -ENODEV if there is an error getting cpu device data + */ +int microblaze_cpu_get_cacheline_size(enum cache_type type); + +/** + * microblaze_cpu_get_cache_size() - Get the cache size + * + * Returns the cache size in bytes for the cache memory type specified in @type + * (dcache or icache). Probes the first UCLASS CPU device via + * uclass_get_device() if not already active. + * + * @type: Cache type (dcache or icache) + * Return: + * >= 0 if OK, -ENODEV if there is an error getting cpu device data + */ +int microblaze_cpu_get_cache_size(enum cache_type type); + +#endif /* __MICROBLAZE_CPU_H */ diff --git a/drivers/cpu/Kconfig b/drivers/cpu/Kconfig index 3d5729f6dc..c4b124da3f 100644 --- a/drivers/cpu/Kconfig +++ b/drivers/cpu/Kconfig @@ -19,3 +19,9 @@ config CPU_RISCV depends on CPU && RISCV help Support CPU cores for RISC-V architecture. + +config CPU_MICROBLAZE + bool "Enable Microblaze CPU driver" + depends on CPU && MICROBLAZE + help + Support CPU cores for Microblaze architecture. diff --git a/drivers/cpu/Makefile b/drivers/cpu/Makefile index c8532637ca..20884b1795 100644 --- a/drivers/cpu/Makefile +++ b/drivers/cpu/Makefile @@ -11,4 +11,5 @@ obj-$(CONFIG_ARCH_IMX8) += imx8_cpu.o obj-$(CONFIG_ARCH_AT91) += at91_cpu.o obj-$(CONFIG_CPU_MPC83XX) += mpc83xx_cpu.o obj-$(CONFIG_CPU_RISCV) += riscv_cpu.o +obj-$(CONFIG_CPU_MICROBLAZE) += microblaze_cpu.o obj-$(CONFIG_SANDBOX) += cpu_sandbox.o diff --git a/drivers/cpu/microblaze_cpu.c b/drivers/cpu/microblaze_cpu.c new file mode 100644 index 0000000000..823ac5671e --- /dev/null +++ b/drivers/cpu/microblaze_cpu.c @@ -0,0 +1,109 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2022, Ovidiu Panait + */ +#include +#include + +static struct microblaze_cpu_plat *get_cpu0_plat(void) +{ + struct udevice *dev; + + if (uclass_get_device(UCLASS_CPU, 0, &dev) == 0) + return dev_get_plat(dev); + + return NULL; +} + +int microblaze_cpu_get_cacheline_size(enum cache_type type) +{ + struct microblaze_cpu_plat *plat = get_cpu0_plat(); + + if (!plat) + return -ENODEV; + + if (type == DCACHE) + return plat->dcache_line_length; + + return plat->icache_line_length; +} + +int microblaze_cpu_get_cache_size(enum cache_type type) +{ + struct microblaze_cpu_plat *plat = get_cpu0_plat(); + + if (!plat) + return -ENODEV; + + if (type == DCACHE) + return plat->dcache_size; + + return plat->icache_size; +} + +static int microblaze_cpu_of_to_plat(struct udevice *dev) +{ + struct microblaze_cpu_plat *plat = dev_get_plat(dev); + + plat->icache_size = dev_read_u32_default(dev, "i-cache-size", 0); + plat->icache_line_length = dev_read_u32_default(dev, + "xlnx,icache-line-len", 0); + plat->icache_line_length <<= 2; + + plat->dcache_size = dev_read_u32_default(dev, "d-cache-size", 0); + plat->dcache_line_length = dev_read_u32_default(dev, + "xlnx,dcache-line-len", 0); + plat->dcache_line_length <<= 2; + + return 0; +} + +static const struct udevice_id microblaze_cpu_ids[] = { + { .compatible = "xlnx,microblaze-11.0" }, + { .compatible = "xlnx,microblaze-10.0" }, + { .compatible = "xlnx,microblaze-9.0.6" }, + { .compatible = "xlnx,microblaze-9.0.5" }, + { .compatible = "xlnx,microblaze-9.0.4" }, + { .compatible = "xlnx,microblaze-9.0.3" }, + { .compatible = "xlnx,microblaze-9.0.2" }, + { .compatible = "xlnx,microblaze-9.0.1" }, + { .compatible = "xlnx,microblaze-9.0.0" }, + { .compatible = "xlnx,microblaze-8.50.c" }, + { .compatible = "xlnx,microblaze-8.50.b" }, + { .compatible = "xlnx,microblaze-8.50.a" }, + { .compatible = "xlnx,microblaze-8.40.b" }, + { .compatible = "xlnx,microblaze-8.40.a" }, + { .compatible = "xlnx,microblaze-8.30.a" }, + { .compatible = "xlnx,microblaze-8.20.b" }, + { .compatible = "xlnx,microblaze-8.20.a" }, + { .compatible = "xlnx,microblaze-8.10.a" }, + { .compatible = "xlnx,microblaze-8.00.b" }, + { .compatible = "xlnx,microblaze-8.00.a" }, + { .compatible = "xlnx,microblaze-7.30.b" }, + { .compatible = "xlnx,microblaze-7.30.a" }, + { .compatible = "xlnx,microblaze-7.20.d" }, + { .compatible = "xlnx,microblaze-7.20.c" }, + { .compatible = "xlnx,microblaze-7.20.b" }, + { .compatible = "xlnx,microblaze-7.20.a" }, + { .compatible = "xlnx,microblaze-7.10.d" }, + { .compatible = "xlnx,microblaze-7.10.c" }, + { .compatible = "xlnx,microblaze-7.10.b" }, + { .compatible = "xlnx,microblaze-7.10.a" }, + { .compatible = "xlnx,microblaze-7.00.b" }, + { .compatible = "xlnx,microblaze-7.00.a" }, + { .compatible = "xlnx,microblaze-6.00.b" }, + { .compatible = "xlnx,microblaze-6.00.a" }, + { .compatible = "xlnx,microblaze-5.00.c" }, + { .compatible = "xlnx,microblaze-5.00.b" }, + { .compatible = "xlnx,microblaze-5.00.a" }, + { } +}; + +U_BOOT_DRIVER(microblaze_cpu) = { + .name = "microblaze_cpu", + .id = UCLASS_CPU, + .of_match = microblaze_cpu_ids, + .of_to_plat = microblaze_cpu_of_to_plat, + .plat_auto = sizeof(struct microblaze_cpu_plat), + .flags = DM_FLAG_PRE_RELOC, +};