| 1 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 2 | // File : hba_driver.h |
|---|
| 3 | // Date : 01/11/2013 |
|---|
| 4 | // Author : alain greiner and zhang |
|---|
| 5 | // Copyright (c) UPMC-LIP6 |
|---|
| 6 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 7 | |
|---|
| 8 | #ifndef _GIET_HBA_DRIVERS_H_ |
|---|
| 9 | #define _GIET_HBA_DRIVERS_H_ |
|---|
| 10 | |
|---|
| 11 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 12 | // HBA component registers offsets |
|---|
| 13 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 14 | |
|---|
| 15 | enum SoclibMultiAhciRegisters |
|---|
| 16 | { |
|---|
| 17 | HBA_PXCLB = 0, // command list base address 32 LSB bits |
|---|
| 18 | HBA_PXCLBU = 1, // command list base address 32 MSB bits |
|---|
| 19 | HBA_PXIS = 4, // interrupt status |
|---|
| 20 | HBA_PXIE = 5, // interrupt enable |
|---|
| 21 | HBA_PXCMD = 6, // run |
|---|
| 22 | HBA_PXCI = 14, // command bit-vector |
|---|
| 23 | HBA_SPAN = 0x400, // 4 Kbytes per channel => 1024 slots |
|---|
| 24 | }; |
|---|
| 25 | |
|---|
| 26 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 27 | // Data structures for command table array |
|---|
| 28 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 29 | |
|---|
| 30 | typedef struct hba_cmd_header_s // size = 128 bytes |
|---|
| 31 | { |
|---|
| 32 | // WORD 0 |
|---|
| 33 | unsigned int res0; // reserved |
|---|
| 34 | |
|---|
| 35 | // WORD 1 |
|---|
| 36 | unsigned char lba0; // LBA 7:0 |
|---|
| 37 | unsigned char lba1; // LBA 15:8 |
|---|
| 38 | unsigned char lba2; // LBA 23:16 |
|---|
| 39 | unsigned char res1; // reserved |
|---|
| 40 | |
|---|
| 41 | // WORD 2 |
|---|
| 42 | unsigned char lba3; // LBA 31:24 |
|---|
| 43 | unsigned char lba4; // LBA 39:32 |
|---|
| 44 | unsigned char lba5; // LBA 47:40 |
|---|
| 45 | unsigned char res2; // reserved |
|---|
| 46 | |
|---|
| 47 | // WORD 3 to 31 |
|---|
| 48 | unsigned int res[29]; // reserved |
|---|
| 49 | |
|---|
| 50 | } hba_cmd_header_t; |
|---|
| 51 | |
|---|
| 52 | typedef struct hba_cmd_entry_s // size = 16 bytes |
|---|
| 53 | { |
|---|
| 54 | unsigned int dba; // Buffer base address 32 LSB bits |
|---|
| 55 | unsigned int dbau; // Buffer base address 32 MSB bits |
|---|
| 56 | unsigned int res0; // reserved |
|---|
| 57 | unsigned int dbc; // Buffer byte count |
|---|
| 58 | |
|---|
| 59 | } hba_cmd_entry_t; |
|---|
| 60 | |
|---|
| 61 | typedef struct hba_cmd_table_s // size = 256 bytes |
|---|
| 62 | { |
|---|
| 63 | |
|---|
| 64 | hba_cmd_header_t header; // contains LBA |
|---|
| 65 | hba_cmd_entry_t entry[248]; // 248 buffers max |
|---|
| 66 | |
|---|
| 67 | } hba_cmd_table_t; |
|---|
| 68 | |
|---|
| 69 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 70 | // Data structures for command list array |
|---|
| 71 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 72 | |
|---|
| 73 | typedef struct hba_cmd_desc_s // size = 16 bytes |
|---|
| 74 | { |
|---|
| 75 | // WORD 0 |
|---|
| 76 | unsigned char flag[2]; // W in bit 6 of flag[0] |
|---|
| 77 | unsigned char prdtl[2]; // Number of buffers |
|---|
| 78 | |
|---|
| 79 | // WORD 1 |
|---|
| 80 | unsigned int prdbc; // Number of bytes actually transfered |
|---|
| 81 | |
|---|
| 82 | // WORD 2, WORD 3 |
|---|
| 83 | unsigned int ctba; // Command Table base address 32 LSB bits |
|---|
| 84 | unsigned int ctbau; // Command Table base address 32 MSB bits |
|---|
| 85 | |
|---|
| 86 | } hba_cmd_desc_t; |
|---|
| 87 | |
|---|
| 88 | typedef struct hba_cmd_list_s // size = 512 bytes |
|---|
| 89 | { |
|---|
| 90 | // 32 command descriptors |
|---|
| 91 | hba_cmd_desc_t desc[32]; |
|---|
| 92 | |
|---|
| 93 | } hba_cmd_list_t; |
|---|
| 94 | |
|---|
| 95 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 96 | // HBA device access functions (vci_hba) |
|---|
| 97 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 98 | |
|---|
| 99 | unsigned int _hba_write( unsigned int mode, |
|---|
| 100 | unsigned int lba, // logic bloc address on device |
|---|
| 101 | void* buffer, // memory buffer base address |
|---|
| 102 | unsigned int count ); // number of blocs |
|---|
| 103 | |
|---|
| 104 | unsigned int _hba_read ( unsigned int mode, |
|---|
| 105 | unsigned int lba, // logic bloc address on device |
|---|
| 106 | void* buffer, // memory buffer base address |
|---|
| 107 | unsigned int count ); // number of blocks |
|---|
| 108 | |
|---|
| 109 | unsigned int _hba_init ( unsigned int channel ); |
|---|
| 110 | |
|---|
| 111 | unsigned int _hba_get_status( unsigned int channel, |
|---|
| 112 | unsigned int* status ); |
|---|
| 113 | |
|---|
| 114 | unsigned int _hba_reset_status( unsigned int channel ); |
|---|
| 115 | |
|---|
| 116 | unsigned int _hba_get_block_size (); |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | #endif |
|---|
| 120 | |
|---|
| 121 | // Local Variables: |
|---|
| 122 | // tab-width: 4 |
|---|
| 123 | // c-basic-offset: 4 |
|---|
| 124 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
|---|
| 125 | // indent-tabs-mode: nil |
|---|
| 126 | // End: |
|---|
| 127 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
|---|
| 128 | |
|---|