AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
pio.c File Reference

ATA programmed I/O (PIO): the CPU moves the data itself. More...

#include <core/system.h>
#include <core/panic.h>
#include <cpu/io.h>
#include <dev/dev.h>
#include <fs/vfs.h>
#include <fs/devfs.h>
#include <fs/posix.h>
#include <fs/mbr.h>
#include <aquila/errno.h>
#include <dev/pci.h>
#include <ata.h>

Go to the source code of this file.

Macros

#define PIO_MAX_RETRIES   5
#define PIO_MAX_SECTORS   256

Functions

static ssize_t pio_read_sectors (struct ata_drive *drive, uint64_t lba, size_t count, void *buf)
 Reads up to PIO_MAX_SECTORS sectors with one command, trying it again a few times if the drive aborts it.
static ssize_t pio_write_sectors (struct ata_drive *drive, uint64_t lba, size_t count, void *buf)
 Writes up to PIO_MAX_SECTORS sectors with one command.
static int pio_flush (struct ata_drive *drive)
 Has the drive write what its cache holds to the disk.
static ssize_t pio_read (struct ata_drive *drive, uint64_t lba, size_t count, void *buf)
 Reads count sectors from lba on, PIO_MAX_SECTORS per command.
static ssize_t pio_write (struct ata_drive *drive, uint64_t lba, size_t count, void *buf)
 Writes count sectors from lba on, PIO_MAX_SECTORS per command.
void pio_init (struct ata_drive *drive)
 Sets a drive up for PIO, and resets its channel.

Detailed Description

ATA programmed I/O (PIO): the CPU moves the data itself.

For each command, the driver writes the sectors' address, sends the command, then waits for the drive to be ready for each sector by polling its status, and copies the sector through the data port, 256 words at a time. It works with any drive, but keeps the CPU busy; bus master DMA (dma.c) is used instead when the controller and the drive can. Only LBA addressing is supported, not CHS.

Definition in file pio.c.

Macro Definition Documentation

◆ PIO_MAX_RETRIES

#define PIO_MAX_RETRIES   5

Definition at line 25 of file pio.c.

Referenced by pio_read_sectors().

◆ PIO_MAX_SECTORS

#define PIO_MAX_SECTORS   256

Definition at line 29 of file pio.c.

Referenced by pio_read(), and pio_write().

Function Documentation

◆ pio_flush()

int pio_flush ( struct ata_drive * drive)
static

Has the drive write what its cache holds to the disk.

Returns 0, or -EIO if it failed.

Definition at line 126 of file pio.c.

References ATA_CMD_CACHE_FLUSH, ATA_CMD_CACHE_FLUSH_EXT, ATA_MODE_LBA48, ATA_REG_CMD, ata_select_drive(), ata_drive::base, io_out8(), ata_drive::mode, and pio_flush().

Referenced by pio_flush(), and pio_init().

◆ pio_init()

void pio_init ( struct ata_drive * drive)

Sets a drive up for PIO, and resets its channel.

Parameters
drivethe drive

Definition at line 182 of file pio.c.

References ata_reset(), ata_drive::flush, pio_flush(), pio_init(), pio_read(), pio_write(), ata_drive::read, and ata_drive::write.

Referenced by ata_probe(), and pio_init().

◆ pio_read()

ssize_t pio_read ( struct ata_drive * drive,
uint64_t lba,
size_t count,
void * buf )
static

Reads count sectors from lba on, PIO_MAX_SECTORS per command.

Returns 0 or a negative errno.

Definition at line 141 of file pio.c.

References MIN, PIO_MAX_SECTORS, pio_read(), and pio_read_sectors().

Referenced by pio_init(), and pio_read().

◆ pio_read_sectors()

ssize_t pio_read_sectors ( struct ata_drive * drive,
uint64_t lba,
size_t count,
void * buf )
static

Reads up to PIO_MAX_SECTORS sectors with one command, trying it again a few times if the drive aborts it.

Returns 0 or a negative errno.

Definition at line 34 of file pio.c.

References __insw, ioaddr::addr, ATA_CAP_LBA, ATA_CMD_READ_SECTORS, ATA_CMD_READ_SECTORS_EXT, ATA_MODE_LBA48, ATA_REG_CMD, ATA_REG_DATA, ata_setup(), ata_drive::base, ata_drive::capabilities, io_out8(), ata_drive::mode, PIO_MAX_RETRIES, pio_read_sectors(), and printk().

Referenced by pio_read(), and pio_read_sectors().

◆ pio_write()

ssize_t pio_write ( struct ata_drive * drive,
uint64_t lba,
size_t count,
void * buf )
static

Writes count sectors from lba on, PIO_MAX_SECTORS per command.

Returns 0 or a negative errno.

Definition at line 160 of file pio.c.

References MIN, PIO_MAX_SECTORS, pio_write(), and pio_write_sectors().

Referenced by pio_init(), and pio_write().

◆ pio_write_sectors()

ssize_t pio_write_sectors ( struct ata_drive * drive,
uint64_t lba,
size_t count,
void * buf )
static