Subversion Repositories Kolibri OS

Rev

Rev 1551 | Go to most recent revision | Blame | 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  <artem@jerdev.co.uk>                ;;
  11. ;;                                                              ;;
  12. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  13.  
  14. $Revision: 1554 $
  15.  
  16.  
  17.  
  18. ;=============================================================================
  19. ;
  20. ; This code is a part of Kolibri-A and will only work with AMD RS760+ chipsets
  21. ;
  22. ;=============================================================================
  23. align 4
  24.  
  25. ;------------------------------------------
  26. ;       params:   al = nbconfig register#
  27. ;       returns: eax = register content
  28. ;
  29. rs7xx_nbconfig_read_pci:
  30.         and     eax, 0x0FC               ; leave register# only
  31.         or      eax, 0x80000000          ; bdf = 0:0.0
  32.         mov     dx,  0x0CF8              ; write to index reg
  33.         out     dx, eax
  34.         add     dl, 4
  35.         in      eax, dx
  36.         ret
  37. align 4
  38.  
  39. rs7xx_nbconfig_flush_pci:
  40.         mov     eax, 0x0B0              ; a scratch reg
  41.         mov     dx,  0xCF8
  42.         out     dx,  eax
  43.         ret
  44.  
  45. align 4
  46.  
  47. rs7xx_nbconfig_write_pci:
  48.         and     eax, 0x0FC               ; leave register# only
  49.         or      eax, 0x80000000          ; bdf = 0:0.0
  50.         mov     dx,  0x0CF8              ; write to index reg
  51.         out     dx, eax
  52.         add     dl, 4
  53.         mov     eax, ebx
  54.         out     dx, eax
  55.         ret
  56.  
  57. ;***************************************************************************
  58. ;   Function
  59. ;      rs7xx_pcie_init:
  60. ;
  61. ;   Description
  62. ;       PCIe extended (memory-mapped) config space detection
  63. ;
  64. ;***************************************************************************
  65.  
  66. align 4
  67.  
  68. rs7xx_pcie_init:
  69.         mov     al, 0x7C                       ; NB_IOC_CFG_CNTL
  70.         call    rs7xx_nbconfig_read_pci
  71.         mov     ebx, eax
  72.         call    rs7xx_nbconfig_flush_pci
  73.         test    ebx, 0x20000000                 ; BAR3 locked?
  74.         jz      .rs7xx_pcie_blocked
  75.         mov     al, 0x84                        ; NB_PCI_ARB
  76.         call    rs7xx_nbconfig_read_pci
  77.         shr     eax,16
  78.         and     ax, 7                           ; the Bus range lays here:
  79.         jnz     @f
  80.         mov     ax, 8                           ; 1=2Mb,  2=4MB,  3=8MB,  4=16MB
  81. @@:
  82.         mov     [PCIe_bus_range], ax            ; 5=32Mb, 6=64MB, 7=128Mb, 8=256Mb
  83.         mov     cl, al
  84.         call    rs7xx_nbconfig_flush_pci
  85.         dec     cl                              ; <4M ?
  86.         jnz     @f
  87.         inc     cl                              ; one PDE needed anyway
  88. @@:
  89.         dec     cl
  90.         mov     ebx, 1
  91.         shl     ebx, cl
  92.         mov     [mmio_pcie_cfg_pdes], bx        ; 1..64 PDE(s) needed,
  93.         shl     ebx, 22
  94.         mov     [mmio_pcie_cfg_lim], ebx        ; or 4..256Mb space to map
  95.         dec     [mmio_pcie_cfg_lim]
  96.  
  97.         mov     al, 0x1C                        ; NB_BAR3_PCIEXP_MMCFG
  98.         call    rs7xx_nbconfig_read_pci
  99.         mov     ebx, eax
  100.         call    rs7xx_nbconfig_flush_pci
  101.         mov     eax, ebx
  102.         and     eax, 0xFFE00000                 ; valid bits [31..21]
  103.         jz      .rs7xx_pcie_blocked             ; NB BAR3 may be invisible!
  104.                                                 ; try to get pcie ecfg address indirectly
  105. .addr_found:
  106.         mov     [mmio_pcie_cfg_addr], eax       ; physical address (lower 32 bits)
  107.         add     [mmio_pcie_cfg_lim],  eax
  108.  
  109.         or      eax, (PG_SHARED + PG_LARGE + PG_UW)  ;  by the way, UW is unsafe!
  110.         mov     ecx, PCIe_CONFIG_SPACE          ; linear address
  111.         mov     ebx, ecx
  112.         shr     ebx, 20
  113.         add     ebx, sys_pgdir                  ; PgDir entry @
  114.         mov     dl, byte[mmio_pcie_cfg_pdes]    ; 1 page = 4M in address space
  115.         cmp     dl, (USER_DMA_BUFFER - PCIe_CONFIG_SPACE) / 4194304
  116.         jb      @f
  117.         mov     dl, ((USER_DMA_BUFFER - PCIe_CONFIG_SPACE) / 4194304) - 1
  118.         mov     byte[mmio_pcie_cfg_pdes], dl
  119. @@:
  120.         xor     dx,  dx                         ; PDEs counter
  121. @@:
  122.         mov     dword[ebx], eax                 ; map 4 buses
  123.         invlpg  [ecx]                           ; next PgDir entry
  124.         add     bx,  4                          ; new PDE
  125.         add     eax, 0x400000                   ; +4M phys.
  126.         add     ecx, 0x400000                   ; +4M lin.
  127.         cmp     dl, byte[mmio_pcie_cfg_pdes]
  128.         jnc     .pcie_cfg_mapped
  129.         inc     dl
  130.         jmp     @b
  131. .pcie_cfg_mapped:
  132.         mov     esi, boot_pcie_ok
  133.         call    boot_log
  134.         ret     ; <<< OK >>>
  135. .rs7xx_pcie_fail:
  136.         mov     esi, boot_rs7xx_fail
  137.         call    boot_log
  138.         ret
  139. .rs7xx_pcie_blocked:
  140.         mov     esi, boot_rs7xx_blkd
  141.         call    boot_log
  142.         call    pci_ext_config
  143.         jmp     .addr_found
  144.         ret
  145.  
  146.  
  147.  
  148.  
  149.  
  150.