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