diff mbox

[3/3] pci-scan: Fix pci-bridge-set-mem-base and pci-bridge-set-mem-limit

Message ID 20170721073537.16095-4-aik@ozlabs.ru
State Rejected
Headers show

Commit Message

Alexey Kardashevskiy July 21, 2017, 7:35 a.m. UTC
From: Thomas Huth <thuth@redhat.com>

The functions used a bogus mixture between programming the registers
with pci-next-mem64 and pci-next-mem - the upper register bits were
filled with the value from the 64-bit memory space while the lower
bits were filled with the bits from the 32-bit memory space variable.

This separates pci-next-mem64 handling from pci-next-mem.

Signed-off-by: Thomas Huth <thuth@redhat.com>
[aik: moved to a separate patch, added pci-next-mem64-align(-extend)
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
 slof/fs/pci-scan.fs | 61 ++++++++++++++++++++++++++++-------------------------
 1 file changed, 32 insertions(+), 29 deletions(-)
diff mbox

Patch

diff --git a/slof/fs/pci-scan.fs b/slof/fs/pci-scan.fs
index d8f7c02..0664220 100644
--- a/slof/fs/pci-scan.fs
+++ b/slof/fs/pci-scan.fs
@@ -113,6 +113,17 @@  here 100 allot CONSTANT pci-device-vec
     pci-next-mem64 @ 0<> and
 ;
 
+: pci-next-mem64-align ( align -- pci-next-mem64 )
+    pci-next-mem64 @ swap #aligned
+    dup pci-next-mem64 x!
+;
+
+: pci-next-mem64-align-extend ( align extend -- pci-next-mem )
+    pci-next-mem64 @ +
+    swap #aligned
+    dup pci-next-mem64 x!
+;
+
 : pci-next-mem-align-1mb ( -- pci-next-mem )
     pci-next-mem
     100000 #aligned                         \ align to 1MB boundary
@@ -126,23 +137,20 @@  here 100 allot CONSTANT pci-device-vec
     dup pci-next-mem !
 ;
 
-\ Update pci-next-mem to be 1MB aligned and set the mem-base and mem-base-upper register
-\ and set the Limit register to the maximum available address space
-\ needed for scanning possible devices behind the bridge
+\ Update pci-next-mem (or mem64) to be aligned and set the mem-base and
+\ mem-base-upper register. Also set the Limit register to the maximum available
+\ address space needed for scanning possible devices behind the bridge
 : pci-bridge-set-mem-base ( addr -- )
     dup pci-bridge-has-mem64               \ check if 64bit support
     IF                                      \ IF 64 bit support
-        pci-next-mem-align-1mb
-        pci-next-mem64 @ 100000000 #aligned \ | read the current Value of 64-bit and align to 4GB boundary
-        dup 100000000 + pci-next-mem64 x!   \ | and write back with 1GB for bridge
-        2 pick swap                         \ |
-        20 rshift                           \ | keep upper 32 bits
-        swap 28 + rtas-config-l!            \ | and write it into the Base-Upper32-bits
-        pci-max-mem64 @ 20 rshift           \ | fetch max Limit address and keep upper 32 bits
-        2 pick 2C + rtas-config-l!          \ | and set the Limit
-        10 rshift                           \ | keep upper 16 bits
-        pci-max-mem @ 1- FFFF0000 and or    \ | and Insert mmem Limit (set it to max)
-        swap 24 + rtas-config-l!            \ | and write it into the bridge
+        100000000 pci-next-mem64-align
+        \ Set base and limit registers:
+        20 rshift over 28 + rtas-config-l!  \ | set prefetch base upper 32 bits
+        pci-next-mem64 @ 10 rshift FFF0 and
+        pci-max-mem64 @ 1- FFF00000 and or
+        over 24 + rtas-config-l!            \ | set prefetch limit & base lower
+        pci-max-mem64 @ 1- 20 rshift
+        swap 2C + rtas-config-l!            \ | and set the limit upper 32 bits
     ELSE
         pci-next-mem-align-1mb
         10 rshift                           \ | keep upper 16 bits
@@ -152,24 +160,19 @@  here 100 allot CONSTANT pci-device-vec
     THEN
 ;
 
-\ Update pci-next-mem to be 1MB aligned and set the mem-limit register
-\ The Limit Value is one less then the upper boundary
-\ If the limit is less than the base the mem is disabled
+\ Update pci-next-mem (or -mem64) to be aligned (with some additional space
+\ for hot-plugging later) and set the mem-limit register. The Limit Value is
+\ one less then the upper boundary.
 : pci-bridge-set-mem-limit ( addr -- )
     dup pci-bridge-has-mem64               \ check if 64bit support
     IF                                      \ IF 64 bit support
-        pci-next-mem-extend-1mb
-        1-                                  \ | make limit one less than boundary
-        pci-next-mem64 @ 100000000 #aligned \ | Reat current value of 64-bar and align at 4GB
-        dup pci-next-mem64 x!               \ | and write it back
-        1-                                  \ | make limite one less than boundary
-        2 pick swap                         \ |
-        20 rshift                           \ | keep upper 32 bits
-        swap 2C + rtas-config-l!            \ | and write it into the Limit-Upper32-bits
-        FFFF0000 and                        \ | keep upper 16 bits
-        over 24 + rtas-config-l@
-        0000FFFF and                        \ | fetch original Value
-        or swap 24 + rtas-config-l!         \ and write it into the bridge
+        100000000 80000000 pci-next-mem64-align-extend
+        \ Update the limit registers:
+        1-
+        20 rshift
+        over 2C + rtas-config-l!            \ | set the limit upper 32 bits
+        pci-next-mem64 @ 1- 10 rshift
+        swap 26 + rtas-config-w!            \ | set limit lower bits
     ELSE
         \ Update current variable (add space for hot-plugging and align it)
         pci-next-mem-extend-1mb