[SLOF] [PATCH slof v5 3/6] fdt: Pass the resulting device tree to QEMU

Alexey Kardashevskiy aik at ozlabs.ru
Tue Oct 17 14:12:39 AEDT 2017


On 16/10/17 23:27, Segher Boessenkool wrote:
> On Mon, Oct 16, 2017 at 11:06:15PM +1100, Alexey Kardashevskiy wrote:
>> On 16/10/17 20:07, Segher Boessenkool wrote:
>>> Maybe something like
>>>
>>>
>>> VARIABLE chosen-cpu-phandle
>>> VARIABLE chosen-cpu-ihandle
>>> : set-chosen-cpu ( -- )
>>>    s" /cpus" find-node  dup 0= ABORT" /cpus not found"
>>>    child                dup 0= ABORT" /cpus/cpu not found"
>>>    dup chosen-cpu-phandle !  0 0 rot open-node
>>>    dup chosen-cpu-ihandle !  encode-int s" cpu" set-chosen ;
>>>
>>>
>>> and then you can use   chosen-cpu-ihandle @   etc.?
>>
>> I can do that but what is the exact benefit of doing it this way? It is
>> going to be used once really, and why would we need to cache both ihandle
>> and phandle but not reg (which we really care about here), for example?
> 
> It's not caching: this is the "real" data, what is in the device tree
> is just some external representation.  Reading things back from the
> device tree is extremely slow at best, and very harmful in worse cases.
> Just say no!
> 
> You can of course choose to not keep the phandle or ihandle around,
> instead just the unit address, for example.
> 
> The point is to use find-node etc. instead of find-device etc. -- easier
> to use and it does not clobber the current packages, etc.  And, of course,
> don't read /chosen data back from the device tree.

Oh, ok.
So I assume there is a better way of getting "reg" as well rather than
reading the property, like "chosen-cpu-phandle @ >unit"?


This is my draft, need "defer" as fdt.fs is included before tree.fs:


diff --git a/board-qemu/slof/fdt.fs b/board-qemu/slof/fdt.fs
index f27cd1b..9ae2e4b 100644
--- a/board-qemu/slof/fdt.fs
+++ b/board-qemu/slof/fdt.fs
@@ -624,14 +624,7 @@ VARIABLE fdt-ms \ debug only
     drop +
 ;

-: fdt-boot-cpu ( -- bootcpu )
-    s" cpu" s" /chosen" find-node get-property 0<> IF 0 EXIT THEN
-    decode-int
-    nip nip ihandle>phandle
-    s" reg" rot get-property 0<> IF 0 EXIT THEN
-    decode-int
-    nip nip
-;
+DEFER chosen-cpu

 : fdt-flatten-tree ( -- tree )
     1 to fdt-debug
@@ -678,7 +671,7 @@ VARIABLE fdt-ms \ debug only
     /fdth               r@ >fdth_rsvmap_off l!
     11                  r@ >fdth_version l!
     10                  r@ >fdth_compat_vers l!
-    fdt-boot-cpu        r@ >fdth_boot_cpu l!
+    chosen-cpu          r@ >fdth_boot_cpu l!
     over                r@ >fdth_string_size l!
     2 pick              r@ >fdth_struct_size l!
                                     ( struct-len strings-len total-len r:
fdt )
diff --git a/board-qemu/slof/tree.fs b/board-qemu/slof/tree.fs
index cc35fa3..2655500 100644
--- a/board-qemu/slof/tree.fs
+++ b/board-qemu/slof/tree.fs
@@ -156,11 +156,18 @@ populate-pci-busses
 6c0 cp

 \ Do not assume that cpu0 is available
-: set-chosen-cpu
-    " /cpus" find-device
-    get-node child dup 0= ABORT" CPU not found"
-    node>path open-dev encode-int s" cpu" set-chosen
+VARIABLE chosen-cpu-phandle
+VARIABLE chosen-cpu-ihandle
+: set-chosen-cpu ( -- )
+    s" /cpus" find-node  dup 0= ABORT" /cpus not found"
+    child                dup 0= ABORT" /cpus/cpu not found"
+    dup chosen-cpu-phandle !  0 0 rot open-node
+    dup chosen-cpu-ihandle !  encode-int s" cpu" set-chosen
 ;
+
+: chosen-cpu-func ( -- reg ) chosen-cpu-phandle @ >unit ;
+' chosen-cpu-func to chosen-cpu
+


-- 
Alexey


More information about the SLOF mailing list