[258] | 1 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 2 | // File : hba_driver.h |
---|
| 3 | // Date : 01/11/2013 |
---|
| 4 | // Author : alain greiner and zhang |
---|
| 5 | // Copyright (c) UPMC-LIP6 |
---|
| 6 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[437] | 7 | // The hba_driver.c and hba_driver.h files are part ot the GIET-VM kernel. |
---|
| 8 | // This driver supports the SocLib VciMultiAhci component, that is a multi-channels, |
---|
| 9 | // block oriented, external storage contrÃŽler, respecting the AHCI standard. |
---|
| 10 | // |
---|
[529] | 11 | // 1. Each HBA channel define an independant physical disk, but this driver |
---|
| 12 | // supports only channel 0, because the GIET-VM uses only one physical disk. |
---|
| 13 | // |
---|
[540] | 14 | // 2. This HBA component support split memory buffers (several physical |
---|
[545] | 15 | // buffers for one single command), but this driver supports only one |
---|
[540] | 16 | // single buffer commands. |
---|
| 17 | // |
---|
| 18 | // 3. The "command list" can contain up to 32 independant commands, posted |
---|
[529] | 19 | // by different user tasks. These independant transfers are handled |
---|
| 20 | // by the HBA device in the same order as they have been written by the |
---|
| 21 | // driver(s) in the command list. There is no global lock protecting the |
---|
| 22 | // the HBA device, but the command list being a shared structure, the driver |
---|
| 23 | // must use an atomic_increment() to get a slot in the command list, |
---|
| 24 | // and increment the write pointer. |
---|
| 25 | // |
---|
[540] | 26 | // 4. This driver implements two operating mode: |
---|
[529] | 27 | // - In synchronous mode, the calling task poll the HBA_PXCI register to |
---|
| 28 | // detect the command completion (busy waiting). |
---|
| 29 | // - In descheduling mode, the calling task is descheduled, and must be |
---|
| 30 | // restart when the command is completed. |
---|
| 31 | // |
---|
[540] | 32 | // 5. As several user tasks can concurrently register commands in the command |
---|
[529] | 33 | // list, and there is only one HBA interrupt, this interrupt is not linked |
---|
| 34 | // to a specific task. In descheduling mode, the HBA IRQ is a "global" IRQ |
---|
| 35 | // that is statically routed to processor P[x_io,y_io,0] in cluster_io. |
---|
| 36 | // The associated global HBA_ISR send a WAKUP WTI to all tasks that have |
---|
| 37 | // a completed command. This HBA_ISR uses a read pointer on the command |
---|
| 38 | // to identify the first expected command completion. The incrementation |
---|
| 39 | // of this read pointer does not require atomic_increment as there is |
---|
| 40 | // no concurrent access for this pointer. |
---|
| 41 | // |
---|
[437] | 42 | // The SEG_IOC_BASE virtual address must be defined in the hard_config.h file. |
---|
| 43 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[258] | 44 | |
---|
| 45 | #ifndef _GIET_HBA_DRIVERS_H_ |
---|
| 46 | #define _GIET_HBA_DRIVERS_H_ |
---|
| 47 | |
---|
| 48 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 49 | // HBA component registers offsets |
---|
| 50 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 51 | |
---|
| 52 | enum SoclibMultiAhciRegisters |
---|
| 53 | { |
---|
| 54 | HBA_PXCLB = 0, // command list base address 32 LSB bits |
---|
| 55 | HBA_PXCLBU = 1, // command list base address 32 MSB bits |
---|
| 56 | HBA_PXIS = 4, // interrupt status |
---|
| 57 | HBA_PXIE = 5, // interrupt enable |
---|
| 58 | HBA_PXCMD = 6, // run |
---|
| 59 | HBA_PXCI = 14, // command bit-vector |
---|
| 60 | HBA_SPAN = 0x400, // 4 Kbytes per channel => 1024 slots |
---|
| 61 | }; |
---|
| 62 | |
---|
| 63 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[540] | 64 | // Data structures for command table |
---|
[258] | 65 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 66 | |
---|
[545] | 67 | /////////////////////////////// |
---|
| 68 | typedef struct hba_cmd_header_s // size = 16 bytes |
---|
[258] | 69 | { |
---|
| 70 | // WORD 0 |
---|
| 71 | unsigned int res0; // reserved |
---|
| 72 | |
---|
| 73 | // WORD 1 |
---|
| 74 | unsigned char lba0; // LBA 7:0 |
---|
| 75 | unsigned char lba1; // LBA 15:8 |
---|
| 76 | unsigned char lba2; // LBA 23:16 |
---|
| 77 | unsigned char res1; // reserved |
---|
| 78 | |
---|
| 79 | // WORD 2 |
---|
| 80 | unsigned char lba3; // LBA 31:24 |
---|
| 81 | unsigned char lba4; // LBA 39:32 |
---|
| 82 | unsigned char lba5; // LBA 47:40 |
---|
| 83 | unsigned char res2; // reserved |
---|
| 84 | |
---|
[545] | 85 | // WORD 3 |
---|
| 86 | unsigned int res3; // reserved |
---|
[258] | 87 | |
---|
| 88 | } hba_cmd_header_t; |
---|
| 89 | |
---|
[545] | 90 | /////////////////////////////// |
---|
[540] | 91 | typedef struct hba_cmd_buffer_s // size = 16 bytes |
---|
[258] | 92 | { |
---|
| 93 | unsigned int dba; // Buffer base address 32 LSB bits |
---|
| 94 | unsigned int dbau; // Buffer base address 32 MSB bits |
---|
| 95 | unsigned int res0; // reserved |
---|
| 96 | unsigned int dbc; // Buffer byte count |
---|
| 97 | |
---|
[540] | 98 | } hba_cmd_buffer_t; |
---|
[258] | 99 | |
---|
[545] | 100 | ////////////////////////////// |
---|
| 101 | typedef struct hba_cmd_table_s // size = 32 bytes |
---|
[258] | 102 | { |
---|
| 103 | |
---|
[540] | 104 | hba_cmd_header_t header; // contains LBA |
---|
| 105 | hba_cmd_buffer_t buffer; // only one physical buffer |
---|
[258] | 106 | |
---|
| 107 | } hba_cmd_table_t; |
---|
| 108 | |
---|
| 109 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[529] | 110 | // Data structure for command descriptor in command list |
---|
[258] | 111 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 112 | |
---|
[545] | 113 | ///////////////////////////// |
---|
[258] | 114 | typedef struct hba_cmd_desc_s // size = 16 bytes |
---|
| 115 | { |
---|
| 116 | // WORD 0 |
---|
| 117 | unsigned char flag[2]; // W in bit 6 of flag[0] |
---|
| 118 | unsigned char prdtl[2]; // Number of buffers |
---|
| 119 | |
---|
| 120 | // WORD 1 |
---|
| 121 | unsigned int prdbc; // Number of bytes actually transfered |
---|
| 122 | |
---|
| 123 | // WORD 2, WORD 3 |
---|
| 124 | unsigned int ctba; // Command Table base address 32 LSB bits |
---|
| 125 | unsigned int ctbau; // Command Table base address 32 MSB bits |
---|
| 126 | |
---|
| 127 | } hba_cmd_desc_t; |
---|
| 128 | |
---|
| 129 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[437] | 130 | // access functions |
---|
[258] | 131 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 132 | |
---|
[437] | 133 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 134 | // This function initializes for a given channel |
---|
| 135 | // - the HBA hardware registers, |
---|
| 136 | // - the command list pointer, |
---|
| 137 | // - the command lists physical addresse, |
---|
| 138 | // - the command tables physical addresses array, |
---|
| 139 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[529] | 140 | extern unsigned int _hba_init (); |
---|
[258] | 141 | |
---|
[437] | 142 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[529] | 143 | // This function register a command in Command List and Command Table |
---|
[437] | 144 | // for a single physical buffer, and updates the HBA_PXCI register. |
---|
| 145 | // Returns 0 if success, > 0 if error. |
---|
| 146 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[529] | 147 | extern unsigned int _hba_access( unsigned int use_irq, |
---|
| 148 | unsigned int to_mem, |
---|
| 149 | unsigned int lba, |
---|
| 150 | unsigned long long paddr, |
---|
| 151 | unsigned int count ); |
---|
[258] | 152 | |
---|
[529] | 153 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 154 | // Interrupt Service Routine executed in descheduling mode. |
---|
| 155 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 156 | extern void _hba_isr( unsigned int irq_type, |
---|
| 157 | unsigned int irq_id, |
---|
| 158 | unsigned int channel ); |
---|
[258] | 159 | #endif |
---|
| 160 | |
---|
| 161 | // Local Variables: |
---|
| 162 | // tab-width: 4 |
---|
| 163 | // c-basic-offset: 4 |
---|
| 164 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 165 | // indent-tabs-mode: nil |
---|
| 166 | // End: |
---|
| 167 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 168 | |
---|