diff --git a/src/include/hardDrive.h b/src/include/hardDrive.h index 00ada36..e8a04d3 100644 --- a/src/include/hardDrive.h +++ b/src/include/hardDrive.h @@ -1,30 +1,6 @@ #ifndef HARD_DRIVE_H #define HARD_DRIVE_H -#define IDE_DATA_REGISTER 0 -#define IDE_ERROR_REGISTER 1 -#define IDE_SECTOR_COUNT_REGISTER 2 -#define IDE_SECTOR_NUMBER_REGISTER 3 -#define IDE_CYLINDER_LOW_REGISTER 4 -#define IDE_CYLINDER_HIGH_REGISTER 5 -// sector size, drive, head -#define IDE_SDH_REGISTER 6 -#define IDE_STATUS_REGISTER 7 -#define IDE_COMMAND_REGISTER 7 -#define IDE_ALTERNATE_STATUS_CONTROL_REGISTER 0 -#define IDE_DRIVE_ADDRESS_CONTROL_REGISTER 1 - -#define IDE_STATUS_BUSY 0x80 -#define IDE_STATUS_READY 0x40 -#define IDE_STATUS_WRITE_FAULT 0x20 -#define IDE_STATUS_SEEK_COMPLETE 0x10 -#define IDE_STATUS_DATA_REQUEST 0x08 -#define IDE_STATUS_CORRECTED_DATA 0x04 -#define IDE_STATUS_INDEX 0x02 -#define IDE_STATUS_ERROR 0x01 - -#define IDE_IDENTIFY_COMMAND 0xEC - #include #include #include @@ -37,7 +13,8 @@ // todo: mount point } HardDrive; -extern void initializeIDEDrive(PciDevice *, ListElement **); +extern void initializeIdeController(PciDevice *, ListElement **); +extern void initializeSataController(PciDevice *, ListElement **); extern void scanHardDrives(); diff --git a/src/include/hardDrive.h b/src/include/hardDrive.h index 00ada36..e8a04d3 100644 --- a/src/include/hardDrive.h +++ b/src/include/hardDrive.h @@ -1,30 +1,6 @@ #ifndef HARD_DRIVE_H #define HARD_DRIVE_H -#define IDE_DATA_REGISTER 0 -#define IDE_ERROR_REGISTER 1 -#define IDE_SECTOR_COUNT_REGISTER 2 -#define IDE_SECTOR_NUMBER_REGISTER 3 -#define IDE_CYLINDER_LOW_REGISTER 4 -#define IDE_CYLINDER_HIGH_REGISTER 5 -// sector size, drive, head -#define IDE_SDH_REGISTER 6 -#define IDE_STATUS_REGISTER 7 -#define IDE_COMMAND_REGISTER 7 -#define IDE_ALTERNATE_STATUS_CONTROL_REGISTER 0 -#define IDE_DRIVE_ADDRESS_CONTROL_REGISTER 1 - -#define IDE_STATUS_BUSY 0x80 -#define IDE_STATUS_READY 0x40 -#define IDE_STATUS_WRITE_FAULT 0x20 -#define IDE_STATUS_SEEK_COMPLETE 0x10 -#define IDE_STATUS_DATA_REQUEST 0x08 -#define IDE_STATUS_CORRECTED_DATA 0x04 -#define IDE_STATUS_INDEX 0x02 -#define IDE_STATUS_ERROR 0x01 - -#define IDE_IDENTIFY_COMMAND 0xEC - #include #include #include @@ -37,7 +13,8 @@ // todo: mount point } HardDrive; -extern void initializeIDEDrive(PciDevice *, ListElement **); +extern void initializeIdeController(PciDevice *, ListElement **); +extern void initializeSataController(PciDevice *, ListElement **); extern void scanHardDrives(); diff --git a/src/kernel/drivers/pci/hardDrive/ataDrive.c b/src/kernel/drivers/pci/hardDrive/ataDrive.c deleted file mode 100644 index e69de29..0000000 --- a/src/kernel/drivers/pci/hardDrive/ataDrive.c +++ /dev/null diff --git a/src/include/hardDrive.h b/src/include/hardDrive.h index 00ada36..e8a04d3 100644 --- a/src/include/hardDrive.h +++ b/src/include/hardDrive.h @@ -1,30 +1,6 @@ #ifndef HARD_DRIVE_H #define HARD_DRIVE_H -#define IDE_DATA_REGISTER 0 -#define IDE_ERROR_REGISTER 1 -#define IDE_SECTOR_COUNT_REGISTER 2 -#define IDE_SECTOR_NUMBER_REGISTER 3 -#define IDE_CYLINDER_LOW_REGISTER 4 -#define IDE_CYLINDER_HIGH_REGISTER 5 -// sector size, drive, head -#define IDE_SDH_REGISTER 6 -#define IDE_STATUS_REGISTER 7 -#define IDE_COMMAND_REGISTER 7 -#define IDE_ALTERNATE_STATUS_CONTROL_REGISTER 0 -#define IDE_DRIVE_ADDRESS_CONTROL_REGISTER 1 - -#define IDE_STATUS_BUSY 0x80 -#define IDE_STATUS_READY 0x40 -#define IDE_STATUS_WRITE_FAULT 0x20 -#define IDE_STATUS_SEEK_COMPLETE 0x10 -#define IDE_STATUS_DATA_REQUEST 0x08 -#define IDE_STATUS_CORRECTED_DATA 0x04 -#define IDE_STATUS_INDEX 0x02 -#define IDE_STATUS_ERROR 0x01 - -#define IDE_IDENTIFY_COMMAND 0xEC - #include #include #include @@ -37,7 +13,8 @@ // todo: mount point } HardDrive; -extern void initializeIDEDrive(PciDevice *, ListElement **); +extern void initializeIdeController(PciDevice *, ListElement **); +extern void initializeSataController(PciDevice *, ListElement **); extern void scanHardDrives(); diff --git a/src/kernel/drivers/pci/hardDrive/ataDrive.c b/src/kernel/drivers/pci/hardDrive/ataDrive.c deleted file mode 100644 index e69de29..0000000 --- a/src/kernel/drivers/pci/hardDrive/ataDrive.c +++ /dev/null diff --git a/src/kernel/drivers/pci/hardDrive/hardDrive.c b/src/kernel/drivers/pci/hardDrive/hardDrive.c index 3adaea3..ecb1a2f 100644 --- a/src/kernel/drivers/pci/hardDrive/hardDrive.c +++ b/src/kernel/drivers/pci/hardDrive/hardDrive.c @@ -3,12 +3,6 @@ #include #include #include -#include -#include - -void initializeSATADrive(PciDevice *pciDevice) { - // todo -} void scanHardDrives() { ListElement *drives = NULL; @@ -20,12 +14,10 @@ } switch (pciDevice->subclass) { case 1: - initializeIDEDrive(pciDevice, &drives); + initializeIdeController(pciDevice, &drives); break; case 6: - printf("found a SATA-controller: %i:%i:%i\n", pciDevice->bus, - pciDevice->device, pciDevice->function); - initializeSATADrive(pciDevice); + initializeSataController(pciDevice, &drives); break; } } diff --git a/src/include/hardDrive.h b/src/include/hardDrive.h index 00ada36..e8a04d3 100644 --- a/src/include/hardDrive.h +++ b/src/include/hardDrive.h @@ -1,30 +1,6 @@ #ifndef HARD_DRIVE_H #define HARD_DRIVE_H -#define IDE_DATA_REGISTER 0 -#define IDE_ERROR_REGISTER 1 -#define IDE_SECTOR_COUNT_REGISTER 2 -#define IDE_SECTOR_NUMBER_REGISTER 3 -#define IDE_CYLINDER_LOW_REGISTER 4 -#define IDE_CYLINDER_HIGH_REGISTER 5 -// sector size, drive, head -#define IDE_SDH_REGISTER 6 -#define IDE_STATUS_REGISTER 7 -#define IDE_COMMAND_REGISTER 7 -#define IDE_ALTERNATE_STATUS_CONTROL_REGISTER 0 -#define IDE_DRIVE_ADDRESS_CONTROL_REGISTER 1 - -#define IDE_STATUS_BUSY 0x80 -#define IDE_STATUS_READY 0x40 -#define IDE_STATUS_WRITE_FAULT 0x20 -#define IDE_STATUS_SEEK_COMPLETE 0x10 -#define IDE_STATUS_DATA_REQUEST 0x08 -#define IDE_STATUS_CORRECTED_DATA 0x04 -#define IDE_STATUS_INDEX 0x02 -#define IDE_STATUS_ERROR 0x01 - -#define IDE_IDENTIFY_COMMAND 0xEC - #include #include #include @@ -37,7 +13,8 @@ // todo: mount point } HardDrive; -extern void initializeIDEDrive(PciDevice *, ListElement **); +extern void initializeIdeController(PciDevice *, ListElement **); +extern void initializeSataController(PciDevice *, ListElement **); extern void scanHardDrives(); diff --git a/src/kernel/drivers/pci/hardDrive/ataDrive.c b/src/kernel/drivers/pci/hardDrive/ataDrive.c deleted file mode 100644 index e69de29..0000000 --- a/src/kernel/drivers/pci/hardDrive/ataDrive.c +++ /dev/null diff --git a/src/kernel/drivers/pci/hardDrive/hardDrive.c b/src/kernel/drivers/pci/hardDrive/hardDrive.c index 3adaea3..ecb1a2f 100644 --- a/src/kernel/drivers/pci/hardDrive/hardDrive.c +++ b/src/kernel/drivers/pci/hardDrive/hardDrive.c @@ -3,12 +3,6 @@ #include #include #include -#include -#include - -void initializeSATADrive(PciDevice *pciDevice) { - // todo -} void scanHardDrives() { ListElement *drives = NULL; @@ -20,12 +14,10 @@ } switch (pciDevice->subclass) { case 1: - initializeIDEDrive(pciDevice, &drives); + initializeIdeController(pciDevice, &drives); break; case 6: - printf("found a SATA-controller: %i:%i:%i\n", pciDevice->bus, - pciDevice->device, pciDevice->function); - initializeSATADrive(pciDevice); + initializeSataController(pciDevice, &drives); break; } } diff --git a/src/kernel/drivers/pci/hardDrive/ideController.c b/src/kernel/drivers/pci/hardDrive/ideController.c index ef3ea00..51bb464 100644 --- a/src/kernel/drivers/pci/hardDrive/ideController.c +++ b/src/kernel/drivers/pci/hardDrive/ideController.c @@ -3,6 +3,30 @@ #include #include +#define IDE_DATA_REGISTER 0 +#define IDE_ERROR_REGISTER 1 +#define IDE_SECTOR_COUNT_REGISTER 2 +#define IDE_SECTOR_NUMBER_REGISTER 3 +#define IDE_CYLINDER_LOW_REGISTER 4 +#define IDE_CYLINDER_HIGH_REGISTER 5 +// sector size, drive, head +#define IDE_SDH_REGISTER 6 +#define IDE_STATUS_REGISTER 7 +#define IDE_COMMAND_REGISTER 7 +#define IDE_ALTERNATE_STATUS_CONTROL_REGISTER 0 +#define IDE_DRIVE_ADDRESS_CONTROL_REGISTER 1 + +#define IDE_STATUS_BUSY 0x80 +#define IDE_STATUS_READY 0x40 +#define IDE_STATUS_WRITE_FAULT 0x20 +#define IDE_STATUS_SEEK_COMPLETE 0x10 +#define IDE_STATUS_DATA_REQUEST 0x08 +#define IDE_STATUS_CORRECTED_DATA 0x04 +#define IDE_STATUS_INDEX 0x02 +#define IDE_STATUS_ERROR 0x01 + +#define IDE_IDENTIFY_COMMAND 0xEC + typedef struct { uint16_t base, control, busMaster; } IdeChannels; @@ -178,7 +202,7 @@ } } -void initializeIDEDrive(PciDevice *pciDevice, ListElement **drives) { +void initializeIdeController(PciDevice *pciDevice, ListElement **drives) { uint8_t *buffer = malloc(2048); IdeChannels *channels[] = {malloc(sizeof(IdeChannels)), malloc(sizeof(IdeChannels))}; diff --git a/src/include/hardDrive.h b/src/include/hardDrive.h index 00ada36..e8a04d3 100644 --- a/src/include/hardDrive.h +++ b/src/include/hardDrive.h @@ -1,30 +1,6 @@ #ifndef HARD_DRIVE_H #define HARD_DRIVE_H -#define IDE_DATA_REGISTER 0 -#define IDE_ERROR_REGISTER 1 -#define IDE_SECTOR_COUNT_REGISTER 2 -#define IDE_SECTOR_NUMBER_REGISTER 3 -#define IDE_CYLINDER_LOW_REGISTER 4 -#define IDE_CYLINDER_HIGH_REGISTER 5 -// sector size, drive, head -#define IDE_SDH_REGISTER 6 -#define IDE_STATUS_REGISTER 7 -#define IDE_COMMAND_REGISTER 7 -#define IDE_ALTERNATE_STATUS_CONTROL_REGISTER 0 -#define IDE_DRIVE_ADDRESS_CONTROL_REGISTER 1 - -#define IDE_STATUS_BUSY 0x80 -#define IDE_STATUS_READY 0x40 -#define IDE_STATUS_WRITE_FAULT 0x20 -#define IDE_STATUS_SEEK_COMPLETE 0x10 -#define IDE_STATUS_DATA_REQUEST 0x08 -#define IDE_STATUS_CORRECTED_DATA 0x04 -#define IDE_STATUS_INDEX 0x02 -#define IDE_STATUS_ERROR 0x01 - -#define IDE_IDENTIFY_COMMAND 0xEC - #include #include #include @@ -37,7 +13,8 @@ // todo: mount point } HardDrive; -extern void initializeIDEDrive(PciDevice *, ListElement **); +extern void initializeIdeController(PciDevice *, ListElement **); +extern void initializeSataController(PciDevice *, ListElement **); extern void scanHardDrives(); diff --git a/src/kernel/drivers/pci/hardDrive/ataDrive.c b/src/kernel/drivers/pci/hardDrive/ataDrive.c deleted file mode 100644 index e69de29..0000000 --- a/src/kernel/drivers/pci/hardDrive/ataDrive.c +++ /dev/null diff --git a/src/kernel/drivers/pci/hardDrive/hardDrive.c b/src/kernel/drivers/pci/hardDrive/hardDrive.c index 3adaea3..ecb1a2f 100644 --- a/src/kernel/drivers/pci/hardDrive/hardDrive.c +++ b/src/kernel/drivers/pci/hardDrive/hardDrive.c @@ -3,12 +3,6 @@ #include #include #include -#include -#include - -void initializeSATADrive(PciDevice *pciDevice) { - // todo -} void scanHardDrives() { ListElement *drives = NULL; @@ -20,12 +14,10 @@ } switch (pciDevice->subclass) { case 1: - initializeIDEDrive(pciDevice, &drives); + initializeIdeController(pciDevice, &drives); break; case 6: - printf("found a SATA-controller: %i:%i:%i\n", pciDevice->bus, - pciDevice->device, pciDevice->function); - initializeSATADrive(pciDevice); + initializeSataController(pciDevice, &drives); break; } } diff --git a/src/kernel/drivers/pci/hardDrive/ideController.c b/src/kernel/drivers/pci/hardDrive/ideController.c index ef3ea00..51bb464 100644 --- a/src/kernel/drivers/pci/hardDrive/ideController.c +++ b/src/kernel/drivers/pci/hardDrive/ideController.c @@ -3,6 +3,30 @@ #include #include +#define IDE_DATA_REGISTER 0 +#define IDE_ERROR_REGISTER 1 +#define IDE_SECTOR_COUNT_REGISTER 2 +#define IDE_SECTOR_NUMBER_REGISTER 3 +#define IDE_CYLINDER_LOW_REGISTER 4 +#define IDE_CYLINDER_HIGH_REGISTER 5 +// sector size, drive, head +#define IDE_SDH_REGISTER 6 +#define IDE_STATUS_REGISTER 7 +#define IDE_COMMAND_REGISTER 7 +#define IDE_ALTERNATE_STATUS_CONTROL_REGISTER 0 +#define IDE_DRIVE_ADDRESS_CONTROL_REGISTER 1 + +#define IDE_STATUS_BUSY 0x80 +#define IDE_STATUS_READY 0x40 +#define IDE_STATUS_WRITE_FAULT 0x20 +#define IDE_STATUS_SEEK_COMPLETE 0x10 +#define IDE_STATUS_DATA_REQUEST 0x08 +#define IDE_STATUS_CORRECTED_DATA 0x04 +#define IDE_STATUS_INDEX 0x02 +#define IDE_STATUS_ERROR 0x01 + +#define IDE_IDENTIFY_COMMAND 0xEC + typedef struct { uint16_t base, control, busMaster; } IdeChannels; @@ -178,7 +202,7 @@ } } -void initializeIDEDrive(PciDevice *pciDevice, ListElement **drives) { +void initializeIdeController(PciDevice *pciDevice, ListElement **drives) { uint8_t *buffer = malloc(2048); IdeChannels *channels[] = {malloc(sizeof(IdeChannels)), malloc(sizeof(IdeChannels))}; diff --git a/src/kernel/drivers/pci/hardDrive/sataController.c b/src/kernel/drivers/pci/hardDrive/sataController.c new file mode 100644 index 0000000..c5ebe18 --- /dev/null +++ b/src/kernel/drivers/pci/hardDrive/sataController.c @@ -0,0 +1,22 @@ +#include <_stdio.h> +#include + +// information source: +// https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/serial-ata-ahci-spec-rev1_3.pdf + +typedef struct { + uint32_t hostCapabilities, globalHostControl, interruptStatus, + implementedPorts, version, cccCtl, cccPts, enclosureManagementLocation, + enclosureManagementControl, hostCapabilitiesExtended, handoffStatus; +} HbaMemoryRegisters; + +void initializeSataController(PciDevice *pciDevice, ListElement **drives) { + if (pciDevice->programmingInterface != 1) { + // todo + return; + } + HbaMemoryRegisters *registers = (HbaMemoryRegisters *)pciDevice->bar5; + printf("hostCapabilities: %x\nimplementedPorts: %x\nversion: %x\n", + registers->hostCapabilities, registers->implementedPorts, + registers->version); +}