Subversion Repositories Kolibri OS

Rev

Rev 1599 | Rev 1683 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) 2010 KolibriOS team.     All rights reserved.  ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;;                                                              ;;
  7. ;;  AMD HyperTransport bus control                              ;;
  8. ;;                                                              ;;
  9. ;;                  art_zh  <kolibri@jerdev.co.uk>              ;;
  10. ;;                                                              ;;
  11. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12.  
  13. $Revision: 1554 $
  14.  
  15. NB_MISC_INDEX   equ     0xF0000060      ; NB Misc indirect access
  16. NB_MISC_DATA    equ     0xF0000064
  17. PCIEIND_INDEX   equ     0xF00000E0      ; PCIe Core indirect config space access
  18. HTIU_NB_INDEX   equ     0xF0000094      ; HyperTransport indirect config space access
  19.  
  20. ;=============================================================================
  21. ;
  22. ; This code is a part of Kolibri-A and will only work with AMD RS760+ chipsets
  23. ;
  24. ;=============================================================================
  25. align 4
  26.  
  27. ;------------------------------------------
  28. ;       params:   al = nbconfig register#
  29. ;       returns: eax = register content
  30. ;
  31. rs7xx_nbconfig_read_pci:
  32.         and     eax, 0x0FC               ; leave register# only
  33.         or      eax, 0x80000000          ; bdf = 0:0.0
  34.         mov     dx,  0x0CF8              ; write to index reg
  35.         out     dx, eax
  36.         add     dl, 4
  37.         in      eax, dx
  38.         ret
  39. align 4
  40.  
  41. rs7xx_nbconfig_flush_pci:
  42.         mov     eax, 0x0B0              ; a scratch reg
  43.         mov     dx,  0xCF8
  44.         out     dx,  eax
  45.         ret
  46.  
  47. align 4
  48.  
  49. ;------------------------------------------
  50. ;       params:   al = nbconfig register#
  51. ;                ebx = register content
  52. ;
  53. rs7xx_nbconfig_write_pci:
  54.         and     eax, 0x0FC               ; leave register# only
  55.         or      eax, 0x80000000          ; bdf = 0:0.0
  56.         mov     dx,  0x0CF8              ; write to index reg
  57.         out     dx, eax
  58.         add     dl, 4
  59.         mov     eax, ebx
  60.         out     dx, eax
  61.         ret
  62.  
  63. ;***************************************************************************
  64. ;   Function
  65. ;      rs7xx_unlock_bar3:     unlocks the BAR3 register of nbconfig that
  66. ;                             makes pcie config address space visible
  67. ;   -----------------------
  68. ;   in: nothing      out: nothing      destroys:   eax ebx edx
  69. ;
  70. ;***************************************************************************
  71. align 4
  72. rs7xx_unlock_bar3:
  73.         mov     eax, NB_MISC_INDEX
  74.         mov     ebx, 0x080                      ; reg#0; write-enable
  75.         call    rs7xx_nbconfig_write_pci        ; set index
  76.         mov     eax, NB_MISC_DATA
  77.         call    rs7xx_nbconfig_read_pci         ; read data
  78.         mov     ebx, eax
  79.         and     ebx, 0xFFFFFFF7                 ; clear bit3
  80.         mov     eax, NB_MISC_DATA
  81.         call    rs7xx_nbconfig_write_pci        ; write it back
  82.         mov     eax, NB_MISC_INDEX
  83.         xor     ebx, ebx                        ; reg#0; write-locked
  84.         call    rs7xx_nbconfig_write_pci        ; set index
  85.         ret
  86.  
  87. ;--------------------------------------------------------------
  88. align 4
  89. rs780_read_misc:
  90. ;  in: eax(al) - reg#           out: eax = NBMISCIND data
  91.         push    edx
  92.         mov     edx, NB_MISC_INDEX
  93.         and     eax, 0x07F
  94.         mov     [edx], eax
  95.         add     dl, 4
  96.         mov     eax, [edx]
  97.         pop     edx
  98.         ret
  99.  
  100. ;-------------------------------------------
  101. align 4
  102. rs780_write_misc:
  103. ;  in: eax(al) - reg#     ebx = NBMISCIND data
  104.         push    edx
  105.         mov     edx, NB_MISC_INDEX
  106.         and     eax, 0x07F
  107.         or      eax, 0x080              ; set WE
  108.         mov     [edx], eax
  109.         add     dl, 4
  110.         mov     [edx], ebx
  111.         sub     dl, 4
  112.         xor     eax,   eax
  113.         mov     [edx], eax              ; safety last
  114.         pop     edx
  115.         ret
  116.  
  117. ;-------------------------------------------------------------
  118. align 4
  119. rs780_read_pcieind:
  120. ;  in: ah = bridge#, al = reg#           out: eax = PCIEIND data
  121.         push    edx
  122.         xor     edx, edx
  123.         mov     ah,  dl                 ; bridge# :     0 = Core+GFX;   0x10 = Core+SB
  124.         and     dl,  15                 ;            0x20 = Core+GPP;  2..12 = a PortBridge
  125.         shl     edx, 15                 ; device#
  126.         add     edx, PCIEIND_INDEX      ; full bdf-address
  127.         and     eax, 0x30FF
  128.         or      al,  al
  129.         jnz     @f
  130.         shl     eax, 4                  ; set bits 17..16 for a Core bridge
  131. @@:
  132.         mov     [edx], eax
  133.         add     dl,  4
  134.         mov     eax, [edx]
  135.         pop     edx
  136.         ret
  137.  
  138. ;-------------------------------------------
  139. align 4
  140. rs780_write_pcieind:
  141. ;  in: ah = bridge#, al = reg#,  ebx = PCIEIND data
  142.         push    edx
  143.         xor     edx, edx
  144.         mov     ah,  dl                 ; bridge# :     0 = Core+GFX;   0x10 = Core+SB
  145.         and     dl,  15                 ;            0x20 = Core+GPP;  2..12 = a PortBridge
  146.         shl     edx, 15                 ; device#
  147.         add     edx, PCIEIND_INDEX      ; full bdf-address
  148.         and     eax, 0x30FF
  149.         or      al,  al
  150.         jnz     @f
  151.         shl     eax, 4                  ; set bits 17..16 for a Core bridge
  152. @@:
  153.         mov     [edx], eax
  154.         add     dl,  4
  155.         mov     [edx], ebx
  156.         sub     dl,  4
  157.         xor     eax,   eax
  158.         mov     [edx], eax              ; safety last
  159.         pop     edx
  160.         ret
  161.  
  162. ;------------------------------------------------
  163. align 4
  164. rs780_read_htiu:
  165. ; in:  al = reg#  |  out: eax = HTIU data
  166. ;------------------------------------------------
  167.         push    edx
  168.         mov     edx,  HTIU_NB_INDEX
  169.         and     eax, 0x07F
  170.         mov     [edx], eax
  171.         add     dl,  4
  172.         mov     eax, [edx]
  173.         pop     edx
  174.         ret
  175. ;------------------------------------------------
  176. align 4
  177. rs780_write_htiu:
  178. ; in:  al = reg#; ebx = data
  179. ;------------------------------------------------
  180.         push    edx
  181.         mov     edx,  HTIU_NB_INDEX
  182.         and     eax, 0x07F
  183.         or      eax, 0x100
  184.         mov     [edx], eax
  185.         add     dl,  4
  186.         mov     [edx], ebx
  187.         sub     dl,  4
  188.         xor     eax,   eax
  189.         mov     [edx], eax
  190.         pop     edx
  191.         ret
  192.  
  193.  
  194.  
  195. ;***************************************************************************
  196. ;   Function
  197. ;      rs7xx_pcie_init:
  198. ;
  199. ;   Description
  200. ;       PCIe extended (memory-mapped) config space detection
  201. ;
  202. ;***************************************************************************
  203.  
  204. align 4
  205.  
  206. rs7xx_pcie_init:
  207.         call    rs7xx_unlock_bar3
  208.         mov     al, 0x7C                       ; NB_IOC_CFG_CNTL
  209.         call    rs7xx_nbconfig_read_pci
  210.         mov     ebx, eax
  211.         call    rs7xx_nbconfig_flush_pci
  212.         test    ebx, 0x20000000                 ; BAR3 locked?
  213.         jz      .rs7xx_pcie_blocked
  214.         mov     al, 0x84                        ; NB_PCI_ARB
  215.         call    rs7xx_nbconfig_read_pci
  216.         shr     eax,16
  217.         and     ax, 7                           ; the Bus range lays here:
  218.         jnz     @f
  219.         mov     ax, 8                           ; 1=2Mb,  2=4MB,  3=8MB,  4=16MB
  220. @@:
  221.         mov     [PCIe_bus_range], ax            ; 5=32Mb, 6=64MB, 7=128Mb, 8=256Mb
  222.         mov     cl, al
  223.         call    rs7xx_nbconfig_flush_pci
  224.         dec     cl                              ; <4M ?
  225.         jnz     @f
  226.         inc     cl                              ; one PDE needed anyway
  227. @@:
  228.         dec     cl
  229.         mov     ebx, 1
  230.         shl     ebx, cl
  231.         mov     [mmio_pcie_cfg_pdes], bx        ; 1..64 PDE(s) needed,
  232.         shl     ebx, 22
  233.         mov     [mmio_pcie_cfg_lim], ebx        ; or 4..256Mb space to map
  234.         dec     [mmio_pcie_cfg_lim]
  235.  
  236.         mov     al, 0x1C                        ; NB_BAR3_PCIEXP_MMCFG
  237.         call    rs7xx_nbconfig_read_pci
  238.         mov     ebx, eax
  239.         call    rs7xx_nbconfig_flush_pci
  240.         mov     eax, ebx
  241.         and     eax, 0xFFE00000                 ; valid bits [31..21]
  242.         jz      .rs7xx_pcie_blocked             ; NB BAR3 may be invisible!
  243.                                                 ; try to get pcie ecfg address indirectly
  244. .addr_found:
  245.         mov     [mmio_pcie_cfg_addr], eax       ; physical address (lower 32 bits)
  246.         add     [mmio_pcie_cfg_lim],  eax
  247.  
  248.         or      eax, (PG_SHARED + PG_LARGE + PG_UW)  ;  by the way, UW is unsafe!
  249.         mov     ecx, PCIe_CONFIG_SPACE          ; linear address
  250.         mov     ebx, ecx
  251.         shr     ebx, 20
  252.         add     ebx, sys_pgdir                  ; PgDir entry @
  253.         mov     dl, byte[mmio_pcie_cfg_pdes]    ; 1 page = 4M in address space
  254.         cmp     dl, (USER_DMA_BUFFER - PCIe_CONFIG_SPACE) / 4194304
  255.         jb      @f
  256.         mov     dl, ((USER_DMA_BUFFER - PCIe_CONFIG_SPACE) / 4194304) - 1
  257.         mov     byte[mmio_pcie_cfg_pdes], dl
  258. @@:
  259.         xor     dx,  dx                         ; PDEs counter
  260. @@:
  261.         mov     dword[ebx], eax                 ; map 4 buses
  262.         add     bx,  4                          ; new PDE
  263.         add     eax, 0x400000                   ; +4M phys.
  264.         add     ecx, 0x400000                   ; +4M lin.
  265.         cmp     dl, byte[mmio_pcie_cfg_pdes]
  266.         jnc     .pcie_cfg_mapped
  267.         inc     dl
  268.         jmp     @b
  269.         mov     eax, cr3
  270.         mov     cr3, eax                        ; flush TLB
  271. .pcie_cfg_mapped:
  272.         mov     esi, boot_pcie_ok
  273.         call    boot_log
  274.         ret     ; <<< OK >>>
  275. .rs7xx_pcie_fail:
  276.         mov     esi, boot_rs7xx_fail
  277.         call    boot_log
  278.         jmp     $
  279. .rs7xx_pcie_blocked:
  280.         mov     esi, boot_rs7xx_blkd
  281.         call    boot_log
  282.         jmp     $
  283.  
  284.  
  285.  
  286.  
  287.  
  288.