[1] | 1 | /* |
---|
| 2 | * ata.h - ATA interface registers |
---|
| 3 | * |
---|
| 4 | * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless |
---|
| 5 | * Copyright (c) 2011,2012 UPMC Sorbonne Universites |
---|
| 6 | * |
---|
| 7 | * This file is part of ALMOS-kernel. |
---|
| 8 | * |
---|
| 9 | * ALMOS-kernel is free software; you can redistribute it and/or modify it |
---|
| 10 | * under the terms of the GNU General Public License as published by |
---|
| 11 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 12 | * |
---|
| 13 | * ALMOS-kernel is distributed in the hope that it will be useful, but |
---|
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 16 | * General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with ALMOS-kernel; if not, write to the Free Software Foundation, |
---|
| 20 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 21 | */ |
---|
| 22 | |
---|
| 23 | #ifndef _ATA_H_ |
---|
| 24 | #define _ATA_H_ |
---|
| 25 | |
---|
| 26 | #include <types.h> |
---|
| 27 | #include <list.h> |
---|
| 28 | #include <driver.h> |
---|
| 29 | |
---|
| 30 | /* ATA Task File offsets */ |
---|
| 31 | #define ATA_DATA_REG 0 |
---|
| 32 | #define ATA_ERROR_REG 1 |
---|
| 33 | #define ATA_PRECOMPENSATION_REG 1 |
---|
| 34 | #define ATA_COUNT_REG 2 |
---|
| 35 | #define ATA_LBA_LOW_REG 3 |
---|
| 36 | #define ATA_LBA_MID_REG 4 |
---|
| 37 | #define ATA_LBA_HIGH_REG 5 |
---|
| 38 | #define ATA_DRIVE_REG 6 |
---|
| 39 | #define ATA_STATUS_REG 7 |
---|
| 40 | #define ATA_CMD_REG 7 |
---|
| 41 | |
---|
| 42 | #define ATA_DOR_PORT 0x3F6 |
---|
| 43 | |
---|
| 44 | /* ATA Status Register bits */ |
---|
| 45 | #define ATA_ERR 0x01 |
---|
| 46 | #define ATA_IDX 0x02 |
---|
| 47 | #define ATA_CORR 0x04 |
---|
| 48 | #define ATA_DRQ 0x08 |
---|
| 49 | #define ATA_DSC 0x10 |
---|
| 50 | #define ATA_WFT 0x20 |
---|
| 51 | #define ATA_DRDY 0x40 |
---|
| 52 | #define ATA_BSY 0x80 |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | /* ATA Error Register bits */ |
---|
| 56 | |
---|
| 57 | /* Block device status */ |
---|
| 58 | #define ATA_IDLE 0 |
---|
| 59 | #define ATA_BUSY 1 |
---|
| 60 | #define ATA_READ_SUCCESS 2 |
---|
| 61 | #define ATA_WRITE_SUCCESS 3 |
---|
| 62 | #define ATA_READ_ERROR 4 |
---|
| 63 | #define ATA_WRITE_ERROR 5 |
---|
| 64 | #define ATA_ERROR 6 |
---|
| 65 | |
---|
| 66 | #define ATA_READ_CMD 0x020 |
---|
| 67 | #define ATA_WRITE_CMD 0x030 |
---|
| 68 | #define ATA_IDENTIFY_CMD 0x0EC |
---|
| 69 | |
---|
| 70 | #define ATA_LBA_CAP 0x0100 |
---|
| 71 | |
---|
| 72 | struct device_s; |
---|
| 73 | |
---|
| 74 | struct ata_identify_s |
---|
| 75 | { |
---|
| 76 | uint16_t general; |
---|
| 77 | uint16_t geometry[6]; |
---|
| 78 | uint16_t vendor_id1[3]; |
---|
| 79 | uint16_t info1[37]; |
---|
| 80 | uint16_t vendor_id2; |
---|
| 81 | uint16_t info2; |
---|
| 82 | uint16_t capabilities; |
---|
| 83 | uint16_t info3[10]; |
---|
| 84 | uint32_t sectors; |
---|
| 85 | //uint16_t lblock_lo; |
---|
| 86 | //uint16_t lblock_hi; |
---|
| 87 | uint32_t info4; |
---|
| 88 | uint16_t reserved1[64]; |
---|
| 89 | uint16_t vendor_id3[32]; |
---|
| 90 | uint16_t reserved2[96]; |
---|
| 91 | } __attribute__ ((packed)); |
---|
| 92 | |
---|
| 93 | struct ata_params_s |
---|
| 94 | { |
---|
| 95 | uint32_t blk_count; |
---|
| 96 | uint32_t blk_size; |
---|
| 97 | struct ata_identify_s info; |
---|
| 98 | }; |
---|
| 99 | |
---|
| 100 | struct ata_context_s |
---|
| 101 | { |
---|
| 102 | struct list_entry request_queue; |
---|
| 103 | struct wait_queue_s pending; |
---|
| 104 | struct ata_params_s params; |
---|
| 105 | }; |
---|
| 106 | |
---|
| 107 | void ibmpc_ata_init(struct device_s *hdd, void *base, uint_t irq); |
---|
| 108 | |
---|
| 109 | #endif /* _ATA_H_ */ |
---|