00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef _ATA_H
00017 #define _ATA_H
00018
00019 #include <bus_manager.h>
00020 #include <iovec.h>
00021 #include <lendian_bitfield.h>
00022 #include <pnp/pnp_driver.h>
00023 #include "r5_wrapper.h"
00024 #include <KernelExport.h>
00025
00026
00027
00028
00029
00030
00031
00032
00033 typedef union {
00034 struct {
00035 uint8 features;
00036 uint8 sector_count;
00037 uint8 sector_number;
00038 uint8 cylinder_0_7;
00039 uint8 cylinder_8_15;
00040 LBITFIELD8_3(
00041 head : 4,
00042 device : 1,
00043 mode : 3
00044 );
00045 uint8 command;
00046 } chs;
00047 struct {
00048 uint8 features;
00049 uint8 sector_count;
00050 uint8 lba_0_7;
00051 uint8 lba_8_15;
00052 uint8 lba_16_23;
00053 LBITFIELD8_3(
00054 lba_24_27 : 4,
00055 device : 1,
00056 mode : 3
00057 );
00058 uint8 command;
00059 } lba;
00060 struct {
00061 LBITFIELD8_3(
00062 dma : 1,
00063 ovl : 1,
00064 _0_res2 : 6
00065 );
00066 LBITFIELD8_2(
00067 _1_res0 : 3,
00068 tag : 5
00069 );
00070 uint8 _2_res;
00071 uint8 byte_count_0_7;
00072 uint8 byte_count_8_15;
00073 LBITFIELD8_6(
00074 lun : 3,
00075 _5_res3 : 1,
00076 device : 1,
00077 _5_one5 : 1,
00078 _5_res6 : 1,
00079 _5_one7 : 1
00080 );
00081 uint8 command;
00082 } packet;
00083 struct {
00084 LBITFIELD8_5(
00085 ili : 1,
00086 eom : 1,
00087 abrt : 1,
00088 _0_res3 : 1,
00089 sense_key : 4
00090 );
00091 LBITFIELD8_4(
00092 cmd_or_data : 1,
00093 input_or_output : 1,
00094 release : 1,
00095 tag : 5
00096 );
00097 uint8 _2_res;
00098 uint8 byte_count_0_7;
00099 uint8 byte_count_8_15;
00100 LBITFIELD8_5(
00101 _4_res0 : 4,
00102 device : 1,
00103 _4_obs5 : 1,
00104 _4_res6 : 1,
00105 _4_obs7 : 1
00106 );
00107 LBITFIELD8_7(
00108 chk : 1,
00109 _7_res1 : 2,
00110 drq : 1,
00111 serv : 1,
00112 dmrd : 1,
00113 drdy : 1,
00114 bsy : 1
00115 );
00116 } packet_res;
00117 struct {
00118 uint8 sector_count;
00119 LBITFIELD8_4(
00120 cmd_or_data : 1,
00121 input_or_output : 1,
00122 release : 1,
00123 tag : 5
00124 );
00125 uint8 lba_0_7;
00126 uint8 lba_8_15;
00127 uint8 lba_16_23;
00128 LBITFIELD8_3(
00129 lba_24_27 : 4,
00130 device : 1,
00131 mode : 3
00132 );
00133 uint8 command;
00134 } queued;
00135 struct {
00136
00137 uint8 features;
00138 uint8 sector_count_0_7;
00139 uint8 lba_0_7;
00140 uint8 lba_8_15;
00141 uint8 lba_16_23;
00142 LBITFIELD8_3(
00143 _5low_res0 : 4,
00144 device : 1,
00145 mode : 3
00146 );
00147 uint8 command;
00148
00149
00150 uint8 _0high_res;
00151 uint8 sector_count_8_15;
00152 uint8 lba_24_31;
00153 uint8 lba_32_39;
00154 uint8 lba_40_47;
00155 } lba48;
00156 struct {
00157
00158 uint8 sector_count_0_7;
00159 LBITFIELD8_4(
00160 cmd_or_data : 1,
00161 input_or_output : 1,
00162 release : 1,
00163 tag : 5
00164 );
00165 uint8 lba_0_7;
00166 uint8 lba_8_15;
00167 uint8 lba_16_23;
00168 LBITFIELD8_3(
00169 _5low_res0 : 4,
00170 device : 1,
00171 mode : 3
00172 );
00173 uint8 command;
00174
00175
00176 uint8 sector_count_8_15;
00177 uint8 _1high_res;
00178 uint8 lba_24_31;
00179 uint8 lba_32_39;
00180 uint8 lba_40_47;
00181 } queued48;
00182 struct {
00183 uint8 _0_res[3];
00184 uint8 ver;
00185 LBITFIELD8_3(
00186 pena : 1,
00187 lock : 1,
00188 pej : 1
00189 );
00190 } set_MSN_res;
00191 struct {
00192 uint8 r[7+5];
00193 } raw;
00194 struct {
00195 uint8 features;
00196 uint8 sector_count;
00197 uint8 sector_number;
00198 uint8 cylinder_low;
00199 uint8 cylinder_high;
00200 uint8 device_head;
00201 uint8 command;
00202 } write;
00203 struct {
00204 uint8 error;
00205 uint8 sector_count;
00206 uint8 sector_number;
00207 uint8 cylinder_low;
00208 uint8 cylinder_high;
00209 uint8 device_head;
00210 uint8 status;
00211 } read;
00212 } ata_task_file;
00213
00214
00215 enum {
00216 ata_mode_chs = 5,
00217 ata_mode_lba = 7
00218 };
00219
00220
00221 typedef enum {
00222 ata_mask_features = 0x01,
00223 ata_mask_sector_count = 0x02,
00224
00225
00226 ata_mask_sector_number = 0x04,
00227 ata_mask_cylinder_low = 0x08,
00228 ata_mask_cylinder_high = 0x10,
00229
00230
00231 ata_mask_LBA_low = 0x04,
00232 ata_mask_LBA_mid = 0x08,
00233 ata_mask_LBA_high = 0x10,
00234
00235
00236 ata_mask_byte_count = 0x18,
00237
00238
00239 ata_mask_error = 0x01,
00240 ata_mask_ireason = 0x02,
00241
00242 ata_mask_device_head = 0x20,
00243 ata_mask_command = 0x40,
00244
00245 ata_mask_status = 0x40,
00246
00247
00248 ata_mask_features_48 = 0x80 | ata_mask_features,
00249 ata_mask_sector_count_48 = 0x100 | ata_mask_sector_count,
00250 ata_mask_LBA_low_48 = 0x200 | ata_mask_LBA_low,
00251 ata_mask_LBA_mid_48 = 0x400 | ata_mask_LBA_mid,
00252 ata_mask_LBA_high_48 = 0x800 | ata_mask_LBA_high,
00253
00254 ata_mask_HOB = 0xf80
00255
00256
00257 } ata_reg_mask;
00258
00259
00260 enum {
00261 ata_status_err = 0x01,
00262 ata_status_index = 0x02,
00263 ata_status_corr = 0x04,
00264 ata_status_drq = 0x08,
00265 ata_status_dsc = 0x10,
00266 ata_status_service = 0x10,
00267 ata_status_dwf = 0x20,
00268 ata_status_dma = 0x20,
00269 ata_status_dmrd = 0x20,
00270 ata_status_df = 0x20,
00271 ata_status_drdy = 0x40,
00272 ata_status_bsy = 0x80
00273 } ata_status_mask;
00274
00275
00276 enum {
00277
00278 ata_devctrl_nien = 0x02,
00279 ata_devctrl_srst = 0x04,
00280 ata_devctrl_bit3 = 0x08,
00281
00282 ata_devctrl_hob = 0x80
00283 } ata_devcntrl_mask;
00284
00285
00286 enum {
00287
00288 ata_error_abrt = 0x04,
00289
00290
00291 ata_error_icrc = 0x80,
00292
00293
00294 ata_error_unc = 0x40,
00295
00296 ata_error_wp = 0x40,
00297
00298
00299 ata_error_mc = 0x20,
00300 ata_error_idnf = 0x10,
00301 ata_error_mcr = 0x08,
00302 ata_error_nm = 0x02,
00303 } ata_error_mask;
00304
00305
00306
00307
00308
00309
00310
00311 typedef struct ata_bus_info *ata_bus;
00312
00313
00314
00315 typedef struct ata_bus_for_channel_interface {
00316
00317
00318
00319
00320
00321 status_t (*irq_handler)(
00322 ata_bus bus,
00323 uint8 status
00324 );
00325 } ata_bus_for_channel_interface;
00326
00327 #define ATA_BUS_FOR_CHANNEL_INTERFACE "ata/bus/for_channel/v1"
00328
00329
00330
00331 #define ATA_BUS_MANAGER_MODULE_NAME "ata/ata_bus_manager/bus/v1"
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341 #define ATA_CHANNEL_TYPE "ata/channel"
00342
00343 #define ATA_CHANNEL_MAX_DEVICES_ITEM "ata/max_devices"
00344
00345
00346 #define ATA_CHANNEL_CAN_DMA_ITEM "ata/can_DMA"
00347
00348 #define ATA_CHANNEL_CAN_CQ_ITEM "ata/can_CQ"
00349
00350
00351 typedef struct ata_channel_info *ata_channel_cookie;
00352
00353
00354
00355
00356 typedef struct ata_channel_interface {
00357
00358
00359
00360 status_t (*write_command_block_regs)(
00361 ata_channel_cookie channel,
00362 ata_task_file *tf,
00363 ata_reg_mask mask
00364 );
00365
00366
00367 status_t (*read_command_block_regs)(
00368 ata_channel_cookie channel,
00369 ata_task_file *tf,
00370 ata_reg_mask mask
00371 );
00372
00373
00374 uint8 (*get_altstatus)(
00375 ata_channel_cookie channel
00376 );
00377
00378
00379 status_t (*write_device_control)(
00380 ata_channel_cookie channel,
00381 uint8 val
00382 );
00383
00384
00385
00386
00387
00388 status_t (*write_pio)(
00389 ata_channel_cookie channel,
00390 uint16 * data,
00391 int count,
00392 bool force_16bit
00393 );
00394
00395
00396 status_t (*read_pio)(
00397 ata_channel_cookie channel,
00398 uint16 *data,
00399 int count,
00400 bool force_16bit
00401 );
00402
00403
00404
00405
00406
00407 status_t (*prepare_dma)(
00408 ata_channel_cookie channel,
00409 const physical_entry *sg_list,
00410 size_t sg_list_count,
00411 bool write
00412 );
00413
00414 status_t (*start_dma)(
00415 ata_channel_cookie channel
00416 );
00417
00418
00419
00420 status_t (*finish_dma)(
00421 ata_channel_cookie channel
00422 );
00423 } ata_channel_interface;
00424
00425 #define ATA_CHANNEL_INTERFACE "ata/channel/v1"
00426
00427
00428 #endif