All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aleksandar Markovic <aleksandar.qemu.devel@gmail.com>
To: Jiaxun Yang <jiaxun.yang@flygoat.com>
Cc: "Huacai Chen" <zltjiangshi@gmail.com>,
	"Huacai Chen" <chenhuacai@gmail.com>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"QEMU Developers" <qemu-devel@nongnu.org>,
	"Aleksandar Rikalo" <aleksandar.rikalo@rt-rk.com>,
	"Aurelien Jarno" <aurelien@aurel32.net>
Subject: Re: [PATCH for-5.1 V4 3/4] hw/mips: Add Loongson-3 machine support (with KVM)
Date: Thu, 11 Jun 2020 10:50:45 +0200	[thread overview]
Message-ID: <CAHiYmc7BoPkwDHOoOOKAWdW7gyZ5UiDAZZ0A8v8EZheP3GxhNQ@mail.gmail.com> (raw)
In-Reply-To: <3cfda172-7637-2791-cf65-0ba7a2e4c6bb@flygoat.com>

> >>> +    int fd = 0, freq = 0;
> >>> +    char buf[1024], *buf_p;

1024 should have been defined via preprocessor constant

> >>> +
> >>> +    fd = open("/proc/cpuinfo", O_RDONLY);
> >>> +    if (fd == -1) {
> >>> +        fprintf(stderr, "Failed to open /proc/cpuinfo!\n");
> >>> +        return 0;
> >>> +    }
> >>> +
> >>> +    if (read(fd, buf, 1024) < 0) {

The same constant should be used here.

...

> >>> +    loaderparams.a1 = 0xffffffff80000000ULL + BOOTPARAM_PHYADDR;
> >>> +    loaderparams.a2 = 0xffffffff80000000ULL + BOOTPARAM_PHYADDR + ret;

What is 0xffffffff80000000ULL? Preprocessor constant possible?

...

> >>> +    if (!kvm_enabled()) {
> >>> +        if (!machine->cpu_type) {
> >>> +            machine->cpu_type = MIPS_CPU_TYPE_NAME("Loongson-3A1000");
> >>> +        }
> >>> +        if (!strstr(machine->cpu_type, "Loongson-3A1000")) {
> >>> +            error_report("Loongson-3/TCG need cpu type Loongson-3A1000");
> >>> +            exit(1);
> >>> +        }
> >>> +    } else {
> >>> +        if (!machine->cpu_type) {
> >>> +            machine->cpu_type = MIPS_CPU_TYPE_NAME("Loongson-3A4000");
> >>> +        }
> >>> +        if (!strstr(machine->cpu_type, "Loongson-3A4000")) {
> >>> +            error_report("Loongson-3/KVM need cpu type Loongson-3A4000");
> >>> +            exit(1);
> >>> +        }
> >>> +    }

Some explanation needs to be written in comments about the code segment above.

I find the whole segment a little bit questionable. For non-KVM one
CPU, for KVM another? Why non-KVM can't use both, and allow to be
specified via command line?

> >>> +    memory_region_add_subregion(address_space_mem, 0x00000000LL, ram);
> >>> +    memory_region_add_subregion(address_space_mem, 0x1fc00000LL, bios);
> >>> +    memory_region_add_subregion(address_space_mem, 0x80000000LL, machine->ram);
> >>> +    memory_region_add_subregion(address_space_mem, PM_MMIO_ADDR, iomem);

I would avoid hard coded numbers.

> >>> +
> >>> +    /*
> >>> +     * We do not support flash operation, just loading pmon.bin as raw BIOS.
> >>> +     * Please use -L to set the BIOS path and -bios to set bios name.
> >>> +     */
> >>> +
> >>> +    if (kernel_filename) {
> >>> +        loaderparams.ram_size = ram_size;
> >>> +        loaderparams.kernel_filename = kernel_filename;
> >>> +        loaderparams.kernel_cmdline = kernel_cmdline;
> >>> +        loaderparams.initrd_filename = initrd_filename;
> >>> +        loaderparams.kernel_entry = load_kernel(env);
> >>> +        rom_add_blob_fixed("bios",
> >>> +                         bios_boot_code, sizeof(bios_boot_code), 0x1fc00000LL);

Again, here, 0x1fc00000LL. This should be defined and properly named
via preprocessor.

> >>> +    } else {
> >>> +        if (bios_name == NULL) {
> >>> +                bios_name = LOONGSON3_BIOSNAME;
> >>> +        }
> >>> +        filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
> >>> +        if (filename) {
> >>> +            bios_size = load_image_targphys(filename, 0x1fc00000LL,

Again.

> >>> +                                            BIOS_SIZE);
> >>> +            g_free(filename);
> >>> +        } else {
> >>> +            bios_size = -1;
> >>> +        }
> >>> +
> >>> +    if (serial_hd(0)) {
> >>> +        serial_mm_init(address_space_mem, 0x1fe001e0, 0, env->irq[2],
> >>> +                           115200, serial_hd(0), DEVICE_NATIVE_ENDIAN);

115200 should be something like XXX_DEFAULT_BAUDRATE

> >>> +    }
> >>> +}
> >>> +
> >>> +static void mips_loongson3_machine_init(MachineClass *mc)
> >>> +{
> >>> +    mc->desc = "Generic Loongson-3 Platform";
> >>> +    mc->init = mips_loongson3_init;
> >>> +    mc->block_default_type = IF_IDE;
> >>> +    mc->max_cpus = LOONGSON_MAX_VCPUS;
> >>> +    mc->default_ram_id = "loongson3.highram";
> >>> +    mc->default_ram_size = 1200 * MiB;
> >>
> >> 1200MiB looks wired... Why not 1024?
> > Oh, it is just because our Fedora28 needs more than 1024MB to work
> > fine, maybe 1280 is better?
>
> Ahh if that's the reason then it looks fine for me.
>

These choices should be documented in brief comments.

If left this way, we leave future developers solve puzzles and
desperately guessing.

Thanks,
Aleksandar


  reply	other threads:[~2020-06-11  8:52 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-02  2:39 [PATCH for-5.1 V4 0/7] mips: Add Loongson-3 machine support (with KVM) Huacai Chen
2020-06-02  2:39 ` [PATCH for-5.1 V4 1/4] hw/mips: Implement the kvm_type() hook in MachineClass Huacai Chen
2020-06-03 14:34   ` Aleksandar Markovic
2020-06-04  0:57     ` Huacai Chen
2020-06-04 10:04       ` Aleksandar Markovic
2020-06-14  8:07   ` Aleksandar Markovic
2020-06-15  0:52     ` Huacai Chen
2020-06-15  8:55       ` Thomas Huth
2020-06-15 19:44         ` Aleksandar Markovic
2020-06-16  6:11           ` Huacai Chen
2020-06-16 21:17             ` Aleksandar Markovic
2020-06-02  2:39 ` [PATCH for-5.1 V4 2/4] target/mips: Add Loongson-3 CPU definition Huacai Chen
2020-06-06  7:30   ` Aleksandar Markovic
2020-06-02  2:39 ` [PATCH for-5.1 V4 3/4] hw/mips: Add Loongson-3 machine support (with KVM) Huacai Chen
2020-06-06  7:32   ` Aleksandar Markovic
2020-06-06  8:01     ` Aleksandar Markovic
2020-06-07  1:12       ` chen huacai
2020-06-07 20:00         ` Aleksandar Markovic
2020-06-08  3:56           ` Huacai Chen
2020-06-11  5:58   ` Jiaxun Yang
2020-06-11  7:49     ` Huacai Chen
2020-06-11  8:12       ` Jiaxun Yang
2020-06-11  8:50         ` Aleksandar Markovic [this message]
2020-06-12  6:07           ` Huacai Chen
2020-06-14  7:51   ` Aleksandar Markovic
2020-06-15  0:55     ` Huacai Chen
2020-06-15  4:42       ` Aleksandar Markovic
2020-06-15  4:50       ` Aleksandar Markovic
2020-06-15  5:36         ` Huacai Chen
2020-06-15  5:58           ` Aleksandar Markovic
2020-06-15  6:04           ` Aleksandar Markovic
2020-06-15  6:29             ` Huacai Chen
2020-06-15  6:44               ` Aleksandar Markovic
2020-06-02  2:39 ` [PATCH for-5.1 V4 4/4] MAINTAINERS: Add myself as Loongson-3 maintainer Huacai Chen
2020-06-02  8:12   ` Philippe Mathieu-Daudé
2020-06-02 12:03     ` chen huacai
2020-06-05  8:38 ` [PATCH for-5.1 V4 0/7] mips: Add Loongson-3 machine support (with KVM) Aleksandar Markovic
2020-06-05  8:40   ` Aleksandar Markovic
2020-06-05  9:05   ` Jiaxun Yang
2020-06-05  9:21     ` Huacai Chen
2020-06-05  9:27     ` Aleksandar Markovic

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHiYmc7BoPkwDHOoOOKAWdW7gyZ5UiDAZZ0A8v8EZheP3GxhNQ@mail.gmail.com \
    --to=aleksandar.qemu.devel@gmail.com \
    --cc=aleksandar.rikalo@rt-rk.com \
    --cc=aurelien@aurel32.net \
    --cc=chenhuacai@gmail.com \
    --cc=f4bug@amsat.org \
    --cc=jiaxun.yang@flygoat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=zltjiangshi@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.