50 lines
1.2 KiB
C
50 lines
1.2 KiB
C
#include <socks/device.h>
|
|
#include "ahci.h"
|
|
|
|
kern_status_t ata_read_blocks(struct device *dev, sectors_t offset, size_t *count, struct iovec *vec, size_t nvec, socks_flags_t flags)
|
|
{
|
|
struct fis_reg_h2d fis = {0};
|
|
size_t c = *count;
|
|
c &= 0xFFFF;
|
|
|
|
fis.fis_type = FIS_TYPE_REG_H2D;
|
|
|
|
fis.count_l = (c & 0xFFu);
|
|
fis.count_h = (c >> 8) & 0xFFu;
|
|
|
|
fis.lba0 = offset & 0xFFu;
|
|
fis.lba1 = (offset >> 8) & 0xFFu;
|
|
fis.lba2 = (offset >> 16) & 0xFFu;
|
|
fis.lba3 = (offset >> 24) & 0xFFu;
|
|
fis.lba4 = (offset >> 32) & 0xFFu;
|
|
fis.lba5 = (offset >> 40) & 0xFFu;
|
|
|
|
fis.device = 1 << 6;
|
|
|
|
struct ahci_device *ahci_dev = dev->dev_priv;
|
|
kern_status_t status = send_ata_command_ex(ahci_dev, &fis, ATA_CMD_READ_DMA_EX, vec, nvec);
|
|
if (status == KERN_OK) {
|
|
*count = c;
|
|
} else {
|
|
*count = 0;
|
|
}
|
|
|
|
return status;
|
|
}
|
|
|
|
kern_status_t ata_write_blocks(struct device *dev, sectors_t offset, size_t *count, struct iovec *vec, size_t nvec, socks_flags_t flags)
|
|
{
|
|
return KERN_UNSUPPORTED;
|
|
}
|
|
|
|
kern_status_t ata_ioctl(struct device *dev, unsigned int req, void *argp)
|
|
{
|
|
return KERN_UNSUPPORTED;
|
|
}
|
|
|
|
struct block_device_ops ata_device_ops = {
|
|
.read_blocks = ata_read_blocks,
|
|
.write_blocks = ata_write_blocks,
|
|
.ioctl = ata_ioctl,
|
|
};
|