duskos

dusk os fork
git clone git://git.alexwennerberg.com/duskos
Log | Files | Refs | README | LICENSE

commit a33b782973b52f099b08f8f28aa587631d55b8fe
parent 1475ca63cc81a04a58953072d9775062aab3f6cf
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Mon, 17 Oct 2022 17:29:55 -0400

drv/pc/ahci: first steps

To try in QEMU, run with "-machine q35". At prompt, do "ahci$ .ahci"

Diffstat:
Afs/drv/pc/ahci.fs | 75+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mfs/xcomp/pc/init.fs | 4+++-
2 files changed, 78 insertions(+), 1 deletion(-)

diff --git a/fs/drv/pc/ahci.fs b/fs/drv/pc/ahci.fs @@ -0,0 +1,75 @@ +\ AHCI driver +?f<< /drv/pc/pci.fs + +struct[ HBAPort + sfield clb + sfield clbu + sfield fb + sfield fbu + sfield is + sfield ie + sfield cmd + CELLSZ sallot \ reserved + sfield tfd + sfield sig + sfield ssts + sfield sctl + sfield serr + sfield sact + sfield ci + sfield sntf + sfield fbs + 11 CELLSZ * sallot \ reserved + 4 CELLSZ * sfield' vendor +]struct + +struct[ HBAMem + sfield cap + sfield ghc + sfield is + sfield pi + sfield vs + sfield ccc_ctl + sfield ccc_pts + sfield em_loc + sfield em_ctl + sfield cap2 + sfield bohc + $a0 SZ - sallot \ reserved + $100 SZ - sfield' vendor + HBAPort SZ 32 * sfield' ports +]struct + +0 structbind HBAMem hba + +\ Search PCI bus for a AHCI controller and if found, bind "hba" to its BAR5 +\ value. +: ahci$ + \ For now, we only search bus 0 + 0 >r 0 >r begin \ V1=slot V2=func + V1 $20 < while + 0 V1 V2 pcisel if + pci.class 1 = pci.subclass 6 = and if pci0.bar5 ['] hba rebind then then + 1 to+ V2 V2 8 = if 0 to V2 1 to+ V1 then repeat rfree ; + +\ Do we have a AHCI controller? +: ahci? hba :self bool ; + +: sigstr ( sig -- str ) case + $101 of = S" ATA" endof + $eb140101 of = S" ATAPI" endof + $c33c0101 of = S" bridge" endof + $96690101 of = S" multiplier" endof + S" unknown" endcase ; + +: .ahci + ahci? not if abort" No AHCI controller" then + ." HBA addr: " hba :self .x nl> + ." Ports implemented: " hba pi .x nl> + $20 >r hba pi 0 begin ( pi id ) + 2dup bit? if + hba ports over HBAPort SZ * + dup HBAPort ssts $0f0f and $0103 = if + ( pi id port ) \ detected and active + ." Device " over . ." type: " HBAPort sig sigstr stype nl> + else drop then then + ( pi id ) 1+ next ; diff --git a/fs/xcomp/pc/init.fs b/fs/xcomp/pc/init.fs @@ -11,12 +11,14 @@ f<< /drv/pc/vga.fs f<< /sys/grid.fs ' (emit) to emit +f<< /drv/pc/pci.fs f<< /drv/pc/ata.fs ATA0:0 ATADrive :identify $c0 and $40 = [if] + ." Using ATA driver...\n" ATADrive :reset drop ATA0:0 bootfs to Filesystem drv [then] +f<< /drv/pc/ahci.fs f<< /fs/fat.fs -f<< /drv/pc/pci.fs f<< /drv/pc/ps28042.fs f<< /sys/ps2.fs