From nobody Sun Nov 16 05:40:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1598532364; cv=none; d=zohomail.com; s=zohoarc; b=e7lvlA2jfrpbnkUzAASQGbMfmSnjlfNGGFD2grLYdZjrBUakYPEEERx+HsdMl/WNfG9Pfoh/7D25qEB8SZGkoZfSKg6XXBYAEMKOhOQeXr+Z1lOiNh2jvtFxm8QeoH8xqtV7YU81PHYS6pwHayt1LfudUgeR0bIhquSsyOOH9/g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598532364; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GtS9zww2uI9JlGnHUkPEZw786WMh7PRdXYUFHEqeMnc=; b=U2a4NEgwXbwXVl9ecm6vWaqEXttH9aqLBqoLQE2qjsQz7NSERXjqhhpWgpiVRkhx0Vsh3rRq1E9eUoXyeHUkdrlIVNVUczetecMlqabHJ7Fv2OrCLMxSQdcPNluwD3b+mBQJYo9KCQOTxVDJeImG4wsKBqyk+0DBOODBrcCzIFM= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1598532364820503.0927470375393; Thu, 27 Aug 2020 05:46:04 -0700 (PDT) Received: from localhost ([::1]:38338 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kBHI3-00045x-M0 for importer@patchew.org; Thu, 27 Aug 2020 08:46:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59072) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kBHBV-00087j-FK for qemu-devel@nongnu.org; Thu, 27 Aug 2020 08:39:17 -0400 Received: from mail02.asahi-net.or.jp ([202.224.55.14]:56309) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kBHBP-0005wW-6A for qemu-devel@nongnu.org; Thu, 27 Aug 2020 08:39:17 -0400 Received: from sakura.ysato.name (ik1-413-38519.vs.sakura.ne.jp [153.127.30.23]) (Authenticated sender: PQ4Y-STU) by mail02.asahi-net.or.jp (Postfix) with ESMTPA id 8DE1826838; Thu, 27 Aug 2020 21:39:09 +0900 (JST) Received: from yo-satoh-debian.localdomain (ZM005235.ppp.dion.ne.jp [222.8.5.235]) by sakura.ysato.name (Postfix) with ESMTPSA id 495171C0696; Thu, 27 Aug 2020 21:39:09 +0900 (JST) From: Yoshinori Sato To: qemu-devel@nongnu.org Subject: [PATCH 18/20] hw/rx: Add Tokudenkairo TKDN-RX62N-BRD Date: Thu, 27 Aug 2020 21:38:57 +0900 Message-Id: <20200827123859.81793-19-ysato@users.sourceforge.jp> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200827123859.81793-1-ysato@users.sourceforge.jp> References: <20200827123859.81793-1-ysato@users.sourceforge.jp> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: softfail client-ip=202.224.55.14; envelope-from=ysato@users.sourceforge.jp; helo=mail02.asahi-net.or.jp X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/27 08:39:06 X-ACL-Warn: Detected OS = ??? X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yoshinori Sato Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Hardware information. http://www.tokudenkairo.co.jp/rx62n/ (Japanese) Signed-off-by: Yoshinori Sato --- default-configs/rx-softmmu.mak | 1 + hw/rx/tkdn-rx62n.c | 192 +++++++++++++++++++++++++++++++++ hw/rx/Kconfig | 6 ++ hw/rx/meson.build | 1 + 4 files changed, 200 insertions(+) create mode 100644 hw/rx/tkdn-rx62n.c diff --git a/default-configs/rx-softmmu.mak b/default-configs/rx-softmmu.mak index df2b4e4f42..ea8731d67b 100644 --- a/default-configs/rx-softmmu.mak +++ b/default-configs/rx-softmmu.mak @@ -1,3 +1,4 @@ # Default configuration for rx-softmmu =20 CONFIG_RX_GDBSIM=3Dy +CONFIG_TKDN_RX62N=3Dy diff --git a/hw/rx/tkdn-rx62n.c b/hw/rx/tkdn-rx62n.c new file mode 100644 index 0000000000..3db0fc8294 --- /dev/null +++ b/hw/rx/tkdn-rx62n.c @@ -0,0 +1,192 @@ +/* + * Tokushudenshikairo TKDN-RX62N-BRD + * + * Copyright (c) 2020 Yoshinori Sato + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License f= or + * more details. + * + * You should have received a copy of the GNU General Public License along= with + * this program. If not, see . + */ + +#include "qemu/osdep.h" +#include "qemu/cutils.h" +#include "qapi/error.h" +#include "qemu-common.h" +#include "cpu.h" +#include "hw/hw.h" +#include "hw/sysbus.h" +#include "hw/loader.h" +#include "hw/rx/loader.h" +#include "hw/qdev-properties.h" +#include "hw/rx/rx62n.h" +#include "net/net.h" +#include "hw/net/mii.h" +#include "hw/boards.h" +#include "sysemu/sysemu.h" +#include "sysemu/qtest.h" +#include "sysemu/device_tree.h" + +typedef struct { + /*< private >*/ + MachineState parent_obj; + /*< public >*/ + RX62NState mcu; + PHYState phy; + MDIOState mdio; +} TKDN_RX62NMachineState; + +#define TYPE_TKDN_RX62N_MACHINE MACHINE_TYPE_NAME("tkdn-rx62n-brd") + +#define TKDN_RX62N_MACHINE(obj) \ + OBJECT_CHECK(TKDN_RX62NMachineState, (obj), TYPE_TKDN_RX62N_MACHINE) + +#define TINYBOOT_TOP (0xffffff00) + +static void set_bootstrap(hwaddr entry, hwaddr dtb) +{ + /* Minimal hardware initialize for kernel requirement */ + /* linux kernel only works little-endian mode */ + static uint8_t tinyboot[256] =3D { + 0xfb, 0x2e, 0x20, 0x00, 0x08, /* mov.l #0x80020, r2 */ + 0xf8, 0x2e, 0x00, 0x01, 0x01, /* mov.l #0x00010100, [r2] */ + 0xfb, 0x2e, 0x10, 0x00, 0x08, /* mov.l #0x80010, r2 */ + 0xf8, 0x22, 0xdf, 0x7d, 0xff, 0xff, /* mov.l #0xffff7ddf, [r2] */ + 0x62, 0x42, /* add #4, r2 */ + 0xf8, 0x22, 0xff, 0x7f, 0xff, 0x7f, /* mov.l #0x7fff7fff, [r2] */ + 0xfb, 0x2e, 0x40, 0x82, 0x08, /* mov.l #0x88240, r2 */ + 0x3c, 0x22, 0x00, /* mov.b #0, 2[r2] */ + 0x3c, 0x21, 0x4e, /* mov.b #78, 1[r2] */ + 0xfb, 0x22, 0x70, 0xff, 0xff, 0xff, /* mov.l #0xffffff70, r2 */ + 0xec, 0x21, /* mov.l [r2], r1 */ + 0xfb, 0x22, 0x74, 0xff, 0xff, 0xff, /* mov.l #0xffffff74, r2 */ + 0xec, 0x22, /* mov.l [r2], r2 */ + 0x7f, 0x02, /* jmp r2 */ + }; + int i; + + *((uint32_t *)&tinyboot[0x70]) =3D cpu_to_le32(dtb); + *((uint32_t *)&tinyboot[0x74]) =3D cpu_to_le32(entry); + + /* setup exception trap trampoline */ + for (i =3D 0; i < 31; i++) { + *((uint32_t *)&tinyboot[0x80 + i * 4]) =3D cpu_to_le32(0x10 + i * = 4); + } + *((uint32_t *)&tinyboot[0xfc]) =3D cpu_to_le32(TINYBOOT_TOP); + rom_add_blob_fixed("tinyboot", tinyboot, sizeof(tinyboot), TINYBOOT_TO= P); +} + +/* Link 100BaseTX-FD */ +#define BMSR (MII_BMSR_100TX_FD | MII_BMSR_100TX_HD | \ + MII_BMSR_10T_FD | MII_BMSR_10T_HD | MII_BMSR_MFPS | \ + MII_BMSR_AN_COMP | MII_BMSR_AUTONEG) +#define ANLPAR (MII_ANLPAR_TXFD | MII_ANAR_CSMACD) + +static void tkdn_rx62n_net_init(MachineState *m, RX62NState *s, + NICInfo *nd) +{ + TKDN_RX62NMachineState *t =3D TKDN_RX62N_MACHINE(m); + object_initialize_child(OBJECT(t), "ether-phy", + &t->phy, TYPE_ETHER_PHY); + qdev_prop_set_uint32(DEVICE(&t->phy), "phy-id", 0x0007c0f0); /* LAN872= 0A */ + qdev_prop_set_uint32(DEVICE(&t->phy), "link-out-pol", phy_out_p); + qdev_prop_set_uint16(DEVICE(&t->phy), "bmsr", BMSR); + qdev_prop_set_uint16(DEVICE(&t->phy), "anlpar", ANLPAR); + qdev_realize(DEVICE(&t->phy), NULL, &error_abort); + + object_initialize_child(OBJECT(t), "mdio-bb", + &t->mdio, TYPE_ETHER_MDIO_BB); + object_property_set_link(OBJECT(&t->mdio), "phy", + OBJECT(&t->phy), &error_abort); + qdev_prop_set_int32(DEVICE(&t->mdio), "address", 0); + qdev_realize(DEVICE(&t->mdio), NULL, &error_abort); +} + +#define SDRAM_BASE 0x08000000 + +static void tkdn_rx62n_init(MachineState *machine) +{ + MachineClass *mc =3D MACHINE_GET_CLASS(machine); + TKDN_RX62NMachineState *s =3D TKDN_RX62N_MACHINE(machine); + RX62NClass *rx62nc; + MemoryRegion *sysmem =3D get_system_memory(); + const char *kernel_filename =3D machine->kernel_filename; + const char *dtb_filename =3D machine->dtb; + rx_kernel_info_t kernel_info; + + if (machine->ram_size < mc->default_ram_size) { + char *sz =3D size_to_str(mc->default_ram_size); + error_report("Invalid RAM size, should be more than %s", sz); + g_free(sz); + } + + /* Allocate memory space */ + memory_region_add_subregion(sysmem, SDRAM_BASE, machine->ram); + + /* Initialize MCU */ + object_initialize_child(OBJECT(machine), "mcu", + &s->mcu, TYPE_R5F562N8_MCU); + rx62nc =3D RX62N_MCU_GET_CLASS(&s->mcu); + object_property_set_link(OBJECT(&s->mcu), "main-bus", OBJECT(sysmem), + &error_abort); + object_property_set_uint(OBJECT(&s->mcu), "xtal-frequency-hz", + 12 * 1000 * 1000, &error_abort); + tkdn_rx62n_net_init(machine, &s->mcu, nd_table); + object_property_set_link(OBJECT(&s->mcu), "mdiodev", + OBJECT(&s->mdio), &error_abort); + /* Load kernel and dtb */ + if (kernel_filename) { + kernel_info.ram_start =3D SDRAM_BASE; + kernel_info.ram_size =3D machine->ram_size; + kernel_info.filename =3D kernel_filename; + kernel_info.dtbname =3D dtb_filename; + kernel_info.cmdline =3D machine->kernel_cmdline; + if (!load_kernel(&kernel_info)) { + exit(1); + } + set_bootstrap(kernel_info.entry, kernel_info.dtb_address); + } else { + if (bios_name) { + if (!load_bios(bios_name, rx62nc->rom_flash_size, &error_abort= )) { + exit(0); + } + } else if (!qtest_enabled()) { + error_report("No bios or kernel specified"); + exit(1); + } + } + qdev_realize(DEVICE(&s->mcu), NULL, &error_abort); +} + +static void tkdn_rx62n_class_init(ObjectClass *oc, void *data) +{ + MachineClass *mc =3D MACHINE_CLASS(oc); + + mc->desc =3D "TokushuDenshiKairo Inc, TKDN-RX62N-BRD"; + mc->init =3D tkdn_rx62n_init; + mc->is_default =3D 0; + mc->default_cpu_type =3D TYPE_RX62N_CPU; + mc->default_ram_size =3D 16 * MiB; + mc->default_ram_id =3D "ext-sdram"; +} + +static const TypeInfo tkdn_rx62n_type =3D { + .name =3D TYPE_TKDN_RX62N_MACHINE, + .parent =3D TYPE_MACHINE, + .instance_size =3D sizeof(TKDN_RX62NMachineState), + .class_init =3D tkdn_rx62n_class_init, +}; + +static void tkdn_rx62n_machine_init(void) +{ + type_register_static(&tkdn_rx62n_type); +} + +type_init(tkdn_rx62n_machine_init) diff --git a/hw/rx/Kconfig b/hw/rx/Kconfig index f20ea63fd9..0ef20d0c3c 100644 --- a/hw/rx/Kconfig +++ b/hw/rx/Kconfig @@ -11,3 +11,9 @@ config RX_GDBSIM bool select RX62N_MCU select FITLOADER + +config TKDN_RX62N + bool + select RX62N_MCU + select FITLOADER + diff --git a/hw/rx/meson.build b/hw/rx/meson.build index 3a81d85a53..0a741e091c 100644 --- a/hw/rx/meson.build +++ b/hw/rx/meson.build @@ -1,6 +1,7 @@ rx_ss =3D ss.source_set() rx_ss.add(files('loader.c')) rx_ss.add(when: 'CONFIG_RX_GDBSIM', if_true: files('rx-gdbsim.c')) +rx_ss.add(when: 'CONFIG_TKDN_RX62N', if_true: files('tkdn-rx62n.c')) rx_ss.add(when: 'CONFIG_RX62N_MCU', if_true: files('rx62n.c', 'rx62n-cpg.c= ')) =20 hw_arch +=3D {'rx': rx_ss} --=20 2.20.1