Subversion Repositories Kolibri OS

Rev

Rev 1507 | Rev 1551 | 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. ;;  PCIe.INC                                                    ;;
  8. ;;                                                              ;;
  9. ;;  Extended PCI express services                               ;;
  10. ;;                                                              ;;
  11. ;;                  art_zh  <artem@jerdev.co.uk>                ;;
  12. ;;                                                              ;;
  13. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14.  
  15. $Revision: 1463 $
  16.  
  17. ;***************************************************************************
  18. ;   Function
  19. ;      pci_ext_config:
  20. ;
  21. ;   Description
  22. ;       PCIe extended (memory-mapped) config space detection
  23. ;
  24. ;   WARNINGs:
  25. ;       1) Very Experimental!
  26. ;       2) direct HT-detection (no ACPI or BIOS service used)
  27. ;       3) Only AMD/HT processors currently supported
  28. ;
  29. ;***************************************************************************
  30.  
  31. mmio_pcie_cfg_addr      dd      0x00000000      ; pcie space may be defined here
  32. mmio_pcie_cfg_lim       dd      0x000FFFFF      ; upper pcie space address
  33.  
  34.  
  35. align 4
  36.  
  37. pci_ext_config:
  38.         mov     ebx, [mmio_pcie_cfg_addr]
  39.         or      ebx,ebx
  40.         jz      @f
  41.         or      ebx, 0x7FFFFFFF         ; required by PCI-SIG standards
  42.         jnz     .pcie_failed
  43.         add     ebx, 0x0FFFFC
  44.         cmp     ebx, [mmio_pcie_cfg_lim]; is the space limit correct?
  45.         ja      .pcie_failed
  46.         jmp     .pcie_cfg_mapped
  47. @@:
  48.         mov     ebx, [cpu_vendor]
  49.         cmp     ebx, dword [AMD_str]
  50.         jne     .pcie_failed
  51.         mov     bx, 0xC184              ; dev = 24, fn = 01, reg = 84h
  52.  
  53. .check_HT_mmio:
  54.         mov     cx, bx
  55.         mov     ax, 0x0002              ; bus = 0, 1dword to read
  56.         call    pci_read_reg
  57.         mov     bx, cx
  58.         sub     bl, 4
  59.         and     al, 0x80                ; check the NP bit
  60.         jz      .no_pcie_cfg
  61.         shl     eax, 8                  ; bus:[27..20], dev:[19:15]
  62.         or      eax, 0x00007FFC         ; fun:[14..12], reg:[11:2]
  63.         mov     [mmio_pcie_cfg_lim], eax
  64.         mov     cl, bl
  65.         mov     ax, 0x0002              ; bus = 0, 1dword to read
  66.         call    pci_read_reg
  67.         mov     bx, cx
  68.         test    al, 0x03                ; MMIO Base RW enabled?
  69.         jz      .no_pcie_cfg
  70.         test    al, 0x0C                ; MMIO Base locked?
  71.         jnz     .no_pcie_cfg
  72.         xor     al, al
  73.         shl     eax, 8
  74.         test    eax, 0x000F0000         ; MMIO Base must be bus0-aligned
  75.         jnz     .no_pcie_cfg
  76.         mov     [mmio_pcie_cfg_addr], eax
  77.         add     eax, 0x000FFFFC
  78.         sub     eax,[mmio_pcie_cfg_lim] ; MMIO must cover at least one bus
  79.         ja      .no_pcie_cfg
  80.  
  81. ;       -- it looks like a true PCIe config space;
  82.         mov     eax,[mmio_pcie_cfg_addr]        ; physical address
  83.         or      eax, (PG_SHARED + PG_LARGE + PG_USER)
  84.         mov     ebx, PCIe_CONFIG_SPACE          ; linear address
  85.         mov     ecx, ebx
  86.         shr     ebx, 20        
  87.         add     ebx, sys_pgdir                  ; PgDir entry @
  88. @@:
  89.         mov     dword[ebx], eax                 ; map 4 buses
  90.         invlpg  [ecx]
  91.         cmp     bl, 4
  92.         jz      .pcie_cfg_mapped                ; fix it later
  93.         add     bl, 4                           ; next PgDir entry
  94.         add     eax, 0x400000                   ; eax += 4M
  95.         add     ecx, 0x400000
  96.         jmp     @b     
  97.  
  98. .pcie_cfg_mapped:
  99.        
  100. ;       -- glad to have the extended PCIe config field found
  101.         mov     esi, boot_pcie_ok
  102.         call    boot_log
  103.         ret     ; <<<<<<<<<<< OK >>>>>>>>>>>
  104.        
  105. .no_pcie_cfg:
  106.  
  107.         xor     eax, eax
  108.         mov     [mmio_pcie_cfg_addr], eax
  109.         mov     [mmio_pcie_cfg_lim],  eax
  110.         add     bl, 12
  111.         cmp     bl, 0xC0                ; MMIO regs lay below this offset
  112.         jb      .check_HT_mmio
  113. .pcie_failed:
  114.         mov     esi, boot_pcie_fail
  115.         call    boot_log
  116.         ret     ; <<<<<<<<< FAILURE >>>>>>>>>
  117.  
  118.