On Sun, 14 Jul 2019, Mark Cave-Ayland wrote:
On 11/07/2019 12:01, BALATON Zoltan wrote:
I'm trying to port fdt unflattening from SLOF to OpenBIOS but need some help with understanding and implementing equivalent forth words, The SLOF fdt.fs uses set-unit which is defined in
https://github.com/aik/SLOF/blob/master/slof/fs/node.fs
: set-space??? get-node dup >r node>space ! true r> node>space? ! ; : set-address? my-#address-cells 1 ?DO ?????????????? get-node node>space i cells + ! LOOP ; : set-unit???? set-space set-address ;
These set the unit address manipulating the fields of the node struct as far as I understand.
But I don't know how to do the same in OpenBIOS. OpenBIOS implements the word that returns these values that set-unit is supposed to change in
https://github.com/openbios/openbios/blob/master/forth/device/package.fs#L19...
as
: my-unit ( -- phys.lo ... phys.hi ) ? ?my-self >in.my-unit ? my-#acells tuck /l* + swap 0 ?do ??? /l - dup l@ swap ? loop ? drop ? ;
but I don't understand how these are stored in OpenBIOS and how to change them. Could somone who understands forth or know OpenBIOS more suggest an implementation of set-unit for OpenBIOS please?
We'll also need set-node which sets active-package I think so suggestions for that are also welcome.
The unit numbers in OpenBIOS seems to touch quite a few internal variables: my-unit, probe-addr and also reg depending upon the device and its parent bus, but the main issue is that during the PCI bus enumeration we don't maintain the full ihandle chain to the root node which tends to break a lot of the "my-*" words.
This is not for PCI devices but for unflattenning an FDT to get the initial device tree (instead of creating it in OpenBIOS so we can get rid of all the ifdefs and knowledge about platforms to simplify OpenBIOS like already done in SLOF). This unflattened initial device tree then can be amended with PCI devices the same way as done now, no libfdt is used in OpenBIOS, the unflattening us done in Forth and manipulation is then done on the forth device tree. So what you talk about may not be needed here. I need the opposite of my-unit instead:
: set-unit ( phys.lo ... phys.hi -- )
that should set addresses somehow (of the current device I think, see definitions from SLOF above). I've looked up my-#acells that seem to be the source of this info:
https://github.com/openbios/openbios/blob/master/forth/device/property.fs#L1...
\ HELPER: get #address-cell value (from parent) \ Legal values are 1..4 (we may optionally support longer addresses) : my-#acells ( -- #address-cells ) my-self ?dup if >in.device-node @ else active-package then ?dup if >dn.parent @ then ?dup if " #address-cells" rot get-package-property if 2 exit then \ we don't have to support more than 4 (and 0 is illegal) decode-int nip nip 4 min 1 max else 2 then ;
So I think we should somehow set #address-cells. It would help if I understood what space and adresses are and know forth but instead of reading all open firmware standards and a forth tutorial I hope there are people here who already know these and can help to implement this word in OpenBIOS which may be faster then me learning everything first. If one could explain the necessary pieces like what are space and addresses (or where exactly are these described in the standard) and how are these stored in OpenBIOS and where to change them or what the above forth words do then I may be able to try to come up with a set-unit definition but without some ropes I can't do it.
This is something that has been on my TODO list for a while, and I do have an incomplete WIP patchset to try and fix this. I'll see if I can find some time soon to fix up the remaining bugs and submit it to the list.
I don't know what's the problem this would fix is so I don't know if it's relevant for the above but it may not be.
Regards, BALATON Zoltan