~ubuntu-branches/debian/sid/grub2/sid-200907171837

« back to all changes in this revision

Viewing changes to include/grub/ata.h

  • Committer: Bazaar Package Importer
  • Author(s): Robert Millan
  • Date: 2009-07-02 13:23:51 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090702132351-tanpn0ryyijp93gu
Tags: 1.96+20090702-1
* New SVN snapshot.
* rules: Remove duplicated files in sparc64-ieee1275 port.
* rules: Comment out -DGRUB_ASSUME_LINUX_HAS_FB_SUPPORT=1 setting.  We'll
  re-evaluate using it when it's more mature.  (Closes: #535026).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ata.h - ATA disk access.  */
 
2
/*
 
3
 *  GRUB  --  GRand Unified Bootloader
 
4
 *  Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
 
5
 *
 
6
 *  GRUB is free software: you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation, either version 3 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  GRUB is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
#ifndef GRUB_ATA_HEADER
 
21
#define GRUB_ATA_HEADER 1
 
22
 
 
23
#include <grub/misc.h>
 
24
#include <grub/symbol.h>
 
25
/* XXX: For now this only works on i386.  */
 
26
#include <grub/cpu/io.h>
 
27
 
 
28
typedef enum
 
29
  {
 
30
    GRUB_ATA_CHS,
 
31
    GRUB_ATA_LBA,
 
32
    GRUB_ATA_LBA48
 
33
  } grub_ata_addressing_t;
 
34
 
 
35
#define GRUB_ATA_REG_DATA       0
 
36
#define GRUB_ATA_REG_ERROR      1
 
37
#define GRUB_ATA_REG_FEATURES   1
 
38
#define GRUB_ATA_REG_SECTORS    2
 
39
#define GRUB_ATAPI_REG_IREASON  2
 
40
#define GRUB_ATA_REG_SECTNUM    3
 
41
#define GRUB_ATA_REG_CYLLSB     4
 
42
#define GRUB_ATA_REG_CYLMSB     5
 
43
#define GRUB_ATA_REG_LBALOW     3
 
44
#define GRUB_ATA_REG_LBAMID     4
 
45
#define GRUB_ATAPI_REG_CNTLOW   4
 
46
#define GRUB_ATA_REG_LBAHIGH    5
 
47
#define GRUB_ATAPI_REG_CNTHIGH  5
 
48
#define GRUB_ATA_REG_DISK       6
 
49
#define GRUB_ATA_REG_CMD        7
 
50
#define GRUB_ATA_REG_STATUS     7
 
51
 
 
52
#define GRUB_ATA_REG2_CONTROL   0
 
53
 
 
54
#define GRUB_ATA_STATUS_ERR     0x01
 
55
#define GRUB_ATA_STATUS_INDEX   0x02
 
56
#define GRUB_ATA_STATUS_ECC     0x04
 
57
#define GRUB_ATA_STATUS_DRQ     0x08
 
58
#define GRUB_ATA_STATUS_SEEK    0x10
 
59
#define GRUB_ATA_STATUS_WRERR   0x20
 
60
#define GRUB_ATA_STATUS_READY   0x40
 
61
#define GRUB_ATA_STATUS_BUSY    0x80
 
62
 
 
63
/* ATAPI interrupt reason values (I/O, D/C bits).  */
 
64
#define GRUB_ATAPI_IREASON_MASK     0x3
 
65
#define GRUB_ATAPI_IREASON_DATA_OUT 0x0
 
66
#define GRUB_ATAPI_IREASON_CMD_OUT  0x1
 
67
#define GRUB_ATAPI_IREASON_DATA_IN  0x2
 
68
#define GRUB_ATAPI_IREASON_ERROR    0x3
 
69
 
 
70
enum grub_ata_commands
 
71
  {
 
72
    GRUB_ATA_CMD_CHECK_POWER_MODE       = 0xe5,
 
73
    GRUB_ATA_CMD_IDENTIFY_DEVICE        = 0xec,
 
74
    GRUB_ATA_CMD_IDENTIFY_PACKET_DEVICE = 0xa1,
 
75
    GRUB_ATA_CMD_IDLE                   = 0xe3,
 
76
    GRUB_ATA_CMD_PACKET                 = 0xa0,
 
77
    GRUB_ATA_CMD_READ_SECTORS           = 0x20,
 
78
    GRUB_ATA_CMD_READ_SECTORS_EXT       = 0x24,
 
79
    GRUB_ATA_CMD_SECURITY_FREEZE_LOCK   = 0xf5,
 
80
    GRUB_ATA_CMD_SET_FEATURES           = 0xef,
 
81
    GRUB_ATA_CMD_SLEEP                  = 0xe6,
 
82
    GRUB_ATA_CMD_SMART                  = 0xb0,
 
83
    GRUB_ATA_CMD_STANDBY_IMMEDIATE      = 0xe0,
 
84
    GRUB_ATA_CMD_WRITE_SECTORS          = 0x30,
 
85
    GRUB_ATA_CMD_WRITE_SECTORS_EXT      = 0x34,
 
86
  };
 
87
 
 
88
enum grub_ata_timeout_milliseconds
 
89
  {
 
90
    GRUB_ATA_TOUT_STD  =  1000,  /* 1s standard timeout.  */
 
91
    GRUB_ATA_TOUT_DATA = 10000   /* 10s DATA I/O timeout.  */
 
92
  };
 
93
 
 
94
struct grub_ata_device
 
95
{
 
96
  /* IDE port to use.  */
 
97
  int port;
 
98
 
 
99
  /* IO addresses on which the registers for this device can be
 
100
     found.  */
 
101
  int ioaddress;
 
102
  int ioaddress2;
 
103
 
 
104
  /* Two devices can be connected to a single cable.  Use this field
 
105
     to select device 0 (commonly known as "master") or device 1
 
106
     (commonly known as "slave").  */
 
107
  int device;
 
108
 
 
109
  /* Addressing methods available for accessing this device.  If CHS
 
110
     is only available, use that.  Otherwise use LBA, except for the
 
111
     high sectors.  In that case use LBA48.  */
 
112
  grub_ata_addressing_t addr;
 
113
 
 
114
  /* Sector count.  */
 
115
  grub_uint64_t size;
 
116
 
 
117
  /* CHS maximums.  */
 
118
  grub_uint16_t cylinders;
 
119
  grub_uint16_t heads;
 
120
  grub_uint16_t sectors_per_track;
 
121
 
 
122
  /* Set to 0 for ATA, set to 1 for ATAPI.  */
 
123
  int atapi;
 
124
 
 
125
  struct grub_ata_device *next;
 
126
};
 
127
 
 
128
grub_err_t EXPORT_FUNC(grub_ata_wait_not_busy) (struct grub_ata_device *dev,
 
129
                                                int milliseconds);
 
130
grub_err_t EXPORT_FUNC(grub_ata_wait_drq) (struct grub_ata_device *dev,
 
131
                                           int rw, int milliseconds);
 
132
void EXPORT_FUNC(grub_ata_pio_read) (struct grub_ata_device *dev,
 
133
                                     char *buf, grub_size_t size);
 
134
 
 
135
static inline void
 
136
grub_ata_regset (struct grub_ata_device *dev, int reg, int val)
 
137
{
 
138
  grub_outb (val, dev->ioaddress + reg);
 
139
}
 
140
 
 
141
static inline grub_uint8_t
 
142
grub_ata_regget (struct grub_ata_device *dev, int reg)
 
143
{
 
144
  return grub_inb (dev->ioaddress + reg);
 
145
}
 
146
 
 
147
static inline void
 
148
grub_ata_regset2 (struct grub_ata_device *dev, int reg, int val)
 
149
{
 
150
  grub_outb (val, dev->ioaddress2 + reg);
 
151
}
 
152
 
 
153
static inline grub_uint8_t
 
154
grub_ata_regget2 (struct grub_ata_device *dev, int reg)
 
155
{
 
156
  return grub_inb (dev->ioaddress2 + reg);
 
157
}
 
158
 
 
159
static inline grub_err_t
 
160
grub_ata_check_ready (struct grub_ata_device *dev)
 
161
{
 
162
  if (grub_ata_regget (dev, GRUB_ATA_REG_STATUS) & GRUB_ATA_STATUS_BUSY)
 
163
    return grub_ata_wait_not_busy (dev, GRUB_ATA_TOUT_STD);
 
164
 
 
165
  return GRUB_ERR_NONE;
 
166
}
 
167
 
 
168
#endif /* ! GRUB_ATA_HEADER */