qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Alexey Kardashevskiy <aik@ozlabs.ru>
Cc: qemu-ppc@nongnu.org, qemu-devel@nongnu.org, Greg Kurz <groug@kaod.org>
Subject: Re: [PATCH qemu v18] spapr: Implement Open Firmware client interface
Date: Thu, 22 Apr 2021 12:00:43 +1000	[thread overview]
Message-ID: <YIDYy14pXebXpuKL@yekko.fritz.box> (raw)
In-Reply-To: <85770051-50df-7d5c-966e-a6e80797b39d@ozlabs.ru>

[-- Attachment #1: Type: text/plain, Size: 6594 bytes --]

On Wed, Apr 21, 2021 at 04:50:12PM +1000, Alexey Kardashevskiy wrote:
> 
> 
> On 4/21/21 15:27, David Gibson wrote:
> > On Tue, Apr 20, 2021 at 07:16:35PM +1000, Alexey Kardashevskiy wrote:
> > > On 20/04/2021 13:14, David Gibson wrote:
[snip]
> > > > > diff --git a/pc-bios/vof/Makefile b/pc-bios/vof/Makefile
> > > > > new file mode 100644
> > > > > index 000000000000..1451e0551818
> > > > > --- /dev/null
> > > > > +++ b/pc-bios/vof/Makefile
> > > > > @@ -0,0 +1,18 @@
> > > > > +all: build-all
> > > > > +
> > > > > +build-all: vof.bin
> > > > > +
> > > > > +%.o: %.S
> > > > > +	cc -m32 -mbig-endian -c -o $@ $<
> > > > 
> > > > Should probably use a $(CC) variable to make it easier for people to
> > > > point this at a cross-compiler.
> > > 
> > > 
> > > 
> > > CROSS ?=
> > > CC = $(CROSS)gcc
> > > LD = $(CROSS)ld
> > > OBJCOPY = $(CROSS)objcopy
> > > 
> > > 
> > > ?
> > > 
> > > Works with
> > > 
> > > make CROSS=/opt/cross/gcc-10.1.0-nolibc/powerpc64-linux/bin/powerpc64-linux-
> > 
> > I was just thinking "CC = cc" etc. so someone can override it from the
> > command line, but your suggestion is even better.
> 
> 
> I am not sure why (there is no "?" in "CC="/etc) but this works too with the
> change above:

The command line overrides variables in the Makefile by default, using
?= just lets environment variables override them as well.

[snip]
> > > > > +        return;
> > > > > +    }
> > > > > +
> > > > > +    g_array_sort(claimed, of_claimed_compare_func);
> > > > > +    vof_claimed_dump(claimed);
> > > > > +
> > > > > +    /*
> > > > > +     * VOF resides in the first page so we do not need to check if there is
> > > > > +     * available memory before the first claimed block
> > > > > +     */
> > > > > +    g_assert(claimed->len && (g_array_index(claimed, OfClaimed, 0).start == 0));
> > > > > +
> > > > > +    avail = g_malloc0(sizeof(avail[0]) * claimed->len);
> > > > > +    for (i = 0, n = 0; i < claimed->len; ++i) {
> > > > > +        OfClaimed c = g_array_index(claimed, OfClaimed, i);
> > > > > +        uint64_t start, size;
> > > > > +
> > > > > +        start = c.start + c.size;
> > > > > +        if (i < claimed->len - 1) {
> > > > > +            OfClaimed cn = g_array_index(claimed, OfClaimed, i + 1);
> > > > > +
> > > > > +            size = cn.start - start;
> > > > > +        } else {
> > > > > +            size = be64_to_cpu(mem0_reg[1]) - start;
> > > > 
> > > > Don't you have vof->top_addr for the end of the ram you care about, so
> > > > you don't need to go poking at the memory node?
> > > 
> > > 
> > > top_addr is limited by 4GB but memory@0 is not and I'd like "available" to
> > > report free memory till the end of the memory@0 node part of which
> > > "available" is.
> > 
> > Hmmm.  AIUI the purpose of 'available' is so the client can know what
> > things it can claim, but IIUC claim only works in the 32-bit arena up
> > to top_addr.  So, does it really make sense to have it include stuff
> > beyond that?
> 
> 
> I am really not sure. The format uses 2 cells for an address. The client
> cannot claim memory above 4GB as the CLI ABI returns only cells but the
> firmware may run 64bit, use some memory above 4GB and report this use to the
> client so the client would have to avoid using that memory until ... I do
> not know... quiesce?

Huh.. yeah, that's pretty confusing.

> It is all very theoretical of course but still feels safer to stretch
> "available" till the end of the node.

Ok, you've convinced me.

[snip]
> > > > > +void vof_build_dt(void *fdt, Vof *vof)
> > > > > +{
> > > > > +    uint32_t phandle;
> > > > > +    int i, offset, proplen = 0;
> > > > > +    const void *prop;
> > > > > +    bool found = false;
> > > > > +    GArray *phandles = g_array_new(false, false, sizeof(uint32_t));
> > > > > +
> > > > > +    /* Find all predefined phandles */
> > > > > +    for (offset = fdt_next_node(fdt, -1, NULL);
> > > > > +         offset >= 0;
> > > > > +         offset = fdt_next_node(fdt, offset, NULL)) {
> > > > > +        prop = fdt_getprop(fdt, offset, "phandle", &proplen);
> > > > > +        if (prop && proplen == sizeof(uint32_t)) {
> > > > > +            phandle = fdt32_ld(prop);
> > > > > +            g_array_append_val(phandles, phandle);
> > > > > +        }
> > > > > +    }
> > > > > +
> > > > > +    /* Assign phandles skipping the predefined ones */
> > > > > +    for (offset = fdt_next_node(fdt, -1, NULL), phandle = 1;
> > > > > +         offset >= 0;
> > > > > +         offset = fdt_next_node(fdt, offset, NULL), ++phandle) {
> > > > > +        prop = fdt_getprop(fdt, offset, "phandle", &proplen);
> > > > > +        if (prop) {
> > > > > +            continue;
> > > > > +        }
> > > > > +        /* Check if the current phandle is not allocated already */
> > > > > +        for ( ; ; ++phandle) {
> > > > > +            for (i = 0, found = false; i < phandles->len; ++i) {
> > > > > +                if (phandle == g_array_index(phandles, uint32_t, i)) {
> > > > > +                    found = true;
> > > > > +                    break;
> > > > > +                }
> > > > > +            }
> > > > > +            if (!found) {
> > > > > +                break;
> > > > > +            }
> > > > > +        }
> > > > > +        _FDT(fdt_setprop_cell(fdt, offset, "phandle", phandle));
> > > > 
> > > > I still think this is needlessly complicated, and you should just find
> > > > max phandle and work from there.
> > > 
> > > 
> > > I still think this is more developer's tool than anything else and having
> > > random phandles is not helping. With less random phandles you can set
> > > conditional breakpoints in gdb scripts and they do not need to change when,
> > > for example, you switch from ibmvscsi to virtio-scsi.
> > 
> > Um... I don't seew how this logic's phandles are any less "random" than
> > starting from the max existing one.  What you allocate still depends
> > on what existing phandles happen to be in the tree.
> 
> 
> I was thinking that all PCI devices get phandles via PHANDLE_PCIDEV() but
> this is only for NVLink which we are removing now. Well. Ok. I'll do it your
> way for now and see if anybody cares. At least this is faster, Nick is going
> to like it :) Thanks,

:)

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      reply	other threads:[~2021-04-22  2:18 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-31  2:53 [PATCH qemu v18] spapr: Implement Open Firmware client interface Alexey Kardashevskiy
2021-04-09  5:52 ` Alexey Kardashevskiy
2021-04-20  3:14 ` David Gibson
2021-04-20  9:16   ` Alexey Kardashevskiy
2021-04-21  5:27     ` David Gibson
2021-04-21  6:50       ` Alexey Kardashevskiy
2021-04-22  2:00         ` David Gibson [this message]

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=YIDYy14pXebXpuKL@yekko.fritz.box \
    --to=david@gibson.dropbear.id.au \
    --cc=aik@ozlabs.ru \
    --cc=groug@kaod.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).