[openfirmware] r1159 - cpu/x86 cpu/x86/pc/olpc/via dev dev/mmc/sdhci

svn at openfirmware.info svn at openfirmware.info
Wed Apr 29 07:55:32 CEST 2009


Author: wmb
Date: 2009-04-29 07:55:31 +0200 (Wed, 29 Apr 2009)
New Revision: 1159

Added:
   cpu/x86/acpitimer.fth
Modified:
   cpu/x86/pc/olpc/via/addrs.fth
   cpu/x86/pc/olpc/via/config.fth
   cpu/x86/pc/olpc/via/devices.fth
   cpu/x86/pc/olpc/via/fw.bth
   cpu/x86/pc/olpc/via/pcinode.fth
   cpu/x86/pc/olpc/via/romreset.bth
   dev/mmc/sdhci/sdhci.fth
   dev/pcibus.fth
Log:
Via demo version - various improvements, still a work in progress.







Added: cpu/x86/acpitimer.fth
===================================================================
--- cpu/x86/acpitimer.fth	                        (rev 0)
+++ cpu/x86/acpitimer.fth	2009-04-29 05:55:31 UTC (rev 1159)
@@ -0,0 +1,62 @@
+\ See license at end of file
+purpose: Timing functions using the ACPI timer
+
+\ The ACPI timer counts at 3.579545 MHz.
+\ 3.579545 * 1024 is 3665
+: acpi-timer@  ( -- counts )  acpi-io-base 8 + pl@  ;
+: acpi-us  ( us -- )
+   d# 3664 * d# 10 rshift  acpi-timer@ +  ( end )
+   begin   dup acpi-timer@ -  0< until    ( end )
+   drop
+;
+: acpi-ms  ( us -- )
+   d# 3580 * acpi-timer@ +  ( end )
+   begin   dup acpi-timer@ -  0< until    ( end )
+   drop
+;
+
+[ifdef] tsc@
+: acpi-calibrate-tsc  ( -- )
+   tsc@  d# 100 acpi-ms  tsc@           ( d.start d.end )
+   2swap d-                             ( d.delta )
+   2dup d# 100 um/mod nip to ms-factor  ( d.delta ms )
+   d# 100,000  um/mod nip to us-factor  ( )
+;
+[else]
+: us  ( us -- )  acpi-us  ;
+' acpi-ms to ms
+\ Timing tools
+variable timestamp1
+: t(  ( -- )  acpi-timer@ timestamp1 ! ;
+: )t  ( -- )
+   acpi-timer@  timestamp1 @  -  d# 1000 d# 3580 */  ( microseconds )
+   push-decimal
+   <#  u# u# u#  [char] , hold  u# u#s u#>  type  ."  uS "
+   pop-base
+;
+
+[then]
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2009 FirmWorks
+\ 
+\ Permission is hereby granted, free of charge, to any person obtaining
+\ a copy of this software and associated documentation files (the
+\ "Software"), to deal in the Software without restriction, including
+\ without limitation the rights to use, copy, modify, merge, publish,
+\ distribute, sublicense, and/or sell copies of the Software, and to
+\ permit persons to whom the Software is furnished to do so, subject to
+\ the following conditions:
+\ 
+\ The above copyright notice and this permission notice shall be
+\ included in all copies or substantial portions of the Software.
+\ 
+\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+\
+\ LICENSE_END

Modified: cpu/x86/pc/olpc/via/addrs.fth
===================================================================
--- cpu/x86/pc/olpc/via/addrs.fth	2009-04-25 04:25:27 UTC (rev 1158)
+++ cpu/x86/pc/olpc/via/addrs.fth	2009-04-29 05:55:31 UTC (rev 1159)
@@ -50,7 +50,14 @@
 h# fe01.b000 constant ehci-pci-base
 h# fe02.4000 constant sd-pci-base
 h# fe02.8000 constant camera-pci-base
+h# fec0.0000 constant ioapic-mmio-base
+h# fed0.0000 constant hpet-mmio-base
+h# fed3.0000 constant spi-mmio-base
+h# fed4.0000 constant wdt-mmio-bast
 
+h#      4000 constant acpi-io-base
+h#      4100 constant smbus-io-base
+
 h# 9.fc00 constant 'ebda  \ Extended BIOS Data Area, which we co-opt for our real-mode workspace
 
 h# e0000 constant rsdp-adr

Modified: cpu/x86/pc/olpc/via/config.fth
===================================================================
--- cpu/x86/pc/olpc/via/config.fth	2009-04-25 04:25:27 UTC (rev 1158)
+++ cpu/x86/pc/olpc/via/config.fth	2009-04-29 05:55:31 UTC (rev 1159)
@@ -13,7 +13,7 @@
 
 \ create virtual-mode
 create addresses-assigned  \ Define if base addresses are already assigned
-create serial-console      \ Define to default to serial port for console
+\ create serial-console      \ Define to default to serial port for console
 create pc
 create linux-support
 create use-elf

Modified: cpu/x86/pc/olpc/via/devices.fth
===================================================================
--- cpu/x86/pc/olpc/via/devices.fth	2009-04-25 04:25:27 UTC (rev 1158)
+++ cpu/x86/pc/olpc/via/devices.fth	2009-04-29 05:55:31 UTC (rev 1159)
@@ -15,16 +15,23 @@
 \ Use the CPU chip's Time Stamp Counter for timing; it does just what we want
 fload ${BP}/cpu/x86/tsc.fth
 
-stand-init:
+\ Calibrate the Time Stamp Counter using the ACPI timer
+fload ${BP}/cpu/x86/acpitimer.fth
+
+fload ${BP}/cpu/x86/pc/olpc/via/smbus.fth	\ SMBUS driver
+
+\ Do this early so the interact timing works right
+: stand-init-io  ( -- )
+   stand-init-io
+
    d# 1,500,000,000  " VIA,C7"
 
    " /cpu" find-device                                  ( cpu-clock-hz model$ )
       " model" string-property                          ( cpu-clock-hz )
-      dup " clock-frequency" integer-property           ( cpu-clock-hz )
-   device-end                                           ( cpu-clock-hz )
+      " clock-frequency" integer-property               ( )
+   device-end                                           ( )
 
-   d# 2000 / dup  to ms-factor                          ( cpu-clock-khz )
-   d# 1000 /      to us-factor                          ( )
+   acpi-calibrate-tsc
 ;
 
 [ifdef] use-ega

Modified: cpu/x86/pc/olpc/via/fw.bth
===================================================================
--- cpu/x86/pc/olpc/via/fw.bth	2009-04-25 04:25:27 UTC (rev 1158)
+++ cpu/x86/pc/olpc/via/fw.bth	2009-04-29 05:55:31 UTC (rev 1159)
@@ -64,8 +64,7 @@
 dev /
 1 encode-int  " #address-cells"  property
 1 encode-int  " #size-cells"     property
-" OLPC" encode-string  " architecture" property
-device-end
+dend
 
 \ Memory management services
 [ifdef] virtual-mode
@@ -86,6 +85,17 @@
 
 fload ${BP}/cpu/x86/pc/rootnode.fth	\ Platform-specific root node changes
 
+dev /
+1 encode-int  " #address-cells"  property
+1 encode-int  " #size-cells"     property
+" OLPC" encode-string  " architecture" property
+[ifdef] demo-board
+" VIA Demo Board" " banner-name" string-property
+[else]
+" OLPC XO 1.5" " banner-name" string-property
+[then]
+device-end
+
 fload ${BP}/cpu/x86/pc/olpc/port80.fth	\ Port 80 debug messages
 
 [ifdef] Later
@@ -233,11 +243,10 @@
 
 hex
 : i-key-wait  ( ms -- pressed? )
-   ['] key? (see)
    cr ." Type 'i' to interrupt stand-init sequence" cr 
    0  do
-      key?  if
-         key upc ascii I  =  if  true unloop exit  then
+      ukey?  if
+         ukey upc ascii I  =  if  true unloop exit  then
       then
       1 ms
    loop
@@ -258,9 +267,8 @@
 
    standalone?  if
       disable-interrupts
-interact
-[ifdef] Later
-      d# 300
+\ interact
+      d# 1000
       i-key-wait  if
   [ifdef] Later
          protect-fw
@@ -271,9 +279,6 @@
   [ifdef] Later
       setup
   [then]
-[else]
- cr
-[then]
    then
 ;
 \ warning !
@@ -548,12 +553,8 @@
 ;
 [then]
 
-
 [ifdef] Later
 : console-start  ( -- )
-[ifdef] rom-loaded
-   video-map cr
-[then]
    " screen" open-dev  ?dup  if
       set-stdout
 \       logo-banner drop
@@ -568,6 +569,7 @@
 \   use-nvramrc?  if  nvramrc safe-evaluate  then
 ;
 [then]
+
 : debug-interact  ( -- )
    early-interact?  if
       " Interrupting startup sequence prior to probing" .because
@@ -657,6 +659,9 @@
 [then]
    ['] (interrupt-auto-boot?) to interrupt-auto-boot?
    ?usb-keyboard
+   install-console
+   install-dual-console
+   banner
 [ifdef] Later
    auto-boot
 [then]
@@ -665,10 +670,10 @@
    frozen?            ( frozen? )
    unfreeze visible   ( frozen? )
    if  banner  then  \ Reissue banner if it was suppressed
-[then]
 
    blue-letters ." Type 'help' for more information." black-letters
    cr cr
+[then]
 
    quit
 ;

Modified: cpu/x86/pc/olpc/via/pcinode.fth
===================================================================
--- cpu/x86/pc/olpc/via/pcinode.fth	2009-04-25 04:25:27 UTC (rev 1158)
+++ cpu/x86/pc/olpc/via/pcinode.fth	2009-04-29 05:55:31 UTC (rev 1159)
@@ -30,11 +30,13 @@
 \  patch noop assign-all-addresses prober
 warning @ warning off
 : assign-pci-addr  ( phys.lo phys.mid phys.hi len | -1 -- phys.hi paddr size )
-   2dup -1 <>  swap preassigned-pci-slot?  and  if  ( phys.lo phys.mid phys.hi len )
-      2swap 2drop    >r                         ( phys.hi r: len )
-      dup config-l@  1 invert and  r>           ( phys.hi paddr len )
-      exit
-   then
+   dup -1 <>  if   ( phys.lo phys.mid phys.hi len )
+      over preassigned-pci-slot?  if               ( phys.lo phys.mid phys.hi len )
+         2swap 2drop    >r                         ( phys.hi r: len )
+         dup config-l@  1 invert and  r>           ( phys.hi paddr len )
+         exit
+      then         ( phys.lo phys.mid phys.hi len )
+   then            ( phys.lo phys.mid phys.hi len | -1 )
    assign-pci-addr
 ;
 warning !

Modified: cpu/x86/pc/olpc/via/romreset.bth
===================================================================
--- cpu/x86/pc/olpc/via/romreset.bth	2009-04-25 04:25:27 UTC (rev 1158)
+++ cpu/x86/pc/olpc/via/romreset.bth	2009-04-29 05:55:31 UTC (rev 1159)
@@ -302,7 +302,7 @@
 1 [if]
  \ This turns an OS reboot into a real cold start - from coreboot
    4001 8888 config-ww   \ Set ACPI base address
-   84 8881 config-wb   \ Enable ACPI regs and guard RTC against power glitches
+   8c 8881 config-wb   \ Enable ACPI regs, 32-bit PM timer, guard RTC against power glitches
    4004 port-rw        \ Get APCI Status register
    d# 10 # ax shr  7 # ax and  1 # ax cmp  <>  if  \ Not a wakeup from S3
       380 config-rb  ax ax or  0<>  if             \ C-page shadowing not on yet

Modified: dev/mmc/sdhci/sdhci.fth
===================================================================
--- dev/mmc/sdhci/sdhci.fth	2009-04-25 04:25:27 UTC (rev 1158)
+++ dev/mmc/sdhci/sdhci.fth	2009-04-29 05:55:31 UTC (rev 1159)
@@ -17,16 +17,30 @@
 
 " sdhci" " compatible" string-property
 
-h# 4000 constant /regs
+h# 100 value /regs   \ Standard size of SDHCI register block
+1 value #slots
 
 : phys+ encode-phys encode+  ;
 : i+  encode-int encode+  ;
 
-0 0 encode-bytes
-0 0 h# 0000.0000  my-space +  phys+   0 i+  h# 0000.0100 i+   \ Config registers
-0 0 h# 0100.0010  my-space +  phys+   0 i+         /regs i+   \ Frame buffer
-" reg" property
+: make-reg  ( -- )
+   0 0 encode-bytes
+   0 0 h# 0000.0000  my-space +  phys+   0 i+  h# 0000.0100 i+   \ Config registers
 
+   my-space " config-l@" $call-parent h# 410111ab =  if  \ Marvell CaFe chip
+      h# 4000 to /regs
+   then
+
+   h# 40 my-space + " config-b@" $call-parent  ( slot_info )
+   4 rshift 7 and  1+                          ( #slots )
+   0  ?do
+      0 0 h# 0100.0010  i 4 * +  my-space +  phys+   0 i+   /regs i+   \ Operational regs for slot N
+   loop
+   " reg" property
+;
+make-reg
+
+
 0 value debug?
 
 0 value chip
@@ -638,7 +652,7 @@
 : power-up-card  ( -- false | retry? true )
    intstat-on
    card-power-off d# 20 ms
-   card-power-on  d# 20 ms  \ This delay is just a guess
+   card-power-on  d# 40 ms  \ This delay is just a guess (20 was barely too slow for a Via board)
    card-inserted?  0=  if  card-power-off  intstat-off  false true exit  then   
    card-clock-slow  d# 10 ms  \ This delay is just a guess
    reset-card     \ Cmd 0

Modified: dev/pcibus.fth
===================================================================
--- dev/pcibus.fth	2009-04-25 04:25:27 UTC (rev 1158)
+++ dev/pcibus.fth	2009-04-29 05:55:31 UTC (rev 1159)
@@ -73,9 +73,9 @@
 \ XXX we need a sophisticated IO space allocator that accounts for
 \ hardwired devices
 
-: self-b@  ( phys.hi -- l )  " config-b@" $call-self  ;
-: self-l@  ( phys.hi -- l )  " config-l@" $call-self  ;
-: self-l!  ( l phys.hi -- )  " config-l!" $call-self  ;
+: self-b@  ( phys.hi -- l )  h# ff.ffff and  " config-b@" $call-self  ;
+: self-l@  ( phys.hi -- l )  h# ff.ffff and  " config-l@" $call-self  ;
+: self-l!  ( l phys.hi -- )  h# ff.ffff and  " config-l!" $call-self  ;
 : 64mem?  ( phys.hi -- flag ) self-l@  7 and 4 = ;
 : io?  ( phys.hi -- flag )
    \ For expansion ROM base address registers, the LSB is an enable bit,




More information about the openfirmware mailing list