Subversion Repositories Kolibri OS

Rev

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

  1. ;-----------------------------------------------------------------------------
  2. ; find the IDE controller in the device list
  3. ;-----------------------------------------------------------------------------
  4.         mov     ecx, IDE_controller_1
  5.         mov     esi, pcidev_list
  6. ;--------------------------------------
  7. align 4
  8. .loop:
  9.         mov     esi, [esi+PCIDEV.fd]
  10.         cmp     esi, pcidev_list
  11.         jz      find_IDE_controller_done
  12.  
  13.         mov     eax, [esi+PCIDEV.class]
  14.         shr     eax, 4
  15.         cmp     eax, 0x01018
  16.         jnz     .loop
  17. ;--------------------------------------
  18. .found:
  19.         mov     eax, [esi+PCIDEV.class]
  20.         DEBUGF  1, 'K : IDE controller programming interface %x\n', eax
  21.         mov     [ecx+IDE_DATA.ProgrammingInterface], eax
  22.  
  23.         mov     ah, [esi+PCIDEV.bus]
  24.         mov     al, 2
  25.         mov     bh, [esi+PCIDEV.devfn]
  26. ;--------------------------------------
  27.         mov     dx, 0x1F0
  28.         test    byte [esi+PCIDEV.class], 1
  29.         jz      @f
  30.         mov     bl, 0x10
  31.         push    eax
  32.         call    pci_read_reg
  33.         and     eax, 0xFFFC
  34.         mov     edx, eax
  35.         pop     eax
  36. @@:
  37.         DEBUGF  1, 'K : BAR0 IDE base addr %x\n', dx
  38.         mov     [StandardATABases], dx
  39.         mov     [ecx+IDE_DATA.BAR0_val], dx
  40. ;--------------------------------------
  41.         mov     dx, 0x3F4
  42.         test    byte [esi+PCIDEV.class], 1
  43.         jz      @f
  44.         mov     bl, 0x14
  45.         push    eax
  46.         call    pci_read_reg
  47.         and     eax, 0xFFFC
  48.         mov     edx, eax
  49.         pop     eax
  50. @@:
  51.         DEBUGF  1, 'K : BAR1 IDE base addr %x\n', dx
  52.         mov     [ecx+IDE_DATA.BAR1_val], dx
  53. ;--------------------------------------
  54.         mov     dx, 0x170
  55.         test    byte [esi+PCIDEV.class], 4
  56.         jz      @f
  57.         mov     bl, 0x18
  58.         push    eax
  59.         call    pci_read_reg
  60.         and     eax, 0xFFFC
  61.         mov     edx, eax
  62.         pop     eax
  63. @@:
  64.         DEBUGF  1, 'K : BAR2 IDE base addr %x\n', dx
  65.         mov     [StandardATABases+2], dx
  66.         mov     [ecx+IDE_DATA.BAR2_val], dx
  67. ;--------------------------------------
  68.         mov     dx, 0x374
  69.         test    byte [esi+PCIDEV.class], 4
  70.         jz      @f
  71.         mov     bl, 0x1C
  72.         push    eax
  73.         call    pci_read_reg
  74.         and     eax, 0xFFFC
  75.         mov     edx, eax
  76.         pop     eax
  77. @@:
  78.         DEBUGF  1, 'K : BAR3 IDE base addr %x\n', dx
  79.         mov     [ecx+IDE_DATA.BAR3_val], dx
  80. ;--------------------------------------
  81.         mov     bl, 0x20
  82.         push    eax
  83.         call    pci_read_reg
  84.         and     eax, 0xFFFC
  85.         DEBUGF  1, 'K : BAR4 IDE controller register base addr %x\n', ax
  86.         mov     [ecx+IDE_DATA.RegsBaseAddres], ax
  87.         pop     eax
  88. ;--------------------------------------
  89.         mov     bl, 0x3C
  90.         push    eax
  91.         call    pci_read_reg
  92.         and     eax, 0xFF
  93.         DEBUGF  1, 'K : IDE Interrupt %x\n', al
  94.         mov     [ecx+IDE_DATA.Interrupt], ax
  95.         pop     eax
  96.  
  97.         add     ecx, sizeof.IDE_DATA
  98. ;--------------------------------------
  99.         jmp     .loop
  100. ;-----------------------------------------------------------------------------
  101. uglobal
  102. align 4
  103. ;--------------------------------------
  104. IDE_controller_pointer dd ?
  105. ;--------------------------------------
  106. IDE_controller_1 IDE_DATA
  107. IDE_controller_2 IDE_DATA
  108. IDE_controller_3 IDE_DATA
  109. ;--------------------------------------
  110. cache_ide0  IDE_CACHE
  111. cache_ide1  IDE_CACHE
  112. cache_ide2  IDE_CACHE
  113. cache_ide3  IDE_CACHE
  114. cache_ide4  IDE_CACHE
  115. cache_ide5  IDE_CACHE
  116. cache_ide6  IDE_CACHE
  117. cache_ide7  IDE_CACHE
  118. cache_ide8  IDE_CACHE
  119. cache_ide9  IDE_CACHE
  120. cache_ide10 IDE_CACHE
  121. cache_ide11 IDE_CACHE
  122. ;--------------------------------------
  123. IDE_device_1 rd 2
  124. IDE_device_2 rd 2
  125. IDE_device_3 rd 2
  126. ;--------------------------------------
  127. endg
  128. ;-----------------------------------------------------------------------------
  129. ; START of initialisation IDE ATA code
  130. ;-----------------------------------------------------------------------------
  131. Init_IDE_ATA_controller:
  132.         cmp     [ecx+IDE_DATA.ProgrammingInterface], 0
  133.         jne     @f
  134.  
  135.         ret
  136. ;--------------------------------------
  137. @@:
  138.         mov     esi, boot_disabling_ide
  139.         call    boot_log
  140. ;--------------------------------------
  141. ; Disable IDE interrupts, because the search
  142. ; for IDE partitions is in the PIO mode.
  143. ;--------------------------------------
  144. .disable_IDE_interrupt:
  145. ; Disable interrupts in IDE controller for PIO
  146.         mov     al, 2
  147.         mov     dx, [ecx+IDE_DATA.BAR1_val] ;0x3F4
  148.         add     dx, 2 ;0x3F6
  149.         out     dx, al
  150.         mov     dx, [ecx+IDE_DATA.BAR3_val] ;0x374
  151.         add     dx, 2 ;0x376
  152.         out     dx, al
  153. ;-----------------------------------------------------------------------------
  154. ; set current ata bases
  155. @@:
  156.         mov     ax, [ecx+IDE_DATA.BAR0_val]
  157.         mov     [StandardATABases], ax
  158.         mov     ax, [ecx+IDE_DATA.BAR2_val]
  159.         mov     [StandardATABases+2], ax
  160.  
  161.         mov     esi, boot_detecthdcd
  162.         call    boot_log
  163. ;--------------------------------------
  164. include 'dev_hdcd.inc'
  165. ;--------------------------------------
  166.         ret
  167. ;-----------------------------------------------------------------------------
  168. Init_IDE_ATA_controller_2:
  169.         cmp     [ecx+IDE_DATA.ProgrammingInterface], 0
  170.         jne     @f
  171.  
  172.         ret
  173. ;--------------------------------------
  174. @@:
  175.         mov     dx, [ecx+IDE_DATA.RegsBaseAddres]
  176. ; test whether it is our interrupt?
  177.         add     dx, 2
  178.         in      al, dx
  179.         test    al, 100b
  180.         jz      @f
  181. ; clear Bus Master IDE Status register
  182. ; clear Interrupt bit
  183.         out     dx, al
  184. ;--------------------------------------
  185. @@:
  186.         add     dx, 8
  187. ; test whether it is our interrupt?
  188.         in      al, dx
  189.         test    al, 100b
  190.         jz      @f
  191. ; clear Bus Master IDE Status register
  192. ; clear Interrupt bit
  193.         out     dx, al
  194. ;--------------------------------------
  195. @@:
  196. ; read status register and remove the interrupt request
  197.         mov     dx, [ecx+IDE_DATA.BAR0_val] ;0x1F0
  198.         add     dx, 0x7 ;0x1F7
  199.         in      al, dx
  200.         mov     dx, [ecx+IDE_DATA.BAR2_val] ;0x170
  201.         add     dx, 0x7 ;0x177
  202.         in      al, dx
  203. ;-----------------------------------------------------------------------------
  204. ;        push    eax edx
  205. ;        mov     dx, [ecx+IDE_DATA.RegsBaseAddres]
  206. ;        xor     eax, eax
  207. ;        add     dx, 2
  208. ;        in      al, dx
  209. ;        DEBUGF  1, "K : Primary Bus Master IDE Status Register %x\n", eax
  210.  
  211. ;        add     dx, 8
  212. ;        in      al, dx
  213. ;        DEBUGF  1, "K : Secondary Bus Master IDE Status Register %x\n", eax
  214. ;        pop     edx eax
  215.  
  216. ;        cmp     [ecx+IDE_DATA.RegsBaseAddres], 0
  217. ;        setnz   [ecx+IDE_DATA.dma_hdd]
  218. ;-----------------------------------------------------------------------------
  219. ; set interrupts for IDE Controller
  220. ;-----------------------------------------------------------------------------
  221.         pushfd
  222.         cli
  223. .enable_IDE_interrupt:
  224.         mov     esi, boot_enabling_ide
  225.         call    boot_log
  226. ; Enable interrupts in IDE controller for DMA
  227.         xor     ebx, ebx
  228.         cmp     ecx, IDE_controller_2
  229.         jne     @f
  230.  
  231.         add     ebx, 5
  232.         jmp     .check_DRIVE_DATA
  233. ;--------------------------------------
  234. @@:
  235.         cmp     ecx, IDE_controller_3
  236.         jne     .check_DRIVE_DATA
  237.  
  238.         add     ebx, 10
  239. ;--------------------------------------
  240. .check_DRIVE_DATA:
  241.         mov     al, 0
  242.         mov     ah, [ebx+DRIVE_DATA+1]
  243.         test    ah, 10100000b ; check for ATAPI devices
  244.         jz      @f
  245. ;--------------------------------------
  246. .ch1_pio_set_ATAPI:
  247.         DEBUGF  1, "K : IDE CH1 PIO, because ATAPI drive present\n"
  248.         jmp     .ch1_pio_set_for_all
  249. ;--------------------------------------
  250. .ch1_pio_set_no_devices:
  251.         DEBUGF  1, "K : IDE CH1 PIO because no devices\n"
  252.         jmp     .ch1_pio_set_for_all
  253. ;-------------------------------------
  254. .ch1_pio_set:
  255.         DEBUGF  1, "K : IDE CH1 PIO because device not support UDMA\n"
  256. ;-------------------------------------
  257. .ch1_pio_set_for_all:
  258.         mov     [ecx+IDE_DATA.dma_hdd_channel_1], al
  259.         jmp     .ch2_check
  260. ;--------------------------------------
  261. @@:
  262.         xor     ebx, ebx
  263.         call    calculate_IDE_device_values_storage
  264.  
  265.         test    ah, 1010000b
  266.         jz      .ch1_pio_set_no_devices
  267.  
  268.         test    ah, 1000000b
  269.         jz      @f
  270.  
  271.         cmp     [ebx+IDE_DEVICE.UDMA_possible_modes], al
  272.         je      .ch1_pio_set
  273.  
  274.         cmp     [ebx+IDE_DEVICE.UDMA_set_mode], al
  275.         je      .ch1_pio_set
  276. ;--------------------------------------
  277. @@:
  278.         test    ah, 10000b
  279.         jz      @f
  280.  
  281.         add     ebx, 2
  282.  
  283.         cmp     [ebx+IDE_DEVICE.UDMA_possible_modes], al
  284.         je      .ch1_pio_set
  285.  
  286.         cmp     [ebx+IDE_DEVICE.UDMA_set_mode], al
  287.         je      .ch1_pio_set
  288. ;--------------------------------------
  289. @@:
  290.         mov     dx, [ecx+IDE_DATA.BAR1_val] ;0x3F4
  291.         add     dx, 2 ;0x3F6
  292.         out     dx, al
  293.         DEBUGF  1, "K : IDE CH1 DMA enabled\n"
  294.         mov     [ecx+IDE_DATA.dma_hdd_channel_1], byte 1
  295. ;--------------------------------------
  296. .ch2_check:
  297.         test    ah, 1010b ; check for ATAPI devices
  298.         jz      @f
  299. ;--------------------------------------
  300. .ch2_pio_set_ATAPI:
  301.         DEBUGF  1, "K : IDE CH2 PIO, because ATAPI drive present\n"
  302.         jmp     .ch2_pio_set_for_all
  303. ;--------------------------------------
  304. .ch2_pio_set_no_devices:
  305.         DEBUGF  1, "K : IDE CH2 PIO because no devices\n"
  306.         jmp     .ch2_pio_set_for_all
  307. ;--------------------------------------
  308. .ch2_pio_set:
  309.         DEBUGF  1, "K : IDE CH2 PIO because device not support UDMA\n"
  310. ;--------------------------------------
  311. .ch2_pio_set_for_all:
  312.         mov     [ecx+IDE_DATA.dma_hdd_channel_2], al
  313.         jmp     .set_interrupts_for_IDE_controllers
  314. ;--------------------------------------
  315. @@:
  316.         mov     ebx, 4
  317.         call    calculate_IDE_device_values_storage
  318.  
  319.         test    ah, 101b
  320.         jz      .ch2_pio_set_no_devices
  321.  
  322.         test    ah, 100b
  323.         jz      @f
  324.  
  325.         cmp     [ebx+IDE_DEVICE.UDMA_possible_modes], al
  326.         je      .ch2_pio_set
  327.  
  328.         cmp     [ebx+IDE_DEVICE.UDMA_set_mode], al
  329.         je      .ch2_pio_set
  330. ;--------------------------------------
  331. @@:
  332.         test    ah, 1b
  333.         jz      @f
  334.  
  335.         add     ebx, 2
  336.  
  337.         cmp     [ebx+IDE_DEVICE.UDMA_possible_modes], al
  338.         je      .ch2_pio_set
  339.  
  340.         cmp     [ebx+IDE_DEVICE.UDMA_set_mode], al
  341.         je      .ch2_pio_set
  342. ;--------------------------------------
  343. @@:
  344.         mov     dx, [ecx+IDE_DATA.BAR3_val] ;0x374
  345.         add     dx, 2 ;0x376
  346.         out     dx, al
  347.         DEBUGF  1, "K : IDE CH2 DMA enabled\n"
  348.         mov     [ecx+IDE_DATA.dma_hdd_channel_2], byte 1
  349. ;--------------------------------------
  350. .set_interrupts_for_IDE_controllers:
  351.         mov     esi, boot_set_int_IDE
  352.         call    boot_log
  353. ;--------------------------------------
  354.         mov     eax, [ecx+IDE_DATA.ProgrammingInterface]
  355.         cmp     ax, 0x0180
  356.         je      .pata_ide
  357.  
  358.         cmp     ax, 0x018a
  359.         jne     .sata_ide
  360. ;--------------------------------------
  361. .pata_ide:
  362.         cmp     [ecx+IDE_DATA.RegsBaseAddres], 0
  363.         je      .end_set_interrupts
  364.  
  365.         push    ecx
  366.         stdcall attach_int_handler, 14, IDE_irq_14_handler, 0
  367.         DEBUGF  1, "K : Set IDE IRQ14 return code %x\n", eax
  368.         stdcall attach_int_handler, 15, IDE_irq_15_handler, 0
  369.         DEBUGF  1, "K : Set IDE IRQ15 return code %x\n", eax
  370.         pop     ecx
  371.  
  372.         jmp     .end_set_interrupts
  373. ;--------------------------------------
  374. .sata_ide:
  375.         cmp     ax, 0x0185
  376.         je      .sata_ide_1
  377.  
  378.         cmp     ax, 0x018f
  379.         jne     .end_set_interrupts
  380. ;--------------------------------------
  381. .sata_ide_1:
  382. ; Some weird controllers generate an interrupt even if IDE interrupts
  383. ; are disabled and no IDE devices. For example, notebook ASUS K72F -
  384. ; IDE controller 010185 generates false interrupt when we work with
  385. ; the IDE controller 01018f. For this reason, the interrupt handler
  386. ; does not need to be installed if both channel IDE controller
  387. ; running in PIO mode.
  388.         cmp     [ecx+IDE_DATA.RegsBaseAddres], 0
  389.         je      .end_set_interrupts
  390.  
  391.         cmp     [ecx+IDE_DATA.dma_hdd_channel_1], 0
  392.         jne     @f
  393.  
  394.         cmp     [ecx+IDE_DATA.dma_hdd_channel_2], 0
  395.         je      .end_set_interrupts
  396. ;--------------------------------------
  397. @@:
  398.         mov     ax, [ecx+IDE_DATA.Interrupt]
  399.         movzx   eax, al
  400.         push    ecx
  401.         stdcall attach_int_handler, eax, IDE_common_irq_handler, 0
  402.         pop     ecx
  403.         DEBUGF  1, "K : Set IDE IRQ%d return code %x\n", [ecx+IDE_DATA.Interrupt]:1, eax
  404. ;--------------------------------------
  405. .end_set_interrupts:
  406.         popfd
  407.         ret
  408. ;-----------------------------------------------------------------------------
  409. ; END of initialisation IDE ATA code
  410. ;-----------------------------------------------------------------------------
  411. find_IDE_controller_done:
  412.         mov     ecx, IDE_controller_1
  413.         mov     [IDE_controller_pointer], ecx
  414.         call    Init_IDE_ATA_controller
  415.         mov     ecx, IDE_controller_2
  416.         mov     [IDE_controller_pointer], ecx
  417.         call    Init_IDE_ATA_controller
  418.         mov     ecx, IDE_controller_3
  419.         mov     [IDE_controller_pointer], ecx
  420.         call    Init_IDE_ATA_controller
  421. ;-----------------------------------------------------------------------------
  422.         mov     esi, boot_getcache
  423.         call    boot_log
  424. include 'getcache.inc'
  425. ;-----------------------------------------------------------------------------
  426.         mov     esi, boot_detectpart
  427.         call    boot_log
  428. include 'sear_par.inc'
  429. ;-----------------------------------------------------------------------------
  430.         mov     esi, boot_init_sys
  431.         call    boot_log
  432.         call    Parser_params
  433.  
  434. if ~ defined extended_primary_loader
  435. ; ramdisk image should be loaded by extended primary loader if it exists
  436. ; READ RAMDISK IMAGE FROM HD
  437. include '../boot/rdload.inc'
  438. end if
  439. ;-----------------------------------------------------------------------------
  440.         mov     ecx, IDE_controller_1
  441.         mov     [IDE_controller_pointer], ecx
  442.         call    Init_IDE_ATA_controller_2
  443.         mov     ecx, IDE_controller_2
  444.         mov     [IDE_controller_pointer], ecx
  445.         call    Init_IDE_ATA_controller_2
  446.         mov     ecx, IDE_controller_3
  447.         mov     [IDE_controller_pointer], ecx
  448.         call    Init_IDE_ATA_controller_2
  449. ;-----------------------------------------------------------------------------
  450.