iPXE
Data Structures | Defines | Functions
ata.h File Reference

ATA devices. More...

#include <stdint.h>
#include <ipxe/uaccess.h>
#include <ipxe/interface.h>

Go to the source code of this file.

Data Structures

union  ata_lba
 An ATA Logical Block Address. More...
union  ata_fifo
 An ATA 2-byte FIFO register. More...
struct  ata_cb
 ATA command block. More...
struct  ata_identity
 Structure returned by ATA IDENTIFY command. More...
struct  ata_cmd
 An ATA command information unit. More...

Defines

#define ATA_DEV_OBSOLETE   0xa0
 Obsolete bits in the ATA device register.
#define ATA_DEV_LBA   0x40
 LBA flag in the ATA device register.
#define ATA_DEV_SLAVE   0x10
 Slave ("device 1") flag in the ATA device register.
#define ATA_DEV_MASTER   0x00
 Master ("device 0") flag in the ATA device register.
#define ATA_DEV_MASK   0xf0
 Mask of non-LBA portion of device register.
#define ATA_CMD_READ   0x20
 "Read sectors" command
#define ATA_CMD_READ_EXT   0x24
 "Read sectors (ext)" command
#define ATA_CMD_WRITE   0x30
 "Write sectors" command
#define ATA_CMD_WRITE_EXT   0x34
 "Write sectors (ext)" command
#define ATA_CMD_IDENTIFY   0xec
 "Identify" command
#define ATA_STAT_ERR   0x01
 Command completed in error.
#define ATA_SUPPORTS_LBA48   ( 1 << 10 )
 Supports LBA48 flag.
#define ATA_SECTOR_SIZE   512
 ATA sector size.
#define ata_command_TYPE(object_type)

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
int ata_command (struct interface *control, struct interface *data, struct ata_cmd *command)
 Issue ATA command.
int ata_open (struct interface *block, struct interface *ata, unsigned int device, unsigned int max_count)
 Open ATA device.

Detailed Description

ATA devices.

Definition in file ata.h.


Define Documentation

#define ATA_DEV_OBSOLETE   0xa0

Obsolete bits in the ATA device register.

Definition at line 111 of file ata.h.

Referenced by atadev_command().

#define ATA_DEV_LBA   0x40

LBA flag in the ATA device register.

Definition at line 114 of file ata.h.

Referenced by atadev_command().

#define ATA_DEV_SLAVE   0x10

Slave ("device 1") flag in the ATA device register.

Definition at line 117 of file ata.h.

Referenced by aoecmd_ata_cmd(), and atadev_edd_describe().

#define ATA_DEV_MASTER   0x00

Master ("device 0") flag in the ATA device register.

Definition at line 120 of file ata.h.

Referenced by aoedev_open().

#define ATA_DEV_MASK   0xf0

Mask of non-LBA portion of device register.

Definition at line 123 of file ata.h.

Referenced by aoecmd_ata_cmd().

#define ATA_CMD_READ   0x20

"Read sectors" command

Definition at line 126 of file ata.h.

#define ATA_CMD_READ_EXT   0x24

"Read sectors (ext)" command

Definition at line 129 of file ata.h.

#define ATA_CMD_WRITE   0x30

"Write sectors" command

Definition at line 132 of file ata.h.

#define ATA_CMD_WRITE_EXT   0x34

"Write sectors (ext)" command

Definition at line 135 of file ata.h.

#define ATA_CMD_IDENTIFY   0xec

"Identify" command

Definition at line 138 of file ata.h.

#define ATA_STAT_ERR   0x01

Command completed in error.

Definition at line 141 of file ata.h.

Referenced by aoecmd_ata_rsp().

#define ATA_SUPPORTS_LBA48   ( 1 << 10 )

Supports LBA48 flag.

Definition at line 162 of file ata.h.

Referenced by atacmd_identify_done().

#define ATA_SECTOR_SIZE   512

ATA sector size.

Definition at line 165 of file ata.h.

Referenced by atacmd_identify_done(), atadev_command(), and atadev_read_capacity().

#define ata_command_TYPE (   object_type)
Value:
typeof ( int ( object_type, struct interface *data,             \
                       struct ata_cmd *command ) )

Definition at line 197 of file ata.h.

Referenced by ata_command().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
int ata_command ( struct interface control,
struct interface data,
struct ata_cmd command 
)

Issue ATA command.

Parameters:
controlATA control interface
dataATA data interface
commandATA command
Return values:
tagCommand tag, or negative error

Definition at line 59 of file ata.c.

References ata_command_TYPE, dest, EOPNOTSUPP, intf_get_dest_op, intf_object(), intf_put(), op, and tag.

                                            {
        struct interface *dest;
        ata_command_TYPE ( void * ) *op =
                intf_get_dest_op ( control, ata_command, &dest );
        void *object = intf_object ( dest );
        int tag;

        if ( op ) {
                tag = op ( object, data, command );
        } else {
                /* Default is to fail to issue the command */
                tag = -EOPNOTSUPP;
        }

        intf_put ( dest );
        return tag;
}
int ata_open ( struct interface block,
struct interface ata,
unsigned int  device,
unsigned int  max_count 
)

Open ATA device.

Parameters:
blockBlock control interface
ataATA control interface
deviceATA device number
max_countMaximum number of blocks per single transfer
Return values:
rcReturn status code

Definition at line 662 of file ata.c.

References ata_device::ata, ata_device::block, ata_device::device, device, ENOMEM, intf_init(), intf_plug_plug(), ata_device::max_count, NULL, ref_init, ref_put, ata_device::refcnt, and zalloc().

Referenced by aoedev_open().

                                                             {
        struct ata_device *atadev;

        /* Allocate and initialise structure */
        atadev = zalloc ( sizeof ( *atadev ) );
        if ( ! atadev )
                return -ENOMEM;
        ref_init ( &atadev->refcnt, NULL );
        intf_init ( &atadev->block, &atadev_block_desc, &atadev->refcnt );
        intf_init ( &atadev->ata, &atadev_ata_desc, &atadev->refcnt );
        atadev->device = device;
        atadev->max_count = max_count;

        /* Attach to ATA and parent and interfaces, mortalise self,
         * and return
         */
        intf_plug_plug ( &atadev->ata, ata );
        intf_plug_plug ( &atadev->block, block );
        ref_put ( &atadev->refcnt );
        return 0;
}