Rev 9131 | Rev 9135 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 9131 | Rev 9134 | ||
---|---|---|---|
Line 8... | Line 8... | ||
8 | $Revision$ |
8 | $Revision$ |
Line 9... | Line 9... | ||
9 | 9 | ||
10 | PCI_REG_STATUS_COMMAND = 0x0004 |
10 | PCI_REG_STATUS_COMMAND = 0x0004 |
Line -... | Line 11... | ||
- | 11 | PCI_REG_BAR5 = 0x0024 |
|
- | 12 | ||
- | 13 | ; different SATA device signatures |
|
- | 14 | SATA_SIG_ATA = 0x00000101 ; SATA drive |
|
- | 15 | SATA_SIG_ATAPI = 0xEB140101 ; SATAPI drive |
|
- | 16 | SATA_SIG_SEMB = 0xC33C0101 ; Enclosure management bridge |
|
- | 17 | SATA_SIG_PM = 0x96690101 ; Port multiplier |
|
- | 18 | ||
- | 19 | ; Device type constants |
|
- | 20 | AHCI_DEV_NULL = 0 |
|
- | 21 | AHCI_DEV_SATA = 1 |
|
- | 22 | AHCI_DEV_SEMB = 2 |
|
- | 23 | AHCI_DEV_PM = 3 |
|
- | 24 | AHCI_DEV_SATAPI = 4 |
|
- | 25 | ||
- | 26 | ; ATA commands |
|
- | 27 | ATA_IDENTIFY = 0xEC |
|
- | 28 | ||
- | 29 | ; ATAPI commands |
|
11 | PCI_REG_BAR5 = 0x0024 |
30 | ATAPI_IDENTIFY = 0xA1 |
12 | 31 | ||
13 | ; bit_ prefix means that its index of bit |
32 | ; bit_ prefix means that its index of bit |
Line 14... | Line 33... | ||
14 | ; format: bit_AHCI_STR_REG_BIT |
33 | ; format: bit_AHCI_STR_REG_BIT |
Line 134... | Line 153... | ||
134 | clb dd ? ; Command list base |
153 | clb dd ? ; Command list base |
135 | fb dd ? ; FIS base |
154 | fb dd ? ; FIS base |
136 | ctba_arr rd 32 ; ctba_arr[0] = clb[0].ctba, ... and so on. |
155 | ctba_arr rd 32 ; ctba_arr[0] = clb[0].ctba, ... and so on. |
137 | port dd ? ; address of correspoding HBA_PORT structure |
156 | port dd ? ; address of correspoding HBA_PORT structure |
138 | portno dd ? ; port index, 0..31 |
157 | portno dd ? ; port index, 0..31 |
- | 158 | drive_type db ? ; drive type |
|
139 | ends |
159 | ends |
Line 140... | Line 160... | ||
140 | 160 | ||
141 | ; Register FIS – Host to Device |
161 | ; Register FIS – Host to Device |
142 | struct FIS_REG_H2D |
162 | struct FIS_REG_H2D |
Line 449... | Line 469... | ||
449 | ; Sleep(10); |
469 | ; Sleep(10); |
450 | ; } |
470 | ; } |
451 | ; rewritten to: |
471 | ; rewritten to: |
452 | bt [esi + HBA_MEM.cap], 27 ; check Supports Staggered Spin-up bit in capabilities |
472 | bt [esi + HBA_MEM.cap], 27 ; check Supports Staggered Spin-up bit in capabilities |
453 | jnc @f |
473 | jnc @f |
454 | DEBUGF 1, "Supports Staggered Spin-up\n" |
474 | DEBUGF 1, "Supports Staggered Spin-up, spinning up the port..\n" |
455 | or [edi + HBA_PORT.command], (0x0002 or 0x0004 or 0x10000000) |
475 | or [edi + HBA_PORT.command], (0x0002 or 0x0004 or 0x10000000) |
456 | push ebx |
476 | push ebx |
457 | mov ebx, 1 ; wait 10 ms |
477 | mov ebx, 1 ; wait 10 ms |
458 | call delay_hs |
478 | call delay_hs |
459 | pop ebx |
479 | pop ebx |
Line 473... | Line 493... | ||
473 | mov ecx, [edi + HBA_PORT.sata_status] |
493 | mov ecx, [edi + HBA_PORT.sata_status] |
474 | and ecx, AHCI_HBA_PxSSTS_DET |
494 | and ecx, AHCI_HBA_PxSSTS_DET |
475 | cmp ecx, AHCI_HBA_PxSSTS_DET_PRESENT |
495 | cmp ecx, AHCI_HBA_PxSSTS_DET_PRESENT |
476 | jne .continue_detect_drives |
496 | jne .continue_detect_drives |
Line 477... | Line 497... | ||
477 | 497 | ||
Line 478... | Line 498... | ||
478 | DEBUGF 1, "K: AHCI: found drive at port %d, cmd = 0x%x, ssts = 0x%x, signature = 0x%x\n", ebx, [edi + HBA_PORT.command], [edi + HBA_PORT.sata_status], [edi + HBA_PORT.signature] |
498 | ; DEBUGF 1, "K: AHCI: found drive at port %d, cmd = 0x%x, ssts = 0x%x, signature = 0x%x\n", ebx, [edi + HBA_PORT.command], [edi + HBA_PORT.sata_status], [edi + HBA_PORT.signature] |
479 | 499 | ||
480 | mov ecx, ebx |
500 | mov ecx, ebx |
481 | imul ecx, sizeof.PORT_DATA |
501 | imul ecx, sizeof.PORT_DATA |
Line -... | Line 502... | ||
- | 502 | add ecx, port_data_arr |
|
- | 503 | stdcall ahci_port_rebase, edi, ebx, ecx |
|
- | 504 | ||
- | 505 | ; DEBUGF 1, "K: AHCI: After REBASING, signature = 0x%x\n", [edi + HBA_PORT.signature] |
|
- | 506 | ||
- | 507 | .switch_sig: |
|
- | 508 | cmp [edi + HBA_PORT.signature], SATA_SIG_ATA |
|
- | 509 | jne @f |
|
- | 510 | mov [ecx + PORT_DATA.drive_type], AHCI_DEV_SATA |
|
- | 511 | jmp .end_switch_sig |
|
- | 512 | @@: |
|
- | 513 | cmp [edi + HBA_PORT.signature], SATA_SIG_ATAPI |
|
- | 514 | jne @f |
|
- | 515 | mov [ecx + PORT_DATA.drive_type], AHCI_DEV_SATAPI |
|
- | 516 | jmp .end_switch_sig |
|
- | 517 | @@: |
|
- | 518 | cmp [edi + HBA_PORT.signature], SATA_SIG_SEMB |
|
- | 519 | jne @f |
|
- | 520 | mov [ecx + PORT_DATA.drive_type], AHCI_DEV_SEMB |
|
- | 521 | jmp .end_switch_sig |
|
- | 522 | @@: |
|
- | 523 | cmp [edi + HBA_PORT.signature], SATA_SIG_PM |
|
- | 524 | jne @f |
|
- | 525 | mov [ecx + PORT_DATA.drive_type], AHCI_DEV_PM |
|
- | 526 | jmp .end_switch_sig |
|
- | 527 | @@: |
|
- | 528 | DEBUGF 1, "Unknown device signature\n" |
|
- | 529 | .end_switch_sig: |
|
482 | add ecx, port_data_arr |
530 | |
Line 483... | Line 531... | ||
483 | stdcall ahci_port_rebase, edi, ebx, ecx |
531 | DEBUGF 1, "K: AHCI: found drive on port %u: TYPE = %u\n", ebx, [ecx + PORT_DATA.drive_type] |
484 | 532 | ||
485 | stdcall ahci_port_identify, ecx |
533 | stdcall ahci_port_identify, ecx |
Line 521... | Line 569... | ||
521 | 569 | ||
Line 522... | Line 570... | ||
522 | DEBUGF 1, "No free cmdslot on port %u\n", [esi + PORT_DATA.portno] |
570 | DEBUGF 1, "No free cmdslot on port %u\n", [esi + PORT_DATA.portno] |
523 | 571 | ||
524 | .cmdslot_found: |
572 | .cmdslot_found: |
Line 525... | Line 573... | ||
525 | mov [cmdslot], eax |
573 | mov [cmdslot], eax |
526 | DEBUGF 1, "Found free cmdslot %u on port %u\n", [cmdslot], [esi + PORT_DATA.portno] |
574 | ; DEBUGF 1, "Found free cmdslot %u on port %u\n", [cmdslot], [esi + PORT_DATA.portno] |
527 | 575 | ||
528 | shl eax, BSF sizeof.HBA_CMD_HDR |
576 | shl eax, BSF sizeof.HBA_CMD_HDR |
Line 562... | Line 610... | ||
562 | mov eax, [cmdtable] |
610 | mov eax, [cmdtable] |
563 | mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.fis_type], FIS_TYPE_REG_H2D |
611 | mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.fis_type], FIS_TYPE_REG_H2D |
564 | movzx ebx, byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.flags] |
612 | movzx ebx, byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.flags] |
565 | bts ebx, bit_AHCI_H2D_FLAG_CMD ; Set Command bit in H2D FIS. |
613 | bts ebx, bit_AHCI_H2D_FLAG_CMD ; Set Command bit in H2D FIS. |
566 | mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.flags], bl |
614 | mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.flags], bl |
- | 615 | ||
567 | ; if (port->signature == AHCI_PxSIG_ATAPI) cmd_fis->command = ATA_IDENTIFY_PACKET; |
616 | mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.command], ATA_IDENTIFY |
568 | ; else cmd_fis->command = ATA_IDENTIFY; |
617 | cmp [esi + PORT_DATA.drive_type], AHCI_DEV_SATAPI |
- | 618 | jne @f |
|
569 | mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.command], 0xEC ;ATA_IDENTIFY ; |
619 | mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.command], ATAPI_IDENTIFY |
- | 620 | @@: |
|
570 | mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.device], 0 |
621 | mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.device], 0 |
Line 571... | Line 622... | ||
571 | 622 | ||
572 | ; TODO Wait on previous command to complete. AHCIPortWait(bd->port_num, tS + 2); |
623 | ; TODO Wait on previous command to complete. AHCIPortWait(bd->port_num, tS + 2); |
573 | mov ebx, 20 ;;; |
624 | mov ebx, 20 ;;; |
Line 578... | Line 629... | ||
578 | 629 | ||
579 | ; TODO AHCIPortCmdWait(bd->port_num, cmd_slot); |
630 | ; TODO AHCIPortCmdWait(bd->port_num, cmd_slot); |
580 | mov ebx, 20 ;;; |
631 | mov ebx, 20 ;;; |
Line 581... | Line 632... | ||
581 | call delay_hs ;;; |
632 | call delay_hs ;;; |
Line 582... | Line 633... | ||
582 | 633 | ||
583 | DEBUGF 1, "sata_error register = 0x%x\n", [edi + HBA_PORT.sata_error] |
634 | ; DEBUGF 1, "sata_error register = 0x%x\n", [edi + HBA_PORT.sata_error] |
584 | 635 | ||
585 | ; mov ecx, ecx |
636 | ; mov ecx, ecx |
Line 596... | Line 647... | ||
596 | ; inc ecx |
647 | ; inc ecx |
597 | ; jmp .print_ident |
648 | ; jmp .print_ident |
598 | ; .end_print_ident: |
649 | ; .end_print_ident: |
599 | ; DEBUGF 1, "\n" |
650 | ; DEBUGF 1, "\n" |
Line -... | Line 651... | ||
- | 651 | ||
- | 652 | ; DEBUGF 1, "after identification: signature = 0x%x\n", [edi + HBA_PORT.signature] |
|
600 | 653 | ||
601 | mov esi, [buf_virt] |
654 | mov esi, [buf_virt] |
602 | add esi, 27*2 |
655 | add esi, 27*2 |
603 | mov edi, modelstr |
656 | mov edi, modelstr |
604 | mov ecx, ((46-27)+1)*2 |
657 | mov ecx, ((46-27)+1)*2 |
Line 622... | Line 675... | ||
622 | .ret: |
675 | .ret: |
623 | popad |
676 | popad |
624 | ret |
677 | ret |
625 | endp |
678 | endp |
Line -... | Line 679... | ||
- | 679 | ||
626 | 680 | ||
627 | ; Start command engine |
681 | ; Start command engine |
628 | ; in: eax - address of HBA_PORT structure |
682 | ; in: eax - address of HBA_PORT structure |
629 | ahci_start_cmd: |
683 | ahci_start_cmd: |
630 | .wait_cr: ; Wait until CR (bit15) is cleared |
684 | .wait_cr: ; Wait until CR (bit15) is cleared |
Line 795... | Line 849... | ||
795 | 849 | ||
796 | mov esi, [ahci_controller + AHCI_DATA.abar] |
850 | mov esi, [ahci_controller + AHCI_DATA.abar] |
797 | mov edx, [esi + HBA_MEM.cap] |
851 | mov edx, [esi + HBA_MEM.cap] |
798 | shr edx, 8 |
852 | shr edx, 8 |
799 | and edx, 0xf |
853 | and edx, 0xf |
800 | DEBUGF 1, "Number of Command Slots on each port = %u\n", edx |
854 | ; DEBUGF 1, "Number of Command Slots on each port = %u\n", edx |
801 | xor ecx, ecx |
855 | xor ecx, ecx |
802 | .for1: |
856 | .for1: |
803 | cmp ecx, edx |
857 | cmp ecx, edx |