From 6be02440e2566d19955947953b3bb63f6dc9b783 Mon Sep 17 00:00:00 2001 From: aaron Date: Fri, 27 Oct 2017 04:10:58 +0000 Subject: [PATCH] git-svn-id: https://spexeah.com:8443/svn/Asuro@269 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c --- src/driver/AHCI.pas | 162 ++++++++++++++++++++++++-------------------- src/driver/PCI.pas | 36 +++++++--- src/kernel.pas | 6 -- 3 files changed, 114 insertions(+), 90 deletions(-) diff --git a/src/driver/AHCI.pas b/src/driver/AHCI.pas index 7f216e33..655763af 100644 --- a/src/driver/AHCI.pas +++ b/src/driver/AHCI.pas @@ -7,95 +7,107 @@ * Contributors: ************************************************ } - unit AHCI +unit AHCI - interface +interface - uses +uses system, util, - isr46; + isr46, + PCI, + drivertypes; - type +type - //Struct hell +//Struct hell - TFIS_Type = ( - REG_H2D, REG_D2H, - DMA_ACT, DMA_SETUP, - DATA, BIST, - PIO_SETUP, DEV_BITS - ); + TFIS_Type = ( + REG_H2D, REG_D2H, + DMA_ACT, DMA_SETUP, + DATA, BIST, + PIO_SETUP, DEV_BITS + ); - TFIS_REG_H2D bitpacked record - fis_type : uint8; - port_mult : UBit4; - rsv0 : UBit3; - coc : boolean; - command : uint8; - feature_low : uint8; - lba0 : uint8; - lba1 : uint8; - lba2 : uint8; - device : uint8; - lba3 : uint8; - lba4 : uint8; - lba5 : uint8; - feature_high : uint8; - count_low : uint8; - count_high : uint8; - icc : uint8; - control : uint8; - rsvl : uint32; - end; - - TFIS_REG_D2H bitpacked record - fis_type : uint8; - port_mult : UBit4; - rsv0 : UBit2; - i : boolean; - rsvl : boolean; - status : uint8; - error : uint8; - lba0 : uint8; - lba1 : uint8; - lba2 : uint8; - device : uint8; - lba3 : uint8; - lba4 : uint8; - lba5 : uint8; - rsv2 : uint8; - count_low : uint8; - count_high : uint8; - rsv3 : uint16; - rsv4 : uint32; - end; + TFIS_REG_H2D = bitpacked record + fis_type : uint8; + port_mult : UBit4; + rsv0 : UBit3; + coc : boolean; + command : uint8; + feature_low : uint8; + lba0 : uint8; + lba1 : uint8; + lba2 : uint8; + device : uint8; + lba3 : uint8; + lba4 : uint8; + lba5 : uint8; + feature_high : uint8; + count_low : uint8; + count_high : uint8; + icc : uint8; + control : uint8; + rsvl : uint32; + end; + + TFIS_REG_D2H = bitpacked record + fis_type : uint8; + port_mult : UBit4; + rsv0 : UBit2; + i : boolean; + rsvl : boolean; + status : uint8; + error : uint8; + lba0 : uint8; + lba1 : uint8; + lba2 : uint8; + device : uint8; + lba3 : uint8; + lba4 : uint8; + lba5 : uint8; + rsv2 : uint8; + count_low : uint8; + count_high : uint8; + rsv3 : uint16; + rsv4 : uint32; + end; - TFIS_Data bitpacked record - fis_type : uint8; - port_mult : UBit4; - rsv0 : UBit4; - rsv1 : uint16; - data : ^uint32; - end; + TFIS_Data = bitpacked record + fis_type : uint8; + port_mult : UBit4; + rsv0 : UBit4; + rsv1 : uint16; + data : ^uint32; + end; - TFIS_PIO_Setup bitpakced record - end; + TFIS_PIO_Setup bitpakced record + end; - TFIS_DMA_Setup bitpacked record - end; + TFIS_DMA_Setup bitpacked record + end; - THBA_Memory bitpacked record - end; + THBA_Memory bitpacked record + end; - THBA_Port bitpacked record - end; + THBA_Port bitpacked record + end; - THBA_FIS bitpacked record - end; + THBA_FIS bitpacked record + end; - var +var + PCI_Devices : array [0..31] of TPCI_Device; - implementation +procedure init(); - end. \ No newline at end of file +implementation + +procedure init(); +var + count : uint16; +begin + PCI_Devices := PCI.getDeviceInfo(1, 6, @count); +end; + +end. \ No newline at end of file diff --git a/src/driver/PCI.pas b/src/driver/PCI.pas index 9e43d58f..09509f24 100644 --- a/src/driver/PCI.pas +++ b/src/driver/PCI.pas @@ -18,6 +18,9 @@ uses ATA; type + + deviceArray = array[0..31] of TPCI_Device; + TPCI_Device_Bridge = bitpacked record device_id : uint16; vendor_id : uint16; @@ -63,12 +66,13 @@ var device_count : uint16; bus_count : uint8 = 1; + get_device_count : uint8; procedure init(); procedure scanBus(bus : uint8); function loadDeviceConfig(bus : uint8; slot : uint8; func : uint8) : boolean; -function getDeviceInfo(class_code : uint8; subclass_code : uint8) : TPCI_Device; //returns TPCI_DEVICE.vendor_id := 0xFFFF if no device found. -//TODO KEIRON HOW SHOULD I RETUNR MULTIPLE DEVICE IN A NICE WAY +function getDeviceInfo(class_code : uint8; subclass_code : uint8; count : intptr) : deviceArray; //(Will in future)returns TPCI_DEVICE.vendor_id := 0xFFFF if no device found. + implementation procedure init(); @@ -78,8 +82,6 @@ begin console.writestringln('PCI: INIT BEGIN.'); console.writestringln('PCI: Scanning Bus: 0'); scanBus(0); - scanbus(1); - scanbus(2); //while unscanned busses scan busses current_bus := 1; @@ -292,18 +294,34 @@ begin console.writestring(' '); console.writehex(device.device_id); console.writestring(' '); - console.writehex(device.vendor_id); - console.writestring(' '); console.writehex(device.class_code); console.writestring(' '); - console.writehexln(device.subclass_class); + console.writehex(device.subclass_class); + console.writestring(' '); + console.writehexln(device.prog_if); devices[device_count] := device; device_count := device_count + 1; + + //if device.class_code = 1 then ata.init(device); end; -function getDeviceInfo(class_code : uint8; subclass_code : uint8) : TPCI_Device; -begin end; +function getDeviceInfo(class_code : uint8; subclass_code : uint8; count : intptr) : deviceArray; +var + i : uint16; + devices_out : array[0..31] of TPCI_Device; +begin + count^ := 0; + for i:=0 to device_count do begin + if (devices[i].class_code = class_code) and (devices[i].subclass_class = subclass_code) then begin + devices_out[i] := devices[i]; //prog_if + count^ := count^ + 1; + end; + end; + + getDeviceInfo := devices_out; + +end; end. \ No newline at end of file diff --git a/src/kernel.pas b/src/kernel.pas index c1bb5817..bbf3e758 100644 --- a/src/kernel.pas +++ b/src/kernel.pas @@ -118,12 +118,6 @@ begin mouse.init(); console.writestringln('DRIVERS: INIT END.'); - //temp := 8294; - //ata.write(uint32(@temp), 10, 4); - //temp := 1234; - //ata.read(uint32(@temp), 10, 4); - //console.writeintln(temp); - console.writestringln(''); console.setdefaultattribute(console.combinecolors(Green, Black)); console.writestringln('Asuro Booted Correctly!');