mbox series

[V9,0/6] mips: Add Loongson-3 machine support

Message ID 1600222344-16808-1-git-send-email-chenhc@lemote.com
Headers show
Series mips: Add Loongson-3 machine support | expand

Message

chen huacai Sept. 16, 2020, 2:12 a.m. UTC
Loongson-3 CPU family include Loongson-3A R1/R2/R3/R4 and Loongson-3B
R1/R2. Loongson-3A R1 is the oldest and its ISA is the smallest, while
Loongson-3A R4 is the newest and its ISA is almost the superset of all
others. To reduce complexity, in QEMU we just define two CPU types:

1, "Loongson-3A1000" CPU which is corresponding to Loongson-3A R1. It is
   suitable for TCG because Loongson-3A R1 has fewest ASE.
2, "Loongson-3A4000" CPU which is corresponding to Loongson-3A R4. It is
   suitable for KVM because Loongson-3A R4 has the VZ ASE.

Loongson-3 lacks English documents. I've tried to translated them with
translate.google.com, and the machine translated documents (together
with their original Chinese versions) are available here.

Loongson-3A R1 (Loongson-3A1000)
User Manual Part 1:
http://ftp.godson.ac.cn/lemote/3A1000_p1.pdf
http://ftp.godson.ac.cn/lemote/Loongson3A1000_processor_user_manual_P1.pdf (Chinese Version)
User Manual Part 2:
http://ftp.godson.ac.cn/lemote/3A1000_p2.pdf
http://ftp.godson.ac.cn/lemote/Loongson3A1000_processor_user_manual_P2.pdf (Chinese Version)

Loongson-3A R2 (Loongson-3A2000)
User Manual Part 1:
http://ftp.godson.ac.cn/lemote/3A2000_p1.pdf
http://ftp.godson.ac.cn/lemote/Loongson3A2000_user1.pdf (Chinese Version)
User Manual Part 2:
http://ftp.godson.ac.cn/lemote/3A2000_p2.pdf
http://ftp.godson.ac.cn/lemote/Loongson3A2000_user2.pdf (Chinese Version)

Loongson-3A R3 (Loongson-3A3000)
User Manual Part 1:
http://ftp.godson.ac.cn/lemote/3A3000_p1.pdf
http://ftp.godson.ac.cn/lemote/Loongson3A3000_3B3000usermanual1.pdf (Chinese Version)
User Manual Part 2:
http://ftp.godson.ac.cn/lemote/3A3000_p2.pdf
http://ftp.godson.ac.cn/lemote/Loongson3A3000_3B3000usermanual2.pdf (Chinese Version)

Loongson-3A R4 (Loongson-3A4000)
User Manual Part 1:
http://ftp.godson.ac.cn/lemote/3A4000_p1.pdf
http://ftp.godson.ac.cn/lemote/3A4000user.pdf (Chinese Version)
User Manual Part 2:
I'm sorry that it is unavailable now.

And human-translated documents (W.I.P) are available here now:
https://github.com/loongson-community/docs/tree/master/English-translation-of-Loongson-manual

Both KVM and TCG are available now!

We now already have a full functional Linux kernel (based on Linux-5.4.x
LTS, the kvm host side and guest side have both been upstream for Linux-
5.9, but Linux-5.9 has not been released yet) here:

https://github.com/chenhuacai/linux

Of course the upstream kernel is also usable (though it is "unstable"
now):

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

How to use QEMU/Loongson-3?
1, Download kernel source from the above URL;
2, Build a kernel with arch/mips/configs/loongson3_{def,hpc}config;
3, Boot a Loongson-3A4000 host with this kernel (for KVM mode);
4, Build QEMU-master with this patchset;
5, modprobe kvm (only necessary for KVM mode);
6, Use QEMU with TCG:
       qemu-system-mips64el -M loongson3-virt,accel=tcg -cpu Loongson-3A1000 -kernel <path_to_kernel> -append ...
   Use QEMU with KVM:
       qemu-system-mips64el -M loongson3-virt,accel=kvm -cpu Loongson-3A4000 -kernel <path_to_kernel> -append ...

   The "-cpu" parameter is optional here and QEMU will use the correct type for TCG/KVM automatically.

V1 -> V2:
1, Add a cover letter;
2, Improve CPU definitions;
3, Remove LS7A-related things (Use GPEX instead);
4, Add a description of how to run QEMU/Loongson-3.

V2 -> V3:
1, Fix all possible checkpatch.pl errors and warnings.

V3 -> V4:
1, Sync code with upstream;
2, Remove merged patches;
3, Fix build failure without CONFIG_KVM;
4, Add Reviewed-by: Aleksandar Markovic <aleksandar.qemu.devel@gmail.com>.

V4 -> V5:
1, Improve coding style;
2, Remove merged patches;
3, Rename machine name from "loongson3" to "loongson3-virt";
4, Rework the "loongson3-virt" machine to drop any ISA things;
5, Rework "hw/mips: Implement the kvm_type() hook in MachineClass";
6, Add Jiaxun Yang as a reviewer of Loongson-3.

V5 -> V6:
1, Fix license preamble;
2, Improve commit messages;
3, Add hw/intc/loongson_liointc.c to MAINTAINERS;
4, Fix all possible checkpatch.pl errors and warnings.

V7 and V8 have only one patch (machine definition) with some minor improvements.

V8 -> V9:
1, Update KVM type definition from kernel;
2, Fix PageMask with variable page size for TCG;
3, Add TCG support (add Loongson-EXT instructions).

Huacai Chen and Jiaxun Yang (6):
 linux-headers: Update MIPS KVM type defintition
 target/mips: Fix PageMask with variable page size
 target/mips: Add loongson-ext lswc2 group of instructions (Part 1)
 target/mips: Add loongson-ext lswc2 group of instructions (Part 2)
 target/mips: Add loongson-ext lsdc2 group of instructions
 hw/mips: Add Loongson-3 machine support

Signed-off-by: Huacai Chen <chenhc@lemote.com>
---
 default-configs/mips64el-softmmu.mak |   1 +
 hw/mips/Kconfig                      |  11 +
 hw/mips/fw_cfg.c                     |  35 ++
 hw/mips/fw_cfg.h                     |  19 +
 hw/mips/loongson3_virt.c             | 956 +++++++++++++++++++++++++++++++++++
 hw/mips/meson.build                  |   3 +-
 linux-headers/linux/kvm.h            |   5 +-
 target/mips/cp0_helper.c             |  36 +-
 target/mips/cpu.h                    |   1 +
 target/mips/translate.c              | 437 ++++++++++++++++
 10 files changed, 1494 insertions(+), 10 deletions(-)
 create mode 100644 hw/mips/fw_cfg.c
 create mode 100644 hw/mips/fw_cfg.h
 create mode 100644 hw/mips/loongson3_virt.c
--
2.7.0

Comments

Richard Henderson Sept. 16, 2020, 3:15 p.m. UTC | #1
On 9/15/20 7:12 PM, Huacai Chen wrote:
> +    case OPC_GSLQ:
> +        gen_base_offset_addr(ctx, t0, rs, lsq_offset);
> +        tcg_gen_qemu_ld_tl(t0, t0, ctx->mem_idx, MO_TEQ |
> +                            ctx->default_tcg_memop_mask);
> +        gen_store_gpr(t0, rt);
> +        gen_base_offset_addr(ctx, t0, rs, lsq_offset + 8);
> +        tcg_gen_qemu_ld_tl(t0, t0, ctx->mem_idx, MO_TEQ |
> +                            ctx->default_tcg_memop_mask);
> +        gen_store_gpr(t0, lsq_rt1);

If rs == rt, this will compute the wrong address for the second load.

Either avoid storing t0 back to rt until both loads are complete, or retain the
address temporary and simply add 8 between the two loads.


r~
Philippe Mathieu-Daudé Sept. 17, 2020, 7:56 a.m. UTC | #2
Hi Huacai,

On 9/16/20 4:12 AM, Huacai Chen wrote:
> Loongson-3 CPU family include Loongson-3A R1/R2/R3/R4 and Loongson-3B
> R1/R2. Loongson-3A R1 is the oldest and its ISA is the smallest, while
> Loongson-3A R4 is the newest and its ISA is almost the superset of all
> others. To reduce complexity, in QEMU we just define two CPU types:
> 
> 1, "Loongson-3A1000" CPU which is corresponding to Loongson-3A R1. It is
>    suitable for TCG because Loongson-3A R1 has fewest ASE.
> 2, "Loongson-3A4000" CPU which is corresponding to Loongson-3A R4. It is
>    suitable for KVM because Loongson-3A R4 has the VZ ASE.
> 
[...]

> Of course the upstream kernel is also usable (though it is "unstable"
> now):
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
> 
> How to use QEMU/Loongson-3?
> 1, Download kernel source from the above URL;
> 2, Build a kernel with arch/mips/configs/loongson3_{def,hpc}config;
> 3, Boot a Loongson-3A4000 host with this kernel (for KVM mode);
> 4, Build QEMU-master with this patchset;
> 5, modprobe kvm (only necessary for KVM mode);
> 6, Use QEMU with TCG:
>        qemu-system-mips64el -M loongson3-virt,accel=tcg -cpu Loongson-3A1000 -kernel <path_to_kernel> -append ...
>    Use QEMU with KVM:
>        qemu-system-mips64el -M loongson3-virt,accel=kvm -cpu Loongson-3A4000 -kernel <path_to_kernel> -append ...

Can you add a KVM-only build CI job?
Simply building, not running test, as there is no MIPS CI.

See for example commit 41e1f0e2256 (".travis.yml: Add a KVM-only
s390x job"), but add it to GitLab instead.

Thanks!

Phil.
Aleksandar Markovic Sept. 17, 2020, 8:22 a.m. UTC | #3
On Wednesday, September 16, 2020, Huacai Chen <zltjiangshi@gmail.com> wrote:

> Loongson-3 CPU family include Loongson-3A R1/R2/R3/R4 and Loongson-3B
> R1/R2. Loongson-3A R1 is the oldest and its ISA is the smallest, while
> Loongson-3A R4 is the newest and its ISA is almost the superset of all
> others. To reduce complexity, in QEMU we just define two CPU types:
>
> 1, "Loongson-3A1000" CPU which is corresponding to Loongson-3A R1. It is
>    suitable for TCG because Loongson-3A R1 has fewest ASE.
> 2, "Loongson-3A4000" CPU which is corresponding to Loongson-3A R4. It is
>    suitable for KVM because Loongson-3A R4 has the VZ ASE.
>
> Loongson-3 lacks English documents. I've tried to translated them with
> translate.google.com, and the machine translated documents (together
> with their original Chinese versions) are available here.
>
> Loongson-3A R1 (Loongson-3A1000)
> User Manual Part 1:
> http://ftp.godson.ac.cn/lemote/3A1000_p1.pdf
> http://ftp.godson.ac.cn/lemote/Loongson3A1000_processor_user_manual_P1.pdf
> (Chinese Version)
> User Manual Part 2:
> http://ftp.godson.ac.cn/lemote/3A1000_p2.pdf
> http://ftp.godson.ac.cn/lemote/Loongson3A1000_processor_user_manual_P2.pdf
> (Chinese Version)
>
> Loongson-3A R2 (Loongson-3A2000)
> User Manual Part 1:
> http://ftp.godson.ac.cn/lemote/3A2000_p1.pdf
> http://ftp.godson.ac.cn/lemote/Loongson3A2000_user1.pdf (Chinese Version)
> User Manual Part 2:
> http://ftp.godson.ac.cn/lemote/3A2000_p2.pdf
> http://ftp.godson.ac.cn/lemote/Loongson3A2000_user2.pdf (Chinese Version)
>
> Loongson-3A R3 (Loongson-3A3000)
> User Manual Part 1:
> http://ftp.godson.ac.cn/lemote/3A3000_p1.pdf
> http://ftp.godson.ac.cn/lemote/Loongson3A3000_3B3000usermanual1.pdf
> (Chinese Version)
> User Manual Part 2:
> http://ftp.godson.ac.cn/lemote/3A3000_p2.pdf
> http://ftp.godson.ac.cn/lemote/Loongson3A3000_3B3000usermanual2.pdf
> (Chinese Version)
>
> Loongson-3A R4 (Loongson-3A4000)
> User Manual Part 1:
> http://ftp.godson.ac.cn/lemote/3A4000_p1.pdf
> http://ftp.godson.ac.cn/lemote/3A4000user.pdf (Chinese Version)
> User Manual Part 2:
> I'm sorry that it is unavailable now.
>
> And human-translated documents (W.I.P) are available here now:
> https://github.com/loongson-community/docs/tree/master/
> English-translation-of-Loongson-manual
>
> Both KVM and TCG are available now!
>
> We now already have a full functional Linux kernel (based on Linux-5.4.x
> LTS, the kvm host side and guest side have both been upstream for Linux-
> 5.9, but Linux-5.9 has not been released yet) here:
>
> https://github.com/chenhuacai/linux
>
> Of course the upstream kernel is also usable (though it is "unstable"
> now):
>
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
>
> How to use QEMU/Loongson-3?
> 1, Download kernel source from the above URL;
> 2, Build a kernel with arch/mips/configs/loongson3_{def,hpc}config;
> 3, Boot a Loongson-3A4000 host with this kernel (for KVM mode);
> 4, Build QEMU-master with this patchset;
> 5, modprobe kvm (only necessary for KVM mode);
> 6, Use QEMU with TCG:
>        qemu-system-mips64el -M loongson3-virt,accel=tcg -cpu
> Loongson-3A1000 -kernel <path_to_kernel> -append ...
>    Use QEMU with KVM:
>        qemu-system-mips64el -M loongson3-virt,accel=kvm -cpu
> Loongson-3A4000 -kernel <path_to_kernel> -append ...
>
>    The "-cpu" parameter is optional here and QEMU will use the correct
> type for TCG/KVM automatically.
>
> V1 -> V2:
> 1, Add a cover letter;
> 2, Improve CPU definitions;
> 3, Remove LS7A-related things (Use GPEX instead);
> 4, Add a description of how to run QEMU/Loongson-3.
>
> V2 -> V3:
> 1, Fix all possible checkpatch.pl errors and warnings.
>
> V3 -> V4:
> 1, Sync code with upstream;
> 2, Remove merged patches;
> 3, Fix build failure without CONFIG_KVM;
> 4, Add Reviewed-by: Aleksandar Markovic <aleksandar.qemu.devel@gmail.com>.
>
> V4 -> V5:
> 1, Improve coding style;
> 2, Remove merged patches;
> 3, Rename machine name from "loongson3" to "loongson3-virt";
> 4, Rework the "loongson3-virt" machine to drop any ISA things;
> 5, Rework "hw/mips: Implement the kvm_type() hook in MachineClass";
> 6, Add Jiaxun Yang as a reviewer of Loongson-3.
>
> V5 -> V6:
> 1, Fix license preamble;
> 2, Improve commit messages;
> 3, Add hw/intc/loongson_liointc.c to MAINTAINERS;
> 4, Fix all possible checkpatch.pl errors and warnings.
>
> V7 and V8 have only one patch (machine definition) with some minor
> improvements.
>
> V8 -> V9:
> 1, Update KVM type definition from kernel;
> 2, Fix PageMask with variable page size for TCG;
> 3, Add TCG support (add Loongson-EXT instructions).
>
> Huacai Chen and Jiaxun Yang (6):
>  linux-headers: Update MIPS KVM type defintition
>  target/mips: Fix PageMask with variable page size
>  target/mips: Add loongson-ext lswc2 group of instructions (Part 1)
>  target/mips: Add loongson-ext lswc2 group of instructions (Part 2)
>  target/mips: Add loongson-ext lsdc2 group of instructions
>  hw/mips: Add Loongson-3 machine support
>
> Signed-off-by: Huacai Chen <chenhc@lemote.com>
> ---
>  default-configs/mips64el-softmmu.mak |   1 +
>  hw/mips/Kconfig                      |  11 +
>  hw/mips/fw_cfg.c                     |  35 ++
>  hw/mips/fw_cfg.h                     |  19 +
>  hw/mips/loongson3_virt.c             | 956 ++++++++++++++++++++++++++++++
> +++++
>  hw/mips/meson.build                  |   3 +-
>  linux-headers/linux/kvm.h            |   5 +-
>  target/mips/cp0_helper.c             |  36 +-
>  target/mips/cpu.h                    |   1 +
>  target/mips/translate.c              | 437 ++++++++++++++++
>  10 files changed, 1494 insertions(+), 10 deletions(-)
>  create mode 100644 hw/mips/fw_cfg.c
>  create mode 100644 hw/mips/fw_cfg.h
>  create mode 100644 hw/mips/loongson3_virt.c
> --


There should be a suitable note in QEMU documentation describing new
functionality.

Thanks,
Aleksandar



> 2.7.0
>
<br><br>On Wednesday, September 16, 2020, Huacai Chen &lt;<a href="mailto:zltjiangshi@gmail.com">zltjiangshi@gmail.com</a>&gt; wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Loongson-3 CPU family include Loongson-3A R1/R2/R3/R4 and Loongson-3B<br>
R1/R2. Loongson-3A R1 is the oldest and its ISA is the smallest, while<br>
Loongson-3A R4 is the newest and its ISA is almost the superset of all<br>
others. To reduce complexity, in QEMU we just define two CPU types:<br>
<br>
1, &quot;Loongson-3A1000&quot; CPU which is corresponding to Loongson-3A R1. It is<br>
   suitable for TCG because Loongson-3A R1 has fewest ASE.<br>
2, &quot;Loongson-3A4000&quot; CPU which is corresponding to Loongson-3A R4. It is<br>
   suitable for KVM because Loongson-3A R4 has the VZ ASE.<br>
<br>
Loongson-3 lacks English documents. I&#39;ve tried to translated them with<br>
<a href="http://translate.google.com" target="_blank">translate.google.com</a>, and the machine translated documents (together<br>
with their original Chinese versions) are available here.<br>
<br>
Loongson-3A R1 (Loongson-3A1000)<br>
User Manual Part 1:<br>
<a href="http://ftp.godson.ac.cn/lemote/3A1000_p1.pdf" target="_blank">http://ftp.godson.ac.cn/<wbr>lemote/3A1000_p1.pdf</a><br>
<a href="http://ftp.godson.ac.cn/lemote/Loongson3A1000_processor_user_manual_P1.pdf" target="_blank">http://ftp.godson.ac.cn/<wbr>lemote/Loongson3A1000_<wbr>processor_user_manual_P1.pdf</a> (Chinese Version)<br>
User Manual Part 2:<br>
<a href="http://ftp.godson.ac.cn/lemote/3A1000_p2.pdf" target="_blank">http://ftp.godson.ac.cn/<wbr>lemote/3A1000_p2.pdf</a><br>
<a href="http://ftp.godson.ac.cn/lemote/Loongson3A1000_processor_user_manual_P2.pdf" target="_blank">http://ftp.godson.ac.cn/<wbr>lemote/Loongson3A1000_<wbr>processor_user_manual_P2.pdf</a> (Chinese Version)<br>
<br>
Loongson-3A R2 (Loongson-3A2000)<br>
User Manual Part 1:<br>
<a href="http://ftp.godson.ac.cn/lemote/3A2000_p1.pdf" target="_blank">http://ftp.godson.ac.cn/<wbr>lemote/3A2000_p1.pdf</a><br>
<a href="http://ftp.godson.ac.cn/lemote/Loongson3A2000_user1.pdf" target="_blank">http://ftp.godson.ac.cn/<wbr>lemote/Loongson3A2000_user1.<wbr>pdf</a> (Chinese Version)<br>
User Manual Part 2:<br>
<a href="http://ftp.godson.ac.cn/lemote/3A2000_p2.pdf" target="_blank">http://ftp.godson.ac.cn/<wbr>lemote/3A2000_p2.pdf</a><br>
<a href="http://ftp.godson.ac.cn/lemote/Loongson3A2000_user2.pdf" target="_blank">http://ftp.godson.ac.cn/<wbr>lemote/Loongson3A2000_user2.<wbr>pdf</a> (Chinese Version)<br>
<br>
Loongson-3A R3 (Loongson-3A3000)<br>
User Manual Part 1:<br>
<a href="http://ftp.godson.ac.cn/lemote/3A3000_p1.pdf" target="_blank">http://ftp.godson.ac.cn/<wbr>lemote/3A3000_p1.pdf</a><br>
<a href="http://ftp.godson.ac.cn/lemote/Loongson3A3000_3B3000usermanual1.pdf" target="_blank">http://ftp.godson.ac.cn/<wbr>lemote/Loongson3A3000_<wbr>3B3000usermanual1.pdf</a> (Chinese Version)<br>
User Manual Part 2:<br>
<a href="http://ftp.godson.ac.cn/lemote/3A3000_p2.pdf" target="_blank">http://ftp.godson.ac.cn/<wbr>lemote/3A3000_p2.pdf</a><br>
<a href="http://ftp.godson.ac.cn/lemote/Loongson3A3000_3B3000usermanual2.pdf" target="_blank">http://ftp.godson.ac.cn/<wbr>lemote/Loongson3A3000_<wbr>3B3000usermanual2.pdf</a> (Chinese Version)<br>
<br>
Loongson-3A R4 (Loongson-3A4000)<br>
User Manual Part 1:<br>
<a href="http://ftp.godson.ac.cn/lemote/3A4000_p1.pdf" target="_blank">http://ftp.godson.ac.cn/<wbr>lemote/3A4000_p1.pdf</a><br>
<a href="http://ftp.godson.ac.cn/lemote/3A4000user.pdf" target="_blank">http://ftp.godson.ac.cn/<wbr>lemote/3A4000user.pdf</a> (Chinese Version)<br>
User Manual Part 2:<br>
I&#39;m sorry that it is unavailable now.<br>
<br>
And human-translated documents (W.I.P) are available here now:<br>
<a href="https://github.com/loongson-community/docs/tree/master/English-translation-of-Loongson-manual" target="_blank">https://github.com/loongson-<wbr>community/docs/tree/master/<wbr>English-translation-of-<wbr>Loongson-manual</a><br>
<br>
Both KVM and TCG are available now!<br>
<br>
We now already have a full functional Linux kernel (based on Linux-5.4.x<br>
LTS, the kvm host side and guest side have both been upstream for Linux-<br>
5.9, but Linux-5.9 has not been released yet) here:<br>
<br>
<a href="https://github.com/chenhuacai/linux" target="_blank">https://github.com/chenhuacai/<wbr>linux</a><br>
<br>
Of course the upstream kernel is also usable (though it is &quot;unstable&quot;<br>
now):<br>
<br>
<a href="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git" target="_blank">https://git.kernel.org/pub/<wbr>scm/linux/kernel/git/torvalds/<wbr>linux.git</a><br>
<br>
How to use QEMU/Loongson-3?<br>
1, Download kernel source from the above URL;<br>
2, Build a kernel with arch/mips/configs/loongson3_{<wbr>def,hpc}config;<br>
3, Boot a Loongson-3A4000 host with this kernel (for KVM mode);<br>
4, Build QEMU-master with this patchset;<br>
5, modprobe kvm (only necessary for KVM mode);<br>
6, Use QEMU with TCG:<br>
       qemu-system-mips64el -M loongson3-virt,accel=tcg -cpu Loongson-3A1000 -kernel &lt;path_to_kernel&gt; -append ...<br>
   Use QEMU with KVM:<br>
       qemu-system-mips64el -M loongson3-virt,accel=kvm -cpu Loongson-3A4000 -kernel &lt;path_to_kernel&gt; -append ...<br>
<br>
   The &quot;-cpu&quot; parameter is optional here and QEMU will use the correct type for TCG/KVM automatically.<br>
<br>
V1 -&gt; V2:<br>
1, Add a cover letter;<br>
2, Improve CPU definitions;<br>
3, Remove LS7A-related things (Use GPEX instead);<br>
4, Add a description of how to run QEMU/Loongson-3.<br>
<br>
V2 -&gt; V3:<br>
1, Fix all possible <a href="http://checkpatch.pl" target="_blank">checkpatch.pl</a> errors and warnings.<br>
<br>
V3 -&gt; V4:<br>
1, Sync code with upstream;<br>
2, Remove merged patches;<br>
3, Fix build failure without CONFIG_KVM;<br>
4, Add Reviewed-by: Aleksandar Markovic &lt;<a href="mailto:aleksandar.qemu.devel@gmail.com">aleksandar.qemu.devel@gmail.<wbr>com</a>&gt;.<br>
<br>
V4 -&gt; V5:<br>
1, Improve coding style;<br>
2, Remove merged patches;<br>
3, Rename machine name from &quot;loongson3&quot; to &quot;loongson3-virt&quot;;<br>
4, Rework the &quot;loongson3-virt&quot; machine to drop any ISA things;<br>
5, Rework &quot;hw/mips: Implement the kvm_type() hook in MachineClass&quot;;<br>
6, Add Jiaxun Yang as a reviewer of Loongson-3.<br>
<br>
V5 -&gt; V6:<br>
1, Fix license preamble;<br>
2, Improve commit messages;<br>
3, Add hw/intc/loongson_liointc.c to MAINTAINERS;<br>
4, Fix all possible <a href="http://checkpatch.pl" target="_blank">checkpatch.pl</a> errors and warnings.<br>
<br>
V7 and V8 have only one patch (machine definition) with some minor improvements.<br>
<br>
V8 -&gt; V9:<br>
1, Update KVM type definition from kernel;<br>
2, Fix PageMask with variable page size for TCG;<br>
3, Add TCG support (add Loongson-EXT instructions).<br>
<br>
Huacai Chen and Jiaxun Yang (6):<br>
 linux-headers: Update MIPS KVM type defintition<br>
 target/mips: Fix PageMask with variable page size<br>
 target/mips: Add loongson-ext lswc2 group of instructions (Part 1)<br>
 target/mips: Add loongson-ext lswc2 group of instructions (Part 2)<br>
 target/mips: Add loongson-ext lsdc2 group of instructions<br>
 hw/mips: Add Loongson-3 machine support<br>
<br>
Signed-off-by: Huacai Chen &lt;<a href="mailto:chenhc@lemote.com">chenhc@lemote.com</a>&gt;<br>
---<br>
 default-configs/mips64el-<wbr>softmmu.mak |   1 +<br>
 hw/mips/Kconfig                      |  11 +<br>
 hw/mips/fw_cfg.c                     |  35 ++<br>
 hw/mips/fw_cfg.h                     |  19 +<br>
 hw/mips/loongson3_virt.c             | 956 ++++++++++++++++++++++++++++++<wbr>+++++<br>
 hw/mips/meson.build                  |   3 +-<br>
 linux-headers/linux/kvm.h            |   5 +-<br>
 target/mips/cp0_helper.c             |  36 +-<br>
 target/mips/cpu.h                    |   1 +<br>
 target/mips/translate.c              | 437 ++++++++++++++++<br>
 10 files changed, 1494 insertions(+), 10 deletions(-)<br>
 create mode 100644 hw/mips/fw_cfg.c<br>
 create mode 100644 hw/mips/fw_cfg.h<br>
 create mode 100644 hw/mips/loongson3_virt.c<br>
--</blockquote><div><br></div><div>There should be a suitable note in QEMU documentation describing new functionality.</div><div><br></div><div>Thanks,</div><div>Aleksandar</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
2.7.0<br>
</blockquote>
Huacai Chen Sept. 19, 2020, 12:44 a.m. UTC | #4
Hi, Richard,

On Wed, Sep 16, 2020 at 11:15 PM Richard Henderson
<richard.henderson@linaro.org> wrote:
>

> On 9/15/20 7:12 PM, Huacai Chen wrote:

> > +    case OPC_GSLQ:

> > +        gen_base_offset_addr(ctx, t0, rs, lsq_offset);

> > +        tcg_gen_qemu_ld_tl(t0, t0, ctx->mem_idx, MO_TEQ |

> > +                            ctx->default_tcg_memop_mask);

> > +        gen_store_gpr(t0, rt);

> > +        gen_base_offset_addr(ctx, t0, rs, lsq_offset + 8);

> > +        tcg_gen_qemu_ld_tl(t0, t0, ctx->mem_idx, MO_TEQ |

> > +                            ctx->default_tcg_memop_mask);

> > +        gen_store_gpr(t0, lsq_rt1);

>

> If rs == rt, this will compute the wrong address for the second load.

>

> Either avoid storing t0 back to rt until both loads are complete, or retain the

> address temporary and simply add 8 between the two loads.

OK, this will be improved in V10.

>

>

> r~
chen huacai Sept. 21, 2020, 2:19 a.m. UTC | #5
Hi, Aleksandar,

On Thu, Sep 17, 2020 at 4:22 PM Aleksandar Markovic
<aleksandar.qemu.devel@gmail.com> wrote:
>

>

>

> On Wednesday, September 16, 2020, Huacai Chen <zltjiangshi@gmail.com> wrote:

>>

>> Loongson-3 CPU family include Loongson-3A R1/R2/R3/R4 and Loongson-3B

>> R1/R2. Loongson-3A R1 is the oldest and its ISA is the smallest, while

>> Loongson-3A R4 is the newest and its ISA is almost the superset of all

>> others. To reduce complexity, in QEMU we just define two CPU types:

>>

>> 1, "Loongson-3A1000" CPU which is corresponding to Loongson-3A R1. It is

>>    suitable for TCG because Loongson-3A R1 has fewest ASE.

>> 2, "Loongson-3A4000" CPU which is corresponding to Loongson-3A R4. It is

>>    suitable for KVM because Loongson-3A R4 has the VZ ASE.

>>

>> Loongson-3 lacks English documents. I've tried to translated them with

>> translate.google.com, and the machine translated documents (together

>> with their original Chinese versions) are available here.

>>

>> Loongson-3A R1 (Loongson-3A1000)

>> User Manual Part 1:

>> http://ftp.godson.ac.cn/lemote/3A1000_p1.pdf

>> http://ftp.godson.ac.cn/lemote/Loongson3A1000_processor_user_manual_P1.pdf (Chinese Version)

>> User Manual Part 2:

>> http://ftp.godson.ac.cn/lemote/3A1000_p2.pdf

>> http://ftp.godson.ac.cn/lemote/Loongson3A1000_processor_user_manual_P2.pdf (Chinese Version)

>>

>> Loongson-3A R2 (Loongson-3A2000)

>> User Manual Part 1:

>> http://ftp.godson.ac.cn/lemote/3A2000_p1.pdf

>> http://ftp.godson.ac.cn/lemote/Loongson3A2000_user1.pdf (Chinese Version)

>> User Manual Part 2:

>> http://ftp.godson.ac.cn/lemote/3A2000_p2.pdf

>> http://ftp.godson.ac.cn/lemote/Loongson3A2000_user2.pdf (Chinese Version)

>>

>> Loongson-3A R3 (Loongson-3A3000)

>> User Manual Part 1:

>> http://ftp.godson.ac.cn/lemote/3A3000_p1.pdf

>> http://ftp.godson.ac.cn/lemote/Loongson3A3000_3B3000usermanual1.pdf (Chinese Version)

>> User Manual Part 2:

>> http://ftp.godson.ac.cn/lemote/3A3000_p2.pdf

>> http://ftp.godson.ac.cn/lemote/Loongson3A3000_3B3000usermanual2.pdf (Chinese Version)

>>

>> Loongson-3A R4 (Loongson-3A4000)

>> User Manual Part 1:

>> http://ftp.godson.ac.cn/lemote/3A4000_p1.pdf

>> http://ftp.godson.ac.cn/lemote/3A4000user.pdf (Chinese Version)

>> User Manual Part 2:

>> I'm sorry that it is unavailable now.

>>

>> And human-translated documents (W.I.P) are available here now:

>> https://github.com/loongson-community/docs/tree/master/English-translation-of-Loongson-manual

>>

>> Both KVM and TCG are available now!

>>

>> We now already have a full functional Linux kernel (based on Linux-5.4.x

>> LTS, the kvm host side and guest side have both been upstream for Linux-

>> 5.9, but Linux-5.9 has not been released yet) here:

>>

>> https://github.com/chenhuacai/linux

>>

>> Of course the upstream kernel is also usable (though it is "unstable"

>> now):

>>

>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

>>

>> How to use QEMU/Loongson-3?

>> 1, Download kernel source from the above URL;

>> 2, Build a kernel with arch/mips/configs/loongson3_{def,hpc}config;

>> 3, Boot a Loongson-3A4000 host with this kernel (for KVM mode);

>> 4, Build QEMU-master with this patchset;

>> 5, modprobe kvm (only necessary for KVM mode);

>> 6, Use QEMU with TCG:

>>        qemu-system-mips64el -M loongson3-virt,accel=tcg -cpu Loongson-3A1000 -kernel <path_to_kernel> -append ...

>>    Use QEMU with KVM:

>>        qemu-system-mips64el -M loongson3-virt,accel=kvm -cpu Loongson-3A4000 -kernel <path_to_kernel> -append ...

>>

>>    The "-cpu" parameter is optional here and QEMU will use the correct type for TCG/KVM automatically.

>>

>> V1 -> V2:

>> 1, Add a cover letter;

>> 2, Improve CPU definitions;

>> 3, Remove LS7A-related things (Use GPEX instead);

>> 4, Add a description of how to run QEMU/Loongson-3.

>>

>> V2 -> V3:

>> 1, Fix all possible checkpatch.pl errors and warnings.

>>

>> V3 -> V4:

>> 1, Sync code with upstream;

>> 2, Remove merged patches;

>> 3, Fix build failure without CONFIG_KVM;

>> 4, Add Reviewed-by: Aleksandar Markovic <aleksandar.qemu.devel@gmail.com>.

>>

>> V4 -> V5:

>> 1, Improve coding style;

>> 2, Remove merged patches;

>> 3, Rename machine name from "loongson3" to "loongson3-virt";

>> 4, Rework the "loongson3-virt" machine to drop any ISA things;

>> 5, Rework "hw/mips: Implement the kvm_type() hook in MachineClass";

>> 6, Add Jiaxun Yang as a reviewer of Loongson-3.

>>

>> V5 -> V6:

>> 1, Fix license preamble;

>> 2, Improve commit messages;

>> 3, Add hw/intc/loongson_liointc.c to MAINTAINERS;

>> 4, Fix all possible checkpatch.pl errors and warnings.

>>

>> V7 and V8 have only one patch (machine definition) with some minor improvements.

>>

>> V8 -> V9:

>> 1, Update KVM type definition from kernel;

>> 2, Fix PageMask with variable page size for TCG;

>> 3, Add TCG support (add Loongson-EXT instructions).

>>

>> Huacai Chen and Jiaxun Yang (6):

>>  linux-headers: Update MIPS KVM type defintition

>>  target/mips: Fix PageMask with variable page size

>>  target/mips: Add loongson-ext lswc2 group of instructions (Part 1)

>>  target/mips: Add loongson-ext lswc2 group of instructions (Part 2)

>>  target/mips: Add loongson-ext lsdc2 group of instructions

>>  hw/mips: Add Loongson-3 machine support

>>

>> Signed-off-by: Huacai Chen <chenhc@lemote.com>

>> ---

>>  default-configs/mips64el-softmmu.mak |   1 +

>>  hw/mips/Kconfig                      |  11 +

>>  hw/mips/fw_cfg.c                     |  35 ++

>>  hw/mips/fw_cfg.h                     |  19 +

>>  hw/mips/loongson3_virt.c             | 956 +++++++++++++++++++++++++++++++++++

>>  hw/mips/meson.build                  |   3 +-

>>  linux-headers/linux/kvm.h            |   5 +-

>>  target/mips/cp0_helper.c             |  36 +-

>>  target/mips/cpu.h                    |   1 +

>>  target/mips/translate.c              | 437 ++++++++++++++++

>>  10 files changed, 1494 insertions(+), 10 deletions(-)

>>  create mode 100644 hw/mips/fw_cfg.c

>>  create mode 100644 hw/mips/fw_cfg.h

>>  create mode 100644 hw/mips/loongson3_virt.c

>> --

>

>

> There should be a suitable note in QEMU documentation describing new functionality.

OK, I will update documentations in V10.

Huacai
>

> Thanks,

> Aleksandar

>

>

>>

>> 2.7.0




-- 
Huacai Chen
chen huacai Sept. 21, 2020, 2:25 a.m. UTC | #6
Hi, Philippe,

On Thu, Sep 17, 2020 at 3:56 PM Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
>

> Hi Huacai,

>

> On 9/16/20 4:12 AM, Huacai Chen wrote:

> > Loongson-3 CPU family include Loongson-3A R1/R2/R3/R4 and Loongson-3B

> > R1/R2. Loongson-3A R1 is the oldest and its ISA is the smallest, while

> > Loongson-3A R4 is the newest and its ISA is almost the superset of all

> > others. To reduce complexity, in QEMU we just define two CPU types:

> >

> > 1, "Loongson-3A1000" CPU which is corresponding to Loongson-3A R1. It is

> >    suitable for TCG because Loongson-3A R1 has fewest ASE.

> > 2, "Loongson-3A4000" CPU which is corresponding to Loongson-3A R4. It is

> >    suitable for KVM because Loongson-3A R4 has the VZ ASE.

> >

> [...]

>

> > Of course the upstream kernel is also usable (though it is "unstable"

> > now):

> >

> > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

> >

> > How to use QEMU/Loongson-3?

> > 1, Download kernel source from the above URL;

> > 2, Build a kernel with arch/mips/configs/loongson3_{def,hpc}config;

> > 3, Boot a Loongson-3A4000 host with this kernel (for KVM mode);

> > 4, Build QEMU-master with this patchset;

> > 5, modprobe kvm (only necessary for KVM mode);

> > 6, Use QEMU with TCG:

> >        qemu-system-mips64el -M loongson3-virt,accel=tcg -cpu Loongson-3A1000 -kernel <path_to_kernel> -append ...

> >    Use QEMU with KVM:

> >        qemu-system-mips64el -M loongson3-virt,accel=kvm -cpu Loongson-3A4000 -kernel <path_to_kernel> -append ...

>

> Can you add a KVM-only build CI job?

> Simply building, not running test, as there is no MIPS CI.

>

> See for example commit 41e1f0e2256 (".travis.yml: Add a KVM-only

> s390x job"), but add it to GitLab instead.

I have some difficulties in CI testing (I think I should setup a CI
environment first), can this work be done by others, or in future
after this series?

Huacai
>

> Thanks!

>

> Phil.




-- 
Huacai Chen