ata_adapter.h

Go to the documentation of this file.
00001 /* 
00002     Copyright (c) 2002-04, Thomas Kurschel. All rights reserved.
00003     Distributed under the terms of the MIT License.
00004 
00005     Generic ATA host adapter library.
00006     
00007     
00008     Module to simplify writing an ATA host adapter driver.
00009     
00010     The interface is not very abstract, i.e. the actual driver is
00011     free to access any host adapter or channel data of this library.
00012 */
00013 
00014 #ifndef _ATA_ADAPTER_H
00015 #define _ATA_ADAPTER_H
00016 
00017 #include <bus/PCI.h>
00018 #include <bus/ATA.h>
00019 #include <pnp/pnp_manager.h>
00020 
00021 
00022 // one Physical Region Descriptor (PRD)
00023 // (one region must not cross 64K boundary; 
00024 //  the PRD table must not cross a 64K boundary)
00025 typedef struct prd_entry {
00026     uint32 address;             // physical address of block (must be even)
00027     uint16 count;               // size of block, 0 stands for 65536 (must be even)
00028     uint8 res6;
00029     LBITFIELD8_2(
00030         res7_0 : 7,
00031         EOT : 1                 // 1 for last entry
00032     );
00033 } prd_entry;
00034 
00035 
00036 // command register
00037 typedef struct ata_bm_command {
00038     LBITFIELD8_4(
00039         start_stop  : 1,        // start BM by changing from 0 to 1; 
00040                                 // stop BM by changing from 1 to 0
00041         res0_1      : 2,
00042         from_device : 1,        // true - read from device, false - write to device
00043         res0_4      : 4
00044     );
00045 } ata_bm_command;
00046 
00047 
00048 // status register
00049 typedef struct ata_bm_status {
00050     LBITFIELD8_7(
00051         active      : 1,        // 1, if BM is active
00052         error       : 1,        // 1, if error occured; write 1 to reset
00053         interrupt   : 1,        // 1, if INTRQ was raised, write 1 to reset
00054         res0_3      : 2,
00055         device0_dma : 1,        // 1, if BIOS/driver has setup DMA for device 0
00056         device1_dma : 1,        // 1, if BIOS/driver has setup DMA for device 1
00057         simplex     : 1         // 1, if only one channel can use DMA at a time
00058     );
00059 } ata_bm_status;
00060 
00061 
00062 // offset of bus master registers
00063 enum {
00064     ata_bm_command_reg  = 0,    // see ata_bm_command
00065     ata_bm_status_reg   = 2,    // see ata_bm_status
00066     ata_bm_prdt_address = 4     // offset of PRDT register; content must be dword-aligned
00067 };
00068 
00069 // bit mask in class_api of PCI configuration
00070 // (for adapters that can run in compatability mode)
00071 enum {
00072     ata_api_primary_native      = 1,    // primary channel is in native mode
00073     ata_api_primary_fixed       = 2,    // primary channel can be switched to native mode
00074     ata_api_secondary_native    = 4,    // secondary channel is in native mode
00075     ata_api_secondary_fixed     = 8     // secondary channel can be switched to native mode
00076 };
00077 
00078 
00079 // (maximum) size of S/G table
00080 // there are so many restrictions that we want to keep it inside one page
00081 // to be sure that we fulfill them all; the -1 is for the termination entry
00082 #define ATA_ADAPTER_MAX_SG_COUNT (B_PAGE_SIZE / sizeof( prd_entry ) - 1)
00083 
00084 
00085 // channel node items
00086 
00087 // io address of command block (uint16)
00088 #define ATA_ADAPTER_COMMAND_BLOCK_BASE "ata_adapter/command_block_base"
00089 // io address of control block (uint16)
00090 #define ATA_ADAPTER_CONTROL_BLOCK_BASE "ata_adapter/control_block_base"
00091 // interrupt number (uint8)
00092 // can also be defined in host adapter node if both channels use same IRQ!
00093 #define ATA_ADAPTER_INTNUM "ata_adapter/irq"
00094 // non-zero if primary channel, else secondary channel (uint8)
00095 #define ATA_ADAPTER_IS_PRIMARY "ata_adapter/is_primary"
00096 
00097 
00098 // host adapter node items
00099 
00100 // io address of bus master registers (uint16)
00101 #define ATA_ADAPTER_BUS_MASTER_BASE "ata_adapter/bus_master_base"
00102 
00103 
00104 // info about one channel
00105 typedef struct ata_channel_info {
00106     const pci_device_interface *pci;    // mirrored from host adapter info
00107     pci_device device;
00108     
00109     struct ata_adapter_info* adapter;
00110     uint8 is_primary;
00111     
00112     uint16 command_block_base;  // io address command block
00113     uint16 control_block_base; // io address control block
00114     uint16 bus_master_base;
00115     int intnum;             // interrupt number 
00116     
00117     uint32 lost;            // != 0 if device got removed, i.e. if it must not
00118                             // be accessed anymore
00119     
00120     const ata_bus_for_channel_interface *ata;
00121     ata_bus ata_bus;
00122     pnp_node_handle node;
00123     
00124     int32 (*inthand)( void *arg );
00125     
00126     area_id prd_area;
00127     prd_entry *prdt;
00128     uint32 prdt_phys;
00129     uint32 dmaing;
00130 } ata_channel_info;
00131 
00132 
00133 // info about host adapter
00134 typedef struct ata_adapter_info {
00135     const pci_device_interface *pci;
00136     pci_device device;
00137     
00138     uint16 bus_master_base;
00139     
00140     uint32 lost;            // != 0 if device got removed, i.e. if it must not
00141                             // be accessed anymore
00142     
00143     ata_channel_info* channels[2]; // for now, no more then 2 channels are allowed
00144     uint8 intnum;   // signals if this adapter is in native mode, i.e. has two irqs assigned iso one
00145     
00146     pnp_node_handle node;
00147 } ata_adapter_info;
00148 
00149 
00150 // interface of IDE adapter library.
00151 typedef struct ata_adapter_interface {
00152     // function calls that can be forwarded from channel driver
00153     status_t (*write_command_block_regs)
00154         (ata_channel_info *channel, ata_task_file *tf, ata_reg_mask mask);
00155     status_t (*read_command_block_regs)
00156         (ata_channel_info *channel, ata_task_file *tf, ata_reg_mask mask);
00157 
00158     uint8 (*get_altstatus) (ata_channel_info *channel);
00159     status_t (*write_device_control) (ata_channel_info *channel, uint8 val);    
00160 
00161     status_t (*write_pio) (ata_channel_info *channel, uint16 *data, int count, bool force_16bit );
00162     status_t (*read_pio) (ata_channel_info *channel, uint16 *data, int count, bool force_16bit );
00163 
00164     status_t (*prepare_dma)(ata_channel_info *channel, 
00165                             const physical_entry *sg_list, size_t sg_list_count,
00166                             bool to_device );
00167     status_t (*start_dma)(ata_channel_info *channel);
00168     status_t (*finish_dma)(ata_channel_info *channel);
00169     
00170     
00171     // default functions that should be replaced by a more specific version
00172     // (copy them from source code of this library and modify them at will)
00173     int32 (*inthand)( void *arg );
00174     
00175     // functions that must be called by init/uninit etc. of channel driver
00176     status_t (*init_channel)( pnp_node_handle node, ata_bus _ata_bus, 
00177         ata_channel_info **cookie, size_t total_data_size,
00178         int32 (*inthand)( void *arg ) );
00179     status_t (*uninit_channel)( ata_channel_info *channel );
00180     void (*channel_removed)( pnp_node_handle node, ata_channel_info *channel );
00181 
00182     // publish channel node
00183     status_t (*publish_channel)( pnp_node_handle adapter_node, 
00184         const char *channel_module_name,
00185         uint16 command_block_base, uint16 control_block_base,
00186         uint8 intnum, bool can_dma, bool is_primary, const char *name, 
00187         io_resource_handle *resources, pnp_node_handle *node );
00188     // verify channel configuration and publish node on success
00189     status_t (*detect_channel)(     
00190         const pci_device_interface *pci, pci_device _pci_device,
00191         pnp_node_handle adapter_node, 
00192         const char *channel_module_name, bool channel_can_dma,
00193         uint16 command_block_base, uint16 control_block_base, uint16 bus_master_base,
00194         uint8 intnum, bool is_primary, const char *name, pnp_node_handle *node,
00195         bool supports_compatibility_mode );
00196 
00197     // functions that must be called by init/uninit etc. of host adapter driver
00198     status_t (*init_adapter)( pnp_node_handle node, void *user_cookie, 
00199         ata_adapter_info **cookie, size_t total_data_size );
00200     status_t (*uninit_adapter)( ata_adapter_info *adapter );
00201     void (*adapter_removed)( pnp_node_handle node, ata_adapter_info *adapter );
00202 
00203     // publish adapter node
00204     status_t (*publish_adapter)(    
00205         pnp_node_handle parent, 
00206         uint16 bus_master_base, io_resource_handle *resources, 
00207         const char *adapter_driver, const char *adapter_driver_type,
00208         const char *adapter_name, const char *asic_name,
00209         bool can_dma, bool can_cq, uint32 dma_alignment, uint32 dma_boundary,
00210         uint32 max_sg_block_size, pnp_node_handle *node );
00211     // verify adapter configuration and publish node on success
00212     status_t (*detect_adapter)(     
00213         const pci_device_interface *pci, pci_device _pci_device,
00214         pnp_node_handle parent, uint16 bus_master_base, 
00215         const char *adapter_driver, const char *adapter_driver_type,
00216         const char *adapter_name, const char *asic_name,
00217         bool can_dma, bool can_cq, uint32 dma_alignment, uint32 dma_boundary,
00218         uint32 max_sg_block_size, pnp_node_handle *node );
00219     // standard master probe for adapter that registers adapter and channel nodes
00220     status_t (*probe_adapter)( pnp_node_handle parent,
00221         const char *adapter_driver, const char *adapter_driver_type,
00222         const char *adapter_name, const char *asic_name,
00223         const char *channel_module_name,
00224         bool can_dma, bool can_cq, uint32 dma_alignment, uint32 dma_boundary,
00225         uint32 max_sg_block_size, bool supports_compatibility_mode );
00226 } ata_adapter_interface;
00227 
00228 #define ATA_ADAPTER_INTERFACE "ata_adapter/v1"
00229 #define ATA_ADAPTER_MODULE_NAME "ata/generic/ata_adapter/v1"
00230 
00231 
00232 #endif

Copyright 2005 by yellowTAB GmbH, Be Inc., Palm Source Inc. and their respective legal successors
All rights reserved.