Subversion Repositories Kolibri OS

Rev

Rev 9023 | Rev 9037 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9023 Rev 9024
Line 108... Line 108...
108
        movzx   edx, byte [esi+PCIDEV.devfn]
108
        movzx   edx, byte [esi+PCIDEV.devfn]
109
        and     edx, 00000111b ; get only 3 lowest bits (function code)
109
        and     edx, 00000111b ; get only 3 lowest bits (function code)
110
        DEBUGF  1, "K: found AHCI controller, (class, subcl, progif) = %x, bus = %x, device = %x, function = %x\n", eax, ebx, ecx, edx
110
        DEBUGF  1, "K: found AHCI controller, (class, subcl, progif) = %x, bus = %x, device = %x, function = %x\n", eax, ebx, ecx, edx
Line 111... Line 111...
111
        
111
        
112
        ; get BAR5 value, it is physical address 
112
        ; get BAR5 value, it is physical address 
113
        mov     ah, [esi + PCIDEV.bus]
-
 
114
        mov     al, 2 ; read dword
113
        movzx   eax, [esi + PCIDEV.bus]
115
        mov     bh, [esi + PCIDEV.devfn]
114
        movzx   ebx, [esi + PCIDEV.devfn]
116
        mov     bl, PCI_REG_BAR5
-
 
117
        call    pci_read_reg
115
        stdcall pci_read32, eax, ebx, PCI_REG_BAR5
Line 118... Line 116...
118
        DEBUGF  1, "K: AHCI controller BAR5 = %x\n", eax
116
        DEBUGF  1, "K: AHCI controller BAR5 = %x\n", eax
119
 
117
 
120
        ; Map BAR5 to virtual memory
118
        ; Map BAR5 to virtual memory
121
        stdcall map_io_mem, eax, HBA_MEMORY_SIZE, PG_SWR + PG_NOCACHE
119
        stdcall map_io_mem, eax, HBA_MEMORY_SIZE, PG_SWR + PG_NOCACHE
Line 122... Line 120...
122
        mov     [ahci_controller + AHCI_DATA.abar], eax
120
        mov     [ahci_controller + AHCI_DATA.abar], eax
123
        DEBUGF  1, "K: AHCI controller BAR5 mapped to virtual addr %x\n", eax
121
        DEBUGF  1, "K: AHCI controller BAR5 mapped to virtual addr %x\n", eax
124
 
122
 
125
        ; Enable dma bus mastering, memory space access, clear the "disable interrupts" bit
-
 
126
        ; Usually, it is already done before us
123
        ; Enable dma bus mastering, memory space access, clear the "disable interrupts" bit
127
        mov     ah, [esi + PCIDEV.bus]
124
        ; Usually, it is already done before us
128
        mov     al, 2 ; read dword
-
 
129
        mov     bh, [esi + PCIDEV.devfn]
125
        movzx   ebx, [esi + PCIDEV.bus]
130
        mov     bl, PCI_REG_STATUS_COMMAND
126
        movzx   ebp, [esi + PCIDEV.devfn]
131
        call    pci_read_reg
127
        stdcall pci_read32, ebx, ebp, PCI_REG_STATUS_COMMAND
132
        DEBUGF  1, "K: AHCI: pci_status_command = %x\nEnabling interrupts, DMA bus mastering and memory space access\n", eax
128
        DEBUGF  1, "K: AHCI: pci_status_command = %x\nEnabling interrupts, DMA bus mastering and memory space access\n", eax
133
        or      eax, 0x06 ; pci.command |= 0x06 (dma bus mastering + memory space access)
-
 
134
        btr     eax, 10 ; clear the "disable interrupts" bit
-
 
135
        DEBUGF  1, "K: AHCI: pci_status_command = %x\n", eax
-
 
136
        mov     ecx, eax
-
 
137
        mov     ah, [esi + PCIDEV.bus]
129
        or      eax, 0x06 ; pci.command |= 0x06 (dma bus mastering + memory space access)
138
        mov     al, 2 ; write dword
-
 
Line 139... Line 130...
139
        mov     bh, [esi + PCIDEV.devfn]
130
        btr     eax, 10 ; clear the "disable interrupts" bit
140
        mov     bl, PCI_REG_STATUS_COMMAND
131
        DEBUGF  1, "K: AHCI: pci_status_command = %x\n", eax
141
        call    pci_write_reg
-
 
142
 
-
 
143
        ; ; Print some register values to debug board
-
 
144
        ; mov     esi, [ahci_controller + AHCI_DATA.abar]
132
        stdcall pci_write32, ebx, ebp, PCI_REG_STATUS_COMMAND, eax
Line 145... Line 133...
145
        ; mov     ebx, [esi + HBA_MEM.capability]
133
 
146
        ; mov     ecx, [esi + HBA_MEM.global_host_control]
134
        ; ; Print some register values to debug board
147
        ; mov     edx, [esi + HBA_MEM.version]
135
        ; mov     esi, [ahci_controller + AHCI_DATA.abar]
148
        ; DEBUGF  1, "K: AHCI: HBA.cap = %x, HBA.ghc = %x, HBA_MEM.version = %x\n", ebx, ecx, edx
136
        ; DEBUGF  1, "K: AHCI: HBA.cap = %x, HBA.ghc = %x, HBA_MEM.version = %x\n", [esi + HBA_MEM.capability], [esi + HBA_MEM.global_host_control], [esi + HBA_MEM.version]
149
 
137
 
150
        ;-------------------------------------------------------
138
        ;-------------------------------------------------------
151
        ; Request BIOS/OS ownership handoff, if supported. (TODO check correctness)
139
        ; Request BIOS/OS ownership handoff, if supported. (TODO check correctness)
152
        mov     esi, [ahci_controller + AHCI_DATA.abar]
140
        mov     esi, [ahci_controller + AHCI_DATA.abar]
153
        ;mov     ebx, [esi + HBA_MEM.capability2]
141
        ;mov     ebx, [esi + HBA_MEM.capability2]
Line 154... Line 142...
154
        ;DEBUGF  1, "K: AHCI: HBA_MEM.cap2 = %x\n", ebx
142
        ;DEBUGF  1, "K: AHCI: HBA_MEM.cap2 = %x\n", ebx
155
        bt      dword [esi + HBA_MEM.capability2], bit_AHCI_HBA_CAP2_BOH
143
        bt      [esi + HBA_MEM.capability2], bit_AHCI_HBA_CAP2_BOH
156
        jnc     .end_handoff
144
        jnc     .end_handoff
Line 157... Line 145...
157
        DEBUGF  1, "K: AHCI: requesting AHCI ownership change...\n"
145
        DEBUGF  1, "K: AHCI: requesting AHCI ownership change...\n"
158
        bts     dword [esi + HBA_MEM.bohc], bit_AHCI_HBA_BOHC_OOS
146
        bts     [esi + HBA_MEM.bohc], bit_AHCI_HBA_BOHC_OOS
Line 159... Line 147...
159
 
147
 
160
.wait_not_bos:
148
.wait_not_bos:
161
        bt      dword [esi + HBA_MEM.bohc], bit_AHCI_HBA_BOHC_BOS
149
        bt      [esi + HBA_MEM.bohc], bit_AHCI_HBA_BOHC_BOS
Line 162... Line 150...
162
        jc      .wait_not_bos
150
        jc      .wait_not_bos
163
 
151
 
164
        mov     ebx, 3
152
        mov     ebx, 3
Line 175... Line 163...
175
 
163
 
176
.end_handoff:
164
.end_handoff:
Line 177... Line 165...
177
        ;-------------------------------------------------------
165
        ;-------------------------------------------------------
178
 
166
 
179
        ; enable the AHCI and reset it
167
        ; enable the AHCI and reset it
Line 180... Line 168...
180
        bts     dword [esi + HBA_MEM.global_host_control], bit_AHCI_HBA_GHC_AHCI_ENABLE
168
        bts     [esi + HBA_MEM.global_host_control], bit_AHCI_HBA_GHC_AHCI_ENABLE
181
        bts     dword [esi + HBA_MEM.global_host_control], bit_AHCI_HBA_GHC_RESET
169
        bts     [esi + HBA_MEM.global_host_control], bit_AHCI_HBA_GHC_RESET
182
 
170
 
183
        ; wait for reset to complete
171
        ; wait for reset to complete
Line 184... Line 172...
184
.wait_reset:
172
.wait_reset:
185
        bt      dword [esi + HBA_MEM.global_host_control], bit_AHCI_HBA_GHC_RESET
173
        bt      [esi + HBA_MEM.global_host_control], bit_AHCI_HBA_GHC_RESET
186
        jc      .wait_reset
174
        jc      .wait_reset
187
 
175
 
188
        ; enable the AHCI and interrupts
176
        ; enable the AHCI and interrupts
189
        bts     dword [esi + HBA_MEM.global_host_control], bit_AHCI_HBA_GHC_AHCI_ENABLE
-
 
190
        bts     dword [esi + HBA_MEM.global_host_control], bit_AHCI_HBA_GHC_INTERRUPT_ENABLE
-
 
191
        mov     ebx, 2
-
 
192
        call    delay_hs
-
 
Line 193... Line 177...
193
        mov     ebx, [esi + HBA_MEM.capability]
177
        bts     [esi + HBA_MEM.global_host_control], bit_AHCI_HBA_GHC_AHCI_ENABLE
Line 194... Line 178...
194
        mov     ecx, [esi + HBA_MEM.capability2]
178
        bts     [esi + HBA_MEM.global_host_control], bit_AHCI_HBA_GHC_INTERRUPT_ENABLE
Line 195... Line -...
195
        mov     edx, [esi + HBA_MEM.version]
-
 
196
        mov     edi, [esi + HBA_MEM.global_host_control]
-
 
197
        
-
 
198
        DEBUGF  1, "K: AHCI: caps: %x %x, ver: %x, ghc: %x\n", ebx, ecx, edx, edi
-
 
199
 
-