Skip to content

Commit 82954d4

Browse files
committed
Patch "interrupt-map" properties to contain the phandles from SLOF
The flattened device tree from QEMU contains some "phandle" and "linux,phandle" properties which are referenced from the "interrupt-map" properties in the pci root nodes. This is bad, since SLOF has a different concept of phandles. Now the code patches the "interrupt-map" properties to contain the values from SLOF and removes the "phandle" and "linux,phandle" properties from the device tree. Signed-off-by: Thomas Huth <thuth@linux.vnet.ibm.com>
1 parent 4f0a051 commit 82954d4

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

board-qemu/slof/fdt.fs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,102 @@ fdt-parse-memory
232232
;
233233
fdt-claim-reserve
234234

235+
236+
\ The following functions are use to replace the FDT phandle and
237+
\ linux,phandle properties with our own OF1275 phandles...
238+
239+
\ This is used to check whether we successfully replaced a phandle value
240+
0 VALUE (fdt-phandle-replaced)
241+
242+
\ Replace phandle value in "interrupt-map" property
243+
: fdt-replace-interrupt-map ( old new prop-addr prop-len -- old new )
244+
BEGIN
245+
dup ( old new prop-addr prop-len prop-len )
246+
WHILE
247+
\ This is a little bit ugly ... we're accessing the property at
248+
\ hard-coded offsets instead of analyzing it completely...
249+
swap dup 10 + ( old new prop-len prop-addr prop-addr+10 )
250+
dup l@ 5 pick = IF
251+
\ it matches the old phandle value!
252+
3 pick swap l!
253+
TRUE TO (fdt-phandle-replaced)
254+
ELSE
255+
drop
256+
THEN
257+
( old new prop-len prop-addr )
258+
1c + swap 1c -
259+
( old new new-prop-addr new-prop-len )
260+
REPEAT
261+
2drop
262+
;
263+
264+
\ Replace one FDT phandle "old" with a OF1275 phandle "new" in the
265+
\ whole tree:
266+
: fdt-replace-all-phandles ( old new node -- )
267+
\ ." Replacing in " dup node>path type cr
268+
>r
269+
s" interrupt-map" r@ get-property 0= IF
270+
( old new prop-addr prop-len R: node )
271+
fdt-replace-interrupt-map
272+
THEN
273+
s" interrupt-parent" r@ get-property 0= IF
274+
( old new prop-addr prop-len R: node )
275+
decode-int -rot 2drop ( old new val R: node )
276+
2 pick = IF ( old new R: node )
277+
dup encode-int s" interrupt-parent" r@ set-property
278+
TRUE TO (fdt-phandle-replaced)
279+
THEN
280+
THEN
281+
\ ... add more properties that have to be fixed here ...
282+
r>
283+
\ Now recurse over all child nodes: ( old new node )
284+
child BEGIN
285+
dup
286+
WHILE
287+
3dup RECURSE
288+
PEER
289+
REPEAT
290+
3drop
291+
;
292+
293+
\ Check whether a node has "phandle" or "linux,phandle" properties
294+
\ and replace them:
295+
: fdt-fix-node-phandle ( node -- )
296+
>r
297+
FALSE TO (fdt-phandle-replaced)
298+
s" phandle" r@ get-property 0= IF
299+
decode-int ( p-addr2 p-len2 val )
300+
\ ." found phandle: " dup . cr
301+
r@ s" /" find-node ( p-addr2 p-len2 val node root )
302+
fdt-replace-all-phandles ( p-addr2 p-len2 )
303+
2drop
304+
(fdt-phandle-replaced) IF
305+
r@ set-node
306+
s" phandle" delete-property
307+
s" linux,phandle" delete-property
308+
ELSE
309+
cr ." Warning: Did not replace phandle in " r@ node>path type cr
310+
THEN
311+
THEN
312+
r> drop
313+
;
314+
315+
\ Recursively walk through all nodes to fix their phandles:
316+
: fdt-fix-phandles ( node -- )
317+
\ ." fixing phandles of " dup node>path type cr
318+
dup fdt-fix-node-phandle
319+
child BEGIN
320+
dup
321+
WHILE
322+
dup RECURSE
323+
PEER
324+
REPEAT
325+
drop
326+
device-end
327+
;
328+
s" /" find-node fdt-fix-phandles
329+
330+
235331
\ Remaining bits from root.fs
236332

237333
defer (client-exec)

0 commit comments

Comments
 (0)