2017-12-29 15:42:37

by Aleksandar Markovic

[permalink] [raw]
Subject: [PATCH v12 0/3] MIPS: Add virtual Ranchu board as a generic-based board

From: Aleksandar Markovic <[email protected]>

v11->v12:

- rebased to the latest code

v10->v11:

- rebased to the latest code

v9->v10:

- added comment in code segment related to measuring frequency
- rebased to the latest code

v8->v9:

- cleaned up PIC initialization details
- added missing '\n' to pr_err() invocations
- removed two Goldfish FB patches, since they got accepted
- rebased to the latest code

v7->v8:

- cleaned commit message for patch #2
- cleaned GPL licence text for patch #2
- revised Goldfish PIC error and info messages
- simplified code around MIPS_MACHINE() for Ranchu
- changed an instance of "__initdata" to "__initconst" in Ranchu
- rebased to the latest code

v6->v7:

- improved commit message for patch 5 (Add Ranchu as a...)
- added code comments for segment that reads clock high/low
- revised usage of "u32", "u64" variables in Ranchu code
- revised header inclusion in Ranchu code
- added code comments for segment that reads clock high/low
- improved displayed message for Ranchu in Kconfig
- added a Ranchu-specific file as maintained in MAINTAINERS
- added proper handling of an error case in PIC initialization
- improved error messages issued during PIC initialization
- rebased to the latest code

v5->v6:

- revised cascading handling code in Goldfish PIC implementation
- used more generic node name in Goldfish PIC documentation file
- used more generic node name in Goldfish FB documentation file
- corrected several minor items in both documentation files
- revisited copyright messages in two source files
- rebased to the latest code

v4->v5:

- removed RTC clock-related patches since they are already applied
- removed 8042-related patch since this issue is expected to be
resolved on the whole platform level
- redesigned Goldfish PIC driver
- updated email addresses in commit messages and MAINTAINERS file
to contain "@mips.com" instead of "@imgtec.com"
- used "MIPS" instead of "Mips" in commit messages
- rebased to the latest code

v3->v4:

- corrected RTC clock patch so that it does not cause build
errors for some targets, and limited compile support to MIPS
architecture, since it is the only case where this driver is
used
- changed titles of patches 2 and 4 to make them consistent
with commit messages of corresponding directories
- applied "checkpatch --strict" to the whole series and
corrected several instances of reported warnings
- rebased to the latest code

v2->v3:

- fixed configuration dependency for VIRTIO_NET and
RTC_DRV_GOLDFISH
- fixed frequency calculation in ranchu_measure_hpt_freq()
- use DT info instead of hard-coding RTC base in
ranchu_measure_hpt_freq()
- Goldfish PIC reworked to follow legacy irq domain paradigm
- Goldfish RTC reimplemented to support alarm functionality
- added COMPILE_TEST to Goldfish PIC & RTC to extend compile
test coverage
- corrected location of documentation for Goldfish FB
- added a patch on unselecting ARCH_MIGHT_HAVE_PC_SERIO
- removed two patches on i8042 as not needed in new organization
- removed the patch on separate MIPS Android config as not needed
- rebased to the latest code

v1->v2:

- patch on RTC driver cleaned up
- added drivers for virtio console and net to the Ranchu board
- minor improvements in commit messages
- updated recipient lists using get_maintainer.pl
- rebased to the latest code

This series adds MIPS Ranchu virtual machine used by Android emulator.
The board relies on the concept of MIPS generic boards, and utilizes
generic board framework for build and device organization.

The Ranchu board is intended to be used by Android emulator.The name
"Ranchu" originates from Android development community. "Goldfish" and
"Ranchu" are names for two generations of virtual boards used by
Android emulator. "Ranchu" is a newer one among the two, and this
series deals with Ranchu. However, for historical reasons, some file,
device, and variable names in this series still contain the word
"Goldfish".

MIPS Ranchu machine includes a number of Goldfish devices. The
support for Virtio devices is also included. Ranchu board supports
up to 16 virtio devices which can be attached using virtio MMIO Bus.
This is summarized in the following picture:

ABUS
||----MIPS CPU
|| | IRQs
||----Goldfish PIC------------(32)--------
|| | | | | | | | | |
||----Goldfish TTY------ | | | | | | | |
|| | | | | | | | |
||----Goldfish RTC-------- | | | | | | |
|| | | | | | | |
||----Goldfish FB----------- | | | | | |
|| | | | | | |
||----Goldfish Events--------- | | | | |
|| | | | | |
||----Goldfish Audio------------ | | | |
|| | | | |
||----Goldfish Battery------------ | | |
|| | | |
||----Android PIPE------------------ | |
|| | |
||----Virtio MMIO Bus | |
|| | | | | |
|| | | (virtio-block)--------- |
|| (16) | |
|| | (virtio-net)------------------


Device Tree is created on the QEMU side based on the information about
devices IO map and IRQ numbers. Kernel will load this DTB using UHI
boot protocol.

Checkpatch script outputs a small number of warnings if applied to
this series. We did not correct the code, since we think the code is
correct for those particular cases of checkpatch warnings.

Miodrag Dinic (3):
Documentation: Add device tree binding for Goldfish PIC driver
irqchip/irq-goldfish-pic: Add Goldfish PIC driver
MIPS: ranchu: Add Ranchu as a new generic-based board

.../interrupt-controller/google,goldfish-pic.txt | 30 +++++
MAINTAINERS | 13 ++
arch/mips/configs/generic/board-ranchu.config | 30 +++++
arch/mips/generic/Kconfig | 10 ++
arch/mips/generic/Makefile | 1 +
arch/mips/generic/board-ranchu.c | 92 ++++++++++++++
drivers/irqchip/Kconfig | 8 ++
drivers/irqchip/Makefile | 1 +
drivers/irqchip/irq-goldfish-pic.c | 139 +++++++++++++++++++++
9 files changed, 324 insertions(+)
create mode 100644 Documentation/devicetree/bindings/interrupt-controller/google,goldfish-pic.txt
create mode 100644 arch/mips/configs/generic/board-ranchu.config
create mode 100644 arch/mips/generic/board-ranchu.c
create mode 100644 drivers/irqchip/irq-goldfish-pic.c

--
2.7.4


2017-12-29 15:43:23

by Aleksandar Markovic

[permalink] [raw]
Subject: [PATCH v12 1/3] Documentation: Add device tree binding for Goldfish PIC driver

From: Miodrag Dinic <[email protected]>

Add documentation for DT binding of Goldfish PIC driver. The compatible
string used by OS for binding the driver is "google,goldfish-pic".

Signed-off-by: Miodrag Dinic <[email protected]>
Signed-off-by: Goran Ferenc <[email protected]>
Signed-off-by: Aleksandar Markovic <[email protected]>
Acked-by: Rob Herring <[email protected]>
---
.../interrupt-controller/google,goldfish-pic.txt | 30 ++++++++++++++++++++++
MAINTAINERS | 5 ++++
2 files changed, 35 insertions(+)
create mode 100644 Documentation/devicetree/bindings/interrupt-controller/google,goldfish-pic.txt

diff --git a/Documentation/devicetree/bindings/interrupt-controller/google,goldfish-pic.txt b/Documentation/devicetree/bindings/interrupt-controller/google,goldfish-pic.txt
new file mode 100644
index 0000000..35f7527
--- /dev/null
+++ b/Documentation/devicetree/bindings/interrupt-controller/google,goldfish-pic.txt
@@ -0,0 +1,30 @@
+Android Goldfish PIC
+
+Android Goldfish programmable interrupt device used by Android
+emulator.
+
+Required properties:
+
+- compatible : should contain "google,goldfish-pic"
+- reg : <registers mapping>
+- interrupts : <interrupt mapping>
+
+Example for mips when used in cascade mode:
+
+ cpuintc {
+ #interrupt-cells = <0x1>;
+ #address-cells = <0>;
+ interrupt-controller;
+ compatible = "mti,cpu-interrupt-controller";
+ };
+
+ interrupt-controller@1f000000 {
+ compatible = "google,goldfish-pic";
+ reg = <0x1f000000 0x1000>;
+
+ interrupt-controller;
+ #interrupt-cells = <0x1>;
+
+ interrupt-parent = <&cpuintc>;
+ interrupts = <0x2>;
+ };
diff --git a/MAINTAINERS b/MAINTAINERS
index a6e86e2..7152b90 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -867,6 +867,11 @@ S: Supported
F: drivers/android/
F: drivers/staging/android/

+ANDROID GOLDFISH PIC DRIVER
+M: Miodrag Dinic <[email protected]>
+S: Supported
+F: Documentation/devicetree/bindings/interrupt-controller/google,goldfish-pic.txt
+
ANDROID GOLDFISH RTC DRIVER
M: Miodrag Dinic <[email protected]>
S: Supported
--
2.7.4

2017-12-29 15:44:06

by Aleksandar Markovic

[permalink] [raw]
Subject: [PATCH v12 2/3] irqchip/irq-goldfish-pic: Add Goldfish PIC driver

From: Miodrag Dinic <[email protected]>

Add device driver for a virtual programmable interrupt controller

The virtual PIC is designed as a device tree-based interrupt controller.

The compatible string used by OS for binding the driver is
"google,goldfish-pic".

Signed-off-by: Miodrag Dinic <[email protected]>
Signed-off-by: Goran Ferenc <[email protected]>
Signed-off-by: Aleksandar Markovic <[email protected]>
---
MAINTAINERS | 1 +
drivers/irqchip/Kconfig | 8 +++
drivers/irqchip/Makefile | 1 +
drivers/irqchip/irq-goldfish-pic.c | 139 +++++++++++++++++++++++++++++++++++++
4 files changed, 149 insertions(+)
create mode 100644 drivers/irqchip/irq-goldfish-pic.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 7152b90..e163873 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -871,6 +871,7 @@ ANDROID GOLDFISH PIC DRIVER
M: Miodrag Dinic <[email protected]>
S: Supported
F: Documentation/devicetree/bindings/interrupt-controller/google,goldfish-pic.txt
+F: drivers/irqchip/irq-goldfish-pic.c

ANDROID GOLDFISH RTC DRIVER
M: Miodrag Dinic <[email protected]>
diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig
index c70476b..d913aec 100644
--- a/drivers/irqchip/Kconfig
+++ b/drivers/irqchip/Kconfig
@@ -343,4 +343,12 @@ config MESON_IRQ_GPIO
help
Support Meson SoC Family GPIO Interrupt Multiplexer

+config GOLDFISH_PIC
+ bool "Goldfish programmable interrupt controller"
+ depends on MIPS && (GOLDFISH || COMPILE_TEST)
+ select IRQ_DOMAIN
+ help
+ Say yes here to enable Goldfish interrupt controller driver used
+ for Goldfish based virtual platforms.
+
endmenu
diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
index d2df34a..d27e3e3 100644
--- a/drivers/irqchip/Makefile
+++ b/drivers/irqchip/Makefile
@@ -84,3 +84,4 @@ obj-$(CONFIG_QCOM_IRQ_COMBINER) += qcom-irq-combiner.o
obj-$(CONFIG_IRQ_UNIPHIER_AIDET) += irq-uniphier-aidet.o
obj-$(CONFIG_ARCH_SYNQUACER) += irq-sni-exiu.o
obj-$(CONFIG_MESON_IRQ_GPIO) += irq-meson-gpio.o
+obj-$(CONFIG_GOLDFISH_PIC) += irq-goldfish-pic.o
diff --git a/drivers/irqchip/irq-goldfish-pic.c b/drivers/irqchip/irq-goldfish-pic.c
new file mode 100644
index 0000000..2a92f03
--- /dev/null
+++ b/drivers/irqchip/irq-goldfish-pic.c
@@ -0,0 +1,139 @@
+/*
+ * Driver for MIPS Goldfish Programmable Interrupt Controller.
+ *
+ * Author: Miodrag Dinic <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/irqchip.h>
+#include <linux/irqchip/chained_irq.h>
+#include <linux/irqdomain.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
+
+#define GFPIC_NR_IRQS 32
+
+/* 8..39 Cascaded Goldfish PIC interrupts */
+#define GFPIC_IRQ_BASE 8
+
+#define GFPIC_REG_IRQ_PENDING 0x04
+#define GFPIC_REG_IRQ_DISABLE_ALL 0x08
+#define GFPIC_REG_IRQ_DISABLE 0x0c
+#define GFPIC_REG_IRQ_ENABLE 0x10
+
+struct goldfish_pic_data {
+ void __iomem *base;
+ struct irq_domain *irq_domain;
+};
+
+static void goldfish_pic_cascade(struct irq_desc *desc)
+{
+ struct goldfish_pic_data *gfpic = irq_desc_get_handler_data(desc);
+ struct irq_chip *host_chip = irq_desc_get_chip(desc);
+ u32 pending, hwirq, virq;
+
+ chained_irq_enter(host_chip, desc);
+
+ pending = readl(gfpic->base + GFPIC_REG_IRQ_PENDING);
+ while (pending) {
+ hwirq = __fls(pending);
+ virq = irq_linear_revmap(gfpic->irq_domain, hwirq);
+ generic_handle_irq(virq);
+ pending &= ~(1 << hwirq);
+ }
+
+ chained_irq_exit(host_chip, desc);
+}
+
+static const struct irq_domain_ops goldfish_irq_domain_ops = {
+ .xlate = irq_domain_xlate_onecell,
+};
+
+static int __init goldfish_pic_of_init(struct device_node *of_node,
+ struct device_node *parent)
+{
+ struct goldfish_pic_data *gfpic;
+ struct irq_chip_generic *gc;
+ struct irq_chip_type *ct;
+ unsigned int parent_irq;
+ int ret = 0;
+
+ gfpic = kzalloc(sizeof(*gfpic), GFP_KERNEL);
+ if (!gfpic) {
+ ret = -ENOMEM;
+ goto out_err;
+ }
+
+ parent_irq = irq_of_parse_and_map(of_node, 0);
+ if (!parent_irq) {
+ pr_err("Failed to map parent IRQ!\n");
+ ret = -EINVAL;
+ goto out_free;
+ }
+
+ gfpic->base = of_iomap(of_node, 0);
+ if (!gfpic->base) {
+ pr_err("Failed to map base address!\n");
+ ret = -ENOMEM;
+ goto out_unmap_irq;
+ }
+
+ /* Mask interrupts. */
+ writel(1, gfpic->base + GFPIC_REG_IRQ_DISABLE_ALL);
+
+ gc = irq_alloc_generic_chip("GFPIC", 1, GFPIC_IRQ_BASE, gfpic->base,
+ handle_level_irq);
+ if (!gc) {
+ pr_err("Failed to allocate chip structures!\n");
+ ret = -ENOMEM;
+ goto out_iounmap;
+ }
+
+ ct = gc->chip_types;
+ ct->regs.enable = GFPIC_REG_IRQ_ENABLE;
+ ct->regs.disable = GFPIC_REG_IRQ_DISABLE;
+ ct->chip.irq_unmask = irq_gc_unmask_enable_reg;
+ ct->chip.irq_mask = irq_gc_mask_disable_reg;
+
+ irq_setup_generic_chip(gc, IRQ_MSK(GFPIC_NR_IRQS), 0,
+ IRQ_NOPROBE | IRQ_LEVEL, 0);
+
+ gfpic->irq_domain = irq_domain_add_legacy(of_node, GFPIC_NR_IRQS,
+ GFPIC_IRQ_BASE, 0,
+ &goldfish_irq_domain_ops,
+ NULL);
+ if (!gfpic->irq_domain) {
+ pr_err("Failed to add irqdomain!\n");
+ ret = -ENOMEM;
+ goto out_destroy_generic_chip;
+ }
+
+ irq_set_chained_handler_and_data(parent_irq,
+ goldfish_pic_cascade, gfpic);
+
+ pr_info("Successfully registered.\n");
+ return 0;
+
+out_destroy_generic_chip:
+ irq_destroy_generic_chip(gc, IRQ_MSK(GFPIC_NR_IRQS),
+ IRQ_NOPROBE | IRQ_LEVEL, 0);
+out_iounmap:
+ iounmap(gfpic->base);
+out_unmap_irq:
+ irq_dispose_mapping(parent_irq);
+out_free:
+ kfree(gfpic);
+out_err:
+ pr_err("Failed to initialize! (errno = %d)\n", ret);
+ return ret;
+}
+
+IRQCHIP_DECLARE(google_gf_pic, "google,goldfish-pic", goldfish_pic_of_init);
--
2.7.4

2017-12-29 15:44:21

by Aleksandar Markovic

[permalink] [raw]
Subject: [PATCH v12 3/3] MIPS: ranchu: Add Ranchu as a new generic-based board

From: Miodrag Dinic <[email protected]>

Provide amendments to the MIPS generic platform framework so that
the new generic-based board Ranchu can be chosen to be built.

The Ranchu board is intended to be used by Android emulator. The name
"Ranchu" originates from Android development community. "Goldfish" and
"Ranchu" are terms used for two generations of virtual boards used by
Android emulator. The name "Ranchu" is a newer one among the two, and
this patch deals with Ranchu. However, for historical reasons, some
devices/drivers still contain the name "Goldfish".

MIPS Ranchu machine includes a number of Goldfish devices. The support
for Virtio devices is also included. Ranchu board supports up to 16
Virtio devices which can be attached using Virtio MMIO Bus. This is
summarized in the following picture:

ABUS
||----MIPS CPU
|| | IRQs
||----Goldfish PIC------------(32)--------
|| | | | | | | | | |
||----Goldfish TTY------ | | | | | | | |
|| | | | | | | | |
||----Goldfish RTC-------- | | | | | | |
|| | | | | | | |
||----Goldfish FB----------- | | | | | |
|| | | | | | |
||----Goldfish Events--------- | | | | |
|| | | | | |
||----Goldfish Audio------------ | | | |
|| | | | |
||----Goldfish Battery------------ | | |
|| | | |
||----Android PIPE------------------ | |
|| | |
||----Virtio MMIO Bus | |
|| | | | | |
|| | | (virtio-block)--------- |
|| (16) | |
|| | (virtio-net)------------------

Device Tree is created on the QEMU side based on the information about
devices IO map and IRQ numbers. Kernel will load this DTB using UHI
boot protocol DTB handover mode.

Signed-off-by: Miodrag Dinic <[email protected]>
Signed-off-by: Goran Ferenc <[email protected]>
Signed-off-by: Aleksandar Markovic <[email protected]>
Reviewed-by: James Hogan <[email protected]>
---
MAINTAINERS | 7 ++
arch/mips/configs/generic/board-ranchu.config | 30 +++++++++
arch/mips/generic/Kconfig | 10 +++
arch/mips/generic/Makefile | 1 +
arch/mips/generic/board-ranchu.c | 92 +++++++++++++++++++++++++++
5 files changed, 140 insertions(+)
create mode 100644 arch/mips/configs/generic/board-ranchu.config
create mode 100644 arch/mips/generic/board-ranchu.c

diff --git a/MAINTAINERS b/MAINTAINERS
index e163873..95679c4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11442,6 +11442,13 @@ S: Maintained
F: Documentation/blockdev/ramdisk.txt
F: drivers/block/brd.c

+RANCHU VIRTUAL BOARD FOR MIPS
+M: Miodrag Dinic <[email protected]>
+L: [email protected]
+S: Supported
+F: arch/mips/generic/board-ranchu.c
+F: arch/mips/configs/generic/board-ranchu.config
+
RANDOM NUMBER DRIVER
M: "Theodore Ts'o" <[email protected]>
S: Maintained
diff --git a/arch/mips/configs/generic/board-ranchu.config b/arch/mips/configs/generic/board-ranchu.config
new file mode 100644
index 0000000..fee9ad4
--- /dev/null
+++ b/arch/mips/configs/generic/board-ranchu.config
@@ -0,0 +1,30 @@
+CONFIG_VIRT_BOARD_RANCHU=y
+
+CONFIG_BATTERY_GOLDFISH=y
+CONFIG_FB=y
+CONFIG_FB_GOLDFISH=y
+CONFIG_GOLDFISH=y
+CONFIG_STAGING=y
+CONFIG_GOLDFISH_AUDIO=y
+CONFIG_GOLDFISH_PIC=y
+CONFIG_GOLDFISH_PIPE=y
+CONFIG_GOLDFISH_TTY=y
+CONFIG_RTC_CLASS=y
+CONFIG_RTC_DRV_GOLDFISH=y
+
+CONFIG_INPUT_EVDEV=y
+CONFIG_INPUT_KEYBOARD=y
+CONFIG_KEYBOARD_GOLDFISH_EVENTS=y
+
+CONFIG_MAGIC_SYSRQ=y
+CONFIG_POWER_SUPPLY=y
+CONFIG_POWER_RESET=y
+CONFIG_POWER_RESET_SYSCON=y
+CONFIG_POWER_RESET_SYSCON_POWEROFF=y
+
+CONFIG_VIRTIO_BLK=y
+CONFIG_VIRTIO_CONSOLE=y
+CONFIG_VIRTIO_MMIO=y
+CONFIG_VIRTIO_MMIO_CMDLINE_DEVICES=y
+CONFIG_NETDEVICES=y
+CONFIG_VIRTIO_NET=y
diff --git a/arch/mips/generic/Kconfig b/arch/mips/generic/Kconfig
index 52e0286..2ff3b17 100644
--- a/arch/mips/generic/Kconfig
+++ b/arch/mips/generic/Kconfig
@@ -49,4 +49,14 @@ config FIT_IMAGE_FDT_XILFPGA
Enable this to include the FDT for the MIPSfpga platform
from Imagination Technologies in the FIT kernel image.

+config VIRT_BOARD_RANCHU
+ bool "Support Ranchu platform for Android emulator"
+ help
+ This enables support for the platform used by Android emulator.
+
+ Ranchu platform consists of a set of virtual devices. This platform
+ enables emulation of variety of virtual configurations while using
+ Android emulator. Android emulator is based on Qemu, and contains
+ the support for the same set of virtual devices.
+
endif
diff --git a/arch/mips/generic/Makefile b/arch/mips/generic/Makefile
index 8749673..5fb60c8 100644
--- a/arch/mips/generic/Makefile
+++ b/arch/mips/generic/Makefile
@@ -15,3 +15,4 @@ obj-y += proc.o
obj-$(CONFIG_YAMON_DT_SHIM) += yamon-dt.o
obj-$(CONFIG_LEGACY_BOARD_SEAD3) += board-sead3.o
obj-$(CONFIG_KEXEC) += kexec.o
+obj-$(CONFIG_VIRT_BOARD_RANCHU) += board-ranchu.o
diff --git a/arch/mips/generic/board-ranchu.c b/arch/mips/generic/board-ranchu.c
new file mode 100644
index 0000000..ea451b8
--- /dev/null
+++ b/arch/mips/generic/board-ranchu.c
@@ -0,0 +1,92 @@
+/*
+ * Support code for virtual Ranchu board for MIPS.
+ *
+ * Author: Miodrag Dinic <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ */
+
+#include <linux/of_address.h>
+#include <linux/types.h>
+
+#include <asm/machine.h>
+#include <asm/mipsregs.h>
+#include <asm/time.h>
+
+#define GOLDFISH_TIMER_LOW 0x00
+#define GOLDFISH_TIMER_HIGH 0x04
+
+static __init u64 read_rtc_time(void __iomem *base)
+{
+ u32 time_low;
+ u32 time_high;
+
+ /*
+ * Reading the low address latches the high value
+ * as well so there is no fear that we may read
+ * inaccurate high value.
+ */
+ time_low = readl(base + GOLDFISH_TIMER_LOW);
+ time_high = readl(base + GOLDFISH_TIMER_HIGH);
+
+ return ((u64)time_high << 32) | time_low;
+}
+
+static __init unsigned int ranchu_measure_hpt_freq(void)
+{
+ u64 rtc_start, rtc_current, rtc_delta;
+ unsigned int start, count;
+ struct device_node *np;
+ void __iomem *rtc_base;
+
+ np = of_find_compatible_node(NULL, NULL, "google,goldfish-rtc");
+ if (!np)
+ panic("%s(): Failed to find 'google,goldfish-rtc' dt node!",
+ __func__);
+
+ rtc_base = of_iomap(np, 0);
+ if (!rtc_base)
+ panic("%s(): Failed to ioremap Goldfish RTC base!", __func__);
+
+ /*
+ * Poll the nanosecond resolution RTC for one
+ * second to calibrate the CPU frequency.
+ */
+ rtc_start = read_rtc_time(rtc_base);
+ start = read_c0_count();
+
+ do {
+ rtc_current = read_rtc_time(rtc_base);
+ rtc_delta = rtc_current - rtc_start;
+ } while (rtc_delta < NSEC_PER_SEC);
+
+ count = read_c0_count() - start;
+
+ /*
+ * Make sure the frequency will be a round number.
+ * Without this correction, the returned value may vary
+ * between subsequent emulation executions.
+ *
+ * TODO: Set this value using device tree.
+ */
+ count += 5000;
+ count -= count % 10000;
+
+ iounmap(rtc_base);
+
+ return count;
+}
+
+static const struct of_device_id ranchu_of_match[] __initconst = {
+ {
+ .compatible = "mti,ranchu",
+ },
+};
+
+MIPS_MACHINE(ranchu) = {
+ .matches = ranchu_of_match,
+ .measure_hpt_freq = ranchu_measure_hpt_freq,
+};
--
2.7.4

2018-02-01 16:08:33

by James Hogan

[permalink] [raw]
Subject: Re: [PATCH v12 3/3] MIPS: ranchu: Add Ranchu as a new generic-based board

On Fri, Dec 29, 2017 at 04:41:47PM +0100, Aleksandar Markovic wrote:
> From: Miodrag Dinic <[email protected]>
>
> Provide amendments to the MIPS generic platform framework so that
> the new generic-based board Ranchu can be chosen to be built.
>
> The Ranchu board is intended to be used by Android emulator. The name
> "Ranchu" originates from Android development community. "Goldfish" and
> "Ranchu" are terms used for two generations of virtual boards used by
> Android emulator. The name "Ranchu" is a newer one among the two, and
> this patch deals with Ranchu. However, for historical reasons, some
> devices/drivers still contain the name "Goldfish".
>
> MIPS Ranchu machine includes a number of Goldfish devices. The support
> for Virtio devices is also included. Ranchu board supports up to 16
> Virtio devices which can be attached using Virtio MMIO Bus. This is
> summarized in the following picture:
>
> ABUS
> ||----MIPS CPU
> || | IRQs
> ||----Goldfish PIC------------(32)--------
> || | | | | | | | | |
> ||----Goldfish TTY------ | | | | | | | |
> || | | | | | | | |
> ||----Goldfish RTC-------- | | | | | | |
> || | | | | | | |
> ||----Goldfish FB----------- | | | | | |
> || | | | | | |
> ||----Goldfish Events--------- | | | | |
> || | | | | |
> ||----Goldfish Audio------------ | | | |
> || | | | |
> ||----Goldfish Battery------------ | | |
> || | | |
> ||----Android PIPE------------------ | |
> || | |
> ||----Virtio MMIO Bus | |
> || | | | | |
> || | | (virtio-block)--------- |
> || (16) | |
> || | (virtio-net)------------------
>
> Device Tree is created on the QEMU side based on the information about
> devices IO map and IRQ numbers. Kernel will load this DTB using UHI
> boot protocol DTB handover mode.
>
> Signed-off-by: Miodrag Dinic <[email protected]>
> Signed-off-by: Goran Ferenc <[email protected]>
> Signed-off-by: Aleksandar Markovic <[email protected]>
> Reviewed-by: James Hogan <[email protected]>

Applied to my 4.16 branch,

Thanks
James

> ---
> MAINTAINERS | 7 ++
> arch/mips/configs/generic/board-ranchu.config | 30 +++++++++
> arch/mips/generic/Kconfig | 10 +++
> arch/mips/generic/Makefile | 1 +
> arch/mips/generic/board-ranchu.c | 92 +++++++++++++++++++++++++++
> 5 files changed, 140 insertions(+)
> create mode 100644 arch/mips/configs/generic/board-ranchu.config
> create mode 100644 arch/mips/generic/board-ranchu.c
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index e163873..95679c4 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -11442,6 +11442,13 @@ S: Maintained
> F: Documentation/blockdev/ramdisk.txt
> F: drivers/block/brd.c
>
> +RANCHU VIRTUAL BOARD FOR MIPS
> +M: Miodrag Dinic <[email protected]>
> +L: [email protected]
> +S: Supported
> +F: arch/mips/generic/board-ranchu.c
> +F: arch/mips/configs/generic/board-ranchu.config
> +
> RANDOM NUMBER DRIVER
> M: "Theodore Ts'o" <[email protected]>
> S: Maintained
> diff --git a/arch/mips/configs/generic/board-ranchu.config b/arch/mips/configs/generic/board-ranchu.config
> new file mode 100644
> index 0000000..fee9ad4
> --- /dev/null
> +++ b/arch/mips/configs/generic/board-ranchu.config
> @@ -0,0 +1,30 @@
> +CONFIG_VIRT_BOARD_RANCHU=y
> +
> +CONFIG_BATTERY_GOLDFISH=y
> +CONFIG_FB=y
> +CONFIG_FB_GOLDFISH=y
> +CONFIG_GOLDFISH=y
> +CONFIG_STAGING=y
> +CONFIG_GOLDFISH_AUDIO=y
> +CONFIG_GOLDFISH_PIC=y
> +CONFIG_GOLDFISH_PIPE=y
> +CONFIG_GOLDFISH_TTY=y
> +CONFIG_RTC_CLASS=y
> +CONFIG_RTC_DRV_GOLDFISH=y
> +
> +CONFIG_INPUT_EVDEV=y
> +CONFIG_INPUT_KEYBOARD=y
> +CONFIG_KEYBOARD_GOLDFISH_EVENTS=y
> +
> +CONFIG_MAGIC_SYSRQ=y
> +CONFIG_POWER_SUPPLY=y
> +CONFIG_POWER_RESET=y
> +CONFIG_POWER_RESET_SYSCON=y
> +CONFIG_POWER_RESET_SYSCON_POWEROFF=y
> +
> +CONFIG_VIRTIO_BLK=y
> +CONFIG_VIRTIO_CONSOLE=y
> +CONFIG_VIRTIO_MMIO=y
> +CONFIG_VIRTIO_MMIO_CMDLINE_DEVICES=y
> +CONFIG_NETDEVICES=y
> +CONFIG_VIRTIO_NET=y
> diff --git a/arch/mips/generic/Kconfig b/arch/mips/generic/Kconfig
> index 52e0286..2ff3b17 100644
> --- a/arch/mips/generic/Kconfig
> +++ b/arch/mips/generic/Kconfig
> @@ -49,4 +49,14 @@ config FIT_IMAGE_FDT_XILFPGA
> Enable this to include the FDT for the MIPSfpga platform
> from Imagination Technologies in the FIT kernel image.
>
> +config VIRT_BOARD_RANCHU
> + bool "Support Ranchu platform for Android emulator"
> + help
> + This enables support for the platform used by Android emulator.
> +
> + Ranchu platform consists of a set of virtual devices. This platform
> + enables emulation of variety of virtual configurations while using
> + Android emulator. Android emulator is based on Qemu, and contains
> + the support for the same set of virtual devices.
> +
> endif
> diff --git a/arch/mips/generic/Makefile b/arch/mips/generic/Makefile
> index 8749673..5fb60c8 100644
> --- a/arch/mips/generic/Makefile
> +++ b/arch/mips/generic/Makefile
> @@ -15,3 +15,4 @@ obj-y += proc.o
> obj-$(CONFIG_YAMON_DT_SHIM) += yamon-dt.o
> obj-$(CONFIG_LEGACY_BOARD_SEAD3) += board-sead3.o
> obj-$(CONFIG_KEXEC) += kexec.o
> +obj-$(CONFIG_VIRT_BOARD_RANCHU) += board-ranchu.o
> diff --git a/arch/mips/generic/board-ranchu.c b/arch/mips/generic/board-ranchu.c
> new file mode 100644
> index 0000000..ea451b8
> --- /dev/null
> +++ b/arch/mips/generic/board-ranchu.c
> @@ -0,0 +1,92 @@
> +/*
> + * Support code for virtual Ranchu board for MIPS.
> + *
> + * Author: Miodrag Dinic <[email protected]>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU General Public License as published by the
> + * Free Software Foundation; either version 2 of the License, or (at your
> + * option) any later version.
> + */
> +
> +#include <linux/of_address.h>
> +#include <linux/types.h>
> +
> +#include <asm/machine.h>
> +#include <asm/mipsregs.h>
> +#include <asm/time.h>
> +
> +#define GOLDFISH_TIMER_LOW 0x00
> +#define GOLDFISH_TIMER_HIGH 0x04
> +
> +static __init u64 read_rtc_time(void __iomem *base)
> +{
> + u32 time_low;
> + u32 time_high;
> +
> + /*
> + * Reading the low address latches the high value
> + * as well so there is no fear that we may read
> + * inaccurate high value.
> + */
> + time_low = readl(base + GOLDFISH_TIMER_LOW);
> + time_high = readl(base + GOLDFISH_TIMER_HIGH);
> +
> + return ((u64)time_high << 32) | time_low;
> +}
> +
> +static __init unsigned int ranchu_measure_hpt_freq(void)
> +{
> + u64 rtc_start, rtc_current, rtc_delta;
> + unsigned int start, count;
> + struct device_node *np;
> + void __iomem *rtc_base;
> +
> + np = of_find_compatible_node(NULL, NULL, "google,goldfish-rtc");
> + if (!np)
> + panic("%s(): Failed to find 'google,goldfish-rtc' dt node!",
> + __func__);
> +
> + rtc_base = of_iomap(np, 0);
> + if (!rtc_base)
> + panic("%s(): Failed to ioremap Goldfish RTC base!", __func__);
> +
> + /*
> + * Poll the nanosecond resolution RTC for one
> + * second to calibrate the CPU frequency.
> + */
> + rtc_start = read_rtc_time(rtc_base);
> + start = read_c0_count();
> +
> + do {
> + rtc_current = read_rtc_time(rtc_base);
> + rtc_delta = rtc_current - rtc_start;
> + } while (rtc_delta < NSEC_PER_SEC);
> +
> + count = read_c0_count() - start;
> +
> + /*
> + * Make sure the frequency will be a round number.
> + * Without this correction, the returned value may vary
> + * between subsequent emulation executions.
> + *
> + * TODO: Set this value using device tree.
> + */
> + count += 5000;
> + count -= count % 10000;
> +
> + iounmap(rtc_base);
> +
> + return count;
> +}
> +
> +static const struct of_device_id ranchu_of_match[] __initconst = {
> + {
> + .compatible = "mti,ranchu",
> + },
> +};
> +
> +MIPS_MACHINE(ranchu) = {
> + .matches = ranchu_of_match,
> + .measure_hpt_freq = ranchu_measure_hpt_freq,
> +};
> --
> 2.7.4
>


Attachments:
(No filename) (8.44 kB)
signature.asc (849.00 B)
Digital signature
Download all attachments