Subversion Repositories Kolibri OS

Rev

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